Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/ctml.h"
14 
15 #include <fstream>
16 
17 using namespace std;
18 
19 namespace Cantera
20 {
21 PDSS_ConstVol::PDSS_ConstVol(VPStandardStateTP* tp, size_t spindex) :
22  PDSS(tp, spindex)
23 {
24  m_pdssType = cPDSS_CONSTVOL;
25 }
26 
28  const std::string& inputFile, const std::string& id) :
29  PDSS(tp, spindex)
30 {
31  m_pdssType = cPDSS_CONSTVOL;
32  constructPDSSFile(tp, spindex, inputFile, id);
33 }
34 
36  const XML_Node& speciesNode,
37  const XML_Node& phaseRoot,
38  bool spInstalled) :
39  PDSS(tp, spindex)
40 {
41  m_pdssType = cPDSS_CONSTVOL;
42  constructPDSSXML(tp, spindex, speciesNode, phaseRoot, spInstalled) ;
43 }
44 
46  PDSS(b)
47 {
48  /*
49  * Use the assignment operator to do the brunt
50  * of the work for the copy constructor.
51  */
52  *this = b;
53 }
54 
56 {
57  if (&b == this) {
58  return *this;
59  }
60  PDSS::operator=(b);
62  return *this;
63 }
64 
66 {
67  return new PDSS_ConstVol(*this);
68 }
69 
71  const XML_Node& speciesNode,
72  const XML_Node& phaseNode, bool spInstalled)
73 {
76 
77  if (!spInstalled) {
78  throw CanteraError("PDSS_ConstVol::constructPDSSXML", "spInstalled false not handled");
79  }
80 
81  const XML_Node* ss = speciesNode.findByName("standardState");
82  if (!ss) {
83  throw CanteraError("PDSS_ConstVol::constructPDSSXML",
84  "no standardState Node for species " + speciesNode.name());
85  }
86  if (ss->attrib("model") != "constant_incompressible") {
87  throw CanteraError("PDSS_ConstVol::initThermoXML",
88  "standardState model for species isn't constant_incompressible: " + speciesNode.name());
89  }
90 
91  m_constMolarVolume = getFloat(*ss, "molarVolume", "toSI");
92 }
93 
95  const std::string& inputFile,
96  const std::string& id)
97 {
98  if (inputFile.size() == 0) {
99  throw CanteraError("PDSS_ConstVol::initThermo",
100  "input file is null");
101  }
102  std::string path = findInputFile(inputFile);
103  ifstream fin(path.c_str());
104  if (!fin) {
105  throw CanteraError("PDSS_ConstVol::initThermo","could not open "
106  +path+" for reading.");
107  }
108  /*
109  * The phase object automatically constructs an XML object.
110  * Use this object to store information.
111  */
112 
113  XML_Node fxml;
114  fxml.build(fin);
115  XML_Node* fxml_phase = findXMLPhase(&fxml, id);
116  if (!fxml_phase) {
117  throw CanteraError("PDSS_ConstVol::initThermo",
118  "ERROR: Can not find phase named " +
119  id + " in file named " + inputFile);
120  }
121 
122  XML_Node& speciesList = fxml_phase->child("speciesArray");
123  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
124  &(fxml_phase->root()));
125  const XML_Node* s = speciesDB->findByAttr("name", tp->speciesName(spindex));
126 
127  constructPDSSXML(tp, spindex, *s, *fxml_phase, true);
128 }
129 
130 void PDSS_ConstVol::initThermoXML(const XML_Node& phaseNode, const std::string& id)
131 {
132  PDSS::initThermoXML(phaseNode, id);
137 }
138 
140 {
145 }
146 
147 doublereal
149 {
150  return m_hss_RT_ptr[m_spindex];
151 }
152 
153 doublereal
155 {
156  doublereal pV = (m_pres * m_Vss_ptr[m_spindex]);
157  return m_h0_RT_ptr[m_spindex] * GasConstant * m_temp - pV;
158 }
159 
160 doublereal
162 {
163  return m_sss_R_ptr[m_spindex];
164 }
165 
166 doublereal
168 {
169  return m_gss_RT_ptr[m_spindex];
170 }
171 
172 doublereal
174 {
175  return m_cpss_R_ptr[m_spindex];
176 }
177 
178 doublereal
180 {
181  return (cp_mole() - m_V0_ptr[m_spindex]);
182 }
183 
184 doublereal
186 {
187  return m_Vss_ptr[m_spindex];
188 }
189 
190 doublereal
192 {
193  return m_mw / m_Vss_ptr[m_spindex];
194 }
195 
196 doublereal
198 {
199  return m_g0_RT_ptr[m_spindex];
200 }
201 
203 {
204  return m_h0_RT_ptr[m_spindex];
205 }
206 
208 {
209  return m_s0_R_ptr[m_spindex];
210 }
211 
212 doublereal PDSS_ConstVol::cp_R_ref() const
213 {
214  return m_cp0_R_ptr[m_spindex];
215 }
216 
218 {
219  return m_V0_ptr[m_spindex];
220 }
221 
222 void PDSS_ConstVol::setPressure(doublereal p)
223 {
224  m_pres = p;
225  doublereal del_pRT = (m_pres - m_p0) / (GasConstant * m_temp);
228 }
229 
230 void PDSS_ConstVol::setTemperature(doublereal temp)
231 {
232  m_temp = temp;
236 
237  doublereal del_pRT = (m_pres - m_p0) / (GasConstant * m_temp);
238 
241  m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex];
243 
244 }
245 
246 void PDSS_ConstVol::setState_TP(doublereal temp, doublereal pres)
247 {
248  setTemperature(temp);
249  setPressure(pres);
250 }
251 
252 void PDSS_ConstVol::setState_TR(doublereal temp, doublereal rho)
253 {
254  doublereal rhoStored = m_mw / m_constMolarVolume;
255  if (fabs(rhoStored - rho) / (rhoStored + rho) > 1.0E-4) {
256  throw CanteraError("PDSS_ConstVol::setState_TR",
257  "Inconsistent supplied rho");
258  }
259  setTemperature(temp);
260 }
261 
262 doublereal PDSS_ConstVol::satPressure(doublereal t)
263 {
264  return 1.0E-200;
265 }
266 
267 }
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:704
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:494
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:1108
SpeciesThermo * m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:604
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:527
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:652
std::string findInputFile(const std::string &name)
Find an input file.
Definition: global.cpp:156
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
Definition: PDSS.cpp:165
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:611
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.
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:565
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.
virtual doublereal density() const
Return the standard state density at standard state.
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:595
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:666
PDSS_enumType m_pdssType
Enumerated type describing the type of the PDSS object.
Definition: PDSS.h:559
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:573
doublereal * m_sss_R_ptr
Standard state entropy divided by R.
Definition: PDSS.h:659
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:742
PDSS_ConstVol(VPStandardStateTP *tp, size_t spindex)
Constructor.
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:173
Class for pressure dependent standard states that use a constant volume model.
Definition: PDSS_ConstVol.h:23
std::string name() const
Returns the name of the XML node.
Definition: xml.h:394
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:625
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
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 PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:574
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:571
doublereal * m_hss_RT_ptr
Standard state enthalpy divided by RT.
Definition: PDSS.h:645
virtual doublereal minTemp(size_t k=npos) const =0
Minimum temperature.
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS.cpp:429
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:193
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:582
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:562
PDSS & operator=(const PDSS &b)
Assignment operator.
Definition: PDSS.cpp:104
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
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
doublereal * m_g0_RT_ptr
Reference state Gibbs free energy divided by RT.
Definition: PDSS.h:631
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:618
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 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:673
doublereal * m_V0_ptr
Reference state molar volume (m3 kg-1)
Definition: PDSS.h:638
XML_Node & root() const
Return the root of the current XML_Node tree.
Definition: xml.cpp:1095
void build(std::istream &f)
Main routine to create an tree-like representation of an XML file.
Definition: xml.cpp:764
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:272
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
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:568
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:590