Cantera  2.4.0
LatticePhase.cpp
Go to the documentation of this file.
1 /**
2  * @file LatticePhase.cpp
3  * Definitions for a simple thermodynamics model of a bulk phase
4  * derived from ThermoPhase,
5  * assuming a lattice of solid atoms
6  * (see \ref thermoprops and class \link Cantera::LatticePhase LatticePhase\endlink).
7  */
8 
9 // This file is part of Cantera. See License.txt in the top-level directory or
10 // at http://www.cantera.org/license.txt for license and copyright information.
11 
15 #include "cantera/base/ctml.h"
16 #include "cantera/base/utilities.h"
17 
18 namespace Cantera
19 {
20 
22  m_Pref(OneAtm),
23  m_Pcurrent(OneAtm),
24  m_speciesMolarVolume(0),
25  m_site_density(0.0)
26 {
27 }
28 
29 LatticePhase::LatticePhase(const std::string& inputFile, const std::string& id_)
30 {
31  initThermoFile(inputFile, id_);
32 }
33 
34 LatticePhase::LatticePhase(XML_Node& phaseRef, const std::string& id_)
35 {
36  importPhase(phaseRef, this);
37 }
38 
39 doublereal LatticePhase::enthalpy_mole() const
40 {
41  return RT() * mean_X(enthalpy_RT_ref()) +
43 }
44 
45 doublereal LatticePhase::entropy_mole() const
46 {
47  return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx());
48 }
49 
50 doublereal LatticePhase::cp_mole() const
51 {
52  return GasConstant * mean_X(cp_R_ref());
53 }
54 
55 doublereal LatticePhase::cv_mole() const
56 {
57  return cp_mole();
58 }
59 
61 {
64 }
65 
66 void LatticePhase::setPressure(doublereal p)
67 {
68  m_Pcurrent = p;
69  calcDensity();
70 }
71 
73 {
75  calcDensity();
76 }
77 
78 void LatticePhase::getActivityConcentrations(doublereal* c) const
79 {
81 }
82 
83 void LatticePhase::getActivityCoefficients(doublereal* ac) const
84 {
85  for (size_t k = 0; k < m_kk; k++) {
86  ac[k] = 1.0;
87  }
88 }
89 
90 doublereal LatticePhase::standardConcentration(size_t k) const
91 {
92  return 1.0;
93 }
94 
95 doublereal LatticePhase::logStandardConc(size_t k) const
96 {
97  return 0.0;
98 }
99 
100 void LatticePhase::getChemPotentials(doublereal* mu) const
101 {
102  doublereal delta_p = m_Pcurrent - m_Pref;
103  const vector_fp& g_RT = gibbs_RT_ref();
104  for (size_t k = 0; k < m_kk; k++) {
105  double xx = std::max(SmallNumber, moleFraction(k));
106  mu[k] = RT() * (g_RT[k] + log(xx))
107  + delta_p * m_speciesMolarVolume[k];
108  }
109 }
110 
111 void LatticePhase::getPartialMolarEnthalpies(doublereal* hbar) const
112 {
113  const vector_fp& _h = enthalpy_RT_ref();
114  scale(_h.begin(), _h.end(), hbar, RT());
115 }
116 
117 void LatticePhase::getPartialMolarEntropies(doublereal* sbar) const
118 {
119  const vector_fp& _s = entropy_R_ref();
120  for (size_t k = 0; k < m_kk; k++) {
121  double xx = std::max(SmallNumber, moleFraction(k));
122  sbar[k] = GasConstant * (_s[k] - log(xx));
123  }
124 }
125 
126 void LatticePhase::getPartialMolarCp(doublereal* cpbar) const
127 {
128  getCp_R(cpbar);
129  for (size_t k = 0; k < m_kk; k++) {
130  cpbar[k] *= GasConstant;
131  }
132 }
133 
134 void LatticePhase::getPartialMolarVolumes(doublereal* vbar) const
135 {
136  getStandardVolumes(vbar);
137 }
138 
139 void LatticePhase::getStandardChemPotentials(doublereal* mu0) const
140 {
141  const vector_fp& gibbsrt = gibbs_RT_ref();
142  scale(gibbsrt.begin(), gibbsrt.end(), mu0, RT());
143 }
144 
145 void LatticePhase::getPureGibbs(doublereal* gpure) const
146 {
147  const vector_fp& gibbsrt = gibbs_RT_ref();
148  doublereal delta_p = (m_Pcurrent - m_Pref);
149  for (size_t k = 0; k < m_kk; k++) {
150  gpure[k] = RT() * gibbsrt[k] + delta_p * m_speciesMolarVolume[k];
151  }
152 }
153 
154 void LatticePhase::getEnthalpy_RT(doublereal* hrt) const
155 {
156  const vector_fp& _h = enthalpy_RT_ref();
157  doublereal delta_prt = (m_Pcurrent - m_Pref) / RT();
158  for (size_t k = 0; k < m_kk; k++) {
159  hrt[k] = _h[k] + delta_prt * m_speciesMolarVolume[k];
160  }
161 }
162 
163 void LatticePhase::getEntropy_R(doublereal* sr) const
164 {
165  const vector_fp& _s = entropy_R_ref();
166  std::copy(_s.begin(), _s.end(), sr);
167 }
168 
169 void LatticePhase::getGibbs_RT(doublereal* grt) const
170 {
171  const vector_fp& gibbsrt = gibbs_RT_ref();
172  doublereal delta_prt = (m_Pcurrent - m_Pref) / RT();
173  for (size_t k = 0; k < m_kk; k++) {
174  grt[k] = gibbsrt[k] + delta_prt * m_speciesMolarVolume[k];
175  }
176 }
177 
178 void LatticePhase::getGibbs_ref(doublereal* g) const
179 {
180  getGibbs_RT_ref(g);
181  for (size_t k = 0; k < m_kk; k++) {
182  g[k] *= RT();
183  }
184 }
185 
186 void LatticePhase::getCp_R(doublereal* cpr) const
187 {
188  const vector_fp& _cpr = cp_R_ref();
189  std::copy(_cpr.begin(), _cpr.end(), cpr);
190 }
191 
192 void LatticePhase::getStandardVolumes(doublereal* vbar) const
193 {
194  copy(m_speciesMolarVolume.begin(), m_speciesMolarVolume.end(), vbar);
195 }
196 
197 const vector_fp& LatticePhase::enthalpy_RT_ref() const
198 {
199  _updateThermo();
200  return m_h0_RT;
201 }
202 
204 {
205  _updateThermo();
206  return m_g0_RT;
207 }
208 
209 void LatticePhase::getGibbs_RT_ref(doublereal* grt) const
210 {
211  _updateThermo();
212  for (size_t k = 0; k < m_kk; k++) {
213  grt[k] = m_g0_RT[k];
214  }
215 }
216 
218 {
219  _updateThermo();
220  return m_s0_R;
221 }
222 
224 {
225  _updateThermo();
226  return m_cp0_R;
227 }
228 
229 bool LatticePhase::addSpecies(shared_ptr<Species> spec)
230 {
231  bool added = ThermoPhase::addSpecies(spec);
232  if (added) {
233  if (m_kk == 1) {
234  m_Pref = refPressure();
235  }
236  m_h0_RT.push_back(0.0);
237  m_g0_RT.push_back(0.0);
238  m_cp0_R.push_back(0.0);
239  m_s0_R.push_back(0.0);
240  if (spec->extra.hasKey("molar_volume")) {
241  m_speciesMolarVolume.push_back(spec->extra["molar_volume"].asDouble());
242  } else {
243  m_speciesMolarVolume.push_back(1.0 / m_site_density);
244  }
245  }
246  return added;
247 }
248 
249 void LatticePhase::setSiteDensity(double sitedens)
250 {
251  m_site_density = sitedens;
252 }
253 
255 {
256  doublereal tnow = temperature();
257  if (m_tlast != tnow) {
258  m_spthermo.update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
259  m_tlast = tnow;
260  for (size_t k = 0; k < m_kk; k++) {
261  m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
262  }
263  m_tlast = tnow;
264  }
265 }
266 
267 void LatticePhase::setParameters(int n, doublereal* const c)
268 {
269  warn_deprecated("LatticePhase::setParameters",
270  "To be removed after Cantera 2.4.");
271  m_site_density = c[0];
273 }
274 
275 void LatticePhase::getParameters(int& n, doublereal* const c) const
276 {
277  warn_deprecated("LatticePhase::getParameters",
278  "To be removed after Cantera 2.4.");
279  c[0] = molarDensity();
280  n = 1;
281 }
282 
284 {
285  eosdata._require("model", "Lattice");
286  setSiteDensity(getFloat(eosdata, "site_density", "toSI"));
287 }
288 
289 }
const vector_fp & entropy_R_ref() const
Returns a reference to the dimensionless reference state Entropy vector.
virtual doublereal pressure() const
In this equation of state implementation, the density is a function only of the mole fractions...
Definition: LatticePhase.h:336
virtual bool addSpecies(shared_ptr< Species > spec)
doublereal m_site_density
Site Density of the lattice solid.
Definition: LatticePhase.h:702
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1607
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the species standard states at the current T an...
doublereal m_Pref
Reference state pressure.
Definition: LatticePhase.h:666
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure of the solution.
doublereal temperature() const
Temperature (K).
Definition: Phase.h:601
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
doublereal calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input...
vector_fp m_g0_RT
Temporary storage for the reference state Gibbs energies.
Definition: LatticePhase.h:684
doublereal moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:471
vector_fp m_s0_R
Temporary storage for the reference state entropies at the current temperature.
Definition: LatticePhase.h:688
virtual void getPartialMolarCp(doublereal *cpbar) const
Returns an array of partial molar Heat Capacities at constant pressure of the species in the solution...
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
doublereal sum_xlogx() const
Evaluate .
Definition: Phase.cpp:624
vector_fp m_h0_RT
Reference state enthalpies / RT.
Definition: LatticePhase.h:678
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
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 setParameters(int n, doublereal *const c)
Set the equation of state parameters from the argument list.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of the species standard states at the current T and P of the solution...
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume of the solution.
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1643
const vector_fp & cp_R_ref() const
Returns a reference to the dimensionless reference state Heat Capacity vector.
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:614
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:748
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 species standard states at the cu...
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
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:576
virtual doublereal enthalpy_mole() const
Return the Molar Enthalpy. Units: J/kmol.
doublereal molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:590
void setSiteDensity(double sitedens)
Set the density of lattice sites [kmol/m^3].
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
Definition: Phase.cpp:834
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature, pressure, and solution concentration.
doublereal m_Pcurrent
The current pressure.
Definition: LatticePhase.h:675
void _updateThermo() const
Update the species reference state thermodynamic functions.
vector_fp m_cp0_R
Temporary storage for the reference state heat capacities.
Definition: LatticePhase.h:681
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species standard states at the current T and P of the ...
virtual void getActivityConcentrations(doublereal *c) const
The activity of a species in solution is related to the chemical potential by The quantity is the ...
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species standard states at their standard states at...
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:466
virtual void setMolarDensity(const doublereal molarDensity)
Set the internally stored molar density (kmol/m^3) of the phase.
Definition: Phase.cpp:595
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
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 getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
const doublereal SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:126
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:661
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:130
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:116
vector_fp m_speciesMolarVolume
Vector of molar volumes for each species in the solution.
Definition: LatticePhase.h:694
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
Contains declarations for string manipulation functions within Cantera.
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:164
virtual bool addSpecies(shared_ptr< Species > spec)
virtual doublereal entropy_mole() const
Molar entropy of the solution. Units: J/kmol/K.
size_t m_kk
Number of species in the phase.
Definition: Phase.h:788
const vector_fp & gibbs_RT_ref() const
Returns a reference to the dimensionless reference state Gibbs free energy vector.
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
Header for a simple thermodynamics model of a bulk phase derived from ThermoPhase, assuming a lattice of solid atoms (see Thermodynamic Properties and class LatticePhase).
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
LatticePhase()
Base Empty constructor.
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.