Cantera  2.4.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 http://www.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_Tlast_ss(-1.0),
29  m_Plast_ss(-1.0)
30 {
31 }
32 
34 {
35  return cSS_CONVENTION_VPSS;
36 }
37 
38 void VPStandardStateTP::getChemPotentials_RT(doublereal* muRT) const
39 {
40  getChemPotentials(muRT);
41  for (size_t k = 0; k < m_kk; k++) {
42  muRT[k] *= 1.0 / RT();
43  }
44 }
45 
46 // ----- Thermodynamic Values for the Species Standard States States ----
47 
49 {
50  getGibbs_RT(g);
51  for (size_t k = 0; k < m_kk; k++) {
52  g[k] *= RT();
53  }
54 }
55 
56 void VPStandardStateTP::getEnthalpy_RT(doublereal* hrt) const
57 {
59  std::copy(m_hss_RT.begin(), m_hss_RT.end(), hrt);
60 }
61 
62 void VPStandardStateTP::getEntropy_R(doublereal* sr) const
63 {
65  std::copy(m_sss_R.begin(), m_sss_R.end(), sr);
66 }
67 
68 void VPStandardStateTP::getGibbs_RT(doublereal* grt) const
69 {
71  std::copy(m_gss_RT.begin(), m_gss_RT.end(), grt);
72 }
73 
74 void VPStandardStateTP::getPureGibbs(doublereal* g) const
75 {
77  std::copy(m_gss_RT.begin(), m_gss_RT.end(), g);
78  scale(g, g+m_kk, g, RT());
79 }
80 
81 void VPStandardStateTP::getIntEnergy_RT(doublereal* urt) const
82 {
84  std::copy(m_hss_RT.begin(), m_hss_RT.end(), urt);
85  for (size_t k = 0; k < m_kk; k++) {
86  urt[k] -= m_Plast_ss / RT() * m_Vss[k];
87  }
88 }
89 
90 void VPStandardStateTP::getCp_R(doublereal* cpr) const
91 {
93  std::copy(m_cpss_R.begin(), m_cpss_R.end(), cpr);
94 }
95 
96 void VPStandardStateTP::getStandardVolumes(doublereal* vol) const
97 {
99  std::copy(m_Vss.begin(), m_Vss.end(), vol);
100 }
101 const vector_fp& VPStandardStateTP::getStandardVolumes() const
102 {
104  return m_Vss;
105 }
106 
107 // ----- Thermodynamic Values for the Species Reference States ----
108 
109 void VPStandardStateTP::getEnthalpy_RT_ref(doublereal* hrt) const
110 {
112  std::copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
113 }
114 
115 void VPStandardStateTP::getGibbs_RT_ref(doublereal* grt) const
116 {
118  std::copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
119 }
120 
121 void VPStandardStateTP::getGibbs_ref(doublereal* g) const
122 {
124  std::copy(m_g0_RT.begin(), m_g0_RT.end(), g);
125  scale(g, g+m_kk, g, RT());
126 }
127 
128 const vector_fp& VPStandardStateTP::Gibbs_RT_ref() const
129 {
131  return m_g0_RT;
132 }
133 
134 void VPStandardStateTP::getEntropy_R_ref(doublereal* sr) const
135 {
137  std::copy(m_s0_R.begin(), m_s0_R.end(), sr);
138 }
139 
140 void VPStandardStateTP::getCp_R_ref(doublereal* cpr) const
141 {
143  std::copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
144 }
145 
146 void VPStandardStateTP::getStandardVolumes_ref(doublereal* vol) const
147 {
149  std::copy(m_Vss.begin(), m_Vss.end(), vol);
150 }
151 
153 {
155  for (size_t k = 0; k < m_kk; k++) {
156  PDSS* kPDSS = m_PDSS_storage[k].get();
157  if (kPDSS == 0) {
158  throw CanteraError("VPStandardStateTP::initThermo",
159  "No PDSS object for species {}", k);
160  }
161  kPDSS->initThermo();
162  }
163 }
164 
165 bool VPStandardStateTP::addSpecies(shared_ptr<Species> spec)
166 {
167  // Specifically skip ThermoPhase::addSpecies since the Species object
168  // doesn't have an associated SpeciesThermoInterpType object
169  bool added = Phase::addSpecies(spec);
170  if (!added) {
171  return false;
172  }
173  m_h0_RT.push_back(0.0);
174  m_cp0_R.push_back(0.0);
175  m_g0_RT.push_back(0.0);
176  m_s0_R.push_back(0.0);
177  m_V0.push_back(0.0);
178  m_hss_RT.push_back(0.0);
179  m_cpss_R.push_back(0.0);
180  m_gss_RT.push_back(0.0);
181  m_sss_R.push_back(0.0);
182  m_Vss.push_back(0.0);
183  return true;
184 }
185 
186 void VPStandardStateTP::setTemperature(const doublereal temp)
187 {
188  setState_TP(temp, m_Pcurrent);
190 }
191 
193 {
194  setState_TP(temperature(), p);
196 }
197 
199 {
200  throw NotImplementedError("VPStandardStateTP::calcDensity() called, "
201  "but EOS for phase is not known");
202 }
203 
204 void VPStandardStateTP::setState_TP(doublereal t, doublereal pres)
205 {
206  // A pretty tricky algorithm is needed here, due to problems involving
207  // standard states of real fluids. For those cases you need to combine the T
208  // and P specification for the standard state, or else you may venture into
209  // the forbidden zone, especially when nearing the triple point. Therefore,
210  // we need to do the standard state thermo calc with the (t, pres) combo.
212  m_Pcurrent = pres;
214 
215  // Now, we still need to do the calculations for general ThermoPhase
216  // objects. So, we switch back to a virtual function call, setTemperature,
217  // and setPressure to recalculate stuff for child ThermoPhase objects of the
218  // VPStandardStateTP object. At this point, we haven't touched m_tlast or
219  // m_plast, so some calculations may still need to be done at the
220  // ThermoPhase object level.
221  calcDensity();
222 }
223 
224 void VPStandardStateTP::installPDSS(size_t k, unique_ptr<PDSS>&& pdss)
225 {
226  pdss->setParent(this, k);
227  pdss->setMolecularWeight(molecularWeight(k));
228  if (pdss->useSTITbyPDSS()) {
229  m_spthermo.install_STIT(k, make_shared<STITbyPDSS>(pdss.get()));
230  } else {
231  auto stit = species(k)->thermo;
232  stit->validate(speciesName(k));
233  pdss->setReferenceThermo(stit);
234  m_spthermo.install_STIT(k, stit);
235  }
236 
237  if (m_PDSS_storage.size() < k+1) {
238  m_PDSS_storage.resize(k+1);
239  }
240  m_PDSS_storage[k].swap(pdss);
241 }
242 
243 PDSS* VPStandardStateTP::providePDSS(size_t k)
244 {
245  return m_PDSS_storage[k].get();
246 }
247 
248 const PDSS* VPStandardStateTP::providePDSS(size_t k) const
249 {
250  return m_PDSS_storage[k].get();
251 }
252 
254 {
256  m_Tlast_ss += 0.0001234;
257 }
258 
260 {
261  double Tnow = temperature();
262  for (size_t k = 0; k < m_kk; k++) {
263  PDSS* kPDSS = m_PDSS_storage[k].get();
264  kPDSS->setState_TP(Tnow, m_Pcurrent);
265  // reference state thermo
266  if (Tnow != m_tlast) {
267  m_h0_RT[k] = kPDSS->enthalpy_RT_ref();
268  m_s0_R[k] = kPDSS->entropy_R_ref();
269  m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
270  m_cp0_R[k] = kPDSS->cp_R_ref();
271  m_V0[k] = kPDSS->molarVolume_ref();
272  }
273  // standard state thermo
274  m_hss_RT[k] = kPDSS->enthalpy_RT();
275  m_sss_R[k] = kPDSS->entropy_R();
276  m_gss_RT[k] = m_hss_RT[k] - m_sss_R[k];
277  m_cpss_R[k] = kPDSS->cp_R();
278  m_Vss[k] = kPDSS->molarVolume();
279  }
281  m_Tlast_ss = Tnow;
282  m_tlast = Tnow;
283 }
284 
286 {
287  double Tnow = temperature();
288  if (Tnow != m_Tlast_ss || Tnow != m_tlast || m_Pcurrent != m_Plast_ss) {
290  }
291 }
292 }
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
doublereal m_Tlast_ss
The last temperature at which the standard statethermodynamic properties were calculated at...
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1607
vector_fp m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
doublereal m_Plast_ss
The last pressure at which the Standard State thermodynamic properties were calculated at...
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
virtual void initThermo()
Initialization routine.
Definition: PDSS.h:452
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...
doublereal temperature() const
Temperature (K).
Definition: Phase.h:601
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
virtual void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
Header for intermediate ThermoPhase object for phases which consist of ions whose thermodynamics is c...
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS.cpp:97
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
Definition: PDSS.cpp:47
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:461
virtual void setTemperature(const doublereal temp)
Set the temperature of the phase.
std::vector< std::unique_ptr< PDSS > > m_PDSS_storage
Storage for the PDSS objects for the species.
Implementation of a pressure dependent standard state virtual function for a Pure Water Phase (see Sp...
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_cp0_R
Vector containing the species reference constant pressure heat capacities at T = m_tlast and P = p_re...
STL namespace.
vector_fp m_Vss
Vector containing the species standard state volumes at T = m_tlast and P = m_plast.
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS.cpp:67
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1643
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:748
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS.cpp:107
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected...
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected...
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS.cpp:72
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS.cpp:102
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
Definition: Phase.cpp:803
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input...
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...
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:191
virtual void _updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
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 doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition: PDSS.cpp:32
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
void installPDSS(size_t k, std::unique_ptr< PDSS > &&pdss)
Install a PDSS object for species k
vector_fp m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
virtual bool addSpecies(shared_ptr< Species > spec)
Add a Species to this Phase.
Definition: Phase.cpp:697
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
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 getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
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 getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
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 ...
vector_fp m_gss_RT
Vector containing the species Standard State Gibbs functions at T = m_tlast and P = m_plast...
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:157
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:165
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:637
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:130
vector_fp m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
vector_fp m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
vector_fp m_h0_RT
Vector containing the species reference enthalpies at T = m_tlast and P = p_ref.
const int cSS_CONVENTION_VPSS
Standard state uses the molality convention.
Definition: ThermoPhase.h:38
size_t m_kk
Number of species in the phase.
Definition: Phase.h:788
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 doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS.cpp:92
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:420
doublereal m_Pcurrent
Current value of the pressure - state variable.
virtual void install_STIT(size_t index, shared_ptr< SpeciesThermoInterpType > stit)
Install a new species thermodynamic property parameterization for one species.
vector_fp m_s0_R
Vector containing the species reference entropies at T = m_tlast and P = p_ref.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
vector_fp m_V0
Vector containing the species reference molar volumes.
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS.cpp:181
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
virtual void setState_TP(doublereal T, doublereal pres)
Set the temperature and pressure at the same time.
virtual int standardStateConvention() const
This method returns the convention used in specification of the standard state, of which there are cu...