Cantera 2.6.0

SingleSpeciesTP.cpp
Go to the documentation of this file.
1/**
2 * @file SingleSpeciesTP.cpp
3 * Definitions for the SingleSpeciesTP class, which is a filter class for ThermoPhase,
4 * that eases the construction of single species phases
5 * ( see \ref thermoprops and class \link Cantera::SingleSpeciesTP SingleSpeciesTP\endlink).
6 */
7
8// This file is part of Cantera. See License.txt in the top-level directory or
9// at https://cantera.org/license.txt for license and copyright information.
10
11#include "cantera/thermo/SingleSpeciesTP.h"
12#include "cantera/base/stringUtils.h"
13#include "cantera/base/global.h"
14
15 using namespace std;
16
17 namespace Cantera
18{
19 SingleSpeciesTP::SingleSpeciesTP() :
20 m_press(OneAtm),
21 m_p0(OneAtm)
22{
23}
24
25// ------------ Molar Thermodynamic Properties --------------------
26
27doublereal SingleSpeciesTP::enthalpy_mole() const
28{
29 double hbar;
30 getPartialMolarEnthalpies(&hbar);
31 return hbar;
32}
33
34doublereal SingleSpeciesTP::intEnergy_mole() const
35{
36 double ubar;
37 getPartialMolarIntEnergies(&ubar);
38 return ubar;
39}
40
41doublereal SingleSpeciesTP::entropy_mole() const
42{
43 double sbar;
44 getPartialMolarEntropies(&sbar);
45 return sbar;
46}
47
48doublereal SingleSpeciesTP::gibbs_mole() const
49{
50 double gbar;
51
52 // Get the chemical potential of the first species. This is the same as the
53 // partial molar Gibbs free energy.
54 getChemPotentials(&gbar);
55 return gbar;
56}
57
58doublereal SingleSpeciesTP::cp_mole() const
59{
60 double cpbar;
61
62 // Really should have a partial molar heat capacity function in ThermoPhase.
63 // However, the standard state heat capacity will do fine here for now.
64 getCp_R(&cpbar);
65 cpbar *= GasConstant;
66 return cpbar;
67}
68
69doublereal SingleSpeciesTP::cv_mole() const
70{
71 // For single species, we go directory to the general Cp - Cv relation
72 //
73 // Cp = Cv + alpha**2 * V * T / beta
74 //
75 // where
76 // alpha = volume thermal expansion coefficient
77 // beta = isothermal compressibility
78 doublereal cvbar = cp_mole();
79 doublereal alpha = thermalExpansionCoeff();
80 doublereal beta = isothermalCompressibility();
81 doublereal V = molecularWeight(0)/density();
82 doublereal T = temperature();
83 if (beta != 0.0) {
84 cvbar -= alpha * alpha * V * T / beta;
85 }
86 return cvbar;
87}
88
89// ----------- Partial Molar Properties of the Solution -----------------
90
91 void SingleSpeciesTP::getChemPotentials(doublereal* mu) const
92{
93 getStandardChemPotentials(mu);
94}
95
96 void SingleSpeciesTP::getChemPotentials_RT(doublereal* murt) const
97{
98 getStandardChemPotentials(murt);
99 murt[0] /= RT();
100}
101
102 void SingleSpeciesTP::getPartialMolarEnthalpies(doublereal* hbar) const
103{
104 getEnthalpy_RT(hbar);
105 hbar[0] *= RT();
106}
107
108 void SingleSpeciesTP::getPartialMolarIntEnergies(doublereal* ubar) const
109{
110 getIntEnergy_RT(ubar);
111 ubar[0] *= RT();
112}
113
114 void SingleSpeciesTP::getPartialMolarEntropies(doublereal* sbar) const
115{
116 getEntropy_R(sbar);
117 sbar[0] *= GasConstant;
118}
119
120 void SingleSpeciesTP::getPartialMolarCp(doublereal* cpbar) const
121{
122 getCp_R(cpbar);
123 cpbar[0] *= GasConstant;
124}
125
126 void SingleSpeciesTP::getPartialMolarVolumes(doublereal* vbar) const
127{
128 vbar[0] = molecularWeight(0) / density();
129}
130
131// Properties of the Standard State of the Species in the Solution
132
133 void SingleSpeciesTP::getPureGibbs(doublereal* gpure) const
134{
135 getGibbs_RT(gpure);
136 gpure[0] *= RT();
137}
138
139 void SingleSpeciesTP::getStandardVolumes(doublereal* vbar) const
140{
141 vbar[0] = molecularWeight(0) / density();
142}
143
144// ---- Thermodynamic Values for the Species Reference States -------
145
146 void SingleSpeciesTP::getEnthalpy_RT_ref(doublereal* hrt) const
147{
148 _updateThermo();
149 hrt[0] = m_h0_RT;
150}
151
152 void SingleSpeciesTP::getGibbs_RT_ref(doublereal* grt) const
153{
154 _updateThermo();
155 grt[0] = m_h0_RT - m_s0_R;
156}
157
158 void SingleSpeciesTP::getGibbs_ref(doublereal* g) const
159{
160 getGibbs_RT_ref(g);
161 g[0] *= RT();
162}
163
164 void SingleSpeciesTP::getEntropy_R_ref(doublereal* er) const
165{
166 _updateThermo();
167 er[0] = m_s0_R;
168}
169
170 void SingleSpeciesTP::getCp_R_ref(doublereal* cpr) const
171{
172 _updateThermo();
173 cpr[0] = m_cp0_R;
174}
175
176// ------------------ Setting the State ------------------------
177
178 void SingleSpeciesTP::setState_HP(doublereal h, doublereal p,
179 doublereal tol)
180{
181 doublereal dt;
182 setPressure(p);
183 for (int n = 0; n < 50; n++) {
184 dt = clip((h - enthalpy_mass())/cp_mass(), -100.0, 100.0);
185 setState_TP(temperature() + dt, p);
186 if (fabs(dt / temperature()) < tol) {
187 return;
188 }
189 }
190 throw CanteraError("SingleSpeciesTP::setState_HP",
191 "no convergence. dt = {}", dt);
192}
193
194 void SingleSpeciesTP::setState_UV(doublereal u, doublereal v,
195 doublereal tol)
196{
197 doublereal dt;
198 if (v == 0.0) {
199 setDensity(1.0E100);
200 } else {
201 setDensity(1.0/v);
202 }
203 for (int n = 0; n < 50; n++) {
204 dt = clip((u - intEnergy_mass())/cv_mass(), -100.0, 100.0);
205 setTemperature(temperature() + dt);
206 if (fabs(dt / temperature()) < tol) {
207 return;
208 }
209 }
210 throw CanteraError("SingleSpeciesTP::setState_UV",
211 "no convergence. dt = {}\nu = {} v = {}", dt, u, v);
212}
213
214 void SingleSpeciesTP::setState_SP(doublereal s, doublereal p,
215 doublereal tol)
216{
217 doublereal dt;
218 setPressure(p);
219 for (int n = 0; n < 50; n++) {
220 dt = clip((s - entropy_mass())*temperature()/cp_mass(), -100.0, 100.0);
221 setState_TP(temperature() + dt, p);
222 if (fabs(dt / temperature()) < tol) {
223 return;
224 }
225 }
226 throw CanteraError("SingleSpeciesTP::setState_SP",
227 "no convergence. dt = {}", dt);
228}
229
230 void SingleSpeciesTP::setState_SV(doublereal s, doublereal v,
231 doublereal tol)
232{
233 doublereal dt;
234 if (v == 0.0) {
235 setDensity(1.0E100);
236 } else {
237 setDensity(1.0/v);
238 }
239 for (int n = 0; n < 50; n++) {
240 dt = clip((s - entropy_mass())*temperature()/cv_mass(), -100.0, 100.0);
241 setTemperature(temperature() + dt);
242 if (fabs(dt / temperature()) < tol) {
243 return;
244 }
245 }
246 throw CanteraError("SingleSpeciesTP::setState_SV",
247 "no convergence. dt = {}", dt);
248}
249
250 bool SingleSpeciesTP::addSpecies(shared_ptr<Species> spec)
251{
252 if (m_kk != 0) {
253 throw CanteraError("SingleSpeciesTP::addSpecies",
254 "Stoichiometric substances may only contain one species.");
255 }
256 return ThermoPhase::addSpecies(spec);
257}
258
259 void SingleSpeciesTP::_updateThermo() const
260{
261 doublereal tnow = temperature();
262 if (m_tlast != tnow) {
263 m_spthermo.update(tnow, &m_cp0_R, &m_h0_RT, &m_s0_R);
264 m_tlast = tnow;
265 }
266}
267
268}
SingleSpeciesTP.h
Header for the SingleSpeciesTP class, which is a filter class for ThermoPhase, that eases the constru...
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::MultiSpeciesThermo::update
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
Definition: MultiSpeciesThermo.cpp:90
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition: Phase.h:943
Cantera::Phase::setPressure
virtual void setPressure(double p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition: Phase.h:712
Cantera::Phase::molecularWeight
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:492
Cantera::Phase::setDensity
virtual void setDensity(const double density_)
Set the internally stored density (kg/m^3) of the phase.
Definition: Phase.cpp:687
Cantera::Phase::density
virtual double density() const
Density (kg/m^3).
Definition: Phase.h:679
Cantera::Phase::temperature
doublereal temperature() const
Temperature (K).
Definition: Phase.h:654
Cantera::Phase::setTemperature
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:719
Cantera::SingleSpeciesTP::setState_HP
virtual void setState_HP(double h, double p, double tol=1e-9)
Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of the phase.
Definition: SingleSpeciesTP.cpp:178
Cantera::SingleSpeciesTP::setState_UV
virtual void setState_UV(double u, double v, double tol=1e-9)
Set the specific internal energy (J/kg) and specific volume (m^3/kg).
Definition: SingleSpeciesTP.cpp:194
Cantera::SingleSpeciesTP::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: SingleSpeciesTP.cpp:250
Cantera::SingleSpeciesTP::getGibbs_RT_ref
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
Definition: SingleSpeciesTP.cpp:152
Cantera::SingleSpeciesTP::getPartialMolarIntEnergies
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Get the species partial molar internal energies. Units: J/kmol.
Definition: SingleSpeciesTP.cpp:108
Cantera::SingleSpeciesTP::cp_mole
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition: SingleSpeciesTP.cpp:58
Cantera::SingleSpeciesTP::getPartialMolarEnthalpies
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Get the species partial molar enthalpies. Units: J/kmol.
Definition: SingleSpeciesTP.cpp:102
Cantera::SingleSpeciesTP::getPartialMolarEntropies
virtual void getPartialMolarEntropies(doublereal *sbar) const
Get the species partial molar entropy. Units: J/kmol K.
Definition: SingleSpeciesTP.cpp:114
Cantera::SingleSpeciesTP::enthalpy_mole
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
Definition: SingleSpeciesTP.cpp:27
Cantera::SingleSpeciesTP::getPartialMolarVolumes
virtual void getPartialMolarVolumes(doublereal *vbar) const
Get the species partial molar volumes. Units: m^3/kmol.
Definition: SingleSpeciesTP.cpp:126
Cantera::SingleSpeciesTP::cv_mole
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: SingleSpeciesTP.cpp:69
Cantera::SingleSpeciesTP::getPartialMolarCp
virtual void getPartialMolarCp(doublereal *cpbar) const
Get the species partial molar Heat Capacities. Units: J/ kmol /K.
Definition: SingleSpeciesTP.cpp:120
Cantera::SingleSpeciesTP::m_h0_RT
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
Definition: SingleSpeciesTP.h:259
Cantera::SingleSpeciesTP::entropy_mole
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
Definition: SingleSpeciesTP.cpp:41
Cantera::SingleSpeciesTP::m_s0_R
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
Definition: SingleSpeciesTP.h:263
Cantera::SingleSpeciesTP::getChemPotentials_RT
virtual void getChemPotentials_RT(doublereal *murt) const
Get the array of non-dimensional species chemical potentials.
Definition: SingleSpeciesTP.cpp:96
Cantera::SingleSpeciesTP::setState_SP
virtual void setState_SP(double s, double p, double tol=1e-9)
Set the specific entropy (J/kg/K) and pressure (Pa).
Definition: SingleSpeciesTP.cpp:214
Cantera::SingleSpeciesTP::getEntropy_R_ref
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
Definition: SingleSpeciesTP.cpp:164
Cantera::SingleSpeciesTP::gibbs_mole
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
Definition: SingleSpeciesTP.cpp:48
Cantera::SingleSpeciesTP::getCp_R_ref
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
Definition: SingleSpeciesTP.cpp:170
Cantera::SingleSpeciesTP::m_cp0_R
double m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
Definition: SingleSpeciesTP.h:261
Cantera::SingleSpeciesTP::getStandardVolumes
virtual void getStandardVolumes(doublereal *vbar) const
Get the molar volumes of each species in their standard states at the current T and P of the solution...
Definition: SingleSpeciesTP.cpp:139
Cantera::SingleSpeciesTP::SingleSpeciesTP
SingleSpeciesTP()
Base empty constructor.
Definition: SingleSpeciesTP.cpp:19
Cantera::SingleSpeciesTP::_updateThermo
void _updateThermo() const
Definition: SingleSpeciesTP.cpp:259
Cantera::SingleSpeciesTP::getChemPotentials
virtual void getChemPotentials(doublereal *mu) const
Get the array of chemical potentials.
Definition: SingleSpeciesTP.cpp:91
Cantera::SingleSpeciesTP::getGibbs_ref
virtual void getGibbs_ref(doublereal *g) const
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
Definition: SingleSpeciesTP.cpp:158
Cantera::SingleSpeciesTP::getPureGibbs
virtual void getPureGibbs(doublereal *gpure) const
Get the Gibbs functions for the standard state of the species at the current T and P of the solution.
Definition: SingleSpeciesTP.cpp:133
Cantera::SingleSpeciesTP::setState_SV
virtual void setState_SV(double s, double v, double tol=1e-9)
Set the specific entropy (J/kg/K) and specific volume (m^3/kg).
Definition: SingleSpeciesTP.cpp:230
Cantera::SingleSpeciesTP::intEnergy_mole
virtual doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
Definition: SingleSpeciesTP.cpp:34
Cantera::SingleSpeciesTP::getEnthalpy_RT_ref
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
Definition: SingleSpeciesTP.cpp:146
Cantera::ThermoPhase::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: ThermoPhase.cpp:1140
Cantera::ThermoPhase::entropy_mass
doublereal entropy_mass() const
Specific entropy. Units: J/kg/K.
Definition: ThermoPhase.h:758
Cantera::ThermoPhase::setState_TP
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
Definition: ThermoPhase.cpp:138
Cantera::ThermoPhase::getIntEnergy_RT
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Definition: ThermoPhase.h:631
Cantera::ThermoPhase::RT
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:782
Cantera::ThermoPhase::isothermalCompressibility
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: ThermoPhase.h:283
Cantera::ThermoPhase::m_tlast
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1928
Cantera::ThermoPhase::getCp_R
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition: ThermoPhase.h:642
Cantera::ThermoPhase::getEnthalpy_RT
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition: ThermoPhase.h:590
Cantera::ThermoPhase::getEntropy_R
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition: ThermoPhase.h:600
Cantera::ThermoPhase::cp_mass
doublereal cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
Definition: ThermoPhase.h:768
Cantera::ThermoPhase::cv_mass
doublereal cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
Definition: ThermoPhase.h:773
Cantera::ThermoPhase::intEnergy_mass
doublereal intEnergy_mass() const
Specific internal energy. Units: J/kg.
Definition: ThermoPhase.h:753
Cantera::ThermoPhase::thermalExpansionCoeff
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: ThermoPhase.h:294
Cantera::ThermoPhase::m_spthermo
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1894
Cantera::ThermoPhase::enthalpy_mass
doublereal enthalpy_mass() const
Specific enthalpy. Units: J/kg.
Definition: ThermoPhase.h:748
Cantera::ThermoPhase::getGibbs_RT
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Definition: ThermoPhase.h:610
Cantera::ThermoPhase::getStandardChemPotentials
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition: ThermoPhase.h:580
global.h
This file contains definitions for utility functions and text for modules, inputfiles,...
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::OneAtm
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:81
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
Cantera::clip
T clip(const T &value, const T &lower, const T &upper)
Clip value such that lower <= value <= upper.
Definition: global.h:356
stringUtils.h
Contains declarations for string manipulation functions within Cantera.