Cantera 2.6.0
GasKinetics.cpp
Go to the documentation of this file.
1/**
2 * @file GasKinetics.cpp Homogeneous kinetics in ideal gases
3 */
4
5// This file is part of Cantera. See License.txt in the top-level directory or
6// at https://cantera.org/license.txt for license and copyright information.
7
10
11using namespace std;
12
13namespace Cantera
14{
16 BulkKinetics(thermo),
17 m_logStandConc(0.0),
18 m_pres(0.0)
19{
20 setDerivativeSettings(AnyMap()); // use default settings
21}
22
24{
25 m_rbuf0.resize(nReactions());
26 m_rbuf1.resize(nReactions());
27 m_rbuf2.resize(nReactions());
28 m_sbuf0.resize(nTotalSpecies());
29 m_state.resize(thermo().stateSize());
30
32}
33
35{
36 updateROP();
37 std::copy(m_concm.begin(), m_concm.end(), concm);
38}
39
41{
42 double T = thermo().temperature();
43 double P = thermo().pressure();
44 m_logStandConc = log(thermo().standardConcentration());
45 double logT = log(T);
46
47 if (T != m_temp) {
48 // Update forward rate constant for each reaction
49 if (!m_rfn.empty()) {
50 m_rates.update(T, logT, m_rfn.data());
51 }
52
53 // Falloff reactions (legacy)
54 if (!m_rfn_low.empty()) {
55 m_falloff_low_rates.update(T, logT, m_rfn_low.data());
56 m_falloff_high_rates.update(T, logT, m_rfn_high.data());
57 }
58 if (!falloff_work.empty()) {
60 }
61
62 updateKc();
63 m_ROP_ok = false;
64 }
65
66 // loop over MultiRate evaluators for each reaction type
67 for (auto& rates : m_bulk_rates) {
68 bool changed = rates->update(thermo(), *this);
69 if (changed) {
70 rates->getRateConstants(m_rfn.data());
71 m_ROP_ok = false;
72 }
73 }
74 if (T != m_temp || P != m_pres) {
75 // P-log reactions (legacy)
76 if (m_plog_rates.nReactions()) {
77 m_plog_rates.update(T, logT, m_rfn.data());
78 m_ROP_ok = false;
79 }
80
81 // Chebyshev reactions (legacy)
82 if (m_cheb_rates.nReactions()) {
83 m_cheb_rates.update(T, logT, m_rfn.data());
84 m_ROP_ok = false;
85 }
86 }
87 m_pres = P;
88 m_temp = T;
89}
90
92{
95 doublereal ctot = thermo().molarDensity();
96
97 // Third-body objects interacting with MultiRate evaluator
99
100 // 3-body reactions (legacy)
101 if (!concm_3b_values.empty()) {
102 m_3b_concm.update(m_phys_conc, ctot, concm_3b_values.data());
104 }
105
106 // Falloff reactions (legacy)
107 if (!concm_falloff_values.empty()) {
110 }
111
112 // P-log reactions (legacy)
113 if (m_plog_rates.nReactions()) {
114 double logP = log(thermo().pressure());
115 m_plog_rates.update_C(&logP);
116 }
117
118 // Chebyshev reactions (legacy)
119 if (m_cheb_rates.nReactions()) {
120 double log10P = log10(thermo().pressure());
121 m_cheb_rates.update_C(&log10P);
122 }
123
124 m_ROP_ok = false;
125}
126
128{
129 thermo().getStandardChemPotentials(m_grt.data());
130 fill(m_delta_gibbs0.begin(), m_delta_gibbs0.end(), 0.0);
131
132 // compute Delta G^0 for all reversible reactions
133 getRevReactionDelta(m_grt.data(), m_delta_gibbs0.data());
134
135 double rrt = 1.0 / thermo().RT();
136 for (size_t i = 0; i < m_revindex.size(); i++) {
137 size_t irxn = m_revindex[i];
138 m_rkcn[irxn] = std::min(
139 exp(m_delta_gibbs0[irxn] * rrt - m_dn[irxn] * m_logStandConc),
140 BigNumber);
141 }
142
143 for (size_t i = 0; i != m_irrev.size(); ++i) {
144 m_rkcn[ m_irrev[i] ] = 0.0;
145 }
146}
147
149{
152
153 // copy rate coefficients into ropf
154 copy(m_rfn.begin(), m_rfn.end(), ropf);
155
156 if (m_falloff_high_rates.nReactions()) {
158 }
159
160 // Scale the forward rate coefficient by the perturbation factor
161 for (size_t i = 0; i < nReactions(); ++i) {
162 ropf[i] *= m_perturb[i];
163 }
164}
165
167{
168 // multiply rop by enhanced 3b conc for all 3b rxns
169 if (!concm_3b_values.empty()) {
170 m_3b_concm.multiply(rop, concm_3b_values.data());
171 }
172
173 // reactions involving third body
174 if (!m_concm.empty()) {
175 m_multi_concm.multiply(rop, m_concm.data());
176 }
177}
178
180{
181 // For reverse rates computed from thermochemistry, multiply the forward
182 // rate coefficients by the reciprocals of the equilibrium constants
183 for (size_t i = 0; i < nReactions(); ++i) {
184 rop[i] *= m_rkcn[i];
185 }
186}
187
189{
190 update_rates_T(); // this step ensures that m_grt is updated
191
192 vector_fp& delta_gibbs0 = m_rbuf0;
193 fill(delta_gibbs0.begin(), delta_gibbs0.end(), 0.0);
194
195 // compute Delta G^0 for all reactions
196 getReactionDelta(m_grt.data(), delta_gibbs0.data());
197
198 double rrt = 1.0 / thermo().RT();
199 for (size_t i = 0; i < nReactions(); i++) {
200 kc[i] = exp(-delta_gibbs0[i] * rrt + m_dn[i] * m_logStandConc);
201 }
202}
203
205{
206 // use m_ropr for temporary storage of reduced pressure
207 vector_fp& pr = m_ropr;
208
209 for (size_t i = 0; i < m_falloff_low_rates.nReactions(); i++) {
210 pr[i] = concm_falloff_values[i] * m_rfn_low[i] / (m_rfn_high[i] + SmallNumber);
211 AssertFinite(pr[i], "GasKinetics::processFalloffReactions",
212 "pr[{}] is not finite.", i);
213 }
214
215 m_falloffn.pr_to_falloff(pr.data(), falloff_work.data());
216
217 for (size_t i = 0; i < m_falloff_low_rates.nReactions(); i++) {
218 if (reactionTypeStr(m_fallindx[i]) == "falloff-legacy") {
219 pr[i] *= m_rfn_high[i];
220 } else { // CHEMACT_RXN
221 pr[i] *= m_rfn_low[i];
222 }
223 ropf[m_fallindx[i]] = pr[i];
224 }
225}
226
227void GasKinetics::updateROP()
228{
231 copy(m_ropf.begin(), m_ropf.end(), m_ropr.begin());
232
233 // multiply ropf by concentration products
234 m_reactantStoich.multiply(m_act_conc.data(), m_ropf.data());
235
236 // for reversible reactions, multiply ropr by concentration products
238 m_revProductStoich.multiply(m_act_conc.data(), m_ropr.data());
239 for (size_t j = 0; j != nReactions(); ++j) {
240 m_ropnet[j] = m_ropf[j] - m_ropr[j];
241 }
242
243 for (size_t i = 0; i < m_rfn.size(); i++) {
244 AssertFinite(m_rfn[i], "GasKinetics::updateROP",
245 "m_rfn[{}] is not finite.", i);
246 AssertFinite(m_ropf[i], "GasKinetics::updateROP",
247 "m_ropf[{}] is not finite.", i);
248 AssertFinite(m_ropr[i], "GasKinetics::updateROP",
249 "m_ropr[{}] is not finite.", i);
250 }
251 m_ROP_ok = true;
252}
253
255{
257
259 warn_deprecated("GasKinetics::getFwdRateConstants",
260 "Behavior to change after Cantera 2.6;\nresults will no longer include "
261 "third-body concentrations for three-body reactions.\nTo switch to new "
262 "behavior, use 'cantera.use_legacy_rate_constants(False)' (Python),\n"
263 "'useLegacyRateConstants(0)' (MATLAB), 'Cantera::use_legacy_rate_constants"
264 "(false)' (C++),\nor 'ct_use_legacy_rate_constants(0)' (clib).");
265
267 }
268
269 // copy result
270 copy(m_ropf.begin(), m_ropf.end(), kfwd);
271}
272
274{
275 settings["skip-third-bodies"] = m_jac_skip_third_bodies;
276 settings["skip-falloff"] = m_jac_skip_falloff;
277 settings["rtol-delta"] = m_jac_rtol_delta;
278}
279
281{
282 bool force = settings.empty();
283 if (force || settings.hasKey("skip-third-bodies")) {
284 m_jac_skip_third_bodies = settings.getBool("skip-third-bodies", false);
285 }
286 if (force || settings.hasKey("skip-falloff")) {
287 m_jac_skip_falloff = settings.getBool("skip-falloff", false);
288 }
289 if (force || settings.hasKey("rtol-delta")) {
290 m_jac_rtol_delta = settings.getDouble("rtol-delta", 1e-8);
291 }
292}
293
294void GasKinetics::assertDerivativesValid(const std::string& name)
295{
296 if (m_legacy.size()) {
297 // Do not support legacy CTI/XML-based reaction rate evaluators
298 throw CanteraError(name, "Not supported for legacy (CTI/XML) input format.");
299 }
300
301 if (!thermo().isIdeal()) {
302 throw NotImplementedError(name,
303 "Not supported for non-ideal ThermoPhase models.");
304 }
305}
306
308{
309 double T = thermo().temperature();
310 double P = thermo().pressure();
311 double rrt = 1. / thermo().RT();
312
313 vector_fp& grt = m_sbuf0;
314 vector_fp& delta_gibbs0 = m_rbuf1;
315 fill(delta_gibbs0.begin(), delta_gibbs0.end(), 0.0);
316
317 // compute perturbed Delta G^0 for all reversible reactions
318 thermo().saveState(m_state);
319 thermo().setState_TP(T * (1. + m_jac_rtol_delta), P);
320 thermo().getStandardChemPotentials(grt.data());
321 getRevReactionDelta(grt.data(), delta_gibbs0.data());
322
323 // apply scaling for derivative of inverse equilibrium constant
324 double Tinv = 1. / T;
325 double rrt_dTinv = rrt * Tinv / m_jac_rtol_delta;
326 double rrtt = rrt * Tinv;
327 for (size_t i = 0; i < m_revindex.size(); i++) {
328 size_t irxn = m_revindex[i];
329 double factor = delta_gibbs0[irxn] - m_delta_gibbs0[irxn];
330 factor *= rrt_dTinv;
331 factor += m_dn[irxn] * Tinv - m_delta_gibbs0[irxn] * rrtt;
332 drkcn[irxn] *= factor;
333 }
334
335 for (size_t i = 0; i < m_irrev.size(); ++i) {
336 drkcn[m_irrev[i]] = 0.0;
337 }
338
339 thermo().restoreState(m_state);
340}
341
342void GasKinetics::process_ddT(const vector_fp& in, double* drop)
343{
344 // apply temperature derivative
345 copy(in.begin(), in.end(), drop);
346 for (auto& rates : m_bulk_rates) {
347 rates->processRateConstants_ddT(drop, m_rfn.data(), m_jac_rtol_delta);
348 }
349}
350
352{
353 assertDerivativesValid("GasKinetics::getFwdRateConstants_ddT");
354 updateROP();
355 process_ddT(m_rfn, dkfwd);
356}
357
359{
360 assertDerivativesValid("GasKinetics::getFwdRatesOfProgress_ddT");
361 updateROP();
362 process_ddT(m_ropf, drop);
363}
364
366{
367 assertDerivativesValid("GasKinetics::getRevRatesOfProgress_ddT");
368 updateROP();
369 process_ddT(m_ropr, drop);
370 Eigen::Map<Eigen::VectorXd> dRevRop(drop, nReactions());
371
372 // reverse rop times scaled inverse equilibrium constant derivatives
373 Eigen::Map<Eigen::VectorXd> dRevRop2(m_rbuf2.data(), nReactions());
374 copy(m_ropr.begin(), m_ropr.end(), m_rbuf2.begin());
375 processEquilibriumConstants_ddT(dRevRop2.data());
376 dRevRop += dRevRop2;
377}
378
380{
381 assertDerivativesValid("GasKinetics::getNetRatesOfProgress_ddT");
382 updateROP();
383 process_ddT(m_ropnet, drop);
384 Eigen::Map<Eigen::VectorXd> dNetRop(drop, nReactions());
385
386 // reverse rop times scaled inverse equilibrium constant derivatives
387 Eigen::Map<Eigen::VectorXd> dNetRop2(m_rbuf2.data(), nReactions());
388 copy(m_ropr.begin(), m_ropr.end(), m_rbuf2.begin());
389 processEquilibriumConstants_ddT(dNetRop2.data());
390 dNetRop -= dNetRop2;
391}
392
393void GasKinetics::process_ddP(const vector_fp& in, double* drop)
394{
395 // apply pressure derivative
396 copy(in.begin(), in.end(), drop);
397 for (auto& rates : m_bulk_rates) {
398 rates->processRateConstants_ddP(drop, m_rfn.data(), m_jac_rtol_delta);
399 }
400}
401
403{
404 assertDerivativesValid("GasKinetics::getFwdRateConstants_ddP");
405 updateROP();
406 process_ddP(m_rfn, dkfwd);
407}
408
410{
411 assertDerivativesValid("GasKinetics::getFwdRatesOfProgress_ddP");
412 updateROP();
413 process_ddP(m_ropf, drop);
414}
415
417{
418 assertDerivativesValid("GasKinetics::getRevRatesOfProgress_ddP");
419 updateROP();
420 process_ddP(m_ropr, drop);
421}
422
424{
425 assertDerivativesValid("GasKinetics::getNetRatesOfProgress_ddP");
426 updateROP();
427 process_ddP(m_ropnet, drop);
428}
429
431 StoichManagerN& stoich, const vector_fp& in,
432 double* drop, bool mass_action)
433{
434 Eigen::Map<Eigen::VectorXd> out(drop, nReactions());
435 out.setZero();
436 double ctot_inv = 1. / thermo().molarDensity();
437
438 // derivatives due to concentrations in law of mass action
439 if (mass_action) {
440 stoich.scale(in.data(), out.data(), ctot_inv);
441 }
443 return;
444 }
445
446 // derivatives due to third-body colliders in law of mass action
447 Eigen::Map<Eigen::VectorXd> outM(m_rbuf1.data(), nReactions());
448 if (mass_action) {
449 outM.fill(0.);
450 m_multi_concm.scale(in.data(), outM.data(), ctot_inv);
451 out += outM;
452 }
453
454 // derivatives due to reaction rates depending on third-body colliders
455 if (!m_jac_skip_falloff) {
456 m_multi_concm.scaleM(in.data(), outM.data(), m_concm.data(), ctot_inv);
457 for (auto& rates : m_bulk_rates) {
458 // processing step assigns zeros to entries not dependent on M
459 rates->processRateConstants_ddM(
460 outM.data(), m_rfn.data(), m_jac_rtol_delta);
461 }
462 out += outM;
463 }
464}
465
467{
468 assertDerivativesValid("GasKinetics::getFwdRateConstants_ddC");
469 updateROP();
470 process_ddC(m_reactantStoich, m_rfn, dkfwd, false);
471}
472
474{
475 assertDerivativesValid("GasKinetics::getFwdRatesOfProgress_ddC");
476 updateROP();
478}
479
481{
482 assertDerivativesValid("GasKinetics::getRevRatesOfProgress_ddC");
483 updateROP();
485}
486
488{
489 assertDerivativesValid("GasKinetics::getNetRatesOfProgress_ddC");
490 updateROP();
492 Eigen::Map<Eigen::VectorXd> dNetRop(drop, nReactions());
493
494 process_ddC(m_revProductStoich, m_ropr, m_rbuf2.data());
495 Eigen::Map<Eigen::VectorXd> dNetRop2(m_rbuf2.data(), nReactions());
496 dNetRop -= dNetRop2;
497}
498
499Eigen::SparseMatrix<double> GasKinetics::process_ddX(
500 StoichManagerN& stoich, const vector_fp& in)
501{
502 Eigen::SparseMatrix<double> out;
503 vector_fp& scaled = m_rbuf1;
504 vector_fp& outV = m_rbuf2;
505
506 // convert from concentration to mole fraction output
507 double ctot = thermo().molarDensity();
508 for (size_t i = 0; i < nReactions(); ++i) {
509 scaled[i] = ctot * in[i];
510 }
511
512 // derivatives handled by StoichManagerN
513 copy(scaled.begin(), scaled.end(), outV.begin());
514 processThirdBodies(outV.data());
515 out = stoich.derivatives(m_act_conc.data(), outV.data());
517 return out;
518 }
519
520 // derivatives due to law of mass action
521 copy(scaled.begin(), scaled.end(), outV.begin());
522 stoich.multiply(m_act_conc.data(), outV.data());
523
524 // derivatives due to reaction rates depending on third-body colliders
525 if (!m_jac_skip_falloff) {
526 for (auto& rates : m_bulk_rates) {
527 // processing step does not modify entries not dependent on M
528 rates->processRateConstants_ddM(
529 outV.data(), m_rfn.data(), m_jac_rtol_delta, false);
530 }
531 }
532
533 // derivatives handled by ThirdBodyCalc
534 out += m_multi_concm.derivatives(outV.data());
535
536 return out;
537}
538
539Eigen::SparseMatrix<double> GasKinetics::fwdRatesOfProgress_ddX()
540{
541 assertDerivativesValid("GasKinetics::fwdRatesOfProgress_ddX");
542
543 // forward reaction rate coefficients
544 vector_fp& rop_rates = m_rbuf0;
545 processFwdRateCoefficients(rop_rates.data());
546 return process_ddX(m_reactantStoich, rop_rates);
547}
548
549Eigen::SparseMatrix<double> GasKinetics::revRatesOfProgress_ddX()
550{
551 assertDerivativesValid("GasKinetics::revRatesOfProgress_ddX");
552
553 // reverse reaction rate coefficients
554 vector_fp& rop_rates = m_rbuf0;
555 processFwdRateCoefficients(rop_rates.data());
556 processEquilibriumConstants(rop_rates.data());
557 return process_ddX(m_revProductStoich, rop_rates);
558}
559
560Eigen::SparseMatrix<double> GasKinetics::netRatesOfProgress_ddX()
561{
562 assertDerivativesValid("GasKinetics::netRatesOfProgress_ddX");
563
564 // forward reaction rate coefficients
565 vector_fp& rop_rates = m_rbuf0;
566 processFwdRateCoefficients(rop_rates.data());
567 Eigen::SparseMatrix<double> jac = process_ddX(m_reactantStoich, rop_rates);
568
569 // reverse reaction rate coefficients
570 processEquilibriumConstants(rop_rates.data());
571 return jac - process_ddX(m_revProductStoich, rop_rates);
572}
573
574bool GasKinetics::addReaction(shared_ptr<Reaction> r, bool resize)
575{
576 // operations common to all reaction types
577 bool added = BulkKinetics::addReaction(r, resize);
578 if (!added) {
579 return false;
580 } else if (!(r->usesLegacy())) {
581 // Rate object already added in BulkKinetics::addReaction
582 return true;
583 }
584
585 if (r->type() == "elementary-legacy") {
586 addElementaryReaction(dynamic_cast<ElementaryReaction2&>(*r));
587 } else if (r->type() == "three-body-legacy") {
588 addThreeBodyReaction(dynamic_cast<ThreeBodyReaction2&>(*r));
589 } else if (r->type() == "falloff-legacy") {
590 addFalloffReaction(dynamic_cast<FalloffReaction2&>(*r));
591 } else if (r->type() == "chemically-activated-legacy") {
592 addFalloffReaction(dynamic_cast<FalloffReaction2&>(*r));
593 } else if (r->type() == "pressure-dependent-Arrhenius-legacy") {
594 addPlogReaction(dynamic_cast<PlogReaction2&>(*r));
595 } else if (r->type() == "Chebyshev-legacy") {
596 addChebyshevReaction(dynamic_cast<ChebyshevReaction2&>(*r));
597 } else {
598 throw CanteraError("GasKinetics::addReaction",
599 "Unknown reaction type specified: '{}'", r->type());
600 }
601 m_legacy.push_back(nReactions() - 1);
602 return true;
603}
604
606{
607 // install high and low rate coeff calculators and extend the high and low
608 // rate coeff value vectors
609 size_t nfall = m_falloff_high_rates.nReactions();
610 m_falloff_high_rates.install(nfall, r.high_rate);
611 m_rfn_high.push_back(0.0);
612 m_falloff_low_rates.install(nfall, r.low_rate);
613 m_rfn_low.push_back(0.0);
614
615 // add this reaction number to the list of falloff reactions
616 m_fallindx.push_back(nReactions()-1);
617 m_rfallindx[nReactions()-1] = nfall;
618
619 // install the enhanced third-body concentration calculator
620 map<size_t, double> efficiencies;
621 for (const auto& eff : r.third_body.efficiencies) {
622 size_t k = kineticsSpeciesIndex(eff.first);
623 if (k != npos) {
624 efficiencies[k] = eff.second;
625 }
626 }
627 m_falloff_concm.install(nfall, efficiencies,
629 nReactions() - 1);
630 concm_falloff_values.resize(m_falloff_concm.workSize());
631
632 // install the falloff function calculator for this reaction
633 m_falloffn.install(nfall, r.type(), r.falloff);
635}
636
638{
639 m_rates.install(nReactions()-1, r.rate);
640 map<size_t, double> efficiencies;
641 for (const auto& eff : r.third_body.efficiencies) {
642 size_t k = kineticsSpeciesIndex(eff.first);
643 if (k != npos) {
644 efficiencies[k] = eff.second;
645 }
646 }
647 m_3b_concm.install(nReactions()-1, efficiencies,
649 concm_3b_values.resize(m_3b_concm.workSize());
650}
651
653{
654 m_plog_rates.install(nReactions()-1, r.rate);
655}
656
658{
659 m_cheb_rates.install(nReactions()-1, r.rate);
660}
661
662void GasKinetics::modifyReaction(size_t i, shared_ptr<Reaction> rNew)
663{
664 // operations common to all bulk reaction types
666
667 // invalidate all cached data
668 invalidateCache();
669
670 if (!(rNew->usesLegacy())) {
671 // Rate object already modified in BulkKinetics::modifyReaction
672 return;
673 }
674
675 if (rNew->type() == "elementary-legacy") {
676 modifyElementaryReaction(i, dynamic_cast<ElementaryReaction2&>(*rNew));
677 } else if (rNew->type() == "three-body-legacy") {
678 modifyThreeBodyReaction(i, dynamic_cast<ThreeBodyReaction2&>(*rNew));
679 } else if (rNew->type() == "falloff-legacy") {
680 modifyFalloffReaction(i, dynamic_cast<FalloffReaction2&>(*rNew));
681 } else if (rNew->type() == "chemically-activated-legacy") {
682 modifyFalloffReaction(i, dynamic_cast<FalloffReaction2&>(*rNew));
683 } else if (rNew->type() == "pressure-dependent-Arrhenius-legacy") {
684 modifyPlogReaction(i, dynamic_cast<PlogReaction2&>(*rNew));
685 } else if (rNew->type() == "Chebyshev-legacy") {
686 modifyChebyshevReaction(i, dynamic_cast<ChebyshevReaction2&>(*rNew));
687 } else {
688 throw CanteraError("GasKinetics::modifyReaction",
689 "Unknown reaction type specified: '{}'", rNew->type());
690 }
691}
692
694{
695 m_rates.replace(i, r.rate);
696}
697
699{
700 size_t iFall = m_rfallindx[i];
701 m_falloff_high_rates.replace(iFall, r.high_rate);
702 m_falloff_low_rates.replace(iFall, r.low_rate);
703 m_falloffn.replace(iFall, r.falloff);
704}
705
707{
708 m_plog_rates.replace(i, r.rate);
709}
710
712{
713 m_cheb_rates.replace(i, r.rate);
714}
715
716void GasKinetics::invalidateCache()
717{
718 BulkKinetics::invalidateCache();
719 m_pres += 0.13579;
720}
721
722}
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:399
bool empty() const
Return boolean indicating whether AnyMap is empty.
Definition: AnyMap.cpp:1401
bool getBool(const std::string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
Definition: AnyMap.cpp:1487
double getDouble(const std::string &key, double default_) const
If key exists, return it as a double, otherwise return default_.
Definition: AnyMap.cpp:1492
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:1406
Partial specialization of Kinetics for chemistry in a single bulk phase.
Definition: BulkKinetics.h:24
virtual void resizeReactions()
Finalize Kinetics object and associated objects.
vector_fp m_act_conc
Activity concentrations, as calculated by ThermoPhase::getActivityConcentrations.
Definition: BulkKinetics.h:76
std::vector< size_t > m_revindex
Indices of reversible reactions.
Definition: BulkKinetics.h:62
std::vector< unique_ptr< MultiRateBase > > m_bulk_rates
Vector of rate handlers.
Definition: BulkKinetics.h:58
ThirdBodyCalc3 m_multi_concm
used with MultiRate evaluator
Definition: BulkKinetics.h:70
vector_fp m_dn
Difference between the global reactants order and the global products order.
Definition: BulkKinetics.h:68
virtual bool addReaction(shared_ptr< Reaction > r, bool resize=true)
Add a single reaction to the mechanism.
std::vector< size_t > m_irrev
Indices of irreversible reactions.
Definition: BulkKinetics.h:63
Rate1< Arrhenius2 > m_rates
Definition: BulkKinetics.h:61
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
vector_fp m_concm
Third body concentrations.
Definition: BulkKinetics.h:73
vector_fp m_phys_conc
Physical concentrations, as calculated by ThermoPhase::getConcentrations.
Definition: BulkKinetics.h:79
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
A pressure-dependent reaction parameterized by a bi-variate Chebyshev polynomial in temperature and p...
Definition: Reaction.h:386
A reaction which follows mass-action kinetics with a modified Arrhenius reaction rate.
Definition: Reaction.h:217
size_t workSize()
Size of the work array required to store intermediate results.
Definition: FalloffMgr.h:85
void pr_to_falloff(doublereal *values, const doublereal *work)
Given a vector of reduced pressures for each falloff reaction, replace each entry by the value of the...
Definition: FalloffMgr.h:105
void install(size_t rxn, int reactionType, shared_ptr< Falloff > f)
Install a new falloff function calculator.
Definition: FalloffMgr.h:45
void replace(size_t rxn, shared_ptr< Falloff > f)
Definition: FalloffMgr.h:80
void updateTemp(doublereal t, doublereal *work)
Update the cached temperature-dependent intermediate results for all installed falloff functions.
Definition: FalloffMgr.h:95
A reaction that is first-order in [M] at low pressure, like a third-body reaction,...
Definition: Reaction.h:297
shared_ptr< FalloffRate > falloff
Falloff function which determines how low_rate and high_rate are combined to determine the rate const...
Definition: Reaction.h:327
Arrhenius2 high_rate
The rate constant in the high-pressure limit.
Definition: Reaction.h:320
ThirdBody third_body
Relative efficiencies of third-body species in enhancing the reaction rate.
Definition: Reaction.h:323
virtual std::string type() const
The type of reaction.
Definition: Reaction.h:304
Arrhenius2 low_rate
The rate constant in the low-pressure limit.
Definition: Reaction.h:317
void processFalloffReactions(double *ropf)
virtual void resizeReactions()
Finalize Kinetics object and associated objects.
Definition: GasKinetics.cpp:23
Eigen::SparseMatrix< double > process_ddX(StoichManagerN &stoich, const vector_fp &in)
Process mole fraction derivative.
virtual void getFwdRatesOfProgress_ddP(double *drop)
Calculate derivatives for forward rates-of-progress with respect to pressure at constant temperature,...
virtual Eigen::SparseMatrix< double > revRatesOfProgress_ddX()
Calculate derivatives for reverse rates-of-progress with respect to species mole fractions at constan...
std::map< size_t, size_t > m_rfallindx
Map of reaction index to falloff reaction index (i.e indices in m_falloff_low_rates and m_falloff_hig...
Definition: GasKinetics.h:156
virtual void getFwdRateConstants(double *kfwd)
Return the forward rate constants.
virtual void getDerivativeSettings(AnyMap &settings) const
Retrieve derivative settings.
virtual void getFwdRateConstants_ddC(double *dkfwd)
Calculate derivatives for forward rate constants with respect to molar concentration at constant temp...
Rate1< Arrhenius2 > m_falloff_low_rates
Rate expressions for falloff reactions at the low-pressure limit.
Definition: GasKinetics.h:159
Rate1< ChebyshevRate > m_cheb_rates
Definition: GasKinetics.h:170
virtual void getRevRatesOfProgress_ddP(double *drop)
Calculate derivatives for reverse rates-of-progress with respect to pressure at constant temperature,...
doublereal m_pres
Last pressure at which rates were evaluated.
Definition: GasKinetics.h:178
virtual Eigen::SparseMatrix< double > netRatesOfProgress_ddX()
Calculate derivatives for net rates-of-progress with respect to species mole fractions at constant te...
void addFalloffReaction(FalloffReaction2 &r)
void processFwdRateCoefficients(double *ropf)
Calculate rate coefficients.
Rate1< Plog > m_plog_rates
Definition: GasKinetics.h:169
virtual void getRevRatesOfProgress_ddC(double *drop)
Calculate derivatives for reverse rates-of-progress with respect to molar concentration at constant t...
virtual void getNetRatesOfProgress_ddP(double *drop)
Calculate derivatives for net rates-of-progress with respect to pressure at constant temperature,...
void addPlogReaction(PlogReaction2 &r)
void modifyFalloffReaction(size_t i, FalloffReaction2 &r)
Rate1< Arrhenius2 > m_falloff_high_rates
Rate expressions for falloff reactions at the high-pressure limit.
Definition: GasKinetics.h:162
void modifyPlogReaction(size_t i, PlogReaction2 &r)
GasKinetics(ThermoPhase *thermo=0)
Constructor.
Definition: GasKinetics.cpp:15
bool m_jac_skip_third_bodies
Derivative settings.
Definition: GasKinetics.h:193
virtual bool addReaction(shared_ptr< Reaction > r, bool resize=true)
Add a single reaction to the mechanism.
void process_ddP(const vector_fp &in, double *drop)
Process pressure derivative.
void assertDerivativesValid(const std::string &name)
Helper function ensuring that all rate derivatives can be calculated.
void processEquilibriumConstants(double *rop)
Multiply rate with inverse equilibrium constant.
void updateKc()
Update the equilibrium constants in molar units.
void processThirdBodies(double *rop)
Multiply rate with third-body collider concentrations.
void process_ddC(StoichManagerN &stoich, const vector_fp &in, double *drop, bool mass_action=true)
Process concentration (molar density) derivative.
vector_fp concm_falloff_values
Definition: GasKinetics.h:181
virtual void getFwdRateConstants_ddT(double *dkfwd)
Calculate derivatives for forward rate constants with respect to temperature at constant pressure,...
std::vector< size_t > m_legacy
Reaction index of each legacy reaction (old framework)
Definition: GasKinetics.h:152
ThirdBodyCalc m_3b_concm
Definition: GasKinetics.h:166
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
virtual void getThirdBodyConcentrations(double *concm)
Return a vector of values of effective concentrations of third-body collision partners of any reactio...
Definition: GasKinetics.cpp:34
virtual void update_rates_C()
Update properties that depend on concentrations.
Definition: GasKinetics.cpp:91
virtual void update_rates_T()
Update temperature-dependent portions of reaction rates and falloff functions.
Definition: GasKinetics.cpp:40
virtual void getFwdRateConstants_ddP(double *dkfwd)
Calculate derivatives for forward rate constants with respect to pressure at constant temperature,...
virtual void getFwdRatesOfProgress_ddT(double *drop)
Calculate derivatives for forward rates-of-progress with respect to temperature at constant pressure,...
std::vector< size_t > m_fallindx
Reaction index of each falloff reaction.
Definition: GasKinetics.h:149
virtual void getEquilibriumConstants(doublereal *kc)
Return a vector of Equilibrium constants.
vector_fp m_rbuf0
Buffers for partial rop results with length nReactions()
Definition: GasKinetics.h:186
void process_ddT(const vector_fp &in, double *drop)
Process temperature derivative.
virtual void getNetRatesOfProgress_ddT(double *drop)
Calculate derivatives for net rates-of-progress with respect to temperature at constant pressure,...
virtual void getFwdRatesOfProgress_ddC(double *drop)
Calculate derivatives for forward rates-of-progress with respect to molar concentration at constant t...
virtual void setDerivativeSettings(const AnyMap &settings)
Set/modify derivative settings.
void modifyThreeBodyReaction(size_t i, ThreeBodyReaction2 &r)
FalloffMgr m_falloffn
Definition: GasKinetics.h:164
void modifyChebyshevReaction(size_t i, ChebyshevReaction2 &r)
vector_fp falloff_work
Definition: GasKinetics.h:179
void addChebyshevReaction(ChebyshevReaction2 &r)
void addThreeBodyReaction(ThreeBodyReaction2 &r)
virtual void getNetRatesOfProgress_ddC(double *drop)
Calculate derivatives for net rates-of-progress with respect to molar concentration at constant tempe...
vector_fp concm_3b_values
Definition: GasKinetics.h:180
virtual Eigen::SparseMatrix< double > fwdRatesOfProgress_ddX()
Calculate derivatives for forward rates-of-progress with respect to species mole fractions at constan...
void processEquilibriumConstants_ddT(double *drkcn)
Multiply rate with scaled temperature derivatives of the inverse equilibrium constant.
virtual void getRevRatesOfProgress_ddT(double *drop)
Calculate derivatives for reverse rates-of-progress with respect to temperature at constant pressure,...
ThirdBodyCalc m_falloff_concm
Definition: GasKinetics.h:167
vector_fp m_delta_gibbs0
Delta G^0 for all reactions.
Definition: Kinetics.h:1372
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
Definition: Kinetics.h:231
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:450
vector_fp m_ropnet
Net rate-of-progress for each reaction.
Definition: Kinetics.h:1384
virtual void getReactionDelta(const double *property, double *deltaProperty) const
Change in species properties.
Definition: Kinetics.cpp:441
vector_fp m_perturb
Vector of perturbation factors for each reaction's rate of progress vector.
Definition: Kinetics.h:1321
vector_fp m_rkcn
Reciprocal of the equilibrium constant in concentration units.
Definition: Kinetics.h:1375
vector_fp m_ropf
Forward rate-of-progress for each reaction.
Definition: Kinetics.h:1378
vector_fp m_ropr
Reverse rate-of-progress for each reaction.
Definition: Kinetics.h:1381
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
Definition: Kinetics.h:1306
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition: Kinetics.h:139
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
Definition: Kinetics.h:265
vector_fp m_rfn
Forward rate constant for each reaction.
Definition: Kinetics.h:1369
virtual std::string reactionTypeStr(size_t i) const
String specifying the type of reaction.
Definition: Kinetics.cpp:402
StoichManagerN m_reactantStoich
Stoichiometry manager for the reactants for each reaction.
Definition: Kinetics.h:1300
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
Definition: Kinetics.h:243
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
void getConcentrations(double *const c) const
Get the species concentrations (kmol/m^3).
Definition: Phase.cpp:596
double molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:671
void saveState(vector_fp &state) const
Save the current internal state of the phase.
Definition: Phase.cpp:286
doublereal temperature() const
Temperature (K).
Definition: Phase.h:654
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
Definition: Phase.cpp:310
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition: Phase.h:672
A pressure-dependent reaction parameterized by logarithmically interpolating between Arrhenius rate e...
Definition: Reaction.h:365
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.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:782
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: ThermoPhase.h:404
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition: ThermoPhase.h:580
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...
void update(const vector_fp &conc, double ctot, double *concm) const
Update third-body concentrations in full vector.
bool empty() const
Return boolean indicating whether ThirdBodyCalc3 is empty.
void multiply(double *output, const double *concm)
Multiply output with effective third-body concentration.
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 copy(const vector_fp &work, double *concm)
Update third-body concentrations in full vector.
Definition: ThirdBodyCalc.h:52
double default_efficiency
The default third body efficiency for species not listed in efficiencies.
Definition: Reaction.h:255
Composition efficiencies
Map of species to third body efficiency.
Definition: Reaction.h:251
A reaction with a non-reacting third body "M" that acts to add or remove energy from the reacting spe...
Definition: Reaction.h:269
ThirdBody third_body
Relative efficiencies of third-body species in enhancing the reaction rate.
Definition: Reaction.h:286
#define AssertFinite(expr, procedure,...)
Throw an exception if the specified exception is not a finite number.
Definition: ctexceptions.h:278
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:192
void warn_deprecated(const std::string &source, const AnyBase &node, const std::string &message)
A deprecation warning for syntax in an input file.
Definition: AnyMap.cpp:1901
const double SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:153
bool legacy_rate_constants_used()
Returns true if legacy rate constant definition should be used.
Definition: global.cpp:109
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:184
const double BigNumber
largest number to compare to inf.
Definition: ct_defs.h:155