Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * 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_SSVol::PDSS_SSVol(VPStandardStateTP* tp, size_t spindex) :
22  PDSS(tp, spindex),
23  volumeModel_(cSSVOLUME_CONSTANT),
24  m_constMolarVolume(-1.0)
25 {
26  m_pdssType = cPDSS_SSVOL;
27  TCoeff_[0] = 0.0;
28  TCoeff_[1] = 0.0;
29  TCoeff_[2] = 0.0;
30 }
31 
33  size_t spindex, const std::string& inputFile, const std::string& id) :
34  PDSS(tp, spindex),
35  volumeModel_(cSSVOLUME_CONSTANT),
36  m_constMolarVolume(-1.0)
37 {
38 
39  m_pdssType = cPDSS_SSVOL;
40  constructPDSSFile(tp, spindex, inputFile, id);
41 }
42 
44  const XML_Node& speciesNode,
45  const XML_Node& phaseRoot,
46  bool spInstalled) :
47  PDSS(tp, spindex),
48  volumeModel_(cSSVOLUME_CONSTANT),
49  m_constMolarVolume(-1.0)
50 {
51  m_pdssType = cPDSS_SSVOL;
52  constructPDSSXML(tp, spindex, speciesNode, phaseRoot, spInstalled) ;
53 }
54 
56  PDSS(b),
57  volumeModel_(cSSVOLUME_CONSTANT),
58  m_constMolarVolume(-1.0)
59 {
60  /*
61  * Use the assignment operator to do the brunt
62  * of the work for the copy constructor.
63  */
64  *this = b;
65 }
66 
68 {
69  if (&b == this) {
70  return *this;
71  }
72  PDSS::operator=(b);
75  TCoeff_ = b.TCoeff_;
76  return *this;
77 }
78 
80 {
81  return new PDSS_SSVol(*this);
82 }
83 
85  const XML_Node& speciesNode,
86  const XML_Node& phaseNode, bool spInstalled)
87 {
90 
91  if (!spInstalled) {
92  throw CanteraError("PDSS_SSVol::constructPDSSXML", "spInstalled false not handled");
93  }
94 
95  const XML_Node* ss = speciesNode.findByName("standardState");
96  if (!ss) {
97  throw CanteraError("PDSS_SSVol::constructPDSSXML",
98  "no standardState Node for species " + speciesNode.name());
99  }
100  std::string model = ss->attrib("model");
101  if (model == "constant_incompressible" || model == "constant") {
103  m_constMolarVolume = getFloat(*ss, "molarVolume", "toSI");
104  } else if (model == "temperature_polynomial") {
106  size_t num = getFloatArray(*ss, TCoeff_, true, "toSI", "volumeTemperaturePolynomial");
107  if (num != 4) {
108  throw CanteraError("PDSS_SSVol::constructPDSSXML",
109  " Didn't get 4 density polynomial numbers for species " + speciesNode.name());
110  }
111  } else if (model == "density_temperature_polynomial") {
113  size_t num = getFloatArray(*ss, TCoeff_, true, "toSI", "densityTemperaturePolynomial");
114  if (num != 4) {
115  throw CanteraError("PDSS_SSVol::constructPDSSXML",
116  " Didn't get 4 density polynomial numbers for species " + speciesNode.name());
117  }
118  } else {
119  throw CanteraError("PDSS_SSVol::constructPDSSXML",
120  "standardState model for species isn't constant_incompressible: " + speciesNode.name());
121  }
122 }
123 
125  const std::string& inputFile, const std::string& id)
126 {
127  if (inputFile.size() == 0) {
128  throw CanteraError("PDSS_SSVol::initThermo",
129  "input file is null");
130  }
131  std::string path = findInputFile(inputFile);
132  ifstream fin(path.c_str());
133  if (!fin) {
134  throw CanteraError("PDSS_SSVol::initThermo","could not open "
135  +path+" for reading.");
136  }
137  /*
138  * The phase object automatically constructs an XML object.
139  * Use this object to store information.
140  */
141 
142  XML_Node fxml;
143  fxml.build(fin);
144  XML_Node* fxml_phase = findXMLPhase(&fxml, id);
145  if (!fxml_phase) {
146  throw CanteraError("PDSS_SSVol::initThermo",
147  "ERROR: Can not find phase named " +
148  id + " in file named " + inputFile);
149  }
150 
151  XML_Node& speciesList = fxml_phase->child("speciesArray");
152  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
153  &(fxml_phase->root()));
154  const XML_Node* s = speciesDB->findByAttr("name", tp->speciesName(spindex));
155 
156  constructPDSSXML(tp, spindex, *s, *fxml_phase, true);
157 }
158 
159 void PDSS_SSVol::initThermoXML(const XML_Node& phaseNode, const std::string& id)
160 {
161  PDSS::initThermoXML(phaseNode, id);
166 }
167 
169 {
174 }
175 
176 doublereal
178 {
179  return m_hss_RT_ptr[m_spindex];
180 }
181 
182 doublereal
184 {
185  doublereal pV = m_pres * m_Vss_ptr[m_spindex];
186  return m_h0_RT_ptr[m_spindex] * GasConstant * m_temp - pV;
187 }
188 
189 doublereal
191 {
192  return m_sss_R_ptr[m_spindex];
193 }
194 
195 doublereal
197 {
198  return m_gss_RT_ptr[m_spindex];
199 }
200 
201 doublereal
203 {
204  return m_cpss_R_ptr[m_spindex];
205 }
206 
207 doublereal
209 {
210  return (cp_mole() - m_V0_ptr[m_spindex]);
211 }
212 
213 doublereal
215 {
216  return m_Vss_ptr[m_spindex];
217 }
218 
219 doublereal
221 {
222  return m_mw / m_Vss_ptr[m_spindex];
223 }
224 
225 doublereal
227 {
228  return m_g0_RT_ptr[m_spindex];
229 }
230 
231 doublereal PDSS_SSVol::enthalpy_RT_ref() const
232 {
233  return m_h0_RT_ptr[m_spindex];
234 }
235 
236 doublereal PDSS_SSVol::entropy_R_ref() const
237 {
238  return m_s0_R_ptr[m_spindex];
239 }
240 
241 doublereal PDSS_SSVol::cp_R_ref() const
242 {
243  return m_cp0_R_ptr[m_spindex];
244 }
245 
246 doublereal PDSS_SSVol::molarVolume_ref() const
247 {
248  return m_V0_ptr[m_spindex];
249 }
250 
252 {
255  } else if (volumeModel_ == cSSVOLUME_TPOLY) {
256  m_Vss_ptr[m_spindex] = TCoeff_[0] + m_temp * (TCoeff_[1] + m_temp * (TCoeff_[2] + m_temp * TCoeff_[3]));
257  dVdT_ = TCoeff_[1] + 2.0 * m_temp * TCoeff_[2] + 3.0 * m_temp * m_temp * TCoeff_[3];
258  d2VdT2_ = 2.0 * TCoeff_[2] + 6.0 * m_temp * TCoeff_[3];
259  } else if (volumeModel_ == cSSVOLUME_DENSITY_TPOLY) {
260  doublereal dens = TCoeff_[0] + m_temp * (TCoeff_[1] + m_temp * (TCoeff_[2] + m_temp * TCoeff_[3]));
261  m_Vss_ptr[m_spindex] = m_mw / dens;
262  doublereal dens2 = dens * dens;
263  doublereal ddensdT = TCoeff_[1] + 2.0 * m_temp * TCoeff_[2] + 3.0 * m_temp * m_temp * TCoeff_[3];
264  doublereal d2densdT2 = 2.0 * TCoeff_[2] + 6.0 * m_temp * TCoeff_[3];
265  dVdT_ = - m_mw / (dens2) * (ddensdT);
266  d2VdT2_ = 2.0 * m_mw / (dens2 * dens) * ddensdT * ddensdT - m_mw / dens2 * d2densdT2;
267  } else {
268  throw CanteraError("PDSS_SSVol::calcMolarVolume", "unimplemented");
269  }
270 }
271 
272 void PDSS_SSVol::setPressure(doublereal p)
273 {
274  m_pres = p;
275  doublereal deltaP = m_pres - m_p0;
276  if (fabs(deltaP) < 1.0E-10) {
281  } else {
282  doublereal del_pRT = deltaP / (GasConstant * m_temp);
283  doublereal sV_term = - deltaP / (GasConstant) * dVdT_;
284  m_hss_RT_ptr[m_spindex] = m_h0_RT_ptr[m_spindex] + sV_term + del_pRT * (m_Vss_ptr[m_spindex]);
288  }
289 }
290 
291 void PDSS_SSVol::setTemperature(doublereal temp)
292 {
293  m_temp = temp;
295  calcMolarVolume();
297  doublereal deltaP = m_pres - m_p0;
298  if (fabs(deltaP) < 1.0E-10) {
300  m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex];
303  } else {
304  doublereal del_pRT = deltaP / (GasConstant * m_temp);
305  doublereal sV_term = - deltaP / (GasConstant) * dVdT_;
306  m_hss_RT_ptr[m_spindex] = m_h0_RT_ptr[m_spindex] + sV_term + del_pRT * (m_Vss_ptr[m_spindex]);
307  m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex] + sV_term;
310  }
311 }
312 
313 void PDSS_SSVol::setState_TP(doublereal temp, doublereal pres)
314 {
315  m_pres = pres;
316  setTemperature(temp);
317 }
318 
319 void PDSS_SSVol::setState_TR(doublereal temp, doublereal rho)
320 {
321  doublereal rhoStored = m_mw / m_constMolarVolume;
322  if (fabs(rhoStored - rho) / (rhoStored + rho) > 1.0E-4) {
323  throw CanteraError("PDSS_SSVol::setState_TR",
324  "Inconsistent supplied rho");
325  }
326  setTemperature(temp);
327 }
328 
329 doublereal PDSS_SSVol::satPressure(doublereal t)
330 {
331  return 1.0E-200;
332 }
333 
334 }
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
PDSS_SSVol & operator=(const PDSS_SSVol &b)
Assignment operator.
Definition: PDSS_SSVol.cpp:67
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:494
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS_SSVol.cpp:214
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition: PDSS_SSVol.cpp:177
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
virtual doublereal satPressure(doublereal t)
saturation pressure
Definition: PDSS_SSVol.cpp:329
SpeciesThermo * m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:604
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
Definition: PDSS_SSVol.cpp:208
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:84
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:527
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_h0_RT_ptr
Reference state enthalpy divided by RT.
Definition: PDSS.h:611
void calcMolarVolume() const
Does the internal calculation of the volume.
Definition: PDSS_SSVol.cpp:251
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
Definition: PDSS_SSVol.cpp:196
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.
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:565
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS_SSVol.cpp:291
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:159
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
This approximation is for a constant volume.
Definition: mix_defs.h:106
size_t m_spindex
Species index in the ThermoPhase corresponding to this species.
Definition: PDSS.h:595
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_SSVol.cpp:183
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
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 setPressure(doublereal pres)
Sets the pressure in the object.
Definition: PDSS_SSVol.cpp:272
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS_SSVol.cpp:241
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
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS_SSVol.cpp:231
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:173
virtual doublereal gibbs_RT_ref() const
Return the molar Gibbs free energy divided by RT at reference pressure.
Definition: PDSS_SSVol.cpp:226
doublereal d2VdT2_
2nd derivative of the volume wrt temperature
Definition: PDSS_SSVol.h:329
SSVolume_Model_enumType volumeModel_
Enumerated data type describing the type of volume model used to calculate the standard state volume ...
Definition: PDSS_SSVol.h:314
doublereal m_constMolarVolume
Value of the constant molar volume for the species.
Definition: PDSS_SSVol.h:320
std::string name() const
Returns the name of the XML node.
Definition: xml.h:394
Declarations for the class PDSS_SSVol (pressure dependent standard state) which handles calculations ...
This approximation is for a species with a quadratic polynomial in temperature.
Definition: mix_defs.h:111
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS_SSVol.cpp:246
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_SSVol.cpp:313
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
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:323
doublereal dVdT_
Derivative of the volume wrt temperature.
Definition: PDSS_SSVol.h:326
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:574
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:571
Class for pressure dependent standard states that uses a standard state volume model of some sort...
Definition: PDSS_SSVol.h:156
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 void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS_SSVol.cpp:168
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_SSVol.cpp:220
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS_SSVol.cpp:202
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 doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS_SSVol.cpp:236
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:193
virtual PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
Definition: PDSS_SSVol.cpp:79
size_t getFloatArray(const XML_Node &node, std::vector< doublereal > &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:323
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
Definition: PDSS_SSVol.cpp:190
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
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
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...
PDSS_SSVol(VPStandardStateTP *tp, size_t spindex)
Constructor.
Definition: PDSS_SSVol.cpp:21
virtual void setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
Definition: PDSS_SSVol.cpp:319
This approximation is for a species where the density is expressed as a quadratic polynomial in tempe...
Definition: mix_defs.h:117
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
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:124
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