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
13#include "cantera/base/global.h"
14
15using namespace std;
16
17namespace Cantera
18{
20 m_press(OneAtm),
21 m_p0(OneAtm)
22{
23}
24
25// ------------ Molar Thermodynamic Properties --------------------
26
28{
29 double hbar;
31 return hbar;
32}
33
35{
36 double ubar;
38 return ubar;
39}
40
42{
43 double sbar;
45 return sbar;
46}
47
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
91void SingleSpeciesTP::getChemPotentials(doublereal* mu) const
92{
94}
95
96void SingleSpeciesTP::getChemPotentials_RT(doublereal* murt) const
97{
99 murt[0] /= RT();
100}
101
103{
104 getEnthalpy_RT(hbar);
105 hbar[0] *= RT();
106}
107
109{
110 getIntEnergy_RT(ubar);
111 ubar[0] *= RT();
112}
113
115{
116 getEntropy_R(sbar);
117 sbar[0] *= GasConstant;
118}
119
120void SingleSpeciesTP::getPartialMolarCp(doublereal* cpbar) const
121{
122 getCp_R(cpbar);
123 cpbar[0] *= GasConstant;
124}
125
126void 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
133void SingleSpeciesTP::getPureGibbs(doublereal* gpure) const
134{
135 getGibbs_RT(gpure);
136 gpure[0] *= RT();
137}
138
139void SingleSpeciesTP::getStandardVolumes(doublereal* vbar) const
140{
141 vbar[0] = molecularWeight(0) / density();
142}
143
144// ---- Thermodynamic Values for the Species Reference States -------
145
146void SingleSpeciesTP::getEnthalpy_RT_ref(doublereal* hrt) const
147{
149 hrt[0] = m_h0_RT;
150}
151
152void SingleSpeciesTP::getGibbs_RT_ref(doublereal* grt) const
153{
155 grt[0] = m_h0_RT - m_s0_R;
156}
157
158void SingleSpeciesTP::getGibbs_ref(doublereal* g) const
159{
161 g[0] *= RT();
162}
163
164void SingleSpeciesTP::getEntropy_R_ref(doublereal* er) const
165{
167 er[0] = m_s0_R;
168}
169
170void SingleSpeciesTP::getCp_R_ref(doublereal* cpr) const
171{
173 cpr[0] = m_cp0_R;
174}
175
176// ------------------ Setting the State ------------------------
177
178void 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
194void 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);
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
214void 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
230void 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);
242 if (fabs(dt / temperature()) < tol) {
243 return;
244 }
245 }
246 throw CanteraError("SingleSpeciesTP::setState_SV",
247 "no convergence. dt = {}", dt);
248}
249
250bool 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
260{
261 doublereal tnow = temperature();
262 if (m_tlast != tnow) {
264 m_tlast = tnow;
265 }
266}
267
268}
Header for the SingleSpeciesTP class, which is a filter class for ThermoPhase, that eases the constru...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
size_t m_kk
Number of species in the phase.
Definition: Phase.h:943
virtual void setPressure(double p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition: Phase.h:712
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:492
virtual void setDensity(const double density_)
Set the internally stored density (kg/m^3) of the phase.
Definition: Phase.cpp:687
virtual double density() const
Density (kg/m^3).
Definition: Phase.h:679
doublereal temperature() const
Temperature (K).
Definition: Phase.h:654
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:719
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.
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).
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Get the species partial molar internal energies. Units: J/kmol.
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Get the species partial molar enthalpies. Units: J/kmol.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Get the species partial molar entropy. Units: J/kmol K.
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Get the species partial molar volumes. Units: m^3/kmol.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
virtual void getPartialMolarCp(doublereal *cpbar) const
Get the species partial molar Heat Capacities. Units: J/ kmol /K.
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
virtual void getChemPotentials_RT(doublereal *murt) const
Get the array of non-dimensional species chemical potentials.
virtual void setState_SP(double s, double p, double tol=1e-9)
Set the specific entropy (J/kg/K) and pressure (Pa).
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
double m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
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...
SingleSpeciesTP()
Base empty constructor.
virtual void getChemPotentials(doublereal *mu) const
Get the array of chemical potentials.
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...
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.
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).
virtual doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
virtual bool addSpecies(shared_ptr< Species > spec)
doublereal entropy_mass() const
Specific entropy. Units: J/kg/K.
Definition: ThermoPhase.h:758
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
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
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:782
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: ThermoPhase.h:283
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1928
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
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
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
doublereal cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
Definition: ThermoPhase.h:768
doublereal cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
Definition: ThermoPhase.h:773
doublereal intEnergy_mass() const
Specific internal energy. Units: J/kg.
Definition: ThermoPhase.h:753
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: ThermoPhase.h:294
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1894
doublereal enthalpy_mass() const
Specific enthalpy. Units: J/kg.
Definition: ThermoPhase.h:748
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
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
This file contains definitions for utility functions and text for modules, inputfiles,...
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:81
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
T clip(const T &value, const T &lower, const T &upper)
Clip value such that lower <= value <= upper.
Definition: global.h:356
Contains declarations for string manipulation functions within Cantera.