Cantera  2.1.2
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/VPSSMgr.h"
16 #include "cantera/thermo/PDSS.h"
18 
19 using namespace std;
20 
21 namespace Cantera
22 {
23 
24 /*
25  * Default constructor
26  */
27 VPStandardStateTP::VPStandardStateTP() :
28  ThermoPhase(),
29  m_Pcurrent(OneAtm),
30  m_Tlast_ss(-1.0),
31  m_Plast_ss(-1.0),
32  m_P0(OneAtm),
33  m_VPSS_ptr(0)
34 {
35 }
36 
38  ThermoPhase(),
39  m_Pcurrent(OneAtm),
40  m_Tlast_ss(-1.0),
41  m_Plast_ss(-1.0),
42  m_P0(OneAtm),
43  m_VPSS_ptr(0)
44 {
46 }
47 
50 {
51  if (&b != this) {
52  /*
53  * Mostly, this is a passthrough to the underlying
54  * assignment operator for the ThermoPhase parent object.
55  */
57  /*
58  * However, we have to handle data that we own.
59  */
63  m_P0 = b.m_P0;
64 
65  /*
66  * Duplicate the pdss objects
67  */
68  if (m_PDSS_storage.size() > 0) {
69  for (int k = 0; k < (int) m_PDSS_storage.size(); k++) {
70  delete m_PDSS_storage[k];
71  }
72  }
73  m_PDSS_storage.resize(m_kk);
74  for (size_t k = 0; k < m_kk; k++) {
75  PDSS* ptmp = b.m_PDSS_storage[k];
76  m_PDSS_storage[k] = ptmp->duplMyselfAsPDSS();
77  }
78 
79  /*
80  * Duplicate the VPSS Manager object that conducts the calculations
81  */
82  if (m_VPSS_ptr) {
83  delete m_VPSS_ptr;
84  m_VPSS_ptr = 0;
85  }
86  m_VPSS_ptr = (b.m_VPSS_ptr)->duplMyselfAsVPSSMgr();
87 
88  /*
89  * The VPSSMgr object contains shallow pointers. Whenever you have shallow
90  * pointers, they have to be fixed up to point to the correct objects referring
91  * back to this ThermoPhase's properties.
92  */
94  /*
95  * The PDSS objects contains shallow pointers. Whenever you have shallow
96  * pointers, they have to be fixed up to point to the correct objects referring
97  * back to this ThermoPhase's properties. This function also sets m_VPSS_ptr
98  * so it occurs after m_VPSS_ptr is set.
99  */
100  for (size_t k = 0; k < m_kk; k++) {
101  PDSS* ptmp = m_PDSS_storage[k];
102  ptmp->initAllPtrs(this, m_VPSS_ptr, m_spthermo);
103  }
104  /*
105  * Ok, the VPSSMgr object is ready for business.
106  * We need to resync the temperature and the pressure of the new standard states
107  * with what is stored in this object.
108  */
110  }
111  return *this;
112 }
113 //====================================================================================================================
115 {
116  for (int k = 0; k < (int) m_PDSS_storage.size(); k++) {
117  delete m_PDSS_storage[k];
118  }
119  delete m_VPSS_ptr;
120 }
121 
123 {
124  return new VPStandardStateTP(*this);
125 }
126 
128 {
129  return cSS_CONVENTION_VPSS;
130 }
131 
132 doublereal VPStandardStateTP::err(const std::string& msg) const
133 {
134  throw CanteraError("VPStandardStateTP","Base class method "
135  +msg+" called. Equation of state type: "+int2str(eosType()));
136  return 0;
137 }
138 
139 void VPStandardStateTP::getChemPotentials_RT(doublereal* muRT) const
140 {
141  getChemPotentials(muRT);
142  doublereal invRT = 1.0 / _RT();
143  for (size_t k = 0; k < m_kk; k++) {
144  muRT[k] *= invRT;
145  }
146 }
147 
148 /*
149  * ----- Thermodynamic Values for the Species Standard States States ----
150  */
152 {
153  getGibbs_RT(g);
154  doublereal RT = _RT();
155  for (size_t k = 0; k < m_kk; k++) {
156  g[k] *= RT;
157  }
158 }
159 
160 inline
161 void VPStandardStateTP::getEnthalpy_RT(doublereal* hrt) const
162 {
165 }
166 
167 //================================================================================================
168 #ifdef H298MODIFY_CAPABILITY
169 void VPStandardStateTP::modifyOneHf298SS(const size_t& k, const doublereal Hf298New)
170 {
171  m_spthermo->modifyOneHf298(k, Hf298New);
172  m_Tlast_ss += 0.0001234;
173 }
174 #endif
175 //================================================================================================
176 void VPStandardStateTP::getEntropy_R(doublereal* srt) const
177 {
179  m_VPSS_ptr->getEntropy_R(srt);
180 }
181 
182 inline
183 void VPStandardStateTP::getGibbs_RT(doublereal* grt) const
184 {
186  m_VPSS_ptr->getGibbs_RT(grt);
187 }
188 
189 inline
190 void VPStandardStateTP::getPureGibbs(doublereal* g) const
191 {
194 }
195 
196 void VPStandardStateTP::getIntEnergy_RT(doublereal* urt) const
197 {
200 }
201 
202 void VPStandardStateTP::getCp_R(doublereal* cpr) const
203 {
205  m_VPSS_ptr->getCp_R(cpr);
206 }
207 
208 void VPStandardStateTP::getStandardVolumes(doublereal* vol) const
209 {
212 }
213 const vector_fp& VPStandardStateTP::getStandardVolumes() const
214 {
216  return m_VPSS_ptr->getStandardVolumes();
217 }
218 
219 /*
220  * ----- Thermodynamic Values for the Species Reference States ----
221  */
222 
223 void VPStandardStateTP::getEnthalpy_RT_ref(doublereal* hrt) const
224 {
227 }
228 
229 void VPStandardStateTP::getGibbs_RT_ref(doublereal* grt) const
230 {
233 }
234 
235 void VPStandardStateTP::getGibbs_ref(doublereal* g) const
236 {
239 }
240 
241 const vector_fp& VPStandardStateTP::Gibbs_RT_ref() const
242 {
244  return m_VPSS_ptr->Gibbs_RT_ref();
245 }
246 
247 void VPStandardStateTP::getEntropy_R_ref(doublereal* er) const
248 {
251 }
252 
253 void VPStandardStateTP::getCp_R_ref(doublereal* cpr) const
254 {
256  m_VPSS_ptr->getCp_R_ref(cpr);
257 }
258 
259 void VPStandardStateTP::getStandardVolumes_ref(doublereal* vol) const
260 {
263 }
264 
266 {
267  initLengths();
270  for (size_t k = 0; k < m_kk; k++) {
271  PDSS* kPDSS = m_PDSS_storage[k];
272  if (kPDSS) {
273  kPDSS->initThermo();
274  }
275  }
276 }
277 
279 {
280  m_VPSS_ptr = vp_ptr;
281 }
282 
283 /*
284  * Initialize the internal lengths.
285  * (this is not a virtual function)
286  */
288 {
289  m_kk = nSpecies();
290 
291 }
292 
293 
294 void VPStandardStateTP::setTemperature(const doublereal temp)
295 {
296  setState_TP(temp, m_Pcurrent);
298 }
299 
301 {
302  setState_TP(temperature(), p);
304 }
305 
307 {
308  err("VPStandardStateTP::calcDensity() called, but EOS for phase is not known");
309 }
310 
311 
312 void VPStandardStateTP::setState_TP(doublereal t, doublereal pres)
313 {
314  /*
315  * A pretty tricky algorithm is needed here, due to problems involving
316  * standard states of real fluids. For those cases you need
317  * to combine the T and P specification for the standard state, or else
318  * you may venture into the forbidden zone, especially when nearing the
319  * triple point.
320  * Therefore, we need to do the standard state thermo calc with the
321  * (t, pres) combo.
322  */
324  m_Pcurrent = pres;
326  /*
327  * Now, we still need to do the calculations for general ThermoPhase objects.
328  * So, we switch back to a virtual function call, setTemperature, and
329  * setPressure to recalculate stuff for child ThermoPhase objects of
330  * the VPStandardStateTP object. At this point,
331  * we haven't touched m_tlast or m_plast, so some calculations may still
332  * need to be done at the ThermoPhase object level.
333  */
334  //setTemperature(t);
335  //setPressure(pres);
336  calcDensity();
337 }
338 
339 
340 
341 void
342 VPStandardStateTP::createInstallPDSS(size_t k, const XML_Node& s,
343  const XML_Node* phaseNode_ptr)
344 {
345  if (m_PDSS_storage.size() < k+1) {
346  m_PDSS_storage.resize(k+1,0);
347  }
348  delete m_PDSS_storage[k];
349  m_PDSS_storage[k] = m_VPSS_ptr->createInstallPDSS(k, s, phaseNode_ptr);
350 }
351 
352 PDSS*
353 VPStandardStateTP::providePDSS(size_t k)
354 {
355  return m_PDSS_storage[k];
356 }
357 
358 const PDSS*
359 VPStandardStateTP::providePDSS(size_t k) const
360 {
361  return m_PDSS_storage[k];
362 }
363 
364 void VPStandardStateTP::initThermoXML(XML_Node& phaseNode, const std::string& id)
365 {
366  // initialize the lengths in the current object and then call the parent
367  // routine.
369 
370  //m_VPSS_ptr->initThermo();
371  for (size_t k = 0; k < m_kk; k++) {
372  PDSS* kPDSS = m_PDSS_storage[k];
373  AssertTrace(kPDSS != 0);
374  if (kPDSS) {
375  kPDSS->initThermoXML(phaseNode, id);
376  }
377  }
378  m_VPSS_ptr->initThermoXML(phaseNode, id);
379  ThermoPhase::initThermoXML(phaseNode, id);
380 }
381 
382 
384 {
385  return m_VPSS_ptr;
386 }
387 
389 {
390  double Tnow = temperature();
392  m_Tlast_ss = Tnow;
393  AssertThrowMsg(m_VPSS_ptr != 0, "VPStandardStateTP::_updateStandardStateThermo()",
394  "Probably indicates that ThermoPhase object wasn't initialized correctly");
396 }
397 
399 {
400  double Tnow = temperature();
401  if (Tnow != m_Tlast_ss || m_Pcurrent != m_Plast_ss) {
403  }
404 }
405 }
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...
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:40
const vector_fp & Gibbs_RT_ref() const
Return a reference to the vector of Gibbs free energies of the species.
Definition: VPSSMgr.h:409
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:71
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Definition: VPSSMgr.cpp:237
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:238
Declaration file for a virtual base class that manages the calculation of standard state properties f...
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:193
doublereal _RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:977
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
Definition: PDSS.cpp:175
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
ThermoPhase & operator=(const ThermoPhase &right)
Assignment operator.
Definition: ThermoPhase.cpp:57
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:451
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:393
virtual void modifyOneHf298SS(const int k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1) ...
Definition: ThermoPhase.h:227
virtual int eosType() const
Equation of state type flag.
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 initAllPtrs(VPStandardStateTP *vptp_ptr, VPSSMgr *vpssmgr_ptr, SpeciesThermo *spthermo_ptr)
Initialize or Reinitialize all shallow pointers in the object.
Definition: PDSS.cpp:192
virtual void getCp_R_ref(doublereal *cprt) const
virtual void initThermo()
Definition: VPSSMgr.cpp:360
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:247
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity.
Definition: VPSSMgr.cpp:151
VPStandardStateTP & operator=(const VPStandardStateTP &b)
Assignment operator.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
virtual PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
Definition: PDSS.cpp:165
virtual void getCp_R_ref(doublereal *cpr) const
Definition: VPSSMgr.cpp:279
void setVPSSMgr(VPSSMgr *vp_ptr)
set the VPSS Mgr
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:183
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
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:125
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:173
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:595
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:289
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:183
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
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:163
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:252
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:216
doublereal temperature() const
Temperature (K).
Definition: Phase.h:528
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:165
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:195
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:562
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
Contains declarations for string manipulation functions within Cantera.
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:217
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:207
size_t m_kk
Number of species in the phase.
Definition: Phase.h:716
virtual void getEntropy_R_ref(doublereal *er) const
Definition: VPSSMgr.cpp:269
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:314
virtual void getGibbs_RT_ref(doublereal *grt) const
Definition: VPSSMgr.cpp:247
doublereal err(const std::string &msg) const
VPStandardStateTP has its own err routine.
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:1625
virtual void getEntropy_R_ref(doublereal *er) const
virtual void getGibbs_ref(doublereal *g) const
Definition: VPSSMgr.cpp:257
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.