Cantera  2.1.2
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/ct_defs.h"
12 #include "cantera/base/xml.h"
13 #include "cantera/base/ctml.h"
16 
18 
19 #include <fstream>
20 
21 using namespace std;
22 
23 namespace Cantera
24 {
25 PDSS_SSVol::PDSS_SSVol(VPStandardStateTP* tp, size_t spindex) :
26  PDSS(tp, spindex),
27  volumeModel_(cSSVOLUME_CONSTANT),
28  m_constMolarVolume(-1.0)
29 {
30  m_pdssType = cPDSS_SSVOL;
31  TCoeff_[0] = 0.0;
32  TCoeff_[1] = 0.0;
33  TCoeff_[2] = 0.0;
34 }
35 
37  size_t spindex, const std::string& inputFile, const std::string& id) :
38  PDSS(tp, spindex),
39  volumeModel_(cSSVOLUME_CONSTANT),
40  m_constMolarVolume(-1.0)
41 {
42 
43  m_pdssType = cPDSS_SSVOL;
44  constructPDSSFile(tp, spindex, inputFile, id);
45 }
46 
48  const XML_Node& speciesNode,
49  const XML_Node& phaseRoot,
50  bool spInstalled) :
51  PDSS(tp, spindex),
52  volumeModel_(cSSVOLUME_CONSTANT),
53  m_constMolarVolume(-1.0)
54 {
55  m_pdssType = cPDSS_SSVOL;
56  constructPDSSXML(tp, spindex, speciesNode, phaseRoot, spInstalled) ;
57 }
58 
60  PDSS(b),
61  volumeModel_(cSSVOLUME_CONSTANT),
62  m_constMolarVolume(-1.0)
63 {
64  /*
65  * Use the assignment operator to do the brunt
66  * of the work for the copy constructor.
67  */
68  *this = b;
69 }
70 
72 {
73  if (&b == this) {
74  return *this;
75  }
76  PDSS::operator=(b);
79  TCoeff_ = b.TCoeff_;
80  return *this;
81 }
82 
84 {
85  return new PDSS_SSVol(*this);
86 }
87 
89  const XML_Node& speciesNode,
90  const XML_Node& phaseNode, bool spInstalled)
91 {
95 
96  if (!spInstalled) {
97  throw CanteraError("PDSS_SSVol::constructPDSSXML", "spInstalled false not handled");
98  }
99 
100  const XML_Node* ss = speciesNode.findByName("standardState");
101  if (!ss) {
102  throw CanteraError("PDSS_SSVol::constructPDSSXML",
103  "no standardState Node for species " + speciesNode.name());
104  }
105  std::string model = (*ss)["model"];
106  if (model == "constant_incompressible" || model == "constant") {
108  m_constMolarVolume = ctml::getFloat(*ss, "molarVolume", "toSI");
109  } else if (model == "temperature_polynomial") {
111  size_t num = ctml::getFloatArray(*ss, TCoeff_, true, "toSI", "volumeTemperaturePolynomial");
112  if (num != 4) {
113  throw CanteraError("PDSS_SSVol::constructPDSSXML",
114  " Didn't get 4 density polynomial numbers for species " + speciesNode.name());
115  }
116  } else if (model == "density_temperature_polynomial") {
118  size_t num = ctml::getFloatArray(*ss, TCoeff_, true, "toSI", "densityTemperaturePolynomial");
119  if (num != 4) {
120  throw CanteraError("PDSS_SSVol::constructPDSSXML",
121  " Didn't get 4 density polynomial numbers for species " + speciesNode.name());
122  }
123  } else {
124  throw CanteraError("PDSS_SSVol::constructPDSSXML",
125  "standardState model for species isn't constant_incompressible: " + speciesNode.name());
126  }
127  std::string id = "";
128 }
129 
131  const std::string& inputFile, const std::string& id)
132 {
133  if (inputFile.size() == 0) {
134  throw CanteraError("PDSS_SSVol::initThermo",
135  "input file is null");
136  }
137  std::string path = findInputFile(inputFile);
138  ifstream fin(path.c_str());
139  if (!fin) {
140  throw CanteraError("PDSS_SSVol::initThermo","could not open "
141  +path+" for reading.");
142  }
143  /*
144  * The phase object automatically constructs an XML object.
145  * Use this object to store information.
146  */
147 
148  XML_Node* fxml = new XML_Node();
149  fxml->build(fin);
150  XML_Node* fxml_phase = findXMLPhase(fxml, id);
151  if (!fxml_phase) {
152  throw CanteraError("PDSS_SSVol::initThermo",
153  "ERROR: Can not find phase named " +
154  id + " in file named " + inputFile);
155  }
156 
157  XML_Node& speciesList = fxml_phase->child("speciesArray");
158  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
159  &(fxml_phase->root()));
160  const vector<string>&sss = tp->speciesNames();
161  const XML_Node* s = speciesDB->findByAttr("name", sss[spindex]);
162 
163  constructPDSSXML(tp, spindex, *s, *fxml_phase, true);
164  delete fxml;
165 }
166 
167 void PDSS_SSVol::initThermoXML(const XML_Node& phaseNode, const std::string& id)
168 {
169  PDSS::initThermoXML(phaseNode, id);
174 }
175 
177 {
180  m_p0 = sp.refPressure(m_spindex);
183 }
184 
185 doublereal
187 {
188  doublereal val = enthalpy_RT();
189  doublereal RT = GasConstant * m_temp;
190  return val * RT;
191 }
192 
193 doublereal
195 {
196  return m_hss_RT_ptr[m_spindex];
197 }
198 
199 doublereal
201 {
202  doublereal pVRT = (m_pres * m_Vss_ptr[m_spindex]) / (GasConstant * m_temp);
203  doublereal val = m_h0_RT_ptr[m_spindex] - pVRT;
204  doublereal RT = GasConstant * m_temp;
205  return val * RT;
206 }
207 
208 doublereal
210 {
211  doublereal val = entropy_R();
212  return val * GasConstant;
213 }
214 
215 doublereal
217 {
218  return m_sss_R_ptr[m_spindex];
219 }
220 
221 doublereal
223 {
224  doublereal val = gibbs_RT();
225  doublereal RT = GasConstant * m_temp;
226  return val * RT;
227 }
228 
229 doublereal
231 {
232  return m_gss_RT_ptr[m_spindex];
233 }
234 
235 doublereal
237 {
238  doublereal val = m_cpss_R_ptr[m_spindex];
239  return val * GasConstant;
240 }
241 
242 doublereal
244 {
245  return m_cpss_R_ptr[m_spindex];
246 }
247 
248 doublereal
250 {
251  return (cp_mole() - m_V0_ptr[m_spindex]);
252 }
253 
254 doublereal
256 {
257  return m_Vss_ptr[m_spindex];
258 }
259 
260 doublereal
262 {
263  doublereal val = m_Vss_ptr[m_spindex];
264  return m_mw/val;
265 }
266 
267 doublereal
269 {
270  return m_g0_RT_ptr[m_spindex];
271 }
272 
273 doublereal PDSS_SSVol::enthalpy_RT_ref() const
274 {
275  return m_h0_RT_ptr[m_spindex];
276 }
277 
278 doublereal PDSS_SSVol::entropy_R_ref() const
279 {
280  return m_s0_R_ptr[m_spindex];
281 }
282 
283 doublereal PDSS_SSVol::cp_R_ref() const
284 {
285  return m_cp0_R_ptr[m_spindex];
286 }
287 
288 doublereal PDSS_SSVol::molarVolume_ref() const
289 {
290  return m_V0_ptr[m_spindex];
291 }
292 
294 {
297  } else if (volumeModel_ == cSSVOLUME_TPOLY) {
298  m_Vss_ptr[m_spindex] = TCoeff_[0] + m_temp * (TCoeff_[1] + m_temp * (TCoeff_[2] + m_temp * TCoeff_[3]));
299  dVdT_ = TCoeff_[1] + 2.0 * m_temp * TCoeff_[2] + 3.0 * m_temp * m_temp * TCoeff_[3];
300  d2VdT2_ = 2.0 * TCoeff_[2] + 6.0 * m_temp * TCoeff_[3];
301  } else if (volumeModel_ == cSSVOLUME_DENSITY_TPOLY) {
302  doublereal dens = TCoeff_[0] + m_temp * (TCoeff_[1] + m_temp * (TCoeff_[2] + m_temp * TCoeff_[3]));
303  m_Vss_ptr[m_spindex] = m_mw / dens;
304  doublereal dens2 = dens * dens;
305  doublereal ddensdT = TCoeff_[1] + 2.0 * m_temp * TCoeff_[2] + 3.0 * m_temp * m_temp * TCoeff_[3];
306  doublereal d2densdT2 = 2.0 * TCoeff_[2] + 6.0 * m_temp * TCoeff_[3];
307  dVdT_ = - m_mw / (dens2) * (ddensdT);
308  d2VdT2_ = 2.0 * m_mw / (dens2 * dens) * ddensdT * ddensdT - m_mw / dens2 * d2densdT2;
309  } else {
310  throw CanteraError("PDSS_SSVol::calcMolarVolume", "unimplemented");
311  }
312 }
313 
314 doublereal PDSS_SSVol::critTemperature() const
315 {
316  throw CanteraError("PDSS_SSVol::critTemperature()", "unimplemented");
317  return 0.0;
318 }
319 
320 doublereal PDSS_SSVol::critPressure() const
321 {
322  throw CanteraError("PDSS_SSVol::critPressure()", "unimplemented");
323  return 0.0;
324 }
325 
326 doublereal PDSS_SSVol::critDensity() const
327 {
328  throw CanteraError("PDSS_SSVol::critDensity()", "unimplemented");
329  return 0.0;
330 }
331 
332 void PDSS_SSVol::setPressure(doublereal p)
333 {
334  m_pres = p;
335  doublereal deltaP = m_pres - m_p0;
336  if (fabs(deltaP) < 1.0E-10) {
341  } else {
342  doublereal del_pRT = deltaP / (GasConstant * m_temp);
343  doublereal sV_term = - deltaP / (GasConstant) * dVdT_;
344  m_hss_RT_ptr[m_spindex] = m_h0_RT_ptr[m_spindex] + sV_term + del_pRT * (m_Vss_ptr[m_spindex]);
348  }
349 }
350 
351 void PDSS_SSVol::setTemperature(doublereal temp)
352 {
353  m_temp = temp;
355  calcMolarVolume();
357  doublereal deltaP = m_pres - m_p0;
358  if (fabs(deltaP) < 1.0E-10) {
360  m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex];
363  } else {
364  doublereal del_pRT = deltaP / (GasConstant * m_temp);
365  doublereal sV_term = - deltaP / (GasConstant) * dVdT_;
366  m_hss_RT_ptr[m_spindex] = m_h0_RT_ptr[m_spindex] + sV_term + del_pRT * (m_Vss_ptr[m_spindex]);
367  m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex] + sV_term;
370  }
371 }
372 
373 void PDSS_SSVol::setState_TP(doublereal temp, doublereal pres)
374 {
375  m_pres = pres;
376  setTemperature(temp);
377 }
378 
379 void PDSS_SSVol::setState_TR(doublereal temp, doublereal rho)
380 {
381  doublereal rhoStored = m_mw / m_constMolarVolume;
382  if (fabs(rhoStored - rho) / (rhoStored + rho) > 1.0E-4) {
383  throw CanteraError("PDSS_SSVol::setState_TR",
384  "Inconsistent supplied rho");
385  }
386  setTemperature(temp);
387 }
388 
389 doublereal PDSS_SSVol::satPressure(doublereal t)
390 {
391  return 1.0E-200;
392 }
393 
394 }
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:716
PDSS_SSVol & operator=(const PDSS_SSVol &b)
Assignment operator.
Definition: PDSS_SSVol.cpp:71
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:484
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS_SSVol.cpp:255
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition: PDSS_SSVol.cpp:194
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
virtual doublereal satPressure(doublereal t)
saturation pressure
Definition: PDSS_SSVol.cpp:389
SpeciesThermo * m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:615
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
Definition: PDSS_SSVol.cpp:249
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:88
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
void calcMolarVolume() const
Does the internal calculation of the volume.
Definition: PDSS_SSVol.cpp:293
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
Definition: PDSS_SSVol.cpp:230
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...
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:576
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS_SSVol.cpp:351
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:167
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
doublereal getFloat(const Cantera::XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:267
virtual doublereal critPressure() const
critical pressure
Definition: PDSS_SSVol.cpp:320
This approximation is for a constant volume.
Definition: mix_defs.h:104
size_t m_spindex
Species index in the ThermoPhase corresponding to this species.
Definition: PDSS.h:606
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_SSVol.cpp:200
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
Pure Virtual base class for the species thermo manager classes.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:584
doublereal * m_sss_R_ptr
Standard state entropy divided by R.
Definition: PDSS.h:670
virtual doublereal critTemperature() const
critical temperature
Definition: PDSS_SSVol.cpp:314
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
Definition: PDSS_SSVol.cpp:332
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS_SSVol.cpp:283
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:754
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS_SSVol.cpp:273
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:183
virtual doublereal gibbs_RT_ref() const
Return the molar gibbs free energy divided by RT at reference pressure.
Definition: PDSS_SSVol.cpp:268
virtual doublereal gibbs_mole() const
Return the molar Gibbs free energy in units of J kmol-1.
Definition: PDSS_SSVol.cpp:222
doublereal d2VdT2_
2nd derivative of the volume wrt temperature
Definition: PDSS_SSVol.h:339
SSVolume_Model_enumType volumeModel_
Enumerated data type describing the type of volume model used to calculate the standard state volume ...
Definition: PDSS_SSVol.h:324
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS_SSVol.cpp:236
doublereal m_constMolarVolume
Value of the constant molar volume for the species.
Definition: PDSS_SSVol.h:330
std::string name() const
Returns the name of the XML node.
Definition: xml.h:390
Declarations for the class PDSS_SSVol (pressure dependent standard state) which handles calculations ...
Classes providing support for XML data files.
This approximation is for a species with a quadratic polynomial in temperature.
Definition: mix_defs.h:109
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS_SSVol.cpp:288
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_SSVol.cpp:373
virtual doublereal refPressure(size_t k=npos) const =0
The reference-state pressure for species k.
virtual doublereal critDensity() const
critical density
Definition: PDSS_SSVol.cpp:326
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
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:333
virtual doublereal enthalpy_mole() const
Return the molar enthalpy in units of J kmol-1.
Definition: PDSS_SSVol.cpp:186
doublereal dVdT_
Derivative of the volume wrt temperature.
Definition: PDSS_SSVol.h:336
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:585
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:582
Class for pressure dependent standard states that uses a standard state volume model of some sort...
Definition: PDSS_SSVol.h:159
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.
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
Definition: Phase.cpp:252
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS_SSVol.cpp:176
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_SSVol.cpp:261
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS_SSVol.cpp:243
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:278
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:195
virtual PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
Definition: PDSS_SSVol.cpp:83
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
Definition: PDSS_SSVol.cpp:216
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
doublereal * m_g0_RT_ptr
Reference state Gibbs free energy divided by RT.
Definition: PDSS.h:642
doublereal * m_cp0_R_ptr
Reference state heat capacity divided by R.
Definition: PDSS.h:629
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:25
virtual void setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
Definition: PDSS_SSVol.cpp:379
This approximation is for a species where the density is expressed as a quadratic polynomial in tempe...
Definition: mix_defs.h:115
doublereal * m_Vss_ptr
Standard State molar volume (m3 kg-1)
Definition: PDSS.h:684
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
Definition: PDSS_SSVol.cpp:209
doublereal * m_V0_ptr
Reference state molar volume (m3 kg-1)
Definition: PDSS.h:649
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:130
XML_Node & root() const
Return the root of the current XML_Node tree.
Definition: xml.cpp:1091
void build(std::istream &f)
Main routine to create an tree-like representation of an XML file.
Definition: xml.cpp:776
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:271
size_t getFloatArray(const Cantera::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:419
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