Cantera  2.4.0
Kinetics.cpp
Go to the documentation of this file.
1 /**
2  * @file Kinetics.cpp Declarations for the base class for kinetics managers
3  * (see \ref kineticsmgr and class \link Cantera::Kinetics Kinetics \endlink).
4  *
5  * Kinetics managers calculate rates of progress of species due to
6  * homogeneous or heterogeneous kinetics.
7  */
8 
9 // This file is part of Cantera. See License.txt in the top-level directory or
10 // at http://www.cantera.org/license.txt for license and copyright information.
11 
15 #include <unordered_set>
16 
17 using namespace std;
18 
19 namespace Cantera
20 {
21 Kinetics::Kinetics() :
22  m_kk(0),
23  m_thermo(0),
24  m_surfphase(npos),
25  m_rxnphase(npos),
26  m_mindim(4),
27  m_skipUndeclaredSpecies(false),
28  m_skipUndeclaredThirdBodies(false)
29 {
30 }
31 
32 Kinetics::~Kinetics() {}
33 
34 void Kinetics::checkReactionIndex(size_t i) const
35 {
36  if (i >= nReactions()) {
37  throw IndexError("checkReactionIndex", "reactions", i, nReactions()-1);
38  }
39 }
40 
41 void Kinetics::checkReactionArraySize(size_t ii) const
42 {
43  if (nReactions() > ii) {
44  throw ArraySizeError("checkReactionArraySize", ii, nReactions());
45  }
46 }
47 
48 void Kinetics::checkPhaseIndex(size_t m) const
49 {
50  if (m >= nPhases()) {
51  throw IndexError("checkPhaseIndex", "phase", m, nPhases()-1);
52  }
53 }
54 
55 void Kinetics::checkPhaseArraySize(size_t mm) const
56 {
57  if (nPhases() > mm) {
58  throw ArraySizeError("checkPhaseArraySize", mm, nPhases());
59  }
60 }
61 
62 void Kinetics::checkSpeciesIndex(size_t k) const
63 {
64  if (k >= m_kk) {
65  throw IndexError("checkSpeciesIndex", "species", k, m_kk-1);
66  }
67 }
68 
69 void Kinetics::checkSpeciesArraySize(size_t kk) const
70 {
71  if (m_kk > kk) {
72  throw ArraySizeError("checkSpeciesArraySize", kk, m_kk);
73  }
74 }
75 
76 std::pair<size_t, size_t> Kinetics::checkDuplicates(bool throw_err) const
77 {
78  //! Map of (key indicating participating species) to reaction numbers
79  std::map<size_t, std::vector<size_t> > participants;
80  std::vector<std::map<int, double> > net_stoich;
81  std::unordered_set<size_t> unmatched_duplicates;
82  for (size_t i = 0; i < m_reactions.size(); i++) {
83  if (m_reactions[i]->duplicate) {
84  unmatched_duplicates.insert(i);
85  }
86  }
87 
88  for (size_t i = 0; i < m_reactions.size(); i++) {
89  // Get data about this reaction
90  unsigned long int key = 0;
91  Reaction& R = *m_reactions[i];
92  net_stoich.emplace_back();
93  std::map<int, double>& net = net_stoich.back();
94  for (const auto& sp : R.reactants) {
95  int k = static_cast<int>(kineticsSpeciesIndex(sp.first));
96  key += k*(k+1);
97  net[-1 -k] -= sp.second;
98  }
99  for (const auto& sp : R.products) {
100  int k = static_cast<int>(kineticsSpeciesIndex(sp.first));
101  key += k*(k+1);
102  net[1+k] += sp.second;
103  }
104 
105  // Compare this reaction to others with similar participants
106  vector<size_t>& related = participants[key];
107  for (size_t m : related) {
108  Reaction& other = *m_reactions[m];
109  if (R.duplicate && other.duplicate) {
110  // marked duplicates
111  unmatched_duplicates.erase(i);
112  unmatched_duplicates.erase(m);
113  continue;
114  } else if (R.reaction_type != other.reaction_type) {
115  continue; // different reaction types
116  }
117  doublereal c = checkDuplicateStoich(net_stoich[i], net_stoich[m]);
118  if (c == 0) {
119  continue; // stoichiometries differ (not by a multiple)
120  } else if (c < 0.0 && !R.reversible && !other.reversible) {
121  continue; // irreversible reactions in opposite directions
122  } else if (R.reaction_type == FALLOFF_RXN ||
123  R.reaction_type == CHEMACT_RXN) {
124  ThirdBody& tb1 = dynamic_cast<FalloffReaction&>(R).third_body;
125  ThirdBody& tb2 = dynamic_cast<FalloffReaction&>(other).third_body;
126  bool thirdBodyOk = true;
127  for (size_t k = 0; k < nTotalSpecies(); k++) {
128  string s = kineticsSpeciesName(k);
129  if (tb1.efficiency(s) * tb2.efficiency(s) != 0.0) {
130  // non-zero third body efficiencies for species `s` in
131  // both reactions
132  thirdBodyOk = false;
133  break;
134  }
135  }
136  if (thirdBodyOk) {
137  continue; // No overlap in third body efficiencies
138  }
139  } else if (R.reaction_type == THREE_BODY_RXN) {
140  ThirdBody& tb1 = dynamic_cast<ThreeBodyReaction&>(R).third_body;
141  ThirdBody& tb2 = dynamic_cast<ThreeBodyReaction&>(other).third_body;
142  bool thirdBodyOk = true;
143  for (size_t k = 0; k < nTotalSpecies(); k++) {
144  string s = kineticsSpeciesName(k);
145  if (tb1.efficiency(s) * tb2.efficiency(s) != 0.0) {
146  // non-zero third body efficiencies for species `s` in
147  // both reactions
148  thirdBodyOk = false;
149  break;
150  }
151  }
152  if (thirdBodyOk) {
153  continue; // No overlap in third body efficiencies
154  }
155  }
156  if (throw_err) {
157  throw CanteraError("Kinetics::checkDuplicates",
158  "Undeclared duplicate reactions detected:\n"
159  "Reaction {}: {}\nReaction {}: {}\n",
160  i+1, other.equation(), m+1, R.equation());
161  } else {
162  return {i,m};
163  }
164  }
165  participants[key].push_back(i);
166  }
167  if (unmatched_duplicates.size()) {
168  size_t i = *unmatched_duplicates.begin();
169  if (throw_err) {
170  throw CanteraError("Kinetics::checkDuplicates",
171  "No duplicate found for declared duplicate reaction number {}"
172  " ({})", i, m_reactions[i]->equation());
173  } else {
174  return {i, i};
175  }
176  }
177  return {npos, npos};
178 }
179 
180 double Kinetics::checkDuplicateStoich(std::map<int, double>& r1,
181  std::map<int, double>& r2) const
182 {
183  std::unordered_set<int> keys; // species keys (k+1 or -k-1)
184  for (auto& r : r1) {
185  keys.insert(r.first);
186  }
187  for (auto& r : r2) {
188  keys.insert(r.first);
189  }
190  int k1 = r1.begin()->first;
191  // check for duplicate written in the same direction
192  doublereal ratio = 0.0;
193  if (r1[k1] && r2[k1]) {
194  ratio = r2[k1]/r1[k1];
195  bool different = false;
196  for (int k : keys) {
197  if ((r1[k] && !r2[k]) ||
198  (!r1[k] && r2[k]) ||
199  (r1[k] && fabs(r2[k]/r1[k] - ratio) > 1.e-8)) {
200  different = true;
201  break;
202  }
203  }
204  if (!different) {
205  return ratio;
206  }
207  }
208 
209  // check for duplicate written in the reverse direction
210  if (r1[k1] == 0.0 || r2[-k1] == 0.0) {
211  return 0.0;
212  }
213  ratio = r2[-k1]/r1[k1];
214  for (int k : keys) {
215  if ((r1[k] && !r2[-k]) ||
216  (!r1[k] && r2[-k]) ||
217  (r1[k] && fabs(r2[-k]/r1[k] - ratio) > 1.e-8)) {
218  return 0.0;
219  }
220  }
221  return ratio;
222 }
223 
225 {
226  Composition balr, balp;
227  // iterate over the products
228  for (const auto& sp : R.products) {
229  const ThermoPhase& ph = speciesPhase(sp.first);
230  size_t k = ph.speciesIndex(sp.first);
231  double stoich = sp.second;
232  for (size_t m = 0; m < ph.nElements(); m++) {
233  balr[ph.elementName(m)] = 0.0; // so that balr contains all species
234  balp[ph.elementName(m)] += stoich*ph.nAtoms(k,m);
235  }
236  }
237  for (const auto& sp : R.reactants) {
238  const ThermoPhase& ph = speciesPhase(sp.first);
239  size_t k = ph.speciesIndex(sp.first);
240  double stoich = sp.second;
241  for (size_t m = 0; m < ph.nElements(); m++) {
242  balr[ph.elementName(m)] += stoich*ph.nAtoms(k,m);
243  }
244  }
245 
246  string msg;
247  bool ok = true;
248  for (const auto& el : balr) {
249  const string& elem = el.first;
250  double elemsum = balr[elem] + balp[elem];
251  double elemdiff = fabs(balp[elem] - balr[elem]);
252  if (elemsum > 0.0 && elemdiff/elemsum > 1e-4) {
253  ok = false;
254  msg += fmt::format(" {} {} {}\n",
255  elem, balr[elem], balp[elem]);
256  }
257  }
258  if (!ok) {
259  msg = "The following reaction is unbalanced: " + R.equation() + "\n" +
260  " Element Reactants Products\n" + msg;
261  throw CanteraError("checkReactionBalance", msg);
262  }
263 }
264 
265 void Kinetics::selectPhase(const doublereal* data, const thermo_t* phase,
266  doublereal* phase_data)
267 {
268  for (size_t n = 0; n < nPhases(); n++) {
269  if (phase == m_thermo[n]) {
270  size_t nsp = phase->nSpecies();
271  copy(data + m_start[n],
272  data + m_start[n] + nsp, phase_data);
273  return;
274  }
275  }
276  throw CanteraError("Kinetics::selectPhase", "Phase not found.");
277 }
278 
279 string Kinetics::kineticsSpeciesName(size_t k) const
280 {
281  for (size_t n = m_start.size()-1; n != npos; n--) {
282  if (k >= m_start[n]) {
283  return thermo(n).speciesName(k - m_start[n]);
284  }
285  }
286  return "<unknown>";
287 }
288 
289 size_t Kinetics::kineticsSpeciesIndex(const std::string& nm) const
290 {
291  for (size_t n = 0; n < m_thermo.size(); n++) {
292  string id = thermo(n).id();
293  // Check the ThermoPhase object for a match
294  size_t k = thermo(n).speciesIndex(nm);
295  if (k != npos) {
296  return k + m_start[n];
297  }
298  }
299  return npos;
300 }
301 
302 size_t Kinetics::kineticsSpeciesIndex(const std::string& nm,
303  const std::string& ph) const
304 {
305  if (ph == "<any>") {
306  return kineticsSpeciesIndex(nm);
307  }
308 
309  for (size_t n = 0; n < m_thermo.size(); n++) {
310  string id = thermo(n).id();
311  if (ph == id) {
312  size_t k = thermo(n).speciesIndex(nm);
313  if (k == npos) {
314  return npos;
315  }
316  return k + m_start[n];
317  }
318  }
319  return npos;
320 }
321 
322 thermo_t& Kinetics::speciesPhase(const std::string& nm)
323 {
324  for (size_t n = 0; n < m_thermo.size(); n++) {
325  size_t k = thermo(n).speciesIndex(nm);
326  if (k != npos) {
327  return thermo(n);
328  }
329  }
330  throw CanteraError("speciesPhase", "unknown species "+nm);
331 }
332 
334 {
335  for (size_t n = m_start.size()-1; n != npos; n--) {
336  if (k >= m_start[n]) {
337  return n;
338  }
339  }
340  throw CanteraError("speciesPhaseIndex", "illegal species index: {}", k);
341 }
342 
343 double Kinetics::reactantStoichCoeff(size_t kSpec, size_t irxn) const
344 {
345  return getValue(m_reactions[irxn]->reactants, kineticsSpeciesName(kSpec),
346  0.0);
347 }
348 
349 double Kinetics::productStoichCoeff(size_t kSpec, size_t irxn) const
350 {
351  return getValue(m_reactions[irxn]->products, kineticsSpeciesName(kSpec),
352  0.0);
353 }
354 
355 void Kinetics::getFwdRatesOfProgress(doublereal* fwdROP)
356 {
357  updateROP();
358  std::copy(m_ropf.begin(), m_ropf.end(), fwdROP);
359 }
360 
361 void Kinetics::getRevRatesOfProgress(doublereal* revROP)
362 {
363  updateROP();
364  std::copy(m_ropr.begin(), m_ropr.end(), revROP);
365 }
366 
367 void Kinetics::getNetRatesOfProgress(doublereal* netROP)
368 {
369  updateROP();
370  std::copy(m_ropnet.begin(), m_ropnet.end(), netROP);
371 }
372 
373 void Kinetics::getReactionDelta(const double* prop, double* deltaProp)
374 {
375  fill(deltaProp, deltaProp + nReactions(), 0.0);
376  // products add
377  m_revProductStoich.incrementReactions(prop, deltaProp);
378  m_irrevProductStoich.incrementReactions(prop, deltaProp);
379  // reactants subtract
380  m_reactantStoich.decrementReactions(prop, deltaProp);
381 }
382 
383 void Kinetics::getRevReactionDelta(const double* prop, double* deltaProp)
384 {
385  fill(deltaProp, deltaProp + nReactions(), 0.0);
386  // products add
387  m_revProductStoich.incrementReactions(prop, deltaProp);
388  // reactants subtract
389  m_reactantStoich.decrementReactions(prop, deltaProp);
390 }
391 
392 void Kinetics::getCreationRates(double* cdot)
393 {
394  updateROP();
395 
396  // zero out the output array
397  fill(cdot, cdot + m_kk, 0.0);
398 
399  // the forward direction creates product species
400  m_revProductStoich.incrementSpecies(m_ropf.data(), cdot);
401  m_irrevProductStoich.incrementSpecies(m_ropf.data(), cdot);
402 
403  // the reverse direction creates reactant species
404  m_reactantStoich.incrementSpecies(m_ropr.data(), cdot);
405 }
406 
407 void Kinetics::getDestructionRates(doublereal* ddot)
408 {
409  updateROP();
410 
411  fill(ddot, ddot + m_kk, 0.0);
412  // the reverse direction destroys products in reversible reactions
413  m_revProductStoich.incrementSpecies(m_ropr.data(), ddot);
414  // the forward direction destroys reactants
415  m_reactantStoich.incrementSpecies(m_ropf.data(), ddot);
416 }
417 
418 void Kinetics::getNetProductionRates(doublereal* net)
419 {
420  updateROP();
421 
422  fill(net, net + m_kk, 0.0);
423  // products are created for positive net rate of progress
424  m_revProductStoich.incrementSpecies(m_ropnet.data(), net);
425  m_irrevProductStoich.incrementSpecies(m_ropnet.data(), net);
426  // reactants are destroyed for positive net rate of progress
427  m_reactantStoich.decrementSpecies(m_ropnet.data(), net);
428 }
429 
431 {
432  // the phase with lowest dimensionality is assumed to be the
433  // phase/interface at which reactions take place
434  if (thermo.nDim() <= m_mindim) {
435  m_mindim = thermo.nDim();
436  m_rxnphase = nPhases();
437  }
438 
439  // there should only be one surface phase
440  if (thermo.type() == kineticsType()) {
441  m_surfphase = nPhases();
442  m_rxnphase = nPhases();
443  }
444  m_thermo.push_back(&thermo);
445  m_phaseindex[m_thermo.back()->id()] = nPhases();
446  resizeSpecies();
447 }
448 
450 {
451  m_kk = 0;
452  m_start.resize(nPhases());
453 
454  for (size_t i = 0; i < m_thermo.size(); i++) {
455  m_start[i] = m_kk; // global index of first species of phase i
456  m_kk += m_thermo[i]->nSpecies();
457  }
458  invalidateCache();
459 }
460 
461 bool Kinetics::addReaction(shared_ptr<Reaction> r)
462 {
463  r->validate();
464  if (m_kk == 0) {
465  init();
466  }
467  resizeSpecies();
468 
469  // If reaction orders are specified, then this reaction does not follow
470  // mass-action kinetics, and is not an elementary reaction. So check that it
471  // is not reversible, since computing the reverse rate from thermochemistry
472  // only works for elementary reactions.
473  if (r->reversible && !r->orders.empty()) {
474  throw CanteraError("Kinetics::addReaction", "Reaction orders may only "
475  "be given for irreversible reactions");
476  }
477 
478  // Check for undeclared species
479  for (const auto& sp : r->reactants) {
480  if (kineticsSpeciesIndex(sp.first) == npos) {
482  return false;
483  } else {
484  throw CanteraError("Kinetics::addReaction", "Reaction '" +
485  r->equation() + "' contains the undeclared species '" +
486  sp.first + "'");
487  }
488  }
489  }
490  for (const auto& sp : r->products) {
491  if (kineticsSpeciesIndex(sp.first) == npos) {
493  return false;
494  } else {
495  throw CanteraError("Kinetics::addReaction", "Reaction '" +
496  r->equation() + "' contains the undeclared species '" +
497  sp.first + "'");
498  }
499  }
500  }
501  for (const auto& sp : r->orders) {
502  if (kineticsSpeciesIndex(sp.first) == npos) {
504  return false;
505  } else {
506  throw CanteraError("Kinetics::addReaction", "Reaction '{}' has "
507  "a reaction order specified for the undeclared species '{}'",
508  r->equation(), sp.first);
509  }
510  }
511  }
512 
514  size_t irxn = nReactions(); // index of the new reaction
515 
516  // indices of reactant and product species within this Kinetics object
517  std::vector<size_t> rk, pk;
518 
519  // Reactant and product stoichiometric coefficients, such that rstoich[i] is
520  // the coefficient for species rk[i]
521  vector_fp rstoich, pstoich;
522 
523  for (const auto& sp : r->reactants) {
524  rk.push_back(kineticsSpeciesIndex(sp.first));
525  rstoich.push_back(sp.second);
526  }
527 
528  for (const auto& sp : r->products) {
529  pk.push_back(kineticsSpeciesIndex(sp.first));
530  pstoich.push_back(sp.second);
531  }
532 
533  // The default order for each reactant is its stoichiometric coefficient,
534  // which can be overridden by entries in the Reaction.orders map. rorder[i]
535  // is the order for species rk[i].
536  vector_fp rorder = rstoich;
537  for (const auto& sp : r->orders) {
538  size_t k = kineticsSpeciesIndex(sp.first);
539  // Find the index of species k within rk
540  auto rloc = std::find(rk.begin(), rk.end(), k);
541  if (rloc != rk.end()) {
542  rorder[rloc - rk.begin()] = sp.second;
543  } else {
544  // If the reaction order involves a non-reactant species, add an
545  // extra term to the reactants with zero stoichiometry so that the
546  // stoichiometry manager can be used to compute the global forward
547  // reaction rate.
548  rk.push_back(k);
549  rstoich.push_back(0.0);
550  rorder.push_back(sp.second);
551  }
552  }
553 
554  m_reactantStoich.add(irxn, rk, rorder, rstoich);
555  // product orders = product stoichiometric coefficients
556  if (r->reversible) {
557  m_revProductStoich.add(irxn, pk, pstoich, pstoich);
558  } else {
559  m_irrevProductStoich.add(irxn, pk, pstoich, pstoich);
560  }
561 
562  m_reactions.push_back(r);
563  m_rfn.push_back(0.0);
564  m_rkcn.push_back(0.0);
565  m_ropf.push_back(0.0);
566  m_ropr.push_back(0.0);
567  m_ropnet.push_back(0.0);
568  m_perturb.push_back(1.0);
569  return true;
570 }
571 
572 void Kinetics::modifyReaction(size_t i, shared_ptr<Reaction> rNew)
573 {
575  shared_ptr<Reaction>& rOld = m_reactions[i];
576  if (rNew->reaction_type != rOld->reaction_type) {
577  throw CanteraError("Kinetics::modifyReaction",
578  "Reaction types are different: {} != {}.",
579  rOld->reaction_type, rNew->reaction_type);
580  }
581 
582  if (rNew->reactants != rOld->reactants) {
583  throw CanteraError("Kinetics::modifyReaction",
584  "Reactants are different: '{}' != '{}'.",
585  rOld->reactantString(), rNew->reactantString());
586  }
587 
588  if (rNew->products != rOld->products) {
589  throw CanteraError("Kinetics::modifyReaction",
590  "Products are different: '{}' != '{}'.",
591  rOld->productString(), rNew->productString());
592  }
593  m_reactions[i] = rNew;
594  invalidateCache();
595 }
596 
597 shared_ptr<Reaction> Kinetics::reaction(size_t i)
598 {
600  return m_reactions[i];
601 }
602 
603 shared_ptr<const Reaction> Kinetics::reaction(size_t i) const
604 {
606  return m_reactions[i];
607 }
608 
609 }
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
Definition: Kinetics.cpp:572
std::string kineticsSpeciesName(size_t k) const
Return the name of the kth species in the kinetics manager.
Definition: Kinetics.cpp:279
StoichManagerN m_irrevProductStoich
Stoichiometry manager for the products of irreversible reactions.
Definition: Kinetics.h:855
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
Definition: Kinetics.h:852
Array size error.
Definition: ctexceptions.h:128
vector_fp m_ropr
Reverse rate-of-progress for each reaction.
Definition: Kinetics.h:921
size_t nElements() const
Number of elements.
Definition: Phase.cpp:88
std::vector< thermo_t * > m_thermo
m_thermo is a vector of pointers to ThermoPhase objects that are involved with this kinetics operator...
Definition: Kinetics.h:882
void checkSpeciesIndex(size_t k) const
Check that the specified species index is in range Throws an exception if k is greater than nSpecies(...
Definition: Kinetics.cpp:62
int reaction_type
Type of the reaction.
Definition: Reaction.h:45
size_t speciesIndex(const std::string &name) const
Returns the index of a species named &#39;name&#39; within the Phase object.
Definition: Phase.cpp:175
thermo_t & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism...
Definition: Kinetics.h:227
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
Definition: Kinetics.h:860
std::vector< size_t > m_start
m_start is a vector of integers specifying the beginning position for the species vector for the n&#39;th...
Definition: Kinetics.h:888
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:165
virtual void getNetRatesOfProgress(doublereal *netROP)
Net rates of progress.
Definition: Kinetics.cpp:367
void selectPhase(const doublereal *data, const thermo_t *phase, doublereal *phase_data)
Definition: Kinetics.cpp:265
virtual void resizeSpecies()
Resize arrays with sizes that depend on the total number of species.
Definition: Kinetics.cpp:449
virtual bool addReaction(shared_ptr< Reaction > r)
Add a single reaction to the mechanism.
Definition: Kinetics.cpp:461
A class for managing third-body efficiencies, including default values.
Definition: Reaction.h:92
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:266
STL namespace.
virtual void getRevReactionDelta(const doublereal *g, doublereal *dg)
Given an array of species properties &#39;g&#39;, return in array &#39;dg&#39; the change in this quantity in the rev...
Definition: Kinetics.cpp:383
vector_fp m_ropnet
Net rate-of-progress for each reaction.
Definition: Kinetics.h:924
const int CHEMACT_RXN
A chemical activation reaction.
Definition: reaction_defs.h:65
size_t nPhases() const
The number of phases participating in the reaction mechanism.
Definition: Kinetics.h:167
virtual void getDestructionRates(doublereal *ddot)
Species destruction rates [kmol/m^3/s or kmol/m^2/s].
Definition: Kinetics.cpp:407
virtual void getCreationRates(doublereal *cdot)
Species creation rates [kmol/m^3/s or kmol/m^2/s].
Definition: Kinetics.cpp:392
void checkSpeciesArraySize(size_t mm) const
Check that an array size is at least nSpecies() Throws an exception if kk is less than nSpecies()...
Definition: Kinetics.cpp:69
virtual void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition: Kinetics.cpp:418
vector_fp m_ropf
Forward rate-of-progress for each reaction.
Definition: Kinetics.h:918
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
const int FALLOFF_RXN
The general form for a gas-phase association or dissociation reaction, with a pressure-dependent rate...
Definition: reaction_defs.h:43
virtual void init()
Prepare the class for the addition of reactions, after all phases have been added.
Definition: Kinetics.h:699
virtual double productStoichCoeff(size_t k, size_t i) const
Stoichiometric coefficient of species k as a product in reaction i.
Definition: Kinetics.cpp:349
void checkReactionBalance(const Reaction &R)
Check that the specified reaction is balanced (same number of atoms for each element in the reactants...
Definition: Kinetics.cpp:224
bool reversible
True if the current reaction is reversible. False otherwise.
Definition: Reaction.h:63
virtual double reactantStoichCoeff(size_t k, size_t i) const
Stoichiometric coefficient of species k as a reactant in reaction i.
Definition: Kinetics.cpp:343
bool duplicate
True if the current reaction is marked as duplicate.
Definition: Reaction.h:66
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
Definition: Kinetics.h:239
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:191
std::map< std::string, doublereal > Composition
Map from string names to doubles.
Definition: ct_defs.h:153
vector_fp m_rfn
Forward rate constant for each reaction.
Definition: Kinetics.h:912
StoichManagerN m_reactantStoich
Stoichiometry manager for the reactants for each reaction.
Definition: Kinetics.h:849
void checkReactionArraySize(size_t ii) const
Check that an array size is at least nReactions() Throws an exception if ii is less than nReactions()...
Definition: Kinetics.cpp:41
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...
Definition: Kinetics.cpp:322
virtual void getRevRatesOfProgress(doublereal *revROP)
Return the Reverse rates of progress of the reactions.
Definition: Kinetics.cpp:361
vector_fp m_perturb
Vector of perturbation factors for each reaction&#39;s rate of progress vector.
Definition: Kinetics.h:864
A reaction that is first-order in [M] at low pressure, like a third-body reaction, but zeroth-order in [M] as pressure increases.
Definition: Reaction.h:128
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
Definition: Kinetics.h:261
virtual std::string kineticsType() const
Identifies the Kinetics manager type.
Definition: Kinetics.h:130
const U & getValue(const std::map< T, U > &m, const T &key, const U &default_val)
Const accessor for a value in a std::map.
Definition: utilities.h:504
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition: Kinetics.h:135
Composition reactants
Reactant species and stoichiometric coefficients.
Definition: Reaction.h:48
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...
Definition: Reaction.h:22
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...
Definition: Kinetics.h:896
void checkPhaseArraySize(size_t mm) const
Check that an array size is at least nPhases() Throws an exception if mm is less than nPhases()...
Definition: Kinetics.cpp:55
virtual std::pair< size_t, size_t > checkDuplicates(bool throw_err=true) const
Check for unmarked duplicate reactions and unmatched marked duplicates.
Definition: Kinetics.cpp:76
double efficiency(const std::string &k) const
Get the third-body efficiency for species k
Definition: Reaction.h:98
const int THREE_BODY_RXN
A gas-phase reaction that requires a third-body collision partner.
Definition: reaction_defs.h:37
vector_fp m_rkcn
Reciprocal of the equilibrium constant in concentration units.
Definition: Kinetics.h:915
virtual std::string type() const
String indicating the thermodynamic model implemented.
Definition: ThermoPhase.h:108
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...
Definition: Kinetics.cpp:180
std::vector< shared_ptr< Reaction > > m_reactions
Vector of Reaction objects represented by this Kinetics manager.
Definition: Kinetics.h:867
std::string id() const
Return the string id for the phase.
Definition: Phase.cpp:68
size_t m_mindim
number of spatial dimensions of lowest-dimensional phase.
Definition: Kinetics.h:909
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
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...
Definition: Kinetics.cpp:333
A reaction with a non-reacting third body "M" that acts to add or remove energy from the reacting spe...
Definition: Reaction.h:112
Contains declarations for string manipulation functions within Cantera.
size_t m_surfphase
Index in the list of phases of the one surface phase.
Definition: Kinetics.h:899
size_t nDim() const
Returns the number of spatial dimensions (1, 2, or 3)
Definition: Phase.h:585
shared_ptr< Reaction > reaction(size_t i)
Return the Reaction object for reaction i.
Definition: Kinetics.cpp:597
An array index is out of range.
Definition: ctexceptions.h:158
Composition products
Product species and stoichiometric coefficients.
Definition: Reaction.h:51
void checkReactionIndex(size_t m) const
Check that the specified reaction index is in range Throws an exception if i is greater than nReactio...
Definition: Kinetics.cpp:34
size_t m_rxnphase
Phase Index where reactions are assumed to be taking place.
Definition: Kinetics.h:906
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
virtual void getFwdRatesOfProgress(doublereal *fwdROP)
Return the forward rates of progress of the reactions.
Definition: Kinetics.cpp:355
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
Definition: Phase.cpp:161
virtual void addPhase(thermo_t &thermo)
Add a phase to the kinetics manager object.
Definition: Kinetics.cpp:430
bool m_skipUndeclaredSpecies
Definition: Kinetics.h:927
virtual void getReactionDelta(const doublereal *property, doublereal *deltaProperty)
Change in species properties.
Definition: Kinetics.cpp:373
std::string elementName(size_t m) const
Name of the element with index m.
Definition: Phase.cpp:107
void checkPhaseIndex(size_t m) const
Check that the specified phase index is in range Throws an exception if m is greater than nPhases() ...
Definition: Kinetics.cpp:48
std::string equation() const
The chemical equation for this reaction.
Definition: Reaction.cpp:89