Cantera  3.2.0
Loading...
Searching...
No Matches
IdealGasPhase.cpp
Go to the documentation of this file.
1/**
2 * @file IdealGasPhase.cpp
3 * ThermoPhase object for the ideal gas equation of
4 * state - workhorse for %Cantera (see @ref thermoprops
5 * and class @link Cantera::IdealGasPhase IdealGasPhase@endlink).
6 */
7
8// This file is part of Cantera. See License.txt in the top-level directory or
9// at https://cantera.org/license.txt for license and copyright information.
10
14
15namespace Cantera
16{
17
18IdealGasPhase::IdealGasPhase(const string& inputFile, const string& id_)
19{
20 initThermoFile(inputFile, id_);
21}
22
23// Molar Thermodynamic Properties of the Solution ------------------
24
26{
27 return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx() - std::log(pressure() / refPressure()));
28}
29
31{
32 return GasConstant * mean_X(cp_R_ref());
33}
34
36{
37 return cp_mole() - GasConstant;
38}
39
41 return sqrt(
43 );
44}
45
47{
48 return pressure() / RT();
49}
50
52{
53 for (size_t k = 0; k < m_kk; k++) {
54 ac[k] = 1.0;
55 }
56}
57
59{
60 getGibbs_ref(muStar);
61 double tmp = log(pressure() / refPressure()) * RT();
62 for (size_t k = 0; k < m_kk; k++) {
63 muStar[k] += tmp; // add RT*ln(P/P_0)
64 }
65}
66
67// Partial Molar Properties of the Solution --------------
68
70{
72 for (size_t k = 0; k < m_kk; k++) {
73 double xx = std::max(SmallNumber, moleFraction(k));
74 mu[k] += RT() * log(xx);
75 }
76}
77
79{
80 const vector<double>& _h = enthalpy_RT_ref();
81 scale(_h.begin(), _h.end(), hbar, RT());
82}
83
85{
86 const vector<double>& _s = entropy_R_ref();
87 scale(_s.begin(), _s.end(), sbar, GasConstant);
88 double logp = log(pressure() / refPressure());
89 for (size_t k = 0; k < m_kk; k++) {
90 double xx = std::max(SmallNumber, moleFraction(k));
91 sbar[k] += GasConstant * (-logp - log(xx));
92 }
93}
94
96{
97 const vector<double>& _h = enthalpy_RT_ref();
98 for (size_t k = 0; k < m_kk; k++) {
99 ubar[k] = RT() * (_h[k] - 1.0);
100 }
101}
102
103void IdealGasPhase::getPartialMolarCp(double* cpbar) const
104{
105 const vector<double>& _cp = cp_R_ref();
106 scale(_cp.begin(), _cp.end(), cpbar, GasConstant);
107}
108
110{
111 double vol = 1.0 / molarDensity();
112 for (size_t k = 0; k < m_kk; k++) {
113 vbar[k] = vol;
114 }
115}
116
117// Properties of the Standard State of the Species in the Solution --
118
119void IdealGasPhase::getEnthalpy_RT(double* hrt) const
120{
121 const vector<double>& _h = enthalpy_RT_ref();
122 copy(_h.begin(), _h.end(), hrt);
123}
124
125void IdealGasPhase::getEntropy_R(double* sr) const
126{
127 const vector<double>& _s = entropy_R_ref();
128 copy(_s.begin(), _s.end(), sr);
129 double tmp = log(pressure() / refPressure());
130 for (size_t k = 0; k < m_kk; k++) {
131 sr[k] -= tmp;
132 }
133}
134
135void IdealGasPhase::getGibbs_RT(double* grt) const
136{
137 const vector<double>& gibbsrt = gibbs_RT_ref();
138 copy(gibbsrt.begin(), gibbsrt.end(), grt);
139 double tmp = log(pressure() / refPressure());
140 for (size_t k = 0; k < m_kk; k++) {
141 grt[k] += tmp;
142 }
143}
144
145void IdealGasPhase::getPureGibbs(double* gpure) const
146{
147 warn_deprecated("IdealGasPhase::getPureGibbs",
148 "To be removed after Cantera 3.2. Use getStandardChemPotentials instead.");
149 const vector<double>& gibbsrt = gibbs_RT_ref();
150 scale(gibbsrt.begin(), gibbsrt.end(), gpure, RT());
151 double tmp = log(pressure() / refPressure()) * RT();
152 for (size_t k = 0; k < m_kk; k++) {
153 gpure[k] += tmp;
154 }
155}
156
157void IdealGasPhase::getIntEnergy_RT(double* urt) const
158{
160}
161
162void IdealGasPhase::getCp_R(double* cpr) const
163{
164 const vector<double>& _cpr = cp_R_ref();
165 copy(_cpr.begin(), _cpr.end(), cpr);
166}
167
169{
170 double tmp = 1.0 / molarDensity();
171 for (size_t k = 0; k < m_kk; k++) {
172 vol[k] = tmp;
173 }
174}
175
176// Thermodynamic Values for the Species Reference States ---------
177
179{
180 const vector<double>& _h = enthalpy_RT_ref();
181 copy(_h.begin(), _h.end(), hrt);
182}
183
184void IdealGasPhase::getGibbs_RT_ref(double* grt) const
185{
186 const vector<double>& gibbsrt = gibbs_RT_ref();
187 copy(gibbsrt.begin(), gibbsrt.end(), grt);
188}
189
190void IdealGasPhase::getGibbs_ref(double* g) const
191{
192 const vector<double>& gibbsrt = gibbs_RT_ref();
193 scale(gibbsrt.begin(), gibbsrt.end(), g, RT());
194}
195
197{
198 const vector<double>& _s = entropy_R_ref();
199 copy(_s.begin(), _s.end(), er);
200}
201
203{
204 const vector<double>& _h = enthalpy_RT_ref();
205 for (size_t k = 0; k < m_kk; k++) {
206 urt[k] = _h[k] - 1.0;
207 }
208}
209
210void IdealGasPhase::getCp_R_ref(double* cprt) const
211{
212 const vector<double>& _cpr = cp_R_ref();
213 copy(_cpr.begin(), _cpr.end(), cprt);
214}
215
217{
218 double tmp = RT() / m_p0;
219 for (size_t k = 0; k < m_kk; k++) {
220 vol[k] = tmp;
221 }
222}
223
224bool IdealGasPhase::addSpecies(shared_ptr<Species> spec)
225{
226 bool added = ThermoPhase::addSpecies(spec);
227 if (added) {
228 if (m_kk == 1) {
229 m_p0 = refPressure();
230 }
231 m_h0_RT.push_back(0.0);
232 m_g0_RT.push_back(0.0);
233 m_expg0_RT.push_back(0.0);
234 m_cp0_R.push_back(0.0);
235 m_s0_R.push_back(0.0);
236 m_pp.push_back(0.0);
237 }
238 return added;
239}
240
241void IdealGasPhase::setToEquilState(const double* mu_RT)
242{
243 const vector<double>& grt = gibbs_RT_ref();
244
245 // Within the method, we protect against inf results if the exponent is too
246 // high.
247 //
248 // If it is too low, we set the partial pressure to zero. This capability is
249 // needed by the elemental potential method.
250 double pres = 0.0;
251 for (size_t k = 0; k < m_kk; k++) {
252 double tmp = -grt[k] + mu_RT[k];
253 if (tmp < -600.) {
254 m_pp[k] = 0.0;
255 } else if (tmp > 300.0) {
256 double tmp2 = tmp / 300.;
257 tmp2 *= tmp2;
258 m_pp[k] = m_p0 * exp(300.) * tmp2;
259 } else {
260 m_pp[k] = m_p0 * exp(tmp);
261 }
262 pres += m_pp[k];
263 }
264 // set state
265 setMoleFractions(m_pp.data());
266 setPressure(pres);
267}
268
270{
271 static const int cacheId = m_cache.getId();
272 CachedScalar cached = m_cache.getScalar(cacheId);
273 double tnow = temperature();
274
275 // If the temperature has changed since the last time these
276 // properties were computed, recompute them.
277 if (cached.state1 != tnow) {
278 m_spthermo.update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
279 cached.state1 = tnow;
280
281 // update the species Gibbs functions
282 for (size_t k = 0; k < m_kk; k++) {
283 m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
284 }
285 }
286}
287}
ThermoPhase object for the ideal gas equation of state - workhorse for Cantera (see Thermodynamic Pro...
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
const vector< double > & entropy_R_ref() const
Returns a reference to the dimensionless reference state Entropy vector.
void getPartialMolarEnthalpies(double *hbar) const override
Returns an array of partial molar enthalpies for the species in the mixture.
void getChemPotentials(double *mu) const override
Get the species chemical potentials. Units: J/kmol.
double m_p0
Reference state pressure.
double soundSpeed() const override
Return the speed of sound. Units: m/s.
double pressure() const override
Pressure.
vector< double > m_g0_RT
Temporary storage for dimensionless reference state Gibbs energies.
void getEntropy_R(double *sr) const override
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
vector< double > m_h0_RT
Temporary storage for dimensionless reference state enthalpies.
void getGibbs_ref(double *g) const override
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
vector< double > m_pp
Temporary array containing internally calculated partial pressures.
void getStandardChemPotentials(double *mu) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void getCp_R(double *cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
void setPressure(double p) override
Set the pressure at constant temperature and composition.
const vector< double > & gibbs_RT_ref() const
Returns a reference to the dimensionless reference state Gibbs free energy vector.
void getStandardVolumes_ref(double *vol) const override
Get the molar volumes of the species reference states at the current T and P_ref of the solution.
void getPartialMolarVolumes(double *vbar) const override
Return an array of partial molar volumes for the species in the mixture.
double cv_mole() const override
Molar heat capacity at constant volume and composition [J/kmol/K].
virtual void updateThermo() const
Update the species reference state thermodynamic functions.
void getPureGibbs(double *gpure) const override
Get the Gibbs functions for the standard state of the species at the current T and P of the solution.
void getIntEnergy_RT_ref(double *urt) const override
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
void getEnthalpy_RT(double *hrt) const override
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
void getEntropy_R_ref(double *er) const override
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
vector< double > m_s0_R
Temporary storage for dimensionless reference state entropies.
void getGibbs_RT(double *grt) const override
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
double entropy_mole() const override
Molar entropy.
void getCp_R_ref(double *cprt) const override
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
void getStandardVolumes(double *vol) const override
Get the molar volumes of the species standard states at the current T and P of the solution.
void getPartialMolarIntEnergies(double *ubar) const override
Return an array of partial molar internal energies for the species in the mixture.
double cp_mole() const override
Molar heat capacity at constant pressure and composition [J/kmol/K].
void getIntEnergy_RT(double *urt) const override
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
void getPartialMolarCp(double *cpbar) const override
Return an array of partial molar heat capacities for the species in the mixture.
double standardConcentration(size_t k=0) const override
Returns the standard concentration , which is used to normalize the generalized concentration.
vector< double > m_cp0_R
Temporary storage for dimensionless reference state heat capacities.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
void setToEquilState(const double *mu_RT) override
This method is used by the ChemEquil equilibrium solver.
void getGibbs_RT_ref(double *grt) const override
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
void getActivityCoefficients(double *ac) const override
Get the array of non-dimensional activity coefficients at the current solution temperature,...
IdealGasPhase(const string &inputFile="", const string &id="")
Construct and initialize an IdealGasPhase ThermoPhase object directly from an input file.
void getPartialMolarEntropies(double *sbar) const override
Returns an array of partial molar entropies of the species in the solution.
const vector< double > & cp_R_ref() const
Returns a reference to the dimensionless reference state Heat Capacity vector.
void getEnthalpy_RT_ref(double *hrt) const override
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
const vector< double > & enthalpy_RT_ref() const
Returns a reference to the dimensionless reference state enthalpy vector.
virtual void update(double T, double *cp_R, double *h_RT, double *s_R) const
Compute the reference-state properties for all species.
virtual double molarDensity() const
Molar density (kmol/m^3).
Definition Phase.cpp:639
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
Definition Phase.cpp:347
ValueCache m_cache
Cached for saved calculations within each ThermoPhase.
Definition Phase.h:901
size_t m_kk
Number of species in the phase.
Definition Phase.h:921
double temperature() const
Temperature (K).
Definition Phase.h:629
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:722
double sum_xlogx() const
Evaluate .
Definition Phase.cpp:689
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition Phase.cpp:504
double mean_X(const double *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition Phase.cpp:679
double RT() const
Return the Gas Constant multiplied by the current temperature.
void initThermoFile(const string &inputFile, const string &id)
Initialize a ThermoPhase object using an input file.
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
virtual double refPressure() const
Returns the reference pressure in Pa.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
CachedScalar getScalar(int id)
Get a reference to a CachedValue object representing a scalar (double) with the given id.
Definition ValueCache.h:161
int getId()
Get a unique id for a cached value.
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition utilities.h:104
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const double SmallNumber
smallest number to compare to zero.
Definition ct_defs.h:158
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1997
A cached property value and the state at which it was evaluated.
Definition ValueCache.h:33
double state1
Value of the first state variable for the state at which value was evaluated, for example temperature...
Definition ValueCache.h:102
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...