39 ReactionRules::ReactionRules() :
40 skipUndeclaredSpecies(false),
41 skipUndeclaredThirdBodies(false),
50 std::vector<ReactionData*> m_rdata;
79 for (
size_t i = 0; i < m_rdata.size(); i++) {
90 map<string, double> bal, balr, balp;
98 for (
size_t index = 0; index < np; index++) {
102 kstoich = rdata.
pstoich[index];
104 for (
size_t m = 0; m < ph.
nElements(); m++) {
111 for (
size_t index = 0; index < rdata.
reactants.size(); index++) {
116 kstoich = rdata.
rstoich[index];
118 for (
size_t m = 0; m < ph.
nElements(); m++) {
126 map<string, double>::iterator b = bal.begin();
127 string msg =
"\n\tElement Reactants Products";
129 doublereal err, elemsum;
130 for (; b != bal.end(); ++b) {
131 elemsum = fabs(balr[b->first]) + fabs(balp[b->first]);
133 err = fabs(b->second/elemsum);
134 if (err > errorTolerance) {
136 msg +=
"\n\t"+b->first+
" "+
fp2str(balr[b->first])
137 +
" "+
fp2str(balp[b->first]);
142 msg =
"The following reaction is unbalanced:\n\t"
143 + rdata.
equation +
"\n" + msg +
"\n";
149 std::string default_phase, std::vector<size_t>& spnum,
163 rptype =
"reactants";
174 vector<string> key, val;
180 doublereal ord, stch;
182 map<string, size_t> speciesMap;
183 for (
size_t n = 0; n < key.size(); n++) {
193 if (rules.skipUndeclaredSpecies) {
197 "Undeclared reactant or product species "+sp);
209 spnum.push_back(isp);
211 stoich.push_back(stch);
212 ord = doublereal(stch);
213 order.push_back(ord);
219 speciesMap[sp] = order.size();
225 if (rp == 1 && rxn.
hasChild(
"order")) {
226 vector<XML_Node*> ord;
229 for (
size_t nn = 0; nn < ord.size(); nn++) {
231 string sp = oo[
"species"];
232 size_t loc = speciesMap[sp];
235 "reaction order specified for non-reactant: "
240 "reaction order must be non-negative");
245 order[loc-1] = forder;
257 doublereal& A, doublereal& b, doublereal& E)
260 if (node[
"name"] ==
"k0") {
262 }
else if (node[
"name"] ==
"kHigh") {
272 E =
getFloat(node,
"E",
"actEnergy");
294 ReactionData& r, doublereal& A, doublereal& b, doublereal& E)
297 size_t k, klocal, not_surf = 0;
308 string spname = node[
"species"];
318 for (
size_t n = 0; n < nr; n++) {
343 if (ispPhaseIndex == np) {
357 "reaction probabilities can only be used in "
358 "reactions with exactly 1 gas/liquid species.");
362 A = 0.25 *
getFloat(node,
"A",
"toSI") * cbar * f;
364 E =
getFloat(node,
"E",
"actEnergy");
368 static void getCoverageDependence(
const XML_Node& node,
369 thermo_t& surfphase, ReactionData& rdata)
371 vector<XML_Node*> cov;
372 node.getChildren(
"coverage", cov);
373 size_t k, nc = cov.size();
377 for (
size_t n = 0; n < nc; n++) {
378 const XML_Node& cnode = *cov[n];
379 spname = cnode[
"species"];
380 k = surfphase.speciesIndex(spname);
381 rdata.cov.push_back(doublereal(k));
382 rdata.cov.push_back(
getFloat(cnode,
"a"));
383 rdata.cov.push_back(
getFloat(cnode,
"m"));
384 e =
getFloat(cnode,
"e",
"actEnergy");
401 string type = f[
"type"];
405 int np =
static_cast<int>(p.size());
406 for (
int n = 0; n < np; n++) {
409 if (type ==
"Troe") {
412 }
else if (np == 3) {
415 throw CanteraError(
"getFalloff()",
"Troe parameterization is specified by number of parameters, "
416 +
int2str(np) +
", is not equal to 3 or 4");
418 }
else if (type ==
"SRI") {
422 throw CanteraError(
"getFalloff()",
"SRI5 m_c parameter is less than zero: " +
fp2str(c[2]));
425 throw CanteraError(
"getFalloff()",
"SRI5 m_d parameter is less than zero: " +
fp2str(c[3]));
427 }
else if (np == 3) {
430 throw CanteraError(
"getFalloff()",
"SRI3 m_c parameter is less than zero: " +
fp2str(c[2]));
433 throw CanteraError(
"getFalloff()",
"SRI parameterization is specified by number of parameters, "
434 +
int2str(np) +
", is not equal to 3 or 5");
451 vector<string> key, val;
455 for (
size_t n = 0; n < key.size(); n++) {
460 }
else if (!rules.skipUndeclaredThirdBodies) {
461 throw CanteraError(
"getEfficiencies",
"Encountered third-body "
462 "efficiency for undefined species \"" + nm +
"\"\n"
473 for (
size_t m = 0; m < kf.
nChildren(); m++) {
475 double p =
getFloat(node,
"P",
"toSI");
479 rate[0] =
getFloat(node,
"A",
"toSI");
491 rdata.
chebDegreeP = atoi(coeffs[
"degreeP"].c_str());
492 rdata.
chebDegreeT = atoi(coeffs[
"degreeT"].c_str());
497 string type = kf.
attrib(
"type");
502 if (type ==
"ExchangeCurrentDensity") {
503 rdata.
rateCoeffType = EXCHANGE_CURRENT_REACTION_RATECOEFF_TYPE;
504 }
else if (type ==
"Arrhenius") {
507 throw CanteraError(
"getRateCoefficient",
"Unknown type: " + type);
511 for (
size_t m = 0; m < kf.
nChildren(); m++) {
513 string nm = c.
name();
516 if (nm ==
"Arrhenius") {
518 if (c[
"type"] ==
"stick") {
519 getStick(c, kin, rdata, coeff[0], coeff[1], coeff[2]);
531 getCoverageDependence(c,
535 if (coeff[0] < 0.0 && !rules.allowNegativeA) {
537 "negative A coefficient for reaction "+
int2str(rdata.
number));
539 }
else if (nm ==
"Arrhenius_ExchangeCurrentDensity") {
543 rdata.
rateCoeffType = EXCHANGE_CURRENT_REACTION_RATECOEFF_TYPE;
544 }
else if (nm ==
"falloff") {
546 }
else if (nm ==
"efficiencies") {
548 }
else if (nm ==
"electrochem") {
570 std::map<int, doublereal>& r2)
573 map<int, doublereal>::const_iterator b = r1.begin(), e = r1.end();
575 doublereal ratio = 0.0;
576 if (r1[k1] == 0.0 || r2[k1] == 0.0) {
579 ratio = r2[k1]/r1[k1];
581 for (; b != e; ++b) {
583 if (r1[k1] == 0.0 || r2[k1] == 0.0) {
586 if (fabs(r2[k1]/r1[k1] - ratio) > 1.e-8) {
595 if (r1[k1] == 0.0 || r2[-k1] == 0.0) {
598 ratio = r2[-k1]/r1[k1];
600 for (; b != e; ++b) {
602 if (r1[k1] == 0.0 || r2[-k1] == 0.0) {
605 if (fabs(r2[-k1]/r1[k1] - ratio) > 1.e-8) {
617 if (r.
name() !=
"reaction") {
619 " expected xml node reaction, got " + r.
name());
635 rules.allowNegativeA = (r.
hasAttrib(
"negative_A")) ? 1 : 0;
642 rdata.
equation = (r.
hasChild(
"equation")) ? r(
"equation") :
"<no equation>";
643 for (
size_t nn = 0; nn < rdata.
equation.size(); nn++) {
646 }
else if (rdata.
equation[nn] ==
']') {
667 string isrev = r[
"reversible"];
668 rdata.
reversible = (isrev ==
"yes" || isrev ==
"true");
679 "reaction orders may only be given for "
680 "irreversible reactions");
691 for (
size_t i = 0; i < rdata.
products.size(); i++) {
692 doublereal po = rdata.
porder[i];
694 doublereal chk = po - 1.0 * int(po);
705 for (
size_t i = 0; i < rdata.
reactants.size(); i++) {
706 doublereal ro = rdata.
rorder[i];
708 doublereal chk = ro - 1.0 * int(ro);
726 string typ = r[
"type"];
727 if (typ ==
"falloff") {
730 }
else if (typ ==
"chemAct") {
733 }
else if (typ ==
"threeBody") {
735 }
else if (typ ==
"plog") {
737 }
else if (typ ==
"chebyshev") {
739 }
else if (typ ==
"surface") {
741 }
else if (typ ==
"edge") {
743 }
else if (typ !=
"") {
744 throw CanteraError(
"installReaction",
"Unknown reaction type: " + typ);
756 unsigned long int participants = 0;
757 for (
size_t nn = 0; nn < rdata.reactants.size(); nn++) {
758 rdata.net_stoich[-1 - int(rdata.reactants[nn])] -= rdata.rstoich[nn];
759 participants += rdata.reactants[nn];
761 for (
size_t nn = 0; nn < rdata.products.size(); nn++) {
762 rdata.net_stoich[int(rdata.products[nn])+1] += rdata.pstoich[nn];
763 participants += 1000000 * rdata.products[nn];
767 for (
size_t mm = 0; mm < related.size(); mm++) {
769 if (rdata.reactants.size() != other.
reactants.size()) {
773 }
else if (rdata.duplicate && other.
duplicate) {
779 }
else if (c < 0.0 && !rdata.reversible && !other.
reversible) {
784 bool thirdBodyOk =
true;
786 if (rdata.efficiency(k) * other.
efficiency(k) != 0.0) {
794 string msg = string(
"Undeclared duplicate reactions detected: \n")
796 +
"\nReaction "+
int2str(iRxn+1)+
": "+rdata.equation+
"\n";
813 std::string default_phase,
bool check_for_duplicates)
817 vector<XML_Node*> rarrays;
828 int na =
static_cast<int>(rarrays.size());
833 for (
int n = 0; n < na; n++) {
863 string sskip = sk[
"species"];
864 if (sskip ==
"undeclared") {
865 rxnrule.skipUndeclaredSpecies =
true;
867 if (sk[
"third_bodies"] ==
"undeclared") {
868 rxnrule.skipUndeclaredThirdBodies =
true;
877 vector<XML_Node*> incl;
879 int ninc =
static_cast<int>(incl.size());
881 vector<XML_Node*> allrxns;
883 nrxns =
static_cast<int>(allrxns.size());
886 for (i = 0; i < nrxns; i++) {
890 default_phase, rxnrule, check_for_duplicates)) {
896 for (
int nii = 0; nii < ninc; nii++) {
898 string imin = ii[
"min"];
899 string imax = ii[
"max"];
903 iwild = imin.find(
"*");
905 imin = imin.substr(0,iwild);
910 for (i = 0; i < nrxns; i++) {
916 rxid = rxid.substr(0,iwild);
923 if ((rxid >= imin) && (rxid <= imax)) {
925 default_phase, rxnrule, check_for_duplicates)) {
957 string owning_phase = phase[
"id"];
959 bool check_for_duplicates =
false;
962 if (d[
"reactions"] ==
"yes") {
963 check_for_duplicates =
true;
972 vector<string> phase_ids;
977 phase_ids.push_back(owning_phase);
979 int np =
static_cast<int>(phase_ids.size());
980 int nt =
static_cast<int>(th.size());
988 for (
int n = 0; n < np; n++) {
989 phase_id = phase_ids[n];
994 for (
int m = 0; m < nt; m++) {
995 if (th[m]->
id() == phase_id) {
1004 msg +=
" "+th[m]->id();
1008 "phase "+phase_id+
" not found. Supplied phases are:"+msg);
1040 vector<ThermoPhase*> phases(1);
these are all used to check for duplicate reactions
XML_Node * get_XML_Node(const std::string &file_ID, XML_Node *root)
This routine will locate an XML node in either the input XML tree or in another input file specified ...
doublereal fpValue(const std::string &val)
Translate a string into one doublereal value.
double efficiency(size_t k) const
Get the actual third-body efficiency for species k
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
const int PLOG_RXN
A pressure-dependent rate expression consisting of several Arrhenius rate expressions evaluated at di...
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
void checkRxnElementBalance(Kinetics &kin, const ReactionData &rdata, doublereal errorTolerance)
This function will check a specific reaction to see if the elements balance.
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase, assuming an ideal solution model (see Thermodynamic Properties and class SurfPhase).
vector_fp falloffParameters
Values used in the falloff parameterization.
std::multimap< double, vector_fp > plogParameters
Arrhenius parameters for P-log reactions.
size_t nElements() const
Number of elements.
double chebPmin
Minimum pressure for Chebyshev fit.
int reactionType
Type of the reaction.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
thermo_t & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism...
vector_fp auxRateCoeffParameters
Vector of auxiliary rate coefficient parameters.
bool duplicate
True if the current reaction is marked as duplicate.
const size_t npos
index returned by functions to indicate "no position"
int falloffType
Type of falloff parameterization to use.
const int EDGE_RXN
A reaction occurring at a one-dimensional interface between two surface phases.
const int CHEBYSHEV_RXN
A general pressure-dependent reaction where k(T,P) is defined in terms of a bivariate Chebyshev polyn...
doublereal beta
for electrochemical reactions
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
vector_fp pstoich
Product stoichiometric coefficients, in the order given by products.
static void getStick(const XML_Node &node, Kinetics &kin, ReactionData &r, doublereal &A, doublereal &b, doublereal &E)
getStick() processes the XML element called Stick that specifies the sticking coefficient reaction...
std::string kineticsSpeciesName(size_t k) const
Return the name of the kth species in the kinetics manager.
vector_fp porder
Reaction order of the reverse reaction with respect to each product species, in the order given by pr...
Class XML_Node is a tree-based representation of the contents of an XML file.
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
doublereal getFloat(const Cantera::XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
bool validate
Perform validation of the rate coefficient data.
static void getArrhenius(const XML_Node &node, int &labeled, doublereal &A, doublereal &b, doublereal &E)
getArrhenius() parses the xml element called Arrhenius.
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, HTML_logs (see Input File Handling, Diagnostic Output, Writing messages to the screen and Writing HTML Logfiles).
const int CHEMACT_RXN
A chemical activation reaction.
bool isReversibleWithFrac
Some reactions can be elementary reactions but have fractional stoichiometries with respect to some p...
vector_fp rateCoeffParameters
Vector of rate coefficient parameters.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
std::map< size_t, doublereal > thirdBodyEfficiencies
Map of species index to third body efficiency.
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
ThermoPhase thermo_t
typedef for the ThermoPhase class
bool installReactionArrays(const XML_Node &p, Kinetics &kin, std::string default_phase, bool check_for_duplicates)
Install information about reactions into the kinetics object, kin.
Base class for a phase with thermodynamic properties.
const int cSurf
A surface phase. Used by class SurfPhase.
const int FALLOFF_RXN
The general form for an association or dissociation reaction, with a pressure-dependent rate...
virtual void init()
Prepare the class for the addition of reactions.
size_t chebDegreeT
Degree of Chebyshev fit in T.
Contains const definitions for types of species reference-state thermodynamics managers (see Species ...
std::string equation
The reaction equation. Used only for display purposes.
bool installReaction(int i, const XML_Node &r, Kinetics &kin, std::string default_phase, ReactionRules &rules, bool validate_rxn)
Install an individual reaction into a kinetics manager.
std::vector< size_t > products
Indices of product species.
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
size_t surfacePhaseIndex()
This returns the integer index of the phase which has ThermoPhase type cSurf.
bool importPhase(XML_Node &phase, ThermoPhase *th, SpeciesThermoFactory *spfactory)
Import a phase information into an empty thermophase object.
double chebPmax
Maximum pressure for Chebyshev fit.
bool getReagents(const XML_Node &rxn, Kinetics &kin, int rp, std::string default_phase, std::vector< size_t > &spnum, vector_fp &stoich, vector_fp &order, const ReactionRules &rules)
Get the reactants or products of a reaction.
bool importKinetics(const XML_Node &phase, std::vector< ThermoPhase * > th, Kinetics *k)
Import a reaction mechanism for a phase or an interface.
std::map< unsigned long int, std::vector< size_t > > m_participants
Map of (key indicating participating species) to reaction numbers Used to speed up duplicate reaction...
doublereal isDuplicateReaction(std::map< int, doublereal > &r1, std::map< int, doublereal > &r2)
This function returns a ratio if two reactions are duplicates of one another, and 0...
static void getFalloff(const XML_Node &f, ReactionData &rdata)
Get falloff parameters for a reaction.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
std::string name() const
Returns the name of the XML node.
thermo_t & speciesPhase(const std::string &nm)
This function looks up the name of a species and returns a reference to the ThermoPhase object of the...
This file defines some constants used to specify reaction types.
Classes providing support for XML data files.
Public interface for kinetics managers.
int number
Index of this reaction within the mechanism.
Rules for parsing and installing reactions.
doublereal default_3b_eff
The default third body efficiency for species not listed in thirdBodyEfficiencies.
size_t chebDegreeP
Degree of Chebyshev fit in P.
Intermediate class which stores data about a reaction and its rate parameterization before adding the...
std::string id() const
Return the string id for the phase.
Base class for exceptions thrown by Cantera classes.
const int SURFACE_RXN
A reaction occurring on a surface.
int getPairs(const Cantera::XML_Node &node, std::vector< std::string > &key, std::vector< std::string > &val)
This function interprets the value portion of an XML element as a series of "Pairs" separated by whit...
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
const int cEdge
An edge between two 2D surfaces.
const int THREE_BODY_RXN
A reaction that requires a third-body collision partner.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
std::map< int, doublereal > net_stoich
Net stoichiometric coefficients for participating species.
std::vector< size_t > reactants
Indices of reactant species.
vector_fp rstoich
Reactant stoichiometric coefficients, in the order given by reactants.
size_t nSpecies() const
Returns the number of species in the phase.
bool reversible
True if the current reaction is reversible. False otherwise.
int rateCoeffType
Type of the rate coefficient for the forward rate constant.
Definitions of global routines for the importing of data from XML files (see Input File Handling)...
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
#define AssertTrace(expr)
Assertion must be true or an error is thrown.
Header for factory to build instances of classes that manage the standard-state thermodynamic propert...
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
void getStringArray(const Cantera::XML_Node &node, std::vector< std::string > &v)
This function interprets the value portion of an XML element as a string.
virtual int eosType() const
Equation of state type flag.
size_t speciesPhaseIndex(size_t k)
This function takes as an argument the kineticsSpecies index (i.e., the list index in the list of spe...
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
const int ELEMENTARY_RXN
A reaction with a rate coefficient that depends only on temperature.
Contains declarations for string manipulation functions within Cantera.
bool global
True for "global" reactions which do not follow elementary mass action kinetics, i.e.
std::string elementName(size_t m) const
Name of the element with index m.
static void getEfficiencies(const XML_Node &eff, Kinetics &kin, ReactionData &rdata, const ReactionRules &rules)
Get the enhanced collision efficiencies.
void getRateCoefficient(const XML_Node &kf, Kinetics &kin, ReactionData &rdata, const ReactionRules &rules)
Read the rate coefficient data from the XML file.
virtual void addReaction(ReactionData &r)
Add a single reaction to the mechanism.
XML_Node & root() const
Return the root of the current XML_Node tree.
virtual void finalize()
Finish adding reactions and prepare for use.
Header file for class ThermoPhase, the base class for phases with thermodynamic properties, and the text for the Module thermoprops (see Thermodynamic Properties and class ThermoPhase).
virtual void addPhase(thermo_t &thermo)
Add a phase to the kinetics manager object.
XML_Node * parent() const
Returns a pointer to the parent node of the current node.
double chebTmax
Maximum temperature for Chebyshev fit.
vector_fp chebCoeffs
Chebyshev coefficients. length chebDegreeT * chebDegreeP.
vector_fp rorder
Reaction order with respect to each reactant species, in the order given by reactants.
XML_Node * get_XML_NameID(const std::string &nameTarget, const std::string &file_ID, XML_Node *root)
This routine will locate an XML node in either the input XML tree or in another input file specified ...
size_t getFloatArray(const Cantera::XML_Node &node, std::vector< doublereal > &v, const bool convert, const std::string &unitsString, const std::string &nodeName)
This function reads the current node or a child node of the current node with the default name...
Declarations for the EdgePhase ThermoPhase object, which models the interface between two surfaces (s...
size_t nChildren(bool discardComments=false) const
Return the number of children.
void getChildren(const std::string &name, std::vector< XML_Node * > &children) const
Get a vector of pointers to XML_Node containing all of the children of the current node which matches...
size_t phaseIndex(const std::string &ph)
Return the phase index of a phase in the list of phases defined within the object.
bool hasAttrib(const std::string &a) const
Tests whether the current node has an attribute with a particular name.
double chebTmin
Minimum temperature for Chebyshev fit.