Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 /*
9  * Copyright (2005) Sandia Corporation. Under the terms of
10  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
11  * U.S. Government retains certain rights in this software.
12  */
15 #include "cantera/base/global.h"
16 
17 using namespace std;
18 
19 namespace Cantera
20 {
21 SingleSpeciesTP::SingleSpeciesTP() :
22  m_press(OneAtm),
23  m_p0(OneAtm)
24 {
25 }
26 
28  m_press(OneAtm),
29  m_p0(OneAtm)
30 {
31  *this = right;
32 }
33 
35 {
36  if (&right != this) {
38  m_press = right.m_press;
39  m_p0 = right.m_p0;
40  m_h0_RT = right.m_h0_RT;
41  m_cp0_R = right.m_cp0_R;
42  m_s0_R = right.m_s0_R;
43  }
44  return *this;
45 }
46 
48 {
49  return new SingleSpeciesTP(*this);
50 }
51 
53 {
54  throw NotImplementedError("SingleSpeciesTP::eosType");
55 }
56 
57 /*
58  * ------------ Molar Thermodynamic Properties --------------------
59  */
60 
62 {
63  double hbar;
65  return hbar;
66 }
67 
69 {
70  double ubar;
72  return ubar;
73 }
74 
76 {
77  double sbar;
79  return sbar;
80 }
81 
82 doublereal SingleSpeciesTP::gibbs_mole() const
83 {
84  double gbar;
85  /*
86  * Get the chemical potential of the first species.
87  * This is the same as the partial molar Gibbs
88  * free energy.
89  */
90  getChemPotentials(&gbar);
91  return gbar;
92 }
93 
94 doublereal SingleSpeciesTP::cp_mole() const
95 {
96  double cpbar;
97  /*
98  * Really should have a partial molar heat capacity
99  * function in ThermoPhase. However, the standard
100  * state heat capacity will do fine here for now.
101  */
102  getCp_R(&cpbar);
103  cpbar *= GasConstant;
104  return cpbar;
105 }
106 
107 doublereal SingleSpeciesTP::cv_mole() const
108 {
109  /*
110  * For single species, we go directory to the general Cp - Cv relation
111  *
112  * Cp = Cv + alpha**2 * V * T / beta
113  *
114  * where
115  * alpha = volume thermal expansion coefficient
116  * beta = isothermal compressibility
117  */
118  doublereal cvbar = cp_mole();
119  doublereal alpha = thermalExpansionCoeff();
120  doublereal beta = isothermalCompressibility();
121  doublereal V = molecularWeight(0)/density();
122  doublereal T = temperature();
123  if (beta != 0.0) {
124  cvbar -= alpha * alpha * V * T / beta;
125  }
126  return cvbar;
127 }
128 
129 /*
130  * ----------- Partial Molar Properties of the Solution -----------------
131  */
132 
133 void SingleSpeciesTP::getChemPotentials(doublereal* mu) const
134 {
136 }
137 
138 void SingleSpeciesTP::getChemPotentials_RT(doublereal* murt) const
139 {
141  murt[0] /= GasConstant * temperature();
142 }
143 
145 {
146  getChemPotentials(mu);
147 }
148 
149 void SingleSpeciesTP::getPartialMolarEnthalpies(doublereal* hbar) const
150 {
151  getEnthalpy_RT(hbar);
152  hbar[0] *= GasConstant * temperature();
153 }
154 
156 {
157  getIntEnergy_RT(ubar);
158  ubar[0] *= GasConstant * temperature();
159 }
160 
161 void SingleSpeciesTP::getPartialMolarEntropies(doublereal* sbar) const
162 {
163  getEntropy_R(sbar);
164  sbar[0] *= GasConstant;
165 }
166 
167 void SingleSpeciesTP::getPartialMolarCp(doublereal* cpbar) const
168 {
169  getCp_R(cpbar);
170  cpbar[0] *= GasConstant;
171 }
172 
173 void SingleSpeciesTP::getPartialMolarVolumes(doublereal* vbar) const
174 {
175  vbar[0] = molecularWeight(0) / density();
176 }
177 
178 /*
179  * Properties of the Standard State of the Species in the Solution
180  */
181 
182 void SingleSpeciesTP::getPureGibbs(doublereal* gpure) const
183 {
184  getGibbs_RT(gpure);
185  gpure[0] *= GasConstant * temperature();
186 }
187 
188 void SingleSpeciesTP::getStandardVolumes(doublereal* vbar) const
189 {
190  vbar[0] = molecularWeight(0) / density();
191 }
192 
193 /*
194  * ---- Thermodynamic Values for the Species Reference States -------
195  */
196 
197 void SingleSpeciesTP::getEnthalpy_RT_ref(doublereal* hrt) const
198 {
199  _updateThermo();
200  hrt[0] = m_h0_RT[0];
201 }
202 
203 void SingleSpeciesTP::getGibbs_RT_ref(doublereal* grt) const
204 {
205  _updateThermo();
206  grt[0] = m_h0_RT[0] - m_s0_R[0];
207 }
208 
209 void SingleSpeciesTP::getGibbs_ref(doublereal* g) const
210 {
211  getGibbs_RT_ref(g);
212  g[0] *= GasConstant * temperature();
213 }
214 
215 void SingleSpeciesTP::getEntropy_R_ref(doublereal* er) const
216 {
217  _updateThermo();
218  er[0] = m_s0_R[0];
219 }
220 
221 void SingleSpeciesTP::getCp_R_ref(doublereal* cpr) const
222 {
223  _updateThermo();
224  cpr[0] = m_cp0_R[0];
225 }
226 
227 /*
228  * ------------------ Setting the State ------------------------
229  */
230 
231 void SingleSpeciesTP::setState_HP(doublereal h, doublereal p,
232  doublereal tol)
233 {
234  doublereal dt;
235  setPressure(p);
236  for (int n = 0; n < 50; n++) {
237  dt = clip((h - enthalpy_mass())/cp_mass(), -100.0, 100.0);
238  setState_TP(temperature() + dt, p);
239  if (fabs(dt) < tol) {
240  return;
241  }
242  }
243  throw CanteraError("setState_HP","no convergence. dt = " + fp2str(dt));
244 }
245 
246 void SingleSpeciesTP::setState_UV(doublereal u, doublereal v,
247  doublereal tol)
248 {
249  doublereal dt;
250  if (v == 0.0) {
251  setDensity(1.0E100);
252  } else {
253  setDensity(1.0/v);
254  }
255  for (int n = 0; n < 50; n++) {
256  dt = clip((u - intEnergy_mass())/cv_mass(), -100.0, 100.0);
257  setTemperature(temperature() + dt);
258  if (fabs(dt) < tol) {
259  return;
260  }
261  }
262  throw CanteraError("setState_UV",
263  "no convergence. dt = " + fp2str(dt)+"\n"
264  +"u = "+fp2str(u)+" v = "+fp2str(v)+"\n");
265 }
266 
267 void SingleSpeciesTP::setState_SP(doublereal s, doublereal p,
268  doublereal tol)
269 {
270  doublereal dt;
271  setPressure(p);
272  for (int n = 0; n < 50; n++) {
273  dt = clip((s - entropy_mass())*temperature()/cp_mass(), -100.0, 100.0);
274  setState_TP(temperature() + dt, p);
275  if (fabs(dt) < tol) {
276  return;
277  }
278  }
279  throw CanteraError("setState_SP","no convergence. dt = " + fp2str(dt));
280 }
281 
282 void SingleSpeciesTP::setState_SV(doublereal s, doublereal v,
283  doublereal tol)
284 {
285  doublereal dt;
286  if (v == 0.0) {
287  setDensity(1.0E100);
288  } else {
289  setDensity(1.0/v);
290  }
291  for (int n = 0; n < 50; n++) {
292  dt = clip((s - entropy_mass())*temperature()/cv_mass(), -100.0, 100.0);
293  setTemperature(temperature() + dt);
294  if (fabs(dt) < tol) {
295  return;
296  }
297  }
298  throw CanteraError("setState_SV","no convergence. dt = " + fp2str(dt));
299 }
300 
302 {
303  /*
304  * Make sure there is one and only one species in this phase.
305  */
306  if (nSpecies() != 1) {
307  throw CanteraError("initThermo",
308  "stoichiometric substances may only contain one species.");
309  }
310 
311  /*
312  * Resize temporary arrays.
313  */
314  m_h0_RT.resize(1);
315  m_cp0_R.resize(1);
316  m_s0_R.resize(1);
317 
318  /*
319  * Make sure the species mole fraction is equal to 1.0;
320  */
321  double x = 1.0;
323  /*
324  * Call the base class initThermo object.
325  */
327 }
328 
330 {
331  doublereal tnow = temperature();
332  if (m_tlast != tnow) {
334  DATA_PTR(m_s0_R));
335  m_tlast = tnow;
336  }
337 }
338 
339 }
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:494
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:608
doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
ThermoPhase * duplMyselfAsThermoPhase() const
Duplication function.
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:213
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:680
virtual void setState_HP(doublereal h, doublereal p, doublereal tol=1.e-8)
Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of the phase.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
ThermoPhase & operator=(const ThermoPhase &right)
Assignment operator.
Definition: ThermoPhase.cpp:60
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
virtual void setState_UV(doublereal u, doublereal v, doublereal tol=1.e-8)
Set the specific internal energy (J/kg) and specific volume (m^3/kg).
T clip(const T &value, const T &lower, const T &upper)
Clip value such that lower <= value <= upper.
Definition: global.h:270
virtual void getEntropy_R_ref(doublereal *er) const
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:670
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).
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:1656
vector_fp m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: ThermoPhase.h:321
doublereal intEnergy_mass() const
Specific internal energy.
Definition: ThermoPhase.h:899
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
void getChemPotentials_RT(doublereal *murt) const
Get the array of non-dimensional species chemical potentials These are partial molar Gibbs free energ...
void getPartialMolarEnthalpies(doublereal *hbar) const
Get the species partial molar enthalpies. Units: J/kmol.
virtual void getGibbs_RT_ref(doublereal *grt) const
virtual void getCp_R_ref(doublereal *cprt) const
void getPartialMolarEntropies(doublereal *sbar) const
Get the species partial molar entropy. Units: J/kmol K.
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:721
doublereal entropy_mass() const
Specific entropy.
Definition: ThermoPhase.h:906
virtual int eosType() const
Returns the equation of state type flag.
doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
void getChemPotentials(doublereal *mu) const
Get the array of chemical potentials.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:28
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:732
SingleSpeciesTP & operator=(const SingleSpeciesTP &right)
Assignment operator.
doublereal cp_mass() const
Specific heat at constant pressure.
Definition: ThermoPhase.h:920
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials. Units: J/kmol.
doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
vector_fp m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
doublereal cv_mass() const
Specific heat at constant volume.
Definition: ThermoPhase.h:927
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 There is no restriction on the sum of the mole fractio...
Definition: Phase.cpp:331
vector_fp m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
virtual void getGibbs_ref(doublereal *g) const
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_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:265
virtual void setState_SP(doublereal s, doublereal p, doublereal tol=1.e-8)
Set the specific entropy (J/kg/K) and pressure (Pa).
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: ThermoPhase.h:310
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:690
doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition: ThermoPhase.h:295
virtual void setState_SV(doublereal s, doublereal v, doublereal tol=1.e-8)
Set the specific entropy (J/kg/K) and specific volume (m^3/kg).
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:638
doublereal enthalpy_mass() const
Specific enthalpy.
Definition: ThermoPhase.h:892
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
Contains declarations for string manipulation functions within Cantera.
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
Definition: ct_defs.h:36
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Get the species partial molar internal energies. Units: J/kmol.
doublereal m_press
The current pressure of the solution (Pa)
doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
void getPartialMolarVolumes(doublereal *vbar) const
Get the species partial molar volumes. Units: m^3/kmol.
void getPureGibbs(doublereal *gpure) const
Get the dimensional Gibbs functions for the standard state of the species at the current T and P...
SingleSpeciesTP()
Base empty constructor.
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const =0
Compute the reference-state properties for all species.
SpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1607
The SingleSpeciesTP class is a filter class for ThermoPhase.
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:700
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase Note the density of a phase is an independent...
Definition: Phase.h:623