22InterfaceKinetics::~InterfaceKinetics()
57 if (T !=
m_temp || m_redo_rates) {
59 for (
size_t n = 0; n <
nPhases(); n++) {
74 bool changed = rates->update(
thermo(0), *
this);
76 rates->getRateConstants(
m_rfn);
90 for (
size_t n = 0; n <
nPhases(); n++) {
100 for (
size_t n = 0; n <
nPhases(); n++) {
101 const auto& tp =
thermo(n);
109 tp.getActivityConcentrations(
113 tp.getConcentrations(span<double>(
m_conc).subspan(
m_start[n], tp.nSpecies()));
134 for (
size_t i = 0; i <
m_revindex.size(); i++) {
138 "illegal value: irxn = {}", irxn);
143 for (
size_t i = 0; i !=
m_irrev.size(); ++i) {
157 for (
size_t n = 0; n <
nPhases(); n++) {
172 std::fill(kc.begin(), kc.end(), 0.0);
175 kc[i] = exp(-kc[i]*rrt);
192 if (doIrreversible) {
247 for (
size_t p = 0; p <
nPhases(); p++) {
252 for (
size_t rp = 0; rp <
nPhases(); rp++) {
266 for (
size_t p = 0; p <
nPhases(); p++) {
271 for (
size_t rp = 0; rp <
nPhases(); rp++) {
294 for (
size_t n = 0; n <
nPhases(); n++) {
301 if (deltaG.data() !=
m_rbuf.data()) {
309 for (
size_t n = 0; n <
nPhases(); n++) {
321 for (
size_t n = 0; n <
nPhases(); n++) {
333 for (
size_t n = 0; n <
nPhases(); n++) {
348 for (
size_t n = 0; n <
nPhases(); n++) {
363 for (
size_t n = 0; n <
nPhases(); n++) {
367 for (
size_t k = 0; k <
m_kk; k++) {
380 for (
size_t n = 0; n <
nPhases(); n++) {
384 for (
size_t k = 0; k <
m_kk; k++) {
399 shared_ptr<ReactionRate> rate = r_base->rate();
401 rate->setContext(*r_base, *
this);
412 for (
const auto& [name, stoich] : r_base->reactants) {
417 for (
const auto& [name, stoich] : r_base->products) {
426 string rtype = rate->subType();
428 rtype = rate->type();
443 if (rate->compositionDependent()) {
448 if (r_base->usesElectrochemistry(*
this)) {
459 shared_ptr<ReactionRate> rate = r_base->rate();
460 rate->setRateIndex(i);
461 rate->setContext(*r_base, *
this);
463 string rtype = rate->subType();
465 rtype = rate->type();
471 "Interface evaluator not available for type '{}'.", rtype);
497 if (
thermo(0).nDim() > 2) {
498 throw CanteraError(
"InterfaceKinetics::init",
"no interface phase is present.");
507 throw CanteraError(
"InterfaceKinetics::resizeSpecies",
"Cannot add"
508 " species to InterfaceKinetics after reactions have been added.");
522 if (!
phase->root()) {
524 "Phase '{}' is not attached to a Solution.",
phase->name());
527 vector<shared_ptr<ReactorBase>> reservoirs;
528 for (
size_t i = 1; i <
nPhases(); i++) {
530 reservoirs.push_back(r);
537 double maxStepSize,
size_t maxSteps,
size_t maxErrTestFails)
540 vector<vector<double>> savedStates(
nPhases());
541 for (
size_t i = 1; i <
nPhases(); i++) {
559 for (
size_t i = 1; i <
nPhases(); i++) {
567 vector<vector<double>> savedStates(
nPhases());
568 for (
size_t i = 1; i <
nPhases(); i++) {
582 for (
size_t i = 1; i <
nPhases(); i++) {
630 vector<double> charges(
m_kk, 0.0);
631 vector<double> netProdRates(
m_kk, 0.0);
632 double dotProduct = 0.0;
639 dotProduct += charges[k] * netProdRates[
m_start[iphase] + k];
650 vector<double>& rop_rates =
m_rbuf0;
660 vector<double>& rop_rates =
m_rbuf0;
671 vector<double>& rop_rates =
m_rbuf0;
683 bool force = settings.
empty();
684 if (force || settings.
hasKey(
"skip-coverage-dependence")) {
688 if (force || settings.
hasKey(
"skip-electrochemistry")) {
692 if (force || settings.
hasKey(
"rtol-delta")) {
707 vector<double>& outV = m_rbuf1;
709 copy(in.begin(), in.end(), outV.begin());
Header file for class ReactorSurface.
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.
double getDouble(const string &key, double default_) const
If key exists, return it as a double, otherwise return default_.
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
bool empty() const
Return boolean indicating whether AnyMap is empty.
bool getBool(const string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
Base class for exceptions thrown by Cantera classes.
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.
void getDeltaElectrochemPotentials(span< double > deltaM) override
Return the vector of values for the reaction electrochemical free energy change.
void applyEquilibriumConstants(span< double > rop)
Multiply rate with inverse equilibrium constant.
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...
vector< bool > m_phaseExists
Vector of booleans indicating whether phases exist or not.
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 getDeltaEnthalpy(span< double > deltaH) override
Return the vector of values for the reactions change in enthalpy.
void getEquilibriumConstants(span< double > kc) override
Equilibrium constant for all reactions including the voltage term.
void solvePseudoSteadyStateProblem(int loglevel=0)
Solve for the pseudo steady-state of the surface problem.
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 getFwdRateConstants(span< double > kfwd) override
Return the forward rate constants.
ReactorNet * m_integrator
Pointer to the Implicit surface chemistry object.
void buildNetwork()
Create a ReactorNet where only the surface species are active, for use with advanceCoverages() and so...
void setMultiplier(size_t i, double f) override
Set the multiplier for reaction i to f.
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 getDeltaSSGibbs(span< double > deltaG) override
Return the vector of values for the reaction standard state Gibbs free energy change.
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.
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 getDerivativeSettings(AnyMap &settings) const override
Retrieve derivative settings.
Eigen::SparseMatrix< double > fwdRatesOfProgress_ddCi() override
Calculate derivatives for forward rates-of-progress with respect to species concentration at constant...
void modifyReaction(size_t i, shared_ptr< Reaction > rNew) override
Modify the rate expression associated with a reaction.
void getRevRateConstants(span< double > krev, bool doIrreversible=false) override
Return the reverse rate constants.
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.
void getDeltaSSEnthalpy(span< double > deltaH) override
Return the vector of values for the change in the standard state enthalpies of reaction.
Eigen::SparseMatrix< double > calculateCompositionDerivatives(StoichManagerN &stoich, span< const double > in)
Process mole fraction derivative.
vector< double > m_mu0_Kc
Vector of standard state electrochemical potentials modified by a standard concentration term.
void _update_rates_T()
Update properties that depend on temperature.
void getDeltaEntropy(span< double > deltaS) override
Return the vector of values for the reactions change in entropy.
void getDeltaSSEntropy(span< double > deltaS) override
Return the vector of values for the change in the standard state entropies for each reaction.
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 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 > netRatesOfProgress_ddCi() override
Calculate derivatives for net rates-of-progress with respect to species concentration at constant tem...
vector< vector< bool > > m_rxnPhaseIsProduct
Vector of vector of booleans indicating whether a phase participates in a reaction as a product.
void getDeltaGibbs(span< double > deltaG) override
Return the vector of values for the reaction Gibbs free energy change.
void setDerivativeSettings(const AnyMap &settings) override
Set/modify derivative settings.
vector< double > m_conc
Array of concentrations for each species in the kinetics mechanism.
shared_ptr< ThermoPhase > phase(size_t n=0) const
Return pointer to phase associated with Kinetics by index.
virtual void resizeReactions()
Finalize Kinetics object and associated objects.
size_t checkPhaseIndex(size_t m) const
Check that the specified phase index is in range.
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
vector< double > m_perturb
Vector of perturbation factors for each reaction's rate of progress vector.
vector< double > m_ropf
Forward rate-of-progress for each reaction.
vector< unique_ptr< MultiRateBase > > m_rateHandlers
Vector of rate handlers.
vector< size_t > m_start
m_start is a vector of integers specifying the beginning position for the species vector for the n'th...
vector< double > m_rkcn
Reciprocal of the equilibrium constant in concentration units.
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
vector< double > m_dH
The enthalpy change for each reaction to calculate Blowers-Masel rates.
vector< double > m_ropr
Reverse rate-of-progress for each reaction.
size_t nPhases() const
The number of phases participating in the reaction mechanism.
vector< shared_ptr< ThermoPhase > > m_thermo
m_thermo is a vector of pointers to ThermoPhase objects that are involved with this kinetics operator
virtual bool addReaction(shared_ptr< Reaction > r, bool resize=true)
Add a single reaction to the mechanism.
vector< size_t > m_revindex
Indices of reversible reactions.
shared_ptr< Solution > root() const
Get the Solution object containing this Kinetics object and associated ThermoPhase objects.
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
map< string, size_t > m_rateTypes
Mapping of rate handlers.
vector< double > m_ropnet
Net rate-of-progress for each reaction.
virtual void addThermo(shared_ptr< ThermoPhase > thermo)
Add a phase to the kinetics manager object.
virtual void getRevReactionDelta(span< const double > g, span< double > dg) const
Given an array of species properties 'g', return in array 'dg' the change in this quantity in the rev...
vector< double > m_rbuf
Buffer used for storage of intermediate reaction-specific results.
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
size_t nReactions() const
Number of reactions in the reaction mechanism.
vector< size_t > m_irrev
Indices of irreversible reactions.
virtual void getNetProductionRates(span< double > wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
virtual void getReactionDelta(span< const double > property, span< double > deltaProperty) const
Change in species properties.
virtual void setMultiplier(size_t i, double f)
Set the multiplier for reaction i to f.
vector< double > m_rfn
Forward rate constant for each reaction.
StoichManagerN m_reactantStoich
Stoichiometry manager for the reactants for each reaction.
virtual void resizeSpecies()
Resize arrays with sizes that depend on the total number of species.
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 ...
An error indicating that an unimplemented function has been called.
size_t nSpecies() const
Returns the number of species in the phase.
double temperature() const
Temperature (K).
virtual void restorePartialState(span< const double > state)
Set the internal thermodynamic state of the phase, excluding composition.
void getCharges(span< double > charges) const
Copy the vector of species charges into array charges.
virtual size_t partialStateSize() const
Get the size of the partial state vector of the phase.
virtual void savePartialState(span< double > state) const
Save the current thermodynamic state of the phase, excluding composition.
double charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
A class representing a network of connected reactors.
void advance(double t)
Advance the state of all reactors in the independent variable (time or space).
virtual void setMaxSteps(int nmax)
Set the maximum number of internal integration steps the integrator will take before reaching the nex...
void setInitialTime(double time)
Set the initial value of the independent variable (typically time).
void setMaxErrTestFails(int nmax)
Set the maximum number of error test failures permitted by the CVODES integrator in a single step.
void solveSteady(int loglevel=0)
Solve directly for the steady-state solution.
void setMaxTimeStep(double maxstep)
Set the maximum integrator step.
void setVerbose(bool v=true)
Enable or disable verbose logging while setting up and integrating the reactor network.
void setTolerances(double rtol, double atol)
Set the relative and absolute tolerances for the integrator.
This class handles operations involving the stoichiometric coefficients on one side of a reaction (re...
Eigen::SparseMatrix< double > derivatives(span< const double > conc, span< const double > rates)
Calculate derivatives with respect to species concentrations.
double electricPotential() const
Returns the electric potential of this phase (V).
virtual void getPartialMolarEnthalpies(span< double > hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void setState_TP(double t, double p)
Set the temperature (K) and pressure (Pa)
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.
virtual void getPartialMolarEntropies(span< double > sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual void getStandardChemPotentials(span< double > mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void setElectricPotential(double v)
Set the electric potential of this phase (V).
void getElectrochemPotentials(span< double > mu) const
Get the species electrochemical potentials.
virtual void getEntropy_R(span< double > sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
virtual void getEnthalpy_RT(span< double > hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
const double Faraday
Faraday constant [C/kmol].
const double GasConstant
Universal Gas Constant [J/kmol/K].
shared_ptr< ReactorSurface > newReactorSurface(shared_ptr< Solution > phase, span< shared_ptr< ReactorBase > > reactors, bool clone, const string &name)
Create a ReactorSurface object with the specified contents and adjacent reactors participating in sur...
shared_ptr< Reservoir > newReservoir(shared_ptr< Solution > phase, bool clone, const string &name)
Create a Reservoir object with the specified contents.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
void checkArraySize(const char *procedure, size_t available, size_t required)
Wrapper for throwing ArraySizeError.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...