Skip to content

Commit

Permalink
[Kinetics] A, b, and Ea can be modified in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Mar 29, 2021
1 parent 155f467 commit 1eca0d8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
7 changes: 7 additions & 0 deletions include/cantera/kinetics/MultiRate.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class MultiRateBase
virtual void add(const size_t rxn_index,
shared_ptr<ReactionRateBase> rate) = 0;

virtual ReactionRateBase& rate(size_t rxn_index) = 0;

//! Replace reaction rate object handled by the evaluator
//! @param rxn_index index of reaction
//! @param rate reaction rate object
Expand Down Expand Up @@ -70,6 +72,11 @@ class MultiBulkRates final : public MultiRateBase
m_bases[j] = nullptr;
}

virtual ReactionRateBase& rate(size_t rxn_index) override {
size_t j = m_indices[rxn_index];
return static_cast<ReactionRateBase&>(m_rates[j]);
}

virtual void add(const size_t rxn_index,
shared_ptr<ReactionRateBase> rate) override {
if (typeid(*rate) != typeid(RateType)) {
Expand Down
12 changes: 3 additions & 9 deletions include/cantera/kinetics/ReactionRate.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,13 @@ class ArrheniusRate final : public ReactionRate<ArrheniusData>, public Arrhenius

//! Set the pre-exponential factor *A* (in m, kmol, s to powers depending
//! on the reaction order)
void setPreExponentialFactor(double A) {
m_A = A;
}
void setPreExponentialFactor(double A);

//! Set the temperature exponent *b*
void setTemperatureExponent(double b) {
m_b = b;
}
void setTemperatureExponent(double b);

//! Set the activation energy [J/kmol]
void setActivationEnergy(double E) {
m_E = E / GasConstant;
}
void setActivationEnergy(double E);

//! Return the activation energy [J/kmol]
double activationEnergy() const {
Expand Down
17 changes: 17 additions & 0 deletions interfaces/cython/cantera/test/test_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ def test_pre_exponential_factor2(self):
self.assertNear(sol.forward_rate_constants[self._index],
2 * self.gas.forward_rate_constants[self._index], 1.e-6)

def test_temperature_exponent1(self):
rc = self.rate(self.gas.T, self.gas.P)
self.rate.temperature_exponent += 1
self.assertNear(self.rate(self.gas.T, self.gas.P), rc * self.gas.T, 1.e-6)

def test_temperature_exponent2(self):
# modify value in memory
b = self.gas.reaction(self._index).rate.temperature_exponent
sol = ct.Solution('kineticsfromscratch.yaml')
sol.TPX = self.gas.TPX
sol.reaction(self._index).rate.temperature_exponent += 1
self.assertNear(sol.reaction(self._index).rate.temperature_exponent, b + 1, 1.e-6)
sol.TP = 1000, ct.one_atm
self.gas.TP = 1000, ct.one_atm
self.assertNear(sol.forward_rate_constants[self._index],
self.gas.forward_rate_constants[self._index] * self.gas.T, 1.e-6)

def test_allow_negative_pre_exponential_factor1(self):
self.assertFalse(self.rate.allow_negative_pre_exponential_factor)
self.rate.allow_negative_pre_exponential_factor = True
Expand Down
25 changes: 25 additions & 0 deletions src/kinetics/ReactionRate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// at https://cantera.org/license.txt for license and copyright information.

#include "cantera/kinetics/ReactionRate.h"
#include "cantera/kinetics/MultiRate.h"
#include "cantera/numerics/Func1.h"
#include "cantera/base/AnyMap.h"

Expand Down Expand Up @@ -70,6 +71,30 @@ void ArrheniusRate::validate(const std::string& equation) {
}
}

void ArrheniusRate::setPreExponentialFactor(double A) {
m_A = A;
if (m_evaluator) {
static_cast<ArrheniusRate&>(
m_evaluator->rate(m_index)).setPreExponentialFactor(A);
}
}

void ArrheniusRate::setTemperatureExponent(double b) {
m_b = b;
if (m_evaluator) {
static_cast<ArrheniusRate&>(
m_evaluator->rate(m_index)).setTemperatureExponent(b);
}
}

void ArrheniusRate::setActivationEnergy(double E) {
m_E = E / GasConstant;
if (m_evaluator) {
static_cast<ArrheniusRate&>(
m_evaluator->rate(m_index)).setActivationEnergy(E);
}
}

PlogRate::PlogRate()
: ReactionRate()
, Plog() {}
Expand Down

0 comments on commit 1eca0d8

Please sign in to comment.