Cantera  2.3.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"
14 
15 using namespace std;
16 
17 namespace Cantera
18 {
19 
20 VPStandardStateTP::VPStandardStateTP() :
21  m_Pcurrent(OneAtm),
22  m_Tlast_ss(-1.0),
23  m_Plast_ss(-1.0),
24  m_P0(OneAtm)
25 {
26 }
27 
29  m_Pcurrent(OneAtm),
30  m_Tlast_ss(-1.0),
31  m_Plast_ss(-1.0),
32  m_P0(OneAtm)
33 {
34  VPStandardStateTP::operator=(b);
35 }
36 
37 VPStandardStateTP& VPStandardStateTP::operator=(const VPStandardStateTP& b)
38 {
39  if (&b != this) {
40  // Mostly, this is a passthrough to the underlying assignment operator
41  // for the ThermoPhase parent object.
43 
44  // However, we have to handle data that we own.
45  m_Pcurrent = b.m_Pcurrent;
46  m_Tlast_ss = b.m_Tlast_ss;
47  m_Plast_ss = b.m_Plast_ss;
48  m_P0 = b.m_P0;
49 
50  m_PDSS_storage.resize(m_kk);
51  for (size_t k = 0; k < m_kk; k++) {
52  m_PDSS_storage[k].reset(b.m_PDSS_storage[k]->duplMyselfAsPDSS());
53  }
54 
55  // Duplicate the VPSS Manager object that conducts the calculations
56  m_VPSS_ptr.reset(b.m_VPSS_ptr->duplMyselfAsVPSSMgr());
57 
58  // The VPSSMgr object contains shallow pointers. Whenever you have
59  // shallow pointers, they have to be fixed up to point to the correct
60  // objects referring back to this ThermoPhase's properties.
61  m_VPSS_ptr->initAllPtrs(this, m_spthermo);
62 
63  // The PDSS objects contains shallow pointers. Whenever you have shallow
64  // pointers, they have to be fixed up to point to the correct objects
65  // referring back to this ThermoPhase's properties. This function also
66  // sets m_VPSS_ptr so it occurs after m_VPSS_ptr is set.
67  for (size_t k = 0; k < m_kk; k++) {
68  m_PDSS_storage[k]->initAllPtrs(this, m_VPSS_ptr.get(), m_spthermo);
69  }
70 
71  // Ok, the VPSSMgr object is ready for business. We need to resync the
72  // temperature and the pressure of the new standard states with what is
73  // stored in this object.
74  m_VPSS_ptr->setState_TP(m_Tlast_ss, m_Plast_ss);
75  }
76  return *this;
77 }
78 
80 {
81  return new VPStandardStateTP(*this);
82 }
83 
85 {
86  return cSS_CONVENTION_VPSS;
87 }
88 
89 void VPStandardStateTP::getChemPotentials_RT(doublereal* muRT) const
90 {
91  getChemPotentials(muRT);
92  for (size_t k = 0; k < m_kk; k++) {
93  muRT[k] *= 1.0 / RT();
94  }
95 }
96 
97 // ----- Thermodynamic Values for the Species Standard States States ----
98 
100 {
101  getGibbs_RT(g);
102  for (size_t k = 0; k < m_kk; k++) {
103  g[k] *= RT();
104  }
105 }
106 
107 void VPStandardStateTP::getEnthalpy_RT(doublereal* hrt) const
108 {
110  m_VPSS_ptr->getEnthalpy_RT(hrt);
111 }
112 
113 void VPStandardStateTP::getEntropy_R(doublereal* srt) const
114 {
116  m_VPSS_ptr->getEntropy_R(srt);
117 }
118 
119 void VPStandardStateTP::getGibbs_RT(doublereal* grt) const
120 {
122  m_VPSS_ptr->getGibbs_RT(grt);
123 }
124 
125 void VPStandardStateTP::getPureGibbs(doublereal* g) const
126 {
128  m_VPSS_ptr->getStandardChemPotentials(g);
129 }
130 
131 void VPStandardStateTP::getIntEnergy_RT(doublereal* urt) const
132 {
134  m_VPSS_ptr->getIntEnergy_RT(urt);
135 }
136 
137 void VPStandardStateTP::getCp_R(doublereal* cpr) const
138 {
140  m_VPSS_ptr->getCp_R(cpr);
141 }
142 
143 void VPStandardStateTP::getStandardVolumes(doublereal* vol) const
144 {
146  m_VPSS_ptr->getStandardVolumes(vol);
147 }
148 const vector_fp& VPStandardStateTP::getStandardVolumes() const
149 {
151  return m_VPSS_ptr->getStandardVolumes();
152 }
153 
154 // ----- Thermodynamic Values for the Species Reference States ----
155 
156 void VPStandardStateTP::getEnthalpy_RT_ref(doublereal* hrt) const
157 {
159  m_VPSS_ptr->getEnthalpy_RT_ref(hrt);
160 }
161 
162 void VPStandardStateTP::getGibbs_RT_ref(doublereal* grt) const
163 {
165  m_VPSS_ptr->getGibbs_RT_ref(grt);
166 }
167 
168 void VPStandardStateTP::getGibbs_ref(doublereal* g) const
169 {
171  m_VPSS_ptr->getGibbs_ref(g);
172 }
173 
174 const vector_fp& VPStandardStateTP::Gibbs_RT_ref() const
175 {
177  return m_VPSS_ptr->Gibbs_RT_ref();
178 }
179 
180 void VPStandardStateTP::getEntropy_R_ref(doublereal* er) const
181 {
183  m_VPSS_ptr->getEntropy_R_ref(er);
184 }
185 
186 void VPStandardStateTP::getCp_R_ref(doublereal* cpr) const
187 {
189  m_VPSS_ptr->getCp_R_ref(cpr);
190 }
191 
192 void VPStandardStateTP::getStandardVolumes_ref(doublereal* vol) const
193 {
195  m_VPSS_ptr->getStandardVolumes_ref(vol);
196 }
197 
199 {
201  m_VPSS_ptr->initThermo();
202  for (size_t k = 0; k < m_kk; k++) {
203  PDSS* kPDSS = m_PDSS_storage[k].get();
204  if (kPDSS) {
205  kPDSS->initThermo();
206  }
207  }
208 }
209 
211 {
212  m_VPSS_ptr.reset(vp_ptr);
213 }
214 
215 bool VPStandardStateTP::addSpecies(shared_ptr<Species> spec)
216 {
217  // Specifically skip ThermoPhase::addSpecies since the Species object
218  // doesn't have an associated SpeciesThermoInterpType object
219  return Phase::addSpecies(spec);
220 }
221 
222 void VPStandardStateTP::setTemperature(const doublereal temp)
223 {
224  setState_TP(temp, m_Pcurrent);
226 }
227 
229 {
230  setState_TP(temperature(), p);
232 }
233 
235 {
236  throw NotImplementedError("VPStandardStateTP::calcDensity() called, "
237  "but EOS for phase is not known");
238 }
239 
240 void VPStandardStateTP::setState_TP(doublereal t, doublereal pres)
241 {
242  // A pretty tricky algorithm is needed here, due to problems involving
243  // standard states of real fluids. For those cases you need to combine the T
244  // and P specification for the standard state, or else you may venture into
245  // the forbidden zone, especially when nearing the triple point. Therefore,
246  // we need to do the standard state thermo calc with the (t, pres) combo.
248  m_Pcurrent = pres;
250 
251  // Now, we still need to do the calculations for general ThermoPhase
252  // objects. So, we switch back to a virtual function call, setTemperature,
253  // and setPressure to recalculate stuff for child ThermoPhase objects of the
254  // VPStandardStateTP object. At this point, we haven't touched m_tlast or
255  // m_plast, so some calculations may still need to be done at the
256  // ThermoPhase object level.
257  calcDensity();
258 }
259 
260 void VPStandardStateTP::createInstallPDSS(size_t k, const XML_Node& s,
261  const XML_Node* phaseNode_ptr)
262 {
263  if (m_PDSS_storage.size() < k+1) {
264  m_PDSS_storage.resize(k+1);
265  }
266  m_PDSS_storage[k].reset(m_VPSS_ptr->createInstallPDSS(k, s, phaseNode_ptr));
267 }
268 
269 PDSS* VPStandardStateTP::providePDSS(size_t k)
270 {
271  return m_PDSS_storage[k].get();
272 }
273 
274 const PDSS* VPStandardStateTP::providePDSS(size_t k) const
275 {
276  return m_PDSS_storage[k].get();
277 }
278 
280 {
282  m_Tlast_ss += 0.0001234;
283 }
284 
285 void VPStandardStateTP::initThermoXML(XML_Node& phaseNode, const std::string& id)
286 {
287  for (size_t k = 0; k < m_kk; k++) {
288  PDSS* kPDSS = m_PDSS_storage[k].get();
289  AssertTrace(kPDSS != 0);
290  if (kPDSS) {
291  kPDSS->initThermoXML(phaseNode, id);
292  }
293  }
294  m_VPSS_ptr->initThermoXML(phaseNode, id);
295  ThermoPhase::initThermoXML(phaseNode, id);
296 }
297 
299 {
300  return m_VPSS_ptr.get();
301 }
302 
304 {
305  double Tnow = temperature();
307  m_Tlast_ss = Tnow;
308  AssertThrowMsg(m_VPSS_ptr != 0, "VPStandardStateTP::_updateStandardStateThermo()",
309  "Probably indicates that ThermoPhase object wasn't initialized correctly");
310  m_VPSS_ptr->setState_TP(Tnow, m_Pcurrent);
311 }
312 
314 {
315  double Tnow = temperature();
316  if (Tnow != m_Tlast_ss || m_Pcurrent != m_Plast_ss) {
318  }
319 }
320 }
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...
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 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:193
virtual void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials.
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:228
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
Definition: PDSS.cpp:167
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
ThermoPhase & operator=(const ThermoPhase &right)
Definition: ThermoPhase.cpp:59
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:494
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.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
STL namespace.
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:809
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
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 void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
void setVPSSMgr(VPSSMgr *vp_ptr)
set the VPSS Mgr
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:175
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
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...
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 void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual bool addSpecies(shared_ptr< Species > spec)
Add a Species to this Phase.
Definition: Phase.cpp:761
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 ...
MultiSpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1693
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...
std::unique_ptr< VPSSMgr > m_VPSS_ptr
Pointer to the VPSS manager that calculates all of the standard state info efficiently.
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
#define AssertTrace(expr)
Assertion must be true or an error is thrown.
Definition: ctexceptions.h:239
#define AssertThrowMsg(expr, procedure,...)
Assertion must be true or an error is thrown.
Definition: ctexceptions.h:270
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
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:176
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:637
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
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:784
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
doublereal m_Pcurrent
Current value of the pressure - state variable.
Namespace for the Cantera kernel.
Definition: application.cpp:29
VPSSMgr * provideVPSSMgr()
Return a pointer to the VPSSMgr for this phase.
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...