Cantera  2.4.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 http://www.cantera.org/license.txt for license and copyright information.
10 
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 
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 
48 doublereal 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 
58 doublereal 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 
69 doublereal 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 {
94 }
95 
96 void SingleSpeciesTP::getChemPotentials_RT(doublereal* murt) const
97 {
99  murt[0] /= RT();
100 }
101 
102 void SingleSpeciesTP::getPartialMolarEnthalpies(doublereal* hbar) const
103 {
104  getEnthalpy_RT(hbar);
105  hbar[0] *= RT();
106 }
107 
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("setState_HP","no convergence. dt = {}", dt);
191 }
192 
193 void SingleSpeciesTP::setState_UV(doublereal u, doublereal v,
194  doublereal tol)
195 {
196  doublereal dt;
197  if (v == 0.0) {
198  setDensity(1.0E100);
199  } else {
200  setDensity(1.0/v);
201  }
202  for (int n = 0; n < 50; n++) {
203  dt = clip((u - intEnergy_mass())/cv_mass(), -100.0, 100.0);
204  setTemperature(temperature() + dt);
205  if (fabs(dt / temperature()) < tol) {
206  return;
207  }
208  }
209  throw CanteraError("setState_UV", "no convergence. dt = {}\n"
210  "u = {} v = {}\n", dt, u, v);
211 }
212 
213 void SingleSpeciesTP::setState_SP(doublereal s, doublereal p,
214  doublereal tol)
215 {
216  doublereal dt;
217  setPressure(p);
218  for (int n = 0; n < 50; n++) {
219  dt = clip((s - entropy_mass())*temperature()/cp_mass(), -100.0, 100.0);
220  setState_TP(temperature() + dt, p);
221  if (fabs(dt / temperature()) < tol) {
222  return;
223  }
224  }
225  throw CanteraError("setState_SP","no convergence. dt = {}", dt);
226 }
227 
228 void SingleSpeciesTP::setState_SV(doublereal s, doublereal v,
229  doublereal tol)
230 {
231  doublereal dt;
232  if (v == 0.0) {
233  setDensity(1.0E100);
234  } else {
235  setDensity(1.0/v);
236  }
237  for (int n = 0; n < 50; n++) {
238  dt = clip((s - entropy_mass())*temperature()/cv_mass(), -100.0, 100.0);
239  setTemperature(temperature() + dt);
240  if (fabs(dt / temperature()) < tol) {
241  return;
242  }
243  }
244  throw CanteraError("setState_SV","no convergence. dt = {}", dt);
245 }
246 
247 bool SingleSpeciesTP::addSpecies(shared_ptr<Species> spec)
248 {
249  if (m_kk != 0) {
250  throw CanteraError("SingleSpeciesTP::addSpecies",
251  "Stoichiometric substances may only contain one species.");
252  }
253  bool added = ThermoPhase::addSpecies(spec);
254  if (added) {
255  double x = 1.0;
257  }
258  return added;
259 }
260 
262 {
263  doublereal tnow = temperature();
264  if (m_tlast != tnow) {
265  m_spthermo.update(tnow, &m_cp0_R, &m_h0_RT, &m_s0_R);
266  m_tlast = tnow;
267  }
268 }
269 
270 }
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 bool addSpecies(shared_ptr< Species > spec)
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
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).
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1607
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: ThermoPhase.h:271
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
doublereal temperature() const
Temperature (K).
Definition: Phase.h:601
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
doublereal cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
Definition: ThermoPhase.h:734
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:576
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: ThermoPhase.h:260
virtual bool addSpecies(shared_ptr< Species > spec)
T clip(const T &value, const T &lower, const T &upper)
Clip value such that lower <= value <= upper.
Definition: global.h:269
STL namespace.
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:607
virtual void getPartialMolarEntropies(doublereal *sbar) const
Get the species partial molar entropy. Units: J/kmol K.
doublereal enthalpy_mass() const
Specific enthalpy. Units: J/kg.
Definition: ThermoPhase.h:714
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, (see Input File Handling, Diagnostic Output, and Writing messages to the screen).
virtual void getPartialMolarCp(doublereal *cpbar) const
Get the species partial molar Heat Capacities. Units: J/ kmol /K.
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1643
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:748
double m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
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:597
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...
virtual void setState_SP(double s, double p, double tol=1e-9)
Set the specific entropy (J/kg/K) and pressure (Pa).
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:556
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Get the species partial molar enthalpies. Units: J/kmol.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
virtual void getChemPotentials(doublereal *mu) const
Get the array of chemical potentials.
doublereal entropy_mass() const
Specific entropy. Units: J/kg/K.
Definition: ThermoPhase.h:724
virtual void getChemPotentials_RT(doublereal *murt) const
Get the array of non-dimensional species chemical potentials.
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
Header for the SingleSpeciesTP class, which is a filter class for ThermoPhase, that eases the constru...
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values.
Definition: Phase.cpp:251
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 getPartialMolarVolumes(doublereal *vbar) const
Get the species partial molar volumes. Units: m^3/kmol.
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
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:608
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Get the species partial molar internal energies. Units: J/kmol.
doublereal cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
Definition: ThermoPhase.h:739
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition: ThermoPhase.h:770
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:637
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
Contains declarations for string manipulation functions within Cantera.
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:546
virtual doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
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:566
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 setState_HP(double h, double p, double tol=1e-9)
Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of the phase.
size_t m_kk
Number of species in the phase.
Definition: Phase.h:788
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:420
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
doublereal intEnergy_mass() const
Specific internal energy. Units: J/kg.
Definition: ThermoPhase.h:719
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 void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase.
Definition: Phase.h:622
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.