19 Kinetics::Kinetics() :
26 m_skipUndeclaredSpecies(false),
27 m_skipUndeclaredThirdBodies(false)
61 m_rxntype = right.m_rxntype;
73 m_rgroups = right.m_rgroups;
74 m_pgroups = right.m_pgroups;
142 size_t ns = tpVector.size();
145 " Number of ThermoPhase objects arent't the same");
147 for (
size_t i = 0; i < ns; i++) {
150 if (ntp->
id() != otp->
id()) {
152 " id() of the ThermoPhase objects isn't the same");
156 " eosType() of the ThermoPhase objects isn't the same");
160 " Number of ThermoPhase objects isn't the same");
171 std::map<size_t, std::vector<size_t> > participants;
172 std::vector<std::map<int, double> > net_stoich;
176 unsigned long int key = 0;
178 net_stoich.push_back(std::map<int, double>());
179 std::map<int, double>& net = net_stoich.back();
180 for (Composition::const_iterator iter = R.
reactants.begin();
185 net[-1 -k] -= iter->second;
187 for (Composition::const_iterator iter = R.
products.begin();
192 net[1+k] += iter->second;
196 vector<size_t>& related = participants[key];
198 for (
size_t m = 0; m < related.size(); m++) {
214 bool thirdBodyOk =
true;
230 bool thirdBodyOk =
true;
245 string msg = string(
"Undeclared duplicate reactions detected:\n")
250 return make_pair(i,m);
253 participants[key].push_back(i);
259 std::map<int, double>& r2)
const
261 map<int, doublereal>::const_iterator b = r1.begin(), e = r1.end();
264 doublereal ratio = 0.0;
265 if (r1[k1] && r2[k1]) {
266 ratio = r2[k1]/r1[k1];
268 bool different =
false;
269 for (; b != e; ++b) {
271 if (!r1[k1] || !r2[k1] || fabs(r2[k1]/r1[k1] - ratio) > 1.e-8) {
284 if (r1[k1] == 0.0 || r2[-k1] == 0.0) {
287 ratio = r2[-k1]/r1[k1];
289 for (; b != e; ++b) {
291 if (!r1[k1] || !r2[-k1] || fabs(r2[-k1]/r1[k1] - ratio) > 1.e-8) {
302 for (Composition::const_iterator iter = R.
products.begin();
307 double stoich = iter->second;
308 for (
size_t m = 0; m < ph.
nElements(); m++) {
313 for (Composition::const_iterator iter = R.
reactants.begin();
318 double stoich = iter->second;
319 for (
size_t m = 0; m < ph.
nElements(); m++) {
326 for (Composition::iterator iter = balr.begin();
329 const string& elem = iter->first;
330 double elemsum = balr[elem] + balp[elem];
331 double elemdiff = fabs(balp[elem] - balr[elem]);
332 if (elemsum > 0.0 && elemdiff/elemsum > 1e-4) {
334 msg +=
" " + elem +
" " +
fp2str(balr[elem]) +
335 " " +
fp2str(balp[elem]) +
"\n";
339 msg =
"The following reaction is unbalanced: " + R.
equation() +
"\n" +
340 " Element Reactants Products\n" + msg;
346 doublereal* phase_data)
348 for (
size_t n = 0; n <
nPhases(); n++) {
352 data +
m_start[n] + nsp, phase_data);
356 throw CanteraError(
"Kinetics::selectPhase",
"Phase not found.");
361 for (
size_t n =
m_start.size()-1; n !=
npos; n--) {
371 for (
size_t n = 0; n <
m_thermo.size(); n++) {
383 const std::string& ph)
const
389 for (
size_t n = 0; n <
m_thermo.size(); n++) {
407 for (
size_t n = 0; n < np; n++) {
413 throw CanteraError(
"speciesPhase",
"unknown species "+nm);
419 for (
size_t n =
m_start.size()-1; n !=
npos; n--) {
458 fill(deltaProp, deltaProp +
m_ii, 0.0);
468 fill(deltaProp, deltaProp +
m_ii, 0.0);
480 fill(cdot, cdot +
m_kk, 0.0);
494 fill(ddot, ddot +
m_kk, 0.0);
505 fill(net, net +
m_kk, 0.0);
535 if (
type() == cEdgeKinetics) {
537 }
else if (
type() == cInterfaceKinetics) {
540 if (thermo.
eosType() == ptype) {
551 for (
size_t n = 0; n <
nPhases(); n++) {
552 size_t nsp =
m_thermo[n]->nSpecies();
563 std::vector<size_t> rk;
564 for (
size_t n = 0; n < r.
reactants.size(); n++) {
566 size_t ns = (size_t) nsFlt;
567 if ((
double) ns != nsFlt) {
568 ns = std::max<size_t>(ns, 1);
573 for (
size_t m = 0; m < ns; m++) {
579 std::vector<size_t> pk;
580 for (
size_t n = 0; n < r.
products.size(); n++) {
582 size_t ns = (size_t) nsFlt;
583 if ((
double) ns != nsFlt) {
584 ns = std::max<size_t>(ns, 1);
589 for (
size_t m = 0; m < ns; m++) {
595 std::vector<size_t> extReactants = r.
reactants;
612 for (
size_t kk = 0; kk < r.
reactants.size(); kk++) {
621 for (
size_t k = 0; k < nsp; k++) {
624 if (kHandled[k] == 0) {
627 extReactants.push_back(k);
628 extROrder.push_back(of);
629 extRStoich.push_back(0.0);
649 m_rfn.push_back(0.0);
664 if (r->reversible && !r->orders.empty()) {
665 throw CanteraError(
"Kinetics::addReaction",
"Reaction orders may only "
666 "be given for irreversible reactions");
670 for (Composition::const_iterator iter = r->reactants.begin();
671 iter != r->reactants.end();
677 throw CanteraError(
"Kinetics::addReaction",
"Reaction '" +
678 r->equation() +
"' contains the undeclared species '" +
683 for (Composition::const_iterator iter = r->products.begin();
684 iter != r->products.end();
690 throw CanteraError(
"Kinetics::addReaction",
"Reaction '" +
691 r->equation() +
"' contains the undeclared species '" +
702 std::vector<size_t> rk, pk;
708 for (Composition::const_iterator iter = r->reactants.begin();
709 iter != r->reactants.end();
713 rstoich.push_back(iter->second);
714 m_rrxn[k][irxn] = iter->second;
718 for (Composition::const_iterator iter = r->products.begin();
719 iter != r->products.end();
723 pstoich.push_back(iter->second);
724 m_prxn[k][irxn] = iter->second;
732 for (Composition::const_iterator iter = r->orders.begin();
733 iter != r->orders.end();
737 vector<size_t>::iterator rloc = std::find(rk.begin(), rk.end(), k);
738 if (rloc != rk.end()) {
739 rorder[rloc - rk.begin()] = iter->second;
746 rstoich.push_back(0.0);
747 rorder.push_back(iter->second);
764 m_rxntype.push_back(r->reaction_type);
765 m_rfn.push_back(0.0);
777 if (rNew->reaction_type != rOld->reaction_type) {
779 "Reaction types are different: " +
int2str(rOld->reaction_type) +
780 " != " +
int2str(rNew->reaction_type) +
".");
783 if (rNew->reactants != rOld->reactants) {
785 "Reactants are different: '" + rOld->reactantString() +
"' != '" +
786 rNew->reactantString() +
"'.");
789 if (rNew->products != rOld->products) {
791 "Products are different: '" + rOld->productString() +
"' != '" +
792 rNew->productString() +
"'.");
804 void Kinetics::installGroups(
size_t irxn,
const vector<grouplist_t>& r,
805 const vector<grouplist_t>& p)
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
std::vector< grouplist_t > rgroups
Optional data used in reaction path diagrams.
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
StoichManagerN m_irrevProductStoich
Stoichiometry manager for the products of irreversible reactions.
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
vector_fp m_ropr
Reverse rate-of-progress for each reaction.
std::vector< thermo_t * > m_thermo
m_thermo is a vector of pointers to ThermoPhase objects that are involved with this kinetics operator...
int reaction_type
Type of the reaction.
void incrementRxnCount()
Increment the number of reactions in the mechanism by one.
std::vector< std::vector< size_t > > m_reactants
This is a vector of vectors containing the reactants for each reaction.
size_t nElements() const
Number of elements.
int reactionType
Type of the reaction.
virtual void assignShallowPointers(const std::vector< thermo_t * > &tpVector)
Reassign the pointers within the Kinetics object.
thermo_t & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism...
vector_fp forwardFullOrder_
Reaction order for the forward direction of the reaction.
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
std::vector< size_t > m_start
m_start is a vector of integers specifying the beginning position for the species vector for the n'th...
const size_t npos
index returned by functions to indicate "no position"
virtual void getNetRatesOfProgress(doublereal *netROP)
Net rates of progress.
virtual Kinetics * duplMyselfAsKinetics(const std::vector< thermo_t * > &tpVector) const
Duplication routine for objects which inherit from Kinetics.
vector_fp pstoich
Product stoichiometric coefficients, in the order given by products.
std::string kineticsSpeciesName(size_t k) const
Return the name of the kth species in the kinetics manager.
std::vector< std::string > m_reactantStrings
Representation of the reactant side of each reaction equation.
void selectPhase(const doublereal *data, const thermo_t *phase, doublereal *phase_data)
vector_fp porder
Reaction order of the reverse reaction with respect to each product species, in the order given by pr...
A class for managing third-body efficiencies, including default values.
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
Kinetics()
Default constructor.
virtual void getRevReactionDelta(const doublereal *g, doublereal *dg)
Given an array of species properties 'g', return in array 'dg' the change in this quantity in the rev...
vector_fp m_ropnet
Net rate-of-progress for each reaction.
const int CHEMACT_RXN
A chemical activation reaction.
virtual void getDestructionRates(doublereal *ddot)
Species destruction rates [kmol/m^3/s or kmol/m^2/s].
virtual void getCreationRates(doublereal *cdot)
Species creation rates [kmol/m^3/s or kmol/m^2/s].
double efficiency(const std::string &k) const
Get the third-body efficiency for species k
virtual void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Base class for a phase with thermodynamic properties.
vector_fp m_ropf
Forward rate-of-progress for each reaction.
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...
std::vector< int > vector_int
Vector of ints.
void checkPhaseIndex(size_t m) const
Check that the specified phase index is in range Throws an exception if m is greater than nPhases() ...
std::string equation
The reaction equation. Used only for display purposes.
std::vector< size_t > products
Indices of product species.
std::vector< std::string > m_rxneqn
Representation of each reaction equation.
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
virtual std::pair< size_t, size_t > checkDuplicates(bool throw_err=true) const
Check for duplicate reactions.
void checkReactionBalance(const Reaction &R)
Check that the specified reaction is balanced (same number of atoms for each element in the reactants...
std::vector< grouplist_t > pgroups
Optional data used in reaction path diagrams.
bool reversible
True if the current reaction is reversible. False otherwise.
bool duplicate
True if the current reaction is marked as duplicate.
size_t nPhases() const
The number of phases participating in the reaction mechanism.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
std::map< std::string, doublereal > Composition
Map from string names to doubles.
std::vector< std::map< size_t, doublereal > > m_prxn
m_prxn is a vector of maps, containing the reactant stoichiometric coefficient information ...
vector_fp m_rfn
Forward rate constant for each reaction.
StoichManagerN m_reactantStoich
Stoichiometry manager for the reactants for each reaction.
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...
void checkSpeciesArraySize(size_t mm) const
Check that an array size is at least nSpecies() Throws an exception if kk is less than nSpecies()...
virtual void getRevRatesOfProgress(doublereal *revROP)
Return the Reverse rates of progress of the reactions.
void checkSpeciesIndex(size_t k) const
Check that the specified species index is in range Throws an exception if k is greater than nSpecies(...
vector_fp m_perturb
Vector of perturbation factors for each reaction's rate of progress vector.
A reaction that is first-order in [M] at low pressure, like a third-body reaction, but zeroth-order in [M] as pressure increases.
Public interface for kinetics managers.
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.
Composition reactants
Reactant species and stoichiometric coefficients.
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Intermediate class which stores data about a reaction and its rate parameterization so that it can be...
const U & getValue(const std::map< T, U > &m, const T &key)
Const accessor for a value in a std::map.
std::map< std::string, size_t > m_phaseindex
Mapping of the phase id, i.e., the id attribute in the XML phase element to the position of the phase...
double checkDuplicateStoich(std::map< int, double > &r1, std::map< int, double > &r2) const
Check whether r1 and r2 represent duplicate stoichiometries This function returns a ratio if two reac...
const int cEdge
An edge between two 2D surfaces.
std::vector< std::map< size_t, doublereal > > m_rrxn
m_rrxn is a vector of maps, containing the reactant stoichiometric coefficient information ...
Kinetics & operator=(const Kinetics &right)
Assignment operator.
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.
vector_fp m_rkcn
Reciprocal of the equilibrium constant in concentration units.
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.
std::vector< shared_ptr< Reaction > > m_reactions
Vector of Reaction objects represented by this Kinetics manager.
size_t nDim() const
Returns the number of spatial dimensions (1, 2, or 3)
std::string equation() const
The chemical equation for this reaction.
size_t m_mindim
number of spatial dimensions of lowest-dimensional phase.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
void checkReactionIndex(size_t m) const
Check that the specified reaction index is in range Throws an exception if i is greater than nReactio...
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...
std::vector< std::vector< size_t > > m_products
This is a vector of vectors containing the products for each reaction.
A reaction with a non-reacting third body "M" that acts to add or remove energy from the reacting spe...
std::vector< std::string > m_productStrings
Representation of the product side of each reaction equation.
void checkReactionArraySize(size_t ii) const
Check that an array size is at least nReactions() Throws an exception if ii is less than nReactions()...
size_t m_ii
Number of reactions in the mechanism.
Contains declarations for string manipulation functions within Cantera.
size_t nReactions() const
Number of reactions in the reaction mechanism.
virtual int type() const
Identifies the kinetics manager type.
size_t m_surfphase
Index in the list of phases of the one surface phase.
std::string elementName(size_t m) const
Name of the element with index m.
virtual double reactantStoichCoeff(size_t k, size_t i) const
Stoichiometric coefficient of species k as a reactant in reaction i.
std::string productString
The products half of the reaction equation, used for display purposes.
shared_ptr< Reaction > reaction(size_t i)
Return the Reaction object for reaction i.
void writelog(const std::string &msg)
Write a message to the screen.
An array index is out of range.
Composition products
Product species and stoichiometric coefficients.
size_t m_rxnphase
Phase Index where reactions are assumed to be taking place.
virtual void getFwdRatesOfProgress(doublereal *fwdROP)
Return the forward rates of progress of the reactions.
virtual void finalize()
Finish adding reactions and prepare for use.
virtual void addPhase(thermo_t &thermo)
Add a phase to the kinetics manager object.
virtual ~Kinetics()
Destructor.
void checkPhaseArraySize(size_t mm) const
Check that an array size is at least nPhases() Throws an exception if mm is less than nPhases()...
virtual double productStoichCoeff(size_t k, size_t i) const
Stoichiometric coefficient of species k as a product in reaction i.
bool m_skipUndeclaredSpecies
vector_fp rorder
Reaction order with respect to each reactant species, in the order given by reactants.
virtual void getReactionDelta(const doublereal *property, doublereal *deltaProperty)
Change in species properties.
std::string speciesName(size_t k) const
Name of the species with index k.
virtual void addReaction(ReactionData &r)
Add a single reaction to the mechanism.
std::string reactantString
The reactants half of the reaction equation, used for display purposes.