Cantera  4.0.0a1
Loading...
Searching...
No Matches
BulkKinetics.cpp
1// This file is part of Cantera. See License.txt in the top-level directory or
2// at https://cantera.org/license.txt for license and copyright information.
3
7#include "cantera/numerics/eigen_dense.h"
8
9namespace Cantera
10{
11
12BulkKinetics::BulkKinetics() {
13 setDerivativeSettings(AnyMap()); // use default settings
14}
15
16bool BulkKinetics::addReaction(shared_ptr<Reaction> r, bool resize)
17{
18 shared_ptr<ReactionRate> rate = r->rate();
19 if (rate) {
20 rate->setContext(*r, *this);
21 }
22
23 bool added = Kinetics::addReaction(r, resize);
24 if (!added) {
25 // undeclared species, etc.
26 return false;
27 }
28 double dn = 0.0;
29 for (const auto& [name, stoich] : r->products) {
30 dn += stoich;
31 }
32 for (const auto& [name, stoich] : r->reactants) {
33 dn -= stoich;
34 }
35
36 m_dn.push_back(dn);
37
38 string rtype = rate->subType();
39 if (rtype == "") {
40 rtype = rate->type();
41 }
42
43 // If necessary, add new MultiRate evaluator
44 if (m_rateTypes.find(rtype) == m_rateTypes.end()) {
45 m_rateTypes[rtype] = m_rateHandlers.size();
46 m_rateHandlers.push_back(rate->newMultiRate());
47 m_rateHandlers.back()->resize(*this);
48 }
49
50 // Set index of rate to number of reaction within kinetics
51 rate->setRateIndex(nReactions() - 1);
52
53 // Add reaction rate to evaluator
54 size_t index = m_rateTypes[rtype];
55 m_rateHandlers[index]->add(nReactions() - 1, *rate);
56
57 // Add reaction to third-body evaluator
58 if (r->thirdBody() != nullptr) {
59 addThirdBody(r);
60 }
61
62 m_concm.push_back(NAN);
63 return true;
64}
65
66void BulkKinetics::addThirdBody(shared_ptr<Reaction> r)
67{
68 map<size_t, double> efficiencies;
69 for (const auto& [name, efficiency] : r->thirdBody()->efficiencies) {
70 size_t k = kineticsSpeciesIndex(name, false);
71 if (k != npos) {
72 efficiencies[k] = efficiency;
73 } else if (!m_skipUndeclaredThirdBodies) {
74 throw CanteraError("BulkKinetics::addThirdBody", "Found third-body"
75 " efficiency for undefined species '{}' while adding reaction '{}'",
76 name, r->equation());
77 } else {
79 }
80 }
81 m_multi_concm.install(nReactions() - 1, efficiencies,
82 r->thirdBody()->default_efficiency,
83 r->thirdBody()->mass_action);
84}
85
86void BulkKinetics::modifyReaction(size_t i, shared_ptr<Reaction> rNew)
87{
88 // operations common to all reaction types
90
91 shared_ptr<ReactionRate> rate = rNew->rate();
92 string rtype = rate->subType();
93 if (rtype == "") {
94 rtype = rate->type();
95 }
96
97 // Ensure that MultiRate evaluator is available
98 if (m_rateTypes.find(rtype) == m_rateTypes.end()) {
99 throw CanteraError("BulkKinetics::modifyReaction",
100 "Evaluator not available for type '{}'.", rtype);
101 }
102
103 // Replace reaction rate to evaluator
104 size_t index = m_rateTypes[rtype];
105 rate->setRateIndex(i);
106 rate->setContext(*rNew, *this);
107 m_rateHandlers[index]->replace(i, *rate);
108 invalidateCache();
109}
110
112{
114 m_act_conc.resize(m_kk);
115 m_phys_conc.resize(m_kk);
116 m_grt.resize(m_kk);
117 for (auto& rates : m_rateHandlers) {
118 rates->resize(*this);
119 }
120}
121
123{
125 m_rbuf0.resize(nReactions());
126 m_rbuf1.resize(nReactions());
127 m_rbuf2.resize(nReactions());
128 m_kf0.resize(nReactions());
129 m_sbuf0.resize(nTotalSpecies());
130 m_state.resize(thermo().stateSize());
132 for (auto& rates : m_rateHandlers) {
133 rates->resize(*this);
134 // @todo ensure that ReactionData are updated; calling rates->update
135 // blocks correct behavior in update_rates_T
136 // and running updateROP() is premature
137 }
138}
139
140void BulkKinetics::setMultiplier(size_t i, double f)
141{
143 m_ROP_ok = false;
144}
145
146void BulkKinetics::invalidateCache()
147{
148 Kinetics::invalidateCache();
149 m_ROP_ok = false;
150}
151
153{
154 checkArraySize("BulkKinetics::getFwdRateConstants", kfwd.size(), nReactions());
155 updateROP();
156 copy(m_rfn.begin(), m_rfn.end(), kfwd.begin());
158 processThirdBodies(kfwd);
159 }
160}
161
163{
164 checkArraySize("BulkKinetics::getEquilibriumConstants", kc.size(), nReactions());
165 updateROP();
166
167 vector<double>& delta_gibbs0 = m_rbuf0;
168 fill(delta_gibbs0.begin(), delta_gibbs0.end(), 0.0);
169
170 // compute Delta G^0 for all reactions
171 getReactionDelta(m_grt, delta_gibbs0);
172
173 double rrt = 1.0 / thermo().RT();
174 double logStandConc = log(thermo().standardConcentration());
175 for (size_t i = 0; i < nReactions(); i++) {
176 kc[i] = exp(-delta_gibbs0[i] * rrt + m_dn[i] * logStandConc);
177 }
178}
179
180void BulkKinetics::getRevRateConstants(span<double> krev, bool doIrreversible)
181{
182 // go get the forward rate constants. -> note, we don't really care about
183 // speed or redundancy in these informational routines.
185
186 if (doIrreversible) {
188 for (size_t i = 0; i < nReactions(); i++) {
189 krev[i] /= m_rbuf0[i];
190 }
191 } else {
192 // m_rkcn[] is zero for irreversible reactions
193 for (size_t i = 0; i < nReactions(); i++) {
194 krev[i] *= m_rkcn[i];
195 }
196 }
197}
198
199void BulkKinetics::getDeltaGibbs(span<double> deltaG)
200{
201 // Get the chemical potentials for each species
202 thermo().getChemPotentials(m_sbuf0);
203 // Use the stoichiometric manager to find deltaG for each reaction.
204 getReactionDelta(m_sbuf0, deltaG);
205}
206
207void BulkKinetics::getDeltaEnthalpy(span<double> deltaH)
208{
209 // Get the partial molar enthalpy for each species
211 // Use the stoichiometric manager to find deltaH for each reaction.
212 getReactionDelta(m_sbuf0, deltaH);
213}
214
215void BulkKinetics::getDeltaEntropy(span<double> deltaS)
216{
217 // Get the partial molar entropy for each species
219 // Use the stoichiometric manager to find deltaS for each reaction.
220 getReactionDelta(m_sbuf0, deltaS);
221}
222
223void BulkKinetics::getDeltaSSGibbs(span<double> deltaG)
224{
225 // Get the standard state chemical potentials of the species. This is the
226 // array of chemical potentials at unit activity. We define these here as
227 // the chemical potentials of the pure species at the temperature and
228 // pressure of the solution.
230 // Use the stoichiometric manager to find deltaG for each reaction.
231 getReactionDelta(m_sbuf0, deltaG);
232}
233
234void BulkKinetics::getDeltaSSEnthalpy(span<double> deltaH)
235{
236 // Get the standard state enthalpies of the species.
237 thermo().getEnthalpy_RT(m_sbuf0);
238 for (size_t k = 0; k < m_kk; k++) {
239 m_sbuf0[k] *= thermo().RT();
240 }
241 // Use the stoichiometric manager to find deltaH for each reaction.
242 getReactionDelta(m_sbuf0, deltaH);
243}
244
245void BulkKinetics::getDeltaSSEntropy(span<double> deltaS)
246{
247 // Get the standard state entropy of the species. We define these here as
248 // the entropies of the pure species at the temperature and pressure of the
249 // solution.
250 thermo().getEntropy_R(m_sbuf0);
251 for (size_t k = 0; k < m_kk; k++) {
252 m_sbuf0[k] *= GasConstant;
253 }
254 // Use the stoichiometric manager to find deltaS for each reaction.
255 getReactionDelta(m_sbuf0, deltaS);
256}
257
259{
260 settings["skip-third-bodies"] = m_jac_skip_third_bodies;
261 settings["skip-falloff"] = m_jac_skip_falloff;
262 settings["rtol-delta"] = m_jac_rtol_delta;
263}
264
266{
267 bool force = settings.empty();
268 if (force || settings.hasKey("skip-third-bodies")) {
269 m_jac_skip_third_bodies = settings.getBool("skip-third-bodies", false);
270 }
271 if (force || settings.hasKey("skip-falloff")) {
272 m_jac_skip_falloff = settings.getBool("skip-falloff", false);
273 }
274 if (force || settings.hasKey("rtol-delta")) {
275 m_jac_rtol_delta = settings.getDouble("rtol-delta", 1e-8);
276 }
277}
278
280{
281 assertDerivativesValid("BulkKinetics::getFwdRateConstants_ddT");
282 updateROP();
283 process_ddT(m_rfn, dkfwd);
284}
285
287{
288 assertDerivativesValid("BulkKinetics::getFwdRatesOfProgress_ddT");
289 updateROP();
290 process_ddT(m_ropf, drop);
291}
292
294{
295 assertDerivativesValid("BulkKinetics::getRevRatesOfProgress_ddT");
296 updateROP();
297 process_ddT(m_ropr, drop);
298
299 // reverse rop times scaled inverse equilibrium constant derivatives
300 copy(m_ropr.begin(), m_ropr.end(), m_rbuf2.begin());
302 Eigen::Map<Eigen::VectorXd> dRevRop(drop.data(), nReactions());
303 Eigen::Map<Eigen::VectorXd> dRevRop2(m_rbuf2.data(), nReactions());
304 dRevRop += dRevRop2;
305}
306
308{
309 assertDerivativesValid("BulkKinetics::getNetRatesOfProgress_ddT");
310 updateROP();
311 process_ddT(m_ropnet, drop);
312
313 // reverse rop times scaled inverse equilibrium constant derivatives
314 copy(m_ropr.begin(), m_ropr.end(), m_rbuf2.begin());
316 Eigen::Map<Eigen::VectorXd> dNetRop(drop.data(), nReactions());
317 Eigen::Map<Eigen::VectorXd> dNetRop2(m_rbuf2.data(), nReactions());
318 dNetRop -= dNetRop2;
319}
320
322{
323 assertDerivativesValid("BulkKinetics::getFwdRateConstants_ddP");
324 updateROP();
325 process_ddP(m_rfn, dkfwd);
326}
327
329{
330 assertDerivativesValid("BulkKinetics::getFwdRatesOfProgress_ddP");
331 updateROP();
332 process_ddP(m_ropf, drop);
333}
334
336{
337 assertDerivativesValid("BulkKinetics::getRevRatesOfProgress_ddP");
338 updateROP();
339 process_ddP(m_ropr, drop);
340}
341
343{
344 assertDerivativesValid("BulkKinetics::getNetRatesOfProgress_ddP");
345 updateROP();
346 process_ddP(m_ropnet, drop);
347}
348
350{
351 assertDerivativesValid("BulkKinetics::getFwdRateConstants_ddC");
352 updateROP();
353 process_ddC(m_reactantStoich, m_rfn, dkfwd, false);
354}
355
357{
358 assertDerivativesValid("BulkKinetics::getFwdRatesOfProgress_ddC");
359 updateROP();
361}
362
364{
365 assertDerivativesValid("BulkKinetics::getRevRatesOfProgress_ddC");
366 updateROP();
368}
369
371{
372 assertDerivativesValid("BulkKinetics::getNetRatesOfProgress_ddC");
373 updateROP();
375 Eigen::Map<Eigen::VectorXd> dNetRop(drop.data(), nReactions());
376
378 Eigen::Map<Eigen::VectorXd> dNetRop2(m_rbuf2.data(), nReactions());
379 dNetRop -= dNetRop2;
380}
381
382Eigen::SparseMatrix<double> BulkKinetics::fwdRatesOfProgress_ddX()
383{
384 assertDerivativesValid("BulkKinetics::fwdRatesOfProgress_ddX");
385
386 // forward reaction rate coefficients
387 vector<double>& rop_rates = m_rbuf0;
388 getFwdRateConstants(rop_rates);
390}
391
392Eigen::SparseMatrix<double> BulkKinetics::revRatesOfProgress_ddX()
393{
394 assertDerivativesValid("BulkKinetics::revRatesOfProgress_ddX");
395
396 // reverse reaction rate coefficients
397 vector<double>& rop_rates = m_rbuf0;
398 getFwdRateConstants(rop_rates);
399 applyEquilibriumConstants(rop_rates);
401}
402
403Eigen::SparseMatrix<double> BulkKinetics::netRatesOfProgress_ddX()
404{
405 assertDerivativesValid("BulkKinetics::netRatesOfProgress_ddX");
406
407 // forward reaction rate coefficients
408 vector<double>& rop_rates = m_rbuf0;
409 getFwdRateConstants(rop_rates);
411
412 // reverse reaction rate coefficients
413 applyEquilibriumConstants(rop_rates);
415}
416
417Eigen::SparseMatrix<double> BulkKinetics::fwdRatesOfProgress_ddCi()
418{
419 assertDerivativesValid("BulkKinetics::fwdRatesOfProgress_ddCi");
420
421 // forward reaction rate coefficients
422 vector<double>& rop_rates = m_rbuf0;
423 getFwdRateConstants(rop_rates);
424 return calculateCompositionDerivatives(m_reactantStoich, rop_rates, false);
425}
426
427Eigen::SparseMatrix<double> BulkKinetics::revRatesOfProgress_ddCi()
428{
429 assertDerivativesValid("BulkKinetics::revRatesOfProgress_ddCi");
430
431 // reverse reaction rate coefficients
432 vector<double>& rop_rates = m_rbuf0;
433 getFwdRateConstants(rop_rates);
434 applyEquilibriumConstants(rop_rates);
435 return calculateCompositionDerivatives(m_revProductStoich, rop_rates, false);
436}
437
438Eigen::SparseMatrix<double> BulkKinetics::netRatesOfProgress_ddCi()
439{
440 assertDerivativesValid("BulkKinetics::netRatesOfProgress_ddCi");
441
442 // forward reaction rate coefficients
443 vector<double>& rop_rates = m_rbuf0;
444 getFwdRateConstants(rop_rates);
445 auto jac = calculateCompositionDerivatives(m_reactantStoich, rop_rates, false);
446
447 // reverse reaction rate coefficients
448 applyEquilibriumConstants(rop_rates);
449 return jac - calculateCompositionDerivatives(m_revProductStoich, rop_rates, false);
450}
451
452void BulkKinetics::updateROP()
453{
454 static const int cacheId = m_cache.getId();
455 CachedScalar last = m_cache.getScalar(cacheId);
456 double T = thermo().temperature();
457 double rho = thermo().density();
458 int statenum = thermo().stateMFNumber();
459
460 if (last.state1 != T || last.state2 != rho) {
461 // Update properties that are independent of the composition
463 fill(m_delta_gibbs0.begin(), m_delta_gibbs0.end(), 0.0);
464 double logStandConc = log(thermo().standardConcentration());
465
466 // compute Delta G^0 for all reversible reactions
468
469 double rrt = 1.0 / thermo().RT();
470 for (size_t i = 0; i < m_revindex.size(); i++) {
471 size_t irxn = m_revindex[i];
472 m_rkcn[irxn] = std::min(
473 exp(m_delta_gibbs0[irxn] * rrt - m_dn[irxn] * logStandConc), BigNumber);
474 }
475
476 for (size_t i = 0; i != m_irrev.size(); ++i) {
477 m_rkcn[ m_irrev[i] ] = 0.0;
478 }
479 }
480
481 if (!last.validate(T, rho, statenum)) {
482 // Update terms dependent on species concentrations and temperature
485 double ctot = thermo().molarDensity();
486
487 // Third-body objects interacting with MultiRate evaluator
489 m_ROP_ok = false;
490 }
491
492 // loop over MultiRate evaluators for each reaction type
493 for (auto& rates : m_rateHandlers) {
494 bool changed = rates->update(thermo(), *this);
495 if (changed) {
496 rates->getRateConstants(m_kf0);
497 m_ROP_ok = false;
498 }
499 }
500
501 if (m_ROP_ok) {
502 // rates of progress are up-to-date only if both the thermodynamic state
503 // and m_perturb are unchanged
504 return;
505 }
506
507 // Scale the forward rate coefficient by the perturbation factor
508 for (size_t i = 0; i < nReactions(); ++i) {
509 m_rfn[i] = m_kf0[i] * m_perturb[i];
510 }
511
512 copy(m_rfn.begin(), m_rfn.end(), m_ropf.begin());
514 copy(m_ropf.begin(), m_ropf.end(), m_ropr.begin());
515
516 // for reversible reactions, multiply ropr by concentration products
518
519 for (auto& rates : m_rateHandlers) {
520 rates->modifyRateConstants(m_ropf, m_ropr);
521 }
522
523 // multiply ropf and ropr by concentration products
526
527 for (size_t j = 0; j != nReactions(); ++j) {
528 m_ropnet[j] = m_ropf[j] - m_ropr[j];
529 }
530
531 for (size_t i = 0; i < m_rfn.size(); i++) {
532 AssertFinite(m_rfn[i], "BulkKinetics::updateROP",
533 "m_rfn[{}] is not finite.", i);
534 AssertFinite(m_ropf[i], "BulkKinetics::updateROP",
535 "m_ropf[{}] is not finite.", i);
536 AssertFinite(m_ropr[i], "BulkKinetics::updateROP",
537 "m_ropr[{}] is not finite.", i);
538 }
539 m_ROP_ok = true;
540}
541
543{
544 checkArraySize("BulkKinetics::getThirdBodyConcentrations", concm.size(), nReactions());
545 updateROP();
546 std::copy(m_concm.begin(), m_concm.end(), concm.begin());
547}
548
550{
551 // reactions involving third body
552 if (!m_concm.empty()) {
554 }
555}
556
558{
559 // For reverse rates computed from thermochemistry, multiply the forward
560 // rate coefficients by the reciprocals of the equilibrium constants
561 for (size_t i = 0; i < nReactions(); ++i) {
562 rop[i] *= m_rkcn[i];
563 }
564}
565
567{
568 double T = thermo().temperature();
569 double P = thermo().pressure();
570 double rrt = 1. / thermo().RT();
571
572 vector<double>& grt = m_sbuf0;
573 vector<double>& delta_gibbs0 = m_rbuf1;
574 fill(delta_gibbs0.begin(), delta_gibbs0.end(), 0.0);
575
576 // compute perturbed Delta G^0 for all reversible reactions
577 thermo().saveState(m_state);
578 thermo().setState_TP(T * (1. + m_jac_rtol_delta), P);
580 getRevReactionDelta(grt, delta_gibbs0);
581
582 // apply scaling for derivative of inverse equilibrium constant
583 double Tinv = 1. / T;
584 double rrt_dTinv = rrt * Tinv / m_jac_rtol_delta;
585 double rrtt = rrt * Tinv;
586 for (size_t i = 0; i < m_revindex.size(); i++) {
587 size_t irxn = m_revindex[i];
588 double factor = delta_gibbs0[irxn] - m_delta_gibbs0[irxn];
589 factor *= rrt_dTinv;
590 factor += m_dn[irxn] * Tinv - m_delta_gibbs0[irxn] * rrtt;
591 drkcn[irxn] *= factor;
592 }
593
594 for (size_t i = 0; i < m_irrev.size(); ++i) {
595 drkcn[m_irrev[i]] = 0.0;
596 }
597
598 thermo().restoreState(m_state);
599}
600
601void BulkKinetics::process_ddT(span<const double> in, span<double> drop)
602{
603 // apply temperature derivative
604 copy(in.begin(), in.end(), drop.begin());
605 for (auto& rates : m_rateHandlers) {
606 rates->processRateConstants_ddT(drop, m_rfn, m_jac_rtol_delta);
607 }
608}
609
610void BulkKinetics::process_ddP(span<const double> in, span<double> drop)
611{
612 // apply pressure derivative
613 copy(in.begin(), in.end(), drop.begin());
614 for (auto& rates : m_rateHandlers) {
615 rates->processRateConstants_ddP(drop, m_rfn, m_jac_rtol_delta);
616 }
617}
618
619void BulkKinetics::process_ddC(StoichManagerN& stoich, span<const double> in,
620 span<double> drop, bool mass_action)
621{
622 Eigen::Map<Eigen::VectorXd> out(drop.data(), nReactions());
623 out.setZero();
624 double ctot_inv = 1. / thermo().molarDensity();
625
626 // derivatives due to concentrations in law of mass action
627 if (mass_action) {
628 stoich.scale(in, span<double>(out.data(), nReactions()), ctot_inv);
629 }
631 return;
632 }
633
634 // derivatives due to third-body colliders in law of mass action
635 Eigen::Map<Eigen::VectorXd> outM(m_rbuf1.data(), nReactions());
636 if (mass_action) {
637 outM.fill(0.);
638 m_multi_concm.scale(in, asSpan(outM), ctot_inv);
639 out += outM;
640 }
641
642 // derivatives due to reaction rates depending on third-body colliders
643 if (!m_jac_skip_falloff) {
644 m_multi_concm.scaleM(in, asSpan(outM), m_concm, ctot_inv);
645 for (auto& rates : m_rateHandlers) {
646 // processing step assigns zeros to entries not dependent on M
647 rates->processRateConstants_ddM(asSpan(outM), m_rfn, m_jac_rtol_delta);
648 }
649 out += outM;
650 }
651}
652
654 StoichManagerN& stoich, span<const double> in, bool ddX)
655{
656 Eigen::SparseMatrix<double> out;
657 vector<double>& scaled = m_rbuf1;
658 vector<double>& outV = m_rbuf2;
659
660 // convert from concentration to mole fraction output
661 copy(in.begin(), in.end(), scaled.begin());
662 if (ddX) {
663 double ctot = thermo().molarDensity();
664 for (size_t i = 0; i < nReactions(); ++i) {
665 scaled[i] *= ctot;
666 }
667 }
668
669 // derivatives handled by StoichManagerN
670 copy(scaled.begin(), scaled.end(), outV.begin());
671 processThirdBodies(outV);
672 out = stoich.derivatives(m_act_conc, outV);
674 return out;
675 }
676
677 // derivatives due to law of mass action
678 copy(scaled.begin(), scaled.end(), outV.begin());
679 stoich.multiply(m_act_conc, outV);
680
681 // derivatives due to reaction rates depending on third-body colliders
682 if (!m_jac_skip_falloff) {
683 for (auto& rates : m_rateHandlers) {
684 // processing step does not modify entries not dependent on M
685 rates->processRateConstants_ddM(outV, m_rfn, m_jac_rtol_delta, false);
686 }
687 }
688
689 // derivatives handled by ThirdBodyCalc
690 out += m_multi_concm.derivatives(outV);
691 return out;
692}
693
695{
696 if (!thermo().isIdeal()) {
697 throw NotImplementedError(name,
698 "Not supported for non-ideal ThermoPhase models.");
699 }
700}
701
702}
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:431
double getDouble(const string &key, double default_) const
If key exists, return it as a double, otherwise return default_.
Definition AnyMap.cpp:1580
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1477
bool empty() const
Return boolean indicating whether AnyMap is empty.
Definition AnyMap.cpp:1468
bool getBool(const string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
Definition AnyMap.cpp:1575
bool addReaction(shared_ptr< Reaction > r, bool resize=true) override
Add a single reaction to the mechanism.
Eigen::SparseMatrix< double > netRatesOfProgress_ddX() override
Calculate derivatives for net rates-of-progress with respect to species mole fractions at constant te...
void applyEquilibriumConstants(span< double > rop)
Multiply rate with inverse equilibrium constant.
Eigen::SparseMatrix< double > revRatesOfProgress_ddCi() override
Calculate derivatives for forward rates-of-progress with respect to species concentration at constant...
void getRevRatesOfProgress_ddP(span< double > drop) override
Calculate derivatives for reverse rates-of-progress with respect to pressure at constant temperature,...
void process_ddT(const span< const double > in, span< double > drop)
Process temperature derivative.
Eigen::SparseMatrix< double > calculateCompositionDerivatives(StoichManagerN &stoich, span< const double > in, bool ddX=true)
Process derivatives.
void getDeltaEnthalpy(span< double > deltaH) override
Return the vector of values for the reactions change in enthalpy.
void getEquilibriumConstants(span< double > kc) override
Return a vector of Equilibrium constants.
Eigen::SparseMatrix< double > fwdRatesOfProgress_ddX() override
Calculate derivatives for forward rates-of-progress with respect to species mole fractions at constan...
void getFwdRatesOfProgress_ddT(span< double > drop) override
Calculate derivatives for forward rates-of-progress with respect to temperature at constant pressure,...
vector< double > m_phys_conc
Physical concentrations, as calculated by ThermoPhase::getConcentrations.
void getRevRatesOfProgress_ddC(span< double > drop) override
Calculate derivatives for reverse rates-of-progress with respect to molar concentration at constant t...
Eigen::SparseMatrix< double > revRatesOfProgress_ddX() override
Calculate derivatives for reverse rates-of-progress with respect to species mole fractions at constan...
void getNetRatesOfProgress_ddT(span< double > drop) override
Calculate derivatives for net rates-of-progress with respect to temperature at constant pressure,...
void getNetRatesOfProgress_ddP(span< double > drop) override
Calculate derivatives for net rates-of-progress with respect to pressure at constant temperature,...
void assertDerivativesValid(const string &name)
Helper function ensuring that all rate derivatives can be calculated.
void getFwdRateConstants(span< double > kfwd) override
Return the forward rate constants.
void process_ddC(StoichManagerN &stoich, span< const double > in, span< double > drop, bool mass_action=true)
Process concentration (molar density) derivative.
void applyEquilibriumConstants_ddT(span< double > drkcn)
Multiply rate with scaled temperature derivatives of the inverse equilibrium constant.
void setMultiplier(size_t i, double f) override
Set the multiplier for reaction i to f.
vector< double > m_dn
Difference between the global reactants order and the global products order.
void process_ddP(const span< const double > in, span< double > drop)
Process pressure derivative.
void getDeltaSSGibbs(span< double > deltaG) override
Return the vector of values for the reaction standard state Gibbs free energy change.
void processThirdBodies(span< double > rop)
Multiply rate with third-body collider concentrations.
bool m_jac_skip_third_bodies
Derivative settings.
void resizeSpecies() override
Resize arrays with sizes that depend on the total number of species.
vector< double > m_grt
Standard chemical potentials for each species.
vector< double > m_act_conc
Activity concentrations, as calculated by ThermoPhase::getActivityConcentrations.
void getFwdRateConstants_ddC(span< double > dkfwd) override
Calculate derivatives for forward rate constants with respect to molar concentration at constant temp...
void getDerivativeSettings(AnyMap &settings) const override
Retrieve derivative settings.
void getNetRatesOfProgress_ddC(span< double > drop) override
Calculate derivatives for net rates-of-progress with respect to molar concentration at constant tempe...
Eigen::SparseMatrix< double > fwdRatesOfProgress_ddCi() override
Calculate derivatives for forward rates-of-progress with respect to species concentration at constant...
void modifyReaction(size_t i, shared_ptr< Reaction > rNew) override
Modify the rate expression associated with a reaction.
void getRevRateConstants(span< double > krev, bool doIrreversible=false) override
Return the reverse rate constants.
vector< double > m_rbuf0
Buffers for partial rop results with length nReactions()
void getDeltaSSEnthalpy(span< double > deltaH) override
Return the vector of values for the change in the standard state enthalpies of reaction.
void getFwdRatesOfProgress_ddP(span< double > drop) override
Calculate derivatives for forward rates-of-progress with respect to pressure at constant temperature,...
void getDeltaEntropy(span< double > deltaS) override
Return the vector of values for the reactions change in entropy.
ThirdBodyCalc m_multi_concm
used with MultiRate evaluator
void getDeltaSSEntropy(span< double > deltaS) override
Return the vector of values for the change in the standard state entropies for each reaction.
void resizeReactions() override
Finalize Kinetics object and associated objects.
void getFwdRateConstants_ddP(span< double > dkfwd) override
Calculate derivatives for forward rate constants with respect to pressure at constant temperature,...
void getRevRatesOfProgress_ddT(span< double > drop) override
Calculate derivatives for reverse rates-of-progress with respect to temperature at constant pressure,...
void getThirdBodyConcentrations(span< double > concm) override
Return a vector of values of effective concentrations of third-body collision partners of any reactio...
Eigen::SparseMatrix< double > netRatesOfProgress_ddCi() override
Calculate derivatives for net rates-of-progress with respect to species concentration at constant tem...
void getFwdRateConstants_ddT(span< double > dkfwd) override
Calculate derivatives for forward rate constants with respect to temperature at constant pressure,...
void getDeltaGibbs(span< double > deltaG) override
Return the vector of values for the reaction Gibbs free energy change.
vector< double > m_concm
Third body concentrations.
vector< double > m_kf0
Forward rate constants without perturbation.
void setDerivativeSettings(const AnyMap &settings) override
Set/modify derivative settings.
void getFwdRatesOfProgress_ddC(span< double > drop) override
Calculate derivatives for forward rates-of-progress with respect to molar concentration at constant t...
Base class for exceptions thrown by Cantera classes.
virtual void resizeReactions()
Finalize Kinetics object and associated objects.
Definition Kinetics.cpp:50
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
Definition Kinetics.h:239
ValueCache m_cache
Cache for saved calculations within each Kinetics object.
Definition Kinetics.h:1434
vector< double > m_perturb
Vector of perturbation factors for each reaction's rate of progress vector.
Definition Kinetics.h:1484
vector< double > m_ropf
Forward rate-of-progress for each reaction.
Definition Kinetics.h:1532
vector< unique_ptr< MultiRateBase > > m_rateHandlers
Vector of rate handlers.
Definition Kinetics.h:1455
vector< double > m_rkcn
Reciprocal of the equilibrium constant in concentration units.
Definition Kinetics.h:1529
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
Definition Kinetics.h:1480
vector< double > m_ropr
Reverse rate-of-progress for each reaction.
Definition Kinetics.h:1535
virtual bool addReaction(shared_ptr< Reaction > r, bool resize=true)
Add a single reaction to the mechanism.
Definition Kinetics.cpp:704
vector< size_t > m_revindex
Indices of reversible reactions.
Definition Kinetics.h:1540
bool m_skipUndeclaredThirdBodies
See skipUndeclaredThirdBodies()
Definition Kinetics.h:1553
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
Definition Kinetics.cpp:797
map< string, size_t > m_rateTypes
Mapping of rate handlers.
Definition Kinetics.h:1456
vector< double > m_ropnet
Net rate-of-progress for each reaction.
Definition Kinetics.h:1538
virtual void getRevReactionDelta(span< const double > g, span< double > dg) const
Given an array of species properties 'g', return in array 'dg' the change in this quantity in the rev...
Definition Kinetics.cpp:408
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
Definition Kinetics.h:1472
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition Kinetics.h:161
vector< size_t > m_irrev
Indices of irreversible reactions.
Definition Kinetics.h:1541
bool m_hasUndeclaredThirdBodies
Flag indicating whether reactions include undeclared third bodies.
Definition Kinetics.h:1556
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
Definition Kinetics.h:273
virtual void getReactionDelta(span< const double > property, span< double > deltaProperty) const
Change in species properties.
Definition Kinetics.cpp:396
virtual void setMultiplier(size_t i, double f)
Set the multiplier for reaction i to f.
Definition Kinetics.h:1377
vector< double > m_rfn
Forward rate constant for each reaction.
Definition Kinetics.h:1523
StoichManagerN m_reactantStoich
Stoichiometry manager for the reactants for each reaction.
Definition Kinetics.h:1466
virtual void resizeSpecies()
Resize arrays with sizes that depend on the total number of species.
Definition Kinetics.cpp:692
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
Definition Kinetics.h:251
vector< double > m_delta_gibbs0
Delta G^0 for all reactions.
Definition Kinetics.h:1526
An error indicating that an unimplemented function has been called.
virtual double molarDensity() const
Molar density (kmol/m^3).
Definition Phase.cpp:587
double temperature() const
Temperature (K).
Definition Phase.h:585
virtual void getConcentrations(span< double > c) const
Get the species concentrations (kmol/m^3).
Definition Phase.cpp:491
virtual double density() const
Density (kg/m^3).
Definition Phase.h:610
int stateMFNumber() const
Return the State Mole Fraction Number.
Definition Phase.h:794
virtual void restoreState(span< const double > state)
Restore the state of the phase from a previously saved state vector.
Definition Phase.cpp:269
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition Phase.h:603
virtual void saveState(span< double > state) const
Write to array 'state' the current internal state.
Definition Phase.cpp:257
This class handles operations involving the stoichiometric coefficients on one side of a reaction (re...
Eigen::SparseMatrix< double > derivatives(span< const double > conc, span< const double > rates)
Calculate derivatives with respect to species concentrations.
void scale(span< const double > in, span< double > out, double factor) const
Scale input by reaction order and factor.
virtual void getPartialMolarEnthalpies(span< double > hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void setState_TP(double t, double p)
Set the temperature (K) and pressure (Pa)
double RT() const
Return the Gas Constant multiplied by the current temperature.
virtual void getPartialMolarEntropies(span< double > sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual void getStandardChemPotentials(span< double > mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
virtual void getActivityConcentrations(span< double > c) const
This method returns an array of generalized concentrations.
virtual void getEntropy_R(span< double > sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
virtual void getEnthalpy_RT(span< double > hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
virtual void getChemPotentials(span< double > mu) const
Get the species chemical potentials. Units: J/kmol.
bool empty() const
Return boolean indicating whether ThirdBodyCalc is empty.
void install(size_t rxnNumber, const map< size_t, double > &efficiencies, double default_efficiency, bool mass_action)
Install reaction that uses third-body effects in ThirdBodyCalc manager.
void update(span< const double > conc, double ctot, span< double > concm) const
Update third-body concentrations in full vector.
Eigen::SparseMatrix< double > derivatives(span< const double > product)
Calculate derivatives with respect to species concentrations.
void multiply(span< double > output, span< const double > concm)
Multiply output with effective third-body concentration.
void scale(span< const double > in, span< double > out, double factor) const
Scale entries involving third-body collider in law of mass action by factor.
void resizeCoeffs(size_t nSpc, size_t nRxn)
Resize the sparse coefficient matrix.
void scaleM(span< const double > in, span< double > out, span< const double > concm, double factor) const
Scale entries involving third-body collider in rate expression by third-body concentration and factor...
CachedScalar getScalar(int id)
Get a reference to a CachedValue object representing a scalar (double) with the given id.
Definition ValueCache.h:161
int getId()
Get a unique id for a cached value.
#define AssertFinite(expr, procedure,...)
Throw an exception if the specified exception is not a finite number.
bool legacy_rate_constants_used()
Returns true if legacy rate constant definition is used.
Definition global.cpp:107
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:123
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:183
span< double > asSpan(Eigen::DenseBase< Derived > &v)
Convenience wrapper for accessing Eigen vector/array/map data as a span.
Definition eigen_dense.h:46
const double BigNumber
largest number to compare to inf.
Definition ct_defs.h:163
void checkArraySize(const char *procedure, size_t available, size_t required)
Wrapper for throwing ArraySizeError.
A cached property value and the state at which it was evaluated.
Definition ValueCache.h:33
double state2
Value of the second state variable for the state at which value was evaluated, for example density or...
Definition ValueCache.h:106
bool validate(double state1New)
Check whether the currently cached value is valid based on a single state variable.
Definition ValueCache.h:39
double state1
Value of the first state variable for the state at which value was evaluated, for example temperature...
Definition ValueCache.h:102