Cantera 2.6.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 https://cantera.org/license.txt for license and copyright information.
9
10#include "cantera/base/ctml.h"
11#include "cantera/thermo/PDSS_SSVol.h"
12#include "cantera/thermo/VPStandardStateTP.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
25 void PDSS_SSVol::setParametersFromXML(const XML_Node& speciesNode)
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 }
58 volumeModel_ = SSVolume_Model::tpoly;
59}
60
61 void PDSS_SSVol::setDensityPolynomial(double* coeffs) {
62 for (size_t i = 0; i < 4; i++) {
63 TCoeff_[i] = coeffs[i];
64 }
65 volumeModel_ = SSVolume_Model::density_tpoly;
66}
67
68 void PDSS_SSVol::getParameters(AnyMap& eosNode) const
69{
70 PDSS::getParameters(eosNode);
71 std::vector<AnyValue> data(4);
72 if (volumeModel_ == SSVolume_Model::density_tpoly) {
73 eosNode["model"] = "density-temperature-polynomial";
74 data[0].setQuantity(TCoeff_[0], "kg/m^3");
75 data[1].setQuantity(TCoeff_[1], "kg/m^3/K");
76 data[2].setQuantity(TCoeff_[2], "kg/m^3/K^2");
77 data[3].setQuantity(TCoeff_[3], "kg/m^3/K^3");
78 } else {
79 eosNode["model"] = "molar-volume-temperature-polynomial";
80 data[0].setQuantity(TCoeff_[0], "m^3/kmol");
81 data[1].setQuantity(TCoeff_[1], "m^3/kmol/K");
82 data[2].setQuantity(TCoeff_[2], "m^3/kmol/K^2");
83 data[3].setQuantity(TCoeff_[3], "m^3/kmol/K^3");
84 }
85 eosNode["data"] = std::move(data);
86}
87
88 void PDSS_SSVol::initThermo()
89{
90 PDSS::initThermo();
91 if (m_input.hasKey("model")) {
92 const string& model = m_input["model"].asString();
93 auto& data = m_input["data"].asVector<AnyValue>(4);
94 if (model == "density-temperature-polynomial") {
95 double coeffs[] {
96 m_input.units().convert(data[0], "kg/m^3"),
97 m_input.units().convert(data[1], "kg/m^3/K"),
98 m_input.units().convert(data[2], "kg/m^3/K^2"),
99 m_input.units().convert(data[3], "kg/m^3/K^3"),
100 };
101 setDensityPolynomial(coeffs);
102 } else if (model == "molar-volume-temperature-polynomial") {
103 double coeffs[] {
104 m_input.units().convert(data[0], "m^3/kmol"),
105 m_input.units().convert(data[1], "m^3/kmol/K"),
106 m_input.units().convert(data[2], "m^3/kmol/K^2"),
107 m_input.units().convert(data[3], "m^3/kmol/K^3"),
108 };
109 setVolumePolynomial(coeffs);
110 }
111 }
112 m_minTemp = m_spthermo->minTemp();
113 m_maxTemp = m_spthermo->maxTemp();
114 m_p0 = m_spthermo->refPressure();
115}
116
117doublereal PDSS_SSVol::intEnergy_mole() const
118{
119 doublereal pV = m_pres * m_Vss;
120 return m_h0_RT * GasConstant * m_temp - pV;
121}
122
123doublereal PDSS_SSVol::cv_mole() const
124{
125 return (cp_mole() - m_V0);
126}
127
128 void PDSS_SSVol::calcMolarVolume()
129{
130 if (volumeModel_ == SSVolume_Model::tpoly) {
131 m_Vss = TCoeff_[0] + m_temp * (TCoeff_[1] + m_temp * (TCoeff_[2] + m_temp * TCoeff_[3]));
132 m_V0 = m_Vss;
133 dVdT_ = TCoeff_[1] + 2.0 * m_temp * TCoeff_[2] + 3.0 * m_temp * m_temp * TCoeff_[3];
134 d2VdT2_ = 2.0 * TCoeff_[2] + 6.0 * m_temp * TCoeff_[3];
135 } else if (volumeModel_ == SSVolume_Model::density_tpoly) {
136 doublereal dens = TCoeff_[0] + m_temp * (TCoeff_[1] + m_temp * (TCoeff_[2] + m_temp * TCoeff_[3]));
137 m_Vss = m_mw / dens;
138 m_V0 = m_Vss;
139 doublereal dens2 = dens * dens;
140 doublereal ddensdT = TCoeff_[1] + 2.0 * m_temp * TCoeff_[2] + 3.0 * m_temp * m_temp * TCoeff_[3];
141 doublereal d2densdT2 = 2.0 * TCoeff_[2] + 6.0 * m_temp * TCoeff_[3];
142 dVdT_ = - m_mw / dens2 * ddensdT;
143 d2VdT2_ = 2.0 * m_mw / (dens2 * dens) * ddensdT * ddensdT - m_mw / dens2 * d2densdT2;
144 } else {
145 throw NotImplementedError("PDSS_SSVol::calcMolarVolume");
146 }
147}
148
149 void PDSS_SSVol::setPressure(doublereal p)
150{
151 m_pres = p;
152 doublereal deltaP = m_pres - m_p0;
153 if (fabs(deltaP) < 1.0E-10) {
154 m_hss_RT = m_h0_RT;
155 m_sss_R = m_s0_R;
156 m_gss_RT = m_hss_RT - m_sss_R;
157 m_cpss_R = m_cp0_R;
158 } else {
159 doublereal del_pRT = deltaP / (GasConstant * m_temp);
160 doublereal sV_term = - deltaP / GasConstant * dVdT_;
161 m_hss_RT = m_h0_RT + sV_term + del_pRT * m_Vss;
162 m_sss_R = m_s0_R + sV_term;
163 m_gss_RT = m_hss_RT - m_sss_R;
164 m_cpss_R = m_cp0_R - m_temp * deltaP * d2VdT2_;
165 }
166}
167
168 void PDSS_SSVol::setTemperature(doublereal temp)
169{
170 m_temp = temp;
171 m_spthermo->updatePropertiesTemp(temp, &m_cp0_R, &m_h0_RT, &m_s0_R);
172 calcMolarVolume();
173 m_g0_RT = m_h0_RT - m_s0_R;
174 doublereal deltaP = m_pres - m_p0;
175 if (fabs(deltaP) < 1.0E-10) {
176 m_hss_RT = m_h0_RT;
177 m_sss_R = m_s0_R;
178 m_gss_RT = m_hss_RT - m_sss_R;
179 m_cpss_R = m_cp0_R;
180 } else {
181 doublereal del_pRT = deltaP / (GasConstant * m_temp);
182 doublereal sV_term = - deltaP / GasConstant * dVdT_;
183 m_hss_RT = m_h0_RT + sV_term + del_pRT * m_Vss;
184 m_sss_R = m_s0_R + sV_term;
185 m_gss_RT = m_hss_RT - m_sss_R;
186 m_cpss_R = m_cp0_R - m_temp * deltaP * d2VdT2_;
187 }
188}
189
190 void PDSS_SSVol::setState_TP(doublereal temp, doublereal pres)
191{
192 m_pres = pres;
193 setTemperature(temp);
194}
195
196doublereal PDSS_SSVol::satPressure(doublereal t)
197{
198 return 1.0E-200;
199}
200
201}
PDSS_SSVol.h
Declarations for the class PDSS_SSVol (pressure dependent standard state) which handles calculations ...
VPStandardStateTP.h
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
Cantera::AnyMap::units
const UnitSystem & units() const
Return the default units that should be used to convert stored values.
Definition: AnyMap.h:598
Cantera::AnyMap::hasKey
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:1406
Cantera::AnyValue
A wrapper for a variable whose type is determined at runtime.
Definition: AnyMap.h:84
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::NotImplementedError
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
Cantera::PDSS_Nondimensional::m_sss_R
double m_sss_R
Standard state entropy divided by R.
Definition: PDSS.h:522
Cantera::PDSS_Nondimensional::cp_mole
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
Definition: PDSS.cpp:262
Cantera::PDSS_Nondimensional::m_cpss_R
double m_cpss_R
Standard state heat capacity divided by R.
Definition: PDSS.h:521
Cantera::PDSS_Nondimensional::m_h0_RT
double m_h0_RT
Reference state enthalpy divided by RT.
Definition: PDSS.h:515
Cantera::PDSS_Nondimensional::m_g0_RT
double m_g0_RT
Reference state Gibbs free energy divided by RT.
Definition: PDSS.h:518
Cantera::PDSS_Nondimensional::m_s0_R
double m_s0_R
Reference state entropy divided by R.
Definition: PDSS.h:517
Cantera::PDSS_Nondimensional::m_gss_RT
double m_gss_RT
Standard state Gibbs free energy divided by RT.
Definition: PDSS.h:523
Cantera::PDSS_Nondimensional::m_cp0_R
double m_cp0_R
Reference state heat capacity divided by R.
Definition: PDSS.h:516
Cantera::PDSS_Nondimensional::m_Vss
double m_Vss
Standard State molar volume (m^3/kmol)
Definition: PDSS.h:524
Cantera::PDSS_Nondimensional::m_hss_RT
double m_hss_RT
Standard state enthalpy divided by RT.
Definition: PDSS.h:520
Cantera::PDSS_Nondimensional::m_V0
double m_V0
Reference state molar volume (m^3/kmol)
Definition: PDSS.h:519
Cantera::PDSS_SSVol::getParameters
virtual void getParameters(AnyMap &eosNode) const
Store the parameters needed to reconstruct a copy of this PDSS object.
Definition: PDSS_SSVol.cpp:68
Cantera::PDSS_SSVol::d2VdT2_
doublereal d2VdT2_
2nd derivative of the volume wrt temperature
Definition: PDSS_SSVol.h:217
Cantera::PDSS_SSVol::setPressure
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
Definition: PDSS_SSVol.cpp:149
Cantera::PDSS_SSVol::setDensityPolynomial
void setDensityPolynomial(double *coeffs)
Set polynomial coefficients for the standard state density as a function of temperature.
Definition: PDSS_SSVol.cpp:61
Cantera::PDSS_SSVol::setVolumePolynomial
void setVolumePolynomial(double *coeffs)
Set polynomial coefficients for the standard state molar volume as a function of temperature.
Definition: PDSS_SSVol.cpp:54
Cantera::PDSS_SSVol::setState_TP
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_SSVol.cpp:190
Cantera::PDSS_SSVol::cv_mole
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
Definition: PDSS_SSVol.cpp:123
Cantera::PDSS_SSVol::TCoeff_
vector_fp TCoeff_
coefficients for the temperature representation
Definition: PDSS_SSVol.h:211
Cantera::PDSS_SSVol::setTemperature
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS_SSVol.cpp:168
Cantera::PDSS_SSVol::PDSS_SSVol
PDSS_SSVol()
Default Constructor.
Definition: PDSS_SSVol.cpp:19
Cantera::PDSS_SSVol::dVdT_
doublereal dVdT_
Derivative of the volume wrt temperature.
Definition: PDSS_SSVol.h:214
Cantera::PDSS_SSVol::initThermo
virtual void initThermo()
Initialization routine.
Definition: PDSS_SSVol.cpp:88
Cantera::PDSS_SSVol::SSVolume_Model
SSVolume_Model
Types of general formulations for the specification of the standard state volume.
Definition: PDSS_SSVol.h:191
Cantera::PDSS_SSVol::SSVolume_Model::tpoly
@ tpoly
This approximation is for a species with a cubic polynomial in temperature.
Cantera::PDSS_SSVol::SSVolume_Model::density_tpoly
@ density_tpoly
This approximation is for a species where the density is expressed as a cubic polynomial in temperatu...
Cantera::PDSS_SSVol::setParametersFromXML
virtual void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
Definition: PDSS_SSVol.cpp:25
Cantera::PDSS_SSVol::calcMolarVolume
void calcMolarVolume()
Does the internal calculation of the volume.
Definition: PDSS_SSVol.cpp:128
Cantera::PDSS_SSVol::satPressure
virtual doublereal satPressure(doublereal t)
saturation pressure
Definition: PDSS_SSVol.cpp:196
Cantera::PDSS_SSVol::volumeModel_
SSVolume_Model volumeModel_
Enumerated data type describing the type of volume model used to calculate the standard state volume ...
Definition: PDSS_SSVol.h:208
Cantera::PDSS_SSVol::intEnergy_mole
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_SSVol.cpp:117
Cantera::PDSS::initThermo
virtual void initThermo()
Initialization routine.
Definition: PDSS.h:415
Cantera::PDSS::setParametersFromXML
virtual void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
Definition: PDSS.h:434
Cantera::PDSS::m_pres
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:458
Cantera::PDSS::m_spthermo
shared_ptr< SpeciesThermoInterpType > m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:478
Cantera::PDSS::m_temp
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:455
Cantera::PDSS::m_maxTemp
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:467
Cantera::PDSS::m_p0
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:461
Cantera::PDSS::m_mw
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:470
Cantera::PDSS::m_input
AnyMap m_input
Input data supplied via setParameters.
Definition: PDSS.h:474
Cantera::PDSS::getParameters
virtual void getParameters(AnyMap &eosNode) const
Store the parameters needed to reconstruct a copy of this PDSS object.
Definition: PDSS.h:424
Cantera::PDSS::m_minTemp
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:464
Cantera::UnitSystem::convert
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:558
Cantera::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Cantera::XML_Node::attrib
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:493
Cantera::XML_Node::name
std::string name() const
Returns the name of the XML node.
Definition: xml.h:371
Cantera::XML_Node::findByName
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:680
ctml.h
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::vector_fp
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:184
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
Cantera::getFloatArray
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:258