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