Cantera  2.1.2
PDSS_ConstVol.cpp
Go to the documentation of this file.
1 /**
2  * @file PDSS_ConstVol.cpp
3  * Implementation of a pressure dependent standard state
4  * virtual function.
5  */
6 /*
7  * Copyright (2006) Sandia Corporation. Under the terms of
8  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
9  * U.S. Government retains certain rights in this software.
10  */
11 #include "cantera/base/ct_defs.h"
12 #include "cantera/base/xml.h"
13 #include "cantera/base/ctml.h"
16 
18 
19 #include <fstream>
20 
21 using namespace std;
22 
23 namespace Cantera
24 {
25 PDSS_ConstVol::PDSS_ConstVol(VPStandardStateTP* tp, size_t spindex) :
26  PDSS(tp, spindex)
27 {
28  m_pdssType = cPDSS_CONSTVOL;
29 }
30 
32  const std::string& inputFile, const std::string& id) :
33  PDSS(tp, spindex)
34 {
35  m_pdssType = cPDSS_CONSTVOL;
36  constructPDSSFile(tp, spindex, inputFile, id);
37 }
38 
40  const XML_Node& speciesNode,
41  const XML_Node& phaseRoot,
42  bool spInstalled) :
43  PDSS(tp, spindex)
44 {
45  m_pdssType = cPDSS_CONSTVOL;
46  constructPDSSXML(tp, spindex, speciesNode, phaseRoot, spInstalled) ;
47 }
48 
50  PDSS(b)
51 {
52  /*
53  * Use the assignment operator to do the brunt
54  * of the work for the copy constructor.
55  */
56  *this = b;
57 }
58 
60 {
61  if (&b == this) {
62  return *this;
63  }
64  PDSS::operator=(b);
66  return *this;
67 }
68 
70 {
71  return new PDSS_ConstVol(*this);
72 }
73 
75  const XML_Node& speciesNode,
76  const XML_Node& phaseNode, bool spInstalled)
77 {
81 
82  if (!spInstalled) {
83  throw CanteraError("PDSS_ConstVol::constructPDSSXML", "spInstalled false not handled");
84  }
85 
86  const XML_Node* ss = speciesNode.findByName("standardState");
87  if (!ss) {
88  throw CanteraError("PDSS_ConstVol::constructPDSSXML",
89  "no standardState Node for species " + speciesNode.name());
90  }
91  std::string model = (*ss)["model"];
92  if (model != "constant_incompressible") {
93  throw CanteraError("PDSS_ConstVol::initThermoXML",
94  "standardState model for species isn't constant_incompressible: " + speciesNode.name());
95  }
96 
97  m_constMolarVolume = ctml::getFloat(*ss, "molarVolume", "toSI");
98 
99  std::string id = "";
100  // initThermoXML(phaseNode, id);
101 }
102 
104  const std::string& inputFile,
105  const std::string& id)
106 {
107  if (inputFile.size() == 0) {
108  throw CanteraError("PDSS_ConstVol::initThermo",
109  "input file is null");
110  }
111  std::string path = findInputFile(inputFile);
112  ifstream fin(path.c_str());
113  if (!fin) {
114  throw CanteraError("PDSS_ConstVol::initThermo","could not open "
115  +path+" for reading.");
116  }
117  /*
118  * The phase object automatically constructs an XML object.
119  * Use this object to store information.
120  */
121 
122  XML_Node* fxml = new XML_Node();
123  fxml->build(fin);
124  XML_Node* fxml_phase = findXMLPhase(fxml, id);
125  if (!fxml_phase) {
126  throw CanteraError("PDSS_ConstVol::initThermo",
127  "ERROR: Can not find phase named " +
128  id + " in file named " + inputFile);
129  }
130 
131  XML_Node& speciesList = fxml_phase->child("speciesArray");
132  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
133  &(fxml_phase->root()));
134  const vector<string>&sss = tp->speciesNames();
135  const XML_Node* s = speciesDB->findByAttr("name", sss[spindex]);
136 
137  constructPDSSXML(tp, spindex, *s, *fxml_phase, true);
138  delete fxml;
139 }
140 
141 void PDSS_ConstVol::initThermoXML(const XML_Node& phaseNode, const std::string& id)
142 {
143  PDSS::initThermoXML(phaseNode, id);
148 }
149 
151 {
154  m_p0 = sp.refPressure(m_spindex);
157 }
158 
159 doublereal
161 {
162  doublereal val = enthalpy_RT();
163  doublereal RT = GasConstant * m_temp;
164  return val * RT;
165 }
166 
167 doublereal
169 {
170  return m_hss_RT_ptr[m_spindex];
171 }
172 
173 doublereal
175 {
176  doublereal pVRT = (m_pres * m_Vss_ptr[m_spindex]) / (GasConstant * m_temp);
177  doublereal val = m_h0_RT_ptr[m_spindex] - pVRT;
178  doublereal RT = GasConstant * m_temp;
179  return val * RT;
180 }
181 
182 doublereal
184 {
185  doublereal val = entropy_R();
186  return val * GasConstant;
187 }
188 
189 doublereal
191 {
192  return m_sss_R_ptr[m_spindex];
193 }
194 
195 doublereal
197 {
198  doublereal val = gibbs_RT();
199  doublereal RT = GasConstant * m_temp;
200  return val * RT;
201 }
202 
203 doublereal
205 {
206  return m_gss_RT_ptr[m_spindex];
207 }
208 
209 doublereal
211 {
212  doublereal val = m_cpss_R_ptr[m_spindex];
213  return val * GasConstant;
214 }
215 
216 doublereal
218 {
219  return m_cpss_R_ptr[m_spindex];
220 }
221 
222 doublereal
224 {
225  return (cp_mole() - m_V0_ptr[m_spindex]);
226 }
227 
228 doublereal
230 {
231  return m_Vss_ptr[m_spindex];
232 }
233 
234 doublereal
236 {
237  doublereal val = m_Vss_ptr[m_spindex];
238  return m_mw/val;
239 }
240 
241 doublereal
243 {
244  return m_g0_RT_ptr[m_spindex];
245 }
246 
248 {
249  return m_h0_RT_ptr[m_spindex];
250 }
251 
253 {
254  return m_s0_R_ptr[m_spindex];
255 }
256 
257 doublereal PDSS_ConstVol::cp_R_ref() const
258 {
259  doublereal val = m_cp0_R_ptr[m_spindex];
260  return (val);
261 }
262 
264 {
265  return m_V0_ptr[m_spindex];
266 }
267 
269 {
270  throw CanteraError("PDSS_ConstVol::critTemperature()", "unimplemented");
271  return 0.0;
272 }
273 
274 doublereal PDSS_ConstVol::critPressure() const
275 {
276  throw CanteraError("PDSS_ConstVol::critPressure()", "unimplemented");
277  return 0.0;
278 }
279 
280 doublereal PDSS_ConstVol::critDensity() const
281 {
282  throw CanteraError("PDSS_ConstVol::critDensity()", "unimplemented");
283  return 0.0;
284 }
285 
286 void PDSS_ConstVol::setPressure(doublereal p)
287 {
288  m_pres = p;
289  doublereal del_pRT = (m_pres - m_p0) / (GasConstant * m_temp);
292 }
293 
294 void PDSS_ConstVol::setTemperature(doublereal temp)
295 {
296  m_temp = temp;
300 
301  doublereal del_pRT = (m_pres - m_p0) / (GasConstant * m_temp);
302 
305  m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex];
307 
308 }
309 
310 void PDSS_ConstVol::setState_TP(doublereal temp, doublereal pres)
311 {
312  setTemperature(temp);
313  setPressure(pres);
314 }
315 
316 void PDSS_ConstVol::setState_TR(doublereal temp, doublereal rho)
317 {
318  doublereal rhoStored = m_mw / m_constMolarVolume;
319  if (fabs(rhoStored - rho) / (rhoStored + rho) > 1.0E-4) {
320  throw CanteraError("PDSS_ConstVol::setState_TR",
321  "Inconsistent supplied rho");
322  }
323  setTemperature(temp);
324 }
325 
326 doublereal PDSS_ConstVol::satPressure(doublereal t)
327 {
328  return 1.0E-200;
329 }
330 
331 }
virtual void setTemperature(doublereal temp)
Set the internal temperature.
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
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
XML_Node * findXMLPhase(XML_Node *root, const std::string &idtarget)
Search an XML_Node tree for a named phase XML_Node.
Definition: xml.cpp:1104
SpeciesThermo * m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:615
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
virtual doublereal gibbs_RT_ref() const
Return the molar gibbs free energy divided by RT at reference pressure.
doublereal * m_cpss_R_ptr
Standard state heat capacity divided by R.
Definition: PDSS.h:663
std::string findInputFile(const std::string &name)
Find an input file.
Definition: global.cpp:191
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
Definition: PDSS.cpp:175
doublereal m_constMolarVolume
Value of the constant molar volume for the species.
doublereal * m_h0_RT_ptr
Reference state enthalpy divided by RT.
Definition: PDSS.h:622
virtual doublereal maxTemp(size_t k=npos) const =0
Maximum temperature.
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
virtual void update_one(size_t k, doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Like update(), but only updates the single species k.
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:576
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
virtual doublereal molarVolume() const
Return the molar volume at standard state.
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
virtual doublereal density() const
Return the standard state density at standard state.
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
void constructPDSSFile(VPStandardStateTP *vptp_ptr, size_t spindex, const std::string &inputFile, const std::string &id)
Initialization of a PDSS object using an input XML file.
size_t m_spindex
Species index in the ThermoPhase corresponding to this species.
Definition: PDSS.h:606
virtual void setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
doublereal * m_gss_RT_ptr
Standard state Gibbs free energy divided by RT.
Definition: PDSS.h:677
PDSS_enumType m_pdssType
Enumerated type describing the type of the PDSS object.
Definition: PDSS.h:570
Pure Virtual base class for the species thermo manager classes.
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
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
doublereal * m_sss_R_ptr
Standard state entropy divided by R.
Definition: PDSS.h:670
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
virtual doublereal satPressure(doublereal t)
saturation pressure
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
PDSS_ConstVol(VPStandardStateTP *tp, size_t spindex)
Constructor.
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:183
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
virtual doublereal gibbs_mole() const
Return the molar Gibbs free energy in units of J kmol-1.
Class for pressure dependent standard states that use a constant volume model.
Definition: PDSS_ConstVol.h:26
virtual doublereal enthalpy_mole() const
Return the molar enthalpy in units of J kmol-1.
std::string name() const
Returns the name of the XML node.
Definition: xml.h:390
Classes providing support for XML data files.
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
virtual doublereal refPressure(size_t k=npos) const =0
The reference-state pressure for species k.
doublereal * m_s0_R_ptr
Reference state entropy divided by R.
Definition: PDSS.h:636
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
PDSS_ConstVol & operator=(const PDSS_ConstVol &b)
Assignment operator.
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual doublereal critDensity() const
critical density
virtual PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:585
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:582
doublereal * m_hss_RT_ptr
Standard state enthalpy divided by RT.
Definition: PDSS.h:656
virtual doublereal minTemp(size_t k=npos) const =0
Minimum temperature.
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
Definition: Phase.cpp:252
virtual doublereal critTemperature() const
critical temperature
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
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:195
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
VPStandardStateTP * m_tp
ThermoPhase which this species belongs to.
Definition: PDSS.h:593
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:573
PDSS & operator=(const PDSS &b)
Assignment operator.
Definition: PDSS.cpp:110
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
doublereal * m_g0_RT_ptr
Reference state Gibbs free energy divided by RT.
Definition: PDSS.h:642
void constructPDSSXML(VPStandardStateTP *vptp_ptr, size_t spindex, const XML_Node &speciesNode, const XML_Node &phaseNode, bool spInstalled)
Initialization of a PDSS object using an xml tree.
Declarations for the class PDSS_ConstVol (pressure dependent standard state) which handles calculatio...
doublereal * m_cp0_R_ptr
Reference state heat capacity divided by R.
Definition: PDSS.h:629
virtual SpeciesThermo & speciesThermo(int k=-1)
Return a changeable reference to the calculation manager for species reference-state thermodynamic pr...
virtual void initThermo()
Initialization routine for all of the shallow pointers.
virtual doublereal critPressure() const
critical pressure
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
doublereal * m_Vss_ptr
Standard State molar volume (m3 kg-1)
Definition: PDSS.h:684
doublereal * m_V0_ptr
Reference state molar volume (m3 kg-1)
Definition: PDSS.h:649
XML_Node & root() const
Return the root of the current XML_Node tree.
Definition: xml.cpp:1091
void build(std::istream &f)
Main routine to create an tree-like representation of an XML file.
Definition: xml.cpp:776
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
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:579
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:601