Cantera  2.5.1
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"
18 #include "cantera/base/utilities.h"
19 #include "cantera/base/ctml.h"
20 
21 using namespace std;
22 
23 namespace Cantera
24 {
25 
26 VPStandardStateTP::VPStandardStateTP() :
27  m_Pcurrent(OneAtm),
28  m_minTemp(0.0),
29  m_maxTemp(BigNumber),
30  m_Tlast_ss(-1.0),
31  m_Plast_ss(-1.0)
32 {
33 }
34 
36 {
37  return cSS_CONVENTION_VPSS;
38 }
39 
40 void VPStandardStateTP::getChemPotentials_RT(doublereal* muRT) const
41 {
42  getChemPotentials(muRT);
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 
58 void VPStandardStateTP::getEnthalpy_RT(doublereal* hrt) const
59 {
61  std::copy(m_hss_RT.begin(), m_hss_RT.end(), hrt);
62 }
63 
64 void VPStandardStateTP::getEntropy_R(doublereal* sr) const
65 {
67  std::copy(m_sss_R.begin(), m_sss_R.end(), sr);
68 }
69 
70 void VPStandardStateTP::getGibbs_RT(doublereal* grt) const
71 {
73  std::copy(m_gss_RT.begin(), m_gss_RT.end(), grt);
74 }
75 
76 void 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 
83 void 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 
92 void VPStandardStateTP::getCp_R(doublereal* cpr) const
93 {
95  std::copy(m_cpss_R.begin(), m_cpss_R.end(), cpr);
96 }
97 
98 void VPStandardStateTP::getStandardVolumes(doublereal* vol) const
99 {
101  std::copy(m_Vss.begin(), m_Vss.end(), vol);
102 }
103 const vector_fp& VPStandardStateTP::getStandardVolumes() const
104 {
106  return m_Vss;
107 }
108 
109 // ----- Thermodynamic Values for the Species Reference States ----
110 
111 void VPStandardStateTP::getEnthalpy_RT_ref(doublereal* hrt) const
112 {
114  std::copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
115 }
116 
117 void VPStandardStateTP::getGibbs_RT_ref(doublereal* grt) const
118 {
120  std::copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
121 }
122 
123 void 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 
130 const vector_fp& VPStandardStateTP::Gibbs_RT_ref() const
131 {
133  return m_g0_RT;
134 }
135 
136 void VPStandardStateTP::getEntropy_R_ref(doublereal* sr) const
137 {
139  std::copy(m_s0_R.begin(), m_s0_R.end(), sr);
140 }
141 
142 void VPStandardStateTP::getCp_R_ref(doublereal* cpr) const
143 {
145  std::copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
146 }
147 
148 void VPStandardStateTP::getStandardVolumes_ref(doublereal* vol) const
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 
167 bool VPStandardStateTP::addSpecies(shared_ptr<Species> spec)
168 {
169  // Specifically skip ThermoPhase::addSpecies since the Species object
170  // doesn't have an associated SpeciesThermoInterpType object
171  bool added = Phase::addSpecies(spec);
172  if (!added) {
173  return false;
174  }
175 
176  // VPStandardState does not use m_spthermo - install a dummy object
177  m_spthermo.install_STIT(m_kk-1, make_shared<SpeciesThermoInterpType>());
178  m_h0_RT.push_back(0.0);
179  m_cp0_R.push_back(0.0);
180  m_g0_RT.push_back(0.0);
181  m_s0_R.push_back(0.0);
182  m_V0.push_back(0.0);
183  m_hss_RT.push_back(0.0);
184  m_cpss_R.push_back(0.0);
185  m_gss_RT.push_back(0.0);
186  m_sss_R.push_back(0.0);
187  m_Vss.push_back(0.0);
188  return true;
189 }
190 
191 void VPStandardStateTP::setTemperature(const doublereal temp)
192 {
193  setState_TP(temp, m_Pcurrent);
195 }
196 
198 {
199  setState_TP(temperature(), p);
201 }
202 
204 {
205  throw NotImplementedError("VPStandardStateTP::calcDensity");
206 }
207 
208 void VPStandardStateTP::setState_TP(doublereal t, doublereal pres)
209 {
210  // A pretty tricky algorithm is needed here, due to problems involving
211  // standard states of real fluids. For those cases you need to combine the T
212  // and P specification for the standard state, or else you may venture into
213  // the forbidden zone, especially when nearing the triple point. Therefore,
214  // we need to do the standard state thermo calc with the (t, pres) combo.
216  m_Pcurrent = pres;
218 
219  // Now, we still need to do the calculations for general ThermoPhase
220  // objects. So, we switch back to a virtual function call, setTemperature,
221  // and setPressure to recalculate stuff for child ThermoPhase objects of the
222  // VPStandardStateTP object. At this point, we haven't touched m_tlast or
223  // m_plast, so some calculations may still need to be done at the
224  // ThermoPhase object level.
225  calcDensity();
226 }
227 
228 void VPStandardStateTP::installPDSS(size_t k, unique_ptr<PDSS>&& pdss)
229 {
230  pdss->setParent(this, k);
231  pdss->setMolecularWeight(molecularWeight(k));
232  Species& spec = *species(k);
233  if (spec.thermo) {
234  pdss->setReferenceThermo(spec.thermo);
235  spec.thermo->validate(spec.name);
236  }
237  m_minTemp = std::max(m_minTemp, pdss->minTemp());
238  m_maxTemp = std::min(m_maxTemp, pdss->maxTemp());
239 
240  if (m_PDSS_storage.size() < k+1) {
241  m_PDSS_storage.resize(k+1);
242  }
243  m_PDSS_storage[k].swap(pdss);
244 }
245 
246 PDSS* VPStandardStateTP::providePDSS(size_t k)
247 {
248  return m_PDSS_storage[k].get();
249 }
250 
251 const PDSS* VPStandardStateTP::providePDSS(size_t k) const
252 {
253  return m_PDSS_storage[k].get();
254 }
255 
257 {
259  m_Tlast_ss += 0.0001234;
260 }
261 
263 {
264  double Tnow = temperature();
265  for (size_t k = 0; k < m_kk; k++) {
266  PDSS* kPDSS = m_PDSS_storage[k].get();
267  kPDSS->setState_TP(Tnow, m_Pcurrent);
268  // reference state thermo
269  if (Tnow != m_tlast) {
270  m_h0_RT[k] = kPDSS->enthalpy_RT_ref();
271  m_s0_R[k] = kPDSS->entropy_R_ref();
272  m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
273  m_cp0_R[k] = kPDSS->cp_R_ref();
274  m_V0[k] = kPDSS->molarVolume_ref();
275  }
276  // standard state thermo
277  m_hss_RT[k] = kPDSS->enthalpy_RT();
278  m_sss_R[k] = kPDSS->entropy_R();
279  m_gss_RT[k] = m_hss_RT[k] - m_sss_R[k];
280  m_cpss_R[k] = kPDSS->cp_R();
281  m_Vss[k] = kPDSS->molarVolume();
282  }
284  m_Tlast_ss = Tnow;
285  m_tlast = Tnow;
286 }
287 
289 {
290  double Tnow = temperature();
291  if (Tnow != m_Tlast_ss || Tnow != m_tlast || m_Pcurrent != m_Plast_ss) {
293  }
294 }
295 
296 double VPStandardStateTP::minTemp(size_t k) const
297 {
298  if (k == npos) {
299  return m_minTemp;
300  } else {
301  return m_PDSS_storage.at(k)->minTemp();
302  }
303 }
304 
305 double VPStandardStateTP::maxTemp(size_t k) const
306 {
307  if (k == npos) {
308  return m_maxTemp;
309  } else {
310  return m_PDSS_storage.at(k)->maxTemp();
311  }
312 }
313 
314 }
Cantera::VPStandardStateTP::m_Pcurrent
doublereal m_Pcurrent
Current value of the pressure - state variable.
Definition: VPStandardStateTP.h:269
Cantera::VPStandardStateTP::m_Vss
vector_fp m_Vss
Vector containing the species standard state volumes at T = m_tlast and P = m_plast.
Definition: VPStandardStateTP.h:329
Cantera::VPStandardStateTP::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: VPStandardStateTP.cpp:167
Cantera::VPStandardStateTP::getEnthalpy_RT_ref
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Definition: VPStandardStateTP.cpp:111
Cantera::VPStandardStateTP::setState_TP
virtual void setState_TP(doublereal T, doublereal pres)
Set the temperature and pressure at the same time.
Definition: VPStandardStateTP.cpp:208
IonsFromNeutralVPSSTP.h
Cantera::VPStandardStateTP::m_g0_RT
vector_fp m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
Definition: VPStandardStateTP.h:302
Cantera::PDSS::entropy_R_ref
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS.cpp:97
Cantera::PDSS::cp_R_ref
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS.cpp:102
Cantera::VPStandardStateTP::m_minTemp
double m_minTemp
The minimum temperature at which data for all species is valid.
Definition: VPStandardStateTP.h:272
Cantera::VPStandardStateTP::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: VPStandardStateTP.cpp:123
Cantera::VPStandardStateTP::m_hss_RT
vector_fp m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
Definition: VPStandardStateTP.h:313
Cantera::VPStandardStateTP::m_s0_R
vector_fp m_s0_R
Vector containing the species reference entropies at T = m_tlast and P = p_ref.
Definition: VPStandardStateTP.h:306
Cantera::VPStandardStateTP::getChemPotentials_RT
virtual void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials.
Definition: VPStandardStateTP.cpp:40
Cantera::PDSS::cp_R
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS.cpp:67
Cantera::VPStandardStateTP::minTemp
virtual double minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid.
Definition: VPStandardStateTP.cpp:296
Cantera::VPStandardStateTP::setPressure
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition: VPStandardStateTP.cpp:197
Cantera::Phase::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Add a Species to this Phase.
Definition: Phase.cpp:833
Cantera::NotImplementedError
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:186
Cantera::BigNumber
const double BigNumber
largest number to compare to inf.
Definition: ct_defs.h:151
Cantera::Phase::setTemperature
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:724
Cantera::VPStandardStateTP::m_Plast_ss
doublereal m_Plast_ss
The last pressure at which the Standard State thermodynamic properties were calculated at.
Definition: VPStandardStateTP.h:283
Cantera::VPStandardStateTP::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: VPStandardStateTP.cpp:64
Cantera::VPStandardStateTP::standardStateConvention
virtual int standardStateConvention() const
This method returns the convention used in specification of the standard state, of which there are cu...
Definition: VPStandardStateTP.cpp:35
Cantera::PDSS::entropy_R
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
Definition: PDSS.cpp:47
Cantera::PDSS::molarVolume_ref
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS.cpp:107
Cantera::PDSS::setState_TP
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS.cpp:181
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:180
Cantera::VPStandardStateTP::m_sss_R
vector_fp m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
Definition: VPStandardStateTP.h:325
Cantera::VPStandardStateTP::invalidateCache
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
Definition: VPStandardStateTP.cpp:256
Cantera::VPStandardStateTP::m_cpss_R
vector_fp m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
Definition: VPStandardStateTP.h:317
Cantera::VPStandardStateTP::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: VPStandardStateTP.cpp:92
PDSS_Water.h
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition: Phase.h:942
Cantera::Phase::molecularWeight
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:521
SpeciesThermoFactory.h
Cantera::VPStandardStateTP::m_h0_RT
vector_fp m_h0_RT
Vector containing the species reference enthalpies at T = m_tlast and P = p_ref.
Definition: VPStandardStateTP.h:294
Cantera::VPStandardStateTP::installPDSS
void installPDSS(size_t k, std::unique_ptr< PDSS > &&pdss)
Install a PDSS object for species k
Definition: VPStandardStateTP.cpp:228
Cantera::VPStandardStateTP::m_gss_RT
vector_fp m_gss_RT
Vector containing the species Standard State Gibbs functions at T = m_tlast and P = m_plast.
Definition: VPStandardStateTP.h:321
Cantera::VPStandardStateTP::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: VPStandardStateTP.cpp:148
Cantera::VPStandardStateTP::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: VPStandardStateTP.cpp:142
Cantera::VPStandardStateTP::setTemperature
virtual void setTemperature(const doublereal temp)
Set the temperature of the phase.
Definition: VPStandardStateTP.cpp:191
Cantera::VPStandardStateTP::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: VPStandardStateTP.cpp:136
Cantera::VPStandardStateTP::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: VPStandardStateTP.cpp:70
Cantera::PDSS::molarVolume
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS.cpp:72
Cantera::ThermoPhase::m_tlast
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1904
Cantera::OneAtm
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:78
Cantera::VPStandardStateTP::m_cp0_R
vector_fp m_cp0_R
Vector containing the species reference constant pressure heat capacities at T = m_tlast and P = p_re...
Definition: VPStandardStateTP.h:298
Cantera::VPStandardStateTP::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: VPStandardStateTP.cpp:117
Cantera::ThermoPhase::RT
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:776
Cantera::VPStandardStateTP::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: VPStandardStateTP.cpp:58
utilities.h
Cantera::Species::name
std::string name
The name of the species.
Definition: Species.h:39
ctml.h
Cantera::ThermoPhase::invalidateCache
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
Definition: ThermoPhase.cpp:1221
Cantera::Phase::temperature
doublereal temperature() const
Temperature (K).
Definition: Phase.h:667
Cantera::VPStandardStateTP::maxTemp
virtual double maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
Definition: VPStandardStateTP.cpp:305
Cantera::VPStandardStateTP::initThermo
virtual void initThermo()
Definition: VPStandardStateTP.cpp:154
PDSSFactory.h
Cantera::PDSS::enthalpy_RT_ref
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS.cpp:92
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:135
Cantera::ThermoPhase::m_spthermo
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1870
Cantera::VPStandardStateTP::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: VPStandardStateTP.cpp:83
Cantera::PDSS::initThermo
virtual void initThermo()
Initialization routine.
Definition: PDSS.h:427
Cantera::cSS_CONVENTION_VPSS
const int cSS_CONVENTION_VPSS
Standard state uses the molality convention.
Definition: ThermoPhase.h:38
Cantera::VPStandardStateTP::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: VPStandardStateTP.cpp:76
Cantera::VPStandardStateTP::m_Tlast_ss
doublereal m_Tlast_ss
The last temperature at which the standard state thermodynamic properties were calculated at.
Definition: VPStandardStateTP.h:279
Cantera::Species::thermo
shared_ptr< SpeciesThermoInterpType > thermo
Thermodynamic data for the species.
Definition: Species.h:55
VPStandardStateTP.h
PDSS.h
Cantera::ThermoPhase::getChemPotentials
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:489
Cantera::Species
Contains data about a single chemical species.
Definition: Species.h:24
Cantera::VPStandardStateTP::calcDensity
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
Definition: VPStandardStateTP.cpp:203
Cantera::VPStandardStateTP::m_PDSS_storage
std::vector< std::unique_ptr< PDSS > > m_PDSS_storage
Storage for the PDSS objects for the species.
Definition: VPStandardStateTP.h:290
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:60
Cantera::VPStandardStateTP::m_V0
vector_fp m_V0
Vector containing the species reference molar volumes.
Definition: VPStandardStateTP.h:309
Cantera::VPStandardStateTP::updateStandardStateThermo
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
Definition: VPStandardStateTP.cpp:288
Cantera::VPStandardStateTP::_updateStandardStateThermo
virtual void _updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
Definition: VPStandardStateTP.cpp:262
Cantera::VPStandardStateTP::m_maxTemp
double m_maxTemp
The maximum temperature at which data for all species is valid.
Definition: VPStandardStateTP.h:275
Cantera::npos
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:188
Cantera::ThermoPhase::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: ThermoPhase.cpp:1096
Cantera::PDSS
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:147
Cantera::Phase::species
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
Definition: Phase.cpp:980
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:263
Cantera::VPStandardStateTP::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: VPStandardStateTP.cpp:50
Cantera::MultiSpeciesThermo::install_STIT
virtual void install_STIT(size_t index, shared_ptr< SpeciesThermoInterpType > stit)
Install a new species thermodynamic property parameterization for one species.
Definition: MultiSpeciesThermo.cpp:26
Cantera::PDSS::enthalpy_RT
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition: PDSS.cpp:32