Cantera  2.1.2
PDSS_IdealGas.cpp
Go to the documentation of this file.
1 /**
2  * @file PDSS_IdealGas.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"
17 
18 #include <fstream>
19 
20 using namespace std;
21 
22 namespace Cantera
23 {
24 PDSS_IdealGas::PDSS_IdealGas(VPStandardStateTP* tp, int spindex) :
25  PDSS(tp, spindex)
26 {
27  m_pdssType = cPDSS_IDEALGAS;
28 }
29 
31  const std::string& inputFile, const std::string& id) :
32  PDSS(tp, spindex)
33 {
34  m_pdssType = cPDSS_IDEALGAS;
35  constructPDSSFile(tp, spindex, inputFile, id);
36 }
37 
38 PDSS_IdealGas::PDSS_IdealGas(VPStandardStateTP* tp, size_t spindex, const XML_Node& speciesNode,
39  const XML_Node& phaseRoot, bool spInstalled) :
40  PDSS(tp, spindex)
41 {
42  if (!spInstalled) {
43  throw CanteraError("PDSS_IdealGas", "sp installing not done yet");
44  }
45  m_pdssType = cPDSS_IDEALGAS;
46  std::string id = "";
47  constructPDSSXML(tp, spindex, phaseRoot, id);
48 }
49 
51  PDSS(b)
52 {
53  /*
54  * Use the assignment operator to do the brunt
55  * of the work for the copy constructor.
56  */
57  *this = b;
58 }
59 
61 {
62  if (&b == this) {
63  return *this;
64  }
65  PDSS::operator=(b);
66  return *this;
67 }
68 
70 {
71  return new PDSS_IdealGas(*this);
72 }
73 
75  const XML_Node& phaseNode, const std::string& id)
76 {
77  //initThermo();
78  //initThermoXML(phaseNode, id);
79 }
80 
82  const std::string& inputFile,
83  const std::string& id)
84 {
85  if (inputFile.size() == 0) {
86  throw CanteraError("PDSS_IdealGas::constructPDSSFile",
87  "input file is null");
88  }
89  std::string path = findInputFile(inputFile);
90  ifstream fin(path.c_str());
91  if (!fin) {
92  throw CanteraError("PDSS_IdealGas::constructPDSSFile","could not open "
93  +path+" for reading.");
94  }
95  /*
96  * The phase object automatically constructs an XML object.
97  * Use this object to store information.
98  */
99 
100  XML_Node* fxml = new XML_Node();
101  fxml->build(fin);
102  XML_Node* fxml_phase = findXMLPhase(fxml, id);
103  if (!fxml_phase) {
104  throw CanteraError("PDSS_IdealGas::constructPDSSFile",
105  "ERROR: Can not find phase named " +
106  id + " in file named " + inputFile);
107  }
108  constructPDSSXML(tp, spindex, *fxml_phase, id);
109  delete fxml;
110 }
111 
112 void PDSS_IdealGas::initThermoXML(const XML_Node& phaseNode, const std::string& id)
113 {
114  PDSS::initThermoXML(phaseNode, id);
115 }
116 
118 {
121  m_p0 = sp.refPressure(m_spindex);
124 }
125 
126 doublereal
128 {
129  doublereal val = enthalpy_RT();
130  doublereal RT = GasConstant * m_temp;
131  return val * RT;
132 }
133 
134 doublereal
136 {
137  return m_h0_RT_ptr[m_spindex];
138 }
139 
140 doublereal
142 {
143  doublereal val = m_h0_RT_ptr[m_spindex] - 1.0;
144  doublereal RT = GasConstant * m_temp;
145  return val * RT;
146 }
147 
148 doublereal
150 {
151  doublereal val = entropy_R();
152  return val * GasConstant;
153 }
154 
155 doublereal
157 {
158  return m_s0_R_ptr[m_spindex] - log(m_pres/m_p0);
159 }
160 
161 doublereal
163 {
164  doublereal val = gibbs_RT();
165  doublereal RT = GasConstant * m_temp;
166  return val * RT;
167 }
168 
169 doublereal
171 {
172  return m_g0_RT_ptr[m_spindex] + log(m_pres/m_p0);
173 }
174 
175 doublereal
177 {
178  doublereal val = cp_R();
179  return val * GasConstant;
180 }
181 
182 doublereal
184 {
185  return m_cp0_R_ptr[m_spindex];
186 }
187 
188 doublereal
190 {
191  return GasConstant * m_temp / m_pres;
192 }
193 
194 
195 doublereal
197 {
198  return m_pres * m_mw / (GasConstant * m_temp);
199 }
200 
201 doublereal
203 {
204  return cp_mole() - GasConstant;
205 }
206 
207 doublereal
209 {
210  return m_g0_RT_ptr[m_spindex];
211 }
212 
214 {
215  return m_h0_RT_ptr[m_spindex];
216 }
217 
219 {
220  return m_s0_R_ptr[m_spindex];
221 }
222 
223 doublereal PDSS_IdealGas::cp_R_ref() const
224 {
225  return cp_R();
226 }
227 
229 {
230  return GasConstant * m_temp / m_p0;
231 }
232 
233 doublereal PDSS_IdealGas::pressure() const
234 {
235  throw CanteraError("PDSS_IdealGas::pressure()", "unimplemented");
236  return 0.0;
237 }
238 
239 void PDSS_IdealGas::setPressure(doublereal p)
240 {
244 }
245 
247 {
248  throw CanteraError("PDSS_IdealGas::critTemperature()", "unimplemented");
249  return 0.0;
250 }
251 
252 doublereal PDSS_IdealGas::critPressure() const
253 {
254  throw CanteraError("PDSS_IdealGas::critPressure()", "unimplemented");
255  return 0.0;
256 }
257 
258 doublereal PDSS_IdealGas::critDensity() const
259 {
260  throw CanteraError("PDSS_IdealGas::critDensity()", "unimplemented");
261  return 0.0;
262 }
263 
264 doublereal PDSS_IdealGas::temperature() const
265 {
267  return m_temp;
268 }
269 
270 void PDSS_IdealGas::setTemperature(doublereal temp)
271 {
272  m_temp = temp;
277 
280  m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex] + log(m_pres/m_p0);
283 }
284 
285 void PDSS_IdealGas::setState_TP(doublereal temp, doublereal pres)
286 {
287  m_pres = pres;
288  setTemperature(temp);
289 }
290 
291 void PDSS_IdealGas::setState_TR(doublereal temp, doublereal rho)
292 {
293  m_pres = GasConstant * temp * rho / m_mw;
294  setTemperature(temp);
295 }
296 
297 doublereal PDSS_IdealGas::satPressure(doublereal t)
298 {
299  throw CanteraError("PDSS_IdealGas::satPressure()", "unimplemented");
300  /*NOTREACHED*/
301  return 0.0;
302 }
303 
304 }
doublereal temperature() const
Return the temperature stored in the object.
Definition: VPSSMgr.h:499
virtual void initThermo()
Initialization routine for all of the shallow pointers.
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 enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
virtual doublereal critPressure() const
critical pressure
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
virtual void setTemperature(doublereal temp)
Set the internal temperature.
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_h0_RT_ptr
Reference state enthalpy divided by RT.
Definition: PDSS.h:622
virtual doublereal satPressure(doublereal t)
saturation pressure
PDSS_IdealGas & operator=(const PDSS_IdealGas &b)
Assignment operator.
virtual doublereal maxTemp(size_t k=npos) const =0
Maximum temperature.
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 entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
virtual doublereal critDensity() const
critical density
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and 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
PDSS_IdealGas(VPStandardStateTP *tp, int spindex)
Constructor.
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
virtual doublereal gibbs_RT_ref() const
Return the molar gibbs free energy divided by RT at reference pressure.
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
VPSSMgr * m_vpssmgr_ptr
Pointer to the VPSS manager for this object.
Definition: PDSS.h:596
size_t m_spindex
Species index in the ThermoPhase corresponding to this species.
Definition: PDSS.h:606
virtual doublereal enthalpy_mole() const
Return the molar enthalpy in units of J kmol-1.
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
virtual PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
Pure Virtual base class for the species thermo manager classes.
doublereal * m_sss_R_ptr
Standard state entropy divided by R.
Definition: PDSS.h:670
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
Declarations for the class PDSS_IdealGas (pressure dependent standard state) which handles calculatio...
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:183
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
virtual doublereal density() const
Return the standard state density at standard state.
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Classes providing support for XML data files.
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
virtual doublereal refPressure(size_t k=npos) const =0
The reference-state pressure for species k.
virtual void setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
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
void constructPDSSXML(VPStandardStateTP *vptp_ptr, size_t spindex, const XML_Node &phaseNode, const std::string &id)
Initialization of a PDSS object using an xml tree.
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:585
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.
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.
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
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 cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
doublereal * m_g0_RT_ptr
Reference state Gibbs free energy divided by RT.
Definition: PDSS.h:642
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
doublereal * m_cp0_R_ptr
Reference state heat capacity divided by R.
Definition: PDSS.h:629
virtual doublereal gibbs_mole() const
Return the molar Gibbs free energy in units of J kmol-1.
virtual SpeciesThermo & speciesThermo(int k=-1)
Return a changeable reference to the calculation manager for species reference-state thermodynamic pr...
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
Derived class for pressure dependent standard states of an ideal gas species.
Definition: PDSS_IdealGas.h:28
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
virtual doublereal pressure() const
Returns the pressure (Pa)
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
virtual doublereal critTemperature() const
critical temperature
void build(std::istream &f)
Main routine to create an tree-like representation of an XML file.
Definition: xml.cpp:776
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