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