Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_ReactionNetwork.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2014 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-----------------------------------------------------------------------------
26 // Filename : $RCSfile: N_DEV_ReactionNetwork.h,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
33 //
34 // Creation Date : 03/20/2006
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.14.2.1 $
40 //
41 // Revision Date : $Date: 2014/02/26 20:16:30 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 #ifndef N_DEV_ReactionNetwork_H
46 #define N_DEV_ReactionNetwork_H
47 
48 #include <N_UTL_Misc.h>
49 #include <N_UTL_fwd.h>
50 #include <iosfwd>
51 #include <vector>
52 #include <map>
53 #include <string>
54 
55 #include <N_DEV_Reaction.h>
56 #include <N_DEV_Specie.h>
57 
58 #include <N_ERH_ErrorMgr.h>
59 
60 // Note: sstream and strstream are only needed here because of all the
61 // inlined functions.
62 #include <sstream>
63 
64 namespace Xyce {
65 namespace Device {
66 
67 //-----------------------------------------------------------------------------
68 // Class : N_DEV_ReactionNetwork
69 // Purpose :
70 // Special Notes :
71 // Creator : Tom Russo, SNL
72 // Creation Date : 03/20/2006
73 //-----------------------------------------------------------------------------
75 {
76 public:
77 
78  ReactionNetwork(const std::string &name = "NoName");
79  ReactionNetwork(const ReactionNetwork & right);
80  virtual ~ReactionNetwork();
81 
82  void setReactionNetworkFromFile(const std::string &fileName);
83 
84  void addReaction(const std::string &name);
85  void addReaction(const std::string &name, N_DEV_Reaction &reaction);
86  void addReactant(const std::string &name, const std::string &reactant, double stoich);
87  void addProduct(const std::string &name, const std::string &reactant, double stoich);
88 
89  // set rate constant calculator for each type of reaction
90  void setSimpleCalc(const std::string &name, double k);
91  void setCaptureCalc(const std::string &name, double sigma, double v);
92  void setEmissionCalc(const std::string &name, double sigma, double v, double N, double E);
93  void setElectronCaptureCalc(const std::string &name, double sigma);
94  void setElectronEmissionCalc(const std::string &name, double sigma, double E);
95  void setHoleCaptureCalc(const std::string &name, double sigma);
96  void setHoleEmissionCalc(const std::string &name, double sigma, double E);
97  void setComplexCalc(const std::string &name);
98  void setDecomplexCalc(const std::string &name, double bindingEnergy,
99  double gammaAB, double gammaA, double gammaB, double concSi);
100 
101  void setRateConstant(const std::string &name, double k);
102  void scaleRateConstant(const std::string &name, double kscale);
103 
104  void setScaleParams(double c, double t, double x);
105 
106  // Use rate constant calculators
107  void scaleRateConstantFromCalculator(const std::string &name);
108  void unscaleRateConstantFromCalculator(const std::string &name);
109  void setRateConstantFromCalculator(const std::string &name, double T);
110  void setRateConstantsFromCalc(double T);
113 
114  void setSpecies(std::vector<Specie> &theSpeciesVect);
115  void addSpecie(const Specie &aSpecie);
116  void setConstants(std::vector<Specie> &theConstantsVect);
117  void addConstant(const Specie &aConstant);
118 
119  int getReactionNum(const std::string name);
120 
121  void addSourceTerm(const std::string &speciesName, const std::string &expressionStr);
122  void addSourceTerm(const std::string &speciesName,Util::Expression *expression);
123  void addMasterSourceTerm(const std::string &speciesName);
124 
125  void addInitialCondition(const std::string &speciesName, double value);
126  std::pair<std::string,double> getInitialCondition(int i);
128 
129  void setSimTime(double time);
130  double getBreakpointTime();
131  inline void setSourceScaleFac(double scf) {sourceScaleFac=scf;};
132  inline void setMasterSourceValue(double msv) {masterSourceValue=msv;};
133 
134  void getDdt(std::vector<double> &concs,std::vector<double> &constants,
135  std::vector<double> &ddt);
136  void getJac(std::vector<double> &concs, std::vector<double> &constants,
137  std::vector<std::vector<double> >&jac);
138  void getDFdConst(const std::string &constantName,
139  std::vector<double> &concs, std::vector<double> &constants,
140  std::vector<double> &dFdConst);
141 
142  double getRate(std::vector<double> &concs,std::vector<double> &constants,
143  std::vector<int> &captureVect, std::vector<int> &emissionVect);
144  void getDRateDC(std::vector<double> &concs,std::vector<double> &constants,
145  std::vector<int> &captureVect, std::vector<int> &emissionVect,
146  std::vector<double>&dratedc);
147 
148  void getDRateDConst(std::vector<double> &concs,std::vector<double> &constants,
149  std::vector<int> &captureVect, std::vector<int> &emissionVect,
150  std::vector<double>&dratedc);
151 
152  double getCaptureLifetime(std::vector<double> &concs,std::vector<double> &constants,
153  std::vector<int> &captureVect,double &concentration);
154  void getCaptureLifetimes(std::vector<double> &concs,std::vector<double> &constants,
155  std::vector<int> &captureVect,double &concentration,
156  std::vector<double> &lifetimes);
157  double getELifetime(std::vector<double>&concs,std::vector<double>&constants);
158  double getHLifetime(std::vector<double>&concs,std::vector<double>&constants);
159  void getELifetimes(std::vector<double>&concs,std::vector<double>&constants,
160  std::vector<double> &lifetimes);
161  void getHLifetimes(std::vector<double>&concs,std::vector<double>&constants,
162  std::vector<double> &lifetimes);
163 
164  double getERate(std::vector<double> &concs,std::vector<double> &constants);
165  double getHRate(std::vector<double> &concs,std::vector<double> &constants);
166 
167  void getDERateDC(std::vector<double> &concs,std::vector<double> &constants,
168  std::vector<double>&dratedc);
169  void getDHRateDC(std::vector<double> &concs,std::vector<double> &constants,
170  std::vector<double>&dratedc);
171 
172  void getDERateDConst(std::vector<double> &concs,std::vector<double> &constants,
173  std::vector<double>&dratedConst);
174  void getDHRateDConst(std::vector<double> &concs,std::vector<double> &constants,
175  std::vector<double>&dratedConst);
176 
177  int getNumSpecies();
178  int getNumConstants();
179  const std::string & getSpeciesName(int i);
180  const std::string & getConstantsName(int i);
181  int getSpeciesNum(const std::string &name);
182  int getConstantNum(const std::string &name);
183  int getReactantNum(const std::string &name);
184  bool reactantExist(const std::string &name);
185  bool constantExist(const std::string &name);
186 
187  void setName(const std::string &name);
188  void clear();
189  void output(std::ostream & os) const;
190 
191  double getDiffusionCoefficient (const std::string & name, const double temp);
192  double getDiffusionCoefficient (int specie, const double temp);
193 
194  int getChargeState (const std::string & name);
195  int getChargeState (int specie);
196 
197  void setApplySources(bool flag);
198 
199 private:
200  N_DEV_Reaction &getReaction(const std::string &name);
201  N_DEV_Reaction &getReaction(int i);
202 
203  std::map<std::string,int> speciesMap;
204  std::vector<Specie> species;
205  std::map<std::string,int> constantsMap;
206  std::vector<Specie> constants;
207  std::vector<std::pair<std::string,double> > initialConditions;
208  std::vector<Reaction> theReactions;
209  std::map<std::string,int> reactionNamesMap;
210  std::vector<std::string> reactionNames;
211  std::string myName;
212  std::vector<int> electronCaptureReactions;
213  std::vector<int> holeCaptureReactions;
214  std::vector<int> electronEmissionReactions;
215  std::vector<int> holeEmissionReactions;
216  std::vector< std::pair<int,Util::Expression *> > theSourceTerms;
217  std::vector<int> masterSourceSpecies;
220  double C0;
221  double t0;
222  double x0;
223 
225 };
226 
227 //-----------------------------------------------------------------------------
228 // Function : ReactionNetwork::clear
229 // Purpose : make the reaction network an empty one
230 // Special Notes :
231 // Scope : public
232 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
233 // Creation Date : 3/20/06
234 //-----------------------------------------------------------------------------
236 {
237  speciesMap.clear();
238  species.clear();
239  constantsMap.clear();
240  constants.clear();
241  theReactions.clear();
242  reactionNamesMap.clear();
243  setName("NoName");
244 }
245 
246 //-----------------------------------------------------------------------------
247 // Function : ReactionNetwork::setName
248 // Purpose : Accessor function to set network name
249 // Special Notes :
250 // Scope : public
251 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
252 // Creation Date : 3/20/06
253 //-----------------------------------------------------------------------------
254 inline void ReactionNetwork::setName(const std::string &name)
255 {
256  myName=name;
257 }
258 
259 //-----------------------------------------------------------------------------
260 // Function : ReactionNetwork::getNumSpecies
261 // Purpose : Accessor function to returning number of species recorded
262 // Special Notes : Only solution species returned, does not include constants
263 // Scope : public
264 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
265 // Creation Date : 3/20/06
266 //-----------------------------------------------------------------------------
268 {
269  return (species.size());
270 }
271 
272 //-----------------------------------------------------------------------------
273 // Function : ReactionNetwork::getNumConstants
274 // Purpose : Accessor function to returning number of constant species
275 // Special Notes :
276 // Scope : public
277 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
278 // Creation Date : 8/10/06
279 //-----------------------------------------------------------------------------
281 {
282  return (constants.size());
283 }
284 
285 //-----------------------------------------------------------------------------
286 // Function : ReactionNetwork::getSpeciesName
287 // Purpose : Accessor function to returning name of indicated species
288 // Special Notes : Only returns solution species names, not constants
289 // Scope : public
290 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
291 // Creation Date : 3/20/06
292 //-----------------------------------------------------------------------------
293 inline const std::string & ReactionNetwork::getSpeciesName(int i)
294 {
295  return species[i].getName();
296 }
297 
298 //-----------------------------------------------------------------------------
299 // Function : ReactionNetwork::getConstantsName
300 // Purpose : Accessor function to returning name of indicated constant
301 // species
302 // Special Notes : Only returns solution constants names, not variable species
303 // Scope : public
304 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
305 // Creation Date : 3/20/06
306 //-----------------------------------------------------------------------------
307 inline const std::string & ReactionNetwork::getConstantsName(int i)
308 {
309  return constants[i].getName();
310 }
311 
312 //-----------------------------------------------------------------------------
313 // Function : ReactionNetwork::getSpeciesNum
314 // Purpose : Accessor function to return number of named variable specie
315 // Special Notes : returns -1 if the specified specie is not a variable
316 // Scope : public
317 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
318 // Creation Date : 3/20/06
319 //-----------------------------------------------------------------------------
320 inline int ReactionNetwork::getSpeciesNum(const std::string &name)
321 {
322  std::map<std::string,int>::iterator n_i;
323  n_i = speciesMap.find(name);
324 
325  if (n_i == speciesMap.end())
326  {
327  return -1;
328  }
329  else
330  {
331  return n_i->second;
332  }
333 }
334 
335 //-----------------------------------------------------------------------------
336 // Function : ReactionNetwork::reactantExist
337 // Purpose : Returns false if the named specie doesn't exist, or if
338 // it is a constant.
339 // Special Notes :
340 // Scope : public
341 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
342 // Creation Date : 4/24/07
343 //-----------------------------------------------------------------------------
344 inline bool ReactionNetwork::reactantExist(const std::string &name)
345 {
346  bool retFlag(true);
347  int i=getSpeciesNum(name);
348  if (i == -1)
349  {
350  retFlag = false; // this reactant does not exist.
351  }
352 
353  return retFlag;
354 }
355 
356 //-----------------------------------------------------------------------------
357 // Function : ReactionNetwork::constantExist
358 // Purpose : Returns false if the named specie doesn't exist, or if
359 // it is a constant.
360 // Special Notes :
361 // Scope : public
362 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
363 // Creation Date : 4/24/07
364 //-----------------------------------------------------------------------------
365 inline bool ReactionNetwork::constantExist(const std::string &name)
366 {
367  bool retFlag(true);
368  int i=getConstantNum(name);
369  if (i == -1)
370  {
371  retFlag = false; // this constant does not exist.
372  }
373 
374  return retFlag;
375 }
376 
377 //-----------------------------------------------------------------------------
378 // Function : ReactionNetwork::getReactantNum
379 // Purpose : Accessor function to return number of named specie
380 // Special Notes : Returns negative numbers for constants, positive for
381 // variables
382 // The species in question better exist, coz there's no way
383 // to return an error condition other than bombing.
384 // Scope : public
385 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
386 // Creation Date : 3/20/06
387 //-----------------------------------------------------------------------------
388 inline int ReactionNetwork::getReactantNum(const std::string &name)
389 {
390  int i=getSpeciesNum(name);
391  if (i == -1)
392  {
393  i=getConstantNum(name);
394  if (i == -1)
395  {
396  std::string msg="ReactionNetwork::getReactantNum: invalid species name specified: ";
397  msg += name;
398  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL, msg);
399  }
400  i = -(i+1);
401  }
402  return i;
403 }
404 
405 //-----------------------------------------------------------------------------
406 // Function : ReactionNetwork::getConstantNum
407 // Purpose : Accessor function to return number of named constant specie
408 // Special Notes : returns -1 if the specified specie is not a constant
409 // Scope : public
410 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
411 // Creation Date : 3/20/06
412 //-----------------------------------------------------------------------------
413 inline int ReactionNetwork::getConstantNum(const std::string &name)
414 {
415  std::map<std::string,int>::iterator n_i;
416  n_i = constantsMap.find(name);
417 
418  if (n_i == constantsMap.end())
419  {
420  return -1;
421  }
422  else
423  {
424  return n_i->second;
425  }
426 }
427 
428 //-----------------------------------------------------------------------------
429 // Function : ReactionNetwork::addInitialCondition
430 // Purpose : add an initial condition to the list
431 //
432 // Scope : public
433 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
434 // Creation Date : 03/20/06
435 //-----------------------------------------------------------------------------
436 inline void ReactionNetwork::addInitialCondition(const std::string &speciesName, double value)
437 {
438  initialConditions.push_back(std::pair<std::string,double>(speciesName,value));
439 }
440 
441 //-----------------------------------------------------------------------------
442 // Function : ReactionNetwork::getNumInitialConditions
443 // Purpose : get an initial condition from the list
444 //
445 // Scope : public
446 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
447 // Creation Date : 03/20/06
448 //-----------------------------------------------------------------------------
449 inline int
451 {
452  return(initialConditions.size());
453 }
454 //-----------------------------------------------------------------------------
455 // Function : ReactionNetwork::getInitialCondition
456 // Purpose : get an initial condition from the list
457 //
458 // Scope : public
459 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
460 // Creation Date : 03/20/06
461 //-----------------------------------------------------------------------------
462 inline std::pair<std::string,double>
464 {
465  return(initialConditions[i]);
466 }
467 
468 //-----------------------------------------------------------------------------
469 // Function : ReactionNetwork::getReactionNum
470 // Purpose : Accessor function to return number of named reaction
471 // Special Notes :
472 // Scope : public
473 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
474 // Creation Date : 3/20/06
475 //-----------------------------------------------------------------------------
476 inline int ReactionNetwork::getReactionNum(std::string name)
477 {
478  std::map<std::string,int>::iterator n_i;
479  n_i = reactionNamesMap.find(name);
480 
481  if (n_i == reactionNamesMap.end())
482  {
483  return -1;
484  }
485  else
486  {
487  return n_i->second;
488  }
489 }
490 
491 //-----------------------------------------------------------------------------
492 // Function : ReactionNetwork::getReaction
493 // Purpose : Accessor function to returning reference to indexed reaction
494 // Special Notes :
495 // Scope : public
496 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
497 // Creation Date : 3/20/06
498 //-----------------------------------------------------------------------------
500 {
501  return theReactions[i];
502 }
503 
504 //-----------------------------------------------------------------------------
505 // Function : ReactionNetwork::getReaction
506 // Purpose : Accessor function to returning reference to named reaction
507 // Special Notes :
508 // Scope : public
509 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
510 // Creation Date : 3/20/06
511 //-----------------------------------------------------------------------------
512 inline N_DEV_Reaction &ReactionNetwork::getReaction(const std::string &name)
513 {
514  int ni;
515  ni=getReactionNum(name);
516  if (ni == -1)
517  {
518  std::ostringstream ost;
519  ost << " Attempt to access non-existant reaction " << name << std::endl;
520  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL, ost.str());
521  }
522 
523  return theReactions[ni];
524 }
525 
526 //-----------------------------------------------------------------------------
527 // Function : ReactionNetwork::setSimpleCalc
528 // Purpose : set the named reaction's rate calculator to type Simple
529 // Special Notes :
530 // Scope : public
531 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
532 // Creation Date : 08/01/06
533 //-----------------------------------------------------------------------------
534 inline void ReactionNetwork::setSimpleCalc(const std::string &name, double k)
535 {
537 }
538 
539 //-----------------------------------------------------------------------------
540 // Function : ReactionNetwork::setCaptureCalc
541 // Purpose : set the named reaction's rate calculator to type Capture
542 // Special Notes :
543 // Scope : public
544 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
545 // Creation Date : 08/01/06
546 //-----------------------------------------------------------------------------
547 inline void ReactionNetwork::setCaptureCalc(const std::string &name, double sigma, double v)
548 {
550 }
551 //-----------------------------------------------------------------------------
552 // Function : ReactionNetwork::setElectronCaptureCalc
553 // Purpose : set the named reaction's rate calculator to type Capture
554 // Special Notes : Specifically uses v_n=2.3e7 cm/s
555 // Scope : public
556 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
557 // Creation Date : 08/01/06
558 //-----------------------------------------------------------------------------
559 inline void ReactionNetwork::setElectronCaptureCalc(const std::string &name, double sigma)
560 {
561  getReaction(name).setCaptureRateCalculator(sigma,2.3e7,C0,t0,x0);
562 }
563 //-----------------------------------------------------------------------------
564 // Function : ReactionNetwork::setHoleCaptureCalc
565 // Purpose : set the named reaction's rate calculator to type Capture
566 // Special Notes : uses v_p=1.9e7 cm/s
567 // Scope : public
568 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
569 // Creation Date : 08/01/06
570 //-----------------------------------------------------------------------------
571 inline void ReactionNetwork::setHoleCaptureCalc(const std::string &name, double sigma)
572 {
573  getReaction(name).setCaptureRateCalculator(sigma,1.9e7,C0,t0,x0);
574 }
575 
576 //-----------------------------------------------------------------------------
577 // Function : ReactionNetwork::setEmissionCalc
578 // Purpose : set the named reaction's rate calculator to type emission
579 // Special Notes :
580 // Scope : public
581 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
582 // Creation Date : 08/01/06
583 //-----------------------------------------------------------------------------
584 inline void ReactionNetwork::setEmissionCalc(const std::string &name, double sigma, double v, double N, double E)
585 {
586  getReaction(name).setEmissionRateCalculator(sigma,v,N,E,C0,t0,x0);
587 }
588 //-----------------------------------------------------------------------------
589 // Function : ReactionNetwork::setElectronEmissionCalc
590 // Purpose : set the named reaction's rate calculator to type emission
591 // Special Notes :Uses v_n=2.3e7 cm/s and N_c=2.86e19 cm^{-3}
592 // Scope : public
593 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
594 // Creation Date : 08/01/06
595 //-----------------------------------------------------------------------------
596 inline void ReactionNetwork::setElectronEmissionCalc(const std::string &name, double sigma, double E)
597 {
598  getReaction(name).setEmissionRateCalculator(sigma,2.3e7,2.86e19,E,C0,t0,x0);
599 }
600 //-----------------------------------------------------------------------------
601 // Function : ReactionNetwork::setHoleEmissionCalc
602 // Purpose : set the named reaction's rate calculator to type emission
603 // Special Notes : uses v_p=1.9e7 cm/s and N_v=2.66e19 cm^{-3}
604 // Scope : public
605 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
606 // Creation Date : 08/01/06
607 //-----------------------------------------------------------------------------
608 inline void ReactionNetwork::setHoleEmissionCalc(const std::string &name, double sigma, double E)
609 {
610  getReaction(name).setEmissionRateCalculator(sigma,1.9e7,2.66e19,E,C0,t0,x0);
611 }
612 
613 //-----------------------------------------------------------------------------
614 // Function : ReactionNetwork::setComplexCalc
615 // Purpose : set the named reaction's rate calculator to type emission
616 // Special Notes :
617 // Scope : public
618 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
619 // Creation Date : 08/01/06
620 //-----------------------------------------------------------------------------
621 inline void ReactionNetwork::setComplexCalc(const std::string &name)
622 {
624 }
625 
626 //-----------------------------------------------------------------------------
627 // Function : ReactionNetwork::setDecomplexCalc
628 // Purpose : set the named reaction's rate calculator to type emission
629 // Special Notes :
630 // Scope : public
631 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
632 // Creation Date : 08/01/06
633 //-----------------------------------------------------------------------------
634 inline void ReactionNetwork::setDecomplexCalc(const std::string &name,
635  double bindingEnergy,
636  double gammaAB,
637  double gammaA,
638  double gammaB,
639  double concSi)
640 {
641 
643  bindingEnergy,gammaAB,gammaA,
644  gammaB,concSi,C0,t0,x0);
645 }
646 
647 
648 
649 //-----------------------------------------------------------------------------
650 // Function : ReactionNetwork::output
651 // Purpose :
652 // Special Notes :
653 // Scope : public
654 // Creator : Eric R. Keiter, SNL, Electrical and Microsystems Modeling
655 // Creation Date : 05/27/06
656 //-----------------------------------------------------------------------------
657 inline void ReactionNetwork::output(std::ostream & os) const
658 {
659  int i;
660 
661  for (i=0;i< species.size();++i)
662  {
663  os << "species["<<i<<"] = " << species[i].getName() << std::endl;
664  }
665  os << std::endl;
666 
667 
668  for (i=0;i<theReactions.size();++i)
669  {
670  os << reactionNames[i];
671  theReactions[i].output( species, os);
672  }
673 
674  if (electronCaptureReactions.size() != 0)
675  {
676  os << "Electron Capture Reactions: " << std::endl;
677  for ( i=0; i<electronCaptureReactions.size(); ++i)
678  {
679  os << " Reaction number " << electronCaptureReactions[i] << "("
680  << reactionNames[electronCaptureReactions[i]] << ")" << std::endl;
681  }
682  }
683  if (holeCaptureReactions.size() != 0)
684  {
685  os << "Hole Capture Reactions: " << std::endl;
686  for ( i=0; i<holeCaptureReactions.size(); ++i)
687  {
688  os << " Reaction number " << holeCaptureReactions[i] << "("
689  << reactionNames[holeCaptureReactions[i]] << ")" << std::endl;
690  }
691  }
692  if (electronEmissionReactions.size() != 0)
693  {
694  os << "Electron Emission Reactions: " << std::endl;
695  for ( i=0; i<electronEmissionReactions.size(); ++i)
696  {
697  os << " Reaction number " << electronEmissionReactions[i] << "("
698  << reactionNames[electronEmissionReactions[i]] << ")" << std::endl;
699  }
700  }
701  if (holeEmissionReactions.size() != 0)
702  {
703  os << "Hole Emission Reactions: " << std::endl;
704  for ( i=0; i<holeEmissionReactions.size(); ++i)
705  {
706  os << " Reaction number " << holeEmissionReactions[i] << "("
707  << reactionNames[holeEmissionReactions[i]] << ")" << std::endl;
708  }
709  }
710 
711  return;
712 }
713 
714 //-----------------------------------------------------------------------------
715 // Function : ReactionNetwork::operator<<
716 // Purpose : "<<" operator
717 // Special Notes :
718 // Scope : public
719 // Creator : Eric R. Keiter, SNL, Electrical and Microsystems Modeling
720 // Creation Date : 05/27/06
721 //-----------------------------------------------------------------------------
722 inline std::ostream & operator<<(std::ostream & os, const ReactionNetwork & rn)
723 {
724  os << "Reaction Network: " << std::endl;
725  rn.output(os);
726 
727  return os;
728 }
729 
730 
731 //-----------------------------------------------------------------------------
732 // Function : ReactionNetwork::getERate
733 // Purpose : Compute the total rate at which electrons are "consumed" or
734 // "produced" by all the capture and emission reactions,
735 // if there are any. This can be used even if the electron
736 // concentration is held fixed (it'll just be the sum of all
737 // reaction rates involving electrons).
738 // Special Notes : Assumes that all emission and capture reactions are
739 // of the form B=>A+E or A+E=>B and will be incorrect if
740 // any reaction not of this form is given a name with
741 // "_ELECTRON_EMISSION" or "_ELECTRON_CAPTURE" in it.
742 //
743 // Scope : public
744 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
745 // Creation Date : 03/20/06
746 //-----------------------------------------------------------------------------
747 inline double ReactionNetwork::getERate(std::vector<double> &concs,
748  std::vector<double> &constant_vec)
749 {
750  return getRate(concs,constant_vec,electronCaptureReactions,
752 }
753 
754 //-----------------------------------------------------------------------------
755 // Function : ReactionNetwork::getELifetime
756 // Purpose :
757 // Special Notes :
758 // Scope : public
759 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
760 // Creation Date : 09/20/06
761 //-----------------------------------------------------------------------------
762 inline double ReactionNetwork::getELifetime(std::vector<double> &concs,
763  std::vector<double> &constant_vec)
764 {
765 
766  double eConc;
767  int concNum=getReactantNum("E");
768  // Bleah
769  if (concNum < 0)
770  eConc = constant_vec[-(concNum+1)];
771  else
772  eConc = concs[concNum];
773 
774 
775  return getCaptureLifetime(concs,constant_vec,electronCaptureReactions,
776  eConc);
777 }
778 
779 //-----------------------------------------------------------------------------
780 // Function : ReactionNetwork::getELifetimes
781 // Purpose :
782 // Special Notes :
783 // Scope : public
784 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
785 // Creation Date : 09/20/06
786 //-----------------------------------------------------------------------------
787 inline void ReactionNetwork::getELifetimes(std::vector<double> &concs,
788  std::vector<double> &constant_vec,
789  std::vector<double> &lifetimes)
790 {
791 
792  double eConc;
793  int concNum=getReactantNum("E");
794  // Bleah
795  if (concNum < 0)
796  eConc = constant_vec[-(concNum+1)];
797  else
798  eConc = concs[concNum];
799 
800 
802  eConc,lifetimes);
803 }
804 
805 //-----------------------------------------------------------------------------
806 // Function : ReactionNetwork::getDERateDC
807 // Purpose : compute vector of derivatives of net electron emission
808 // rate (e.g. result of getERate) with respect to concentration
809 //
810 // Scope : public
811 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
812 // Creation Date : 03/20/06
813 //-----------------------------------------------------------------------------
814 inline void ReactionNetwork::getDERateDC(std::vector<double> &concs,
815  std::vector<double> &constant_vec,
816  std::vector<double> &dRatedC)
817 {
818  getDRateDC(concs,constant_vec,electronCaptureReactions,
819  electronEmissionReactions,dRatedC);
820 }
821 
822 //-----------------------------------------------------------------------------
823 // Function : ReactionNetwork::getDERateDConst
824 // Purpose : compute vector of derivatives of net electron emission
825 // rate (e.g. result of getERate) with respect to concentration
826 //
827 // Scope : public
828 // Creator : Eric R. Keiter
829 // Creation Date : 11/15/08
830 //-----------------------------------------------------------------------------
831 inline void ReactionNetwork::getDERateDConst(std::vector<double> &concs,
832  std::vector<double> &constant_vec,
833  std::vector<double> &dRatedConst)
834 {
835  getDRateDConst(concs,constant_vec,electronCaptureReactions,
836  electronEmissionReactions,dRatedConst);
837 }
838 
839 //-----------------------------------------------------------------------------
840 // Function : ReactionNetwork::getHRate
841 // Purpose : Compute the total rate at which holes are "consumed" or
842 // "produced" by all the capture and emission reactions,
843 // if there are any. This can be used even if the electron
844 // concentration is held fixed (it'll just be the sum of all
845 // reaction rates involving electrons).
846 // Special Notes : Assumes that all emission and capture reactions are
847 // of the form B=>A+H or A+H=>B and will be incorrect if
848 // any reaction not of this form is given a name with
849 // "_HOLE_EMISSION" or "_HOLE_CAPTURE" in it.
850 // Scope : public
851 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
852 // Creation Date : 03/20/06
853 //-----------------------------------------------------------------------------
854 inline double ReactionNetwork::getHRate(std::vector<double> &concs,
855  std::vector<double> &constant_vec)
856 {
857  return getRate(concs,constant_vec,holeCaptureReactions,
859 }
860 
861 
862 //-----------------------------------------------------------------------------
863 // Function : ReactionNetwork::getHLifetime
864 // Purpose :
865 // Special Notes :
866 // Scope : public
867 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
868 // Creation Date : 09/20/06
869 //-----------------------------------------------------------------------------
870 inline double ReactionNetwork::getHLifetime(std::vector<double> &concs,
871  std::vector<double> &constant_vec)
872 {
873 
874  double hConc;
875  int concNum=getReactantNum("H");
876  // Bleah
877  if (concNum < 0)
878  hConc = constant_vec[-(concNum+1)];
879  else
880  hConc = concs[concNum];
881 
882  return getCaptureLifetime(concs,constant_vec,holeCaptureReactions,
883  hConc);
884 }
885 
886 //-----------------------------------------------------------------------------
887 // Function : ReactionNetwork::getHLifetimes
888 // Purpose :
889 // Special Notes :
890 // Scope : public
891 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
892 // Creation Date : 09/20/06
893 //-----------------------------------------------------------------------------
894 inline void ReactionNetwork::getHLifetimes(std::vector<double> &concs,
895  std::vector<double> &constant_vec,
896  std::vector<double> &lifetimes)
897 {
898 
899  double hConc;
900  int concNum=getReactantNum("H");
901  // Bleah
902  if (concNum < 0)
903  hConc = constant_vec[-(concNum+1)];
904  else
905  hConc = concs[concNum];
906 
907 
908  getCaptureLifetimes(concs,constant_vec,holeCaptureReactions,
909  hConc,lifetimes);
910 }
911 
912 //-----------------------------------------------------------------------------
913 // Function : ReactionNetwork::getDHRateDC
914 // Purpose : compute vector of derivatives of net hole emission
915 // rate (e.g. result of getHRate) with respect to concentration
916 //
917 // Scope : public
918 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
919 // Creation Date : 03/20/06
920 //-----------------------------------------------------------------------------
921 inline void ReactionNetwork::getDHRateDC(std::vector<double> &concs,
922  std::vector<double> &constant_vec,
923  std::vector<double> &dRatedC)
924 {
925  getDRateDC(concs,constant_vec,holeCaptureReactions,
926  holeEmissionReactions,dRatedC);
927 }
928 
929 //-----------------------------------------------------------------------------
930 // Function : ReactionNetwork::getDHRateDConst
931 // Purpose : compute vector of derivatives of net hole emission
932 // rate (e.g. result of getHRate) with respect to concentration
933 //
934 // Scope : public
935 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
936 // Creation Date : 03/20/06
937 //-----------------------------------------------------------------------------
938 inline void ReactionNetwork::getDHRateDConst(std::vector<double> &concs,
939  std::vector<double> &constant_vec,
940  std::vector<double> &dRatedConst)
941 {
942  getDRateDConst(concs,constant_vec,holeCaptureReactions,
943  holeEmissionReactions,dRatedConst);
944 }
945 
946 //-----------------------------------------------------------------------------
947 // Function : ReactionNetwork::getDiffusionCoefficient
948 // Purpose :
949 // Scope : public
950 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
951 // Creation Date : 03/20/06
952 //-----------------------------------------------------------------------------
954 (const std::string & name, const double temp)
955 {
956  int num = getSpeciesNum(name);
957  double D = 0.0;
958 
959  if (num < 0)
960  D = 0.0;
961  else
962  D = species[num].getDiffusionCoefficient(temp);
963 
964  return D;
965 }
966 
967 //-----------------------------------------------------------------------------
968 // Function : ReactionNetwork::getDiffusionCoefficient
969 // Purpose :
970 // Scope : public
971 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
972 // Creation Date : 10/31/06
973 //-----------------------------------------------------------------------------
975 (int specie, const double temp)
976 {
977  double D = 0.0;
978 
979  if (specie < 0)
980  D = 0.0;
981  else
982  D = species[specie].getDiffusionCoefficient(temp);
983 
984  return D;
985 }
986 
987 //-----------------------------------------------------------------------------
988 // Function : ReactionNetwork::getChargeState
989 // Purpose :
990 // Scope : public
991 // Creator : Lawrence C Musson
992 // Creation Date : 02/22/2012
993 //-----------------------------------------------------------------------------
995 (const std::string & name)
996 {
997  int num = getSpeciesNum(name);
998  int z = 0;
999 
1000  if (num < 0)
1001  z = 0;
1002  else
1003  z = species[num].getChargeState();
1004 
1005  return z;
1006 }
1007 
1008 //-----------------------------------------------------------------------------
1009 // Function : ReactionNetwork::getChargeState
1010 // Purpose :
1011 // Scope : public
1012 // Creator : Lawrence C Musson
1013 // Creation Date : 10/31/06
1014 //-----------------------------------------------------------------------------
1016 (int specie)
1017 {
1018  int z = 0;
1019 
1020  if (specie < 0)
1021  z = 0;
1022  else
1023  z = species[specie].getChargeState();
1024 
1025  return z;
1026 }
1027 
1028 //-----------------------------------------------------------------------------
1029 // Function : ReactionNetwork::setApplySources
1030 // Purpose :
1031 // Scope : public
1032 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
1033 // Creation Date : 04/19/09
1034 //-----------------------------------------------------------------------------
1035 inline void ReactionNetwork::setApplySources(bool flag)
1036 {
1037  applySources = flag;
1038 }
1039 
1040 } // namespace Device
1041 } // namespace Xyce
1042 
1043 #endif