52 #include <Xyce_config.h>
57 #include <N_UTL_Misc.h>
58 #include <N_UTL_fwd.h>
63 #ifdef Xyce_DEBUG_DEVICE
70 #include <N_ERH_ErrorMgr.h>
105 std::vector< std::pair<int,double> > & products,
108 theReactants(reactants),
109 theProducts(products),
110 theRateConstant(rateConstant),
131 :theReactants(right.theReactants),
132 theProducts(right.theProducts),
133 concDependency(right.concDependency),
134 constDependency(right.constDependency),
135 theRateConstant(right.theRateConstant),
136 numconcs(right.numconcs),
137 numconsts(right.numconsts)
166 if (
this == &right)
return *
this;
168 #ifdef Xyce_DEBUG_DEVICE
169 Xyce::dout() <<
"We're doing an assignment of reaction! " << std::endl;
238 std::vector<std::pair<int,double> >::iterator iter;
239 std::vector<std::pair<int,double> >::iterator iter_end=
theReactants.end();
240 bool foundSpecies=
false;
245 for (iter=
theReactants.begin(); iter != iter_end; iter++)
247 if (iter->first == species)
249 iter->second += stoich;
257 theReactants.push_back(std::pair<int,double>(species,stoich));
271 std::vector<std::pair<int,double> >::iterator iter;
272 std::vector<std::pair<int,double> >::iterator iter_end=
theProducts.end();
273 bool foundSpecies=
false;
278 for (iter=
theProducts.begin(); iter != iter_end; iter++)
280 if (iter->first == species)
282 iter->second += stoich;
290 theProducts.push_back(std::pair<int,double>(species,stoich));
325 std::vector<double> &constants)
339 for (i=0;i<rSize;++i)
345 c=concentrations[species];
349 c=constants[-(species+1)];
354 reactionRate *= pow(c,stoich);
375 std::vector<double> &constants,
376 std::vector<double> &dratedc)
378 int cSize=concentrations.size();
395 for (i=0;i<cSize;++i)
406 for (i=0;i<rSize;++i)
412 c=concentrations[species];
416 c=constants[-(species+1)];
424 for (j=0;j<cSize;++j)
430 dratedc[j] *= stoich*pow(c,stoich-1.0);
434 dratedc[j] *= pow(c,stoich);
441 for (j=0;j<cSize;++j)
471 std::vector<double> &concentrations,
472 std::vector<double> &constants,
475 int cSize=constants.size();
497 for (i=0;i<rSize;++i)
503 c=concentrations[species];
507 c=constants[-(species+1)];
515 if (species < 0 && constNum ==-(species+1))
518 dratedc *= stoich*pow(c,stoich-1.0);
522 dratedc *= pow(c,stoich);
528 if (constNum !=-(species+1))
552 std::vector<double> &constants,
553 std::vector<double> &ddt)
563 reactionRate=
getRate(concentrations,constants);
567 for (i=0;i<rSize;++i)
573 ddt[species] -= stoich*reactionRate;
577 for (i=0;i<pSize;++i)
583 ddt[species] += stoich*reactionRate;
614 std::vector<double> &constants,
615 std::vector<std::vector<double> > &jac)
617 int cSize=concentrations.size();
622 std::vector<double> dratedc(cSize,0.0);
628 getDRateDC(concentrations, constants, dratedc);
634 for (i=0;i<rSize;++i)
640 for (j=0;j<cSize;++j)
644 jac[species][j] -= stoich*dratedc[j];
650 for (i=0;i<pSize;++i)
656 for (j=0;j<cSize;++j)
660 jac[species][j] += stoich*dratedc[j];
698 std::vector<double> &concentrations,
699 std::vector<double> &constants,
700 std::vector<double> &dFdConst)
702 int constSize=constants.size();
713 getDRateDConst(constantNumber,concentrations, constants, dratedc);
723 for (i=0;i<rSize;++i)
729 dFdConst[species] -= stoich*dratedc;
733 for (i=0;i<pSize;++i)
739 dFdConst[species] += stoich*dratedc;
776 double C0,
double t0,
double x0)
798 double N,
double Energy,
799 double C0,
double t0,
double x0)
821 std::vector<Specie> &C,
822 double C0,
double t0,
double x0)
844 std::vector<Specie> &C,
845 double bindingEnergy,
846 double gammaAB,
double gammaA,
847 double gammaB,
double concSi,
848 double C0,
double t0,
double x0)
858 bindingEnergy, gammaAB,gammaA,
936 for (i=0;i<rSize;++i)
964 for (i=0;i<rSize;++i)
982 (
const std::vector<Specie> & species, std::ostream & os )
const
985 int isize = theReactants.size();
987 bool firstPrintDone=
false;
988 for (i=0;i<isize;++i)
990 int speciesIndex = theReactants[i].first;
991 if (speciesIndex >= 0)
993 if (firstPrintDone) os <<
" + ";
994 double tmp = theReactants[i].second;
996 os <<
" "<<tmp<<
" * ";
997 os.setf(std::ios::right); os.width(3);
998 os << species[speciesIndex].getName();
1000 firstPrintDone =
true;
1005 isize = theProducts.size();
1006 firstPrintDone=
false;
1007 for (i=0;i<isize;++i)
1009 int speciesIndex = theProducts[i].first;
1010 if (speciesIndex >= 0)
1012 if (firstPrintDone) os <<
" + ";
1013 double tmp = theProducts[i].second;
1015 os <<
" " << tmp <<
" * ";
1016 os.setf(std::ios::right); os.width(3);
1018 os << species[speciesIndex].getName();
1019 firstPrintDone =
true;
1023 os <<
" Rate Constant: ";
1024 os.precision(8); os.setf(std::ios::scientific);
1025 os << theRateConstant;
1028 os <<
"\n Dependencies:\n";
1029 for (
int j=0;j<concDependency.size();++j)
1031 os <<
" " << species[j].getName() <<
" = " << concDependency[j] << std::endl;