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