Cantera  3.3.0a1
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 fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
114
115 if (m_revindex.size() > 0) {
116 /*
117 * Get the vector of standard state electrochemical potentials for
118 * species in the Interfacial kinetics object and store it in m_mu0[]
119 * and m_mu0_Kc[]
120 */
121 updateMu0();
122 double rrt = 1.0 / thermo(0).RT();
123
124 // compute Delta mu^0 for all reversible reactions
125 getRevReactionDelta(m_mu0_Kc.data(), m_rkcn.data());
126
127 for (size_t i = 0; i < m_revindex.size(); i++) {
128 size_t irxn = m_revindex[i];
129 if (irxn == npos || irxn >= nReactions()) {
130 throw CanteraError("InterfaceKinetics::updateKc",
131 "illegal value: irxn = {}", irxn);
132 }
133 // WARNING this may overflow HKM
134 m_rkcn[irxn] = exp(m_rkcn[irxn]*rrt);
135 }
136 for (size_t i = 0; i != m_irrev.size(); ++i) {
137 m_rkcn[ m_irrev[i] ] = 0.0;
138 }
139 }
140}
141
143{
144 // First task is update the electrical potentials from the Phases
146
147 // @todo There is significant potential to further simplify calculations
148 // once the old framework is removed
149 size_t ik = 0;
150 for (size_t n = 0; n < nPhases(); n++) {
152 for (size_t k = 0; k < thermo(n).nSpecies(); k++) {
153 m_mu0_Kc[ik] = m_mu0[ik] + Faraday * m_phi[n] * thermo(n).charge(k);
154 m_mu0_Kc[ik] -= thermo(0).RT() * thermo(n).logStandardConc(k);
155 ik++;
156 }
157 }
158}
159
161{
162 updateMu0();
163 double rrt = 1.0 / thermo(0).RT();
164 std::fill(kc, kc + nReactions(), 0.0);
165 getReactionDelta(m_mu0_Kc.data(), kc);
166 for (size_t i = 0; i < nReactions(); i++) {
167 kc[i] = exp(-kc[i]*rrt);
168 }
169}
170
172{
173 updateROP();
174 for (size_t i = 0; i < nReactions(); i++) {
175 // base rate coefficient multiplied by perturbation factor
176 kfwd[i] = m_rfn[i] * m_perturb[i];
177 }
178}
179
180void InterfaceKinetics::getRevRateConstants(double* krev, bool doIrreversible)
181{
183 if (doIrreversible) {
185 for (size_t i = 0; i < nReactions(); i++) {
186 krev[i] /= m_ropnet[i];
187 }
188 } else {
189 for (size_t i = 0; i < nReactions(); i++) {
190 krev[i] *= m_rkcn[i];
191 }
192 }
193}
194
196{
197 // evaluate rate constants and equilibrium constants at temperature and phi
198 // (electric potential)
200 // get updated activities (rates updated below)
202
203 if (m_ROP_ok) {
204 return;
205 }
206
207 for (size_t i = 0; i < nReactions(); i++) {
208 // Scale the base forward rate coefficient by the perturbation factor
209 m_ropf[i] = m_rfn[i] * m_perturb[i];
210 // Multiply the scaled forward rate coefficient by the reciprocal of the
211 // equilibrium constant
212 m_ropr[i] = m_ropf[i] * m_rkcn[i];
213 }
214
215 for (auto& rates : m_rateHandlers) {
216 rates->modifyRateConstants(m_ropf.data(), m_ropr.data());
217 }
218
219 // multiply ropf by the activity concentration reaction orders to obtain
220 // the forward rates of progress.
221 m_reactantStoich.multiply(m_actConc.data(), m_ropf.data());
222
223 // For reversible reactions, multiply ropr by the activity concentration
224 // products
225 m_revProductStoich.multiply(m_actConc.data(), m_ropr.data());
226
227 for (size_t j = 0; j != nReactions(); ++j) {
228 m_ropnet[j] = m_ropf[j] - m_ropr[j];
229 }
230
231 // For reactions involving multiple phases, we must check that the phase
232 // being consumed actually exists. This is particularly important for phases
233 // that are stoichiometric phases containing one species with a unity
234 // activity
235 if (m_phaseExistsCheck) {
236 for (size_t j = 0; j != nReactions(); ++j) {
237 if ((m_ropr[j] > m_ropf[j]) && (m_ropr[j] > 0.0)) {
238 for (size_t p = 0; p < nPhases(); p++) {
239 if (m_rxnPhaseIsProduct[j][p] && !m_phaseExists[p]) {
240 m_ropnet[j] = 0.0;
241 m_ropr[j] = m_ropf[j];
242 if (m_ropf[j] > 0.0) {
243 for (size_t rp = 0; rp < nPhases(); rp++) {
244 if (m_rxnPhaseIsReactant[j][rp] && !m_phaseExists[rp]) {
245 m_ropnet[j] = 0.0;
246 m_ropr[j] = m_ropf[j] = 0.0;
247 }
248 }
249 }
250 }
251 if (m_rxnPhaseIsReactant[j][p] && !m_phaseIsStable[p]) {
252 m_ropnet[j] = 0.0;
253 m_ropr[j] = m_ropf[j];
254 }
255 }
256 } else if ((m_ropf[j] > m_ropr[j]) && (m_ropf[j] > 0.0)) {
257 for (size_t p = 0; p < nPhases(); p++) {
258 if (m_rxnPhaseIsReactant[j][p] && !m_phaseExists[p]) {
259 m_ropnet[j] = 0.0;
260 m_ropf[j] = m_ropr[j];
261 if (m_ropf[j] > 0.0) {
262 for (size_t rp = 0; rp < nPhases(); rp++) {
263 if (m_rxnPhaseIsProduct[j][rp] && !m_phaseExists[rp]) {
264 m_ropnet[j] = 0.0;
265 m_ropf[j] = m_ropr[j] = 0.0;
266 }
267 }
268 }
269 }
270 if (m_rxnPhaseIsProduct[j][p] && !m_phaseIsStable[p]) {
271 m_ropnet[j] = 0.0;
272 m_ropf[j] = m_ropr[j];
273 }
274 }
275 }
276 }
277 }
278 m_ROP_ok = true;
279}
280
282{
283 // Get the chemical potentials of the species in the all of the phases used
284 // in the kinetics mechanism
285 for (size_t n = 0; n < nPhases(); n++) {
286 m_thermo[n]->getChemPotentials(m_mu.data() + m_start[n]);
287 }
288
289 // Use the stoichiometric manager to find deltaG for each reaction.
290 getReactionDelta(m_mu.data(), m_rbuf.data());
291 if (deltaG != 0 && (m_rbuf.data() != deltaG)) {
292 for (size_t j = 0; j < nReactions(); ++j) {
293 deltaG[j] = m_rbuf[j];
294 }
295 }
296}
297
299{
300 // Get the chemical potentials of the species
301 for (size_t n = 0; n < nPhases(); n++) {
303 }
304
305 // Use the stoichiometric manager to find deltaG for each reaction.
306 getReactionDelta(m_grt.data(), deltaM);
307}
308
310{
311 // Get the partial molar enthalpy of all species
312 for (size_t n = 0; n < nPhases(); n++) {
314 }
315
316 // Use the stoichiometric manager to find deltaH for each reaction.
317 getReactionDelta(m_grt.data(), deltaH);
318}
319
321{
322 // Get the partial molar entropy of all species in all of the phases
323 for (size_t n = 0; n < nPhases(); n++) {
325 }
326
327 // Use the stoichiometric manager to find deltaS for each reaction.
328 getReactionDelta(m_grt.data(), deltaS);
329}
330
332{
333 // Get the standard state chemical potentials of the species. This is the
334 // array of chemical potentials at unit activity We define these here as the
335 // chemical potentials of the pure species at the temperature and pressure
336 // of the solution.
337 for (size_t n = 0; n < nPhases(); n++) {
339 }
340
341 // Use the stoichiometric manager to find deltaG for each reaction.
342 getReactionDelta(m_mu0.data(), deltaGSS);
343}
344
346{
347 // Get the standard state enthalpies of the species. This is the array of
348 // chemical potentials at unit activity We define these here as the
349 // enthalpies of the pure species at the temperature and pressure of the
350 // solution.
351 for (size_t n = 0; n < nPhases(); n++) {
352 thermo(n).getEnthalpy_RT(m_grt.data() + m_start[n]);
353 }
354 for (size_t k = 0; k < m_kk; k++) {
355 m_grt[k] *= thermo(0).RT();
356 }
357
358 // Use the stoichiometric manager to find deltaH for each reaction.
359 getReactionDelta(m_grt.data(), deltaH);
360}
361
363{
364 // Get the standard state entropy of the species. We define these here as
365 // the entropies of the pure species at the temperature and pressure of the
366 // solution.
367 for (size_t n = 0; n < nPhases(); n++) {
368 thermo(n).getEntropy_R(m_grt.data() + m_start[n]);
369 }
370 for (size_t k = 0; k < m_kk; k++) {
371 m_grt[k] *= GasConstant;
372 }
373
374 // Use the stoichiometric manager to find deltaS for each reaction.
375 getReactionDelta(m_grt.data(), deltaS);
376}
377
378bool InterfaceKinetics::addReaction(shared_ptr<Reaction> r_base, bool resize)
379{
380 if (!m_surf) {
381 init();
382 }
383
384 size_t i = nReactions();
385 shared_ptr<ReactionRate> rate = r_base->rate();
386 if (rate) {
387 rate->setContext(*r_base, *this);
388 }
389
390 bool added = Kinetics::addReaction(r_base, resize);
391 if (!added) {
392 return false;
393 }
394
395 m_rxnPhaseIsReactant.emplace_back(nPhases(), false);
396 m_rxnPhaseIsProduct.emplace_back(nPhases(), false);
397
398 for (const auto& [name, stoich] : r_base->reactants) {
399 size_t k = kineticsSpeciesIndex(name);
400 size_t p = speciesPhaseIndex(k);
401 m_rxnPhaseIsReactant[i][p] = true;
402 }
403 for (const auto& [name, stoich] : r_base->products) {
404 size_t k = kineticsSpeciesIndex(name);
405 size_t p = speciesPhaseIndex(k);
406 m_rxnPhaseIsProduct[i][p] = true;
407 }
408
409 // Set index of rate to number of reaction within kinetics
410 rate->setRateIndex(nReactions() - 1);
411
412 string rtype = rate->subType();
413 if (rtype == "") {
414 rtype = rate->type();
415 }
416
417 // If necessary, add new interface MultiRate evaluator
418 if (m_rateTypes.find(rtype) == m_rateTypes.end()) {
419 m_rateTypes[rtype] = m_rateHandlers.size();
420 m_rateHandlers.push_back(rate->newMultiRate());
421 m_rateHandlers.back()->resize(m_kk, nReactions(), nPhases());
422 }
423
424 // Add reaction rate to evaluator
425 size_t index = m_rateTypes[rtype];
426 m_rateHandlers[index]->add(nReactions() - 1, *rate);
427
428 // Set flag for coverage dependence to true
429 if (rate->compositionDependent()) {
431 }
432
433 // Set flag for electrochemistry to true
434 if (r_base->usesElectrochemistry(*this)) {
436 }
437
438 return true;
439}
440
441void InterfaceKinetics::modifyReaction(size_t i, shared_ptr<Reaction> r_base)
442{
443 Kinetics::modifyReaction(i, r_base);
444
445 shared_ptr<ReactionRate> rate = r_base->rate();
446 rate->setRateIndex(i);
447 rate->setContext(*r_base, *this);
448
449 string rtype = rate->subType();
450 if (rtype == "") {
451 rtype = rate->type();
452 }
453
454 // Ensure that interface MultiRate evaluator is available
455 if (!m_rateTypes.count(rtype)) {
456 throw CanteraError("InterfaceKinetics::modifyReaction",
457 "Interface evaluator not available for type '{}'.", rtype);
458 }
459 // Replace reaction rate evaluator
460 size_t index = m_rateTypes[rate->type()];
461 m_rateHandlers[index]->replace(i, *rate);
462
463 // Invalidate cached data
464 m_redo_rates = true;
465 m_temp += 0.1;
466}
467
468void InterfaceKinetics::setMultiplier(size_t i, double f)
469{
471 m_ROP_ok = false;
472}
473
474void InterfaceKinetics::setIOFlag(int ioFlag)
475{
476 m_ioFlag = ioFlag;
477 if (m_integrator) {
478 m_integrator->setIOFlag(ioFlag);
479 }
480}
481
482void InterfaceKinetics::addThermo(shared_ptr<ThermoPhase> thermo)
483{
485 m_phaseExists.push_back(true);
486 m_phaseIsStable.push_back(true);
487}
488
490{
491 if (thermo(0).nDim() > 2) {
492 throw CanteraError("InterfaceKinetics::init", "no interface phase is present.");
493 }
494}
495
497{
498 size_t kOld = m_kk;
500 if (m_kk != kOld && nReactions()) {
501 throw CanteraError("InterfaceKinetics::resizeSpecies", "Cannot add"
502 " species to InterfaceKinetics after reactions have been added.");
503 }
504 m_actConc.resize(m_kk);
505 m_conc.resize(m_kk);
506 m_mu0.resize(m_kk);
507 m_mu.resize(m_kk);
508 m_mu0_Kc.resize(m_kk);
509 m_grt.resize(m_kk);
510 m_phi.resize(nPhases(), 0.0);
511}
512
513void InterfaceKinetics::advanceCoverages(double tstep, double rtol, double atol,
514 double maxStepSize, size_t maxSteps, size_t maxErrTestFails)
515{
516 if (m_integrator == 0) {
517 vector<InterfaceKinetics*> k{this};
519 }
520 m_integrator->setTolerances(rtol, atol);
521 m_integrator->setMaxStepSize(maxStepSize);
522 m_integrator->setMaxSteps(maxSteps);
523 m_integrator->setMaxErrTestFails(maxErrTestFails);
524 m_integrator->integrate(0.0, tstep);
525 delete m_integrator;
526 m_integrator = 0;
527}
528
530 int ifuncOverride, double timeScaleOverride)
531{
532 // create our own solver object
533 if (m_integrator == 0) {
534 vector<InterfaceKinetics*> k{this};
537 }
538 m_integrator->setIOFlag(m_ioFlag);
539 // New direct method to go here
540 m_integrator->solvePseudoSteadyStateProblem(ifuncOverride, timeScaleOverride);
541}
542
543void InterfaceKinetics::setPhaseExistence(const size_t iphase, const int exists)
544{
545 checkPhaseIndex(iphase);
546 if (exists) {
547 if (!m_phaseExists[iphase]) {
550 m_phaseExists[iphase] = true;
551 }
552 m_phaseIsStable[iphase] = true;
553 } else {
554 if (m_phaseExists[iphase]) {
556 m_phaseExists[iphase] = false;
557 }
558 m_phaseIsStable[iphase] = false;
559 }
560}
561
562int InterfaceKinetics::phaseExistence(const size_t iphase) const
563{
564 checkPhaseIndex(iphase);
565 return m_phaseExists[iphase];
566}
567
568int InterfaceKinetics::phaseStability(const size_t iphase) const
569{
570 checkPhaseIndex(iphase);
571 return m_phaseIsStable[iphase];
572}
573
574void InterfaceKinetics::setPhaseStability(const size_t iphase, const int isStable)
575{
576 checkPhaseIndex(iphase);
577 if (isStable) {
578 m_phaseIsStable[iphase] = true;
579 } else {
580 m_phaseIsStable[iphase] = false;
581 }
582}
583
584double InterfaceKinetics::interfaceCurrent(const size_t iphase)
585{
586 vector<double> charges(m_kk, 0.0);
587 vector<double> netProdRates(m_kk, 0.0);
588 double dotProduct = 0.0;
589
590 thermo(iphase).getCharges(charges.data());
591 getNetProductionRates(netProdRates.data());
592
593 for (size_t k = 0; k < thermo(iphase).nSpecies(); k++)
594 {
595 dotProduct += charges[k] * netProdRates[m_start[iphase] + k];
596 }
597
598 return dotProduct * Faraday;
599}
600
602{
603 // check derivatives are valid
604 assertDerivativesValid("InterfaceKinetics::fwdRatesOfProgress_ddCi");
605 // forward reaction rate coefficients
606 vector<double>& rop_rates = m_rbuf0;
607 getFwdRateConstants(rop_rates.data());
609}
610
612{
613 // check derivatives are valid
614 assertDerivativesValid("InterfaceKinetics::revRatesOfProgress_ddCi");
615 // reverse reaction rate coefficients
616 vector<double>& rop_rates = m_rbuf0;
617 getFwdRateConstants(rop_rates.data());
618 applyEquilibriumConstants(rop_rates.data());
620}
621
623{
624 // check derivatives are valid
625 assertDerivativesValid("InterfaceKinetics::netRatesOfProgress_ddCi");
626 // forward reaction rate coefficients
627 vector<double>& rop_rates = m_rbuf0;
628 getFwdRateConstants(rop_rates.data());
629 Eigen::SparseMatrix<double> jac = calculateCompositionDerivatives(m_reactantStoich,
630 rop_rates);
631
632 // reverse reaction rate coefficients
633 applyEquilibriumConstants(rop_rates.data());
635}
636
638{
639 bool force = settings.empty();
640 if (force || settings.hasKey("skip-coverage-dependence")) {
641 m_jac_skip_coverage_dependence = settings.getBool("skip-coverage-dependence",
642 false);
643 }
644 if (force || settings.hasKey("skip-electrochemistry")) {
645 m_jac_skip_electrochemistry = settings.getBool("skip-electrochemistry",
646 false);
647 }
648 if (force || settings.hasKey("rtol-delta")) {
649 m_jac_rtol_delta = settings.getDouble("rtol-delta", 1e-8);
650 }
651}
652
654{
655 settings["skip-coverage-dependence"] = m_jac_skip_electrochemistry;
656 settings["skip-electrochemistry"] = m_jac_skip_coverage_dependence;
657 settings["rtol-delta"] = m_jac_rtol_delta;
658}
659
661 StoichManagerN& stoich, const vector<double>& in)
662{
663 vector<double>& outV = m_rbuf1;
664 // derivatives handled by StoichManagerN
665 copy(in.begin(), in.end(), outV.begin());
666 return stoich.derivatives(m_actConc.data(), outV.data());
667}
668
670{
672 throw NotImplementedError(name, "Coverage-dependent reactions not supported.");
674 throw NotImplementedError(name, "Electrochemical reactions not supported.");
675 }
676}
677
679{
680 // For reverse rates computed from thermochemistry, multiply the forward
681 // rate coefficients by the reciprocals of the equilibrium constants
682 for (size_t i = 0; i < nReactions(); ++i) {
683 rop[i] *= m_rkcn[i];
684 }
685}
686
687}
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 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:67
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
Definition Kinetics.h:239
vector< double > m_perturb
Vector of perturbation factors for each reaction's rate of progress vector.
Definition Kinetics.h:1481
vector< double > m_ropf
Forward rate-of-progress for each reaction.
Definition Kinetics.h:1529
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:391
vector< unique_ptr< MultiRateBase > > m_rateHandlers
Vector of rate handlers.
Definition Kinetics.h:1452
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:1506
vector< double > m_rkcn
Reciprocal of the equilibrium constant in concentration units.
Definition Kinetics.h:1526
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
Definition Kinetics.h:1477
virtual void getReactionDelta(const double *property, double *deltaProperty) const
Change in species properties.
Definition Kinetics.cpp:382
vector< double > m_dH
The enthalpy change for each reaction to calculate Blowers-Masel rates.
Definition Kinetics.h:1541
vector< double > m_ropr
Reverse rate-of-progress for each reaction.
Definition Kinetics.h:1532
size_t nPhases() const
The number of phases participating in the reaction mechanism.
Definition Kinetics.h:189
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:1500
virtual bool addReaction(shared_ptr< Reaction > r, bool resize=true)
Add a single reaction to the mechanism.
Definition Kinetics.cpp:672
vector< size_t > m_revindex
Indices of reversible reactions.
Definition Kinetics.h:1537
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
Definition Kinetics.cpp:765
map< string, size_t > m_rateTypes
Mapping of rate handlers.
Definition Kinetics.h:1453
vector< double > m_ropnet
Net rate-of-progress for each reaction.
Definition Kinetics.h:1535
virtual void addThermo(shared_ptr< ThermoPhase > thermo)
Add a phase to the kinetics manager object.
Definition Kinetics.cpp:582
vector< double > m_rbuf
Buffer used for storage of intermediate reaction-specific results.
Definition Kinetics.h:1544
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
Definition Kinetics.h:1469
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:1538
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
Definition Kinetics.h:273
virtual void setMultiplier(size_t i, double f)
Set the multiplier for reaction i to f.
Definition Kinetics.h:1374
vector< double > m_rfn
Forward rate constant for each reaction.
Definition Kinetics.h:1520
StoichManagerN m_reactantStoich
Stoichiometry manager for the reactants for each reaction.
Definition Kinetics.h:1463
virtual void resizeSpecies()
Resize arrays with sizes that depend on the total number of species.
Definition Kinetics.cpp:660
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
Definition Kinetics.h:251
virtual void getNetProductionRates(double *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition Kinetics.cpp:425
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:343
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:430
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:245
double temperature() const
Temperature (K).
Definition Phase.h:598
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:574
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
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...