Skip to content

Commit

Permalink
[thermo] set Te = T when thermo=IdealGas, and add TwoTempPlasmaRate::…
Browse files Browse the repository at this point in the history
…ddTScaledFromStruct
  • Loading branch information
BangShiuh committed Feb 21, 2022
1 parent 9d5fe95 commit e7e79e8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
9 changes: 9 additions & 0 deletions include/cantera/kinetics/Arrhenius.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ class TwoTempPlasmaRate final : public ArrheniusBase
* shared_data.recipTe * shared_data.recipT);
}

//! Evaluate derivative of reaction rate with respect to temperature
//! divided by reaction rate
/*!
* @param shared_data data shared by all reactions of a given type
*/
virtual double ddTScaledFromStruct(const ReactionData& shared_data) const {
return ((m_Ea_R - m_EE_R) * shared_data.recipT) * shared_data.recipT;
}

//! Return the activation energy *Ea* [J/kmol]
double activationEnergy() const {
return m_Ea_R * GasConstant;
Expand Down
16 changes: 16 additions & 0 deletions include/cantera/thermo/IdealGasPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,22 @@ class IdealGasPhase: public ThermoPhase
setDensity(p * meanMolecularWeight() / RT());
}

//! Set the internally stored temperature of the phase (K).
//! Since the gas is in equilibrium, the electron temperature
//! is also set to the same value.
//! @param temp Temperature in Kelvin
virtual void setTemperature(const double temp) {
Phase::setTemperature(temp);
Phase::setElectronTemperature(temp);
}

//! Set the internally stored electron temperature of the phase (K).
//! @param etemp Electron temperature in Kelvin
virtual void setElectronTemperature(const double etemp) {
throw NotImplementedError("IdealGasPhase::setElectronTemperature",
"Not implemented for thermo model '{}'", type());
}

//! Set the density and pressure at constant composition.
/*!
* Units: kg/m^3, Pa.
Expand Down
45 changes: 17 additions & 28 deletions interfaces/cython/cantera/test/test_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def tearDownClass(cls):
def setUp(self):
self.gas.X = "H2:0.1, H2O:0.2, O2:0.7, O:1e-4, OH:1e-5, H:2e-5, H2O2:1e-7"
self.gas.TP = 900, 2 * ct.one_atm
self.gas.Te = 2300

def from_parts(self):
# create reaction rate object from parts
Expand Down Expand Up @@ -384,43 +383,33 @@ def test_negative_A(self):
rate.allow_negative_pre_exponential_factor = True
self.assertTrue(rate.allow_negative_pre_exponential_factor)

def test_temperature_derivative(self):
# check temperature derivative against numerical derivative
deltaT = self.gas.derivative_settings["rtol-delta"]
deltaT *= self.gas.T
rate = self.from_yaml()
k0 = self.eval(rate)

# derivative at constant pressure and constant electron temperature
dcdt = - self.gas.density_mole / self.gas.T
drate = self.gas.forward_rate_constants_ddT
drate += self.gas.forward_rate_constants_ddC * dcdt
self.gas.TP = self.gas.T + deltaT, self.gas.P
# Due to Te changes automatically with T, the initial value is used instead.
k1 = rate(self.gas.T, self.gas.Te - deltaT)
self.assertNear((k1 - k0) / deltaT, drate[self._index], 1e-6)


class TestTwoTempPlasmaRateShort(ReactionRateTests, utilities.CanteraTest):
class TestTwoTempPlasmaRateShort(TestTwoTempPlasmaRate, utilities.CanteraTest):
# test TwoTempPlasma rate expressions

_cls = ct.TwoTempPlasmaRate
_type = "two-temperature-plasma"
_index = 12
_input = {"rate-constant": {"A": 17283, "b": -3.1, "Ea-gas": 0.0, "Ea-electron": 0.0}}
_yaml = """
type: two-temperature-plasma
rate-constant: {A: 17283, b: -3.1, Ea-gas: 0.0 J/mol, Ea-electron: 0.0 J/mol}
"""

@classmethod
def setUpClass(cls):
ReactionRateTests.setUpClass()
cls._parts = {key.replace("-", "_"): value for key, value in cls._input["rate-constant"].items()}

def eval(self, rate):
# check evaluation as a function of temperature and electron temperature
return rate(self.gas.T, self.gas.Te)

def test_from_parts(self):
rate = self.from_parts()
self.assertEqual(self._parts["A"], rate.pre_exponential_factor)
self.assertEqual(self._parts["b"], rate.temperature_exponent)
self.assertAlmostEqual(self._parts["Ea_gas"], rate.activation_energy)
self.assertAlmostEqual(self._parts["Ea_electron"], rate.activation_electron_energy)
self.check_rate(rate)

def test_negative_A(self):
# test reaction rate property
rate = self.from_parts()
self.assertFalse(rate.allow_negative_pre_exponential_factor)
rate.allow_negative_pre_exponential_factor = True
self.assertTrue(rate.allow_negative_pre_exponential_factor)


class FalloffRateTests(ReactionRateTests):
# test Falloff rate expressions
Expand Down
1 change: 0 additions & 1 deletion interfaces/cython/cantera/test/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ def check_setters(self, T1, rho1, Y1):
s1 = self.phase.s
u1 = self.phase.u
v1 = self.phase.v
self.phase.Te = T1

def check_state(T, rho, Y):
self.assertNear(self.phase.T, T)
Expand Down

0 comments on commit e7e79e8

Please sign in to comment.