Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Copyright (2005) Sandia Corporation. Under the terms of
10  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
11  * U.S. Government retains certain rights in this software.
12  */
13 
15 #include "cantera/thermo/PDSS.h"
16 
17 using namespace std;
18 
19 namespace Cantera
20 {
21 
22 /*
23  * Default constructor
24  */
25 VPStandardStateTP::VPStandardStateTP() :
26  m_Pcurrent(OneAtm),
27  m_Tlast_ss(-1.0),
28  m_Plast_ss(-1.0),
29  m_P0(OneAtm),
30  m_VPSS_ptr(0)
31 {
32 }
33 
35  m_Pcurrent(OneAtm),
36  m_Tlast_ss(-1.0),
37  m_Plast_ss(-1.0),
38  m_P0(OneAtm),
39  m_VPSS_ptr(0)
40 {
42 }
43 
46 {
47  if (&b != this) {
48  /*
49  * Mostly, this is a passthrough to the underlying
50  * assignment operator for the ThermoPhase parent object.
51  */
53  /*
54  * However, we have to handle data that we own.
55  */
59  m_P0 = b.m_P0;
60 
61  /*
62  * Duplicate the pdss objects
63  */
64  if (m_PDSS_storage.size() > 0) {
65  for (int k = 0; k < (int) m_PDSS_storage.size(); k++) {
66  delete m_PDSS_storage[k];
67  }
68  }
69  m_PDSS_storage.resize(m_kk);
70  for (size_t k = 0; k < m_kk; k++) {
71  m_PDSS_storage[k] = b.m_PDSS_storage[k]->duplMyselfAsPDSS();
72  }
73 
74  /*
75  * Duplicate the VPSS Manager object that conducts the calculations
76  */
77  delete m_VPSS_ptr;
78  m_VPSS_ptr = (b.m_VPSS_ptr)->duplMyselfAsVPSSMgr();
79 
80  /*
81  * The VPSSMgr object contains shallow pointers. Whenever you have shallow
82  * pointers, they have to be fixed up to point to the correct objects referring
83  * back to this ThermoPhase's properties.
84  */
86  /*
87  * The PDSS objects contains shallow pointers. Whenever you have shallow
88  * pointers, they have to be fixed up to point to the correct objects referring
89  * back to this ThermoPhase's properties. This function also sets m_VPSS_ptr
90  * so it occurs after m_VPSS_ptr is set.
91  */
92  for (size_t k = 0; k < m_kk; k++) {
93  m_PDSS_storage[k]->initAllPtrs(this, m_VPSS_ptr, m_spthermo);
94  }
95  /*
96  * Ok, the VPSSMgr object is ready for business.
97  * We need to resync the temperature and the pressure of the new standard states
98  * with what is stored in this object.
99  */
101  }
102  return *this;
103 }
104 
106 {
107  for (int k = 0; k < (int) m_PDSS_storage.size(); k++) {
108  delete m_PDSS_storage[k];
109  }
110  delete m_VPSS_ptr;
111 }
112 
114 {
115  return new VPStandardStateTP(*this);
116 }
117 
119 {
120  return cSS_CONVENTION_VPSS;
121 }
122 
123 void VPStandardStateTP::getChemPotentials_RT(doublereal* muRT) const
124 {
125  getChemPotentials(muRT);
126  doublereal invRT = 1.0 / _RT();
127  for (size_t k = 0; k < m_kk; k++) {
128  muRT[k] *= invRT;
129  }
130 }
131 
132 /*
133  * ----- Thermodynamic Values for the Species Standard States States ----
134  */
136 {
137  getGibbs_RT(g);
138  doublereal RT = _RT();
139  for (size_t k = 0; k < m_kk; k++) {
140  g[k] *= RT;
141  }
142 }
143 
144 inline
145 void VPStandardStateTP::getEnthalpy_RT(doublereal* hrt) const
146 {
149 }
150 
151 void VPStandardStateTP::modifyOneHf298SS(const size_t k, const doublereal Hf298New)
152 {
153  m_spthermo->modifyOneHf298(k, Hf298New);
154  m_Tlast_ss += 0.0001234;
155 }
156 
157 void VPStandardStateTP::getEntropy_R(doublereal* srt) const
158 {
160  m_VPSS_ptr->getEntropy_R(srt);
161 }
162 
163 inline
164 void VPStandardStateTP::getGibbs_RT(doublereal* grt) const
165 {
167  m_VPSS_ptr->getGibbs_RT(grt);
168 }
169 
170 inline
171 void VPStandardStateTP::getPureGibbs(doublereal* g) const
172 {
175 }
176 
177 void VPStandardStateTP::getIntEnergy_RT(doublereal* urt) const
178 {
181 }
182 
183 void VPStandardStateTP::getCp_R(doublereal* cpr) const
184 {
186  m_VPSS_ptr->getCp_R(cpr);
187 }
188 
189 void VPStandardStateTP::getStandardVolumes(doublereal* vol) const
190 {
193 }
194 const vector_fp& VPStandardStateTP::getStandardVolumes() const
195 {
197  return m_VPSS_ptr->getStandardVolumes();
198 }
199 
200 /*
201  * ----- Thermodynamic Values for the Species Reference States ----
202  */
203 
204 void VPStandardStateTP::getEnthalpy_RT_ref(doublereal* hrt) const
205 {
208 }
209 
210 void VPStandardStateTP::getGibbs_RT_ref(doublereal* grt) const
211 {
214 }
215 
216 void VPStandardStateTP::getGibbs_ref(doublereal* g) const
217 {
220 }
221 
222 const vector_fp& VPStandardStateTP::Gibbs_RT_ref() const
223 {
225  return m_VPSS_ptr->Gibbs_RT_ref();
226 }
227 
228 void VPStandardStateTP::getEntropy_R_ref(doublereal* er) const
229 {
232 }
233 
234 void VPStandardStateTP::getCp_R_ref(doublereal* cpr) const
235 {
237  m_VPSS_ptr->getCp_R_ref(cpr);
238 }
239 
240 void VPStandardStateTP::getStandardVolumes_ref(doublereal* vol) const
241 {
244 }
245 
247 {
250  for (size_t k = 0; k < m_kk; k++) {
251  PDSS* kPDSS = m_PDSS_storage[k];
252  if (kPDSS) {
253  kPDSS->initThermo();
254  }
255  }
256 }
257 
259 {
260  m_VPSS_ptr = vp_ptr;
261 }
262 
263 bool VPStandardStateTP::addSpecies(shared_ptr<Species> spec)
264 {
265  // Specifically skip ThermoPhase::addSpecies since the Species object
266  // doesn't have an associated SpeciesThermoInterpType object
267  return Phase::addSpecies(spec);
268 }
269 
270 void VPStandardStateTP::setTemperature(const doublereal temp)
271 {
272  setState_TP(temp, m_Pcurrent);
274 }
275 
277 {
278  setState_TP(temperature(), p);
280 }
281 
283 {
284  throw NotImplementedError("VPStandardStateTP::calcDensity() called, "
285  "but EOS for phase is not known");
286 }
287 
288 
289 void VPStandardStateTP::setState_TP(doublereal t, doublereal pres)
290 {
291  /*
292  * A pretty tricky algorithm is needed here, due to problems involving
293  * standard states of real fluids. For those cases you need
294  * to combine the T and P specification for the standard state, or else
295  * you may venture into the forbidden zone, especially when nearing the
296  * triple point.
297  * Therefore, we need to do the standard state thermo calc with the
298  * (t, pres) combo.
299  */
301  m_Pcurrent = pres;
303  /*
304  * Now, we still need to do the calculations for general ThermoPhase objects.
305  * So, we switch back to a virtual function call, setTemperature, and
306  * setPressure to recalculate stuff for child ThermoPhase objects of
307  * the VPStandardStateTP object. At this point,
308  * we haven't touched m_tlast or m_plast, so some calculations may still
309  * need to be done at the ThermoPhase object level.
310  */
311  //setTemperature(t);
312  //setPressure(pres);
313  calcDensity();
314 }
315 
316 
317 
318 void
319 VPStandardStateTP::createInstallPDSS(size_t k, const XML_Node& s,
320  const XML_Node* phaseNode_ptr)
321 {
322  if (m_PDSS_storage.size() < k+1) {
323  m_PDSS_storage.resize(k+1,0);
324  }
325  delete m_PDSS_storage[k];
326  m_PDSS_storage[k] = m_VPSS_ptr->createInstallPDSS(k, s, phaseNode_ptr);
327 }
328 
329 PDSS*
330 VPStandardStateTP::providePDSS(size_t k)
331 {
332  return m_PDSS_storage[k];
333 }
334 
335 const PDSS*
336 VPStandardStateTP::providePDSS(size_t k) const
337 {
338  return m_PDSS_storage[k];
339 }
340 
341 void VPStandardStateTP::initThermoXML(XML_Node& phaseNode, const std::string& id)
342 {
343  for (size_t k = 0; k < m_kk; k++) {
344  PDSS* kPDSS = m_PDSS_storage[k];
345  AssertTrace(kPDSS != 0);
346  if (kPDSS) {
347  kPDSS->initThermoXML(phaseNode, id);
348  }
349  }
350  m_VPSS_ptr->initThermoXML(phaseNode, id);
351  ThermoPhase::initThermoXML(phaseNode, id);
352 }
353 
354 
356 {
357  return m_VPSS_ptr;
358 }
359 
361 {
362  double Tnow = temperature();
364  m_Tlast_ss = Tnow;
365  AssertThrowMsg(m_VPSS_ptr != 0, "VPStandardStateTP::_updateStandardStateThermo()",
366  "Probably indicates that ThermoPhase object wasn't initialized correctly");
368 }
369 
371 {
372  double Tnow = temperature();
373  if (Tnow != m_Tlast_ss || m_Pcurrent != m_Plast_ss) {
375  }
376 }
377 }
doublereal m_Tlast_ss
The last temperature at which the standard statethermodynamic properties were calculated at...
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species at their standard states of solution at the cu...
const vector_fp & Gibbs_RT_ref() const
Return a reference to the vector of Gibbs free energies of the species.
Definition: VPSSMgr.h:404
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine.
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
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:213
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Definition: VPSSMgr.cpp:228
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:235
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the standard state at the current temperatu...
Definition: VPSSMgr.cpp:186
doublereal _RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:936
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
Definition: PDSS.cpp:165
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
ThermoPhase & operator=(const ThermoPhase &right)
Assignment operator.
Definition: ThermoPhase.cpp:60
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 setTemperature(const doublereal temp)
Set the temperature of the phase.
virtual PDSS * createInstallPDSS(size_t k, const XML_Node &speciesNode, const XML_Node *const phaseNode_ptr)
Install specific content for species k in the standard-state thermodynamic calculator and also create...
Definition: VPSSMgr.cpp:405
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the standard state of the species at ...
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Finalize the thermo after all species have been entered.
Definition: VPSSMgr.cpp:383
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
std::vector< PDSS * > m_PDSS_storage
Storage for the PDSS objects for the species.
virtual void getCp_R_ref(doublereal *cprt) const
virtual void initThermo()
Definition: VPSSMgr.cpp:350
VPSSMgr * m_VPSS_ptr
Pointer to the VPSS manager that calculates all of the standard state info efficiently.
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
#define AssertThrowMsg(expr, procedure, message)
Assertion must be true or an error is thrown.
Definition: ctexceptions.h:301
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity.
Definition: VPSSMgr.cpp:145
VPStandardStateTP & operator=(const VPStandardStateTP &b)
Assignment operator.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
virtual bool addSpecies(shared_ptr< Species > spec)
Add a Species to this Phase.
virtual void getCp_R_ref(doublereal *cpr) const
Definition: VPSSMgr.cpp:269
void setVPSSMgr(VPSSMgr *vp_ptr)
set the VPSS Mgr
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:173
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
virtual int standardStateConvention() const
This method returns the convention used in specification of the standard state, of which there are cu...
virtual ~VPStandardStateTP()
Destructor.
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 initAllPtrs(VPStandardStateTP *vp_ptr, SpeciesThermo *sp_ptr)
Initialize the internal shallow pointers in this object.
Definition: VPSSMgr.cpp:119
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input...
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: VPSSMgr.cpp:166
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:554
void getPureGibbs(doublereal *gpure) const
Get the standard state Gibbs functions for each species at the current T and P.
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: VPSSMgr.cpp:279
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Enthalpy functions for the standard state species at the current T an...
Definition: VPSSMgr.cpp:176
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species at their standard states of solution at the cu...
Definition: VPSSMgr.cpp:156
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:844
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the standard state at the current temperatu...
#define AssertTrace(expr)
Assertion must be true or an error is thrown.
Definition: ctexceptions.h:270
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Enthalpy functions for the standard state species at the current T an...
virtual void getGibbs_ref(doublereal *g) const
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:193
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:638
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 initThermoXML(XML_Node &phaseNode, const std::string &id)
Initialize a ThermoPhase object, potentially reading activity coefficient information from an XML dat...
const int cSS_CONVENTION_VPSS
Standard state uses the molality convention.
Definition: ThermoPhase.h:36
virtual void modifyOneHf298(const size_t k, const doublereal Hf298New)=0
Modify the value of the 298 K Heat of Formation of the standard state of one species in the phase (J ...
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of each species in their standard states at the current T and P of the solution...
Definition: VPSSMgr.cpp:209
void modifyOneHf298SS(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of the standard state of one species in the phase (J ...
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the standard state of the species at ...
Definition: VPSSMgr.cpp:199
size_t m_kk
Number of species in the phase.
Definition: Phase.h:843
virtual void getEntropy_R_ref(doublereal *er) const
Definition: VPSSMgr.cpp:259
doublereal m_Pcurrent
Current value of the pressure - state variable.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity.
virtual void setState_TP(doublereal T, doublereal P)
Set the temperature (K) and pressure (Pa)
Definition: VPSSMgr.cpp:304
virtual void getGibbs_RT_ref(doublereal *grt) const
Definition: VPSSMgr.cpp:238
VPSSMgr * provideVPSSMgr()
Return a pointer to the VPSSMgr for this phase.
SpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1607
virtual void getEntropy_R_ref(doublereal *er) const
virtual void getGibbs_ref(doublereal *g) const
Definition: VPSSMgr.cpp:248
void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials.
virtual void setState_TP(doublereal T, doublereal pres)
Set the temperature and pressure at the same time.
virtual void _updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.