Cantera 2.6.0

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
11#include "cantera/thermo/IdealGasPhase.h"
12#include "cantera/thermo/ThermoFactory.h"
13#include "cantera/base/utilities.h"
14
15 using namespace std;
16
17 namespace Cantera
18{
19
20 IdealGasPhase::IdealGasPhase(const std::string& inputFile, const std::string& id_) :
21 m_p0(-1.0)
22{
23 initThermoFile(inputFile, id_);
24}
25
26 IdealGasPhase::IdealGasPhase(XML_Node& phaseRef, const std::string& id_) :
27 m_p0(-1.0)
28{
29 importPhase(phaseRef, this);
30}
31
32// Molar Thermodynamic Properties of the Solution ------------------
33
34doublereal IdealGasPhase::entropy_mole() const
35{
36 return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx() - std::log(pressure() / refPressure()));
37}
38
39doublereal IdealGasPhase::cp_mole() const
40{
41 return GasConstant * mean_X(cp_R_ref());
42}
43
44doublereal IdealGasPhase::cv_mole() const
45{
46 return cp_mole() - GasConstant;
47}
48
49doublereal IdealGasPhase::standardConcentration(size_t k) const
50{
51 return pressure() / RT();
52}
53
54 void IdealGasPhase::getActivityCoefficients(doublereal* ac) const
55{
56 for (size_t k = 0; k < m_kk; k++) {
57 ac[k] = 1.0;
58 }
59}
60
61 void IdealGasPhase::getStandardChemPotentials(doublereal* muStar) const
62{
63 const vector_fp& gibbsrt = gibbs_RT_ref();
64 scale(gibbsrt.begin(), gibbsrt.end(), muStar, RT());
65 double tmp = log(pressure() / refPressure()) * RT();
66 for (size_t k = 0; k < m_kk; k++) {
67 muStar[k] += tmp; // add RT*ln(P/P_0)
68 }
69}
70
71// Partial Molar Properties of the Solution --------------
72
73 void IdealGasPhase::getChemPotentials(doublereal* mu) const
74{
75 getStandardChemPotentials(mu);
76 for (size_t k = 0; k < m_kk; k++) {
77 double xx = std::max(SmallNumber, moleFraction(k));
78 mu[k] += RT() * log(xx);
79 }
80}
81
82 void IdealGasPhase::getPartialMolarEnthalpies(doublereal* hbar) const
83{
84 const vector_fp& _h = enthalpy_RT_ref();
85 scale(_h.begin(), _h.end(), hbar, RT());
86}
87
88 void IdealGasPhase::getPartialMolarEntropies(doublereal* sbar) const
89{
90 const vector_fp& _s = entropy_R_ref();
91 scale(_s.begin(), _s.end(), sbar, GasConstant);
92 doublereal logp = log(pressure() / refPressure());
93 for (size_t k = 0; k < m_kk; k++) {
94 doublereal xx = std::max(SmallNumber, moleFraction(k));
95 sbar[k] += GasConstant * (-logp - log(xx));
96 }
97}
98
99 void IdealGasPhase::getPartialMolarIntEnergies(doublereal* ubar) const
100{
101 const vector_fp& _h = enthalpy_RT_ref();
102 for (size_t k = 0; k < m_kk; k++) {
103 ubar[k] = RT() * (_h[k] - 1.0);
104 }
105}
106
107 void IdealGasPhase::getPartialMolarCp(doublereal* cpbar) const
108{
109 const vector_fp& _cp = cp_R_ref();
110 scale(_cp.begin(), _cp.end(), cpbar, GasConstant);
111}
112
113 void IdealGasPhase::getPartialMolarVolumes(doublereal* vbar) const
114{
115 double vol = 1.0 / molarDensity();
116 for (size_t k = 0; k < m_kk; k++) {
117 vbar[k] = vol;
118 }
119}
120
121// Properties of the Standard State of the Species in the Solution --
122
123 void IdealGasPhase::getEnthalpy_RT(doublereal* hrt) const
124{
125 const vector_fp& _h = enthalpy_RT_ref();
126 copy(_h.begin(), _h.end(), hrt);
127}
128
129 void IdealGasPhase::getEntropy_R(doublereal* sr) const
130{
131 const vector_fp& _s = entropy_R_ref();
132 copy(_s.begin(), _s.end(), sr);
133 double tmp = log(pressure() / refPressure());
134 for (size_t k = 0; k < m_kk; k++) {
135 sr[k] -= tmp;
136 }
137}
138
139 void IdealGasPhase::getGibbs_RT(doublereal* grt) const
140{
141 const vector_fp& gibbsrt = gibbs_RT_ref();
142 copy(gibbsrt.begin(), gibbsrt.end(), grt);
143 double tmp = log(pressure() / refPressure());
144 for (size_t k = 0; k < m_kk; k++) {
145 grt[k] += tmp;
146 }
147}
148
149 void IdealGasPhase::getPureGibbs(doublereal* gpure) const
150{
151 const vector_fp& gibbsrt = gibbs_RT_ref();
152 scale(gibbsrt.begin(), gibbsrt.end(), gpure, RT());
153 double tmp = log(pressure() / refPressure()) * RT();
154 for (size_t k = 0; k < m_kk; k++) {
155 gpure[k] += tmp;
156 }
157}
158
159 void IdealGasPhase::getIntEnergy_RT(doublereal* urt) const
160{
161 const vector_fp& _h = enthalpy_RT_ref();
162 for (size_t k = 0; k < m_kk; k++) {
163 urt[k] = _h[k] - 1.0;
164 }
165}
166
167 void IdealGasPhase::getCp_R(doublereal* cpr) const
168{
169 const vector_fp& _cpr = cp_R_ref();
170 copy(_cpr.begin(), _cpr.end(), cpr);
171}
172
173 void IdealGasPhase::getStandardVolumes(doublereal* vol) const
174{
175 double tmp = 1.0 / molarDensity();
176 for (size_t k = 0; k < m_kk; k++) {
177 vol[k] = tmp;
178 }
179}
180
181// Thermodynamic Values for the Species Reference States ---------
182
183 void IdealGasPhase::getEnthalpy_RT_ref(doublereal* hrt) const
184{
185 const vector_fp& _h = enthalpy_RT_ref();
186 copy(_h.begin(), _h.end(), hrt);
187}
188
189 void IdealGasPhase::getGibbs_RT_ref(doublereal* grt) const
190{
191 const vector_fp& gibbsrt = gibbs_RT_ref();
192 copy(gibbsrt.begin(), gibbsrt.end(), grt);
193}
194
195 void IdealGasPhase::getGibbs_ref(doublereal* g) const
196{
197 const vector_fp& gibbsrt = gibbs_RT_ref();
198 scale(gibbsrt.begin(), gibbsrt.end(), g, RT());
199}
200
201 void IdealGasPhase::getEntropy_R_ref(doublereal* er) const
202{
203 const vector_fp& _s = entropy_R_ref();
204 copy(_s.begin(), _s.end(), er);
205}
206
207 void IdealGasPhase::getIntEnergy_RT_ref(doublereal* urt) const
208{
209 const vector_fp& _h = enthalpy_RT_ref();
210 for (size_t k = 0; k < m_kk; k++) {
211 urt[k] = _h[k] - 1.0;
212 }
213}
214
215 void IdealGasPhase::getCp_R_ref(doublereal* cprt) const
216{
217 const vector_fp& _cpr = cp_R_ref();
218 copy(_cpr.begin(), _cpr.end(), cprt);
219}
220
221 void IdealGasPhase::getStandardVolumes_ref(doublereal* vol) const
222{
223 doublereal tmp = RT() / m_p0;
224 for (size_t k = 0; k < m_kk; k++) {
225 vol[k] = tmp;
226 }
227}
228
229 bool IdealGasPhase::addSpecies(shared_ptr<Species> spec)
230{
231 bool added = ThermoPhase::addSpecies(spec);
232 if (added) {
233 if (m_kk == 1) {
234 m_p0 = refPressure();
235 }
236 m_h0_RT.push_back(0.0);
237 m_g0_RT.push_back(0.0);
238 m_expg0_RT.push_back(0.0);
239 m_cp0_R.push_back(0.0);
240 m_s0_R.push_back(0.0);
241 m_pp.push_back(0.0);
242 }
243 return added;
244}
245
246 void IdealGasPhase::setToEquilState(const doublereal* mu_RT)
247{
248 const vector_fp& grt = gibbs_RT_ref();
249
250 // Within the method, we protect against inf results if the exponent is too
251 // high.
252 //
253 // If it is too low, we set the partial pressure to zero. This capability is
254 // needed by the elemental potential method.
255 doublereal pres = 0.0;
256 for (size_t k = 0; k < m_kk; k++) {
257 double tmp = -grt[k] + mu_RT[k];
258 if (tmp < -600.) {
259 m_pp[k] = 0.0;
260 } else if (tmp > 300.0) {
261 double tmp2 = tmp / 300.;
262 tmp2 *= tmp2;
263 m_pp[k] = m_p0 * exp(300.) * tmp2;
264 } else {
265 m_pp[k] = m_p0 * exp(tmp);
266 }
267 pres += m_pp[k];
268 }
269 // set state
270 setState_PX(pres, &m_pp[0]);
271}
272
273 void IdealGasPhase::updateThermo() const
274{
275 static const int cacheId = m_cache.getId();
276 CachedScalar cached = m_cache.getScalar(cacheId);
277 doublereal tnow = temperature();
278
279 // If the temperature has changed since the last time these
280 // properties were computed, recompute them.
281 if (cached.state1 != tnow) {
282 m_spthermo.update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
283 cached.state1 = tnow;
284
285 // update the species Gibbs functions
286 for (size_t k = 0; k < m_kk; k++) {
287 m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
288 }
289 }
290}
291}
IdealGasPhase.h
ThermoPhase object for the ideal gas equation of state - workhorse for Cantera (see Thermodynamic Pro...
ThermoFactory.h
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
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::getGibbs_RT_ref
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
Definition: IdealGasPhase.cpp:189
Cantera::IdealGasPhase::getActivityCoefficients
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature,...
Definition: IdealGasPhase.cpp:54
Cantera::IdealGasPhase::getGibbs_RT
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Definition: IdealGasPhase.cpp:139
Cantera::IdealGasPhase::getPartialMolarIntEnergies
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
Definition: IdealGasPhase.cpp:99
Cantera::IdealGasPhase::cp_mole
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure.
Definition: IdealGasPhase.cpp:39
Cantera::IdealGasPhase::m_h0_RT
vector_fp m_h0_RT
Temporary storage for dimensionless reference state enthalpies.
Definition: IdealGasPhase.h:599
Cantera::IdealGasPhase::getPartialMolarEnthalpies
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: IdealGasPhase.cpp:82
Cantera::IdealGasPhase::getPartialMolarEntropies
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: IdealGasPhase.cpp:88
Cantera::IdealGasPhase::setToEquilState
virtual void setToEquilState(const doublereal *mu_RT)
This method is used by the ChemEquil equilibrium solver.
Definition: IdealGasPhase.cpp:246
Cantera::IdealGasPhase::getPartialMolarVolumes
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
Definition: IdealGasPhase.cpp:113
Cantera::IdealGasPhase::m_pp
vector_fp m_pp
Temporary array containing internally calculated partial pressures.
Definition: IdealGasPhase.h:613
Cantera::IdealGasPhase::getStandardVolumes
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of the species standard states at the current T and P of the solution.
Definition: IdealGasPhase.cpp:173
Cantera::IdealGasPhase::m_s0_R
vector_fp m_s0_R
Temporary storage for dimensionless reference state entropies.
Definition: IdealGasPhase.h:608
Cantera::IdealGasPhase::cv_mole
virtual doublereal cv_mole() const
Molar heat capacity at constant volume.
Definition: IdealGasPhase.cpp:44
Cantera::IdealGasPhase::cp_R_ref
const vector_fp & cp_R_ref() const
Returns a reference to the dimensionless reference state Heat Capacity vector.
Definition: IdealGasPhase.h:580
Cantera::IdealGasPhase::getCp_R
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition: IdealGasPhase.cpp:167
Cantera::IdealGasPhase::getPartialMolarCp
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
Definition: IdealGasPhase.cpp:107
Cantera::IdealGasPhase::enthalpy_RT_ref
const vector_fp & enthalpy_RT_ref() const
Returns a reference to the dimensionless reference state enthalpy vector.
Definition: IdealGasPhase.h:550
Cantera::IdealGasPhase::updateThermo
virtual void updateThermo() const
Definition: IdealGasPhase.cpp:273
Cantera::IdealGasPhase::getEntropy_R
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition: IdealGasPhase.cpp:129
Cantera::IdealGasPhase::entropy_mole
virtual doublereal entropy_mole() const
Molar entropy.
Definition: IdealGasPhase.cpp:34
Cantera::IdealGasPhase::entropy_R_ref
const vector_fp & entropy_R_ref() const
Returns a reference to the dimensionless reference state Entropy vector.
Definition: IdealGasPhase.h:570
Cantera::IdealGasPhase::gibbs_RT_ref
const vector_fp & gibbs_RT_ref() const
Returns a reference to the dimensionless reference state Gibbs free energy vector.
Definition: IdealGasPhase.h:560
Cantera::IdealGasPhase::getEntropy_R_ref
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
Definition: IdealGasPhase.cpp:201
Cantera::IdealGasPhase::getIntEnergy_RT_ref
virtual void getIntEnergy_RT_ref(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
Definition: IdealGasPhase.cpp:207
Cantera::IdealGasPhase::getIntEnergy_RT
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Definition: IdealGasPhase.cpp:159
Cantera::IdealGasPhase::pressure
virtual doublereal pressure() const
Pressure.
Definition: IdealGasPhase.h:371
Cantera::IdealGasPhase::getCp_R_ref
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
Definition: IdealGasPhase.cpp:215
Cantera::IdealGasPhase::m_p0
doublereal m_p0
Reference state pressure.
Definition: IdealGasPhase.h:596
Cantera::IdealGasPhase::getStandardChemPotentials
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition: IdealGasPhase.cpp:61
Cantera::IdealGasPhase::getStandardVolumes_ref
virtual void getStandardVolumes_ref(doublereal *vol) const
Get the molar volumes of the species reference states at the current T and P_ref of the solution.
Definition: IdealGasPhase.cpp:221
Cantera::IdealGasPhase::getChemPotentials
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: IdealGasPhase.cpp:73
Cantera::IdealGasPhase::getGibbs_ref
virtual void getGibbs_ref(doublereal *g) const
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
Definition: IdealGasPhase.cpp:195
Cantera::IdealGasPhase::getEnthalpy_RT
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition: IdealGasPhase.cpp:123
Cantera::IdealGasPhase::IdealGasPhase
IdealGasPhase(const std::string &inputFile="", const std::string &id="")
Construct and initialize an IdealGasPhase ThermoPhase object directly from an ASCII input file.
Definition: IdealGasPhase.cpp:20
Cantera::IdealGasPhase::getPureGibbs
virtual void getPureGibbs(doublereal *gpure) const
Get the Gibbs functions for the standard state of the species at the current T and P of the solution.
Definition: IdealGasPhase.cpp:149
Cantera::IdealGasPhase::getEnthalpy_RT_ref
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
Definition: IdealGasPhase.cpp:183
Cantera::IdealGasPhase::standardConcentration
virtual doublereal standardConcentration(size_t k=0) const
Returns the standard concentration , which is used to normalize the generalized concentration.
Definition: IdealGasPhase.cpp:49
Cantera::MultiSpeciesThermo::update
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
Definition: MultiSpeciesThermo.cpp:90
Cantera::Phase::molarDensity
double molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:671
Cantera::Phase::mean_X
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:717
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::moleFraction
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:548
Cantera::Phase::temperature
doublereal temperature() const
Temperature (K).
Definition: Phase.h:654
Cantera::Phase::sum_xlogx
doublereal sum_xlogx() const
Evaluate .
Definition: Phase.cpp:727
Cantera::ThermoPhase::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: ThermoPhase.cpp:1140
Cantera::ThermoPhase::RT
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:782
Cantera::ThermoPhase::initThermoFile
void initThermoFile(const std::string &inputFile, const std::string &id)
Definition: ThermoPhase.cpp:1066
Cantera::ThermoPhase::setState_PX
virtual void setState_PX(doublereal p, doublereal *x)
Set the pressure (Pa) and mole fractions.
Definition: ThermoPhase.cpp:187
Cantera::ThermoPhase::refPressure
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:150
Cantera::ThermoPhase::m_spthermo
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1894
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
Cantera::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Cantera::importPhase
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Definition: ThermoFactory.cpp:250
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::SmallNumber
const double SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:153
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::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
Cantera::scale
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:100
Cantera::CachedValue
Definition: ValueCache.h:32
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
utilities.h
Various templated functions that carry out common vector operations (see Templated Utility Functions)...