52 #include <Xyce_config.h>
55 #include <N_UTL_Misc.h>
56 #include <N_UTL_fwd.h>
61 #ifdef Xyce_DEBUG_DEVICE
68 #include <N_ERH_ErrorMgr.h>
106 std::vector< std::pair<int,double> > & products,
109 theReactants(reactants),
110 theProducts(products),
111 theRateConstant(rateConstant),
132 :theReactants(right.theReactants),
133 theProducts(right.theProducts),
134 concDependency(right.concDependency),
135 constDependency(right.constDependency),
136 theRateConstant(right.theRateConstant),
137 numconcs(right.numconcs),
138 numconsts(right.numconsts)
167 if (
this == &right)
return *
this;
169 #ifdef Xyce_DEBUG_DEVICE
170 Xyce::dout() <<
"We're doing an assignment of reaction! " << std::endl;
239 std::vector<std::pair<int,double> >::iterator iter;
240 std::vector<std::pair<int,double> >::iterator iter_end=
theReactants.end();
241 bool foundSpecies=
false;
246 for (iter=
theReactants.begin(); iter != iter_end; iter++)
248 if (iter->first == species)
250 iter->second += stoich;
258 theReactants.push_back(std::pair<int,double>(species,stoich));
272 std::vector<std::pair<int,double> >::iterator iter;
273 std::vector<std::pair<int,double> >::iterator iter_end=
theProducts.end();
274 bool foundSpecies=
false;
279 for (iter=
theProducts.begin(); iter != iter_end; iter++)
281 if (iter->first == species)
283 iter->second += stoich;
291 theProducts.push_back(std::pair<int,double>(species,stoich));
326 std::vector<double> &constants)
346 double t0 = 7.1428571428571427e-11;
348 double conc=0.0,hconc;
350 for (i=0;i<rSize;++i)
357 c=concentrations[species];
361 c=constants[-(species+1)];
367 reactionRate *= pow(c,stoich);
390 std::vector<double> &constants,
391 std::vector<double> &dratedc)
393 int cSize=concentrations.size();
410 for (i=0;i<cSize;++i)
421 for (i=0;i<rSize;++i)
427 c=concentrations[species];
431 c=constants[-(species+1)];
439 for (j=0;j<cSize;++j)
445 dratedc[j] *= stoich*pow(c,stoich-1.0);
449 dratedc[j] *= pow(c,stoich);
456 for (j=0;j<cSize;++j)
486 std::vector<double> &concentrations,
487 std::vector<double> &constants,
490 int cSize=constants.size();
512 for (i=0;i<rSize;++i)
518 c=concentrations[species];
522 c=constants[-(species+1)];
530 if (species < 0 && constNum ==-(species+1))
533 dratedc *= stoich*pow(c,stoich-1.0);
537 dratedc *= pow(c,stoich);
543 if (constNum !=-(species+1))
567 std::vector<double> &constants,
568 std::vector<double> &ddt)
578 reactionRate=
getRate(concentrations,constants);
582 for (i=0;i<rSize;++i)
588 ddt[species] -= stoich*reactionRate;
592 for (i=0;i<pSize;++i)
598 ddt[species] += stoich*reactionRate;
629 std::vector<double> &constants,
630 std::vector<std::vector<double> > &jac)
632 int cSize=concentrations.size();
637 std::vector<double> dratedc(cSize,0.0);
643 getDRateDC(concentrations, constants, dratedc);
649 for (i=0;i<rSize;++i)
655 for (j=0;j<cSize;++j)
659 jac[species][j] -= stoich*dratedc[j];
665 for (i=0;i<pSize;++i)
671 for (j=0;j<cSize;++j)
675 jac[species][j] += stoich*dratedc[j];
713 std::vector<double> &concentrations,
714 std::vector<double> &constants,
715 std::vector<double> &dFdConst)
717 int constSize=constants.size();
728 getDRateDConst(constantNumber,concentrations, constants, dratedc);
738 for (i=0;i<rSize;++i)
744 dFdConst[species] -= stoich*dratedc;
748 for (i=0;i<pSize;++i)
754 dFdConst[species] += stoich*dratedc;
791 double C0,
double t0,
double x0)
813 double N,
double Energy,
814 double C0,
double t0,
double x0)
836 std::vector<Specie> &C,
837 double C0,
double t0,
double x0)
859 std::vector<Specie> &C,
860 double bindingEnergy,
861 double gammaAB,
double gammaA,
862 double gammaB,
double concSi,
863 double C0,
double t0,
double x0)
873 bindingEnergy, gammaAB,gammaA,
889 std::vector<Specie> &C,
double sigma,
890 double C0,
double t0,
double x0)
932 std::vector<double> &concs,
933 std::vector<double> &constant_vec)
997 for (i=0;i<rSize;++i)
1025 for (i=0;i<rSize;++i)
1043 (
const std::vector<Specie> & species, std::ostream & os )
const
1046 int isize = theReactants.size();
1048 bool firstPrintDone=
false;
1049 for (i=0;i<isize;++i)
1051 int speciesIndex = theReactants[i].first;
1052 if (speciesIndex >= 0)
1054 if (firstPrintDone) os <<
" + ";
1055 double tmp = theReactants[i].second;
1057 os <<
" "<<tmp<<
" * ";
1058 os.setf(std::ios::right); os.width(3);
1059 os << species[speciesIndex].getName();
1061 firstPrintDone =
true;
1066 isize = theProducts.size();
1067 firstPrintDone=
false;
1068 for (i=0;i<isize;++i)
1070 int speciesIndex = theProducts[i].first;
1071 if (speciesIndex >= 0)
1073 if (firstPrintDone) os <<
" + ";
1074 double tmp = theProducts[i].second;
1076 os <<
" " << tmp <<
" * ";
1077 os.setf(std::ios::right); os.width(3);
1079 os << species[speciesIndex].getName();
1080 firstPrintDone =
true;
1084 os <<
" Rate Constant: ";
1085 os.precision(8); os.setf(std::ios::scientific);
1086 os << theRateConstant;
1089 os <<
"\n Dependencies:\n";
1090 for (
int j=0;j<concDependency.size();++j)
1092 os <<
" " << species[j].getName() <<
" = " << concDependency[j] << std::endl;