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
6#include "cantera/thermo/PlasmaPhase.h"
7#include <boost/math/special_functions/gamma.hpp>
8#include "cantera/thermo/Species.h"
9#include "cantera/base/global.h"
10#include "cantera/numerics/funcs.h"
11
12 namespace Cantera {
13
14 PlasmaPhase::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
28 setElectronTemperature(temperature());
29}
30
31 void PlasmaPhase::updateElectronEnergyDistribution()
32{
33 if (m_distributionType == "discretized") {
34 throw CanteraError("PlasmaPhase::updateElectronEnergyDistribution",
35 "Invalid for discretized electron energy distribution.");
36 } else if (m_distributionType == "isotropic") {
37 setIsotropicElectronEnergyDistribution();
38 }
39}
40
41 void PlasmaPhase::normalizeElectronEnergyDistribution() {
42 Eigen::ArrayXd eps32 = m_electronEnergyLevels.pow(3./2.);
43 double norm = 2./3. * numericalQuadrature(m_quadratureMethod,
44 m_electronEnergyDist, eps32);
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 }
50 m_electronEnergyDist /= norm;
51}
52
53 void PlasmaPhase::setElectronEnergyDistributionType(const std::string& type)
54{
55 if (type == "discretized" ||
56 type == "isotropic") {
57 m_distributionType = type;
58 } else {
59 throw CanteraError("PlasmaPhase::setElectronEnergyDistributionType",
60 "Unknown type for electron energy distribution.");
61 }
62}
63
64 void PlasmaPhase::setIsotropicElectronEnergyDistribution()
65{
66 m_electronEnergyDist.resize(m_nPoints);
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);
72 m_electronEnergyDist =
73 c1 * m_electronEnergyLevels.sqrt() /
74 std::pow(meanElectronEnergy(), 1.5) *
75 (-c2 * (m_electronEnergyLevels /
76 meanElectronEnergy()).pow(x)).exp();
77 checkElectronEnergyDistribution();
78}
79
80 void PlasmaPhase::setElectronTemperature(const double Te) {
81 m_electronTemp = Te;
82 updateElectronEnergyDistribution();
83}
84
85 void PlasmaPhase::setMeanElectronEnergy(double energy) {
86 m_electronTemp = 2.0 / 3.0 * energy * ElectronCharge / Boltzmann;
87 updateElectronEnergyDistribution();
88}
89
90 void PlasmaPhase::setElectronEnergyLevels(const double* levels, size_t length)
91{
92 m_nPoints = length;
93 m_electronEnergyLevels = Eigen::Map<const Eigen::ArrayXd>(levels, length);
94 checkElectronEnergyLevels();
95 updateElectronEnergyDistribution();
96}
97
98 void PlasmaPhase::checkElectronEnergyLevels() const
99{
100 Eigen::ArrayXd h = m_electronEnergyLevels.tail(m_nPoints - 1) -
101 m_electronEnergyLevels.head(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
109 void PlasmaPhase::checkElectronEnergyDistribution() const
110{
111 Eigen::ArrayXd h = m_electronEnergyLevels.tail(m_nPoints - 1) -
112 m_electronEnergyLevels.head(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
126 void PlasmaPhase::setDiscretizedElectronEnergyDist(const double* levels,
127 const double* dist,
128 size_t length)
129{
130 m_distributionType = "discretized";
131 m_nPoints = length;
132 m_electronEnergyLevels =
133 Eigen::Map<const Eigen::ArrayXd>(levels, length);
134 m_electronEnergyDist =
135 Eigen::Map<const Eigen::ArrayXd>(dist, length);
136 checkElectronEnergyLevels();
137 if (m_do_normalizeElectronEnergyDist) {
138 normalizeElectronEnergyDistribution();
139 }
140 checkElectronEnergyDistribution();
141 updateElectronTemperatureFromEnergyDist();
142}
143
144 void PlasmaPhase::updateElectronTemperatureFromEnergyDist()
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
153 void PlasmaPhase::setIsotropicShapeFactor(double x) {
154 m_isotropicShapeFactor = x;
155 setIsotropicElectronEnergyDistribution();
156}
157
158 void PlasmaPhase::getParameters(AnyMap& phaseNode) const
159{
160 IdealGasPhase::getParameters(phaseNode);
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
178 void 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 }
202 setIsotropicElectronEnergyDistribution();
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
222 bool 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) {
230 if (m_electronSpeciesIndex == npos) {
231 m_electronSpeciesIndex = k;
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
241 void PlasmaPhase::initThermo()
242{
243 IdealGasPhase::initThermo();
244 // check electron species
245 if (m_electronSpeciesIndex == npos) {
246 throw CanteraError("PlasmaPhase::initThermo",
247 "No electron species found.");
248 }
249}
250
251 void PlasmaPhase::updateThermo() const
252{
253 IdealGasPhase::updateThermo();
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) {
262 m_spthermo.update_single(k, electronTemperature(),
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}
PlasmaPhase.h
Header file for class PlasmaPhase.
Species.h
Declaration for class Cantera::Species.
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
Cantera::AnyMap::convert
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
Cantera::AnyMap::hasKey
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:1406
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::IdealGasPhase::m_g0_RT
vector_fp m_g0_RT
Temporary storage for dimensionless reference state Gibbs energies.
Definition: IdealGasPhase.h:605
Cantera::IdealGasPhase::m_cp0_R
vector_fp m_cp0_R
Temporary storage for dimensionless reference state heat capacities.
Definition: IdealGasPhase.h:602
Cantera::IdealGasPhase::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: IdealGasPhase.cpp:229
Cantera::IdealGasPhase::m_h0_RT
vector_fp m_h0_RT
Temporary storage for dimensionless reference state enthalpies.
Definition: IdealGasPhase.h:599
Cantera::IdealGasPhase::m_s0_R
vector_fp m_s0_R
Temporary storage for dimensionless reference state entropies.
Definition: IdealGasPhase.h:608
Cantera::IdealGasPhase::updateThermo
virtual void updateThermo() const
Definition: IdealGasPhase.cpp:273
Cantera::MultiSpeciesThermo::update_single
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.
Definition: MultiSpeciesThermo.cpp:81
Cantera::Phase::m_cache
ValueCache m_cache
Cached for saved calculations within each ThermoPhase.
Definition: Phase.h:923
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition: Phase.h:943
Cantera::Phase::temperature
doublereal temperature() const
Temperature (K).
Definition: Phase.h:654
Cantera::PlasmaPhase::checkElectronEnergyDistribution
void checkElectronEnergyDistribution() const
Check the electron energy distribution.
Definition: PlasmaPhase.cpp:109
Cantera::PlasmaPhase::meanElectronEnergy
double meanElectronEnergy() const
Mean electron energy [eV].
Definition: PlasmaPhase.h:166
Cantera::PlasmaPhase::m_nPoints
size_t m_nPoints
Number of points of electron energy levels.
Definition: PlasmaPhase.h:240
Cantera::PlasmaPhase::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: PlasmaPhase.cpp:222
Cantera::PlasmaPhase::setParameters
virtual void setParameters(const AnyMap &phaseNode, const AnyMap &rootNode=AnyMap())
Set equation of state parameters from an AnyMap phase description.
Definition: PlasmaPhase.cpp:178
Cantera::PlasmaPhase::getParameters
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
Definition: PlasmaPhase.cpp:158
Cantera::PlasmaPhase::normalizeElectronEnergyDistribution
void normalizeElectronEnergyDistribution()
Electron energy distribution norm.
Definition: PlasmaPhase.cpp:41
Cantera::PlasmaPhase::m_quadratureMethod
std::string m_quadratureMethod
Numerical quadrature method for electron energy distribution.
Definition: PlasmaPhase.h:259
Cantera::PlasmaPhase::setElectronTemperature
virtual void setElectronTemperature(double Te)
Set the internally stored electron temperature of the phase (K).
Definition: PlasmaPhase.cpp:80
Cantera::PlasmaPhase::PlasmaPhase
PlasmaPhase(const std::string &inputFile="", const std::string &id="")
Construct and initialize a PlasmaPhase object directly from an input file.
Definition: PlasmaPhase.cpp:14
Cantera::PlasmaPhase::m_electronEnergyDist
Eigen::ArrayXd m_electronEnergyDist
Normalized electron energy distribution vector [-] Length: m_nPoints.
Definition: PlasmaPhase.h:247
Cantera::PlasmaPhase::m_electronEnergyLevels
Eigen::ArrayXd m_electronEnergyLevels
electron energy levels [ev]. Length: m_nPoints
Definition: PlasmaPhase.h:243
Cantera::PlasmaPhase::setDiscretizedElectronEnergyDist
void setDiscretizedElectronEnergyDist(const double *levels, const double *distrb, size_t length)
Set discretized electron energy distribution.
Definition: PlasmaPhase.cpp:126
Cantera::PlasmaPhase::checkElectronEnergyLevels
void checkElectronEnergyLevels() const
Check the electron energy levels.
Definition: PlasmaPhase.cpp:98
Cantera::PlasmaPhase::updateElectronTemperatureFromEnergyDist
void updateElectronTemperatureFromEnergyDist()
Update electron temperature (K) From energy distribution.
Definition: PlasmaPhase.cpp:144
Cantera::PlasmaPhase::setElectronEnergyDistributionType
void setElectronEnergyDistributionType(const std::string &type)
Set electron energy distribution type.
Definition: PlasmaPhase.cpp:53
Cantera::PlasmaPhase::updateElectronEnergyDistribution
void updateElectronEnergyDistribution()
Update electron energy distribution.
Definition: PlasmaPhase.cpp:31
Cantera::PlasmaPhase::electronTemperature
virtual double electronTemperature() const
Electron Temperature (K)
Definition: PlasmaPhase.h:186
Cantera::PlasmaPhase::updateThermo
virtual void updateThermo() const
Definition: PlasmaPhase.cpp:251
Cantera::PlasmaPhase::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: PlasmaPhase.cpp:241
Cantera::PlasmaPhase::m_electronTemp
double m_electronTemp
Electron temperature [K].
Definition: PlasmaPhase.h:253
Cantera::PlasmaPhase::setElectronEnergyLevels
void setElectronEnergyLevels(const double *levels, size_t length)
Set electron energy levels.
Definition: PlasmaPhase.cpp:90
Cantera::PlasmaPhase::m_do_normalizeElectronEnergyDist
bool m_do_normalizeElectronEnergyDist
Flag of normalizing electron energy distribution.
Definition: PlasmaPhase.h:262
Cantera::PlasmaPhase::type
virtual std::string type() const
String indicating the thermodynamic model implemented.
Definition: PlasmaPhase.h:92
Cantera::PlasmaPhase::m_distributionType
std::string m_distributionType
Electron energy distribution type.
Definition: PlasmaPhase.h:256
Cantera::PlasmaPhase::setIsotropicElectronEnergyDistribution
void setIsotropicElectronEnergyDistribution()
Set isotropic electron energy distribution.
Definition: PlasmaPhase.cpp:64
Cantera::PlasmaPhase::setMeanElectronEnergy
void setMeanElectronEnergy(double energy)
Set mean electron energy [eV].
Definition: PlasmaPhase.cpp:85
Cantera::PlasmaPhase::m_electronSpeciesIndex
size_t m_electronSpeciesIndex
Index of electron species.
Definition: PlasmaPhase.h:250
Cantera::PlasmaPhase::setIsotropicShapeFactor
void setIsotropicShapeFactor(double x)
Set the shape factor of isotropic electron energy distribution.
Definition: PlasmaPhase.cpp:153
Cantera::PlasmaPhase::enableNormalizeElectronEnergyDist
void enableNormalizeElectronEnergyDist(bool enable)
Set flag of automatically normalize electron energy distribution Flag: m_do_normalizeElectronEnergyDi...
Definition: PlasmaPhase.h:172
Cantera::ThermoPhase::initThermoFile
void initThermoFile(const std::string &inputFile, const std::string &id)
Definition: ThermoPhase.cpp:1066
Cantera::ThermoPhase::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: ThermoPhase.cpp:1102
Cantera::ThermoPhase::m_spthermo
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1894
Cantera::ThermoPhase::setParameters
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
Definition: ThermoPhase.cpp:1187
Cantera::ThermoPhase::getParameters
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
Definition: ThermoPhase.cpp:1193
Cantera::ValueCache::getScalar
CachedScalar getScalar(int id)
Get a reference to a CachedValue object representing a scalar (doublereal) with the given id.
Definition: ValueCache.h:165
Cantera::ValueCache::getId
int getId()
Get a unique id for a cached value.
Definition: ValueCache.cpp:21
funcs.h
Header for a file containing miscellaneous numerical functions.
global.h
This file contains definitions for utility functions and text for modules, inputfiles,...
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::npos
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:192
Cantera::Boltzmann
const double Boltzmann
Boltzmann constant [J/K].
Definition: ct_defs.h:69
Cantera::vector_fp
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
Cantera::warn_user
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
Cantera::numericalQuadrature
double numericalQuadrature(const std::string &method, const Eigen::ArrayXd &f, const Eigen::ArrayXd &x)
Numerical integration of a function.
Definition: funcs.cpp:115
Cantera::ElectronCharge
const double ElectronCharge
Elementary charge [C].
Definition: ct_defs.h:75
Cantera::CachedValue
Definition: ValueCache.h:32
Cantera::CachedValue::state2
double state2
Value of the second state variable for the state at which value was evaluated, for example density or...
Definition: ValueCache.h:111
Cantera::CachedValue::state1
double state1
Value of the first state variable for the state at which value was evaluated, for example temperature...
Definition: ValueCache.h:107