Skip to content

Commit

Permalink
[Kinetics] Implement MultiRate::processVoltageCorrections
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Mar 13, 2022
1 parent 5cfb693 commit 78470a6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
28 changes: 27 additions & 1 deletion include/cantera/kinetics/MultiRate.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MultiRate final : public MultiRateBase
CT_DEFINE_HAS_MEMBER(has_ddT, ddTScaledFromStruct)
CT_DEFINE_HAS_MEMBER(has_ddP, perturbPressure)
CT_DEFINE_HAS_MEMBER(has_ddM, perturbThirdBodies)
CT_DEFINE_HAS_MEMBER(has_chargeTransfer, voltageCorrection)

public:
virtual std::string type() override {
Expand Down Expand Up @@ -98,6 +99,15 @@ class MultiRate final : public MultiRateBase
_process_ddM(rop, kf, deltaM, overwrite);
}

virtual void processVoltageCorrections(double* kf,
const double* pot,
double RT) override
{
// call helper function: implementation depends on whether
// ReactionRate::voltageCorrection is defined
_processVoltageCorrections(kf, pot, RT);
}

virtual void update(double T) override {
m_shared.update(T);
_update();
Expand Down Expand Up @@ -147,7 +157,7 @@ class MultiRate final : public MultiRateBase
void _update() {
}

//! Helper function to update a single rate that has an `updateFromStruct method`.
//! Helper function to update a single rate that has an `updateFromStruct` method`.
template <typename T=RateType,
typename std::enable_if<has_update<T>::value, bool>::type = true>
void _updateRate(RateType& rate) {
Expand All @@ -161,6 +171,22 @@ class MultiRate final : public MultiRateBase
void _updateRate(RateType& rate) {
}

//! Helper function to update a single rate that has a `voltageCorrection` method.
template <typename T=RateType,
typename std::enable_if<has_chargeTransfer<T>::value, bool>::type = true>
void _processVoltageCorrections(double* kf, const double* pot, double RT) {
for (auto& rxn : m_rxn_rates) {
kf[rxn.first] *= rxn.second.voltageCorrection(pot, RT);
}
}

//! Helper function for single rate that does not implement `updateFromStruct`.
//! Exists to allow generic implementations of `evalSingle` and `ddTSingle`.
template <typename T=RateType,
typename std::enable_if<!has_chargeTransfer<T>::value, bool>::type = true>
void _processVoltageCorrections(double* kf, const double* pot, double RT) {
}

//! Helper function to process temperature derivatives for rate types that
//! implement the `ddTScaledFromStruct` method.
template <typename T=RateType,
Expand Down
10 changes: 10 additions & 0 deletions include/cantera/kinetics/MultiRateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ class MultiRateBase
double deltaM,
bool overwrite=true) = 0;

//! Process voltage correction for charge transfer reactions.
//! @param[in,out] kf array of forward rate constants
//! @param pot array of potential energies due to voltages
//! @param RT product of gas constant and temperature of reacting phase
//! @warning The updated calculation of voltage corrections is an experimental
//! part of the %Cantera API and may be changed or removed without notice.
virtual void processVoltageCorrections(double* kf,
const double* pot,
double RT) = 0;

//! Update common reaction rate data based on temperature.
//! Only used in conjunction with evalSingle and ReactionRate::eval
//! @param T temperature [K]
Expand Down
21 changes: 20 additions & 1 deletion src/kinetics/InterfaceKinetics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ void InterfaceKinetics::resizeReactions()
// blocks correct behavior in InterfaceKinetics::_update_rates_T
// and running updateROP() is premature
}

for (auto& rates : m_chargeTransferRates) {
rates->resize(nTotalSpecies(), nReactions());
// @todo ensure that ReactionData are updated; calling rates->update
// blocks correct behavior in InterfaceKinetics::_update_rates_T
// and running updateROP() is premature
}
}

void InterfaceKinetics::setElectricPotential(int n, doublereal V)
Expand Down Expand Up @@ -98,7 +105,7 @@ void InterfaceKinetics::_update_rates_T()
m_redo_rates = false;
}

// loop over MultiRate evaluators for each reaction type
// loop over interface MultiRate evaluators for each reaction type
for (auto& rates : m_interfaceRates) {
bool changed = rates->update(thermo(), *this);
if (changed) {
Expand All @@ -108,6 +115,18 @@ void InterfaceKinetics::_update_rates_T()
}
}

// loop over charge transfer MultiRate evaluators for each reaction type
for (auto& rates : m_chargeTransferRates) {
bool changed = rates->update(thermo(), *this);
if (changed) {
rates->getRateConstants(m_rfn.data());
rates->processVoltageCorrections(
m_rfn.data(), m_pot.data(), thermo(reactionPhaseIndex()).RT());
m_ROP_ok = false;
m_redo_rates = true;
}
}

if (!m_ROP_ok) {
updateKc();
}
Expand Down

0 comments on commit 78470a6

Please sign in to comment.