Cantera  2.1.2
VPSSMgr_Water_HKFT.cpp
Go to the documentation of this file.
1 /**
2  * @file VPSSMgr_Water_HKFT.cpp
3  * Definition file for a derived class that handles the calculation
4  * of standard state thermo properties for pure water and
5  * a set of species which obey the HKFT standard state
6  * dependence
7  * (see \ref thermoprops and class
8  * \link Cantera::VPSSMgr_Water_HKFT VPSSMgr_Water_HKFT\endlink).
9  */
10 
11 /*
12  * Copyright (2005) Sandia Corporation. Under the terms of
13  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
14  * U.S. Government retains certain rights in this software.
15  */
16 
21 
22 using namespace std;
23 
24 namespace Cantera
25 {
26 
27 VPSSMgr_Water_HKFT::VPSSMgr_Water_HKFT(VPStandardStateTP* vp_ptr,
28  SpeciesThermo* spth) :
29  VPSSMgr(vp_ptr, spth),
30  m_waterSS(0),
31  m_tlastRef(-1.0)
32 {
35 }
36 
38  VPSSMgr(right.m_vptp_ptr, right.m_spthermo),
39  m_waterSS(0),
40  m_tlastRef(-1.0)
41 {
44  *this = right;
45 }
46 
47 
50 {
51  if (&b == this) {
52  return *this;
53  }
55  m_waterSS = (PDSS_Water*) m_vptp_ptr->providePDSS(0);
56  m_tlastRef = -1.0;
57  return *this;
58 }
59 
60 VPSSMgr*
62 {
63  return new VPSSMgr_Water_HKFT(*this);
64 }
65 
66 void
68 {
70  copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
71 }
72 
73 void
75 {
77  copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
78 }
79 
80 void
82 {
83  getGibbs_RT_ref(g);
84  doublereal RT = GasConstant * m_tlast;
85  for (size_t k = 0; k < m_kk; k++) {
86  g[k] *= RT;
87  }
88 }
89 
90 void
92 {
94  copy(m_s0_R.begin(), m_s0_R.end(), sr);
95 }
96 
97 void
98 VPSSMgr_Water_HKFT::getCp_R_ref(doublereal* cpr) const
99 {
101  copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
102 }
103 
104 void
106 {
108  copy(m_V0.begin(), m_V0.end(), vol);
109 }
110 
111 void VPSSMgr_Water_HKFT::setState_P(doublereal pres)
112 {
113  if (m_plast != pres) {
114  m_plast = pres;
116  }
117 }
118 
119 void VPSSMgr_Water_HKFT::setState_T(doublereal temp)
120 {
121  if (m_tlast != temp) {
122  m_tlast = temp;
124  }
125 }
126 
127 void VPSSMgr_Water_HKFT::setState_TP(doublereal temp, doublereal pres)
128 {
129  if (m_tlast != temp) {
130  m_tlast = temp;
131  m_plast = pres;
133  } else if (m_plast != pres) {
134  m_plast = pres;
136  }
137 }
138 
140 {
141  if (m_tlastRef != m_tlast) {
144  }
145 }
146 
148 {
150  doublereal RT = GasConstant * m_tlast;
151  m_waterSS->setState_TP(m_tlast, m_p0);
152  m_h0_RT[0] = (m_waterSS->enthalpy_mole())/ RT;
154  m_cp0_R[0] = (m_waterSS->cp_mole()) / GasConstant;
155  m_g0_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
157  PDSS_HKFT* ps;
158  for (size_t k = 1; k < m_kk; k++) {
159  ps = (PDSS_HKFT*) m_vptp_ptr->providePDSS(k);
160  ps->setState_TP(m_tlast, m_p0);
161  m_cp0_R[k] = ps->cp_R();
162  m_s0_R[k] = ps->entropy_mole() / GasConstant;
163  m_g0_RT[k] = ps->gibbs_RT();
164  m_h0_RT[k] = m_g0_RT[k] + m_s0_R[k];
165 #ifdef DEBUG_MODE_NOT
166  double h = ps->enthalpy_RT();
167  if (fabs(m_h0_RT[k] - h) > 1.0E-4) {
168  printf(" VPSSMgr_Water_HKFT::_updateRefStateThermo:: we have a discrepancy\n");
169  }
170 #endif
171  m_V0[k] = ps->molarVolume();
172 
173  }
174  m_waterSS->setState_TP(m_tlast, m_plast);
175  for (size_t k = 1; k < m_kk; k++) {
176  ps = (PDSS_HKFT*) m_vptp_ptr->providePDSS(k);
177  ps->setState_TP(m_tlast, m_plast);
178  }
179 }
180 
182 {
183  doublereal RT = GasConstant * m_tlast;
184  // Do the water
185  m_waterSS->setState_TP(m_tlast, m_plast);
186  m_hss_RT[0] = (m_waterSS->enthalpy_mole())/ RT;
189  m_gss_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
191 
192  for (size_t k = 1; k < m_kk; k++) {
193  PDSS_HKFT* ps = (PDSS_HKFT*) m_vptp_ptr->providePDSS(k);
194  ps->setState_TP(m_tlast, m_plast);
195  m_cpss_R[k] = ps->cp_R();
196  m_sss_R[k] = ps->entropy_R();
197  m_gss_RT[k] = ps->gibbs_RT();
198  m_hss_RT[k] = m_gss_RT[k] + m_sss_R[k];
199  m_Vss[k] = ps->molarVolume();
200  }
201 }
202 
204 {
206 }
207 
208 
209 void
210 VPSSMgr_Water_HKFT::initThermoXML(XML_Node& phaseNode, const std::string& id)
211 {
212  VPSSMgr::initThermoXML(phaseNode, id);
213 
214  XML_Node& speciesList = phaseNode.child("speciesArray");
215  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
216  &phaseNode.root());
217  const vector<string> &sss = m_vptp_ptr->speciesNames();
218 
219  m_waterSS->setState_TP(300., OneAtm);
221 
222  for (size_t k = 1; k < m_kk; k++) {
223  const XML_Node* s = speciesDB->findByAttr("name", sss[k]);
224  if (!s) {
225  throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
226  "No species Node for species " + sss[k]);
227  }
228  const XML_Node* ss = s->findByName("standardState");
229  if (!ss) {
230  throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
231  "No standardState Node for species " + sss[k]);
232  }
233  std::string model = lowercase((*ss)["model"]);
234  if (model != "hkft") {
235  throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
236  "Standard state model for a solute species isn't "
237  "the HKFT standard state model: " + sss[k]);
238  }
239  }
240 }
241 
242 PDSS*
243 VPSSMgr_Water_HKFT::createInstallPDSS(size_t k, const XML_Node& speciesNode,
244  const XML_Node* const phaseNode_ptr)
245 {
246  PDSS* kPDSS = 0;
247 
248  const XML_Node* ss = speciesNode.findByName("standardState");
249  if (!ss) {
250  std::string sName = speciesNode["name"];
251  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
252  "No standardState Node for species " + sName);
253  }
254  // Will have to do something for water
255  // -> make sure it's species 0
256  // -> make sure it's designated as a real water EOS
257  if (k == 0) {
258  string xn = speciesNode["name"];
259  if (xn != "H2O(L)") {
260  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
261  "h2o wrong name: " + xn);
262  }
263 
264  std::string model = (*ss)["model"];
265  if (model != "waterIAPWS" && model != "waterPDSS") {
266  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
267  "wrong SS mode: " + model);
268  }
269  //VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
270  delete m_waterSS;
271  m_waterSS = new PDSS_Water(m_vptp_ptr, 0);
272 
273  GeneralSpeciesThermo* genSpthermo = dynamic_cast<GeneralSpeciesThermo*>(m_spthermo);
274  if (!genSpthermo) {
275  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
276  "failed dynamic cast");
277  }
278  genSpthermo->installPDSShandler(k, m_waterSS, this);
279 
280  kPDSS = m_waterSS;
281  } else {
282  std::string model = (*ss)["model"];
283  if (model != "HKFT") {
284  std::string sName = speciesNode["name"];
285  throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
286  "standardState model for species isn't "
287  "HKFT: " + sName);
288  }
289 
290  kPDSS = new PDSS_HKFT(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
291 
292  GeneralSpeciesThermo* genSpthermo = dynamic_cast<GeneralSpeciesThermo*>(m_spthermo);
293  if (!genSpthermo) {
294  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
295  "failed dynamic cast");
296  }
297  genSpthermo->installPDSShandler(k, kPDSS, this);
298  }
299  return kPDSS;
300 }
301 
302 void
304  SpeciesThermo* sp_ptr)
305 {
306  VPSSMgr::initAllPtrs(vp_ptr, sp_ptr);
307  m_waterSS = dynamic_cast<PDSS_Water*>(m_vptp_ptr->providePDSS(0));
308  if (!m_waterSS) {
309  throw CanteraError("VPSSMgr_Water_ConstVol::initAllPtrs",
310  "bad dynamic cast");
311  }
312 }
313 
315 {
316  return cPDSS_UNDEF;
317 }
318 
320 {
321  return cVPSSMGR_WATER_HKFT;
322 }
323 }
vector_fp m_V0
Vector containing the species reference molar volumes.
Definition: VPSSMgr.h:778
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
Definition: PDSS.cpp:252
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition: PDSS_HKFT.cpp:222
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:293
virtual void setState_T(doublereal T)
Set the temperature (K)
XML_Node * findByAttr(const std::string &attr, const std::string &val, int depth=100000) const
This routine carries out a recursive search for an XML node based on an attribute of each XML node...
Definition: xml.cpp:716
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:484
doublereal m_tlastRef
Last reference temperature calculated.
bool m_useTmpRefStateStorage
Definition: VPSSMgr.h:751
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_HKFT.cpp:492
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...
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:71
vector_fp m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:808
VPSSMgr_Water_HKFT(VPStandardStateTP *vptp_ptr, SpeciesThermo *spth)
Constructor.
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:238
VPSSMgr & operator=(const VPSSMgr &right)
Assignment operator.
Definition: VPSSMgr.cpp:67
Variable pressure SS calculate for phases consisting of real water as the first species and species o...
Definition: mix_defs.h:146
bool m_useTmpStandardStateStorage
Definition: VPSSMgr.h:784
virtual void getEntropy_R_ref(doublereal *er) const
virtual void getGibbs_RT_ref(doublereal *grt) const
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Finalize the thermo after all species have been entered.
Definition: VPSSMgr.cpp:393
PDSS_Water * m_waterSS
Shallow pointer to the water object.
size_t m_kk
Number of species in the phase.
Definition: VPSSMgr.h:716
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
Implementation of a pressure dependent standard state virtual function for a Pure Water Phase (see Sp...
virtual VPSSMgr * duplMyselfAsVPSSMgr() const
Duplication routine for objects which derive from VPSSMgr.
virtual void initAllPtrs(VPStandardStateTP *vp_ptr, SpeciesThermo *sp_ptr)
Initialize the internal shallow pointers in this object.
virtual void initThermo()
Definition: VPSSMgr.cpp:360
std::string lowercase(const std::string &s)
Cast a copy of a string to lower case.
Definition: stringUtils.cpp:58
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_Water.cpp:442
Pure Virtual base class for the species thermo manager classes.
VPSSMgr_enumType
enum for VPSSMgr types that are responsible for calculating the species standard state and reference-...
Definition: mix_defs.h:133
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:584
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Finalize the thermo after all species have been entered.
const XML_Node * findByName(const std::string &nm, int depth=100000) const
This routine carries out a recursive search for an XML node based on the name of the node...
Definition: xml.cpp:754
virtual doublereal enthalpy_mole() const
Return the molar enthalpy in units of J kmol-1.
Definition: PDSS_Water.cpp:269
virtual void setState_P(doublereal P)
Set the pressure (Pa)
doublereal pref_safe(doublereal temp) const
Returns a reference pressure value that can be safely calculated by the underlying real equation of s...
Definition: PDSS_Water.cpp:467
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
Definition: PDSS.cpp:241
virtual void getCp_R_ref(doublereal *cpr) const
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
Definition: PDSS_HKFT.cpp:245
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
vector_fp m_cp0_R
Vector containing the species reference constant pressure heat capacities at T = m_tlast and P = p_re...
Definition: VPSSMgr.h:763
A species thermodynamic property manager for a phase.
VPStandardStateTP * m_vptp_ptr
Variable pressure ThermoPhase object.
Definition: VPSSMgr.h:719
virtual void initAllPtrs(VPStandardStateTP *vp_ptr, SpeciesThermo *sp_ptr)
Initialize the internal shallow pointers in this object.
Definition: VPSSMgr.cpp:125
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_Water.cpp:454
Class for the liquid water pressure dependent standard state.
Definition: PDSS_Water.h:54
doublereal m_plast
The last pressure at which the Standard State thermodynamic properties were calculated at...
Definition: VPSSMgr.h:733
PDSS_enumType
Types of PDSS's.
Definition: mix_defs.h:119
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
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...
Manages standard state thermo properties for real water and a set of species which have the HKFT equa...
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS_HKFT.cpp:359
virtual void getGibbs_ref(doublereal *g) const
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual PDSS_enumType reportPDSSType(int index=-1) const
This utility function reports the type of parameterization used for the species with index number ind...
vector_fp m_Vss
Vector containing the species standard state volumes at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:814
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
Definition: Phase.cpp:252
vector_fp m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:790
virtual VPSSMgr_enumType reportVPSSMgrType() const
This utility function reports the type of manager for the calculation of ss properties.
vector_fp m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
Definition: VPSSMgr.h:796
vector_fp m_h0_RT
Definition: VPSSMgr.h:757
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS.cpp:264
Headers for a completely general species thermodynamic property manager for a phase (see Managers for...
VPSSMgr_Water_HKFT & operator=(const VPSSMgr_Water_HKFT &right)
Assignment operator.
virtual void _updateRefStateThermo() const
Updates the reference state thermodynamic functions at the current T of the solution and the referenc...
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:195
vector_fp m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:769
virtual void updateRefStateThermo() const
Updates the internal reference state thermodynamic vectors at the current T of the solution and the r...
doublereal m_p0
Definition: VPSSMgr.h:739
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
Class for pressure dependent standard states corresponding to ionic solutes in electrolyte water...
Definition: PDSS_HKFT.h:32
SpeciesThermo * m_spthermo
Pointer to reference state thermo calculator.
Definition: VPSSMgr.h:725
doublereal m_tlast
The last temperature at which the standard state thermodynamic properties were calculated at...
Definition: VPSSMgr.h:729
virtual void setState_TP(doublereal T, doublereal P)
Set the temperature (K) and pressure (Pa)
XML_Node & root() const
Return the root of the current XML_Node tree.
Definition: xml.cpp:1091
vector_fp m_gss_RT
Vector containing the species Standard State Gibbs functions at T = m_tlast and P = m_plast...
Definition: VPSSMgr.h:802
virtual void _updateStandardStateThermo()
Updates the standard state thermodynamic functions at the current T and P of the solution.
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:281
XML_Node * get_XML_NameID(const std::string &nameTarget, const std::string &file_ID, XML_Node *root)
This routine will locate an XML node in either the input XML tree or in another input file specified ...
Definition: global.cpp:271
Declarations for the class PDSS_HKFT (pressure dependent standard state) which handles calculations f...
Declaration file for a derived class that handles the calculation of standard state thermo properties...
vector_fp m_s0_R
Vector containing the species reference entropies at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:775
void installPDSShandler(size_t k, PDSS *PDSS_ptr, VPSSMgr *vpssmgr_ptr)
Install a PDSS object to handle the reference state thermodynamics calculation.