Cantera  2.1.2
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 
21 
22 using namespace std;
23 
24 namespace Cantera
25 {
26 VPSSMgr_Water_ConstVol::VPSSMgr_Water_ConstVol(VPStandardStateTP* vp_ptr,
27  SpeciesThermo* spth) :
28  VPSSMgr(vp_ptr, spth),
29  m_waterSS(0)
30 {
33 }
34 
36  VPSSMgr(right.m_vptp_ptr, right.m_spthermo)
37 {
40  *this = right;
41 }
42 
45 {
46  if (&b == this) {
47  return *this;
48  }
50  return *this;
51 }
52 
53 VPSSMgr*
55 {
56  return new VPSSMgr_Water_ConstVol(*this);
57 }
58 
59 void
61  SpeciesThermo* sp_ptr)
62 {
63  VPSSMgr::initAllPtrs(vp_ptr, sp_ptr);
64  m_waterSS = dynamic_cast<PDSS_Water*>(m_vptp_ptr->providePDSS(0));
65  if (!m_waterSS) {
66  throw CanteraError("VPSSMgr_Water_ConstVol::initAllPtrs",
67  "bad dynamic cast");
68  }
69 }
70 
71 void
73 {
74  // Everything should be OK except for the water SS
76  if (m_p0 != m_plast) {
77  doublereal RT = GasConstant * m_tlast;
78  m_waterSS->setState_TP(m_tlast, m_p0);
79  m_h0_RT[0] = (m_waterSS->enthalpy_mole()) / RT;
80  m_waterSS->setState_TP(m_tlast, m_plast);
81  } else {
82  m_h0_RT[0] = m_hss_RT[0];
83  }
84  copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
85 }
86 
87 void
89 {
90  // Everything should be OK except for the water SS
92  if (m_p0 != m_plast) {
93  doublereal RT = GasConstant * m_tlast;
94  m_waterSS->setState_TP(m_tlast, m_p0);
95  m_g0_RT[0] = (m_waterSS->gibbs_mole()) / RT;
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  doublereal RT = GasConstant * m_tlast;
107  getGibbs_RT_ref(g);
108  for (size_t k = 0; k < m_kk; k++) {
109  g[k] *= RT;
110  }
111 }
112 
113 void
115 {
116  // Everything should be OK except for the water SS
118  if (m_p0 != m_plast) {
122  } else {
123  m_s0_R[0] = m_sss_R[0];
124  }
125  copy(m_s0_R.begin(), m_s0_R.end(), sr);
126 }
127 
128 void
130 {
131  // Everything should be OK except for the water SS
133  if (m_p0 != m_plast) {
135  m_cp0_R[0] = (m_waterSS->cp_mole()) / GasConstant;
137  } else {
138  m_cp0_R[0] = m_cpss_R[0];
139  }
140  copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
141 }
142 
143 void
145 {
146  // Everything should be OK except for the water SS
148  if (m_p0 != m_plast) {
152  } else {
153  m_V0[0] = m_Vss[0];
154  }
155  copy(m_V0.begin(), m_V0.end(), vol);
156 }
157 
159 {
161  m_spthermo->update(m_tlast, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
162  for (size_t k = 0; k < m_kk; k++) {
163  m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
164  PDSS* kPDSS = m_vptp_ptr->providePDSS(k);
165  kPDSS->setTemperature(m_tlast);
166  }
167  doublereal RT = GasConstant * m_tlast;
168  m_waterSS->setState_TP(m_tlast, m_p0);
169  m_h0_RT[0] = (m_waterSS->enthalpy_mole())/ RT;
171  m_cp0_R[0] = (m_waterSS->cp_mole()) / GasConstant;
172  m_g0_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
174  m_waterSS->setState_TP(m_tlast, m_plast);
175 }
176 
178 {
179  doublereal RT = GasConstant * m_tlast;
180  doublereal del_pRT = (m_plast - OneAtm) / (RT);
181 
182  for (size_t k = 1; k < m_kk; k++) {
183  m_hss_RT[k] = m_h0_RT[k] + del_pRT * m_Vss[k];
184  m_cpss_R[k] = m_cp0_R[k];
185  m_sss_R[k] = m_s0_R[k];
186  m_gss_RT[k] = m_hss_RT[k] - m_sss_R[k];
187  // m_Vss[k] constant
188  PDSS* kPDSS = m_vptp_ptr->providePDSS(k);
189  kPDSS->setState_TP(m_tlast, m_plast);
190  }
191  // Do the water
192  m_waterSS->setState_TP(m_tlast, m_plast);
193  m_hss_RT[0] = (m_waterSS->enthalpy_mole())/ RT;
196  m_gss_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
198 }
199 
201 {
203 }
204 
205 void
206 VPSSMgr_Water_ConstVol::initThermoXML(XML_Node& phaseNode, const std::string& id)
207 {
208  VPSSMgr::initThermoXML(phaseNode, id);
209 
210  XML_Node& speciesList = phaseNode.child("speciesArray");
211  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
212  &phaseNode.root());
213  const vector<string>&sss = m_vptp_ptr->speciesNames();
214 
215 
216  if (!m_waterSS) {
217  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
218  "bad dynamic cast");
219  }
220 
221  m_waterSS->setState_TP(300., OneAtm);
223 
224  for (size_t k = 1; k < m_kk; k++) {
225  const XML_Node* s = speciesDB->findByAttr("name", sss[k]);
226  if (!s) {
227  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
228  "no species Node for species " + sss[k]);
229  }
230  const XML_Node* ss = s->findByName("standardState");
231  if (!ss) {
232  std::string sName = s->operator[]("name");
233  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
234  "no standardState Node for species " + sName);
235  }
236  std::string model = (*ss)["model"];
237  if (model != "constant_incompressible") {
238  std::string sName = s->operator[]("name");
239  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
240  "standardState model for species isn't "
241  "constant_incompressible: " + sName);
242  }
243  m_Vss[k] = ctml::getFloat(*ss, "molarVolume", "toSI");
244  }
245 }
246 
247 PDSS*
249  const XML_Node* const phaseNode_ptr)
250 {
251  PDSS* kPDSS = 0;
252  // Will have to do something for water
253  // -> make sure it's species 0
254  // -> make sure it's designated as a real water EOS
255  if (k == 0) {
256  string xn = speciesNode["name"];
257  if (xn != "H2O(L)") {
258  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
259  "h2o wrong name: " + xn);
260  }
261  const XML_Node* ss = speciesNode.findByName("standardState");
262  std::string model = (*ss)["model"];
263  if (model != "waterIAPWS" && model != "waterPDSS") {
264  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
265  "wrong SS mode: " + model);
266  }
267  delete m_waterSS;
268  m_waterSS = new PDSS_Water(m_vptp_ptr, 0);
269  GeneralSpeciesThermo* genSpthermo = dynamic_cast<GeneralSpeciesThermo*>(m_spthermo);
270  if (!genSpthermo) {
271  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
272  "failed dynamic cast");
273  }
274  genSpthermo->installPDSShandler(k, m_waterSS, this);
275  kPDSS = m_waterSS;
276  } else {
277 
278  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
279 
280  const XML_Node* ss = speciesNode.findByName("standardState");
281  if (!ss) {
282  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
283  "no standardState Node for species " + speciesNode.name());
284  }
285  std::string model = (*ss)["model"];
286  if (model != "constant_incompressible") {
287  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
288  "standardState model for species isn't "
289  "constant_incompressible: " + speciesNode.name());
290  }
291  if (m_Vss.size() < k+1) {
292  m_Vss.resize(k+1, 0.0);
293  }
294  m_Vss[k] = ctml::getFloat(*ss, "molarVolume", "toSI");
295 
296  // instantiate a new kPDSS object
297  kPDSS = new PDSS_ConstVol(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
298  }
299  return kPDSS;
300 }
301 
303 {
304  return cPDSS_UNDEF;
305 }
306 
308 {
310 }
311 }
vector_fp m_V0
Vector containing the species reference molar volumes.
Definition: VPSSMgr.h:778
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
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
PDSS_Water * m_waterSS
Pointer to the Water PDSS object.
bool m_useTmpRefStateStorage
Definition: VPSSMgr.h:751
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
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:238
VPSSMgr_Water_ConstVol & operator=(const VPSSMgr_Water_ConstVol &right)
Assignment operator.
VPSSMgr & operator=(const VPSSMgr &right)
Assignment operator.
Definition: VPSSMgr.cpp:67
bool m_useTmpStandardStateStorage
Definition: VPSSMgr.h:784
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:393
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...
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...
doublereal getFloat(const Cantera::XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:267
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:143
virtual void initThermo()
Definition: VPSSMgr.cpp:360
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_Water.cpp:442
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: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
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
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 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.
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS.cpp:384
VPStandardStateTP * m_vptp_ptr
Variable pressure ThermoPhase object.
Definition: VPSSMgr.h:719
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:26
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: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
std::string name() const
Returns the name of the XML node.
Definition: xml.h:390
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:287
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
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: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
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
Headers for a completely general species thermodynamic property manager for a phase (see Managers for...
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
doublereal m_p0
Definition: VPSSMgr.h:739
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
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:725
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:440
doublereal m_tlast
The last temperature at which the standard state thermodynamic properties were calculated at...
Definition: VPSSMgr.h:729
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 setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS.cpp:398
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
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:775
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.