Cantera 2.6.0
VPStandardStateTP.cpp
Go to the documentation of this file.
1/**
2 * @file VPStandardStateTP.cpp
3 * Definition file for a derived class of ThermoPhase that handles
4 * variable pressure standard state methods for calculating
5 * thermodynamic properties (see \ref thermoprops and
6 * class \link Cantera::VPStandardStateTP VPStandardStateTP\endlink).
7 */
8
9// This file is part of Cantera. See License.txt in the top-level directory or
10// at https://cantera.org/license.txt for license and copyright information.
11
13#include "cantera/thermo/PDSS.h"
16
17using namespace std;
18
19namespace Cantera
20{
21
23 m_Pcurrent(OneAtm),
24 m_minTemp(0.0),
25 m_maxTemp(BigNumber),
26 m_Tlast_ss(-1.0),
27 m_Plast_ss(-1.0)
28{
29}
30
31VPStandardStateTP::~VPStandardStateTP()
32{
33}
34
36{
38}
39
40void VPStandardStateTP::getChemPotentials_RT(doublereal* muRT) const
41{
43 for (size_t k = 0; k < m_kk; k++) {
44 muRT[k] *= 1.0 / RT();
45 }
46}
47
48// ----- Thermodynamic Values for the Species Standard States States ----
49
51{
52 getGibbs_RT(g);
53 for (size_t k = 0; k < m_kk; k++) {
54 g[k] *= RT();
55 }
56}
57
58void VPStandardStateTP::getEnthalpy_RT(doublereal* hrt) const
59{
61 std::copy(m_hss_RT.begin(), m_hss_RT.end(), hrt);
62}
63
64void VPStandardStateTP::getEntropy_R(doublereal* sr) const
65{
67 std::copy(m_sss_R.begin(), m_sss_R.end(), sr);
68}
69
70void VPStandardStateTP::getGibbs_RT(doublereal* grt) const
71{
73 std::copy(m_gss_RT.begin(), m_gss_RT.end(), grt);
74}
75
76void VPStandardStateTP::getPureGibbs(doublereal* g) const
77{
79 std::copy(m_gss_RT.begin(), m_gss_RT.end(), g);
80 scale(g, g+m_kk, g, RT());
81}
82
83void VPStandardStateTP::getIntEnergy_RT(doublereal* urt) const
84{
86 std::copy(m_hss_RT.begin(), m_hss_RT.end(), urt);
87 for (size_t k = 0; k < m_kk; k++) {
88 urt[k] -= m_Plast_ss / RT() * m_Vss[k];
89 }
90}
91
92void VPStandardStateTP::getCp_R(doublereal* cpr) const
93{
95 std::copy(m_cpss_R.begin(), m_cpss_R.end(), cpr);
96}
97
98void VPStandardStateTP::getStandardVolumes(doublereal* vol) const
99{
101 std::copy(m_Vss.begin(), m_Vss.end(), vol);
102}
103const vector_fp& VPStandardStateTP::getStandardVolumes() const
104{
106 return m_Vss;
107}
108
109// ----- Thermodynamic Values for the Species Reference States ----
110
111void VPStandardStateTP::getEnthalpy_RT_ref(doublereal* hrt) const
112{
114 std::copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
115}
116
117void VPStandardStateTP::getGibbs_RT_ref(doublereal* grt) const
118{
120 std::copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
121}
122
123void VPStandardStateTP::getGibbs_ref(doublereal* g) const
124{
126 std::copy(m_g0_RT.begin(), m_g0_RT.end(), g);
127 scale(g, g+m_kk, g, RT());
128}
129
130const vector_fp& VPStandardStateTP::Gibbs_RT_ref() const
131{
133 return m_g0_RT;
134}
135
136void VPStandardStateTP::getEntropy_R_ref(doublereal* sr) const
137{
139 std::copy(m_s0_R.begin(), m_s0_R.end(), sr);
140}
141
142void VPStandardStateTP::getCp_R_ref(doublereal* cpr) const
143{
145 std::copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
146}
147
149{
151 std::copy(m_Vss.begin(), m_Vss.end(), vol);
152}
153
155{
157 for (size_t k = 0; k < m_kk; k++) {
158 PDSS* kPDSS = m_PDSS_storage[k].get();
159 if (kPDSS == 0) {
160 throw CanteraError("VPStandardStateTP::initThermo",
161 "No PDSS object for species {}", k);
162 }
163 kPDSS->initThermo();
164 }
165}
166
167void VPStandardStateTP::getSpeciesParameters(const std::string& name,
168 AnyMap& speciesNode) const
169{
170 AnyMap eos;
171 providePDSS(speciesIndex(name))->getParameters(eos);
172 speciesNode["equation-of-state"].getMapWhere(
173 "model", eos.getString("model", ""), true) = std::move(eos);
174}
175
176bool VPStandardStateTP::addSpecies(shared_ptr<Species> spec)
177{
178 // Specifically skip ThermoPhase::addSpecies since the Species object
179 // doesn't have an associated SpeciesThermoInterpType object
180 bool added = Phase::addSpecies(spec);
181 if (!added) {
182 return false;
183 }
184
185 // VPStandardState does not use m_spthermo - install a dummy object
186 m_spthermo.install_STIT(m_kk-1, make_shared<SpeciesThermoInterpType>());
187 m_h0_RT.push_back(0.0);
188 m_cp0_R.push_back(0.0);
189 m_g0_RT.push_back(0.0);
190 m_s0_R.push_back(0.0);
191 m_V0.push_back(0.0);
192 m_hss_RT.push_back(0.0);
193 m_cpss_R.push_back(0.0);
194 m_gss_RT.push_back(0.0);
195 m_sss_R.push_back(0.0);
196 m_Vss.push_back(0.0);
197 return true;
198}
199
200void VPStandardStateTP::setTemperature(const doublereal temp)
201{
202 setState_TP(temp, m_Pcurrent);
204}
205
207{
210}
211
213{
214 throw NotImplementedError("VPStandardStateTP::calcDensity");
215}
216
217void VPStandardStateTP::setState_TP(doublereal t, doublereal pres)
218{
219 // A pretty tricky algorithm is needed here, due to problems involving
220 // standard states of real fluids. For those cases you need to combine the T
221 // and P specification for the standard state, or else you may venture into
222 // the forbidden zone, especially when nearing the triple point. Therefore,
223 // we need to do the standard state thermo calc with the (t, pres) combo.
225 m_Pcurrent = pres;
227
228 // Now, we still need to do the calculations for general ThermoPhase
229 // objects. So, we switch back to a virtual function call, setTemperature,
230 // and setPressure to recalculate stuff for child ThermoPhase objects of the
231 // VPStandardStateTP object. At this point, we haven't touched m_tlast or
232 // m_plast, so some calculations may still need to be done at the
233 // ThermoPhase object level.
234 calcDensity();
235}
236
237void VPStandardStateTP::installPDSS(size_t k, unique_ptr<PDSS>&& pdss)
238{
239 pdss->setParent(this, k);
240 pdss->setMolecularWeight(molecularWeight(k));
241 Species& spec = *species(k);
242 if (spec.thermo) {
243 pdss->setReferenceThermo(spec.thermo);
244 spec.thermo->validate(spec.name);
245 }
246 m_minTemp = std::max(m_minTemp, pdss->minTemp());
247 m_maxTemp = std::min(m_maxTemp, pdss->maxTemp());
248
249 if (m_PDSS_storage.size() < k+1) {
250 m_PDSS_storage.resize(k+1);
251 }
252 m_PDSS_storage[k].swap(pdss);
253}
254
255PDSS* VPStandardStateTP::providePDSS(size_t k)
256{
257 return m_PDSS_storage[k].get();
258}
259
260const PDSS* VPStandardStateTP::providePDSS(size_t k) const
261{
262 return m_PDSS_storage[k].get();
263}
264
266{
268 m_Tlast_ss += 0.0001234;
269}
270
272{
273 double Tnow = temperature();
274 for (size_t k = 0; k < m_kk; k++) {
275 PDSS* kPDSS = m_PDSS_storage[k].get();
276 kPDSS->setState_TP(Tnow, m_Pcurrent);
277 // reference state thermo
278 if (Tnow != m_tlast) {
279 m_h0_RT[k] = kPDSS->enthalpy_RT_ref();
280 m_s0_R[k] = kPDSS->entropy_R_ref();
281 m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
282 m_cp0_R[k] = kPDSS->cp_R_ref();
283 m_V0[k] = kPDSS->molarVolume_ref();
284 }
285 // standard state thermo
286 m_hss_RT[k] = kPDSS->enthalpy_RT();
287 m_sss_R[k] = kPDSS->entropy_R();
288 m_gss_RT[k] = m_hss_RT[k] - m_sss_R[k];
289 m_cpss_R[k] = kPDSS->cp_R();
290 m_Vss[k] = kPDSS->molarVolume();
291 }
293 m_Tlast_ss = Tnow;
294 m_tlast = Tnow;
295}
296
298{
299 double Tnow = temperature();
300 if (Tnow != m_Tlast_ss || Tnow != m_tlast || m_Pcurrent != m_Plast_ss) {
302 }
303}
304
305double VPStandardStateTP::minTemp(size_t k) const
306{
307 if (k == npos) {
308 return m_minTemp;
309 } else {
310 return m_PDSS_storage.at(k)->minTemp();
311 }
312}
313
314double VPStandardStateTP::maxTemp(size_t k) const
315{
316 if (k == npos) {
317 return m_maxTemp;
318 } else {
319 return m_PDSS_storage.at(k)->maxTemp();
320 }
321}
322
323}
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
Declaration for class Cantera::Species.
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
const std::string & getString(const std::string &key, const std::string &default_) const
If key exists, return it as a string, otherwise return default_.
Definition: AnyMap.cpp:1502
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
virtual void install_STIT(size_t index, shared_ptr< SpeciesThermoInterpType > stit)
Install a new species thermodynamic property parameterization for one species.
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:148
virtual void initThermo()
Initialization routine.
Definition: PDSS.h:415
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS.cpp:102
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
Definition: PDSS.cpp:47
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS.cpp:181
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition: PDSS.cpp:32
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS.cpp:67
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS.cpp:107
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS.cpp:72
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS.cpp:92
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS.cpp:97
virtual void getParameters(AnyMap &eosNode) const
Store the parameters needed to reconstruct a copy of this PDSS object.
Definition: PDSS.h:424
virtual bool addSpecies(shared_ptr< Species > spec)
Add a Species to this Phase.
Definition: Phase.cpp:803
std::string name() const
Return the name of the phase.
Definition: Phase.cpp:70
size_t m_kk
Number of species in the phase.
Definition: Phase.h:943
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:492
doublereal temperature() const
Temperature (K).
Definition: Phase.h:654
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:719
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition: Phase.cpp:187
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
Definition: Phase.cpp:950
Contains data about a single chemical species.
Definition: Species.h:26
std::string name
The name of the species.
Definition: Species.h:42
shared_ptr< SpeciesThermoInterpType > thermo
Thermodynamic data for the species.
Definition: Species.h:58
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:782
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1928
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:495
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 invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
vector_fp m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
vector_fp m_cp0_R
Vector containing the species reference constant pressure heat capacities at T = m_tlast and P = p_re...
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
doublereal m_Tlast_ss
The last temperature at which the standard state thermodynamic properties were calculated at.
virtual void _updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
vector_fp m_h0_RT
Vector containing the species reference enthalpies at T = m_tlast and P = p_ref.
doublereal m_Plast_ss
The last pressure at which the Standard State thermodynamic properties were calculated at.
virtual void setState_TP(doublereal T, doublereal pres)
Set the temperature and pressure at the same time.
vector_fp m_s0_R
Vector containing the species reference entropies at T = m_tlast and P = p_ref.
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
vector_fp m_Vss
Vector containing the species standard state volumes at T = m_tlast and P = m_plast.
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
void installPDSS(size_t k, std::unique_ptr< PDSS > &&pdss)
Install a PDSS object for species k
double m_maxTemp
The maximum temperature at which data for all species is valid.
virtual double minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid.
double m_minTemp
The minimum temperature at which data for all species is valid.
virtual int standardStateConvention() const
This method returns the convention used in specification of the standard state, of which there are cu...
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
vector_fp m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
vector_fp m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
virtual void setTemperature(const doublereal temp)
Set the temperature of the phase.
doublereal m_Pcurrent
Current value of the pressure - state variable.
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
virtual void getSpeciesParameters(const std::string &name, AnyMap &speciesNode) const
Get phase-specific parameters of a Species object such that an identical one could be reconstructed a...
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
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.
virtual double maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
virtual void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials.
vector_fp m_gss_RT
Vector containing the species Standard State Gibbs functions at T = m_tlast and P = m_plast.
vector_fp m_V0
Vector containing the species reference molar volumes.
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
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...
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
vector_fp m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
std::vector< std::unique_ptr< PDSS > > m_PDSS_storage
Storage for the PDSS objects for the species.
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.
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
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 int cSS_CONVENTION_VPSS
Standard state uses the molality convention.
Definition: ThermoPhase.h:39
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:81
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:100
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
const double BigNumber
largest number to compare to inf.
Definition: ct_defs.h:155
Various templated functions that carry out common vector operations (see Templated Utility Functions)...