Cantera  2.3.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 
26  m_press(OneAtm),
27  m_p0(OneAtm)
28 {
29  *this = right;
30 }
31 
32 SingleSpeciesTP& SingleSpeciesTP::operator=(const SingleSpeciesTP& right)
33 {
34  if (&right != this) {
36  m_press = right.m_press;
37  m_p0 = right.m_p0;
38  m_h0_RT = right.m_h0_RT;
39  m_cp0_R = right.m_cp0_R;
40  m_s0_R = right.m_s0_R;
41  }
42  return *this;
43 }
44 
46 {
47  return new SingleSpeciesTP(*this);
48 }
49 
51 {
52  warn_deprecated("SingleSpeciesTP::eosType",
53  "To be removed after Cantera 2.3.");
54  throw NotImplementedError("SingleSpeciesTP::eosType");
55 }
56 
57 // ------------ Molar Thermodynamic Properties --------------------
58 
60 {
61  double hbar;
63  return hbar;
64 }
65 
67 {
68  double ubar;
70  return ubar;
71 }
72 
74 {
75  double sbar;
77  return sbar;
78 }
79 
80 doublereal SingleSpeciesTP::gibbs_mole() const
81 {
82  double gbar;
83 
84  // Get the chemical potential of the first species. This is the same as the
85  // partial molar Gibbs free energy.
86  getChemPotentials(&gbar);
87  return gbar;
88 }
89 
90 doublereal SingleSpeciesTP::cp_mole() const
91 {
92  double cpbar;
93 
94  // Really should have a partial molar heat capacity function in ThermoPhase.
95  // However, the standard state heat capacity will do fine here for now.
96  getCp_R(&cpbar);
97  cpbar *= GasConstant;
98  return cpbar;
99 }
100 
101 doublereal SingleSpeciesTP::cv_mole() const
102 {
103  // For single species, we go directory to the general Cp - Cv relation
104  //
105  // Cp = Cv + alpha**2 * V * T / beta
106  //
107  // where
108  // alpha = volume thermal expansion coefficient
109  // beta = isothermal compressibility
110  doublereal cvbar = cp_mole();
111  doublereal alpha = thermalExpansionCoeff();
112  doublereal beta = isothermalCompressibility();
113  doublereal V = molecularWeight(0)/density();
114  doublereal T = temperature();
115  if (beta != 0.0) {
116  cvbar -= alpha * alpha * V * T / beta;
117  }
118  return cvbar;
119 }
120 
121 // ----------- Partial Molar Properties of the Solution -----------------
122 
123 void SingleSpeciesTP::getChemPotentials(doublereal* mu) const
124 {
126 }
127 
128 void SingleSpeciesTP::getChemPotentials_RT(doublereal* murt) const
129 {
131  murt[0] /= RT();
132 }
133 
134 void SingleSpeciesTP::getPartialMolarEnthalpies(doublereal* hbar) const
135 {
136  getEnthalpy_RT(hbar);
137  hbar[0] *= RT();
138 }
139 
141 {
142  getIntEnergy_RT(ubar);
143  ubar[0] *= RT();
144 }
145 
146 void SingleSpeciesTP::getPartialMolarEntropies(doublereal* sbar) const
147 {
148  getEntropy_R(sbar);
149  sbar[0] *= GasConstant;
150 }
151 
152 void SingleSpeciesTP::getPartialMolarCp(doublereal* cpbar) const
153 {
154  getCp_R(cpbar);
155  cpbar[0] *= GasConstant;
156 }
157 
158 void SingleSpeciesTP::getPartialMolarVolumes(doublereal* vbar) const
159 {
160  vbar[0] = molecularWeight(0) / density();
161 }
162 
163 // Properties of the Standard State of the Species in the Solution
164 
165 void SingleSpeciesTP::getPureGibbs(doublereal* gpure) const
166 {
167  getGibbs_RT(gpure);
168  gpure[0] *= RT();
169 }
170 
171 void SingleSpeciesTP::getStandardVolumes(doublereal* vbar) const
172 {
173  vbar[0] = molecularWeight(0) / density();
174 }
175 
176 // ---- Thermodynamic Values for the Species Reference States -------
177 
178 void SingleSpeciesTP::getEnthalpy_RT_ref(doublereal* hrt) const
179 {
180  _updateThermo();
181  hrt[0] = m_h0_RT;
182 }
183 
184 void SingleSpeciesTP::getGibbs_RT_ref(doublereal* grt) const
185 {
186  _updateThermo();
187  grt[0] = m_h0_RT - m_s0_R;
188 }
189 
190 void SingleSpeciesTP::getGibbs_ref(doublereal* g) const
191 {
192  getGibbs_RT_ref(g);
193  g[0] *= RT();
194 }
195 
196 void SingleSpeciesTP::getEntropy_R_ref(doublereal* er) const
197 {
198  _updateThermo();
199  er[0] = m_s0_R;
200 }
201 
202 void SingleSpeciesTP::getCp_R_ref(doublereal* cpr) const
203 {
204  _updateThermo();
205  cpr[0] = m_cp0_R;
206 }
207 
208 // ------------------ Setting the State ------------------------
209 
210 void SingleSpeciesTP::setState_HP(doublereal h, doublereal p,
211  doublereal tol)
212 {
213  doublereal dt;
214  setPressure(p);
215  for (int n = 0; n < 50; n++) {
216  dt = clip((h - enthalpy_mass())/cp_mass(), -100.0, 100.0);
217  setState_TP(temperature() + dt, p);
218  if (fabs(dt / temperature()) < tol) {
219  return;
220  }
221  }
222  throw CanteraError("setState_HP","no convergence. dt = {}", dt);
223 }
224 
225 void SingleSpeciesTP::setState_UV(doublereal u, doublereal v,
226  doublereal tol)
227 {
228  doublereal dt;
229  if (v == 0.0) {
230  setDensity(1.0E100);
231  } else {
232  setDensity(1.0/v);
233  }
234  for (int n = 0; n < 50; n++) {
235  dt = clip((u - intEnergy_mass())/cv_mass(), -100.0, 100.0);
236  setTemperature(temperature() + dt);
237  if (fabs(dt / temperature()) < tol) {
238  return;
239  }
240  }
241  throw CanteraError("setState_UV", "no convergence. dt = {}\n"
242  "u = {} v = {}\n", dt, u, v);
243 }
244 
245 void SingleSpeciesTP::setState_SP(doublereal s, doublereal p,
246  doublereal tol)
247 {
248  doublereal dt;
249  setPressure(p);
250  for (int n = 0; n < 50; n++) {
251  dt = clip((s - entropy_mass())*temperature()/cp_mass(), -100.0, 100.0);
252  setState_TP(temperature() + dt, p);
253  if (fabs(dt / temperature()) < tol) {
254  return;
255  }
256  }
257  throw CanteraError("setState_SP","no convergence. dt = {}", dt);
258 }
259 
260 void SingleSpeciesTP::setState_SV(doublereal s, doublereal v,
261  doublereal tol)
262 {
263  doublereal dt;
264  if (v == 0.0) {
265  setDensity(1.0E100);
266  } else {
267  setDensity(1.0/v);
268  }
269  for (int n = 0; n < 50; n++) {
270  dt = clip((s - entropy_mass())*temperature()/cv_mass(), -100.0, 100.0);
271  setTemperature(temperature() + dt);
272  if (fabs(dt / temperature()) < tol) {
273  return;
274  }
275  }
276  throw CanteraError("setState_SV","no convergence. dt = {}", dt);
277 }
278 
279 bool SingleSpeciesTP::addSpecies(shared_ptr<Species> spec)
280 {
281  if (m_kk != 0) {
282  throw CanteraError("SingleSpeciesTP::addSpecies",
283  "Stoichiometric substances may only contain one species.");
284  }
285  bool added = ThermoPhase::addSpecies(spec);
286  if (added) {
287  double x = 1.0;
289  }
290  return added;
291 }
292 
294 {
295  doublereal tnow = temperature();
296  if (m_tlast != tnow) {
297  m_spthermo->update(tnow, &m_cp0_R, &m_h0_RT, &m_s0_R);
298  m_tlast = tnow;
299  }
300 }
301 
302 }
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).
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:304
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
virtual int eosType() const
Returns the equation of state type flag.
doublereal temperature() const
Temperature (K).
Definition: Phase.h:601
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:193
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:784
ThermoPhase & operator=(const ThermoPhase &right)
Definition: ThermoPhase.cpp:59
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:609
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: ThermoPhase.h:293
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:295
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
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:764
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:1737
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:809
double m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
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:630
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:589
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:774
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:327
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:641
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Get the species partial molar internal energies. Units: J/kmol.
MultiSpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1693
doublereal cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
Definition: ThermoPhase.h:789
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition: ThermoPhase.h:831
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.
doublereal m_press
The current pressure of the solution (Pa). It gets initialized to 1 atm.
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:579
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:599
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:784
SingleSpeciesTP()
Base empty constructor.
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:496
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: application.cpp:29
doublereal intEnergy_mass() const
Specific internal energy. Units: J/kg.
Definition: ThermoPhase.h:769
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...
The SingleSpeciesTP class is a filter class for ThermoPhase.
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.