Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/ctml.h"
14 
15 #include <fstream>
16 
17 using namespace std;
18 
19 namespace Cantera
20 {
21 PDSS_IdealGas::PDSS_IdealGas(VPStandardStateTP* tp, int spindex) :
22  PDSS(tp, spindex)
23 {
24  m_pdssType = cPDSS_IDEALGAS;
25 }
26 
28  const std::string& inputFile, const std::string& id) :
29  PDSS(tp, spindex)
30 {
31  m_pdssType = cPDSS_IDEALGAS;
32  constructPDSSFile(tp, spindex, inputFile, id);
33 }
34 
35 PDSS_IdealGas::PDSS_IdealGas(VPStandardStateTP* tp, size_t spindex, const XML_Node& speciesNode,
36  const XML_Node& phaseRoot, bool spInstalled) :
37  PDSS(tp, spindex)
38 {
39  if (!spInstalled) {
40  throw CanteraError("PDSS_IdealGas", "sp installing not done yet");
41  }
42  m_pdssType = cPDSS_IDEALGAS;
43  constructPDSSXML(tp, spindex, phaseRoot, "");
44 }
45 
47  PDSS(b)
48 {
49  /*
50  * Use the assignment operator to do the brunt
51  * of the work for the copy constructor.
52  */
53  *this = b;
54 }
55 
57 {
58  if (&b == this) {
59  return *this;
60  }
61  PDSS::operator=(b);
62  return *this;
63 }
64 
66 {
67  return new PDSS_IdealGas(*this);
68 }
69 
71  const XML_Node& phaseNode, const std::string& id)
72 {
73 }
74 
76  const std::string& inputFile,
77  const std::string& id)
78 {
79  if (inputFile.size() == 0) {
80  throw CanteraError("PDSS_IdealGas::constructPDSSFile",
81  "input file is null");
82  }
83  std::string path = findInputFile(inputFile);
84  ifstream fin(path.c_str());
85  if (!fin) {
86  throw CanteraError("PDSS_IdealGas::constructPDSSFile","could not open "
87  +path+" for reading.");
88  }
89  /*
90  * The phase object automatically constructs an XML object.
91  * Use this object to store information.
92  */
93 
94  XML_Node fxml;
95  fxml.build(fin);
96  XML_Node* fxml_phase = findXMLPhase(&fxml, id);
97  if (!fxml_phase) {
98  throw CanteraError("PDSS_IdealGas::constructPDSSFile",
99  "ERROR: Can not find phase named " +
100  id + " in file named " + inputFile);
101  }
102  constructPDSSXML(tp, spindex, *fxml_phase, id);
103 }
104 
106 {
111 }
112 
113 doublereal
115 {
116  return m_h0_RT_ptr[m_spindex];
117 }
118 
119 doublereal
121 {
122  return (m_h0_RT_ptr[m_spindex] - 1.0) * GasConstant * m_temp;
123 }
124 
125 doublereal
127 {
128  return m_s0_R_ptr[m_spindex] - log(m_pres/m_p0);
129 }
130 
131 doublereal
133 {
134  return m_g0_RT_ptr[m_spindex] + log(m_pres/m_p0);
135 }
136 
137 doublereal
139 {
140  return m_cp0_R_ptr[m_spindex];
141 }
142 
143 doublereal
145 {
146  return GasConstant * m_temp / m_pres;
147 }
148 
149 
150 doublereal
152 {
153  return m_pres * m_mw / (GasConstant * m_temp);
154 }
155 
156 doublereal
158 {
159  return cp_mole() - GasConstant;
160 }
161 
162 doublereal
164 {
165  return m_g0_RT_ptr[m_spindex];
166 }
167 
169 {
170  return m_h0_RT_ptr[m_spindex];
171 }
172 
174 {
175  return m_s0_R_ptr[m_spindex];
176 }
177 
178 doublereal PDSS_IdealGas::cp_R_ref() const
179 {
180  return cp_R();
181 }
182 
184 {
185  return GasConstant * m_temp / m_p0;
186 }
187 
188 doublereal PDSS_IdealGas::pressure() const
189 {
190  throw CanteraError("PDSS_IdealGas::pressure()", "unimplemented");
191 }
192 
193 void PDSS_IdealGas::setPressure(doublereal p)
194 {
198 }
199 
200 doublereal PDSS_IdealGas::temperature() const
201 {
203  return m_temp;
204 }
205 
206 void PDSS_IdealGas::setTemperature(doublereal temp)
207 {
208  m_temp = temp;
213 
216  m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex] + log(m_pres/m_p0);
219 }
220 
221 void PDSS_IdealGas::setState_TP(doublereal temp, doublereal pres)
222 {
223  m_pres = pres;
224  setTemperature(temp);
225 }
226 
227 void PDSS_IdealGas::setState_TR(doublereal temp, doublereal rho)
228 {
229  m_pres = GasConstant * temp * rho / m_mw;
230  setTemperature(temp);
231 }
232 
233 }
doublereal temperature() const
Return the temperature stored in the object.
Definition: VPSSMgr.h:494
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:1108
SpeciesThermo * m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:604
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference 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:652
std::string findInputFile(const std::string &name)
Find an input file.
Definition: global.cpp:156
doublereal * m_h0_RT_ptr
Reference state enthalpy divided by RT.
Definition: PDSS.h:611
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.
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:565
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.
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:585
size_t m_spindex
Species index in the ThermoPhase corresponding to this species.
Definition: PDSS.h:595
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 PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
doublereal * m_sss_R_ptr
Standard state entropy divided by R.
Definition: PDSS.h:659
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 doublereal temperature() const
Return the current stored temperature.
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:173
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.
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:625
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
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:574
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.
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.
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS.cpp:429
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
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 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:631
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:618
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:673
doublereal * m_V0_ptr
Reference state molar volume (m3 kg-1)
Definition: PDSS.h:638
Derived class for pressure dependent standard states of an ideal gas species.
Definition: PDSS_IdealGas.h:25
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.
void build(std::istream &f)
Main routine to create an tree-like representation of an XML file.
Definition: xml.cpp:764
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