Cantera  3.2.0
Loading...
Searching...
No Matches
InterfaceKinetics.cpp
Go to the documentation of this file.
1/**
2 * @file InterfaceKinetics.cpp
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
13
14namespace Cantera
15{
16
17InterfaceKinetics::~InterfaceKinetics()
18{
19 delete m_integrator;
20}
21
23{
25
26 // resize buffer
27 m_rbuf0.resize(nReactions());
28 m_rbuf1.resize(nReactions());
29
30 for (auto& rates : m_rateHandlers) {
31 rates->resize(nTotalSpecies(), nReactions(), nPhases());
32 // @todo ensure that ReactionData are updated; calling rates->update
33 // blocks correct behavior in InterfaceKinetics::_update_rates_T
34 // and running updateROP() is premature
35 }
36}
37
39{
41 m_redo_rates = true;
42}
43
45{
46 // First task is update the electrical potentials from the Phases
48
49 // Go find the temperature from the surface
50 double T = thermo(0).temperature();
51 m_redo_rates = true;
52 if (T != m_temp || m_redo_rates) {
53 // Calculate the forward rate constant by calling m_rates and store it in m_rfn[]
54 for (size_t n = 0; n < nPhases(); n++) {
56 }
57
58 // Use the stoichiometric manager to find deltaH for each reaction.
59 getReactionDelta(m_grt.data(), m_dH.data());
60
61 m_temp = T;
62 m_ROP_ok = false;
63 m_redo_rates = false;
64 }
65
66 // loop over interface MultiRate evaluators for each reaction type
67 for (auto& rates : m_rateHandlers) {
68 bool changed = rates->update(thermo(0), *this);
69 if (changed) {
70 rates->getRateConstants(m_rfn.data());
71 m_ROP_ok = false;
72 m_redo_rates = true;
73 }
74 }
75
76 if (!m_ROP_ok) {
77 updateKc();
78 }
79}
80
82{
83 // Store electric potentials for each phase in the array m_phi[].
84 for (size_t n = 0; n < nPhases(); n++) {
85 if (thermo(n).electricPotential() != m_phi[n]) {
87 m_redo_rates = true;
88 }
89 }
90}
91
93{
94 for (size_t n = 0; n < nPhases(); n++) {
95 const auto& tp = thermo(n);
96 /*
97 * We call the getActivityConcentrations function of each ThermoPhase
98 * class that makes up this kinetics object to obtain the generalized
99 * concentrations for species within that class. This is collected in
100 * the vector m_conc. m_start[] are integer indices for that vector
101 * denoting the start of the species for each phase.
102 */
103 tp.getActivityConcentrations(m_actConc.data() + m_start[n]);
104
105 // Get regular concentrations too
106 tp.getConcentrations(m_conc.data() + m_start[n]);
107 }
108 m_ROP_ok = false;
109}
110
112{
113 warn_deprecated("InterfaceKinetics::getActivityConcentrations",
114 "To be removed after Cantera 3.2.");
116 copy(m_actConc.begin(), m_actConc.end(), conc);
117}
118
120{
121 fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
122
123 if (m_revindex.size() > 0) {
124 /*
125 * Get the vector of standard state electrochemical potentials for
126 * species in the Interfacial kinetics object and store it in m_mu0[]
127 * and m_mu0_Kc[]
128 */
129 updateMu0();
130 double rrt = 1.0 / thermo(0).RT();
131
132 // compute Delta mu^0 for all reversible reactions
133 getRevReactionDelta(m_mu0_Kc.data(), m_rkcn.data());
134
135 for (size_t i = 0; i < m_revindex.size(); i++) {
136 size_t irxn = m_revindex[i];
137 if (irxn == npos || irxn >= nReactions()) {
138 throw CanteraError("InterfaceKinetics::updateKc",
139 "illegal value: irxn = {}", irxn);
140 }
141 // WARNING this may overflow HKM
142 m_rkcn[irxn] = exp(m_rkcn[irxn]*rrt);
143 }
144 for (size_t i = 0; i != m_irrev.size(); ++i) {
145 m_rkcn[ m_irrev[i] ] = 0.0;
146 }
147 }
148}
149
151{
152 // First task is update the electrical potentials from the Phases
154
155 // @todo There is significant potential to further simplify calculations
156 // once the old framework is removed
157 size_t ik = 0;
158 for (size_t n = 0; n < nPhases(); n++) {
160 for (size_t k = 0; k < thermo(n).nSpecies(); k++) {
161 m_mu0_Kc[ik] = m_mu0[ik] + Faraday * m_phi[n] * thermo(n).charge(k);
162 m_mu0_Kc[ik] -= thermo(0).RT() * thermo(n).logStandardConc(k);
163 ik++;
164 }
165 }
166}
167
169{
170 updateMu0();
171 double rrt = 1.0 / thermo(0).RT();
172 std::fill(kc, kc + nReactions(), 0.0);
173 getReactionDelta(m_mu0_Kc.data(), kc);
174 for (size_t i = 0; i < nReactions(); i++) {
175 kc[i] = exp(-kc[i]*rrt);
176 }
177}
178
180{
181 updateROP();
182 for (size_t i = 0; i < nReactions(); i++) {
183 // base rate coefficient multiplied by perturbation factor
184 kfwd[i] = m_rfn[i] * m_perturb[i];
185 }
186}
187
188void InterfaceKinetics::getRevRateConstants(double* krev, bool doIrreversible)
189{
191 if (doIrreversible) {
193 for (size_t i = 0; i < nReactions(); i++) {
194 krev[i] /= m_ropnet[i];
195 }
196 } else {
197 for (size_t i = 0; i < nReactions(); i++) {
198 krev[i] *= m_rkcn[i];
199 }
200 }
201}
202
204{
205 // evaluate rate constants and equilibrium constants at temperature and phi
206 // (electric potential)
208 // get updated activities (rates updated below)
210
211 if (m_ROP_ok) {
212 return;
213 }
214
215 for (size_t i = 0; i < nReactions(); i++) {
216 // Scale the base forward rate coefficient by the perturbation factor
217 m_ropf[i] = m_rfn[i] * m_perturb[i];
218 // Multiply the scaled forward rate coefficient by the reciprocal of the
219 // equilibrium constant
220 m_ropr[i] = m_ropf[i] * m_rkcn[i];
221 }
222
223 for (auto& rates : m_rateHandlers) {
224 rates->modifyRateConstants(m_ropf.data(), m_ropr.data());
225 }
226
227 // multiply ropf by the activity concentration reaction orders to obtain
228 // the forward rates of progress.
229 m_reactantStoich.multiply(m_actConc.data(), m_ropf.data());
230
231 // For reversible reactions, multiply ropr by the activity concentration
232 // products
233 m_revProductStoich.multiply(m_actConc.data(), m_ropr.data());
234
235 for (size_t j = 0; j != nReactions(); ++j) {
236 m_ropnet[j] = m_ropf[j] - m_ropr[j];
237 }
238
239 // For reactions involving multiple phases, we must check that the phase
240 // being consumed actually exists. This is particularly important for phases
241 // that are stoichiometric phases containing one species with a unity
242 // activity
243 if (m_phaseExistsCheck) {
244 for (size_t j = 0; j != nReactions(); ++j) {
245 if ((m_ropr[j] > m_ropf[j]) && (m_ropr[j] > 0.0)) {
246 for (size_t p = 0; p < nPhases(); p++) {
247 if (m_rxnPhaseIsProduct[j][p] && !m_phaseExists[p]) {
248 m_ropnet[j] = 0.0;
249 m_ropr[j] = m_ropf[j];
250 if (m_ropf[j] > 0.0) {
251 for (size_t rp = 0; rp < nPhases(); rp++) {
252 if (m_rxnPhaseIsReactant[j][rp] && !m_phaseExists[rp]) {
253 m_ropnet[j] = 0.0;
254 m_ropr[j] = m_ropf[j] = 0.0;
255 }
256 }
257 }
258 }
259 if (m_rxnPhaseIsReactant[j][p] && !m_phaseIsStable[p]) {
260 m_ropnet[j] = 0.0;
261 m_ropr[j] = m_ropf[j];
262 }
263 }
264 } else if ((m_ropf[j] > m_ropr[j]) && (m_ropf[j] > 0.0)) {
265 for (size_t p = 0; p < nPhases(); p++) {
266 if (m_rxnPhaseIsReactant[j][p] && !m_phaseExists[p]) {
267 m_ropnet[j] = 0.0;
268 m_ropf[j] = m_ropr[j];
269 if (m_ropf[j] > 0.0) {
270 for (size_t rp = 0; rp < nPhases(); rp++) {
271 if (m_rxnPhaseIsProduct[j][rp] && !m_phaseExists[rp]) {
272 m_ropnet[j] = 0.0;
273 m_ropf[j] = m_ropr[j] = 0.0;
274 }
275 }
276 }
277 }
278 if (m_rxnPhaseIsProduct[j][p] && !m_phaseIsStable[p]) {
279 m_ropnet[j] = 0.0;
280 m_ropf[j] = m_ropr[j];
281 }
282 }
283 }
284 }
285 }
286 m_ROP_ok = true;
287}
288
290{
291 // Get the chemical potentials of the species in the all of the phases used
292 // in the kinetics mechanism
293 for (size_t n = 0; n < nPhases(); n++) {
294 m_thermo[n]->getChemPotentials(m_mu.data() + m_start[n]);
295 }
296
297 // Use the stoichiometric manager to find deltaG for each reaction.
298 getReactionDelta(m_mu.data(), m_rbuf.data());
299 if (deltaG != 0 && (m_rbuf.data() != deltaG)) {
300 for (size_t j = 0; j < nReactions(); ++j) {
301 deltaG[j] = m_rbuf[j];
302 }
303 }
304}
305
307{
308 // Get the chemical potentials of the species
309 for (size_t n = 0; n < nPhases(); n++) {
311 }
312
313 // Use the stoichiometric manager to find deltaG for each reaction.
314 getReactionDelta(m_grt.data(), deltaM);
315}
316
318{
319 // Get the partial molar enthalpy of all species
320 for (size_t n = 0; n < nPhases(); n++) {
322 }
323
324 // Use the stoichiometric manager to find deltaH for each reaction.
325 getReactionDelta(m_grt.data(), deltaH);
326}
327
329{
330 // Get the partial molar entropy of all species in all of the phases
331 for (size_t n = 0; n < nPhases(); n++) {
333 }
334
335 // Use the stoichiometric manager to find deltaS for each reaction.
336 getReactionDelta(m_grt.data(), deltaS);
337}
338
340{
341 // Get the standard state chemical potentials of the species. This is the
342 // array of chemical potentials at unit activity We define these here as the
343 // chemical potentials of the pure species at the temperature and pressure
344 // of the solution.
345 for (size_t n = 0; n < nPhases(); n++) {
347 }
348
349 // Use the stoichiometric manager to find deltaG for each reaction.
350 getReactionDelta(m_mu0.data(), deltaGSS);
351}
352
354{
355 // Get the standard state enthalpies of the species. This is the array of
356 // chemical potentials at unit activity We define these here as the
357 // enthalpies of the pure species at the temperature and pressure of the
358 // solution.
359 for (size_t n = 0; n < nPhases(); n++) {
360 thermo(n).getEnthalpy_RT(m_grt.data() + m_start[n]);
361 }
362 for (size_t k = 0; k < m_kk; k++) {
363 m_grt[k] *= thermo(0).RT();
364 }
365
366 // Use the stoichiometric manager to find deltaH for each reaction.
367 getReactionDelta(m_grt.data(), deltaH);
368}
369
371{
372 // Get the standard state entropy of the species. We define these here as
373 // the entropies of the pure species at the temperature and pressure of the
374 // solution.
375 for (size_t n = 0; n < nPhases(); n++) {
376 thermo(n).getEntropy_R(m_grt.data() + m_start[n]);
377 }
378 for (size_t k = 0; k < m_kk; k++) {
379 m_grt[k] *= GasConstant;
380 }
381
382 // Use the stoichiometric manager to find deltaS for each reaction.
383 getReactionDelta(m_grt.data(), deltaS);
384}
385
386bool InterfaceKinetics::addReaction(shared_ptr<Reaction> r_base, bool resize)
387{
388 if (!m_surf) {
389 init();
390 }
391
392 size_t i = nReactions();
393 shared_ptr<ReactionRate> rate = r_base->rate();
394 if (rate) {
395 rate->setContext(*r_base, *this);
396 }
397
398 bool added = Kinetics::addReaction(r_base, resize);
399 if (!added) {
400 return false;
401 }
402
403 m_rxnPhaseIsReactant.emplace_back(nPhases(), false);
404 m_rxnPhaseIsProduct.emplace_back(nPhases(), false);
405
406 for (const auto& [name, stoich] : r_base->reactants) {
407 size_t k = kineticsSpeciesIndex(name);
408 size_t p = speciesPhaseIndex(k);
409 m_rxnPhaseIsReactant[i][p] = true;
410 }
411 for (const auto& [name, stoich] : r_base->products) {
412 size_t k = kineticsSpeciesIndex(name);
413 size_t p = speciesPhaseIndex(k);
414 m_rxnPhaseIsProduct[i][p] = true;
415 }
416
417 // Set index of rate to number of reaction within kinetics
418 rate->setRateIndex(nReactions() - 1);
419
420 string rtype = rate->subType();
421 if (rtype == "") {
422 rtype = rate->type();
423 }
424
425 // If necessary, add new interface MultiRate evaluator
426 if (m_rateTypes.find(rtype) == m_rateTypes.end()) {
427 m_rateTypes[rtype] = m_rateHandlers.size();
428 m_rateHandlers.push_back(rate->newMultiRate());
429 m_rateHandlers.back()->resize(m_kk, nReactions(), nPhases());
430 }
431
432 // Add reaction rate to evaluator
433 size_t index = m_rateTypes[rtype];
434 m_rateHandlers[index]->add(nReactions() - 1, *rate);
435
436 // Set flag for coverage dependence to true
437 if (rate->compositionDependent()) {
439 }
440
441 // Set flag for electrochemistry to true
442 if (r_base->usesElectrochemistry(*this)) {
444 }
445
446 return true;
447}
448
449void InterfaceKinetics::modifyReaction(size_t i, shared_ptr<Reaction> r_base)
450{
451 Kinetics::modifyReaction(i, r_base);
452
453 shared_ptr<ReactionRate> rate = r_base->rate();
454 rate->setRateIndex(i);
455 rate->setContext(*r_base, *this);
456
457 string rtype = rate->subType();
458 if (rtype == "") {
459 rtype = rate->type();
460 }
461
462 // Ensure that interface MultiRate evaluator is available
463 if (!m_rateTypes.count(rtype)) {
464 throw CanteraError("InterfaceKinetics::modifyReaction",
465 "Interface evaluator not available for type '{}'.", rtype);
466 }
467 // Replace reaction rate evaluator
468 size_t index = m_rateTypes[rate->type()];
469 m_rateHandlers[index]->replace(i, *rate);
470
471 // Invalidate cached data
472 m_redo_rates = true;
473 m_temp += 0.1;
474}
475
476void InterfaceKinetics::setMultiplier(size_t i, double f)
477{
479 m_ROP_ok = false;
480}
481
482void InterfaceKinetics::setIOFlag(int ioFlag)
483{
484 m_ioFlag = ioFlag;
485 if (m_integrator) {
486 m_integrator->setIOFlag(ioFlag);
487 }
488}
489
490void InterfaceKinetics::addThermo(shared_ptr<ThermoPhase> thermo)
491{
493 m_phaseExists.push_back(true);
494 m_phaseIsStable.push_back(true);
495}
496
498{
499 if (thermo(0).nDim() > 2) {
500 throw CanteraError("InterfaceKinetics::init", "no interface phase is present.");
501 }
502}
503
505{
506 size_t kOld = m_kk;
508 if (m_kk != kOld && nReactions()) {
509 throw CanteraError("InterfaceKinetics::resizeSpecies", "Cannot add"
510 " species to InterfaceKinetics after reactions have been added.");
511 }
512 m_actConc.resize(m_kk);
513 m_conc.resize(m_kk);
514 m_mu0.resize(m_kk);
515 m_mu.resize(m_kk);
516 m_mu0_Kc.resize(m_kk);
517 m_grt.resize(m_kk);
518 m_phi.resize(nPhases(), 0.0);
519}
520
521void InterfaceKinetics::advanceCoverages(double tstep, double rtol, double atol,
522 double maxStepSize, size_t maxSteps, size_t maxErrTestFails)
523{
524 if (m_integrator == 0) {
525 vector<InterfaceKinetics*> k{this};
527 }
528 m_integrator->setTolerances(rtol, atol);
529 m_integrator->setMaxStepSize(maxStepSize);
530 m_integrator->setMaxSteps(maxSteps);
531 m_integrator->setMaxErrTestFails(maxErrTestFails);
532 m_integrator->integrate(0.0, tstep);
533 delete m_integrator;
534 m_integrator = 0;
535}
536
538 int ifuncOverride, double timeScaleOverride)
539{
540 // create our own solver object
541 if (m_integrator == 0) {
542 vector<InterfaceKinetics*> k{this};
545 }
546 m_integrator->setIOFlag(m_ioFlag);
547 // New direct method to go here
548 m_integrator->solvePseudoSteadyStateProblem(ifuncOverride, timeScaleOverride);
549}
550
551void InterfaceKinetics::setPhaseExistence(const size_t iphase, const int exists)
552{
553 checkPhaseIndex(iphase);
554 if (exists) {
555 if (!m_phaseExists[iphase]) {
558 m_phaseExists[iphase] = true;
559 }
560 m_phaseIsStable[iphase] = true;
561 } else {
562 if (m_phaseExists[iphase]) {
564 m_phaseExists[iphase] = false;
565 }
566 m_phaseIsStable[iphase] = false;
567 }
568}
569
570int InterfaceKinetics::phaseExistence(const size_t iphase) const
571{
572 checkPhaseIndex(iphase);
573 return m_phaseExists[iphase];
574}
575
576int InterfaceKinetics::phaseStability(const size_t iphase) const
577{
578 checkPhaseIndex(iphase);
579 return m_phaseIsStable[iphase];
580}
581
582void InterfaceKinetics::setPhaseStability(const size_t iphase, const int isStable)
583{
584 checkPhaseIndex(iphase);
585 if (isStable) {
586 m_phaseIsStable[iphase] = true;
587 } else {
588 m_phaseIsStable[iphase] = false;
589 }
590}
591
592double InterfaceKinetics::interfaceCurrent(const size_t iphase)
593{
594 vector<double> charges(m_kk, 0.0);
595 vector<double> netProdRates(m_kk, 0.0);
596 double dotProduct = 0.0;
597
598 thermo(iphase).getCharges(charges.data());
599 getNetProductionRates(netProdRates.data());
600
601 for (size_t k = 0; k < thermo(iphase).nSpecies(); k++)
602 {
603 dotProduct += charges[k] * netProdRates[m_start[iphase] + k];
604 }
605
606 return dotProduct * Faraday;
607}
608
610{
611 // check derivatives are valid
612 assertDerivativesValid("InterfaceKinetics::fwdRatesOfProgress_ddCi");
613 // forward reaction rate coefficients
614 vector<double>& rop_rates = m_rbuf0;
615 getFwdRateConstants(rop_rates.data());
617}
618
620{
621 // check derivatives are valid
622 assertDerivativesValid("InterfaceKinetics::revRatesOfProgress_ddCi");
623 // reverse reaction rate coefficients
624 vector<double>& rop_rates = m_rbuf0;
625 getFwdRateConstants(rop_rates.data());
626 applyEquilibriumConstants(rop_rates.data());
628}
629
631{
632 // check derivatives are valid
633 assertDerivativesValid("InterfaceKinetics::netRatesOfProgress_ddCi");
634 // forward reaction rate coefficients
635 vector<double>& rop_rates = m_rbuf0;
636 getFwdRateConstants(rop_rates.data());
637 Eigen::SparseMatrix<double> jac = calculateCompositionDerivatives(m_reactantStoich,
638 rop_rates);
639
640 // reverse reaction rate coefficients
641 applyEquilibriumConstants(rop_rates.data());
643}
644
646{
647 bool force = settings.empty();
648 if (force || settings.hasKey("skip-coverage-dependence")) {
649 m_jac_skip_coverage_dependence = settings.getBool("skip-coverage-dependence",
650 false);
651 }
652 if (force || settings.hasKey("skip-electrochemistry")) {
653 m_jac_skip_electrochemistry = settings.getBool("skip-electrochemistry",
654 false);
655 }
656 if (force || settings.hasKey("rtol-delta")) {
657 m_jac_rtol_delta = settings.getDouble("rtol-delta", 1e-8);
658 }
659}
660
662{
663 settings["skip-coverage-dependence"] = m_jac_skip_electrochemistry;
664 settings["skip-electrochemistry"] = m_jac_skip_coverage_dependence;
665 settings["rtol-delta"] = m_jac_rtol_delta;
666}
667
669 StoichManagerN& stoich, const vector<double>& in)
670{
671 vector<double>& outV = m_rbuf1;
672 // derivatives handled by StoichManagerN
673 copy(in.begin(), in.end(), outV.begin());
674 return stoich.derivatives(m_actConc.data(), outV.data());
675}
676
678{
680 throw NotImplementedError(name, "Coverage-dependent reactions not supported.");
682 throw NotImplementedError(name, "Electrochemical reactions not supported.");
683 }
684}
685
687{
688 // For reverse rates computed from thermochemistry, multiply the forward
689 // rate coefficients by the reciprocals of the equilibrium constants
690 for (size_t i = 0; i < nReactions(); ++i) {
691 rop[i] *= m_rkcn[i];
692 }
693}
694
695}
Declarations for the implicit integration of surface site density equations (see Kinetics Managers an...
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase,...
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
Base class for exceptions thrown by Cantera classes.
Advances the surface coverages of the associated set of SurfacePhase objects in time.
void initialize(double t0=0.0)
Must be called before calling method 'advance'.
void integrate(double t0, double t1)
Integrate from t0 to t1. The integrator is reinitialized first.
void setTolerances(double rtol=1.e-7, double atol=1.e-14)
Set the relative and absolute integration tolerances.
void setMaxStepSize(double maxstep=0.0)
Set the maximum integration step-size.
void setMaxSteps(size_t maxsteps=20000)
Set the maximum number of CVODES integration steps.
void solvePseudoSteadyStateProblem(int ifuncOverride=-1, double timeScaleOverride=1.0)
Solve for the pseudo steady-state of the surface problem.
void setMaxErrTestFails(size_t maxErrTestFails=7)
Set the maximum number of CVODES error test failures.
bool addReaction(shared_ptr< Reaction > r, bool resize=true) override
Add a single reaction to the mechanism.
int phaseExistence(const size_t iphase) const
Gets the phase existence int for the ith phase.
double interfaceCurrent(const size_t iphase)
Gets the interface current for the ith phase.
SurfPhase * m_surf
Pointer to the single surface phase.
vector< vector< bool > > m_rxnPhaseIsReactant
Vector of vector of booleans indicating whether a phase participates in a reaction as a reactant.
vector< int > m_phaseIsStable
Vector of int indicating whether phases are stable or not.
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.
vector< bool > m_phaseExists
Vector of booleans indicating whether phases exist or not.
void getDeltaSSGibbs(double *deltaG) override
Return the vector of values for the reaction standard state Gibbs free energy change.
double m_temp
Current temperature of the data.
void setPhaseStability(const size_t iphase, const int isStable)
Set the stability of a phase in the reaction object.
void getDeltaGibbs(double *deltaG) override
Return the vector of values for the reaction Gibbs free energy change.
bool m_jac_skip_coverage_dependence
A flag used to neglect rate coefficient coverage dependence in derivative formation.
void _update_rates_phi()
Update properties that depend on the electric potential.
vector< double > m_phi
Vector of phase electric potentials.
void assertDerivativesValid(const string &name)
Helper function ensuring that all rate derivatives can be calculated.
double m_jac_rtol_delta
Relative tolerance used in developing numerical portions of specific derivatives.
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.
void advanceCoverages(double tstep, double rtol=1.e-7, double atol=1.e-14, double maxStepSize=0, size_t maxSteps=20000, size_t maxErrTestFails=7)
Advance the surface coverages in time.
void getDeltaSSEnthalpy(double *deltaH) override
Return the vector of values for the change in the standard state enthalpies of reaction.
void resizeSpecies() override
Resize arrays with sizes that depend on the total number of species.
vector< double > m_grt
Temporary work vector of length m_kk.
void getActivityConcentrations(double *const conc) override
Get the vector of activity concentrations used in the kinetics object.
void getRevRateConstants(double *krev, bool doIrreversible=false) override
Return the reverse rate constants.
void getEquilibriumConstants(double *kc) override
Equilibrium constant for all reactions including the voltage term.
bool m_has_electrochemistry
A flag stating if the object uses electrochemistry.
void updateKc()
Update the equilibrium constants and stored electrochemical potentials in molar units for all reversi...
void setPhaseExistence(const size_t iphase, const int exists)
Set the existence of a phase in the reaction object.
void updateROP() override
Internal routine that updates the Rates of Progress of the reactions.
void applyEquilibriumConstants(double *rop)
Multiply rate with inverse equilibrium constant.
void getDerivativeSettings(AnyMap &settings) const override
Retrieve derivative settings.
void getDeltaEnthalpy(double *deltaH) override
Return the vector of values for the reactions change in enthalpy.
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.
bool m_jac_skip_electrochemistry
A flag used to neglect electrochemical contributions in derivative formation.
void _update_rates_C()
Update properties that depend on the species mole fractions and/or concentration,.
vector< double > m_rbuf0
Buffers for partial rop results with length nReactions()
int phaseStability(const size_t iphase) const
Gets the phase stability int for the ith phase.
vector< double > m_mu0_Kc
Vector of standard state electrochemical potentials modified by a standard concentration term.
ImplicitSurfChem * m_integrator
Pointer to the Implicit surface chemistry object.
void _update_rates_T()
Update properties that depend on temperature.
void solvePseudoSteadyStateProblem(int ifuncOverride=-1, double timeScaleOverride=1.0)
Solve for the pseudo steady-state of the surface problem.
bool m_has_coverage_dependence
A flag stating if the object has coverage dependent rates.
virtual void updateMu0()
Update the standard state chemical potentials and species equilibrium constant entries.
void addThermo(shared_ptr< ThermoPhase > thermo) override
Add a thermo phase to the kinetics manager object.
vector< double > m_mu
Vector of chemical potentials for all species.
vector< double > m_actConc
Array of activity concentrations for each species in the kinetics object.
vector< double > m_mu0
Vector of standard state chemical potentials for all species.
void getDeltaElectrochemPotentials(double *deltaM) override
Return the vector of values for the reaction electrochemical free energy change.
void setElectricPotential(int n, double V)
Set the electric potential in the nth phase.
void init() override
Prepare the class for the addition of reactions, after all phases have been added.
void resizeReactions() override
Finalize Kinetics object and associated objects.
int m_phaseExistsCheck
Int flag to indicate that some phases in the kinetics mechanism are non-existent.
Eigen::SparseMatrix< double > calculateCompositionDerivatives(StoichManagerN &stoich, const vector< double > &in)
Process mole fraction derivative.
Eigen::SparseMatrix< double > netRatesOfProgress_ddCi() override
Calculate derivatives for net rates-of-progress with respect to species concentration at constant tem...
void getDeltaEntropy(double *deltaS) override
Return the vector of values for the reactions change in entropy.
vector< vector< bool > > m_rxnPhaseIsProduct
Vector of vector of booleans indicating whether a phase participates in a reaction as a product.
void setDerivativeSettings(const AnyMap &settings) override
Set/modify derivative settings.
vector< double > m_conc
Array of concentrations for each species in the kinetics mechanism.
virtual void resizeReactions()
Finalize Kinetics object and associated objects.
Definition Kinetics.cpp:50
size_t checkPhaseIndex(size_t m) const
Check that the specified phase index is in range.
Definition Kinetics.cpp:77
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
Definition Kinetics.h:270
vector< double > m_perturb
Vector of perturbation factors for each reaction's rate of progress vector.
Definition Kinetics.h:1553
vector< double > m_ropf
Forward rate-of-progress for each reaction.
Definition Kinetics.h:1601
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:455
vector< unique_ptr< MultiRateBase > > m_rateHandlers
Vector of rate handlers.
Definition Kinetics.h:1524
vector< size_t > m_start
m_start is a vector of integers specifying the beginning position for the species vector for the n'th...
Definition Kinetics.h:1578
vector< double > m_rkcn
Reciprocal of the equilibrium constant in concentration units.
Definition Kinetics.h:1598
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
Definition Kinetics.h:1549
virtual void getReactionDelta(const double *property, double *deltaProperty) const
Change in species properties.
Definition Kinetics.cpp:446
vector< double > m_dH
The enthalpy change for each reaction to calculate Blowers-Masel rates.
Definition Kinetics.h:1613
vector< double > m_ropr
Reverse rate-of-progress for each reaction.
Definition Kinetics.h:1604
size_t nPhases() const
The number of phases participating in the reaction mechanism.
Definition Kinetics.h:201
vector< shared_ptr< ThermoPhase > > m_thermo
m_thermo is a vector of pointers to ThermoPhase objects that are involved with this kinetics operator
Definition Kinetics.h:1572
virtual bool addReaction(shared_ptr< Reaction > r, bool resize=true)
Add a single reaction to the mechanism.
Definition Kinetics.cpp:736
vector< size_t > m_revindex
Indices of reversible reactions.
Definition Kinetics.h:1609
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
Definition Kinetics.cpp:829
map< string, size_t > m_rateTypes
Mapping of rate handlers.
Definition Kinetics.h:1525
vector< double > m_ropnet
Net rate-of-progress for each reaction.
Definition Kinetics.h:1607
virtual void addThermo(shared_ptr< ThermoPhase > thermo)
Add a phase to the kinetics manager object.
Definition Kinetics.cpp:646
vector< double > m_rbuf
Buffer used for storage of intermediate reaction-specific results.
Definition Kinetics.h:1616
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
Definition Kinetics.h:1541
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:1610
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
Definition Kinetics.h:304
virtual void setMultiplier(size_t i, double f)
Set the multiplier for reaction i to f.
Definition Kinetics.h:1446
vector< double > m_rfn
Forward rate constant for each reaction.
Definition Kinetics.h:1592
StoichManagerN m_reactantStoich
Stoichiometry manager for the reactants for each reaction.
Definition Kinetics.h:1535
virtual void resizeSpecies()
Resize arrays with sizes that depend on the total number of species.
Definition Kinetics.cpp:724
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
Definition Kinetics.h:282
virtual void getNetProductionRates(double *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition Kinetics.cpp:489
size_t speciesPhaseIndex(size_t k) const
This function takes as an argument the kineticsSpecies index (that is, the list index in the list of ...
Definition Kinetics.cpp:407
An error indicating that an unimplemented function has been called.
void getCharges(double *charges) const
Copy the vector of species charges into array charges.
Definition Phase.cpp:470
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:270
double temperature() const
Temperature (K).
Definition Phase.h:629
double charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
Definition Phase.h:605
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.
virtual void getPartialMolarEnthalpies(double *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
double electricPotential() const
Returns the electric potential of this phase (V).
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 double logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
double RT() const
Return the Gas Constant multiplied by the current temperature.
void getElectrochemPotentials(double *mu) const
Get the species electrochemical potentials.
void setElectricPotential(double v)
Set the electric potential of this phase (V).
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 getPartialMolarEntropies(double *sbar) const
Returns an array of partial molar entropies of the species in the solution.
const double Faraday
Faraday constant [C/kmol].
Definition ct_defs.h:131
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
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1997
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...