Cantera  2.5.1
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 https://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 
79 {
80  return Units(1.0);
81 }
82 
83 void LatticePhase::getActivityConcentrations(doublereal* c) const
84 {
86 }
87 
88 void LatticePhase::getActivityCoefficients(doublereal* ac) const
89 {
90  for (size_t k = 0; k < m_kk; k++) {
91  ac[k] = 1.0;
92  }
93 }
94 
95 doublereal LatticePhase::standardConcentration(size_t k) const
96 {
97  return 1.0;
98 }
99 
100 doublereal LatticePhase::logStandardConc(size_t k) const
101 {
102  return 0.0;
103 }
104 
105 void LatticePhase::getChemPotentials(doublereal* mu) const
106 {
107  doublereal delta_p = m_Pcurrent - m_Pref;
108  const vector_fp& g_RT = gibbs_RT_ref();
109  for (size_t k = 0; k < m_kk; k++) {
110  double xx = std::max(SmallNumber, moleFraction(k));
111  mu[k] = RT() * (g_RT[k] + log(xx))
112  + delta_p * m_speciesMolarVolume[k];
113  }
114 }
115 
116 void LatticePhase::getPartialMolarEnthalpies(doublereal* hbar) const
117 {
118  const vector_fp& _h = enthalpy_RT_ref();
119  scale(_h.begin(), _h.end(), hbar, RT());
120 }
121 
122 void LatticePhase::getPartialMolarEntropies(doublereal* sbar) const
123 {
124  const vector_fp& _s = entropy_R_ref();
125  for (size_t k = 0; k < m_kk; k++) {
126  double xx = std::max(SmallNumber, moleFraction(k));
127  sbar[k] = GasConstant * (_s[k] - log(xx));
128  }
129 }
130 
131 void LatticePhase::getPartialMolarCp(doublereal* cpbar) const
132 {
133  getCp_R(cpbar);
134  for (size_t k = 0; k < m_kk; k++) {
135  cpbar[k] *= GasConstant;
136  }
137 }
138 
139 void LatticePhase::getPartialMolarVolumes(doublereal* vbar) const
140 {
141  getStandardVolumes(vbar);
142 }
143 
144 void LatticePhase::getStandardChemPotentials(doublereal* mu0) const
145 {
146  const vector_fp& gibbsrt = gibbs_RT_ref();
147  scale(gibbsrt.begin(), gibbsrt.end(), mu0, RT());
148 }
149 
150 void LatticePhase::getPureGibbs(doublereal* gpure) const
151 {
152  const vector_fp& gibbsrt = gibbs_RT_ref();
153  doublereal delta_p = (m_Pcurrent - m_Pref);
154  for (size_t k = 0; k < m_kk; k++) {
155  gpure[k] = RT() * gibbsrt[k] + delta_p * m_speciesMolarVolume[k];
156  }
157 }
158 
159 void LatticePhase::getEnthalpy_RT(doublereal* hrt) const
160 {
161  const vector_fp& _h = enthalpy_RT_ref();
162  doublereal delta_prt = (m_Pcurrent - m_Pref) / RT();
163  for (size_t k = 0; k < m_kk; k++) {
164  hrt[k] = _h[k] + delta_prt * m_speciesMolarVolume[k];
165  }
166 }
167 
168 void LatticePhase::getEntropy_R(doublereal* sr) const
169 {
170  const vector_fp& _s = entropy_R_ref();
171  std::copy(_s.begin(), _s.end(), sr);
172 }
173 
174 void LatticePhase::getGibbs_RT(doublereal* grt) const
175 {
176  const vector_fp& gibbsrt = gibbs_RT_ref();
177  doublereal delta_prt = (m_Pcurrent - m_Pref) / RT();
178  for (size_t k = 0; k < m_kk; k++) {
179  grt[k] = gibbsrt[k] + delta_prt * m_speciesMolarVolume[k];
180  }
181 }
182 
183 void LatticePhase::getGibbs_ref(doublereal* g) const
184 {
185  getGibbs_RT_ref(g);
186  for (size_t k = 0; k < m_kk; k++) {
187  g[k] *= RT();
188  }
189 }
190 
191 void LatticePhase::getCp_R(doublereal* cpr) const
192 {
193  const vector_fp& _cpr = cp_R_ref();
194  std::copy(_cpr.begin(), _cpr.end(), cpr);
195 }
196 
197 void LatticePhase::getStandardVolumes(doublereal* vbar) const
198 {
199  copy(m_speciesMolarVolume.begin(), m_speciesMolarVolume.end(), vbar);
200 }
201 
202 const vector_fp& LatticePhase::enthalpy_RT_ref() const
203 {
204  _updateThermo();
205  return m_h0_RT;
206 }
207 
209 {
210  _updateThermo();
211  return m_g0_RT;
212 }
213 
214 void LatticePhase::getGibbs_RT_ref(doublereal* grt) const
215 {
216  _updateThermo();
217  for (size_t k = 0; k < m_kk; k++) {
218  grt[k] = m_g0_RT[k];
219  }
220 }
221 
223 {
224  _updateThermo();
225  return m_s0_R;
226 }
227 
229 {
230  _updateThermo();
231  return m_cp0_R;
232 }
233 
234 bool LatticePhase::addSpecies(shared_ptr<Species> spec)
235 {
236  bool added = ThermoPhase::addSpecies(spec);
237  if (added) {
238  if (m_kk == 1) {
239  m_Pref = refPressure();
240  }
241  m_h0_RT.push_back(0.0);
242  m_g0_RT.push_back(0.0);
243  m_cp0_R.push_back(0.0);
244  m_s0_R.push_back(0.0);
245  double mv = 1.0 / m_site_density;
246  if (spec->input.hasKey("equation-of-state")) {
247  auto& eos = spec->input["equation-of-state"].getMapWhere(
248  "model", "constant-volume");
249  if (eos.hasKey("density")) {
250  mv = molecularWeight(m_kk-1) / eos.convert("density", "kg/m^3");
251  } else if (eos.hasKey("molar-density")) {
252  mv = 1.0 / eos.convert("molar-density", "kmol/m^3");
253  } else if (eos.hasKey("molar-volume")) {
254  mv = eos.convert("molar-volume", "m^3/kmol");
255  }
256  } else if (spec->extra.hasKey("molar_volume")) {
257  // from XML
258  mv = spec->extra["molar_volume"].asDouble();
259  }
260  m_speciesMolarVolume.push_back(mv);
261  }
262  return added;
263 }
264 
265 void LatticePhase::setSiteDensity(double sitedens)
266 {
267  m_site_density = sitedens;
268  for (size_t k = 0; k < m_kk; k++) {
269  if (species(k)->extra.hasKey("molar_volume")) {
270  continue;
271  } else if (species(k)->input.hasKey("equation-of-state")) {
272  auto& eos = species(k)->input["equation-of-state"].getMapWhere(
273  "model", "constant-volume");
274  if (eos.hasKey("molar-volume") || eos.hasKey("density")
275  || eos.hasKey("molar-density")) {
276  continue;
277  }
278  }
280  }
281 }
282 
284 {
285  doublereal tnow = temperature();
286  if (m_tlast != tnow) {
287  m_spthermo.update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
288  m_tlast = tnow;
289  for (size_t k = 0; k < m_kk; k++) {
290  m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
291  }
292  m_tlast = tnow;
293  }
294 }
295 
297 {
298  if (m_input.hasKey("site-density")) {
299  setSiteDensity(m_input.convert("site-density", "kmol/m^3"));
300  }
301 }
302 
304 {
305  eosdata._require("model", "Lattice");
306  setSiteDensity(getFloat(eosdata, "site_density", "toSI"));
307 }
308 
309 }
Cantera::LatticePhase::getPartialMolarCp
virtual void getPartialMolarCp(doublereal *cpbar) const
Returns an array of partial molar Heat Capacities at constant pressure of the species in the solution...
Definition: LatticePhase.cpp:131
Cantera::LatticePhase::m_h0_RT
vector_fp m_h0_RT
Reference state enthalpies / RT.
Definition: LatticePhase.h:669
Cantera::LatticePhase::compositionChanged
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
Definition: LatticePhase.cpp:72
Cantera::LatticePhase::cp_mole
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure of the solution.
Definition: LatticePhase.cpp:50
Cantera::LatticePhase::pressure
virtual doublereal pressure() const
In this equation of state implementation, the density is a function only of the mole fractions.
Definition: LatticePhase.h:347
Cantera::LatticePhase::getPureGibbs
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.
Definition: LatticePhase.cpp:150
Cantera::Phase::getMoleFractions
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:572
Cantera::SmallNumber
const double SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:149
Cantera::LatticePhase::m_site_density
doublereal m_site_density
Site Density of the lattice solid.
Definition: LatticePhase.h:693
Cantera::AnyMap::convert
double convert(const std::string &key, const std::string &units) const
Convert the item stored by the given key to the units specified in units.
Definition: AnyMap.cpp:1055
Cantera::ThermoPhase::refPressure
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:145
Cantera::LatticePhase::getEntropy_R
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the species standard states at the current T an...
Definition: LatticePhase.cpp:168
Cantera::LatticePhase::cp_R_ref
const vector_fp & cp_R_ref() const
Returns a reference to the dimensionless reference state Heat Capacity vector.
Definition: LatticePhase.cpp:228
Cantera::LatticePhase::getGibbs_ref
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...
Definition: LatticePhase.cpp:183
Cantera::Phase::meanMolecularWeight
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:748
Cantera::LatticePhase::setPressure
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition: LatticePhase.cpp:66
Cantera::AnyMap::hasKey
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:984
Cantera::LatticePhase::logStandardConc
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
Definition: LatticePhase.cpp:100
Cantera::Phase::assignDensity
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition: Phase.cpp:727
Cantera::MultiSpeciesThermo::update
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
Definition: MultiSpeciesThermo.cpp:90
Cantera::LatticePhase::standardConcentration
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
Definition: LatticePhase.cpp:95
Cantera::LatticePhase::calcDensity
doublereal calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
Definition: LatticePhase.cpp:60
Cantera::LatticePhase::m_g0_RT
vector_fp m_g0_RT
Temporary storage for the reference state Gibbs energies.
Definition: LatticePhase.h:675
Cantera::LatticePhase::getCp_R
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition: LatticePhase.cpp:191
Cantera::LatticePhase::getStandardVolumes
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of the species standard states at the current T and P of the solution.
Definition: LatticePhase.cpp:197
ThermoFactory.h
Cantera::LatticePhase::m_s0_R
vector_fp m_s0_R
Temporary storage for the reference state entropies at the current temperature.
Definition: LatticePhase.h:679
Cantera::vector_fp
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:180
Cantera::LatticePhase::cv_mole
virtual doublereal cv_mole() const
Molar heat capacity at constant volume of the solution.
Definition: LatticePhase.cpp:55
Cantera::Phase::moleFraction
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:577
Cantera::LatticePhase::getPartialMolarVolumes
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
Definition: LatticePhase.cpp:139
LatticePhase.h
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition: Phase.h:942
Cantera::ThermoPhase::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: ThermoPhase.cpp:1134
Cantera::ThermoPhase::m_input
AnyMap m_input
Data supplied via setParameters.
Definition: ThermoPhase.h:1874
Cantera::LatticePhase::setSiteDensity
void setSiteDensity(double sitedens)
Set the density of lattice sites [kmol/m^3].
Definition: LatticePhase.cpp:265
Cantera::Phase::molecularWeight
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:521
Cantera::LatticePhase::getGibbs_RT
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 ...
Definition: LatticePhase.cpp:174
Cantera::LatticePhase::setParametersFromXML
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: LatticePhase.cpp:303
Cantera::LatticePhase::getEnthalpy_RT
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species standard states at their standard states at...
Definition: LatticePhase.cpp:159
Cantera::LatticePhase::enthalpy_mole
virtual doublereal enthalpy_mole() const
Return the Molar Enthalpy. Units: J/kmol.
Definition: LatticePhase.cpp:39
Cantera::ThermoPhase::input
const AnyMap & input() const
Access input data associated with the phase description.
Definition: ThermoPhase.cpp:1186
Cantera::LatticePhase::getPartialMolarEntropies
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: LatticePhase.cpp:122
Cantera::LatticePhase::standardConcentrationUnits
virtual Units standardConcentrationUnits() const
The activity of a species in solution is related to the chemical potential by.
Definition: LatticePhase.cpp:78
Cantera::LatticePhase::getChemPotentials
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: LatticePhase.cpp:105
Cantera::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Cantera::ThermoPhase::m_tlast
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1904
Cantera::OneAtm
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:78
Cantera::LatticePhase::m_Pcurrent
doublereal m_Pcurrent
The current pressure.
Definition: LatticePhase.h:666
Cantera::ThermoPhase::RT
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:776
utilities.h
Cantera::LatticePhase::m_cp0_R
vector_fp m_cp0_R
Temporary storage for the reference state heat capacities.
Definition: LatticePhase.h:672
Cantera::LatticePhase::getGibbs_RT_ref
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
Definition: LatticePhase.cpp:214
Cantera::ThermoPhase::initThermoFile
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
Definition: ThermoPhase.cpp:1064
Cantera::Phase::sum_xlogx
doublereal sum_xlogx() const
Evaluate .
Definition: Phase.cpp:756
Cantera::LatticePhase::getActivityConcentrations
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: LatticePhase.cpp:83
ctml.h
stringUtils.h
Cantera::LatticePhase::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: LatticePhase.cpp:296
Cantera::Phase::temperature
doublereal temperature() const
Temperature (K).
Definition: Phase.h:667
Cantera::LatticePhase::getActivityCoefficients
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature,...
Definition: LatticePhase.cpp:88
Cantera::LatticePhase::entropy_mole
virtual doublereal entropy_mole() const
Molar entropy of the solution. Units: J/kmol/K.
Definition: LatticePhase.cpp:45
Cantera::LatticePhase::_updateThermo
void _updateThermo() const
Update the species reference state thermodynamic functions.
Definition: LatticePhase.cpp:283
Cantera::scale
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:135
Cantera::LatticePhase::gibbs_RT_ref
const vector_fp & gibbs_RT_ref() const
Returns a reference to the dimensionless reference state Gibbs free energy vector.
Definition: LatticePhase.cpp:208
Cantera::ThermoPhase::m_spthermo
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1870
Cantera::LatticePhase::m_speciesMolarVolume
vector_fp m_speciesMolarVolume
Vector of molar volumes for each species in the solution.
Definition: LatticePhase.h:685
Cantera::getFloat
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
Cantera::Phase::mean_X
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:746
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition: Units.h:29
Cantera::Phase::molarDensity
double molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:700
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:109
Cantera::LatticePhase::entropy_R_ref
const vector_fp & entropy_R_ref() const
Returns a reference to the dimensionless reference state Entropy vector.
Definition: LatticePhase.cpp:222
Cantera::importPhase
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Definition: ThermoFactory.cpp:237
Cantera::XML_Node::_require
void _require(const std::string &a, const std::string &v) const
Require that the current XML node has an attribute named by the first argument, a,...
Definition: xml.cpp:576
Cantera::LatticePhase::getStandardChemPotentials
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: LatticePhase.cpp:144
Cantera::LatticePhase::LatticePhase
LatticePhase()
Base Empty constructor.
Definition: LatticePhase.cpp:21
Cantera::LatticePhase::getPartialMolarEnthalpies
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: LatticePhase.cpp:116
Cantera::LatticePhase::m_Pref
doublereal m_Pref
Reference state pressure.
Definition: LatticePhase.h:657
Cantera::Phase::species
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
Definition: Phase.cpp:980
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:263
Cantera::Phase::compositionChanged
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
Definition: Phase.cpp:1028
Cantera::LatticePhase::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: LatticePhase.cpp:234