Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 /*
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/ctml.h"
23 
24 using namespace std;
25 
26 namespace Cantera
27 {
28 VPSSMgr_Water_ConstVol::VPSSMgr_Water_ConstVol(VPStandardStateTP* vp_ptr,
29  SpeciesThermo* spth) :
30  VPSSMgr(vp_ptr, spth),
31  m_waterSS(0)
32 {
35 }
36 
38  VPSSMgr(right.m_vptp_ptr, right.m_spthermo)
39 {
42  *this = right;
43 }
44 
47 {
48  if (&b == this) {
49  return *this;
50  }
52  return *this;
53 }
54 
55 VPSSMgr*
57 {
58  return new VPSSMgr_Water_ConstVol(*this);
59 }
60 
61 void
63  SpeciesThermo* sp_ptr)
64 {
65  VPSSMgr::initAllPtrs(vp_ptr, sp_ptr);
66  m_waterSS = dynamic_cast<PDSS_Water*>(m_vptp_ptr->providePDSS(0));
67  if (!m_waterSS) {
68  throw CanteraError("VPSSMgr_Water_ConstVol::initAllPtrs",
69  "bad dynamic cast");
70  }
71 }
72 
73 void
75 {
76  // Everything should be OK except for the water SS
78  if (m_p0 != m_plast) {
81  m_waterSS->setState_TP(m_tlast, m_plast);
82  } else {
83  m_h0_RT[0] = m_hss_RT[0];
84  }
85  copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
86 }
87 
88 void
90 {
91  // Everything should be OK except for the water SS
93  if (m_p0 != m_plast) {
96  m_waterSS->setState_TP(m_tlast, m_plast);
97  } else {
98  m_g0_RT[0] = m_gss_RT[0];
99  }
100  copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
101 }
102 
103 void
105 {
106  getGibbs_RT_ref(g);
107  for (size_t k = 0; k < m_kk; k++) {
108  g[k] *= GasConstant * m_tlast;
109  }
110 }
111 
112 void
114 {
115  // Everything should be OK except for the water SS
117  if (m_p0 != m_plast) {
121  } else {
122  m_s0_R[0] = m_sss_R[0];
123  }
124  copy(m_s0_R.begin(), m_s0_R.end(), sr);
125 }
126 
127 void
129 {
130  // Everything should be OK except for the water SS
132  if (m_p0 != m_plast) {
134  m_cp0_R[0] = (m_waterSS->cp_mole()) / GasConstant;
136  } else {
137  m_cp0_R[0] = m_cpss_R[0];
138  }
139  copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
140 }
141 
142 void
144 {
145  // Everything should be OK except for the water SS
147  if (m_p0 != m_plast) {
151  } else {
152  m_V0[0] = m_Vss[0];
153  }
154  copy(m_V0.begin(), m_V0.end(), vol);
155 }
156 
158 {
160  m_spthermo->update(m_tlast, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
161  for (size_t k = 0; k < m_kk; k++) {
162  m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
163  m_vptp_ptr->providePDSS(k)->setTemperature(m_tlast);
164  }
168  m_cp0_R[0] = (m_waterSS->cp_mole()) / GasConstant;
169  m_g0_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
171  m_waterSS->setState_TP(m_tlast, m_plast);
172 }
173 
175 {
176  doublereal del_pRT = (m_plast - OneAtm) / (GasConstant * m_tlast);
177 
178  for (size_t k = 1; k < m_kk; k++) {
179  m_hss_RT[k] = m_h0_RT[k] + del_pRT * m_Vss[k];
180  m_cpss_R[k] = m_cp0_R[k];
181  m_sss_R[k] = m_s0_R[k];
182  m_gss_RT[k] = m_hss_RT[k] - m_sss_R[k];
183  // m_Vss[k] constant
184  PDSS* kPDSS = m_vptp_ptr->providePDSS(k);
185  kPDSS->setState_TP(m_tlast, m_plast);
186  }
187  // Do the water
188  m_waterSS->setState_TP(m_tlast, m_plast);
189  m_hss_RT[0] = (m_waterSS->enthalpy_mole()) / (GasConstant * m_tlast);
192  m_gss_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
194 }
195 
197 {
199 }
200 
201 void
202 VPSSMgr_Water_ConstVol::initThermoXML(XML_Node& phaseNode, const std::string& id)
203 {
204  VPSSMgr::initThermoXML(phaseNode, id);
205 
206  XML_Node& speciesList = phaseNode.child("speciesArray");
207  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
208  &phaseNode.root());
209 
210  if (!m_waterSS) {
211  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
212  "bad dynamic cast");
213  }
214 
215  m_waterSS->setState_TP(300., OneAtm);
217 
218  for (size_t k = 1; k < m_kk; k++) {
219  const XML_Node* s = speciesDB->findByAttr("name", m_vptp_ptr->speciesName(k));
220  if (!s) {
221  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
222  "no species Node for species " + m_vptp_ptr->speciesName(k));
223  }
224  const XML_Node* ss = s->findByName("standardState");
225  if (!ss) {
226  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
227  "no standardState Node for species " + s->attrib("name"));
228  }
229  if (ss->attrib("model") != "constant_incompressible") {
230  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
231  "standardState model for species isn't "
232  "constant_incompressible: " + s->attrib("name"));
233  }
234  m_Vss[k] = getFloat(*ss, "molarVolume", "toSI");
235  }
236 }
237 
238 PDSS*
240  const XML_Node* const phaseNode_ptr)
241 {
242  PDSS* kPDSS = 0;
243  // Will have to do something for water
244  // -> make sure it's species 0
245  // -> make sure it's designated as a real water EOS
246  if (k == 0) {
247  string xn = speciesNode["name"];
248  if (xn != "H2O(L)") {
249  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
250  "h2o wrong name: " + xn);
251  }
252  const XML_Node* ss = speciesNode.findByName("standardState");
253  std::string model = ss->attrib("model");
254  if (model != "waterIAPWS" && model != "waterPDSS") {
255  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
256  "wrong SS mode: " + model);
257  }
258  delete m_waterSS;
259  m_waterSS = new PDSS_Water(m_vptp_ptr, 0);
260  GeneralSpeciesThermo* genSpthermo = dynamic_cast<GeneralSpeciesThermo*>(m_spthermo);
261  if (!genSpthermo) {
262  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
263  "failed dynamic cast");
264  }
265  genSpthermo->installPDSShandler(k, m_waterSS, this);
266  kPDSS = m_waterSS;
267  } else {
268 
269  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
270 
271  const XML_Node* ss = speciesNode.findByName("standardState");
272  if (!ss) {
273  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
274  "no standardState Node for species " + speciesNode.name());
275  }
276  if (ss->attrib("model") != "constant_incompressible") {
277  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
278  "standardState model for species isn't "
279  "constant_incompressible: " + speciesNode.name());
280  }
281  if (m_Vss.size() < k+1) {
282  m_Vss.resize(k+1, 0.0);
283  }
284  m_Vss[k] = getFloat(*ss, "molarVolume", "toSI");
285 
286  // instantiate a new kPDSS object
287  kPDSS = new PDSS_ConstVol(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
288  }
289  return kPDSS;
290 }
291 
293 {
294  return cPDSS_UNDEF;
295 }
296 
298 {
300 }
301 }
vector_fp m_V0
Vector containing the species reference molar volumes.
Definition: VPSSMgr.h:773
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
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
PDSS_Water * m_waterSS
Pointer to the Water PDSS object.
bool m_useTmpRefStateStorage
Definition: VPSSMgr.h:746
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
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
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:235
VPSSMgr_Water_ConstVol & operator=(const VPSSMgr_Water_ConstVol &right)
Assignment operator.
VPSSMgr & operator=(const VPSSMgr &right)
Assignment operator.
Definition: VPSSMgr.cpp:61
bool m_useTmpStandardStateStorage
Definition: VPSSMgr.h:779
virtual void initAllPtrs(VPStandardStateTP *vp_ptr, SpeciesThermo *sp_ptr)
Initialize the internal shallow pointers in this object.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Finalize the thermo after all species have been entered.
Definition: VPSSMgr.cpp:383
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...
Handles the calculation of standard state thermo properties for real water and a set of species which...
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 VPSSMgr_enumType reportVPSSMgrType() const
This utility function reports the type of manager for the calculation of ss properties.
virtual void getCp_R_ref(doublereal *cpr) const
Variable pressure SS calculate for phases consisting of real water as the first species and species h...
Definition: mix_defs.h:145
virtual void initThermo()
Definition: VPSSMgr.cpp:350
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_Water.cpp:378
virtual void getGibbs_ref(doublereal *g) const
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
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
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 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:758
A species thermodynamic property manager for a phase.
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS.cpp:348
VPStandardStateTP * m_vptp_ptr
Variable pressure ThermoPhase object.
Definition: VPSSMgr.h:714
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:23
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: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
std::string name() const
Returns the name of the XML node.
Definition: xml.h:394
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Finalize the thermo after all species have been entered.
virtual doublereal gibbs_mole() const
Return the molar Gibbs free energy in units of J kmol-1.
Definition: PDSS_Water.cpp:229
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
VPSSMgr_Water_ConstVol(VPStandardStateTP *vp_ptr, SpeciesThermo *sp_ptr)
Base Constructor.
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual void getEntropy_R_ref(doublereal *er) const
virtual void getGibbs_RT_ref(doublereal *grt) const
virtual VPSSMgr * duplMyselfAsVPSSMgr() const
Duplication routine for objects which derive from VPSSMgr.
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
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
Headers for a completely general species thermodynamic property manager for a phase (see Managers for...
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
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
doublereal m_p0
Definition: VPSSMgr.h:734
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:194
Declarations for the class PDSS_ConstVol (pressure dependent standard state) which handles calculatio...
SpeciesThermo * m_spthermo
Pointer to reference state thermo calculator.
Definition: VPSSMgr.h:720
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const =0
Compute the reference-state properties for all species.
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:394
doublereal m_tlast
The last temperature at which the standard state thermodynamic properties were calculated at...
Definition: VPSSMgr.h:724
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
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
virtual void _updateRefStateThermo() const
Updates the reference state thermodynamic functions at the current T of the solution and the referenc...
vector_fp m_s0_R
Vector containing the species reference entropies at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:770
virtual void _updateStandardStateThermo()
Updates the standard state thermodynamic functions at the current T and P of the solution.
void installPDSShandler(size_t k, PDSS *PDSS_ptr, VPSSMgr *vpssmgr_ptr)
Install a PDSS object to handle the reference state thermodynamics calculation.