Cantera  2.5.1
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 https://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::setParametersFromXML",
32  "no 'standardState' Node for species '{}'",
33  speciesNode.name());
34  }
35  std::string model = ss->attrib("model");
36  vector_fp coeffs;
37  getFloatArray(*ss, coeffs, true, "toSI", "volumeTemperaturePolynomial");
38  if (coeffs.size() != 4) {
39  throw CanteraError("PDSS_SSVol::setParametersFromXML",
40  "Didn't get 4 density polynomial numbers for species '{}'",
41  speciesNode.name());
42  }
43  if (model == "temperature_polynomial") {
44  setVolumePolynomial(coeffs.data());
45  } else if (model == "density_temperature_polynomial") {
46  setDensityPolynomial(coeffs.data());
47  } else {
48  throw CanteraError("PDSS_SSVol::setParametersFromXML",
49  "Unknown 'standardState' model '{}' for species '{}'",
50  model, speciesNode.name());
51  }
52 }
53 
54 void PDSS_SSVol::setVolumePolynomial(double* coeffs) {
55  for (size_t i = 0; i < 4; i++) {
56  TCoeff_[i] = coeffs[i];
57  }
59 }
60 
61 void PDSS_SSVol::setDensityPolynomial(double* coeffs) {
62  for (size_t i = 0; i < 4; i++) {
63  TCoeff_[i] = coeffs[i];
64  }
66 }
67 
69 {
71  if (m_input.hasKey("model")) {
72  const string& model = m_input["model"].asString();
73  auto& data = m_input["data"].asVector<AnyValue>(4);
74  if (model == "density-temperature-polynomial") {
75  double coeffs[] {
76  m_input.units().convert(data[0], "kg/m^3"),
77  m_input.units().convert(data[1], "kg/m^3/K"),
78  m_input.units().convert(data[2], "kg/m^3/K^2"),
79  m_input.units().convert(data[3], "kg/m^3/K^3"),
80  };
81  setDensityPolynomial(coeffs);
82  } else if (model == "molar-volume-temperature-polynomial") {
83  double coeffs[] {
84  m_input.units().convert(data[0], "m^3/kmol"),
85  m_input.units().convert(data[1], "m^3/kmol/K"),
86  m_input.units().convert(data[2], "m^3/kmol/K^2"),
87  m_input.units().convert(data[3], "m^3/kmol/K^3"),
88  };
89  setVolumePolynomial(coeffs);
90  }
91  }
92  m_minTemp = m_spthermo->minTemp();
93  m_maxTemp = m_spthermo->maxTemp();
94  m_p0 = m_spthermo->refPressure();
95 }
96 
97 doublereal PDSS_SSVol::intEnergy_mole() const
98 {
99  doublereal pV = m_pres * m_Vss;
100  return m_h0_RT * GasConstant * m_temp - pV;
101 }
102 
103 doublereal PDSS_SSVol::cv_mole() const
104 {
105  return (cp_mole() - m_V0);
106 }
107 
109 {
111  m_Vss = TCoeff_[0] + m_temp * (TCoeff_[1] + m_temp * (TCoeff_[2] + m_temp * TCoeff_[3]));
112  m_V0 = m_Vss;
113  dVdT_ = TCoeff_[1] + 2.0 * m_temp * TCoeff_[2] + 3.0 * m_temp * m_temp * TCoeff_[3];
114  d2VdT2_ = 2.0 * TCoeff_[2] + 6.0 * m_temp * TCoeff_[3];
116  doublereal dens = TCoeff_[0] + m_temp * (TCoeff_[1] + m_temp * (TCoeff_[2] + m_temp * TCoeff_[3]));
117  m_Vss = m_mw / dens;
118  m_V0 = m_Vss;
119  doublereal dens2 = dens * dens;
120  doublereal ddensdT = TCoeff_[1] + 2.0 * m_temp * TCoeff_[2] + 3.0 * m_temp * m_temp * TCoeff_[3];
121  doublereal d2densdT2 = 2.0 * TCoeff_[2] + 6.0 * m_temp * TCoeff_[3];
122  dVdT_ = - m_mw / dens2 * ddensdT;
123  d2VdT2_ = 2.0 * m_mw / (dens2 * dens) * ddensdT * ddensdT - m_mw / dens2 * d2densdT2;
124  } else {
125  throw NotImplementedError("PDSS_SSVol::calcMolarVolume");
126  }
127 }
128 
129 void PDSS_SSVol::setPressure(doublereal p)
130 {
131  m_pres = p;
132  doublereal deltaP = m_pres - m_p0;
133  if (fabs(deltaP) < 1.0E-10) {
134  m_hss_RT = m_h0_RT;
135  m_sss_R = m_s0_R;
137  m_cpss_R = m_cp0_R;
138  } else {
139  doublereal del_pRT = deltaP / (GasConstant * m_temp);
140  doublereal sV_term = - deltaP / GasConstant * dVdT_;
141  m_hss_RT = m_h0_RT + sV_term + del_pRT * m_Vss;
142  m_sss_R = m_s0_R + sV_term;
144  m_cpss_R = m_cp0_R - m_temp * deltaP * d2VdT2_;
145  }
146 }
147 
148 void PDSS_SSVol::setTemperature(doublereal temp)
149 {
150  m_temp = temp;
151  m_spthermo->updatePropertiesTemp(temp, &m_cp0_R, &m_h0_RT, &m_s0_R);
152  calcMolarVolume();
153  m_g0_RT = m_h0_RT - m_s0_R;
154  doublereal deltaP = m_pres - m_p0;
155  if (fabs(deltaP) < 1.0E-10) {
156  m_hss_RT = m_h0_RT;
157  m_sss_R = m_s0_R;
159  m_cpss_R = m_cp0_R;
160  } else {
161  doublereal del_pRT = deltaP / (GasConstant * m_temp);
162  doublereal sV_term = - deltaP / GasConstant * dVdT_;
163  m_hss_RT = m_h0_RT + sV_term + del_pRT * m_Vss;
164  m_sss_R = m_s0_R + sV_term;
166  m_cpss_R = m_cp0_R - m_temp * deltaP * d2VdT2_;
167  }
168 }
169 
170 void PDSS_SSVol::setState_TP(doublereal temp, doublereal pres)
171 {
172  m_pres = pres;
173  setTemperature(temp);
174 }
175 
176 void PDSS_SSVol::setState_TR(doublereal temp, doublereal rho)
177 {
178  setTemperature(temp);
179  warn_deprecated("PDSS_SSVol::setState_TR",
180  "Setter only changes temperature and "
181  "will be removed after Cantera 2.5.");
182  doublereal rhoStored = m_mw / m_Vss;
183  if (fabs(rhoStored - rho) / (rhoStored + rho) > 1.0E-4) {
184  throw CanteraError("PDSS_SSVol::setState_TR",
185  "Inconsistent supplied rho");
186  }
187 }
188 
189 doublereal PDSS_SSVol::satPressure(doublereal t)
190 {
191  return 1.0E-200;
192 }
193 
194 }
Declarations for the class PDSS_SSVol (pressure dependent standard state) which handles calculations ...
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:984
const UnitSystem & units() const
Return the default units that should be used to convert stored values.
Definition: AnyMap.h:492
A wrapper for a variable whose type is determined at runtime.
Definition: AnyMap.h:77
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
double m_sss_R
Standard state entropy divided by R.
Definition: PDSS.h:531
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS.cpp:262
double m_cpss_R
Standard state heat capacity divided by R.
Definition: PDSS.h:530
double m_h0_RT
Reference state enthalpy divided by RT.
Definition: PDSS.h:524
double m_g0_RT
Reference state Gibbs free energy divided by RT.
Definition: PDSS.h:527
double m_s0_R
Reference state entropy divided by R.
Definition: PDSS.h:526
double m_gss_RT
Standard state Gibbs free energy divided by RT.
Definition: PDSS.h:532
double m_cp0_R
Reference state heat capacity divided by R.
Definition: PDSS.h:525
double m_Vss
Standard State molar volume (m^3/kmol)
Definition: PDSS.h:533
double m_hss_RT
Standard state enthalpy divided by RT.
Definition: PDSS.h:529
double m_V0
Reference state molar volume (m^3/kmol)
Definition: PDSS.h:528
doublereal d2VdT2_
2nd derivative of the volume wrt temperature
Definition: PDSS_SSVol.h:215
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
Definition: PDSS_SSVol.cpp:129
void setDensityPolynomial(double *coeffs)
Set polynomial coefficients for the standard state density as a function of temperature.
Definition: PDSS_SSVol.cpp:61
void setVolumePolynomial(double *coeffs)
Set polynomial coefficients for the standard state molar volume as a function of temperature.
Definition: PDSS_SSVol.cpp:54
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_SSVol.cpp:170
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
Definition: PDSS_SSVol.cpp:103
vector_fp TCoeff_
coefficients for the temperature representation
Definition: PDSS_SSVol.h:209
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS_SSVol.cpp:148
doublereal dVdT_
Derivative of the volume wrt temperature.
Definition: PDSS_SSVol.h:212
virtual void initThermo()
Initialization routine.
Definition: PDSS_SSVol.cpp:68
SSVolume_Model
Types of general formulations for the specification of the standard state volume.
Definition: PDSS_SSVol.h:189
@ tpoly
This approximation is for a species with a cubic polynomial in temperature.
@ density_tpoly
This approximation is for a species where the density is expressed as a cubic polynomial in temperatu...
virtual void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
Definition: PDSS_SSVol.cpp:25
void calcMolarVolume()
Does the internal calculation of the volume.
Definition: PDSS_SSVol.cpp:108
virtual void setState_TR(doublereal temp, doublereal rho)
Definition: PDSS_SSVol.cpp:176
virtual doublereal satPressure(doublereal t)
saturation pressure
Definition: PDSS_SSVol.cpp:189
SSVolume_Model volumeModel_
Enumerated data type describing the type of volume model used to calculate the standard state volume ...
Definition: PDSS_SSVol.h:206
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_SSVol.cpp:97
virtual void initThermo()
Initialization routine.
Definition: PDSS.h:427
virtual void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
Definition: PDSS.h:443
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:467
shared_ptr< SpeciesThermoInterpType > m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:487
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:464
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:476
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:470
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:479
AnyMap m_input
Input data supplied via setParameters.
Definition: PDSS.h:483
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:473
double convert(double value, const std::string &src, const std::string &dest) const
Convert value from the units of src to the units of dest.
Definition: Units.cpp:322
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:104
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:492
std::string name() const
Returns the name of the XML node.
Definition: xml.h:372
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:679
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
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:180
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:109
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
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