Cantera  2.3.0
VPSSMgr_Water_ConstVol.cpp
Go to the documentation of this file.
1 /**
2  * @file VPSSMgr_Water_ConstVol.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 have a constant molar volume pressure
6  * dependence.
7  * (see \ref thermoprops and class
8  * \link Cantera::VPSSMgr_Water_ConstVol VPSSMgr_Water_ConstVol\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 
18 #include "cantera/base/ctml.h"
19 
20 using namespace std;
21 
22 namespace Cantera
23 {
24 VPSSMgr_Water_ConstVol::VPSSMgr_Water_ConstVol(VPStandardStateTP* vp_ptr,
25  MultiSpeciesThermo* spth) :
26  VPSSMgr(vp_ptr, spth),
27  m_waterSS(0)
28 {
31 }
32 
34  VPSSMgr(right.m_vptp_ptr, right.m_spthermo)
35 {
38  *this = right;
39 }
40 
41 VPSSMgr_Water_ConstVol&
42 VPSSMgr_Water_ConstVol::operator=(const VPSSMgr_Water_ConstVol& b)
43 {
44  if (&b == this) {
45  return *this;
46  }
48  return *this;
49 }
50 
52 {
53  return new VPSSMgr_Water_ConstVol(*this);
54 }
55 
57  MultiSpeciesThermo* sp_ptr)
58 {
59  VPSSMgr::initAllPtrs(vp_ptr, sp_ptr);
60  m_waterSS = dynamic_cast<PDSS_Water*>(m_vptp_ptr->providePDSS(0));
61  if (!m_waterSS) {
62  throw CanteraError("VPSSMgr_Water_ConstVol::initAllPtrs",
63  "bad dynamic cast");
64  }
65 }
66 
67 void VPSSMgr_Water_ConstVol::getEnthalpy_RT_ref(doublereal* hrt) const
68 {
69  // Everything should be OK except for the water SS
71  if (m_p0 != m_plast) {
75  } else {
76  m_h0_RT[0] = m_hss_RT[0];
77  }
78  copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
79 }
80 
81 void VPSSMgr_Water_ConstVol::getGibbs_RT_ref(doublereal* grt) const
82 {
83  // Everything should be OK except for the water SS
85  if (m_p0 != m_plast) {
89  } else {
90  m_g0_RT[0] = m_gss_RT[0];
91  }
92  copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
93 }
94 
95 void VPSSMgr_Water_ConstVol::getGibbs_ref(doublereal* g) const
96 {
97  getGibbs_RT_ref(g);
98  for (size_t k = 0; k < m_kk; k++) {
99  g[k] *= GasConstant * m_tlast;
100  }
101 }
102 
104 {
105  // Everything should be OK except for the water SS
107  if (m_p0 != m_plast) {
111  } else {
112  m_s0_R[0] = m_sss_R[0];
113  }
114  copy(m_s0_R.begin(), m_s0_R.end(), sr);
115 }
116 
117 void VPSSMgr_Water_ConstVol::getCp_R_ref(doublereal* cpr) const
118 {
119  // Everything should be OK except for the water SS
121  if (m_p0 != m_plast) {
123  m_cp0_R[0] = (m_waterSS->cp_mole()) / GasConstant;
125  } else {
126  m_cp0_R[0] = m_cpss_R[0];
127  }
128  copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
129 }
130 
132 {
133  // Everything should be OK except for the water SS
135  if (m_p0 != m_plast) {
139  } else {
140  m_V0[0] = m_Vss[0];
141  }
142  copy(m_V0.begin(), m_V0.end(), vol);
143 }
144 
146 {
148  m_spthermo->update(m_tlast, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
149  for (size_t k = 0; k < m_kk; k++) {
150  m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
151  m_vptp_ptr->providePDSS(k)->setTemperature(m_tlast);
152  }
156  m_cp0_R[0] = (m_waterSS->cp_mole()) / GasConstant;
157  m_g0_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
160 }
161 
163 {
164  doublereal del_pRT = (m_plast - OneAtm) / (GasConstant * m_tlast);
165 
166  for (size_t k = 1; k < m_kk; k++) {
167  m_hss_RT[k] = m_h0_RT[k] + del_pRT * m_Vss[k];
168  m_cpss_R[k] = m_cp0_R[k];
169  m_sss_R[k] = m_s0_R[k];
170  m_gss_RT[k] = m_hss_RT[k] - m_sss_R[k];
171  // m_Vss[k] constant
172  PDSS* kPDSS = m_vptp_ptr->providePDSS(k);
173  kPDSS->setState_TP(m_tlast, m_plast);
174  }
175  // Do the water
180  m_gss_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
182 }
183 
185  const std::string& id)
186 {
187  VPSSMgr::initThermoXML(phaseNode, id);
188  XML_Node& speciesList = phaseNode.child("speciesArray");
189  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
190  &phaseNode.root());
191 
192  if (!m_waterSS) {
193  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
194  "bad dynamic cast");
195  }
196 
197  m_waterSS->setState_TP(300., OneAtm);
199 
200  for (size_t k = 1; k < m_kk; k++) {
201  const XML_Node* s = speciesDB->findByAttr("name", m_vptp_ptr->speciesName(k));
202  if (!s) {
203  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
204  "no species Node for species " + m_vptp_ptr->speciesName(k));
205  }
206  const XML_Node* ss = s->findByName("standardState");
207  if (!ss) {
208  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
209  "no standardState Node for species " + s->attrib("name"));
210  }
211  if (ss->attrib("model") != "constant_incompressible") {
212  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
213  "standardState model for species isn't "
214  "constant_incompressible: " + s->attrib("name"));
215  }
216  m_Vss[k] = getFloat(*ss, "molarVolume", "toSI");
217  }
218 }
219 
221  const XML_Node& speciesNode, const XML_Node* const phaseNode_ptr)
222 {
223  PDSS* kPDSS = 0;
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  string xn = speciesNode["name"];
229  if (xn != "H2O(L)") {
230  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
231  "h2o wrong name: " + xn);
232  }
233  const XML_Node* ss = speciesNode.findByName("standardState");
234  std::string model = ss->attrib("model");
235  if (model != "waterIAPWS" && model != "waterPDSS") {
236  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
237  "wrong SS mode: " + model);
238  }
239  delete m_waterSS;
240  m_waterSS = new PDSS_Water(m_vptp_ptr, 0);
242  kPDSS = m_waterSS;
243  } else {
244  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
245  const XML_Node* ss = speciesNode.findByName("standardState");
246  if (!ss) {
247  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
248  "no standardState Node for species " + speciesNode.name());
249  }
250  if (ss->attrib("model") != "constant_incompressible") {
251  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
252  "standardState model for species isn't "
253  "constant_incompressible: " + speciesNode.name());
254  }
255  if (m_Vss.size() < k+1) {
256  m_Vss.resize(k+1, 0.0);
257  }
258  m_Vss[k] = getFloat(*ss, "molarVolume", "toSI");
259 
260  // instantiate a new kPDSS object
261  kPDSS = new PDSS_ConstVol(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
262  }
263  return kPDSS;
264 }
265 
267 {
268  warn_deprecated("VPSSMgr_Water_ConstVol::reportPDSSType",
269  "To be removed after Cantera 2.3.");
270  return cPDSS_UNDEF;
271 }
272 
274 {
275  warn_deprecated("VPSSMgr_Water_ConstVol::reportVPSSMgrType",
276  "To be removed after Cantera 2.3.");
278 }
279 }
vector_fp m_V0
Vector containing the species reference molar volumes.
Definition: VPSSMgr.h:753
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...
PDSS_Water * m_waterSS
Pointer to the Water PDSS object.
bool m_useTmpRefStateStorage
boolean indicating whether temporary reference state storage is used -> default is false ...
Definition: VPSSMgr.h:734
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
std::string name() const
Returns the name of the XML node.
Definition: xml.h:370
virtual PDSS_enumType reportPDSSType(int index=-1) const
This utility function reports the type of parameterization used for the species with index number ind...
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 void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:228
VPSSMgr & operator=(const VPSSMgr &right)
Definition: VPSSMgr.cpp:60
virtual VPSSMgr * duplMyselfAsVPSSMgr() const
Duplication routine for objects which derive from VPSSMgr.
virtual void getGibbs_RT_ref(doublereal *grt) const
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
VPSSMgr_Water_ConstVol(VPStandardStateTP *vp_ptr, MultiSpeciesThermo *sp_ptr)
Base Constructor.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Finalize the thermo after all species have been entered.
Definition: VPSSMgr.cpp:364
size_t m_kk
Number of species in the phase.
Definition: VPSSMgr.h:704
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.
Handles the calculation of standard state thermo properties for real water and a set of species which...
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.
Variable pressure SS calculate for phases consisting of real water as the first species and species h...
Definition: mix_defs.h:129
virtual void getCp_R_ref(doublereal *cpr) const
VPSSMgr_enumType
enum for VPSSMgr types that are responsible for calculating the species standard state and reference-...
Definition: mix_defs.h:119
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
virtual void getEntropy_R_ref(doublereal *er) const
virtual VPSSMgr_enumType reportVPSSMgrType() const
This utility function reports the type of manager for the calculation of ss properties.
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
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS.cpp:351
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
Declaration file for a derived class that handles the calculation of standard state thermo properties...
Class for pressure dependent standard states that use a constant volume model.
Definition: PDSS_ConstVol.h:22
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
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Finalize the thermo after all species have been entered.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
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
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual void initAllPtrs(VPStandardStateTP *vp_ptr, MultiSpeciesThermo *sp_ptr)
Initialize the internal shallow pointers in this object.
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 void _updateRefStateThermo() const
Updates the reference state thermodynamic functions at the current T of the solution and the referenc...
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 doublereal gibbs_mole() const
Return the molar Gibbs free energy in units of J kmol-1.
Definition: PDSS_Water.cpp:208
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
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
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:178
Declarations for the class PDSS_ConstVol (pressure dependent standard state) which handles calculatio...
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
virtual void getGibbs_ref(doublereal *g) const
A species thermodynamic property manager for a phase.
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:496
void installSTSpecies(size_t k, const XML_Node &speciesNode, const XML_Node *phaseNode_ptr)
Install specific content for species k in the reference-state thermodynamic SpeciesManager object...
Definition: VPSSMgr.cpp:375
doublereal m_tlast
The last temperature at which the standard state thermodynamic properties were calculated at...
Definition: VPSSMgr.h:717
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
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
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
virtual void _updateStandardStateThermo()
Updates the standard state thermodynamic functions at the current T and P of the solution.