Cantera  2.3.0
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 // This file is part of Cantera. See License.txt in the top-level directory or
8 // at http://www.cantera.org/license.txt for license and copyright information.
9 
10 #include "cantera/base/ctml.h"
13 
14 using namespace std;
15 
16 namespace Cantera
17 {
18 PDSS_ConstVol::PDSS_ConstVol(VPStandardStateTP* tp, size_t spindex) :
19  PDSS(tp, spindex)
20 {
21  m_pdssType = cPDSS_CONSTVOL;
22 }
23 
25  const std::string& inputFile, const std::string& id) :
26  PDSS(tp, spindex)
27 {
28  warn_deprecated("PDSS_ConstVol constructor from XML input file",
29  "To be removed after Cantera 2.3.");
30  m_pdssType = cPDSS_CONSTVOL;
31  constructPDSSFile(tp, spindex, inputFile, id);
32 }
33 
35  const XML_Node& speciesNode,
36  const XML_Node& phaseRoot,
37  bool spInstalled) :
38  PDSS(tp, spindex)
39 {
40  m_pdssType = cPDSS_CONSTVOL;
41  constructPDSSXML(tp, spindex, speciesNode, phaseRoot, spInstalled);
42 }
43 
45  PDSS(b)
46 {
47  // Use the assignment operator to do the brunt of the work for the copy
48  // constructor.
49  *this = b;
50 }
51 
52 PDSS_ConstVol& PDSS_ConstVol::operator=(const PDSS_ConstVol& b)
53 {
54  if (&b == this) {
55  return *this;
56  }
57  PDSS::operator=(b);
58  m_constMolarVolume = b.m_constMolarVolume;
59  return *this;
60 }
61 
63 {
64  return new PDSS_ConstVol(*this);
65 }
66 
68  const XML_Node& speciesNode,
69  const XML_Node& phaseNode, bool spInstalled)
70 {
73 
74  if (!spInstalled) {
75  throw CanteraError("PDSS_ConstVol::constructPDSSXML", "spInstalled false not handled");
76  }
77 
78  const XML_Node* ss = speciesNode.findByName("standardState");
79  if (!ss) {
80  throw CanteraError("PDSS_ConstVol::constructPDSSXML",
81  "no standardState Node for species " + speciesNode.name());
82  }
83  if (ss->attrib("model") != "constant_incompressible") {
84  throw CanteraError("PDSS_ConstVol::initThermoXML",
85  "standardState model for species isn't constant_incompressible: " + speciesNode.name());
86  }
87 
88  m_constMolarVolume = getFloat(*ss, "molarVolume", "toSI");
89 }
90 
92  const std::string& inputFile,
93  const std::string& id)
94 {
95  warn_deprecated("PDSS_ConstVol::constructPDSSFile",
96  "To be removed after Cantera 2.3.");
97  if (inputFile.size() == 0) {
98  throw CanteraError("PDSS_ConstVol::initThermo",
99  "input file is null");
100  }
101 
102  // The phase object automatically constructs an XML object. Use this object
103  // to store information.
104  XML_Node fxml;
105  fxml.build(findInputFile(inputFile));
106  XML_Node* fxml_phase = findXMLPhase(&fxml, id);
107  if (!fxml_phase) {
108  throw CanteraError("PDSS_ConstVol::initThermo",
109  "ERROR: Can not find phase named " +
110  id + " in file named " + inputFile);
111  }
112 
113  XML_Node& speciesList = fxml_phase->child("speciesArray");
114  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
115  &fxml_phase->root());
116  const XML_Node* s = speciesDB->findByAttr("name", tp->speciesName(spindex));
117  constructPDSSXML(tp, spindex, *s, *fxml_phase, true);
118 }
119 
120 void PDSS_ConstVol::initThermoXML(const XML_Node& phaseNode, const std::string& id)
121 {
122  PDSS::initThermoXML(phaseNode, id);
127 }
128 
130 {
135 }
136 
137 doublereal PDSS_ConstVol::enthalpy_RT() const
138 {
139  return m_hss_RT_ptr[m_spindex];
140 }
141 
143 {
144  doublereal pV = (m_pres * m_Vss_ptr[m_spindex]);
145  return m_h0_RT_ptr[m_spindex] * GasConstant * m_temp - pV;
146 }
147 
148 doublereal PDSS_ConstVol::entropy_R() const
149 {
150  return m_sss_R_ptr[m_spindex];
151 }
152 
153 doublereal PDSS_ConstVol::gibbs_RT() const
154 {
155  return m_gss_RT_ptr[m_spindex];
156 }
157 
158 doublereal PDSS_ConstVol::cp_R() const
159 {
160  return m_cpss_R_ptr[m_spindex];
161 }
162 
163 doublereal PDSS_ConstVol::cv_mole() const
164 {
165  return (cp_mole() - m_V0_ptr[m_spindex]);
166 }
167 
168 doublereal PDSS_ConstVol::molarVolume() const
169 {
170  return m_Vss_ptr[m_spindex];
171 }
172 
173 doublereal PDSS_ConstVol::density() const
174 {
175  return m_mw / m_Vss_ptr[m_spindex];
176 }
177 
178 doublereal PDSS_ConstVol::gibbs_RT_ref() const
179 {
180  return m_g0_RT_ptr[m_spindex];
181 }
182 
184 {
185  return m_h0_RT_ptr[m_spindex];
186 }
187 
189 {
190  return m_s0_R_ptr[m_spindex];
191 }
192 
193 doublereal PDSS_ConstVol::cp_R_ref() const
194 {
195  return m_cp0_R_ptr[m_spindex];
196 }
197 
199 {
200  return m_V0_ptr[m_spindex];
201 }
202 
203 void PDSS_ConstVol::setPressure(doublereal p)
204 {
205  m_pres = p;
206  doublereal del_pRT = (m_pres - m_p0) / (GasConstant * m_temp);
209 }
210 
211 void PDSS_ConstVol::setTemperature(doublereal temp)
212 {
213  m_temp = temp;
217 
218  doublereal del_pRT = (m_pres - m_p0) / (GasConstant * m_temp);
219 
224 }
225 
226 void PDSS_ConstVol::setState_TP(doublereal temp, doublereal pres)
227 {
228  setTemperature(temp);
229  setPressure(pres);
230 }
231 
232 void PDSS_ConstVol::setState_TR(doublereal temp, doublereal rho)
233 {
234  doublereal rhoStored = m_mw / m_constMolarVolume;
235  if (fabs(rhoStored - rho) / (rhoStored + rho) > 1.0E-4) {
236  throw CanteraError("PDSS_ConstVol::setState_TR",
237  "Inconsistent supplied rho");
238  }
239  setTemperature(temp);
240 }
241 
242 doublereal PDSS_ConstVol::satPressure(doublereal t)
243 {
244  return 1.0E-200;
245 }
246 
247 }
virtual void setTemperature(doublereal temp)
Set the internal temperature.
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature.
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
virtual doublereal gibbs_RT_ref() const
Return the molar Gibbs free energy divided by RT at reference pressure.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
std::string name() const
Returns the name of the XML node.
Definition: xml.h:370
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
XML_Node * findXMLPhase(XML_Node *root, const std::string &idtarget)
Search an XML_Node tree for a named phase XML_Node.
Definition: xml.cpp:1038
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:695
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
doublereal * m_cpss_R_ptr
Standard state heat capacity divided by R.
Definition: PDSS.h:627
std::string findInputFile(const std::string &name)
Find an input file.
Definition: global.cpp:155
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
Definition: PDSS.cpp:167
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:586
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:544
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
STL namespace.
virtual doublereal refPressure(size_t k=npos) const
The reference-state pressure for species k.
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
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:570
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:641
PDSS_enumType m_pdssType
Enumerated type describing the type of the PDSS object.
Definition: PDSS.h:538
virtual MultiSpeciesThermo & speciesThermo(int k=-1)
Return a changeable reference to the calculation manager for species reference-state thermodynamic pr...
doublereal * m_sss_R_ptr
Standard state entropy divided by R.
Definition: PDSS.h:634
virtual doublereal molarVolume() const
Return the molar volume at standard state.
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
virtual doublereal satPressure(doublereal t)
saturation pressure
PDSS_ConstVol(VPStandardStateTP *tp, size_t spindex)
Constructor.
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:175
Class for pressure dependent standard states that use a constant volume model.
Definition: PDSS_ConstVol.h:22
virtual PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:267
doublereal * m_s0_R_ptr
Reference state entropy divided by R.
Definition: PDSS.h:600
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
void build(const std::string &filename)
Populate the XML tree from an input file.
Definition: xml.cpp:716
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:553
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature.
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:550
doublereal * m_hss_RT_ptr
Standard state enthalpy divided by RT.
Definition: PDSS.h:620
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:546
XML_Node & root() const
Return the root of the current XML_Node tree.
Definition: xml.cpp:1025
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
virtual doublereal density() const
Return the standard state density at standard state.
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:500
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:176
VPStandardStateTP * m_tp
ThermoPhase which this species belongs to.
Definition: PDSS.h:561
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
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:541
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
PDSS & operator=(const PDSS &b)
Definition: PDSS.cpp:103
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:178
doublereal * m_g0_RT_ptr
Reference state Gibbs free energy divided by RT.
Definition: PDSS.h:606
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.
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:593
MultiSpeciesThermo * m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:579
virtual void initThermo()
Initialization routine for all of the shallow pointers.
doublereal * m_Vss_ptr
Standard State molar volume (m3 kg-1)
Definition: PDSS.h:648
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:661
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS.cpp:432
doublereal * m_V0_ptr
Reference state molar volume (m3 kg-1)
Definition: PDSS.h:613
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:496
Namespace for the Cantera kernel.
Definition: application.cpp:29
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
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:547
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:567