Cantera  3.2.0a4
Loading...
Searching...
No Matches
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
17
18namespace Cantera
19{
20
21LatticePhase::LatticePhase(const string& inputFile, const string& id_)
22{
23 warn_deprecated("class LatticePhase", "To be removed after Cantera 3.2. Can be "
24 "replaced by use of IdealSolidSolnPhase with the site density used to set the "
25 "molar density of each constituent species.");
26 initThermoFile(inputFile, id_);
27}
28
30{
31 return RT() * mean_X(enthalpy_RT_ref()) +
33}
34
36{
37 return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx());
38}
39
41 return enthalpy_mole() - temperature() * entropy_mole();
42}
43
45{
46 return GasConstant * mean_X(cp_R_ref());
47}
48
50{
51 return cp_mole();
52}
53
55{
58}
59
61{
62 m_Pcurrent = p;
64}
65
67{
70}
71
73{
74 return Units(1.0);
75}
76
78{
80}
81
83{
84 for (size_t k = 0; k < m_kk; k++) {
85 ac[k] = 1.0;
86 }
87}
88
90{
91 return 1.0;
92}
93
94double LatticePhase::logStandardConc(size_t k) const
95{
96 return 0.0;
97}
98
99void LatticePhase::getChemPotentials(double* mu) const
100{
101 double delta_p = m_Pcurrent - m_Pref;
102 const vector<double>& g_RT = gibbs_RT_ref();
103 for (size_t k = 0; k < m_kk; k++) {
104 double xx = std::max(SmallNumber, moleFraction(k));
105 mu[k] = RT() * (g_RT[k] + log(xx))
106 + delta_p * m_speciesMolarVolume[k];
107 }
108}
109
111{
112 const vector<double>& _h = enthalpy_RT_ref();
113 scale(_h.begin(), _h.end(), hbar, RT());
114}
115
117{
118 const vector<double>& _s = entropy_R_ref();
119 for (size_t k = 0; k < m_kk; k++) {
120 double xx = std::max(SmallNumber, moleFraction(k));
121 sbar[k] = GasConstant * (_s[k] - log(xx));
122 }
123}
124
125void LatticePhase::getPartialMolarCp(double* cpbar) const
126{
127 getCp_R(cpbar);
128 for (size_t k = 0; k < m_kk; k++) {
129 cpbar[k] *= GasConstant;
130 }
131}
132
134{
135 getStandardVolumes(vbar);
136}
137
139{
140 const vector<double>& gibbsrt = gibbs_RT_ref();
141 scale(gibbsrt.begin(), gibbsrt.end(), mu0, RT());
142}
143
144void LatticePhase::getPureGibbs(double* gpure) const
145{
146 const vector<double>& gibbsrt = gibbs_RT_ref();
147 double delta_p = (m_Pcurrent - m_Pref);
148 for (size_t k = 0; k < m_kk; k++) {
149 gpure[k] = RT() * gibbsrt[k] + delta_p * m_speciesMolarVolume[k];
150 }
151}
152
153void LatticePhase::getEnthalpy_RT(double* hrt) const
154{
155 const vector<double>& _h = enthalpy_RT_ref();
156 double delta_prt = (m_Pcurrent - m_Pref) / RT();
157 for (size_t k = 0; k < m_kk; k++) {
158 hrt[k] = _h[k] + delta_prt * m_speciesMolarVolume[k];
159 }
160}
161
162void LatticePhase::getEntropy_R(double* sr) const
163{
164 const vector<double>& _s = entropy_R_ref();
165 std::copy(_s.begin(), _s.end(), sr);
166}
167
168void LatticePhase::getGibbs_RT(double* grt) const
169{
170 const vector<double>& gibbsrt = gibbs_RT_ref();
171 double delta_prt = (m_Pcurrent - m_Pref) / RT();
172 for (size_t k = 0; k < m_kk; k++) {
173 grt[k] = gibbsrt[k] + delta_prt * m_speciesMolarVolume[k];
174 }
175}
176
177void LatticePhase::getGibbs_ref(double* g) const
178{
180 for (size_t k = 0; k < m_kk; k++) {
181 g[k] *= RT();
182 }
183}
184
185void LatticePhase::getCp_R(double* cpr) const
186{
187 const vector<double>& _cpr = cp_R_ref();
188 std::copy(_cpr.begin(), _cpr.end(), cpr);
189}
190
191void LatticePhase::getStandardVolumes(double* vbar) const
192{
193 copy(m_speciesMolarVolume.begin(), m_speciesMolarVolume.end(), vbar);
194}
195
196const vector<double>& LatticePhase::enthalpy_RT_ref() const
197{
199 return m_h0_RT;
200}
201
202const vector<double>& LatticePhase::gibbs_RT_ref() const
203{
205 return m_g0_RT;
206}
207
208void LatticePhase::getGibbs_RT_ref(double* grt) const
209{
211 for (size_t k = 0; k < m_kk; k++) {
212 grt[k] = m_g0_RT[k];
213 }
214}
215
216const vector<double>& LatticePhase::entropy_R_ref() const
217{
219 return m_s0_R;
220}
221
222const vector<double>& LatticePhase::cp_R_ref() const
223{
225 return m_cp0_R;
226}
227
228bool LatticePhase::addSpecies(shared_ptr<Species> spec)
229{
230 bool added = ThermoPhase::addSpecies(spec);
231 if (added) {
232 if (m_kk == 1) {
234 }
235 m_h0_RT.push_back(0.0);
236 m_g0_RT.push_back(0.0);
237 m_cp0_R.push_back(0.0);
238 m_s0_R.push_back(0.0);
239 double mv = 1.0 / m_site_density;
240 if (spec->input.hasKey("equation-of-state")) {
241 auto& eos = spec->input["equation-of-state"].getMapWhere(
242 "model", "constant-volume");
243 if (eos.hasKey("density")) {
244 mv = molecularWeight(m_kk-1) / eos.convert("density", "kg/m^3");
245 } else if (eos.hasKey("molar-density")) {
246 mv = 1.0 / eos.convert("molar-density", "kmol/m^3");
247 } else if (eos.hasKey("molar-volume")) {
248 mv = eos.convert("molar-volume", "m^3/kmol");
249 }
250 }
251 m_speciesMolarVolume.push_back(mv);
252 }
253 return added;
254}
255
256void LatticePhase::setSiteDensity(double sitedens)
257{
258 m_site_density = sitedens;
259 for (size_t k = 0; k < m_kk; k++) {
260 if (species(k)->input.hasKey("equation-of-state")) {
261 auto& eos = species(k)->input["equation-of-state"].getMapWhere(
262 "model", "constant-volume");
263 if (eos.hasKey("molar-volume") || eos.hasKey("density")
264 || eos.hasKey("molar-density")) {
265 continue;
266 }
267 }
269 }
270}
271
273{
274 double tnow = temperature();
275 if (m_tlast != tnow) {
276 m_spthermo.update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
277 m_tlast = tnow;
278 for (size_t k = 0; k < m_kk; k++) {
279 m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
280 }
281 m_tlast = tnow;
282 }
283}
284
286{
287 if (m_input.hasKey("site-density")) {
288 setSiteDensity(m_input.convert("site-density", "kmol/m^3"));
289 }
290}
291
293{
295 phaseNode["site-density"].setQuantity(m_site_density, "kmol/m^3");
296}
297
298void LatticePhase::getSpeciesParameters(const string& name, AnyMap& speciesNode) const
299{
301 size_t k = speciesIndex(name);
302 // Output volume information in a form consistent with the input
303 const auto S = species(k);
304 if (S->input.hasKey("equation-of-state")) {
305 auto& eosIn = S->input["equation-of-state"].getMapWhere(
306 "model", "constant-volume");
307 auto& eosOut = speciesNode["equation-of-state"].getMapWhere(
308 "model", "constant-volume", true);
309
310 if (eosIn.hasKey("density")) {
311 eosOut["model"] = "constant-volume";
312 eosOut["density"].setQuantity(
313 molecularWeight(k) / m_speciesMolarVolume[k], "kg/m^3");
314 } else if (eosIn.hasKey("molar-density")) {
315 eosOut["model"] = "constant-volume";
316 eosOut["molar-density"].setQuantity(1.0 / m_speciesMolarVolume[k],
317 "kmol/m^3");
318 } else if (eosIn.hasKey("molar-volume")) {
319 eosOut["model"] = "constant-volume";
320 eosOut["molar-volume"].setQuantity(m_speciesMolarVolume[k],
321 "m^3/kmol");
322 }
323 }
324 // Otherwise, species volume is determined by the phase-level site density
325}
326
327}
Header for a simple thermodynamics model of a bulk phase derived from ThermoPhase,...
Declaration for class Cantera::Species.
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:431
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1477
double convert(const string &key, const string &units) const
Convert the item stored by the given key to the units specified in units.
Definition AnyMap.cpp:1595
const vector< double > & entropy_R_ref() const
Returns a reference to the dimensionless reference state Entropy vector.
double enthalpy_mole() const override
Return the Molar Enthalpy. Units: J/kmol.
double logStandardConc(size_t k=0) const override
Natural logarithm of the standard concentration of the kth species.
void getPartialMolarEnthalpies(double *hbar) const override
Returns an array of partial molar enthalpies for the species in the mixture.
void getChemPotentials(double *mu) const override
Get the species chemical potentials. Units: J/kmol.
double m_site_density
Site Density of the lattice solid.
double pressure() const override
Pressure. Units: Pa.
vector< double > m_g0_RT
Temporary storage for the reference state Gibbs energies.
void getSpeciesParameters(const string &name, AnyMap &speciesNode) const override
Get phase-specific parameters of a Species object such that an identical one could be reconstructed a...
void getEntropy_R(double *sr) const override
Get the array of nondimensional Entropy functions for the species standard states at the current T an...
vector< double > m_h0_RT
Reference state enthalpies / RT.
void getGibbs_ref(double *g) const override
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
double m_Pref
Reference state pressure.
void getStandardChemPotentials(double *mu) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void getCp_R(double *cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
void getParameters(AnyMap &phaseNode) const override
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
void getActivityConcentrations(double *c) const override
This method returns an array of generalized concentrations.
void setPressure(double p) override
Set the internally stored pressure (Pa) at constant temperature and composition.
const vector< double > & gibbs_RT_ref() const
Returns a reference to the dimensionless reference state Gibbs free energy vector.
void getPartialMolarVolumes(double *vbar) const override
Return an array of partial molar volumes for the species in the mixture.
double cv_mole() const override
Molar heat capacity at constant volume of the solution.
void getPureGibbs(double *gpure) const override
Get the Gibbs functions for the standard state of the species at the current T and P of the solution.
void getEnthalpy_RT(double *hrt) const override
Get the nondimensional Enthalpy functions for the species standard states at their standard states at...
vector< double > m_s0_R
Temporary storage for the reference state entropies at the current temperature.
void getGibbs_RT(double *grt) const override
Get the nondimensional Gibbs functions for the species standard states at the current T and P of the ...
double entropy_mole() const override
Molar entropy of the solution. Units: J/kmol/K.
void setSiteDensity(double sitedens)
Set the density of lattice sites [kmol/m^3].
vector< double > m_speciesMolarVolume
Vector of molar volumes for each species in the solution.
void getStandardVolumes(double *vol) const override
Get the molar volumes of the species standard states at the current T and P of the solution.
double cp_mole() const override
Molar heat capacity at constant pressure of the solution.
Units standardConcentrationUnits() const override
Returns the units of the "standard concentration" for this phase.
void getPartialMolarCp(double *cpbar) const override
Returns an array of partial molar Heat Capacities at constant pressure of the species in the solution...
void compositionChanged() override
Apply changes to the state which are needed after the composition changes.
double gibbs_mole() const override
Molar Gibbs function of the solution. Units: J/kmol.
double standardConcentration(size_t k=0) const override
Return the standard concentration for the kth species.
vector< double > m_cp0_R
Temporary storage for the reference state heat capacities.
double calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
void _updateThermo() const
Update the species reference state thermodynamic functions.
void getGibbs_RT_ref(double *grt) const override
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
void getActivityCoefficients(double *ac) const override
Get the array of non-dimensional activity coefficients at the current solution temperature,...
LatticePhase(const string &inputFile="", const string &id="")
Full constructor for a lattice phase.
void getPartialMolarEntropies(double *sbar) const override
Returns an array of partial molar entropies of the species in the solution.
const vector< double > & cp_R_ref() const
Returns a reference to the dimensionless reference state Heat Capacity vector.
double m_Pcurrent
The current pressure.
virtual void update(double T, double *cp_R, double *h_RT, double *s_R) const
Compute the reference-state properties for all species.
virtual double molarDensity() const
Molar density (kmol/m^3).
Definition Phase.cpp:604
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition Phase.cpp:625
size_t m_kk
Number of species in the phase.
Definition Phase.h:879
double temperature() const
Temperature (K).
Definition Phase.h:587
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:680
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition Phase.cpp:462
double sum_xlogx() const
Evaluate .
Definition Phase.cpp:654
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:129
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition Phase.cpp:467
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
Definition Phase.cpp:951
double mean_X(const double *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition Phase.cpp:644
double molecularWeight(size_t k) const
Molecular weight of species k.
Definition Phase.cpp:411
shared_ptr< Species > species(const string &name) const
Return the Species object for the named species.
Definition Phase.cpp:902
string name() const
Return the name of the phase.
Definition Phase.cpp:20
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
double RT() const
Return the Gas Constant multiplied by the current temperature.
double m_tlast
last value of the temperature processed by reference state
void initThermoFile(const string &inputFile, const string &id)
Initialize a ThermoPhase object using an input file.
virtual void getSpeciesParameters(const string &name, AnyMap &speciesNode) const
Get phase-specific parameters of a Species object such that an identical one could be reconstructed a...
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
virtual double refPressure() const
Returns the reference pressure in Pa.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
AnyMap m_input
Data supplied via setParameters.
const AnyMap & input() const
Access input data associated with the phase description.
A representation of the units associated with a dimensional quantity.
Definition Units.h:35
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition utilities.h:104
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const double SmallNumber
smallest number to compare to zero.
Definition ct_defs.h:158
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1997
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...