Cantera  4.0.0a1
Loading...
Searching...
No Matches
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#include "cantera/base/global.h"
17
18namespace Cantera
19{
20
22{
23 // Defined in .cpp to limit dependence on PDSS.h via vector<unique_ptr<PDSS>>
24}
25
26VPStandardStateTP::~VPStandardStateTP()
27{
28 // Defined in .cpp to limit dependence on PDSS.h
29}
30
32{
34}
35
36// ----- Thermodynamic Values for the Species Standard States States ----
37
39{
40 getGibbs_RT(g);
41 for (size_t k = 0; k < m_kk; k++) {
42 g[k] *= RT();
43 }
44}
45
46void VPStandardStateTP::getEnthalpy_RT(span<double> hrt) const
47{
48 checkArraySize("VPStandardStateTP::getEnthalpy_RT", hrt.size(), m_kk);
50 std::copy(m_hss_RT.begin(), m_hss_RT.end(), hrt.begin());
51}
52
53void VPStandardStateTP::getEntropy_R(span<double> sr) const
54{
55 checkArraySize("VPStandardStateTP::getEntropy_R", sr.size(), m_kk);
57 std::copy(m_sss_R.begin(), m_sss_R.end(), sr.begin());
58}
59
60void VPStandardStateTP::getGibbs_RT(span<double> grt) const
61{
62 checkArraySize("VPStandardStateTP::getGibbs_RT", grt.size(), m_kk);
64 std::copy(m_gss_RT.begin(), m_gss_RT.end(), grt.begin());
65}
66
67void VPStandardStateTP::getIntEnergy_RT(span<double> urt) const
68{
69 checkArraySize("VPStandardStateTP::getIntEnergy_RT", urt.size(), m_kk);
71 std::copy(m_hss_RT.begin(), m_hss_RT.end(), urt.begin());
72 for (size_t k = 0; k < m_kk; k++) {
73 urt[k] -= m_Plast_ss / RT() * m_Vss[k];
74 }
75}
76
77void VPStandardStateTP::getCp_R(span<double> cpr) const
78{
79 checkArraySize("VPStandardStateTP::getCp_R", cpr.size(), m_kk);
81 std::copy(m_cpss_R.begin(), m_cpss_R.end(), cpr.begin());
82}
83
84void VPStandardStateTP::getStandardVolumes(span<double> vol) const
85{
86 checkArraySize("VPStandardStateTP::getStandardVolumes", vol.size(), m_kk);
88 std::copy(m_Vss.begin(), m_Vss.end(), vol.begin());
89}
90span<const double> VPStandardStateTP::getStandardVolumes() const
91{
93 return m_Vss;
94}
95
96// ----- Thermodynamic Values for the Species Reference States ----
97
98void VPStandardStateTP::getEnthalpy_RT_ref(span<double> hrt) const
99{
100 checkArraySize("VPStandardStateTP::getEnthalpy_RT_ref", hrt.size(), m_kk);
102 std::copy(m_h0_RT.begin(), m_h0_RT.end(), hrt.begin());
103}
104
105void VPStandardStateTP::getGibbs_RT_ref(span<double> grt) const
106{
107 checkArraySize("VPStandardStateTP::getGibbs_RT_ref", grt.size(), m_kk);
109 std::copy(m_g0_RT.begin(), m_g0_RT.end(), grt.begin());
110}
111
112void VPStandardStateTP::getGibbs_ref(span<double> g) const
113{
114 checkArraySize("VPStandardStateTP::getGibbs_ref", g.size(), m_kk);
116 std::copy(m_g0_RT.begin(), m_g0_RT.end(), g.begin());
117 scale(g.begin(), g.end(), g.begin(), RT());
118}
119
120void VPStandardStateTP::getEntropy_R_ref(span<double> sr) const
121{
122 checkArraySize("VPStandardStateTP::getEntropy_R_ref", sr.size(), m_kk);
124 std::copy(m_s0_R.begin(), m_s0_R.end(), sr.begin());
125}
126
127void VPStandardStateTP::getCp_R_ref(span<double> cpr) const
128{
129 checkArraySize("VPStandardStateTP::getCp_R_ref", cpr.size(), m_kk);
131 std::copy(m_cp0_R.begin(), m_cp0_R.end(), cpr.begin());
132}
133
135{
136 checkArraySize("VPStandardStateTP::getStandardVolumes_ref", vol.size(), m_kk);
138 std::copy(m_Vss.begin(), m_Vss.end(), vol.begin());
139}
140
142{
144 for (size_t k = 0; k < m_kk; k++) {
145 PDSS* kPDSS = m_PDSS_storage[k].get();
146 if (kPDSS == 0) {
147 throw CanteraError("VPStandardStateTP::initThermo",
148 "No PDSS object for species {}", k);
149 }
150 kPDSS->initThermo();
151 }
152}
153
155 AnyMap& speciesNode) const
156{
157 AnyMap eos;
158 providePDSS(speciesIndex(name, true))->getParameters(eos);
159 speciesNode["equation-of-state"].getMapWhere(
160 "model", eos.getString("model", ""), true) = std::move(eos);
161}
162
163bool VPStandardStateTP::addSpecies(shared_ptr<Species> spec)
164{
165 // Specifically skip ThermoPhase::addSpecies since the Species object
166 // doesn't have an associated SpeciesThermoInterpType object
167 bool added = Phase::addSpecies(spec);
168 if (!added) {
169 return false;
170 }
171
172 // VPStandardState does not use m_spthermo - install a dummy object
173 m_spthermo.install_STIT(m_kk-1, make_shared<SpeciesThermoInterpType>());
174 m_h0_RT.push_back(0.0);
175 m_cp0_R.push_back(0.0);
176 m_g0_RT.push_back(0.0);
177 m_s0_R.push_back(0.0);
178 m_V0.push_back(0.0);
179 m_hss_RT.push_back(0.0);
180 m_cpss_R.push_back(0.0);
181 m_gss_RT.push_back(0.0);
182 m_sss_R.push_back(0.0);
183 m_Vss.push_back(0.0);
184 return true;
185}
186
188{
189 setState_TP(temp, m_Pcurrent);
191}
192
194{
197}
198
200{
202 double dd = meanMolecularWeight() / mean_X(m_workS);
204}
205
206void VPStandardStateTP::setState_TP(double t, double pres)
207{
208 if (pres < 0) {
209 throw CanteraError("VPStandardStateTP::setState_TP",
210 "Pressure must be positive. Specified state was T = {}, P = {}.", t, pres);
211 }
212 // A pretty tricky algorithm is needed here, due to problems involving
213 // standard states of real fluids. For those cases you need to combine the T
214 // and P specification for the standard state, or else you may venture into
215 // the forbidden zone, especially when nearing the triple point. Therefore,
216 // we need to do the standard state thermo calc with the (t, pres) combo.
218 m_Pcurrent = pres;
220
221 // Now, we still need to do the calculations for general ThermoPhase
222 // objects. So, we switch back to a virtual function call, setTemperature,
223 // and setPressure to recalculate stuff for child ThermoPhase objects of the
224 // VPStandardStateTP object. At this point, we haven't touched m_tlast or
225 // m_plast, so some calculations may still need to be done at the
226 // ThermoPhase object level.
227 calcDensity();
228}
229
230void VPStandardStateTP::installPDSS(size_t k, unique_ptr<PDSS>&& pdss)
231{
232 pdss->setParent(this, k);
233 pdss->setMolecularWeight(molecularWeight(k));
234 Species& spec = *species(k);
235 if (spec.thermo) {
236 pdss->setReferenceThermo(spec.thermo);
237 spec.thermo->validate(spec.name);
238 }
239 m_minTemp = std::max(m_minTemp, pdss->minTemp());
240 m_maxTemp = std::min(m_maxTemp, pdss->maxTemp());
241
242 if (m_PDSS_storage.size() < k+1) {
243 m_PDSS_storage.resize(k+1);
244 }
245 m_PDSS_storage[k].swap(pdss);
246}
247
248PDSS* VPStandardStateTP::providePDSS(size_t k)
249{
250 return m_PDSS_storage[k].get();
251}
252
253const PDSS* VPStandardStateTP::providePDSS(size_t k) const
254{
255 return m_PDSS_storage[k].get();
256}
257
259{
261 m_Tlast_ss += 0.0001234;
262}
263
265{
266 double Tnow = temperature();
267 for (size_t k = 0; k < m_kk; k++) {
268 PDSS* kPDSS = m_PDSS_storage[k].get();
269 kPDSS->setState_TP(Tnow, m_Pcurrent);
270 // reference state thermo
271 if (Tnow != m_tlast) {
272 m_h0_RT[k] = kPDSS->enthalpy_RT_ref();
273 m_s0_R[k] = kPDSS->entropy_R_ref();
274 m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
275 m_cp0_R[k] = kPDSS->cp_R_ref();
276 m_V0[k] = kPDSS->molarVolume_ref();
277 }
278 // standard state thermo
279 m_hss_RT[k] = kPDSS->enthalpy_RT();
280 m_sss_R[k] = kPDSS->entropy_R();
281 m_gss_RT[k] = m_hss_RT[k] - m_sss_R[k];
282 m_cpss_R[k] = kPDSS->cp_R();
283 m_Vss[k] = kPDSS->molarVolume();
284 }
286 m_Tlast_ss = Tnow;
287 m_tlast = Tnow;
288}
289
291{
292 double Tnow = temperature();
293 if (Tnow != m_Tlast_ss || Tnow != m_tlast || m_Pcurrent != m_Plast_ss) {
295 }
296}
297
298double VPStandardStateTP::minTemp(size_t k) const
299{
300 if (k == npos) {
301 return m_minTemp;
302 } else {
303 return m_PDSS_storage.at(k)->minTemp();
304 }
305}
306
307double VPStandardStateTP::maxTemp(size_t k) const
308{
309 if (k == npos) {
310 return m_maxTemp;
311 } else {
312 return m_PDSS_storage.at(k)->maxTemp();
313 }
314}
315
316}
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:431
const string & getString(const string &key, const string &default_) const
If key exists, return it as a string, otherwise return default_.
Definition AnyMap.cpp:1590
Base class for exceptions thrown by Cantera classes.
virtual void install_STIT(size_t index, shared_ptr< SpeciesThermoInterpType > stit)
Install a new species thermodynamic property parameterization for one species.
Virtual base class for a species with a pressure dependent standard state.
Definition PDSS.h:140
virtual void initThermo()
Initialization routine.
Definition PDSS.h:383
virtual double cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition PDSS.cpp:93
virtual double entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition PDSS.cpp:88
virtual double molarVolume_ref() const
Return the molar volume at reference pressure.
Definition PDSS.cpp:98
virtual double enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition PDSS.cpp:23
virtual double enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition PDSS.cpp:83
virtual double entropy_R() const
Return the standard state entropy divided by RT.
Definition PDSS.cpp:38
virtual double cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition PDSS.cpp:58
virtual double molarVolume() const
Return the molar volume at standard state.
Definition PDSS.cpp:63
virtual void getParameters(AnyMap &eosNode) const
Store the parameters needed to reconstruct a copy of this PDSS object.
Definition PDSS.h:392
virtual void setState_TP(double temp, double pres)
Set the internal temperature and pressure.
Definition PDSS.cpp:152
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition Phase.cpp:608
virtual bool addSpecies(shared_ptr< Species > spec)
Add a Species to this Phase.
Definition Phase.cpp:708
vector< double > m_workS
Vector of size m_kk, used as a temporary holding area.
Definition Phase.h:899
size_t m_kk
Number of species in the phase.
Definition Phase.h:875
size_t speciesIndex(const string &name, bool raise=true) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:127
double temperature() const
Temperature (K).
Definition Phase.h:585
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:676
double mean_X(span< const double > Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition Phase.cpp:627
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition Phase.h:646
double molecularWeight(size_t k) const
Molecular weight of species k.
Definition Phase.cpp:388
shared_ptr< Species > species(const string &name) const
Return the Species object for the named species.
Definition Phase.cpp:881
string name() const
Return the name of the phase.
Definition Phase.cpp:20
Contains data about a single chemical species.
Definition Species.h:25
string name
The name of the species.
Definition Species.h:41
shared_ptr< SpeciesThermoInterpType > thermo
Thermodynamic data for the species.
Definition Species.h:80
virtual void getPartialMolarVolumes(span< double > vbar) const
Return an array of partial molar volumes for the species in the mixture.
double RT() const
Return the Gas Constant multiplied by the current temperature.
double m_tlast
last value of the temperature processed by reference state
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
void invalidateCache() override
Invalidate any cached values which are normally updated only when a change in state is detected.
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
void getGibbs_ref(span< double > g) const override
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
double m_Plast_ss
The last pressure at which the Standard State thermodynamic properties were calculated at.
void getCp_R(span< double > cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
int standardStateConvention() const override
This method returns the convention used in specification of the standard state, of which there are cu...
void getEntropy_R_ref(span< double > er) const override
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
vector< double > m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
void getIntEnergy_RT(span< double > urt) const override
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
vector< double > m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
void installPDSS(size_t k, unique_ptr< PDSS > &&pdss)
Install a PDSS object for species k
void getSpeciesParameters(const string &name, AnyMap &speciesNode) const override
Get phase-specific parameters of a Species object such that an identical one could be reconstructed a...
vector< double > m_h0_RT
Vector containing the species reference enthalpies at T = m_tlast and P = p_ref.
virtual void _updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
void getStandardChemPotentials(span< double > mu) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void getGibbs_RT(span< double > grt) const override
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
void getCp_R_ref(span< double > cprt) const override
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
void setPressure(double p) override
Set the internally stored pressure (Pa) at constant temperature and composition.
vector< unique_ptr< PDSS > > m_PDSS_storage
Storage for the PDSS objects for the species.
vector< double > m_gss_RT
Vector containing the species Standard State Gibbs functions at T = m_tlast and P = m_plast.
void getEnthalpy_RT_ref(span< double > hrt) const override
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
double m_Tlast_ss
The last temperature at which the standard state thermodynamic properties were calculated at.
void getEnthalpy_RT(span< double > hrt) const override
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
void getEntropy_R(span< double > sr) const override
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
vector< double > m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
double m_maxTemp
The maximum temperature at which data for all species is valid.
void setTemperature(const double temp) override
Set the temperature of the phase.
double minTemp(size_t k=npos) const override
Minimum temperature for which the thermodynamic data for the species or phase are valid.
vector< double > m_s0_R
Vector containing the species reference entropies at T = m_tlast and P = p_ref.
vector< double > m_Vss
Vector containing the species standard state volumes at T = m_tlast and P = m_plast.
double m_minTemp
The minimum temperature at which data for all species is valid.
vector< double > m_V0
Vector containing the species reference molar volumes.
void invalidateCache() override
Invalidate any cached values which are normally updated only when a change in state is detected.
void getGibbs_RT_ref(span< double > grt) const override
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
void setState_TP(double T, double pres) override
Set the temperature and pressure at the same time.
vector< double > m_cp0_R
Vector containing the species reference constant pressure heat capacities at T = m_tlast and P = p_re...
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
vector< double > m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
void getStandardVolumes_ref(span< double > vol) const override
Get the molar volumes of the species reference states at the current T and P_ref of the solution.
double maxTemp(size_t k=npos) const override
Maximum temperature for which the thermodynamic data for the species are valid.
double m_Pcurrent
Current value of the pressure - state variable.
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition utilities.h:118
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:183
const int cSS_CONVENTION_VPSS
Standard state uses the molality convention.
void checkArraySize(const char *procedure, size_t available, size_t required)
Wrapper for throwing ArraySizeError.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...