rizer.cantera_ext
C++ Cantera 1-D plasma extension (custom Domain1D models and solvers)
Loading...
Searching...
No Matches
PlasmaRates.h
Go to the documentation of this file.
1// PlasmaRates.h
2//
3// C++ ports of the custom plasma reaction rates that rizer defines in
4// Python as `ct.ExtensibleRate`s (rizer/kin/extensible_rate.py):
5//
6// * janev-dissociative-recombination-C2Hy — a closed-form rate in Te only.
7// * Druyvesteyn — modified Arrhenius in Te with
8// a squared-ratio exponential, k = A Te^b exp(-(Ea/Te)^2).
9// * reverse-two-temperature-plasma — the reverse of a forward
10// `two-temperature-plasma` reaction, k_rev = k_fwd / K_eq.
11//
12// Python `ct.ExtensibleRate`s are unknown to Cantera's C++ ReactionRateFactory,
13// so a mechanism that uses them (e.g. data/mechanisms/Goutier2025/CH4_to_C2H2.yaml)
14// fails to load in C++. Registering these C++ rates via `registerPlasmaRates()`
15// before `newSolution()` lets that mechanism load and evaluate natively in the
16// PlasmaChannel1D extension.
17
18#ifndef RIZER_PLASMARATES_H
19#define RIZER_PLASMARATES_H
20
23#include "cantera/base/AnyMap.h"
24
25#include <memory>
26#include <string>
27#include <unordered_map>
28#include <unordered_set>
29#include <vector>
30
31namespace Cantera { class Solution; }
32
33namespace rizer {
34
41
51std::shared_ptr<Cantera::Solution> loadMechanism(const std::string& mech,
52 const std::string& phase);
53
54
55// ---------------------------------------------------------------------------
56// janev-dissociative-recombination-C2Hy
57// ---------------------------------------------------------------------------
58
62{
67 bool update(const Cantera::ThermoPhase& phase,
68 const Cantera::Kinetics& kin) override;
74 double electronTemp = 1.0;
75};
76
85{
86public:
88
95 const Cantera::UnitStack& rate_units);
96
97 std::unique_ptr<Cantera::MultiRateBase> newMultiRate() const override;
98
99 const std::string type() const override {
100 return "janev-dissociative-recombination-C2Hy";
101 }
102
108 void setParameters(const Cantera::AnyMap& node,
109 const Cantera::UnitStack& rate_units) override;
110
114 double evalFromStruct(const ElectronTemperatureData& shared_data) const;
115
116protected:
117 void getParameters(Cantera::AnyMap& node) const override;
118
119 double m_A = NAN;
122};
123
124
125// ---------------------------------------------------------------------------
126// Druyvesteyn
127// ---------------------------------------------------------------------------
128
137{
138public:
139 DruyvesteynRate() = default;
140
147 const Cantera::UnitStack& rate_units);
148
149 std::unique_ptr<Cantera::MultiRateBase> newMultiRate() const override;
150
151 const std::string type() const override { return "Druyvesteyn"; }
152
158 void setParameters(const Cantera::AnyMap& node,
159 const Cantera::UnitStack& rate_units) override;
160
166 void validate(const std::string& equation,
167 const Cantera::Kinetics& kin) override;
168
172 double evalFromStruct(const ElectronTemperatureData& shared_data) const;
173
177 double logRate(double Te) const;
178
179protected:
180 void getParameters(Cantera::AnyMap& node) const override;
181
182 double m_A = NAN;
184 double m_b = NAN;
185 double m_Ea_K = NAN;
186};
187
188
189// ---------------------------------------------------------------------------
190// reverse-two-temperature-plasma
191// ---------------------------------------------------------------------------
192
205{
212 bool update(const Cantera::ThermoPhase& phase,
213 const Cantera::Kinetics& kin) override;
215 void invalidateCache() override {
217 m_Tg = m_Te = m_P = NAN;
218 }
219
226 void buildShadow(const Cantera::ThermoPhase& phase,
227 const Cantera::Kinetics& kin);
228
230 std::shared_ptr<Cantera::Solution> shadow;
233 std::vector<double> kf_Tg, Keq_Tg;
236 std::vector<double> kf_Te, Keq_Te;
241 std::vector<double> logKeq_Tg, logKeq_Te;
244 std::unordered_map<std::string, size_t> fwdIndex;
246 std::unordered_set<std::string> ambiguousForward;
249 bool anyTeTagged = false;
251 std::vector<std::shared_ptr<Cantera::ReactionRate>> fwdRate;
253 std::vector<double> deltaN;
254
256 double gasTemperature() const { return m_Tg; }
258 double electronTemperature() const { return m_Te; }
259
260private:
265 void computeLogEquilibriumConstants(std::vector<double>& logKeq);
266
267 double m_Tg = NAN;
268 double m_Te = NAN;
269 double m_P = NAN;
270 std::vector<double> m_deltaG;
271};
272
279{
280public:
282
289 const Cantera::UnitStack& rate_units);
290
291 std::unique_ptr<Cantera::MultiRateBase> newMultiRate() const override;
292
293 const std::string type() const override {
294 return "reverse-two-temperature-plasma";
295 }
296
302 void setParameters(const Cantera::AnyMap& node,
303 const Cantera::UnitStack& rate_units) override;
304
317 double evalFromStruct(const ReverseTwoTempData& shared_data) const;
318
319protected:
320 void getParameters(Cantera::AnyMap& node) const override;
321
326 std::string m_T = "Tg";
329 mutable size_t m_idx = Cantera::npos;
330};
331
332} // namespace rizer
333
334#endif // RIZER_PLASMARATES_H
void setParameters(const Cantera::AnyMap &node, const Cantera::UnitStack &rate_units) override
Set the rate parameters from a YAML/AnyMap rate node.
double logRate(double Te) const
Natural log of the rate, , finite where the rate itself underflows to 0.
std::unique_ptr< Cantera::MultiRateBase > newMultiRate() const override
double m_b
Te exponent [-].
const std::string type() const override
double m_A
Pre-factor in Cantera's internal (kmol, m, s) rate-coefficient units [order-dependent].
void getParameters(Cantera::AnyMap &node) const override
void validate(const std::string &equation, const Cantera::Kinetics &kin) override
Reject a missing or negative pre-factor (mirrors the Python rate's validate; missing "A" leaves m_A a...
double evalFromStruct(const ElectronTemperatureData &shared_data) const
Evaluate the Druyvesteyn rate .
double m_Ea_K
Activation energy expressed in Kelvin [K].
std::unique_ptr< Cantera::MultiRateBase > newMultiRate() const override
const std::string type() const override
Definition PlasmaRates.h:99
void setParameters(const Cantera::AnyMap &node, const Cantera::UnitStack &rate_units) override
Set the rate parameters from a YAML/AnyMap rate node.
double evalFromStruct(const ElectronTemperatureData &shared_data) const
Evaluate the Janev dissociative-recombination rate .
double m_A
Rate pre-factor, in Cantera's internal (kmol, m, s) rate-coefficient units [kmol/m^3/s units,...
void getParameters(Cantera::AnyMap &node) const override
std::unique_ptr< Cantera::MultiRateBase > newMultiRate() const override
double evalFromStruct(const ReverseTwoTempData &shared_data) const
Evaluate the reverse rate at the tagged temperature.
void getParameters(Cantera::AnyMap &node) const override
std::string m_forward_equation
Equation string of the forward reaction this rate reverses [-].
const std::string type() const override
size_t m_idx
Cached index of the forward reaction in the shadow kinetics' reaction list [-].
void setParameters(const Cantera::AnyMap &node, const Cantera::UnitStack &rate_units) override
Set the rate parameters from a YAML/AnyMap rate node.
std::string m_T
Which temperature tags this reaction ("Te" or "Tg"); informational, kept for YAML round-trip [-].
const size_t npos
std::shared_ptr< Cantera::Solution > loadMechanism(const std::string &mech, const std::string &phase)
Load a mechanism with rizer's custom rate types registered first.
void registerPlasmaRates()
Register the custom plasma reaction rates with Cantera's ReactionRateFactory.
virtual void update(double T)
virtual void invalidateCache()
Shared data carrying the electron temperature (mirrors Cantera's own TwoTempPlasmaData but only needs...
Definition PlasmaRates.h:62
void invalidateCache() override
Definition PlasmaRates.h:70
double electronTemp
electron temperature [K]
Definition PlasmaRates.h:74
bool update(const Cantera::ThermoPhase &phase, const Cantera::Kinetics &kin) override
Read the electron temperature from the phase.
Shared data for all reverse-two-temperature-plasma reactions.
bool update(const Cantera::ThermoPhase &phase, const Cantera::Kinetics &kin) override
Refresh the cached Tg, Te, P and the shadow-solution rate/equilibrium constants.
std::unordered_set< std::string > ambiguousForward
Forward equations shared by more than one forward reaction [-].
std::vector< std::shared_ptr< Cantera::ReactionRate > > fwdRate
Per-reaction forward rate of the shadow, read by the log-space path.
std::shared_ptr< Cantera::Solution > shadow
Forward-only ideal-gas shadow solution [-].
std::vector< double > Keq_Tg
bool anyTeTagged
Whether any reverse reaction is tagged T: Te.
std::vector< double > kf_Te
Per-reaction forward rate constant [kmol/m^3/s units, order-dependent] and dimensionless Kc,...
std::vector< double > logKeq_Tg
Per-reaction natural log of Kc at Tg and at Te [-], from the standard Gibbs energy of reaction,...
std::vector< double > logKeq_Te
std::vector< double > Keq_Te
double electronTemperature() const
Electron temperature from the last update() [K].
std::vector< double > deltaN
Per-reaction change in moles, products minus reactants [-].
std::unordered_map< std::string, size_t > fwdIndex
Forward reaction equation string -> index into the shadow kinetics' reaction list [-].
void invalidateCache() override
void buildShadow(const Cantera::ThermoPhase &phase, const Cantera::Kinetics &kin)
Lazily build the ideal-gas shadow Solution from the main phase + kinetics.
double gasTemperature() const
Gas temperature from the last update() [K].
std::vector< double > kf_Tg
Per-reaction forward rate constant [kmol/m^3/s units, order-dependent] and dimensionless Kc,...