Cantera  2.1.2
StoichSubstance.cpp
Go to the documentation of this file.
1 /**
2  * @file StoichSubstance.cpp
3  * This file contains the class definitions for the StoichSubstance
4  * ThermoPhase class.
5  */
6 
7 // Copyright 2001 California Institute of Technology
8 
9 #include "cantera/base/ct_defs.h"
13 
14 namespace Cantera
15 {
17  m_press(OneAtm),
18  m_p0(OneAtm),
19  m_tlast(-1.0)
20 {
21 }
22 
24  m_press(OneAtm),
25  m_p0(OneAtm),
26  m_tlast(-1.0)
27 {
28  *this = operator=(right);
29 }
30 
33 {
34  if (&right != this) {
36  m_press = right.m_press;
37  m_p0 = right.m_p0;
38  m_tlast = right.m_tlast;
39  m_h0_RT = right.m_h0_RT;
40  m_cp0_R = right.m_cp0_R;
41  m_s0_R = right.m_s0_R;
42  }
43  return *this;
44 }
45 
47 {
48  return new StoichSubstance(*this);
49 }
50 
52 {
53  return intEnergy_mole() + m_press / molarDensity();
54 }
55 
57 {
58  _updateThermo();
59  return GasConstant * temperature() * m_h0_RT[0]
60  - m_p0 / molarDensity();
61 }
62 
64 {
65  _updateThermo();
66  return GasConstant * m_s0_R[0];
67 }
68 
69 doublereal StoichSubstance::gibbs_mole() const
70 {
71  return enthalpy_mole() - temperature() * entropy_mole();
72 }
73 
74 doublereal StoichSubstance::cp_mole() const
75 {
76  _updateThermo();
77  return GasConstant * m_cp0_R[0];
78 }
79 
80 doublereal StoichSubstance::cv_mole() const
81 {
82  return cp_mole();
83 }
84 
86 {
87  if (m_kk > 1) {
88  throw CanteraError("initThermo",
89  "stoichiometric substances may only contain one species.");
90  }
91  doublereal tmin = m_spthermo->minTemp();
92  doublereal tmax = m_spthermo->maxTemp();
93  m_p0 = refPressure();
94 
95  m_h0_RT.resize(m_kk);
96  m_cp0_R.resize(m_kk);
97  m_s0_R.resize(m_kk);
98 
99  // Put the object on a valid temperature point.
100  double tnow = 300.;
101  if (tnow > tmin && tnow < tmax) {
102 
103  } else {
104  tnow = 0.1 * (9 * tmin + tmax);
105  }
106  setState_TP(tnow, m_p0);
107 }
108 
109 void StoichSubstance::_updateThermo() const
110 {
111  doublereal tnow = temperature();
112  if (m_tlast != tnow) {
113  m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0],
114  &m_s0_R[0]);
115  m_tlast = tnow;
116  }
117 }
118 
119 doublereal StoichSubstance::pressure() const
120 {
121  return m_press;
122 }
123 
125 {
126  m_press = p;
127 }
128 
130 {
131  c[0] = 1.0;
132 }
133 
134 doublereal StoichSubstance::standardConcentration(size_t k) const
135 {
136  return 1.0;
137 }
138 
139 doublereal StoichSubstance::logStandardConc(size_t k) const
140 {
141  return 0.0;
142 }
143 
145 {
146  mu0[0] = gibbs_mole();
147 }
148 
150 getUnitsStandardConc(double* uA, int k, int sizeUA) const
151 {
152  for (int i = 0; i < sizeUA; i++) {
153  uA[i] = 0.0;
154  }
155 }
156 
157 void StoichSubstance::getChemPotentials_RT(doublereal* mu) const
158 {
159  mu[0] = gibbs_mole() / (GasConstant * temperature());
160 }
161 
162 void StoichSubstance::getChemPotentials(doublereal* mu) const
163 {
164  mu[0] = gibbs_mole();
165 }
166 
168 {
169  getChemPotentials(mu);
170 }
171 
172 void StoichSubstance::getPartialMolarEnthalpies(doublereal* hbar) const
173 {
174  hbar[0] = enthalpy_mole();
175 }
176 
177 void StoichSubstance::getPartialMolarEntropies(doublereal* sbar) const
178 {
179  sbar[0] = entropy_mole();
180 }
181 
182 void StoichSubstance::getPartialMolarVolumes(doublereal* vbar) const
183 {
184  vbar[0] = 1.0 / molarDensity();
185 }
186 
187 void StoichSubstance::getEnthalpy_RT(doublereal* hrt) const
188 {
189  hrt[0] = enthalpy_mole() / (GasConstant * temperature());
190 }
191 
192 void StoichSubstance::getEntropy_R(doublereal* sr) const
193 {
194  sr[0] = entropy_mole() / GasConstant;
195 }
196 
197 void StoichSubstance::getGibbs_RT(doublereal* grt) const
198 {
199  grt[0] = gibbs_mole() / (GasConstant * temperature());
200 }
201 
202 void StoichSubstance::getPureGibbs(doublereal* gpure) const
203 {
204  gpure[0] = gibbs_mole();
205 }
206 
207 void StoichSubstance::getCp_R(doublereal* cpr) const
208 {
209  cpr[0] = cp_mole() / GasConstant;
210 }
211 
212 void StoichSubstance::getStandardVolumes(doublereal* vol) const
213 {
214  vol[0] = 1.0 / molarDensity();
215 }
216 
217 void StoichSubstance::getEnthalpy_RT_ref(doublereal* hrt) const
218 {
219  _updateThermo();
220  hrt[0] = m_h0_RT[0];
221 }
222 
223 void StoichSubstance::getGibbs_RT_ref(doublereal* grt) const
224 {
225  _updateThermo();
226  grt[0] = m_h0_RT[0] - m_s0_R[0];
227 }
228 
229 void StoichSubstance::getGibbs_ref(doublereal* g) const
230 {
231  getGibbs_RT_ref(g);
232  g[0] *= GasConstant * temperature();
233 }
234 
235 void StoichSubstance::getEntropy_R_ref(doublereal* er) const
236 {
237  _updateThermo();
238  er[0] = m_s0_R[0];
239 }
240 
241 void StoichSubstance::getCp_R_ref(doublereal* cprt) const
242 {
243  _updateThermo();
244  cprt[0] = m_cp0_R[0];
245 }
246 
247 void StoichSubstance::setParameters(int n, double* const c)
248 {
249  warn_deprecated("StoichSubstance::setParameters");
250  double rho = c[0];
251  setDensity(rho);
252 }
253 
254 void StoichSubstance::getParameters(int& n, double* const c) const
255 {
256  warn_deprecated("StoichSubstance::getParameters");
257  double rho = density();
258  c[0] = rho;
259 }
260 
262 {
263  eosdata._require("model","StoichSubstance");
264  doublereal rho = ctml::getFloat(eosdata, "density", "toSI");
265  setDensity(rho);
266 }
267 
268 }
virtual doublereal enthalpy_mole() const
Molar enthalpy.
virtual doublereal gibbs_mole() const
Molar gibbs Function.
void _require(const std::string &a, const std::string &v) const
Require that the current xml node have an attribute named by the first argument, a, and that this attribute have the the string value listed in the second argument, v.
Definition: xml.cpp:614
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:534
virtual void getActivityConcentrations(doublereal *c) const
This method returns the array of generalized concentrations.
virtual void getUnitsStandardConc(double *uA, int k=0, int sizeUA=6) const
Returns the units of the standard and generalized concentrations.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:71
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
ThermoPhase & operator=(const ThermoPhase &right)
Assignment operator.
Definition: ThermoPhase.cpp:57
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 maxTemp(size_t k=npos) const =0
Maximum temperature.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:76
Virtual base class for the calculation of multiple-species thermodynamic reference-state property man...
doublereal getFloat(const Cantera::XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:267
ThermoPhase * duplMyselfAsThermoPhase() const
Duplicator from the ThermoPhase parent class.
doublereal molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:597
virtual void getPartialMolarVolumes(doublereal *vbar) const
returns an array of partial molar volumes of the species in the solution.
virtual doublereal logStandardConc(size_t k=0) const
Returns the natural logarithm of the standard concentration of the kth species.
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure.
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
virtual void getStandardChemPotentials(doublereal *mu0) const
Get the array of chemical potentials at unit activity .
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...
Class StoichSubstance represents a stoichiometric (fixed composition) incompressible substance...
virtual void setParameters(int n, double *const c)
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
StoichSubstance & operator=(const StoichSubstance &right)
Assignment operator.
virtual void getStandardVolumes(doublereal *vol) const
Get the standard volumes for the standard state of the species at the current T and P...
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
virtual doublereal pressure() const
Report the Pressure. Units: Pa.
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 getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the standard state of the species at ...
virtual doublereal cv_mole() const
Molar heat capacity at constant volume.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
virtual void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional chemical potentials .
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species at their standard states of solution at the cu...
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
virtual doublereal intEnergy_mole() const
Molar internal energy.
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:159
virtual doublereal minTemp(size_t k=npos) const =0
Minimum temperature.
StoichSubstance()
Default empty constructor.
virtual doublereal entropy_mole() const
Molar entropy.
doublereal temperature() const
Temperature (K).
Definition: Phase.h:528
virtual void getParameters(int &n, double *const c) const
virtual void getChemPotentials(doublereal *mu) const
For a stoichiometric substance, there is only one species.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
This file contains the class declarations for the StoichSubstance ThermoPhase class.
size_t m_kk
Number of species in the phase.
Definition: Phase.h:716
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const =0
Compute the reference-state properties for all species.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Enthalpy functions for the standard state species at the current T an...
SpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1625
virtual doublereal standardConcentration(size_t k=0) const
The standard concentration.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
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:549