20 InterfaceKinetics::InterfaceKinetics(
thermo_t* thermo) :
32 m_ProdStanConcReac(0),
39 m_has_coverage_dependence(false),
40 m_has_electrochem_rxns(false),
41 m_has_exchange_current_density_formulation(false),
42 m_phaseExistsCheck(false),
45 m_rxnPhaseIsReactant(0),
46 m_rxnPhaseIsProduct(0),
71 m_ProdStanConcReac(0),
78 m_has_coverage_dependence(false),
79 m_has_electrochem_rxns(false),
80 m_has_exchange_current_density_formulation(false),
81 m_phaseExistsCheck(false),
84 m_rxnPhaseIsReactant(0),
85 m_rxnPhaseIsProduct(0),
100 if (
this == &right) {
109 m_redo_rates = right.m_redo_rates;
126 m_beta = right.m_beta;
129 m_StandardConc = right.m_StandardConc;
130 m_deltaG0 = right.m_deltaG0;
131 m_ProdStanConcReac = right.m_ProdStanConcReac;
132 m_logp0 = right.m_logp0;
133 m_logc0 = right.m_logc0;
134 m_ropf = right.m_ropf;
135 m_ropr = right.m_ropr;
136 m_ropnet = right.m_ropnet;
137 m_ROP_ok = right.m_ROP_ok;
141 m_rkcn = right.m_rkcn;
151 m_ioFlag = right.m_ioFlag;
158 return cInterfaceKinetics;
184 if (T !=
m_temp || m_redo_rates) {
196 m_redo_rates =
false;
202 for (
size_t n = 0; n <
nPhases(); n++) {
212 for (
size_t n = 0; n <
nPhases(); n++) {
234 fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
244 doublereal rrt = 1.0 / rt;
246 for (
size_t n = 0; n < np; n++) {
249 for (
size_t k = 0; k < nsp; k++) {
259 for (
size_t i = 0; i <
m_nrev; i++) {
263 "illegal value: irxn = "+
int2str(irxn));
266 m_rkcn[irxn] = exp(m_rkcn[irxn]*rrt);
268 for (
size_t i = 0; i !=
m_nirrev; ++i) {
274 void InterfaceKinetics::checkPartialEquil()
285 for (
size_t n = 0; n <
nPhases(); n++) {
288 for (
size_t k = 0; k < nsp; k++) {
299 for (
size_t i = 0; i <
m_nrev; i++) {
302 <<
" " << rmu[irxn]/rt << endl;
303 printf(
"%12.6e %12.6e %12.6e %12.6e \n",
304 m_ropf[irxn], m_ropr[irxn], m_ropnet[irxn],
305 m_ropnet[irxn]/(m_ropf[irxn] + m_ropr[irxn]));
313 std::copy(m_ropf.begin(), m_ropf.end(), fwdROP);
319 std::copy(m_ropr.begin(), m_ropr.end(), revROP);
325 std::copy(m_ropnet.begin(), m_ropnet.end(), netROP);
332 doublereal rrt = 1.0/rt;
333 for (
size_t n = 0; n <
nPhases(); n++) {
336 for (
size_t k = 0; k < nsp; k++) {
343 fill(kc, kc +
m_ii, 0.0);
347 for (
size_t i = 0; i <
m_ii; i++) {
348 kc[i] = exp(-kc[i]*rrt);
352 void InterfaceKinetics::getExchangeCurrentQuantities()
362 for (
size_t n = 0; n <
nPhases(); n++) {
365 for (
size_t k = 0; k < nsp; k++) {
373 for (
size_t i = 0; i <
m_ii; i++) {
374 m_ProdStanConcReac[i] = 1.0;
403 for (
size_t n = 0; n <
nPhases(); n++) {
405 for (
size_t k = 0; k < nsp; k++) {
427 #ifdef DEBUG_KIN_MODE
430 for (
size_t i = 0; i < m_beta.size(); i++) {
432 eamod = m_beta[i]*
m_rwork[irxn];
435 #ifdef DEBUG_KIN_MODE
437 if (eamod + ea < 0.0) {
438 writelog(
"Warning: act energy mod too large!\n");
442 for (n = 0; n < np; n++) {
449 doublereal rrt = 1.0/rt;
450 kf[irxn] *= exp(-eamod*rrt);
457 getExchangeCurrentQuantities();
459 doublereal rrt = 1.0/rt;
460 for (
size_t i = 0; i <
m_ctrxn.size(); i++) {
463 if (iECDFormulation) {
464 double tmp = exp(- m_beta[i] * m_deltaG0[irxn] * rrt);
465 double tmp2 = m_ProdStanConcReac[irxn];
466 tmp *= 1.0 / tmp2 / Faraday;
478 copy(m_rfn.begin(), m_rfn.end(), kfwd);
488 if (doIrreversible) {
490 for (
size_t i = 0; i <
m_ii; i++) {
491 krev[i] /= m_ropnet[i];
501 "To be removed in Cantera 2.2.");
502 copy(
m_E.begin(),
m_E.end(), E);
515 copy(m_rfn.begin(), m_rfn.end(), m_ropf.begin());
521 copy(m_ropf.begin(), m_ropf.end(), m_ropr.begin());
541 for (
size_t j = 0; j !=
m_ii; ++j) {
542 m_ropnet[j] = m_ropf[j] - m_ropr[j];
551 for (
size_t j = 0; j !=
m_ii; ++j) {
552 if ((m_ropr[j] > m_ropf[j]) && (m_ropr[j] > 0.0)) {
553 for (
size_t p = 0; p <
nPhases(); p++) {
557 m_ropr[j] = m_ropf[j];
558 if (m_ropf[j] > 0.0) {
559 for (
size_t rp = 0; rp <
nPhases(); rp++) {
563 m_ropr[j] = m_ropf[j] = 0.0;
573 m_ropr[j] = m_ropf[j];
577 }
else if ((m_ropf[j] > m_ropr[j]) && (m_ropf[j] > 0.0)) {
578 for (
size_t p = 0; p <
nPhases(); p++) {
582 m_ropf[j] = m_ropr[j];
583 if (m_ropf[j] > 0.0) {
584 for (
size_t rp = 0; rp <
nPhases(); rp++) {
588 m_ropf[j] = m_ropr[j] = 0.0;
598 m_ropf[j] = m_ropr[j];
615 for (
size_t n = 0; n <
nPhases(); n++) {
636 for (
size_t n = 0; n < np; n++) {
652 for (
size_t n = 0; n <
nPhases(); n++) {
668 for (
size_t n = 0; n <
nPhases(); n++) {
686 for (
size_t n = 0; n <
nPhases(); n++) {
704 for (
size_t n = 0; n <
nPhases(); n++) {
708 for (
size_t k = 0; k <
m_kk; k++) {
725 for (
size_t n = 0; n <
nPhases(); n++) {
729 for (
size_t k = 0; k <
m_kk; k++) {
745 addElementaryReaction(r);
769 const std::vector<size_t>& vr =
reactants(i);
770 for (
size_t ik = 0; ik < vr.size(); ik++) {
775 const std::vector<size_t>& vp =
products(i);
776 for (
size_t ik = 0; ik < vp.size(); ik++) {
783 void InterfaceKinetics::addElementaryReaction(
ReactionData& r)
787 size_t ncov = r.
cov.size();
791 for (
size_t m = 0; m < ncov; m++) {
792 rp.push_back(r.
cov[m]);
800 if (r.
rateCoeffType == EXCHANGE_CURRENT_REACTION_RATECOEFF_TYPE) {
809 size_t iloc =
m_rates.install(reactionNumber(), r);
821 m_beta.push_back(r.
beta);
822 m_ctrxn.push_back(reactionNumber());
823 if (r.
rateCoeffType == EXCHANGE_CURRENT_REACTION_RATECOEFF_TYPE) {
836 void InterfaceKinetics::setIOFlag(
int ioFlag)
871 void InterfaceKinetics::installReagents(
const ReactionData& r)
879 m_ropf.push_back(0.0);
880 m_ropr.push_back(0.0);
881 m_ropnet.push_back(0.0);
882 m_rkcn.push_back(0.0);
888 size_t rnum = reactionNumber();
897 std::vector<size_t> rk;
898 size_t nr = r.reactants.size();
899 for (n = 0; n < nr; n++) {
900 nsFlt = r.rstoich[n];
902 if ((doublereal) ns != nsFlt) {
913 m_rrxn[r.reactants[n]][rnum] = nsFlt;
914 for (m = 0; m < ns; m++) {
915 rk.push_back(r.reactants[n]);
924 std::vector<size_t> pk;
925 size_t np = r.products.size();
926 for (n = 0; n < np; n++) {
927 nsFlt = r.pstoich[n];
929 if ((doublereal) ns != nsFlt) {
940 m_prxn[r.products[n]][rnum] = nsFlt;
941 for (m = 0; m < ns; m++) {
942 pk.push_back(r.products[n]);
964 m_irrev.push_back(reactionNumber());
979 for (
size_t n = 0; n <
nPhases(); n++) {
994 size_t safe_reaction_size = std::max<size_t>(
nReactions(), 1);
995 m_rwork.resize(safe_reaction_size);
998 "no surface phase is present.");
1002 "expected interface dimension = 2, but got dimension = "
1005 m_StandardConc.resize(
m_kk, 0.0);
1006 m_deltaG0.resize(safe_reaction_size, 0.0);
1007 m_ProdStanConcReac.resize(safe_reaction_size, 0.0);
1010 throw CanteraError(
"InterfaceKinetics::finalize",
"internal error");
1017 m_ropf.resize(1, 0.0);
1018 m_ropr.resize(1, 0.0);
1019 m_ropnet.resize(1, 0.0);
1020 m_rkcn.resize(1, 0.0);
1028 for (
size_t i = 0; i <
m_ctrxn.size(); i++) {
1045 vector<InterfaceKinetics*> k;
1060 vector<InterfaceKinetics*> k;
1075 throw CanteraError(
"InterfaceKinetics:setPhaseExistence",
"out of bounds");
1099 throw CanteraError(
"InterfaceKinetics:phaseExistence()",
"out of bounds");
1107 throw CanteraError(
"InterfaceKinetics:phaseStability()",
"out of bounds");
1115 throw CanteraError(
"InterfaceKinetics:setPhaseStability",
"out of bounds");
1129 "no edge phase is present.");
1133 "expected interface dimension = 1, but got dimension = "
1140 m_ropf.resize(1, 0.0);
1141 m_ropr.resize(1, 0.0);
1142 m_ropnet.resize(1, 0.0);
1143 m_rkcn.resize(1, 0.0);
virtual void getActivationEnergies(doublereal *E)
Return the activation energies in Kelvin.
virtual void getNetProductionRates(size_t nsp, const doublereal *ropnet, doublereal *w)
Species net production rates.
void setElectricPotential(int n, doublereal V)
Set the electric potential in the nth phase.
int phaseStability(const size_t iphase) const
Gets the phase stability int for the ith phase.
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
std::vector< thermo_t * > m_thermo
m_thermo is a vector of pointers to ThermoPhase objects that are involved with this kinetics operator...
virtual void getCreationRates(doublereal *cdot)
Species creation rates [kmol/m^3/s or kmol/m^2/s].
doublereal electricPotential() const
Returns the electric potential of this phase (V).
void incrementRxnCount()
Increment the number of reactions in the mechanism by one.
virtual bool ready() const
Returns true if the kinetics manager has been properly initialized and finalized. ...
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase, assuming an ideal solution model (see Thermodynamic Properties and class SurfPhase).
std::vector< std::vector< size_t > > m_reactants
This is a vector of vectors containing the reactants for each reaction.
doublereal m_logtemp
Current log of the temperature.
virtual void getDeltaEnthalpy(doublereal *deltaH)
Return the vector of values for the reactions change in enthalpy.
virtual void getDestructionRates(size_t nSpecies, const doublereal *fwdRatesOfProgress, const doublereal *revRatesOfProgress, doublereal *destructionRates)
Species destruction rates.
virtual void assignShallowPointers(const std::vector< thermo_t * > &tpVector)
Reassign the pointers within the Kinetics object.
virtual void getNetProductionRates(doublereal *net)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
doublereal electrochem_beta(size_t irxn) const
Return the charge transfer rxn Beta parameter for the ith reaction.
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
thermo_t & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism...
void setElectricPotential(doublereal v)
Set the electric potential of this phase (V).
void solvePseudoSteadyStateProblem(int ifuncOverride=-1, doublereal timeScaleOverride=1.0)
Solve for the pseudo steady-state of the surface problem.
virtual void getCreationRates(size_t nSpecies, const doublereal *fwdRatesOfProgress, const doublereal *revRatesOfProgress, doublereal *creationRates)
Species creation rates.
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
SurfPhase * m_surf
Pointer to the single surface phase.
int phaseExistence(const size_t iphase) const
Gets the phase existence int for the ith phase.
virtual void getRevReactionDelta(size_t nr, const doublereal *g, doublereal *dg)
Given an array of species properties 'g', return in array 'dg' the change in this quantity in the rev...
std::vector< size_t > m_start
m_start is a vector of integers specifying the beginning position for the species vector for the n'th...
const size_t npos
index returned by functions to indicate "no position"
vector_fp m_phi
Vector of phase electric potentials.
void advanceCoverages(doublereal tstep)
Advance the surface coverages in time.
vector_fp cov
Adjustments to the Arrhenius rate expression dependent on surface species coverages.
doublereal beta
for electrochemical reactions
void applyButlerVolmerCorrection(doublereal *const kf)
Apply corrections for interfacial charge transfer reactions.
virtual const std::vector< size_t > & products(size_t i) const
Returns a read-only reference to the vector of product index numbers for reaction i...
virtual void getReactionDelta(size_t nReactions, const doublereal *g, doublereal *dg)
Calculates the change of a molar species property in a reaction.
virtual void getDeltaEntropy(doublereal *deltaS)
Return the vector of values for the reactions change in entropy.
virtual ~InterfaceKinetics()
Destructor.
virtual void getDeltaSSEntropy(doublereal *deltaS)
Return the vector of values for the change in the standard state entropies for each reaction...
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
virtual void getEquilibriumConstants(doublereal *kc)
Return a vector of Equilibrium constants.
std::vector< std::vector< bool > > m_rxnPhaseIsProduct
Vector of vector of booleans indicating whether a phase participates in a reaction as a product...
void registerReaction(size_t rxnNumber, int type, size_t loc)
Write values into m_index.
virtual std::string reactionString(size_t i) const
Return a string representing the reaction.
virtual void addPhase(thermo_t &thermo)
Add a phase to the kinetics manager object.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
virtual void addReaction(ReactionData &r)
Add a single reaction to the mechanism.
size_t reactionPhaseIndex()
Phase where the reactions occur.
virtual void getFwdRatesOfProgress(doublereal *fwdROP)
Return the forward rates of progress of the reactions.
size_t m_nrev
Number of reversible reactions in the mechanism.
std::vector< std::map< size_t, doublereal > > m_prxn
m_prxn is a vector of maps, containing the reactant stoichiometric coefficient information ...
bool m_has_electrochem_rxns
Boolean flag indicating whether any reaction in the mechanism has a beta electrochemical parameter...
std::vector< std::string > m_rxneqn
String expression for each rxn.
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
void multiply_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Multiply each entry in x by the corresponding entry in y.
int m_phaseExistsCheck
Int flag to indicate that some phases in the kinetics mechanism are non-existent. ...
virtual void finalize()
Finish adding reactions and prepare for use.
vector_fp rateCoeffParameters
Vector of rate coefficient parameters.
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
virtual void getDestructionRates(doublereal *ddot)
Species destruction rates [kmol/m^3/s or kmol/m^2/s].
Base class for a phase with thermodynamic properties.
void updateKc()
Update the equilibrium constants in molar units for all reversible reactions.
std::string equation
The reaction equation. Used only for display purposes.
doublereal m_temp
Current temperature of the data.
std::vector< std::map< size_t, doublereal > > m_rrxn
m_rrxn is a vector of maps, containing the reactant stoichiometric coefficient information ...
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
size_t surfacePhaseIndex()
This returns the integer index of the phase which has ThermoPhase type cSurf.
bool m_has_coverage_dependence
Boolean flag indicating whether any reaction in the mechanism has a coverage dependent forward reacti...
virtual void multiplyReactants(const doublereal *C, doublereal *R)
Given an array of concentrations C, multiply the entries in array R by the concentration products for...
vector_int m_ctrxn_ecdf
Vector of booleans indicating whether the charge transfer reaction may be described by an exchange cu...
virtual void getDeltaGibbs(doublereal *deltaG)
Return the vector of values for the reaction gibbs free energy change.
virtual void getFwdRateConstants(doublereal *kfwd)
Return the forward rate constants.
vector_fp m_E
Vector of raw activation energies for the reactions.
size_t nPhases() const
The number of phases participating in the reaction mechanism.
A kinetics manager for heterogeneous reaction mechanisms.
virtual void getNetRatesOfProgress(doublereal *netROP)
Net rates of progress.
vector_fp m_conc
an array of generalized concentrations for each species
void solvePseudoSteadyStateProblem(int ifuncOverride=-1, doublereal timeScaleOverride=1.0)
Solve for the pseudo steady-state of the surface problem.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
virtual int type() const
Identifies the kinetics manager type.
std::vector< bool > m_phaseExists
Vector of booleans indicating whether phases exist or not.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
void _update_rates_T()
Update properties that depend on temperature.
vector_fp m_perturb
Vector of perturbation factors for each reaction's rate of progress vector.
Public interface for kinetics managers.
virtual void getActivityConcentrations(doublereal *const conc)
Get the vector of activity concentrations used in the kinetics object.
void _update_rates_C()
Update properties that depend on the species mole fractions and/or concentration,.
vector_fp m_pot
Vector of potential energies due to Voltages.
Intermediate class which stores data about a reaction and its rate parameterization before adding the...
size_t m_nirrev
Number of irreversible reactions in the mechanism.
void setPhaseStability(const size_t iphase, const int isStable)
Set the stability of a phase in the reaction object.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Base class for exceptions thrown by Cantera classes.
bool m_has_exchange_current_density_formulation
Boolean flag indicating whether any reaction in the mechanism is described by an exchange current den...
Declarations for the implicit integration of surface site density equations (see Kinetics Managers an...
std::vector< std::vector< bool > > m_rxnPhaseIsReactant
Vector of vector of booleans indicating whether a phase participates in a reaction as a reactant...
Kinetics & operator=(const Kinetics &right)
Assignment operator.
virtual void getRevRatesOfProgress(doublereal *revROP)
Return the Reverse rates of progress of the reactions.
std::vector< size_t > m_revindex
List of reactions numbers which are reversible reactions.
virtual const std::vector< size_t > & reactants(size_t i) const
Returns a read-only reference to the vector of reactant index numbers for reaction i...
virtual void getRevRateConstants(doublereal *krev, bool doIrreversible=false)
Return the reverse rate constants.
size_t nSpecies() const
Returns the number of species in the phase.
int rateCoeffType
Type of the rate coefficient for the forward rate constant.
void _update_rates_phi()
Update properties that depend on the electric potential.
virtual void init()
Prepare the class for the addition of reactions.
std::vector< size_t > m_irrev
Vector of irreversible reaction numbers.
Advances the surface coverages of the associated set of SurfacePhase objects in time.
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
doublereal temperature() const
Temperature (K).
size_t nDim() const
Returns the number of spatial dimensions (1, 2, or 3)
InterfaceKinetics(thermo_t *thermo=0)
Constructor.
virtual Kinetics * duplMyselfAsKinetics(const std::vector< thermo_t * > &tpVector) const
Duplication routine for objects which inherit from Kinetics.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
void applyExchangeCurrentDensityFormulation(doublereal *const kfwd)
When an electrode reaction rate is optionally specified in terms of its exchange current density...
virtual void initialize(doublereal t0=0.0)
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
void updateROP()
Internal routine that updates the Rates of Progress of the reactions.
size_t speciesPhaseIndex(size_t k)
This function takes as an argument the kineticsSpecies index (i.e., the list index in the list of spe...
std::vector< std::vector< size_t > > m_products
This is a vector of vectors containing the products for each reaction.
std::vector< int > m_phaseIsStable
Vector of int indicating whether phases are stable or not.
Rate1< SurfaceArrhenius > m_rates
Templated class containing the vector of reactions for this interface.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
vector_fp m_rwork
Vector temporary.
size_t m_ii
Number of reactions in the mechanism.
const int ELEMENTARY_RXN
A reaction with a rate coefficient that depends only on temperature.
std::vector< size_t > m_ctrxn
Vector of reaction indexes specifying the id of the current transfer reactions in the mechanism...
virtual void multiplyRevProducts(const doublereal *c, doublereal *r)
Given an array of concentrations C, multiply the entries in array R by the concentration products for...
size_t nReactions() const
Number of reactions in the reaction mechanism.
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
void setPhaseExistence(const size_t iphase, const int exists)
Set the existence of a phase in the reaction object.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
void writelog(const std::string &msg)
Write a message to the screen.
std::map< size_t, std::pair< int, size_t > > m_index
Vector of information about reactions in the mechanism.
virtual void getDeltaSSGibbs(doublereal *deltaG)
Return the vector of values for the reaction standard state gibbs free energy change.
virtual void getDeltaElectrochemPotentials(doublereal *deltaM)
Return the vector of values for the reaction electrochemical free energy change.
ReactionStoichMgr m_rxnstoich
Stoichiometric manager for the reaction mechanism.
virtual void finalize()
Finish adding reactions and prepare for use.
vector_fp m_mu0
Vector of standard state chemical potentials.
vector_fp m_grt
Temporary work vector of length m_kk.
virtual void addPhase(thermo_t &thermo)
Add a phase to the kinetics manager object.
virtual void getDeltaSSEnthalpy(doublereal *deltaH)
Return the vector of values for the change in the standard state enthalpies of reaction.
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
ImplicitSurfChem * m_integrator
Pointer to the Implicit surface chemistry object.
void integrate(doublereal t0, doublereal t1)
Integrate from t0 to t1. The integrator is reinitialized first.
InterfaceKinetics & operator=(const InterfaceKinetics &right)
Assignment operator.
bool m_finalized
boolean indicating whether mechanism has been finalized
virtual void finalize()
Finish adding reactions and prepare for use.
virtual void add(size_t rxn, const std::vector< size_t > &reactants, const std::vector< size_t > &products, bool reversible)
Add a reaction with mass-action kinetics.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...