Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
10 #include "cantera/base/ctml.h"
11 
12 namespace Cantera
13 {
15  m_press(OneAtm),
16  m_p0(OneAtm)
17 {
18 }
19 
21  m_press(OneAtm),
22  m_p0(OneAtm)
23 {
24  *this = right;
25 }
26 
28 {
29  if (&right != this) {
31  m_press = right.m_press;
32  m_p0 = right.m_p0;
33  m_h0_RT = right.m_h0_RT;
34  m_cp0_R = right.m_cp0_R;
35  m_s0_R = right.m_s0_R;
36  }
37  return *this;
38 }
39 
41 {
42  return new StoichSubstance(*this);
43 }
44 
46 {
47  return intEnergy_mole() + m_press / molarDensity();
48 }
49 
51 {
52  _updateThermo();
53  return GasConstant * temperature() * m_h0_RT[0]
54  - m_p0 / molarDensity();
55 }
56 
58 {
59  _updateThermo();
60  return GasConstant * m_s0_R[0];
61 }
62 
63 doublereal StoichSubstance::cp_mole() const
64 {
65  _updateThermo();
66  return GasConstant * m_cp0_R[0];
67 }
68 
69 doublereal StoichSubstance::cv_mole() const
70 {
71  return cp_mole();
72 }
73 
75 {
77  if (m_kk > 1) {
78  throw CanteraError("initThermo",
79  "stoichiometric substances may only contain one species.");
80  }
81  doublereal tmin = m_spthermo->minTemp();
82  doublereal tmax = m_spthermo->maxTemp();
83  m_p0 = refPressure();
84 
85  m_h0_RT.resize(m_kk);
86  m_cp0_R.resize(m_kk);
87  m_s0_R.resize(m_kk);
88 
89  // Put the object on a valid temperature point.
90  double tnow = 300.;
91  if (tnow > tmin && tnow < tmax) {
92 
93  } else {
94  tnow = 0.1 * (9 * tmin + tmax);
95  }
96  setState_TP(tnow, m_p0);
97 }
98 
99 void StoichSubstance::_updateThermo() const
100 {
101  doublereal tnow = temperature();
102  if (m_tlast != tnow) {
103  m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0],
104  &m_s0_R[0]);
105  m_tlast = tnow;
106  }
107 }
108 
109 doublereal StoichSubstance::pressure() const
110 {
111  return m_press;
112 }
113 
115 {
116  m_press = p;
117 }
118 
120 {
121  c[0] = 1.0;
122 }
123 
124 doublereal StoichSubstance::standardConcentration(size_t k) const
125 {
126  return 1.0;
127 }
128 
129 doublereal StoichSubstance::logStandardConc(size_t k) const
130 {
131  return 0.0;
132 }
133 
135 {
136  mu0[0] = gibbs_mole();
137 }
138 
139 void StoichSubstance::getUnitsStandardConc(double* uA, int k, int sizeUA) const
140 {
141  warn_deprecated("StoichSubstance::getUnitsStandardConc",
142  "To be removed after Cantera 2.2.");
143  for (int i = 0; i < sizeUA; i++) {
144  uA[i] = 0.0;
145  }
146 }
147 
148 void StoichSubstance::getChemPotentials_RT(doublereal* mu) const
149 {
150  mu[0] = gibbs_mole() / (GasConstant * temperature());
151 }
152 
153 void StoichSubstance::getChemPotentials(doublereal* mu) const
154 {
155  mu[0] = gibbs_mole();
156 }
157 
159 {
160  getChemPotentials(mu);
161 }
162 
163 void StoichSubstance::getPartialMolarEnthalpies(doublereal* hbar) const
164 {
165  hbar[0] = enthalpy_mole();
166 }
167 
168 void StoichSubstance::getPartialMolarEntropies(doublereal* sbar) const
169 {
170  sbar[0] = entropy_mole();
171 }
172 
174 {
175  ubar[0] = intEnergy_mole();
176 }
177 
178 void StoichSubstance::getPartialMolarCp(doublereal *cpbar) const
179 {
180  cpbar[0] = cp_mole();
181 }
182 
183 void StoichSubstance::getPartialMolarVolumes(doublereal* vbar) const
184 {
185  vbar[0] = 1.0 / molarDensity();
186 }
187 
188 void StoichSubstance::getEnthalpy_RT(doublereal* hrt) const
189 {
190  hrt[0] = enthalpy_mole() / (GasConstant * temperature());
191 }
192 
193 void StoichSubstance::getEntropy_R(doublereal* sr) const
194 {
195  sr[0] = entropy_mole() / GasConstant;
196 }
197 
198 void StoichSubstance::getGibbs_RT(doublereal* grt) const
199 {
200  grt[0] = gibbs_mole() / (GasConstant * temperature());
201 }
202 
203 void StoichSubstance::getPureGibbs(doublereal* gpure) const
204 {
205  gpure[0] = gibbs_mole();
206 }
207 
208 void StoichSubstance::getCp_R(doublereal* cpr) const
209 {
210  cpr[0] = cp_mole() / GasConstant;
211 }
212 
213 void StoichSubstance::getStandardVolumes(doublereal* vol) const
214 {
215  vol[0] = 1.0 / molarDensity();
216 }
217 
218 void StoichSubstance::getEnthalpy_RT_ref(doublereal* hrt) const
219 {
220  _updateThermo();
221  hrt[0] = m_h0_RT[0];
222 }
223 
224 void StoichSubstance::getGibbs_RT_ref(doublereal* grt) const
225 {
226  _updateThermo();
227  grt[0] = m_h0_RT[0] - m_s0_R[0];
228 }
229 
230 void StoichSubstance::getGibbs_ref(doublereal* g) const
231 {
232  getGibbs_RT_ref(g);
233  g[0] *= GasConstant * temperature();
234 }
235 
236 void StoichSubstance::getEntropy_R_ref(doublereal* er) const
237 {
238  _updateThermo();
239  er[0] = m_s0_R[0];
240 }
241 
242 void StoichSubstance::getCp_R_ref(doublereal* cprt) const
243 {
244  _updateThermo();
245  cprt[0] = m_cp0_R[0];
246 }
247 
248 void StoichSubstance::setParameters(int n, double* const c)
249 {
250  double rho = c[0];
251  setDensity(rho);
252 }
253 
254 void StoichSubstance::getParameters(int& n, double* const c) const
255 {
256  double rho = density();
257  c[0] = rho;
258 }
259 
261 {
262  eosdata._require("model","StoichSubstance");
263  doublereal rho = getFloat(eosdata, "density", "toSI");
264  setDensity(rho);
265 }
266 
267 }
virtual doublereal enthalpy_mole() const
Molar enthalpy.
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:603
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:608
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.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
Definition: ThermoPhase.h:242
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
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 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
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:78
ThermoPhase * duplMyselfAsThermoPhase() const
Duplicator from the ThermoPhase parent class.
doublereal molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:663
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 getPartialMolarCp(doublereal *cpbar) const
Get the partial molar heat capacities Units: J/kmol/K.
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1656
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)
Set the equation of state parameters.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
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:99
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:150
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:602
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Get the species partial molar enthalpies. Units: J/kmol.
virtual void getParameters(int &n, double *const c) const
Get the equation of state parameters in a vector.
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:64
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:194
This file contains the class declarations for the StoichSubstance ThermoPhase class.
size_t m_kk
Number of species in the phase.
Definition: Phase.h:843
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:1607
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:623