Cantera  2.3.0
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 // This file is part of Cantera. See License.txt in the top-level directory or
12 // at http://www.cantera.org/license.txt for license and copyright information.
13 
19 #include "cantera/base/xml.h"
21 
22 using namespace std;
23 
24 namespace Cantera
25 {
26 
27 VPSSMgr_Water_HKFT::VPSSMgr_Water_HKFT(VPStandardStateTP* vp_ptr,
28  MultiSpeciesThermo* 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 VPSSMgr_Water_HKFT& VPSSMgr_Water_HKFT::operator=(const VPSSMgr_Water_HKFT& b)
48 {
49  if (&b == this) {
50  return *this;
51  }
53  m_waterSS = &dynamic_cast<PDSS_Water&>(*m_vptp_ptr->providePDSS(0));
54  m_tlastRef = -1.0;
55  return *this;
56 }
57 
59 {
60  return new VPSSMgr_Water_HKFT(*this);
61 }
62 
63 void VPSSMgr_Water_HKFT::getEnthalpy_RT_ref(doublereal* hrt) const
64 {
66  copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
67 }
68 
69 void VPSSMgr_Water_HKFT::getGibbs_RT_ref(doublereal* grt) const
70 {
72  copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
73 }
74 
75 void VPSSMgr_Water_HKFT::getGibbs_ref(doublereal* g) const
76 {
77  getGibbs_RT_ref(g);
78  for (size_t k = 0; k < m_kk; k++) {
79  g[k] *= GasConstant * m_tlast;
80  }
81 }
82 
83 void VPSSMgr_Water_HKFT::getEntropy_R_ref(doublereal* sr) const
84 {
86  copy(m_s0_R.begin(), m_s0_R.end(), sr);
87 }
88 
89 void VPSSMgr_Water_HKFT::getCp_R_ref(doublereal* cpr) const
90 {
92  copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
93 }
94 
95 void VPSSMgr_Water_HKFT::getStandardVolumes_ref(doublereal* vol) const
96 {
98  copy(m_V0.begin(), m_V0.end(), vol);
99 }
100 
101 void VPSSMgr_Water_HKFT::setState_P(doublereal pres)
102 {
103  if (m_plast != pres) {
104  m_plast = pres;
106  }
107 }
108 
109 void VPSSMgr_Water_HKFT::setState_T(doublereal temp)
110 {
111  if (m_tlast != temp) {
112  m_tlast = temp;
114  }
115 }
116 
117 void VPSSMgr_Water_HKFT::setState_TP(doublereal temp, doublereal pres)
118 {
119  if (m_tlast != temp) {
120  m_tlast = temp;
121  m_plast = pres;
123  } else if (m_plast != pres) {
124  m_plast = pres;
126  }
127 }
128 
130 {
131  if (m_tlastRef != m_tlast) {
134  }
135 }
136 
138 {
143  m_cp0_R[0] = (m_waterSS->cp_mole()) / GasConstant;
144  m_g0_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
146  PDSS* ps;
147  for (size_t k = 1; k < m_kk; k++) {
148  ps = m_vptp_ptr->providePDSS(k);
149  ps->setState_TP(m_tlast, m_p0);
150  m_cp0_R[k] = ps->cp_R();
151  m_s0_R[k] = ps->entropy_mole() / GasConstant;
152  m_g0_RT[k] = ps->gibbs_RT();
153  m_h0_RT[k] = m_g0_RT[k] + m_s0_R[k];
154  m_V0[k] = ps->molarVolume();
155 
156  }
158  for (size_t k = 1; k < m_kk; k++) {
159  ps = m_vptp_ptr->providePDSS(k);
161  }
162 }
163 
165 {
166  // Do the water
171  m_gss_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
173 
174  for (size_t k = 1; k < m_kk; k++) {
175  PDSS* ps = m_vptp_ptr->providePDSS(k);
177  m_cpss_R[k] = ps->cp_R();
178  m_sss_R[k] = ps->entropy_R();
179  m_gss_RT[k] = ps->gibbs_RT();
180  m_hss_RT[k] = m_gss_RT[k] + m_sss_R[k];
181  m_Vss[k] = ps->molarVolume();
182  }
183 }
184 
186  const std::string& id)
187 {
188  VPSSMgr::initThermoXML(phaseNode, id);
189  XML_Node& speciesList = phaseNode.child("speciesArray");
190  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
191  &phaseNode.root());
192  m_waterSS->setState_TP(300., OneAtm);
194 
195  for (size_t k = 1; k < m_kk; k++) {
196  string name = m_vptp_ptr->speciesName(k);
197  const XML_Node* s = speciesDB->findByAttr("name", name);
198  if (!s) {
199  throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
200  "No species Node for species " + name);
201  }
202  const XML_Node* ss = s->findByName("standardState");
203  if (!ss) {
204  throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
205  "No standardState Node for species " + name);
206  }
207  if (!ba::iequals(ss->attrib("model"), "hkft")) {
208  throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
209  "Standard state model for a solute species isn't "
210  "the HKFT standard state model: " + name);
211  }
212  }
213 }
214 
216  const XML_Node& speciesNode, const XML_Node* const phaseNode_ptr)
217 {
218  PDSS* kPDSS = 0;
219  const XML_Node* ss = speciesNode.findByName("standardState");
220  if (!ss) {
221  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
222  "No standardState Node for species " + speciesNode["name"]);
223  }
224  // Will have to do something for water
225  // -> make sure it's species 0
226  // -> make sure it's designated as a real water EOS
227  if (k == 0) {
228  if (speciesNode["name"] != "H2O(L)") {
229  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
230  "h2o wrong name: " + speciesNode["name"]);
231  }
232 
233  std::string model = ss->attrib("model");
234  if (model != "waterIAPWS" && model != "waterPDSS") {
235  throw CanteraError("VPSSMgr_Water_HKFT::installSpecies",
236  "wrong SS mode: " + model);
237  }
238  delete m_waterSS;
239  m_waterSS = new PDSS_Water(m_vptp_ptr, 0);
241  kPDSS = m_waterSS;
242  } else {
243  if (ss->attrib("model") != "HKFT") {
244  throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
245  "standardState model for species isn't "
246  "HKFT: " + speciesNode["name"]);
247  }
248 
249  kPDSS = new PDSS_HKFT(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
250  m_spthermo->installPDSShandler(k, kPDSS, this);
251  }
252  return kPDSS;
253 }
254 
256  MultiSpeciesThermo* sp_ptr)
257 {
258  VPSSMgr::initAllPtrs(vp_ptr, sp_ptr);
259  m_waterSS = dynamic_cast<PDSS_Water*>(m_vptp_ptr->providePDSS(0));
260  if (!m_waterSS) {
261  throw CanteraError("VPSSMgr_Water_ConstVol::initAllPtrs",
262  "bad dynamic cast");
263  }
264 }
265 
267 {
268  warn_deprecated("VPSSMgr_Water_HKFT::reportPDSSType",
269  "To be removed after Cantera 2.3.");
270  return cPDSS_UNDEF;
271 }
272 
274 {
275  warn_deprecated("VPSSMgr_Water_HKFT::reportVPSSMgrType",
276  "To be removed after Cantera 2.3.");
277  return cVPSSMGR_WATER_HKFT;
278 }
279 }
vector_fp m_V0
Vector containing the species reference molar volumes.
Definition: VPSSMgr.h:753
Header for a general species thermodynamic property manager for a phase (see MultiSpeciesThermo).
virtual void getCp_R_ref(doublereal *cpr) const
virtual void setState_T(doublereal T)
Set the temperature (K)
virtual VPSSMgr * duplMyselfAsVPSSMgr() const
Duplication routine for objects which derive from VPSSMgr.
doublereal m_tlastRef
Last reference temperature calculated.
bool m_useTmpRefStateStorage
boolean indicating whether temporary reference state storage is used -> default is false ...
Definition: VPSSMgr.h:734
virtual VPSSMgr_enumType reportVPSSMgrType() const
This utility function reports the type of manager for the calculation of ss properties.
virtual void getGibbs_ref(doublereal *g) const
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 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:695
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
vector_fp m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:773
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:228
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
Definition: PDSS.cpp:226
VPSSMgr & operator=(const VPSSMgr &right)
Definition: VPSSMgr.cpp:60
Variable pressure SS calculate for phases consisting of real water as the first species and species o...
Definition: mix_defs.h:132
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
Definition: PDSS.cpp:231
bool m_useTmpStandardStateStorage
boolean indicating whether temporary standard state storage is used -> default is false ...
Definition: VPSSMgr.h:757
virtual void initAllPtrs(VPStandardStateTP *vp_ptr, MultiSpeciesThermo *sp_ptr)
Initialize the internal shallow pointers in this object.
Definition: VPSSMgr.cpp:121
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Finalize the thermo after all species have been entered.
Definition: VPSSMgr.cpp:364
PDSS_Water * m_waterSS
Shallow pointer to the water object.
size_t m_kk
Number of species in the phase.
Definition: VPSSMgr.h:704
virtual void initAllPtrs(VPStandardStateTP *vp_ptr, MultiSpeciesThermo *sp_ptr)
Initialize the internal shallow pointers in this object.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
Implementation of a pressure dependent standard state virtual function for a Pure Water Phase (see Sp...
void installPDSShandler(size_t k, PDSS *PDSS_ptr, VPSSMgr *vpssmgr_ptr)
Install a PDSS object to handle the reference state thermodynamics calculation.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
STL namespace.
virtual void _updateRefStateThermo() const
Updates the reference state thermodynamic functions at the current T of the solution and the referenc...
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS.cpp:251
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
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...
VPSSMgr_enumType
enum for VPSSMgr types that are responsible for calculating the species standard state and reference-...
Definition: mix_defs.h:119
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Finalize the thermo after all species have been entered.
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS.cpp:256
virtual void setState_P(doublereal P)
Set the pressure (Pa)
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:742
VPStandardStateTP * m_vptp_ptr
Variable pressure ThermoPhase object.
Definition: VPSSMgr.h:707
MultiSpeciesThermo * m_spthermo
Pointer to reference state thermo calculator.
Definition: VPSSMgr.h:713
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_Water.cpp:364
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:267
Class for the liquid water pressure dependent standard state.
Definition: PDSS_Water.h:49
doublereal m_plast
The last pressure at which the Standard State thermodynamic properties were calculated at...
Definition: VPSSMgr.h:721
PDSS_enumType
Types of PDSS&#39;s.
Definition: mix_defs.h:105
Classes providing support for XML data files.
VPSSMgr_Water_HKFT(VPStandardStateTP *vptp_ptr, MultiSpeciesThermo *spth)
Constructor.
virtual void getEntropy_R_ref(doublereal *er) const
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
Manages standard state thermo properties for real water and a set of species which have the HKFT equa...
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:203
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:377
virtual void getGibbs_RT_ref(doublereal *grt) const
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS_Water.cpp:213
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
Definition: PDSS.cpp:241
vector_fp m_Vss
Vector containing the species standard state volumes at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:777
XML_Node & child(const size_t n) const
Return a changeable reference to the n&#39;th child of the current node.
Definition: xml.cpp:546
XML_Node & root() const
Return the root of the current XML_Node tree.
Definition: xml.cpp:1025
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_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:761
vector_fp m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
Definition: VPSSMgr.h:765
vector_fp m_h0_RT
Vector containing the species reference enthalpies at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:738
virtual void updateRefStateThermo() const
Updates the internal reference state thermodynamic vectors at the current T of the solution and the r...
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:500
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:176
vector_fp m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:746
doublereal m_p0
Reference pressure (Pa) must be the same for all species - defaults to 1 atm.
Definition: VPSSMgr.h:724
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
Contains declarations for string manipulation functions within Cantera.
Class for pressure dependent standard states corresponding to ionic solutes in electrolyte water...
Definition: PDSS_HKFT.h:27
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_Water.cpp:353
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:661
A species thermodynamic property manager for a phase.
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:496
doublereal m_tlast
The last temperature at which the standard state thermodynamic properties were calculated at...
Definition: VPSSMgr.h:717
virtual void setState_TP(doublereal T, doublereal P)
Set the temperature (K) and pressure (Pa)
Namespace for the Cantera kernel.
Definition: application.cpp:29
vector_fp m_gss_RT
Vector containing the species Standard State Gibbs functions at T = m_tlast and P = m_plast...
Definition: VPSSMgr.h:769
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS.cpp:365
virtual void _updateStandardStateThermo()
Updates the standard state thermodynamic functions at the current T and P of the solution.
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:750
virtual doublereal enthalpy_mole() const
Return the molar enthalpy in units of J kmol-1.
Definition: PDSS_Water.cpp:193