Cantera  2.4.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 
19 PDSS_SSVol::PDSS_SSVol()
20  : volumeModel_(SSVolume_Model::tpoly)
21  , TCoeff_(4, 0.0)
22 {
23 }
24 
26 {
27  PDSS::setParametersFromXML(speciesNode);
28 
29  const XML_Node* ss = speciesNode.findByName("standardState");
30  if (!ss) {
31  throw CanteraError("PDSS_SSVol::constructPDSSXML",
32  "no standardState Node for species " + speciesNode.name());
33  }
34  std::string model = ss->attrib("model");
35  vector_fp coeffs;
36  getFloatArray(*ss, coeffs, true, "toSI", "volumeTemperaturePolynomial");
37  if (coeffs.size() != 4) {
38  throw CanteraError("PDSS_SSVol::setParametersFromXML",
39  " Didn't get 4 density polynomial numbers for species " + speciesNode.name());
40  }
41  if (model == "temperature_polynomial") {
42  setVolumePolynomial(coeffs.data());
43  } else if (model == "density_temperature_polynomial") {
44  setDensityPolynomial(coeffs.data());
45  } else {
46  throw CanteraError("PDSS_SSVol::constructPDSSXML",
47  "Unknown standardState model '{}'' for species '{}'",
48  model, speciesNode.name());
49  }
50 }
51 
52 void PDSS_SSVol::setVolumePolynomial(double* coeffs) {
53  for (size_t i = 0; i < 4; i++) {
54  TCoeff_[i] = coeffs[i];
55  }
57 }
58 
59 void PDSS_SSVol::setDensityPolynomial(double* coeffs) {
60  for (size_t i = 0; i < 4; i++) {
61  TCoeff_[i] = coeffs[i];
62  }
64 }
65 
67 {
69  m_minTemp = m_spthermo->minTemp();
70  m_maxTemp = m_spthermo->maxTemp();
71  m_p0 = m_spthermo->refPressure();
72 }
73 
74 doublereal PDSS_SSVol::intEnergy_mole() const
75 {
76  doublereal pV = m_pres * m_Vss;
77  return m_h0_RT * GasConstant * m_temp - pV;
78 }
79 
80 doublereal PDSS_SSVol::cv_mole() const
81 {
82  return (cp_mole() - m_V0);
83 }
84 
86 {
88  m_Vss = TCoeff_[0] + m_temp * (TCoeff_[1] + m_temp * (TCoeff_[2] + m_temp * TCoeff_[3]));
89  m_V0 = m_Vss;
90  dVdT_ = TCoeff_[1] + 2.0 * m_temp * TCoeff_[2] + 3.0 * m_temp * m_temp * TCoeff_[3];
91  d2VdT2_ = 2.0 * TCoeff_[2] + 6.0 * m_temp * TCoeff_[3];
93  doublereal dens = TCoeff_[0] + m_temp * (TCoeff_[1] + m_temp * (TCoeff_[2] + m_temp * TCoeff_[3]));
94  m_Vss = m_mw / dens;
95  m_V0 = m_Vss;
96  doublereal dens2 = dens * dens;
97  doublereal ddensdT = TCoeff_[1] + 2.0 * m_temp * TCoeff_[2] + 3.0 * m_temp * m_temp * TCoeff_[3];
98  doublereal d2densdT2 = 2.0 * TCoeff_[2] + 6.0 * m_temp * TCoeff_[3];
99  dVdT_ = - m_mw / dens2 * ddensdT;
100  d2VdT2_ = 2.0 * m_mw / (dens2 * dens) * ddensdT * ddensdT - m_mw / dens2 * d2densdT2;
101  } else {
102  throw CanteraError("PDSS_SSVol::calcMolarVolume", "unimplemented");
103  }
104 }
105 
106 void PDSS_SSVol::setPressure(doublereal p)
107 {
108  m_pres = p;
109  doublereal deltaP = m_pres - m_p0;
110  if (fabs(deltaP) < 1.0E-10) {
111  m_hss_RT = m_h0_RT;
112  m_sss_R = m_s0_R;
114  m_cpss_R = m_cp0_R;
115  } else {
116  doublereal del_pRT = deltaP / (GasConstant * m_temp);
117  doublereal sV_term = - deltaP / GasConstant * dVdT_;
118  m_hss_RT = m_h0_RT + sV_term + del_pRT * m_Vss;
119  m_sss_R = m_s0_R + sV_term;
121  m_cpss_R = m_cp0_R - m_temp * deltaP * d2VdT2_;
122  }
123 }
124 
125 void PDSS_SSVol::setTemperature(doublereal temp)
126 {
127  m_temp = temp;
128  m_spthermo->updatePropertiesTemp(temp, &m_cp0_R, &m_h0_RT, &m_s0_R);
129  calcMolarVolume();
130  m_g0_RT = m_h0_RT - m_s0_R;
131  doublereal deltaP = m_pres - m_p0;
132  if (fabs(deltaP) < 1.0E-10) {
133  m_hss_RT = m_h0_RT;
134  m_sss_R = m_s0_R;
136  m_cpss_R = m_cp0_R;
137  } else {
138  doublereal del_pRT = deltaP / (GasConstant * m_temp);
139  doublereal sV_term = - deltaP / GasConstant * dVdT_;
140  m_hss_RT = m_h0_RT + sV_term + del_pRT * m_Vss;
141  m_sss_R = m_s0_R + sV_term;
143  m_cpss_R = m_cp0_R - m_temp * deltaP * d2VdT2_;
144  }
145 }
146 
147 void PDSS_SSVol::setState_TP(doublereal temp, doublereal pres)
148 {
149  m_pres = pres;
150  setTemperature(temp);
151 }
152 
153 void PDSS_SSVol::setState_TR(doublereal temp, doublereal rho)
154 {
155  setTemperature(temp);
156  doublereal rhoStored = m_mw / m_Vss;
157  if (fabs(rhoStored - rho) / (rhoStored + rho) > 1.0E-4) {
158  throw CanteraError("PDSS_SSVol::setState_TR",
159  "Inconsistent supplied rho");
160  }
161 }
162 
163 doublereal PDSS_SSVol::satPressure(doublereal t)
164 {
165  return 1.0E-200;
166 }
167 
168 }
virtual void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
Definition: PDSS_SSVol.cpp:25
double m_gss_RT
Standard state Gibbs free energy divided by RT.
Definition: PDSS.h:544
SSVolume_Model volumeModel_
Enumerated data type describing the type of volume model used to calculate the standard state volume ...
Definition: PDSS_SSVol.h:205
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_SSVol.cpp:74
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 satPressure(doublereal t)
saturation pressure
Definition: PDSS_SSVol.cpp:163
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 void initThermo()
Initialization routine.
Definition: PDSS.h:452
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:256
virtual void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
Definition: PDSS.h:459
double m_sss_R
Standard state entropy divided by R.
Definition: PDSS.h:543
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:483
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS_SSVol.cpp:125
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
STL namespace.
void setVolumePolynomial(double *coeffs)
Set polynomial coefficients for the standard state molar volume as a function of temperature.
Definition: PDSS_SSVol.cpp:52
double m_cp0_R
Reference state heat capacity divided by R.
Definition: PDSS.h:537
void calcMolarVolume()
Does the internal calculation of the volume.
Definition: PDSS_SSVol.cpp:85
void setDensityPolynomial(double *coeffs)
Set polynomial coefficients for the standard state density as a function of temperature.
Definition: PDSS_SSVol.cpp:59
This approximation is for a species with a cubic polynomial in temperature.
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
Definition: PDSS_SSVol.cpp:106
This approximation is for a species where the density is expressed as a cubic polynomial in temperatu...
double m_hss_RT
Standard state enthalpy divided by RT.
Definition: PDSS.h:541
SSVolume_Model
Types of general formulations for the specification of the standard state volume. ...
Definition: PDSS_SSVol.h:188
double m_cpss_R
Standard state heat capacity divided by R.
Definition: PDSS.h:542
double m_s0_R
Reference state entropy divided by R.
Definition: PDSS.h:538
double m_Vss
Standard State molar volume (m^3/kmol)
Definition: PDSS.h:545
doublereal d2VdT2_
2nd derivative of the volume wrt temperature
Definition: PDSS_SSVol.h:214
double m_V0
Reference state molar volume (m^3/kmol)
Definition: PDSS.h:540
shared_ptr< SpeciesThermoInterpType > m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:499
Declarations for the class PDSS_SSVol (pressure dependent standard state) which handles calculations ...
double m_g0_RT
Reference state Gibbs free energy divided by RT.
Definition: PDSS.h:539
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_SSVol.cpp:147
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
vector_fp TCoeff_
coefficients for the temperature representation
Definition: PDSS_SSVol.h:208
doublereal dVdT_
Derivative of the volume wrt temperature.
Definition: PDSS_SSVol.h:211
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:492
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:489
virtual void initThermo()
Initialization routine.
Definition: PDSS_SSVol.cpp:66
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
Definition: PDSS_SSVol.cpp:80
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
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
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:480
double m_h0_RT
Reference state enthalpy divided by RT.
Definition: PDSS.h:536
virtual void setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
Definition: PDSS_SSVol.cpp:153
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS.cpp:262
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:486
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:495