28 ReactionRules::ReactionRules() :
29 skipUndeclaredSpecies(false),
30 skipUndeclaredThirdBodies(false),
39 "Kinetics::checkReactionBalance. To be removed after Cantera 2.2.");
42 map<string, double> bal, balr, balp;
49 for (
size_t index = 0; index < np; index++) {
55 for (
size_t m = 0; m < ph.
nElements(); m++) {
60 for (
size_t index = 0; index < rdata.
reactants.size(); index++) {
66 for (
size_t m = 0; m < ph.
nElements(); m++) {
72 map<string, double>::iterator b = bal.begin();
73 string msg =
"\n\tElement Reactants Products";
75 doublereal err, elemsum;
76 for (; b != bal.end(); ++b) {
77 elemsum = fabs(balr[b->first]) + fabs(balp[b->first]);
79 err = fabs(b->second/elemsum);
80 if (err > errorTolerance) {
82 msg +=
"\n\t"+b->first+
" "+
fp2str(balr[b->first])
83 +
" "+
fp2str(balp[b->first]);
88 msg =
"The following reaction is unbalanced:\n\t"
89 + rdata.
equation +
"\n" + msg +
"\n";
95 std::string default_phase, std::vector<size_t>& spnum,
99 warn_deprecated(
"getReagents",
"Now handled through newReaction() and its "
100 "support functions. To be removed after Cantera 2.2.");
110 rptype =
"reactants";
121 std::vector<string> key, val;
127 doublereal ord, stch;
129 map<string, size_t> speciesMap;
130 for (
size_t n = 0; n < key.size(); n++) {
140 if (rules.skipUndeclaredSpecies) {
144 "Undeclared reactant or product species " + spName);
156 spnum.push_back(isp);
158 stoich.push_back(stch);
159 ord = doublereal(stch);
160 order.push_back(ord);
165 speciesMap[spName] = order.size();
172 if (rp == 1 && rxn.
hasChild(
"order")) {
173 std::vector<XML_Node*> ord = rxn.
getChildren(
"order");
175 for (
size_t nn = 0; nn < ord.size(); nn++) {
177 string sp = oo[
"species"];
178 size_t loc = speciesMap[sp];
181 "reaction order specified for non-reactant: "
186 "reaction order must be non-negative");
191 order[loc-1] = forder;
204 doublereal& A, doublereal& b, doublereal& E)
206 if (node[
"name"] ==
"k0") {
208 }
else if (node[
"name"] ==
"kHigh") {
218 E =
getFloat(node,
"E",
"actEnergy");
241 ReactionData& r, doublereal& A, doublereal& b, doublereal& E)
244 size_t k, klocal, not_surf = 0;
255 string spname = node[
"species"];
265 for (
size_t n = 0; n < nr; n++) {
288 if (ispPhaseIndex == np) {
301 "reaction probabilities can only be used in "
302 "reactions with exactly 1 gas/liquid species.");
306 A = 0.25 *
getFloat(node,
"A",
"toSI") * cbar * f;
308 E =
getFloat(node,
"E",
"actEnergy");
331 vector<XML_Node*> cov = node.
getChildren(
"coverage");
332 size_t k, nc = cov.size();
336 for (
size_t n = 0; n < nc; n++) {
338 spname = cnode[
"species"];
340 rdata.
cov.push_back(doublereal(k));
343 e =
getFloat(cnode,
"e",
"actEnergy");
361 string type = f[
"type"];
365 size_t np = p.size();
366 for (
size_t n = 0; n < np; n++) {
369 if (type ==
"Troe") {
370 if (np == 3 || np == 4) {
373 throw CanteraError(
"getFalloff()",
"Troe parameterization is specified by number of parameters, "
374 +
int2str(np) +
", is not equal to 3 or 4");
376 }
else if (type ==
"SRI") {
377 if (np == 3 || np == 5) {
380 throw CanteraError(
"getFalloff()",
"SRI parameterization is specified by number of parameters, "
381 +
int2str(np) +
", is not equal to 3 or 5");
399 vector<string> key, val;
403 for (
size_t n = 0; n < key.size(); n++) {
408 }
else if (!rules.skipUndeclaredThirdBodies) {
409 throw CanteraError(
"getEfficiencies",
"Encountered third-body "
410 "efficiency for undefined species \"" + nm +
"\"\n"
419 warn_deprecated(
"getRateCoefficent",
"Now handled through newReaction() "
420 "and its support functions. To be removed after Cantera 2.2.");
423 for (
size_t m = 0; m < kf.
nChildren(); m++) {
425 double p =
getFloat(node,
"P",
"toSI");
429 rate[0] =
getFloat(node,
"A",
"toSI");
441 rdata.
chebDegreeP = atoi(coeffs[
"degreeP"].c_str());
442 rdata.
chebDegreeT = atoi(coeffs[
"degreeT"].c_str());
447 string type = kf.
attrib(
"type");
452 if (type ==
"ExchangeCurrentDensity") {
453 rdata.
rateCoeffType = EXCHANGE_CURRENT_REACTION_RATECOEFF_TYPE;
454 }
else if (type ==
"Arrhenius") {
457 throw CanteraError(
"getRateCoefficient",
"Unknown type: " + type);
461 for (
size_t m = 0; m < kf.
nChildren(); m++) {
463 string nm = c.
name();
466 if (nm ==
"Arrhenius") {
468 if (c[
"type"] ==
"stick") {
469 getStick(c, kin, rdata, coeff[0], coeff[1], coeff[2]);
485 if (coeff[0] < 0.0 && !rules.allowNegativeA) {
487 "negative A coefficient for reaction "+
int2str(rdata.
number));
489 }
else if (nm ==
"Arrhenius_ExchangeCurrentDensity") {
493 rdata.
rateCoeffType = EXCHANGE_CURRENT_REACTION_RATECOEFF_TYPE;
494 }
else if (nm ==
"falloff") {
496 }
else if (nm ==
"efficiencies") {
498 }
else if (nm ==
"electrochem") {
520 std::map<int, doublereal>& r2)
523 "Kinetics::checkDuplicateStoich. To be removed after Cantera 2.2.");
524 map<int, doublereal>::const_iterator b = r1.begin(), e = r1.end();
527 doublereal ratio = 0.0;
528 if (r1[k1] && r2[k1]) {
529 ratio = r2[k1]/r1[k1];
531 bool different =
false;
532 for (; b != e; ++b) {
534 if (!r1[k1] || !r2[k1] || fabs(r2[k1]/r1[k1] - ratio) > 1.e-8) {
547 if (r1[k1] == 0.0 || r2[-k1] == 0.0) {
550 ratio = r2[-k1]/r1[k1];
552 for (; b != e; ++b) {
554 if (!r1[k1] || !r2[-k1] || fabs(r2[-k1]/r1[k1] - ratio) > 1.e-8) {
562 std::string default_phase,
bool check_for_duplicates)
573 vector<XML_Node*> rarrays = p.
getChildren(
"reactionArray");
574 if (rarrays.empty()) {
578 for (
size_t n = 0; n < rarrays.size(); n++) {
607 if (sk[
"species"] ==
"undeclared") {
610 if (sk[
"third_bodies"] ==
"undeclared") {
619 vector<XML_Node*> incl = rxns.
getChildren(
"include");
620 vector<XML_Node*> allrxns = rdata->
getChildren(
"reaction");
623 for (
size_t i = 0; i < allrxns.size(); i++) {
628 for (
size_t nii = 0; nii < incl.size(); nii++) {
630 string imin = ii[
"min"];
631 string imax = ii[
"max"];
635 iwild = imin.find(
"*");
637 imin = imin.substr(0,iwild);
642 for (
size_t i = 0; i < allrxns.size(); i++) {
648 rxid = rxid.substr(0,iwild);
655 if ((rxid >= imin) && (rxid <= imax)) {
665 if (check_for_duplicates) {
687 string owning_phase = phase[
"id"];
689 bool check_for_duplicates =
false;
693 if (d[
"reactions"] ==
"yes") {
694 check_for_duplicates =
true;
704 vector<string> phase_ids;
709 phase_ids.push_back(owning_phase);
711 int np =
static_cast<int>(phase_ids.size());
712 int nt =
static_cast<int>(th.size());
720 for (
int n = 0; n < np; n++) {
721 phase_id = phase_ids[n];
726 for (
int m = 0; m < nt; m++) {
727 if (th[m]->
id() == phase_id) {
736 msg +=
" "+th[m]->id();
740 "phase "+phase_id+
" not found. Supplied phases are:"+msg);
771 std::vector<ThermoPhase*> phases(1);
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.
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.
static void getCoverageDependence(const XML_Node &node, thermo_t &surfphase, ReactionData &rdata)
Read the XML data concerning the coverage dependence of an interfacial reaction.
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.
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.
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 gas-phase pressure-dependent reaction where k(T,P) is defined in terms of a bivariate Cheby...
vector_fp cov
Adjustments to the Arrhenius rate expression dependent on surface species coverages.
doublereal beta
Forward value of the apparent Electrochemical transfer coefficient.
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.
Class XML_Node is a tree-based representation of the contents of an XML file.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
static void getArrhenius(const XML_Node &node, int &labeled, doublereal &A, doublereal &b, doublereal &E)
getArrhenius() parses the XML element called Arrhenius.
const int CHEMACT_RXN
A chemical activation reaction.
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.
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 a gas-phase 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.
std::string equation
The reaction equation. Used only for display purposes.
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.
virtual std::pair< size_t, size_t > checkDuplicates(bool throw_err=true) const
Check for duplicate reactions.
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.
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...
Public interface for kinetics managers.
int number
Index of this reaction within the mechanism.
int getPairs(const 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...
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.
shared_ptr< Reaction > newReaction(const XML_Node &rxn_node)
Create a new Reaction object for the reaction defined in rxn_node
const int SURFACE_RXN
A reaction occurring on a surface.
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 gas-phase 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::vector< size_t > reactants
Indices of reactant species.
vector_fp rstoich
Reactant stoichiometric coefficients, in the order given by reactants.
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.
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 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...
size_t getFloatArray(const 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...
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
const int ELEMENTARY_RXN
A reaction with a rate coefficient that depends only on temperature and voltage that also obeys mass-...
Contains declarations for string manipulation functions within Cantera.
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
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.
doublereal fp_value() const
Return the value of an XML node as a single double.
XML_Node & root() const
Return the root of the current XML_Node tree.
virtual void finalize()
Finish adding reactions and prepare for use.
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.
void skipUndeclaredThirdBodies(bool skip)
Determine behavior when adding a new reaction that contains third-body efficiencies for species not d...
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 ...
virtual void addReaction(ReactionData &r)
Add a single reaction to the mechanism.
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.
void skipUndeclaredSpecies(bool skip)
Determine behavior when adding a new reaction that contains species not defined in any of the phases ...
double chebTmin
Minimum temperature for Chebyshev fit.