46 #include <Xyce_config.h>
51 #include <N_UTL_Misc.h>
53 #ifdef Xyce_DEBUG_DEVICE
60 #include <N_ERH_ErrorMgr.h>
61 #include <N_UTL_Xyce.h>
62 #include <N_UTL_fwd.h>
63 #include <N_UTL_Expression.h>
66 #ifdef Xyce_REACTION_PARSER
74 #include "N_DEV_ReactionParser.hxx"
81 int N_DEV_ReactionLexer::getToken(Xyce::Device::N_DEV_ReactionParser::semantic_value *lvalp, \
82 Xyce::Device::location *llocp, \
83 map<std::string,int> &theSpeciesIDs)
92 #include <FlexLexer.h>
96 #define yylex N_DEV_lex
132 : speciesMap(right.speciesMap),
133 species(right.species),
134 constantsMap(right.constantsMap),
135 constants(right.constants),
136 initialConditions(right.initialConditions),
137 theReactions(right.theReactions),
138 reactionNamesMap(right.reactionNamesMap),
139 reactionNames(right.reactionNames),
140 myName(right.myName),
141 electronCaptureReactions(right.electronCaptureReactions),
142 holeCaptureReactions(right.holeCaptureReactions),
143 electronEmissionReactions(right.electronEmissionReactions),
144 holeEmissionReactions(right.holeEmissionReactions),
145 sourceScaleFac(right.sourceScaleFac),
149 applySources(right.applySources)
157 for (i=0;i<sourceSize;++i)
159 Util::Expression *newSource;
161 newSource =
new Util::Expression(*((right.
theSourceTerms[i]).second));
191 std::pair<int,Util::Expression *> tempPair =
theSourceTerms.back();
193 delete tempPair.second;
211 #ifdef Xyce_REACTION_PARSER
216 std::ifstream reactionFile;
217 std::map<std::string,int> theSpeciesIDs;
220 reactionFile.open(fileName.c_str(),std::ios::in);
221 if (reactionFile.is_open())
227 Report::UserError() <<
"ReactionNetwork::setReactionNetworkFromFile: Cannot open reaction specification file: " << fileName;
230 XyceDevice::ReactionParser theParser(theLexer, theSpeciesIDs, *
this);
233 if (theParser.parse())
235 #ifdef Xyce_DEBUG_DEVICE
236 Xyce::dout() << *
this << std::endl;
238 Report::UserError() <<
"ReactionNetwork::setReactionNetworkFromFile: Parsing reaction spec from file " << fileName <<
" failed.";
264 int nspec=theSpeciesVect.size();
269 for (i=0;i<nspec;++i)
296 int nspec=theConstantsVect.size();
301 for (i=0;i<nspec;++i)
372 Report::DevelFatal() <<
" Attempt to add reaction duplicate name " << name;
389 if (name.find(
"_ELECTRON_CAPTURE",0) != std::string::npos)
393 else if (name.find(
"_HOLE_CAPTURE",0) != std::string::npos)
397 else if (name.find(
"_ELECTRON_EMISSION",0) != std::string::npos)
401 else if (name.find(
"_HOLE_EMISSION",0) != std::string::npos)
422 std::map<std::string,int>::iterator n_i;
426 if (reactionNum == -1)
428 Report::DevelFatal() <<
" Attempt to add reactant " << reactant
429 <<
" to non-existant reaction " << name;
443 Report::DevelFatal() <<
"attempt to add unknown reactant " << reactant
444 <<
" to reaction number " << reactionNum
449 speciesNum = -(n_i->second+1);
454 speciesNum = n_i->second;
477 std::map<std::string,int>::iterator n_i;
483 if (reactionNum == -1)
485 Report::DevelFatal() <<
" Attempt to add product " << product
486 <<
" to non-existant reaction " << name;
500 Report::DevelFatal() <<
"attempt to add unknown product " << product
501 <<
" to reaction number " << reactionNum
506 std::ostringstream ost;
508 #ifdef Xyce_RXN_WARNINGS
509 Report::UserWarning() <<
" Specified constant species " << product
510 <<
" as product of reaction number " << reactionNum
511 <<
"(" << name <<
")"<<std::endl
512 <<
" IGNORING that product";
518 speciesNum = n_i->second;
540 if (reactionNum == -1)
542 Report::DevelFatal() <<
" Attempt to set rate constant of non-existant reaction "
565 if (reactionNum == -1)
567 Report::DevelFatal() <<
" Attempt to scale rate constant of non-existant reaction "
591 if (reactionNum == -1)
593 Report::DevelFatal() <<
" Attempt to scale rate constant of non-existant reaction "
613 std::vector<double> &concs,
614 std::vector<double> &constant_vec)
620 if (reactionNum == -1)
622 Report::DevelFatal() <<
" Attempt to scale rate constant of non-existant reaction "
646 if (reactionNum == -1)
648 Report::DevelFatal() <<
" Attempt to scale rate constant of non-existant reaction "
672 if (reactionNum == -1)
674 Report::DevelFatal() <<
" Attempt to scale rate constant of non-existant reaction "
696 for (i=0; i<numReacts; ++i)
713 std::vector<double> &concs,
714 std::vector<double> &constant_vec)
718 for (i=0; i<numReacts; ++i)
720 theReactions[i].setRateConstantFromCalculator(T,concs,constant_vec);
737 for (i=0; i<numReacts; ++i)
756 for (i=0; i<numReacts; ++i)
779 std::vector<N_DEV_Reaction>::iterator reactionIter=
theReactions.begin();
780 std::vector<N_DEV_Reaction>::iterator reactionIterEnd=
theReactions.end();
785 for (; reactionIter != reactionIterEnd; ++reactionIter)
787 reactionIter->setScaleFactors(
C0,
t0,
x0);
806 Util::Expression *foo=
new Util::Expression(expressionStr);
807 theSourceTerms.push_back( std::pair<int,Util::Expression *>(speciesNum, foo));
824 Util::Expression * ExpressionCopy=
new Util::Expression(*expression);
829 std::pair<int,Util::Expression *>(speciesNum,ExpressionCopy));
862 std::vector< std::pair<int,Util::Expression *> >::iterator iterSource=
864 std::vector< std::pair<int,Util::Expression *> >::iterator source_end=
867 for (;iterSource != source_end; ++iterSource)
869 (iterSource->second)->set_sim_time(time);
884 double breaktime=0, btime;
885 std::vector< std::pair<int,Util::Expression *> >::iterator iterSource=
887 std::vector< std::pair<int,Util::Expression *> >::iterator source_end=
890 for (;iterSource != source_end; ++iterSource)
892 btime=(iterSource->second)->get_break_time();
919 std::vector<double> &ddt)
923 for (i=0;i<rSize;++i)
929 std::vector< std::pair<int,Util::Expression *> >::iterator iterSource=
931 std::vector< std::pair<int,Util::Expression *> >::iterator source_end=
934 for (;iterSource != source_end; ++iterSource)
937 (iterSource->second)->evaluateFunction(return_val);
945 for (; iterMasterSource!= masterSource_end; ++iterMasterSource)
963 std::vector<std::vector<double> >&jac)
967 for (i=0;i<rSize;++i)
983 std::vector<double> &concs,
984 std::vector<double> &constant_vec,
985 std::vector<double> &dFdConst)
988 int cSize=concs.size();
992 dFdConst.resize(cSize);
993 for (i=0;i<cSize;++i)
996 for (i=0;i<rSize;++i)
998 theReactions[i].getDFdConst(constNum,concs,constant_vec,dFdConst);
1023 std::vector<double> &constant_vec,
1024 std::vector<int> &captureVect,
1025 std::vector<int> &emissionVect)
1030 for (i=0;i<captureVect.size();++i)
1032 rate -=
theReactions[captureVect[i]].getRate(concs, constant_vec);
1035 for (i=0;i<emissionVect.size();++i)
1037 rate +=
theReactions[emissionVect[i]].getRate(concs,constant_vec);
1057 std::vector<double> &constant_vec,
1058 std::vector<int> &captureVect,
1059 double & concentration)
1064 for (i=0;i<captureVect.size();++i)
1066 rate +=
theReactions[captureVect[i]].getRate(concs, constant_vec);
1071 return concentration/rate;
1093 std::vector<double> &constant_vec,
1094 std::vector<int> &captureVect,
1095 double & concentration,
1096 std::vector<double> &lifetimes)
1099 lifetimes.resize(captureVect.size());
1101 for (i=0;i<captureVect.size();++i)
1103 lifetimes[i] =
theReactions[captureVect[i]].getRate(concs, constant_vec);
1105 if (lifetimes[i] > 0)
1106 lifetimes[i] = concentration/lifetimes[i];
1136 std::vector<double> &constant_vec,
1137 std::vector<int> &captureVect,
1138 std::vector<int> &emissionVect,
1139 std::vector<double> &dRatedC)
1142 int cSize=dRatedC.size();
1143 std::vector<double> tempdRdC(cSize);
1145 for (i=0;i<cSize;++i)
1150 for (i=0;i<captureVect.size();++i)
1152 tempdRdC.assign(cSize,0.0);
1153 theReactions[captureVect[i]].getDRateDC(concs, constant_vec, tempdRdC);
1155 for (j=0;j<cSize;++j)
1157 dRatedC[j] -= tempdRdC[j];
1158 #ifdef Xyce_DEBUG_DEVICE
1164 for (i=0;i<emissionVect.size();++i)
1166 tempdRdC.assign(cSize,0.0);
1167 theReactions[emissionVect[i]].getDRateDC(concs, constant_vec, tempdRdC);
1169 for (j=0;j<cSize;++j)
1171 dRatedC[j] += tempdRdC[j];
1172 #ifdef Xyce_DEBUG_DEVICE
1203 std::vector<double> &constant_vec,
1204 std::vector<int> &captureVect,
1205 std::vector<int> &emissionVect,
1206 std::vector<double> &dRatedConst)
1209 int cSize=dRatedConst.size();
1210 std::vector<double> tempdRdConst(cSize);
1212 for (i=0;i<cSize;++i)
1217 for (i=0;i<captureVect.size();++i)
1219 tempdRdConst.assign(cSize,0.0);
1221 for (j=0;j<cSize;++j)
1223 theReactions[captureVect[i]].getDRateDConst(j, concs, constant_vec, tempdRdConst[j]);
1224 dRatedConst[j] -= tempdRdConst[j];
1225 #ifdef Xyce_DEBUG_DEVICE
1230 #ifdef Xyce_DEBUG_DEVICE
1238 for (i=0;i<emissionVect.size();++i)
1240 tempdRdConst.assign(cSize,0.0);
1242 for (j=0;j<cSize;++j)
1244 theReactions[emissionVect[i]].getDRateDConst(j, concs, constant_vec, tempdRdConst[j]);
1245 dRatedConst[j] += tempdRdConst[j];
1246 #ifdef Xyce_DEBUG_DEVICE
1251 #ifdef Xyce_DEBUG_DEVICE
1273 double sigma,
double hopDistance)
1284 int carrierIndex=-1;
1286 double thermalVelocity=0.0;
1288 if(carrierName ==
"E")
1291 thermalVelocity = 2.3e7;
1294 else if(carrierName ==
"H")
1297 thermalVelocity = 1.9e7;
1302 Report::DevelFatal() <<
"ReactionNetwork::setBourgoinCorbettCalc: Illegal carrier for BC enhancement: " << carrierName;
1305 species[speciesIndex].setBCEnhancedDiffusion(carrierIndex,sigma,thermalVelocity,hopDistance);