Cantera  2.3.0
PDSS_SSVol.cpp
Go to the documentation of this file.
1 /**
2  * @file PDSS_SSVol.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_SSVol::PDSS_SSVol(VPStandardStateTP* tp, size_t spindex) :
19  PDSS(tp, spindex),
20  volumeModel_(SSVolume_Model::constant),
21  m_constMolarVolume(-1.0)
22 {
23  m_pdssType = cPDSS_SSVOL;
24  TCoeff_[0] = 0.0;
25  TCoeff_[1] = 0.0;
26  TCoeff_[2] = 0.0;
27 }
28 
30  size_t spindex, const std::string& inputFile, const std::string& id) :
31  PDSS(tp, spindex),
32  volumeModel_(SSVolume_Model::constant),
33  m_constMolarVolume(-1.0)
34 {
35  warn_deprecated("PDSS_SSVol constructor from XML input file",
36  "To be removed after Cantera 2.3.");
37  m_pdssType = cPDSS_SSVOL;
38  constructPDSSFile(tp, spindex, inputFile, id);
39 }
40 
42  const XML_Node& speciesNode,
43  const XML_Node& phaseRoot,
44  bool spInstalled) :
45  PDSS(tp, spindex),
46  volumeModel_(SSVolume_Model::constant),
47  m_constMolarVolume(-1.0)
48 {
49  m_pdssType = cPDSS_SSVOL;
50  constructPDSSXML(tp, spindex, speciesNode, phaseRoot, spInstalled);
51 }
52 
54  PDSS(b),
55  volumeModel_(SSVolume_Model::constant),
56  m_constMolarVolume(-1.0)
57 {
58  // Use the assignment operator to do the brunt of the work for the copy
59  // constructor.
60  *this = b;
61 }
62 
63 PDSS_SSVol& PDSS_SSVol::operator=(const PDSS_SSVol& b)
64 {
65  if (&b == this) {
66  return *this;
67  }
68  PDSS::operator=(b);
69  volumeModel_ = b.volumeModel_;
70  m_constMolarVolume = b.m_constMolarVolume;
71  TCoeff_ = b.TCoeff_;
72  return *this;
73 }
74 
76 {
77  return new PDSS_SSVol(*this);
78 }
79 
81  const XML_Node& speciesNode,
82  const XML_Node& phaseNode, bool spInstalled)
83 {
86 
87  if (!spInstalled) {
88  throw CanteraError("PDSS_SSVol::constructPDSSXML", "spInstalled false not handled");
89  }
90 
91  const XML_Node* ss = speciesNode.findByName("standardState");
92  if (!ss) {
93  throw CanteraError("PDSS_SSVol::constructPDSSXML",
94  "no standardState Node for species " + speciesNode.name());
95  }
96  std::string model = ss->attrib("model");
97  if (model == "constant_incompressible" || model == "constant") {
99  m_constMolarVolume = getFloat(*ss, "molarVolume", "toSI");
100  } else if (model == "temperature_polynomial") {
102  size_t num = getFloatArray(*ss, TCoeff_, true, "toSI", "volumeTemperaturePolynomial");
103  if (num != 4) {
104  throw CanteraError("PDSS_SSVol::constructPDSSXML",
105  " Didn't get 4 density polynomial numbers for species " + speciesNode.name());
106  }
107  } else if (model == "density_temperature_polynomial") {
109  size_t num = getFloatArray(*ss, TCoeff_, true, "toSI", "densityTemperaturePolynomial");
110  if (num != 4) {
111  throw CanteraError("PDSS_SSVol::constructPDSSXML",
112  " Didn't get 4 density polynomial numbers for species " + speciesNode.name());
113  }
114  } else {
115  throw CanteraError("PDSS_SSVol::constructPDSSXML",
116  "standardState model for species isn't constant_incompressible: " + speciesNode.name());
117  }
118 }
119 
121  const std::string& inputFile, const std::string& id)
122 {
123  warn_deprecated("PDSS_SSVol::constructPDSSFile",
124  "To be removed after Cantera 2.3.");
125  if (inputFile.size() == 0) {
126  throw CanteraError("PDSS_SSVol::initThermo",
127  "input file is null");
128  }
129 
130  // The phase object automatically constructs an XML object. Use this object
131  // to store information.
132  XML_Node fxml;
133  fxml.build(findInputFile(inputFile));
134  XML_Node* fxml_phase = findXMLPhase(&fxml, id);
135  if (!fxml_phase) {
136  throw CanteraError("PDSS_SSVol::initThermo",
137  "ERROR: Can not find phase named " +
138  id + " in file named " + inputFile);
139  }
140 
141  XML_Node& speciesList = fxml_phase->child("speciesArray");
142  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
143  &fxml_phase->root());
144  const XML_Node* s = speciesDB->findByAttr("name", tp->speciesName(spindex));
145  constructPDSSXML(tp, spindex, *s, *fxml_phase, true);
146 }
147 
148 void PDSS_SSVol::initThermoXML(const XML_Node& phaseNode, const std::string& id)
149 {
150  PDSS::initThermoXML(phaseNode, id);
155 }
156 
158 {
163 }
164 
165 doublereal PDSS_SSVol::enthalpy_RT() const
166 {
167  return m_hss_RT_ptr[m_spindex];
168 }
169 
170 doublereal PDSS_SSVol::intEnergy_mole() const
171 {
172  doublereal pV = m_pres * m_Vss_ptr[m_spindex];
173  return m_h0_RT_ptr[m_spindex] * GasConstant * m_temp - pV;
174 }
175 
176 doublereal PDSS_SSVol::entropy_R() const
177 {
178  return m_sss_R_ptr[m_spindex];
179 }
180 
181 doublereal PDSS_SSVol::gibbs_RT() const
182 {
183  return m_gss_RT_ptr[m_spindex];
184 }
185 
186 doublereal PDSS_SSVol::cp_R() const
187 {
188  return m_cpss_R_ptr[m_spindex];
189 }
190 
191 doublereal PDSS_SSVol::cv_mole() const
192 {
193  return (cp_mole() - m_V0_ptr[m_spindex]);
194 }
195 
196 doublereal PDSS_SSVol::molarVolume() const
197 {
198  return m_Vss_ptr[m_spindex];
199 }
200 
201 doublereal PDSS_SSVol::density() const
202 {
203  return m_mw / m_Vss_ptr[m_spindex];
204 }
205 
206 doublereal PDSS_SSVol::gibbs_RT_ref() const
207 {
208  return m_g0_RT_ptr[m_spindex];
209 }
210 
211 doublereal PDSS_SSVol::enthalpy_RT_ref() const
212 {
213  return m_h0_RT_ptr[m_spindex];
214 }
215 
216 doublereal PDSS_SSVol::entropy_R_ref() const
217 {
218  return m_s0_R_ptr[m_spindex];
219 }
220 
221 doublereal PDSS_SSVol::cp_R_ref() const
222 {
223  return m_cp0_R_ptr[m_spindex];
224 }
225 
226 doublereal PDSS_SSVol::molarVolume_ref() const
227 {
228  return m_V0_ptr[m_spindex];
229 }
230 
232 {
235  } else if (volumeModel_ == SSVolume_Model::tpoly) {
236  m_Vss_ptr[m_spindex] = TCoeff_[0] + m_temp * (TCoeff_[1] + m_temp * (TCoeff_[2] + m_temp * TCoeff_[3]));
237  dVdT_ = TCoeff_[1] + 2.0 * m_temp * TCoeff_[2] + 3.0 * m_temp * m_temp * TCoeff_[3];
238  d2VdT2_ = 2.0 * TCoeff_[2] + 6.0 * m_temp * TCoeff_[3];
240  doublereal dens = TCoeff_[0] + m_temp * (TCoeff_[1] + m_temp * (TCoeff_[2] + m_temp * TCoeff_[3]));
241  m_Vss_ptr[m_spindex] = m_mw / dens;
242  doublereal dens2 = dens * dens;
243  doublereal ddensdT = TCoeff_[1] + 2.0 * m_temp * TCoeff_[2] + 3.0 * m_temp * m_temp * TCoeff_[3];
244  doublereal d2densdT2 = 2.0 * TCoeff_[2] + 6.0 * m_temp * TCoeff_[3];
245  dVdT_ = - m_mw / dens2 * ddensdT;
246  d2VdT2_ = 2.0 * m_mw / (dens2 * dens) * ddensdT * ddensdT - m_mw / dens2 * d2densdT2;
247  } else {
248  throw CanteraError("PDSS_SSVol::calcMolarVolume", "unimplemented");
249  }
250 }
251 
252 void PDSS_SSVol::setPressure(doublereal p)
253 {
254  m_pres = p;
255  doublereal deltaP = m_pres - m_p0;
256  if (fabs(deltaP) < 1.0E-10) {
261  } else {
262  doublereal del_pRT = deltaP / (GasConstant * m_temp);
263  doublereal sV_term = - deltaP / GasConstant * dVdT_;
264  m_hss_RT_ptr[m_spindex] = m_h0_RT_ptr[m_spindex] + sV_term + del_pRT * m_Vss_ptr[m_spindex];
268  }
269 }
270 
271 void PDSS_SSVol::setTemperature(doublereal temp)
272 {
273  m_temp = temp;
275  calcMolarVolume();
277  doublereal deltaP = m_pres - m_p0;
278  if (fabs(deltaP) < 1.0E-10) {
283  } else {
284  doublereal del_pRT = deltaP / (GasConstant * m_temp);
285  doublereal sV_term = - deltaP / GasConstant * dVdT_;
286  m_hss_RT_ptr[m_spindex] = m_h0_RT_ptr[m_spindex] + sV_term + del_pRT * m_Vss_ptr[m_spindex];
290  }
291 }
292 
293 void PDSS_SSVol::setState_TP(doublereal temp, doublereal pres)
294 {
295  m_pres = pres;
296  setTemperature(temp);
297 }
298 
299 void PDSS_SSVol::setState_TR(doublereal temp, doublereal rho)
300 {
301  doublereal rhoStored = m_mw / m_constMolarVolume;
302  if (fabs(rhoStored - rho) / (rhoStored + rho) > 1.0E-4) {
303  throw CanteraError("PDSS_SSVol::setState_TR",
304  "Inconsistent supplied rho");
305  }
306  setTemperature(temp);
307 }
308 
309 doublereal PDSS_SSVol::satPressure(doublereal t)
310 {
311  return 1.0E-200;
312 }
313 
314 }
size_t getFloatArray(const XML_Node &node, vector_fp &v, const bool convert, const std::string &unitsString, const std::string &nodeName)
This function reads the current node or a child node of the current node with the default name...
Definition: ctml.cpp:299
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS_SSVol.cpp:196
SSVolume_Model volumeModel_
Enumerated data type describing the type of volume model used to calculate the standard state volume ...
Definition: PDSS_SSVol.h:323
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature.
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_SSVol.cpp:170
virtual PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
Definition: PDSS_SSVol.cpp:75
void calcMolarVolume() const
Does the internal calculation of the volume.
Definition: PDSS_SSVol.cpp:231
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
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
virtual doublereal satPressure(doublereal t)
saturation pressure
Definition: PDSS_SSVol.cpp:309
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
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.
Definition: PDSS_SSVol.cpp:80
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_h0_RT_ptr
Reference state enthalpy divided by RT.
Definition: PDSS.h:586
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
Definition: PDSS_SSVol.cpp:176
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:544
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS_SSVol.cpp:271
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
Definition: PDSS_SSVol.cpp:148
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 enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS_SSVol.cpp:211
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
Definition: PDSS_SSVol.cpp:181
size_t m_spindex
Species index in the ThermoPhase corresponding to this species.
Definition: PDSS.h:570
doublereal * m_gss_RT_ptr
Standard state Gibbs free energy divided by RT.
Definition: PDSS.h:641
This approximation is for a constant volume.
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
This approximation is for a species with a quadratic polynomial in temperature.
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
Definition: PDSS_SSVol.cpp:252
This approximation is for a species where the density is expressed as a quadratic polynomial in tempe...
SSVolume_Model
Types of general formulations for the specification of the standard state volume. ...
Definition: PDSS_SSVol.h:304
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:175
virtual doublereal gibbs_RT_ref() const
Return the molar Gibbs free energy divided by RT at reference pressure.
Definition: PDSS_SSVol.cpp:206
doublereal d2VdT2_
2nd derivative of the volume wrt temperature
Definition: PDSS_SSVol.h:338
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS_SSVol.cpp:186
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:267
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS_SSVol.cpp:221
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition: PDSS_SSVol.cpp:165
doublereal m_constMolarVolume
Value of the constant molar volume for the species.
Definition: PDSS_SSVol.h:329
Declarations for the class PDSS_SSVol (pressure dependent standard state) which handles calculations ...
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_SSVol.cpp:293
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 ...
vector_fp TCoeff_
coefficients for the temperature representation
Definition: PDSS_SSVol.h:332
doublereal dVdT_
Derivative of the volume wrt temperature.
Definition: PDSS_SSVol.h:335
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
Class for pressure dependent standard states that uses a standard state volume model of some sort...
Definition: PDSS_SSVol.h:163
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&#39;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 void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS_SSVol.cpp:157
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS_SSVol.cpp:216
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
Definition: PDSS_SSVol.cpp:191
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_SSVol.cpp:201
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
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
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.
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
PDSS_SSVol(VPStandardStateTP *tp, size_t spindex)
Constructor.
Definition: PDSS_SSVol.cpp:18
virtual void setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
Definition: PDSS_SSVol.cpp:299
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
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.
Definition: PDSS_SSVol.cpp:120
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
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
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS_SSVol.cpp:226