rizer.cantera_ext
C++ Cantera 1-D plasma extension (custom Domain1D models and solvers)
Loading...
Searching...
No Matches
ElectronReactions.cpp
Go to the documentation of this file.
2
5
6#include <sstream>
7#include <stdexcept>
8#include <string>
9
10namespace rizer
11{
12
13 // ------------------------------------------------------------------------------ //
14 // Free functions //
15 // ------------------------------------------------------------------------------ //
16
17 bool equationHasElectron(const std::string &equation,
18 const std::string &electron)
19 {
20 std::string s = equation;
21 for (char &ch : s)
22 {
23 if (ch == '+' || ch == '=' || ch == '<' || ch == '>')
24 ch = ' ';
25 }
26 std::istringstream iss(s);
27 std::string token;
28 while (iss >> token)
29 {
30 if (token == electron)
31 return true;
32 }
33 return false;
34 }
35
37 Cantera::Kinetics &kinetics, const std::string &electron,
38 const std::vector<double> &species_h0k, std::size_t n_species,
39 bool reacting)
40 {
41 const std::size_t n_reactions = kinetics.nReactions();
43 index.is_electron_reaction.assign(n_reactions, 0);
44 index.threshold_energy.assign(n_reactions, 0.0);
45
46 // Selected exactly as the Python reference selects them: the electron
47 // participates iff it appears in the equation. That covers
48 // two-temperature-plasma, three-body-two-temperature-plasma,
49 // reverse-two-temperature-plasma, Druyvesteyn and janev-* reactions,
50 // including the ones carrying a spectator electron.
51 for (std::size_t i = 0; i < n_reactions; i++)
52 {
53 if (equationHasElectron(kinetics.reaction(i)->equation(), electron))
54 {
55 index.is_electron_reaction[i] = 1;
56 index.any_electron_reaction = true;
57 }
58 }
59
60 if (!(reacting && index.any_electron_reaction))
61 {
62 return index;
63 }
64
65 // Fixed per-reaction threshold energy, eps_th_i = sum_k nu_ki H_k(0 K),
66 // from the caller's per-species formation enthalpies. Mirrors
67 // rizer.kinetics.electron_reactions.ElectronicReactionEnergetics.
68 if (species_h0k.empty())
69 {
70 throw std::invalid_argument(
71 "buildElectronReactionIndex: species_h0k is required (the "
72 "mechanism has an electron-impact reaction and chemistry is "
73 "live).");
74 }
75 if (species_h0k.size() != n_species)
76 {
77 throw std::invalid_argument(
78 "buildElectronReactionIndex: species_h0k has " +
79 std::to_string(species_h0k.size()) + " entries, expected " +
80 std::to_string(n_species) + ".");
81 }
82 kinetics.getReactionDelta(
83 Cantera::span<const double>(species_h0k.data(), n_species),
85 index.threshold_energy.size()));
86 return index;
87 }
88
89} // namespace rizer
Which reactions of a mechanism the electron takes part in, and what each of them costs the electron p...
shared_ptr< Reaction > reaction(size_t i)
size_t nReactions() const
virtual void getReactionDelta(span< const double > property, span< double > deltaProperty) const
ElectronReactionIndex buildElectronReactionIndex(Cantera::Kinetics &kinetics, const std::string &electron, const std::vector< double > &species_h0k, std::size_t n_species, bool reacting)
Build the index for one mechanism.
bool equationHasElectron(const std::string &equation, const std::string &electron)
Test whether the electron participates in a reaction equation as a standalone token.
The per-reaction data the electron pool's inelastic power needs.
bool any_electron_reaction
Whether any reaction at all involves the electron [-].
std::vector< double > threshold_energy
Threshold energy [J/kmol], length nReactions(), zero where no electron takes part.
std::vector< char > is_electron_reaction
1 where the electron participates, 0 elsewhere, length nReactions().