Cantera 2.6.0
PlasmaPhase.cpp
Go to the documentation of this file.
1//! @file PlasmaPhase.cpp
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
7#include <boost/math/special_functions/gamma.hpp>
11
12namespace Cantera {
13
14PlasmaPhase::PlasmaPhase(const std::string& inputFile, const std::string& id_)
15 : m_isotropicShapeFactor(2.0)
16 , m_nPoints(1001)
17 , m_electronSpeciesIndex(npos)
18 , m_distributionType("isotropic")
19 , m_quadratureMethod("simpson")
20 , m_do_normalizeElectronEnergyDist(true)
21{
22 initThermoFile(inputFile, id_);
23
24 // initial grid
25 m_electronEnergyLevels = Eigen::ArrayXd::LinSpaced(m_nPoints, 0.0, 1.0);
26
27 // initial electron temperature
29}
30
32{
33 if (m_distributionType == "discretized") {
34 throw CanteraError("PlasmaPhase::updateElectronEnergyDistribution",
35 "Invalid for discretized electron energy distribution.");
36 } else if (m_distributionType == "isotropic") {
38 }
39}
40
42 Eigen::ArrayXd eps32 = m_electronEnergyLevels.pow(3./2.);
43 double norm = 2./3. * numericalQuadrature(m_quadratureMethod,
45 if (norm < 0.0) {
46 throw CanteraError("PlasmaPhase::normalizeElectronEnergyDistribution",
47 "The norm is negative. This might be caused by bad "
48 "electron energy distribution");
49 }
51}
52
54{
55 if (type == "discretized" ||
56 type == "isotropic") {
58 } else {
59 throw CanteraError("PlasmaPhase::setElectronEnergyDistributionType",
60 "Unknown type for electron energy distribution.");
61 }
62}
63
65{
67 double x = m_isotropicShapeFactor;
68 double gamma1 = boost::math::tgamma(3.0 / 2.0 * x);
69 double gamma2 = boost::math::tgamma(5.0 / 2.0 * x);
70 double c1 = x * std::pow(gamma2, 1.5) / std::pow(gamma1, 2.5);
71 double c2 = x * std::pow(gamma2 / gamma1, x);
73 c1 * m_electronEnergyLevels.sqrt() /
74 std::pow(meanElectronEnergy(), 1.5) *
76 meanElectronEnergy()).pow(x)).exp();
78}
79
81 m_electronTemp = Te;
83}
84
86 m_electronTemp = 2.0 / 3.0 * energy * ElectronCharge / Boltzmann;
88}
89
90void PlasmaPhase::setElectronEnergyLevels(const double* levels, size_t length)
91{
92 m_nPoints = length;
93 m_electronEnergyLevels = Eigen::Map<const Eigen::ArrayXd>(levels, length);
96}
97
99{
100 Eigen::ArrayXd h = m_electronEnergyLevels.tail(m_nPoints - 1) -
102 if (m_electronEnergyLevels[0] < 0.0 || (h <= 0.0).any()) {
103 throw CanteraError("PlasmaPhase::checkElectronEnergyLevels",
104 "Values of electron energy levels need to be positive and "
105 "monotonically increasing.");
106 }
107}
108
110{
111 Eigen::ArrayXd h = m_electronEnergyLevels.tail(m_nPoints - 1) -
113 if ((m_electronEnergyDist < 0.0).any()) {
114 throw CanteraError("PlasmaPhase::checkElectronEnergyDistribution",
115 "Values of electron energy distribution cannot be negative.");
116 }
117 if (m_electronEnergyDist[m_nPoints - 1] > 0.01) {
118 warn_user("PlasmaPhase::checkElectronEnergyDistribution",
119 "The value of the last element of electron energy distribution exceed 0.01. "
120 "This indicates that the value of electron energy level is not high enough "
121 "to contain the isotropic distribution at mean electron energy of "
122 "{} eV", meanElectronEnergy());
123 }
124}
125
127 const double* dist,
128 size_t length)
129{
130 m_distributionType = "discretized";
131 m_nPoints = length;
133 Eigen::Map<const Eigen::ArrayXd>(levels, length);
135 Eigen::Map<const Eigen::ArrayXd>(dist, length);
139 }
142}
143
145{
146 // calculate mean electron energy and electron temperature
147 Eigen::ArrayXd eps52 = m_electronEnergyLevels.pow(5./2.);
148 double epsilon_m = 2.0 / 5.0 * numericalQuadrature(m_quadratureMethod,
149 m_electronEnergyDist, eps52);
150 m_electronTemp = 2.0 / 3.0 * epsilon_m * ElectronCharge / Boltzmann;
151}
152
154 m_isotropicShapeFactor = x;
156}
157
158void PlasmaPhase::getParameters(AnyMap& phaseNode) const
159{
161 AnyMap eedf;
162 eedf["type"] = m_distributionType;
163 vector_fp levels(m_nPoints);
164 Eigen::Map<Eigen::ArrayXd>(levels.data(), m_nPoints) = m_electronEnergyLevels;
165 eedf["energy-levels"] = levels;
166 if (m_distributionType == "isotropic") {
167 eedf["shape-factor"] = m_isotropicShapeFactor;
168 eedf["mean-electron-energy"].setQuantity(meanElectronEnergy(), "eV");
169 } else if (m_distributionType == "discretized") {
170 vector_fp dist(m_nPoints);
171 Eigen::Map<Eigen::ArrayXd>(dist.data(), m_nPoints) = m_electronEnergyDist;
172 eedf["distribution"] = dist;
173 eedf["normalize"] = m_do_normalizeElectronEnergyDist;
174 }
175 phaseNode["electron-energy-distribution"] = std::move(eedf);
176}
177
178void PlasmaPhase::setParameters(const AnyMap& phaseNode, const AnyMap& rootNode)
179{
180 IdealGasPhase::setParameters(phaseNode, rootNode);
181 if (phaseNode.hasKey("electron-energy-distribution")) {
182 const AnyMap eedf = phaseNode["electron-energy-distribution"].as<AnyMap>();
183 m_distributionType = eedf["type"].asString();
184 if (m_distributionType == "isotropic") {
185 if (eedf.hasKey("shape-factor")) {
186 setIsotropicShapeFactor(eedf["shape-factor"].asDouble());
187 } else {
188 throw CanteraError("PlasmaPhase::setParameters",
189 "isotropic type requires shape-factor key.");
190 }
191 if (eedf.hasKey("mean-electron-energy")) {
192 double energy = eedf.convert("mean-electron-energy", "eV");
193 setMeanElectronEnergy(energy);
194 } else {
195 throw CanteraError("PlasmaPhase::setParameters",
196 "isotropic type requires electron-temperature key.");
197 }
198 if (eedf.hasKey("energy-levels")) {
199 setElectronEnergyLevels(eedf["energy-levels"].asVector<double>().data(),
200 eedf["energy-levels"].asVector<double>().size());
201 }
203 } else if (m_distributionType == "discretized") {
204 if (!eedf.hasKey("energy-levels")) {
205 throw CanteraError("PlasmaPhase::setParameters",
206 "Cannot find key energy-levels.");
207 }
208 if (!eedf.hasKey("distribution")) {
209 throw CanteraError("PlasmaPhase::setParameters",
210 "Cannot find key distribution.");
211 }
212 if (eedf.hasKey("normalize")) {
213 enableNormalizeElectronEnergyDist(eedf["normalize"].asBool());
214 }
215 setDiscretizedElectronEnergyDist(eedf["energy-levels"].asVector<double>().data(),
216 eedf["distribution"].asVector<double>().data(),
217 eedf["energy-levels"].asVector<double>().size());
218 }
219 }
220}
221
222bool PlasmaPhase::addSpecies(shared_ptr<Species> spec)
223{
224 bool added = IdealGasPhase::addSpecies(spec);
225 size_t k = m_kk - 1;
226
227 if (spec->composition.find("E") != spec->composition.end() &&
228 spec->composition.size() == 1 &&
229 spec->composition["E"] == 1) {
232 } else {
233 throw CanteraError("PlasmaPhase::addSpecies",
234 "Cannot add species, {}. "
235 "Only one electron species is allowed.", spec->name);
236 }
237 }
238 return added;
239}
240
242{
244 // check electron species
246 throw CanteraError("PlasmaPhase::initThermo",
247 "No electron species found.");
248 }
249}
250
252{
254 static const int cacheId = m_cache.getId();
255 CachedScalar cached = m_cache.getScalar(cacheId);
256 double tempNow = temperature();
257 double electronTempNow = electronTemperature();
258 size_t k = m_electronSpeciesIndex;
259 // If the electron temperature has changed since the last time these
260 // properties were computed, recompute them.
261 if (cached.state1 != tempNow || cached.state2 != electronTempNow) {
263 &m_cp0_R[k], &m_h0_RT[k], &m_s0_R[k]);
264 cached.state1 = tempNow;
265 cached.state2 = electronTempNow;
266 }
267 // update the species Gibbs functions
268 m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
269}
270
271}
Header file for class PlasmaPhase.
Declaration for class Cantera::Species.
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
double convert(const std::string &key, const std::string &units) const
Convert the item stored by the given key to the units specified in units.
Definition: AnyMap.cpp:1508
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:1406
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
vector_fp m_g0_RT
Temporary storage for dimensionless reference state Gibbs energies.
vector_fp m_cp0_R
Temporary storage for dimensionless reference state heat capacities.
virtual bool addSpecies(shared_ptr< Species > spec)
vector_fp m_h0_RT
Temporary storage for dimensionless reference state enthalpies.
vector_fp m_s0_R
Temporary storage for dimensionless reference state entropies.
virtual void updateThermo() const
virtual void update_single(size_t k, double T, double *cp_R, double *h_RT, double *s_R) const
Get reference-state properties for a single species.
ValueCache m_cache
Cached for saved calculations within each ThermoPhase.
Definition: Phase.h:923
size_t m_kk
Number of species in the phase.
Definition: Phase.h:943
doublereal temperature() const
Temperature (K).
Definition: Phase.h:654
void checkElectronEnergyDistribution() const
Check the electron energy distribution.
double meanElectronEnergy() const
Mean electron energy [eV].
Definition: PlasmaPhase.h:166
size_t m_nPoints
Number of points of electron energy levels.
Definition: PlasmaPhase.h:240
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void setParameters(const AnyMap &phaseNode, const AnyMap &rootNode=AnyMap())
Set equation of state parameters from an AnyMap phase description.
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
void normalizeElectronEnergyDistribution()
Electron energy distribution norm.
Definition: PlasmaPhase.cpp:41
std::string m_quadratureMethod
Numerical quadrature method for electron energy distribution.
Definition: PlasmaPhase.h:259
virtual void setElectronTemperature(double Te)
Set the internally stored electron temperature of the phase (K).
Definition: PlasmaPhase.cpp:80
PlasmaPhase(const std::string &inputFile="", const std::string &id="")
Construct and initialize a PlasmaPhase object directly from an input file.
Definition: PlasmaPhase.cpp:14
Eigen::ArrayXd m_electronEnergyDist
Normalized electron energy distribution vector [-] Length: m_nPoints.
Definition: PlasmaPhase.h:247
Eigen::ArrayXd m_electronEnergyLevels
electron energy levels [ev]. Length: m_nPoints
Definition: PlasmaPhase.h:243
void setDiscretizedElectronEnergyDist(const double *levels, const double *distrb, size_t length)
Set discretized electron energy distribution.
void checkElectronEnergyLevels() const
Check the electron energy levels.
Definition: PlasmaPhase.cpp:98
void updateElectronTemperatureFromEnergyDist()
Update electron temperature (K) From energy distribution.
void setElectronEnergyDistributionType(const std::string &type)
Set electron energy distribution type.
Definition: PlasmaPhase.cpp:53
void updateElectronEnergyDistribution()
Update electron energy distribution.
Definition: PlasmaPhase.cpp:31
virtual double electronTemperature() const
Electron Temperature (K)
Definition: PlasmaPhase.h:186
virtual void updateThermo() const
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
double m_electronTemp
Electron temperature [K].
Definition: PlasmaPhase.h:253
void setElectronEnergyLevels(const double *levels, size_t length)
Set electron energy levels.
Definition: PlasmaPhase.cpp:90
bool m_do_normalizeElectronEnergyDist
Flag of normalizing electron energy distribution.
Definition: PlasmaPhase.h:262
virtual std::string type() const
String indicating the thermodynamic model implemented.
Definition: PlasmaPhase.h:92
std::string m_distributionType
Electron energy distribution type.
Definition: PlasmaPhase.h:256
void setIsotropicElectronEnergyDistribution()
Set isotropic electron energy distribution.
Definition: PlasmaPhase.cpp:64
void setMeanElectronEnergy(double energy)
Set mean electron energy [eV].
Definition: PlasmaPhase.cpp:85
size_t m_electronSpeciesIndex
Index of electron species.
Definition: PlasmaPhase.h:250
void setIsotropicShapeFactor(double x)
Set the shape factor of isotropic electron energy distribution.
void enableNormalizeElectronEnergyDist(bool enable)
Set flag of automatically normalize electron energy distribution Flag: m_do_normalizeElectronEnergyDi...
Definition: PlasmaPhase.h:172
void initThermoFile(const std::string &inputFile, const std::string &id)
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1894
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
CachedScalar getScalar(int id)
Get a reference to a CachedValue object representing a scalar (doublereal) with the given id.
Definition: ValueCache.h:165
int getId()
Get a unique id for a cached value.
Definition: ValueCache.cpp:21
Header for a file containing miscellaneous numerical functions.
This file contains definitions for utility functions and text for modules, inputfiles,...
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:192
const double Boltzmann
Boltzmann constant [J/K].
Definition: ct_defs.h:69
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:184
double numericalQuadrature(const std::string &method, const Eigen::ArrayXd &f, const Eigen::ArrayXd &x)
Numerical integration of a function.
Definition: funcs.cpp:115
const double ElectronCharge
Elementary charge [C].
Definition: ct_defs.h:75
void warn_user(const std::string &method, const std::string &msg, const Args &... args)
Print a user warning raised from method as CanteraWarning.
Definition: global.h:245
double state2
Value of the second state variable for the state at which value was evaluated, for example density or...
Definition: ValueCache.h:111
double state1
Value of the first state variable for the state at which value was evaluated, for example temperature...
Definition: ValueCache.h:107