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"
13
14using namespace std;
15
16namespace Cantera
17{
18
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
54void PDSS_SSVol::setVolumePolynomial(double* coeffs) {
55 for (size_t i = 0; i < 4; i++) {
56 TCoeff_[i] = coeffs[i];
57 }
59}
60
62 for (size_t i = 0; i < 4; i++) {
63 TCoeff_[i] = coeffs[i];
64 }
66}
67
69{
70 PDSS::getParameters(eosNode);
71 std::vector<AnyValue> data(4);
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
89{
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
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
129{
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];
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
149void PDSS_SSVol::setPressure(doublereal p)
150{
151 m_pres = p;
152 doublereal deltaP = m_pres - m_p0;
153 if (fabs(deltaP) < 1.0E-10) {
155 m_sss_R = m_s0_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;
164 m_cpss_R = m_cp0_R - m_temp * deltaP * d2VdT2_;
165 }
166}
167
168void PDSS_SSVol::setTemperature(doublereal temp)
169{
170 m_temp = temp;
171 m_spthermo->updatePropertiesTemp(temp, &m_cp0_R, &m_h0_RT, &m_s0_R);
174 doublereal deltaP = m_pres - m_p0;
175 if (fabs(deltaP) < 1.0E-10) {
177 m_sss_R = m_s0_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;
186 m_cpss_R = m_cp0_R - m_temp * deltaP * d2VdT2_;
187 }
188}
189
190void 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}
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 ...
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
const UnitSystem & units() const
Return the default units that should be used to convert stored values.
Definition: AnyMap.h:598
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:1406
A wrapper for a variable whose type is determined at runtime.
Definition: AnyMap.h:84
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:522
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:521
double m_h0_RT
Reference state enthalpy divided by RT.
Definition: PDSS.h:515
double m_g0_RT
Reference state Gibbs free energy divided by RT.
Definition: PDSS.h:518
double m_s0_R
Reference state entropy divided by R.
Definition: PDSS.h:517
double m_gss_RT
Standard state Gibbs free energy divided by RT.
Definition: PDSS.h:523
double m_cp0_R
Reference state heat capacity divided by R.
Definition: PDSS.h:516
double m_Vss
Standard State molar volume (m^3/kmol)
Definition: PDSS.h:524
double m_hss_RT
Standard state enthalpy divided by RT.
Definition: PDSS.h:520
double m_V0
Reference state molar volume (m^3/kmol)
Definition: PDSS.h:519
virtual void getParameters(AnyMap &eosNode) const
Store the parameters needed to reconstruct a copy of this PDSS object.
Definition: PDSS_SSVol.cpp:68
doublereal d2VdT2_
2nd derivative of the volume wrt temperature
Definition: PDSS_SSVol.h:217
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
Definition: PDSS_SSVol.cpp:149
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:190
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
vector_fp TCoeff_
coefficients for the temperature representation
Definition: PDSS_SSVol.h:211
virtual void setTemperature(doublereal temp)
Set the internal temperature.
Definition: PDSS_SSVol.cpp:168
PDSS_SSVol()
Default Constructor.
Definition: PDSS_SSVol.cpp:19
doublereal dVdT_
Derivative of the volume wrt temperature.
Definition: PDSS_SSVol.h:214
virtual void initThermo()
Initialization routine.
Definition: PDSS_SSVol.cpp:88
SSVolume_Model
Types of general formulations for the specification of the standard state volume.
Definition: PDSS_SSVol.h:191
@ 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:128
virtual doublereal satPressure(doublereal t)
saturation pressure
Definition: PDSS_SSVol.cpp:196
SSVolume_Model volumeModel_
Enumerated data type describing the type of volume model used to calculate the standard state volume ...
Definition: PDSS_SSVol.h:208
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_SSVol.cpp:117
virtual void initThermo()
Initialization routine.
Definition: PDSS.h:415
virtual void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
Definition: PDSS.h:434
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:458
shared_ptr< SpeciesThermoInterpType > m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:478
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:455
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:467
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:461
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:470
AnyMap m_input
Input data supplied via setParameters.
Definition: PDSS.h:474
virtual void getParameters(AnyMap &eosNode) const
Store the parameters needed to reconstruct a copy of this PDSS object.
Definition: PDSS.h:424
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:464
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
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:493
std::string name() const
Returns the name of the XML node.
Definition: xml.h:371
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 ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
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
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
size_t getFloatArray(const XML_Node &node, vector_fp &v, const bool convert=true, const std::string &unitsString="", const std::string &nodeName="floatArray")
This function reads the current node or a child node of the current node with the default name,...
Definition: ctml.cpp:258