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 }
Header for intermediate ThermoPhase object for phases which consist of ions whose thermodynamics is c...
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
Implementation of a pressure dependent standard state virtual function for a Pure Water Phase (see Sp...
Header for factory functions to build instances of classes that manage the standard-state thermodynam...
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
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:427
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 bool addSpecies(shared_ptr< Species > spec)
Add a Species to this Phase.
Definition: Phase.cpp:833
size_t m_kk
Number of species in the phase.
Definition: Phase.h:942
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:521
doublereal temperature() const
Temperature (K).
Definition: Phase.h:667
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:724
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
Definition: Phase.cpp:980
Contains data about a single chemical species.
Definition: Species.h:25
std::string name
The name of the species.
Definition: Species.h:39
shared_ptr< SpeciesThermoInterpType > thermo
Thermodynamic data for the species.
Definition: Species.h:55
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:776
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1904
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:489
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:1870
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)
Add a Species to this Phase.
Definition: Phase.cpp:833
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 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.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:188
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:78
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
const double BigNumber
largest number to compare to inf.
Definition: ct_defs.h:151
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
const int cSS_CONVENTION_VPSS
Standard state uses the molality convention.
Definition: ThermoPhase.h:38
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:135
Various templated functions that carry out common vector operations (see Templated Utility Functions)...