Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
22 #include "cantera/base/xml.h"
23 
24 using namespace std;
25 
26 namespace Cantera
27 {
28 
29 VPSSMgr_Water_HKFT::VPSSMgr_Water_HKFT(VPStandardStateTP* vp_ptr,
30  SpeciesThermo* spth) :
31  VPSSMgr(vp_ptr, spth),
32  m_waterSS(0),
33  m_tlastRef(-1.0)
34 {
37 }
38 
40  VPSSMgr(right.m_vptp_ptr, right.m_spthermo),
41  m_waterSS(0),
42  m_tlastRef(-1.0)
43 {
46  *this = right;
47 }
48 
49 
52 {
53  if (&b == this) {
54  return *this;
55  }
57  m_waterSS = dynamic_cast<PDSS_Water*>(m_vptp_ptr->providePDSS(0));
58  m_tlastRef = -1.0;
59  return *this;
60 }
61 
62 VPSSMgr*
64 {
65  return new VPSSMgr_Water_HKFT(*this);
66 }
67 
68 void
70 {
72  copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
73 }
74 
75 void
77 {
79  copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
80 }
81 
82 void
84 {
85  getGibbs_RT_ref(g);
86  for (size_t k = 0; k < m_kk; k++) {
87  g[k] *= GasConstant * m_tlast;
88  }
89 }
90 
91 void
93 {
95  copy(m_s0_R.begin(), m_s0_R.end(), sr);
96 }
97 
98 void
99 VPSSMgr_Water_HKFT::getCp_R_ref(doublereal* cpr) const
100 {
102  copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
103 }
104 
105 void
107 {
109  copy(m_V0.begin(), m_V0.end(), vol);
110 }
111 
112 void VPSSMgr_Water_HKFT::setState_P(doublereal pres)
113 {
114  if (m_plast != pres) {
115  m_plast = pres;
117  }
118 }
119 
120 void VPSSMgr_Water_HKFT::setState_T(doublereal temp)
121 {
122  if (m_tlast != temp) {
123  m_tlast = temp;
125  }
126 }
127 
128 void VPSSMgr_Water_HKFT::setState_TP(doublereal temp, doublereal pres)
129 {
130  if (m_tlast != temp) {
131  m_tlast = temp;
132  m_plast = pres;
134  } else if (m_plast != pres) {
135  m_plast = pres;
137  }
138 }
139 
141 {
142  if (m_tlastRef != m_tlast) {
145  }
146 }
147 
149 {
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* ps;
158  for (size_t k = 1; k < m_kk; k++) {
159  ps = 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 = m_vptp_ptr->providePDSS(k);
177  ps->setState_TP(m_tlast, m_plast);
178  }
179 }
180 
182 {
183  // Do the water
188  m_gss_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
190 
191  for (size_t k = 1; k < m_kk; k++) {
192  PDSS* ps = m_vptp_ptr->providePDSS(k);
193  ps->setState_TP(m_tlast, m_plast);
194  m_cpss_R[k] = ps->cp_R();
195  m_sss_R[k] = ps->entropy_R();
196  m_gss_RT[k] = ps->gibbs_RT();
197  m_hss_RT[k] = m_gss_RT[k] + m_sss_R[k];
198  m_Vss[k] = ps->molarVolume();
199  }
200 }
201 
203 {
205 }
206 
207 
208 void
209 VPSSMgr_Water_HKFT::initThermoXML(XML_Node& phaseNode, const std::string& id)
210 {
211  VPSSMgr::initThermoXML(phaseNode, id);
212 
213  XML_Node& speciesList = phaseNode.child("speciesArray");
214  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
215  &phaseNode.root());
216  m_waterSS->setState_TP(300., OneAtm);
218 
219  for (size_t k = 1; k < m_kk; k++) {
220  string name = m_vptp_ptr->speciesName(k);
221  const XML_Node* s = speciesDB->findByAttr("name", name);
222  if (!s) {
223  throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
224  "No species Node for species " + name);
225  }
226  const XML_Node* ss = s->findByName("standardState");
227  if (!ss) {
228  throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
229  "No standardState Node for species " + name);
230  }
231  std::string model = lowercase(ss->attrib("model"));
232  if (model != "hkft") {
233  throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
234  "Standard state model for a solute species isn't "
235  "the HKFT standard state model: " + name);
236  }
237  }
238 }
239 
240 PDSS*
241 VPSSMgr_Water_HKFT::createInstallPDSS(size_t k, const XML_Node& speciesNode,
242  const XML_Node* const phaseNode_ptr)
243 {
244  PDSS* kPDSS = 0;
245 
246  const XML_Node* ss = speciesNode.findByName("standardState");
247  if (!ss) {
248  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
249  "No standardState Node for species " + speciesNode["name"]);
250  }
251  // Will have to do something for water
252  // -> make sure it's species 0
253  // -> make sure it's designated as a real water EOS
254  if (k == 0) {
255  if (speciesNode["name"] != "H2O(L)") {
256  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
257  "h2o wrong name: " + speciesNode["name"]);
258  }
259 
260  std::string model = ss->attrib("model");
261  if (model != "waterIAPWS" && model != "waterPDSS") {
262  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
263  "wrong SS mode: " + model);
264  }
265  //VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
266  delete m_waterSS;
267  m_waterSS = new PDSS_Water(m_vptp_ptr, 0);
268 
269  GeneralSpeciesThermo* genSpthermo = dynamic_cast<GeneralSpeciesThermo*>(m_spthermo);
270  if (!genSpthermo) {
271  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
272  "failed dynamic cast");
273  }
274  genSpthermo->installPDSShandler(k, m_waterSS, this);
275 
276  kPDSS = m_waterSS;
277  } else {
278  if (ss->attrib("model") != "HKFT") {
279  throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
280  "standardState model for species isn't "
281  "HKFT: " + speciesNode["name"]);
282  }
283 
284  kPDSS = new PDSS_HKFT(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
285 
286  GeneralSpeciesThermo* genSpthermo = dynamic_cast<GeneralSpeciesThermo*>(m_spthermo);
287  if (!genSpthermo) {
288  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
289  "failed dynamic cast");
290  }
291  genSpthermo->installPDSShandler(k, kPDSS, this);
292  }
293  return kPDSS;
294 }
295 
296 void
298  SpeciesThermo* sp_ptr)
299 {
300  VPSSMgr::initAllPtrs(vp_ptr, sp_ptr);
301  m_waterSS = dynamic_cast<PDSS_Water*>(m_vptp_ptr->providePDSS(0));
302  if (!m_waterSS) {
303  throw CanteraError("VPSSMgr_Water_ConstVol::initAllPtrs",
304  "bad dynamic cast");
305  }
306 }
307 
309 {
310  return cPDSS_UNDEF;
311 }
312 
314 {
315  return cVPSSMGR_WATER_HKFT;
316 }
317 }
vector_fp m_V0
Vector containing the species reference molar volumes.
Definition: VPSSMgr.h:773
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
Definition: PDSS.cpp:237
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:234
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:704
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:494
doublereal m_tlastRef
Last reference temperature calculated.
bool m_useTmpRefStateStorage
Definition: VPSSMgr.h:746
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:69
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:527
vector_fp m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:803
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:235
VPSSMgr & operator=(const VPSSMgr &right)
Assignment operator.
Definition: VPSSMgr.cpp:61
Variable pressure SS calculate for phases consisting of real water as the first species and species o...
Definition: mix_defs.h:148
bool m_useTmpStandardStateStorage
Definition: VPSSMgr.h:779
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:383
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition: PDSS.cpp:212
PDSS_Water * m_waterSS
Shallow pointer to the water object.
size_t m_kk
Number of species in the phase.
Definition: VPSSMgr.h:711
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:350
std::string lowercase(const std::string &s)
Cast a copy of a string to lower case.
Definition: stringUtils.cpp:73
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_Water.cpp:378
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:135
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:573
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:742
virtual doublereal enthalpy_mole() const
Return the molar enthalpy in units of J kmol-1.
Definition: PDSS_Water.cpp:214
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:402
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
Definition: PDSS.cpp:227
virtual void getCp_R_ref(doublereal *cpr) const
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
Definition: PDSS.cpp:222
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:758
A species thermodynamic property manager for a phase.
VPStandardStateTP * m_vptp_ptr
Variable pressure ThermoPhase object.
Definition: VPSSMgr.h:714
virtual void initAllPtrs(VPStandardStateTP *vp_ptr, SpeciesThermo *sp_ptr)
Initialize the internal shallow pointers in this object.
Definition: VPSSMgr.cpp:119
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_Water.cpp:389
Class for the liquid water pressure dependent standard state.
Definition: PDSS_Water.h:51
doublereal m_plast
The last pressure at which the Standard State thermodynamic properties were calculated at...
Definition: VPSSMgr.h:728
PDSS_enumType
Types of PDSS's.
Definition: mix_defs.h:121
Classes providing support for XML data files.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
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 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:809
vector_fp m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:785
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:791
vector_fp m_h0_RT
Definition: VPSSMgr.h:752
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS.cpp:247
Headers for a completely general species thermodynamic property manager for a phase (see Managers for...
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS.cpp:252
VPSSMgr_Water_HKFT & operator=(const VPSSMgr_Water_HKFT &right)
Assignment operator.
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
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:193
vector_fp m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:764
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:734
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
Class for pressure dependent standard states corresponding to ionic solutes in electrolyte water...
Definition: PDSS_HKFT.h:29
SpeciesThermo * m_spthermo
Pointer to reference state thermo calculator.
Definition: VPSSMgr.h:720
doublereal m_tlast
The last temperature at which the standard state thermodynamic properties were calculated at...
Definition: VPSSMgr.h:724
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:1095
vector_fp m_gss_RT
Vector containing the species Standard State Gibbs functions at T = m_tlast and P = m_plast...
Definition: VPSSMgr.h:797
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS.cpp:362
virtual void _updateStandardStateThermo()
Updates the standard state thermodynamic functions at the current T and P of the solution.
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:272
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:224
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:252
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:770
void installPDSShandler(size_t k, PDSS *PDSS_ptr, VPSSMgr *vpssmgr_ptr)
Install a PDSS object to handle the reference state thermodynamics calculation.