Cantera  2.4.0
LatticeSolidPhase.h
Go to the documentation of this file.
1 /**
2  * @file LatticeSolidPhase.h Header for a simple thermodynamics model of a bulk
3  * solid phase derived from ThermoPhase, assuming an ideal solution model
4  * based on a lattice of solid atoms (see \ref thermoprops and class \link
5  * Cantera::LatticeSolidPhase LatticeSolidPhase\endlink).
6  */
7 
8 // This file is part of Cantera. See License.txt in the top-level directory or
9 // at http://www.cantera.org/license.txt for license and copyright information.
10 
11 #ifndef CT_LATTICESOLID_H
12 #define CT_LATTICESOLID_H
13 
14 #include "ThermoPhase.h"
15 
16 namespace Cantera
17 {
18 
19 //! A phase that is comprised of a fixed additive combination of other lattice
20 //! phases
21 /*!
22  * This is the main way %Cantera describes semiconductors and other solid
23  * phases. This ThermoPhase object calculates its properties as a sum over other
24  * LatticePhase objects. Each of the LatticePhase objects is a ThermoPhase
25  * object by itself.
26  *
27  * The results from this LatticeSolidPhase model reduces to the LatticePhase
28  * model when there is one lattice phase and the molar densities of the
29  * sublattice and the molar density within the LatticeSolidPhase have the same
30  * values.
31  *
32  * The mole fraction vector is redefined witin the the LatticeSolidPhase object.
33  * Each of the mole fractions sum to one on each of the sublattices. The
34  * routine getMoleFraction() and setMoleFraction() have been redefined to use
35  * this convention.
36  *
37  * ## Specification of Species Standard State Properties
38  *
39  * The standard state properties are calculated in the normal way for each of
40  * the sublattices. The normal way here means that a thermodynamic polynomial in
41  * temperature is developed. Also, a constant volume approximation for the
42  * pressure dependence is assumed. All of these properties are on a Joules per
43  * kmol of sublattice constituent basis.
44  *
45  * ## Specification of Solution Thermodynamic Properties
46  *
47  * The sum over the LatticePhase objects is carried out by weighting each
48  * LatticePhase object value with the molar density (kmol m-3) of its
49  * LatticePhase. Then the resulting quantity is divided by the molar density of
50  * the total compound. The LatticeSolidPhase object therefore only contains a
51  * listing of the number of LatticePhase object that comprises the solid, and it
52  * contains a value for the molar density of the entire mixture. This is the
53  * same thing as saying that
54  *
55  * \f[
56  * L_i = L^{solid} \theta_i
57  * \f]
58  *
59  * \f$ L_i \f$ is the molar volume of the ith lattice. \f$ L^{solid} \f$ is the
60  * molar volume of the entire solid. \f$ \theta_i \f$ is a fixed weighting
61  * factor for the ith lattice representing the lattice stoichiometric
62  * coefficient. For this object the \f$ \theta_i \f$ values are fixed.
63  *
64  * Let's take FeS2 as an example, which may be thought of as a combination of
65  * two lattices: Fe and S lattice. The Fe sublattice has a molar density of 1
66  * gmol cm-3. The S sublattice has a molar density of 2 gmol cm-3. We then
67  * define the LatticeSolidPhase object as having a nominal composition of FeS2,
68  * and having a molar density of 1 gmol cm-3. All quantities pertaining to the
69  * FeS2 compound will be have weights associated with the sublattices. The Fe
70  * sublattice will have a weight of 1.0 associated with it. The S sublattice
71  * will have a weight of 2.0 associated with it.
72  *
73  * ### Specification of Solution Density Properties
74  *
75  * Currently, molar density is not a constant within the object, even though the
76  * species molar volumes are a constant. The basic idea is that a swelling of
77  * one of the sublattices will result in a swelling of of all of the lattices.
78  * Therefore, the molar volumes of the individual lattices are not independent
79  * of one another.
80  *
81  * The molar volume of the Lattice solid is calculated from the following
82  * formula
83  *
84  * \f[
85  * V = \sum_i{ \theta_i V_i^{lattice}}
86  * \f]
87  *
88  * where \f$ V_i^{lattice} \f$ is the molar volume of the ith sublattice. This
89  * is calculated from the following standard formula.
90  *
91  * \f[
92  * V_i = \sum_k{ X_k V_k}
93  * \f]
94  *
95  * where k is a species in the ith sublattice.
96  *
97  * The mole fraction vector is redefined witin the the LatticeSolidPhase object.
98  * Each of the mole fractions sum to one on each of the sublattices. The
99  * routine getMoleFraction() and setMoleFraction() have been redefined to use
100  * this convention.
101  *
102  * (This object is still under construction)
103  */
105 {
106 public:
107  //! Base empty constructor
109 
110  virtual std::string type() const {
111  return "LatticeSolid";
112  }
113 
114  virtual doublereal minTemp(size_t k = npos) const;
115  virtual doublereal maxTemp(size_t k = npos) const;
116  virtual doublereal refPressure() const;
117 
118  //! This method returns the convention used in specification of the standard
119  //! state, of which there are currently two, temperature based, and variable
120  //! pressure based.
121  /*!
122  * All of the thermo is determined by slave ThermoPhase routines.
123  */
124  virtual int standardStateConvention() const {
125  return cSS_CONVENTION_SLAVE;
126  }
127 
128  //! Return the Molar Enthalpy. Units: J/kmol.
129  /*!
130  * The molar enthalpy is determined by the following formula, where \f$
131  * \theta_n \f$ is the lattice stoichiometric coefficient of the nth lattice
132  *
133  * \f[
134  * \tilde h(T,P) = {\sum_n \theta_n \tilde h_n(T,P) }
135  * \f]
136  *
137  * \f$ \tilde h_n(T,P) \f$ is the enthalpy of the nth lattice.
138  *
139  * units J/kmol
140  */
141  virtual doublereal enthalpy_mole() const;
142 
143  //! Return the Molar Internal Energy. Units: J/kmol.
144  /*!
145  * The molar enthalpy is determined by the following formula, where \f$
146  * \theta_n \f$ is the lattice stoichiometric coefficient of the nth lattice
147  *
148  * \f[
149  * \tilde u(T,P) = {\sum_n \theta_n \tilde u_n(T,P) }
150  * \f]
151  *
152  * \f$ \tilde u_n(T,P) \f$ is the internal energy of the nth lattice.
153  *
154  * units J/kmol
155  */
156  virtual doublereal intEnergy_mole() const;
157 
158  //! Return the Molar Entropy. Units: J/kmol/K.
159  /*!
160  * The molar enthalpy is determined by the following formula, where \f$
161  * \theta_n \f$ is the lattice stoichiometric coefficient of the nth lattice
162  *
163  * \f[
164  * \tilde s(T,P) = \sum_n \theta_n \tilde s_n(T,P)
165  * \f]
166  *
167  * \f$ \tilde s_n(T,P) \f$ is the molar entropy of the nth lattice.
168  *
169  * units J/kmol/K
170  */
171  virtual doublereal entropy_mole() const;
172 
173  //! Return the Molar Gibbs energy. Units: J/kmol.
174  /*!
175  * The molar Gibbs free energy is determined by the following formula, where
176  * \f$ \theta_n \f$ is the lattice stoichiometric coefficient of the nth
177  * lattice
178  *
179  * \f[
180  * \tilde h(T,P) = {\sum_n \theta_n \tilde h_n(T,P) }
181  * \f]
182  *
183  * \f$ \tilde h_n(T,P) \f$ is the enthalpy of the nth lattice.
184  *
185  * units J/kmol
186  */
187  virtual doublereal gibbs_mole() const;
188 
189  //! Return the constant pressure heat capacity. Units: J/kmol/K
190  /*!
191  * The molar constant pressure heat capacity is determined by the following
192  * formula, where \f$ C_n \f$ is the lattice molar density of the nth
193  * lattice, and \f$ C_T \f$ is the molar density of the solid compound.
194  *
195  * \f[
196  * \tilde c_{p,n}(T,P) = \frac{\sum_n C_n \tilde c_{p,n}(T,P) }{C_T},
197  * \f]
198  *
199  * \f$ \tilde c_{p,n}(T,P) \f$ is the heat capacity of the nth lattice.
200  *
201  * units J/kmol/K
202  */
203  virtual doublereal cp_mole() const;
204 
205  //! Return the constant volume heat capacity. Units: J/kmol/K
206  /*!
207  * The molar constant volume heat capacity is determined by the following
208  * formula, where \f$ C_n \f$ is the lattice molar density of the nth
209  * lattice, and \f$ C_T \f$ is the molar density of the solid compound.
210  *
211  * \f[
212  * \tilde c_{v,n}(T,P) = \frac{\sum_n C_n \tilde c_{v,n}(T,P) }{C_T},
213  * \f]
214  *
215  * \f$ \tilde c_{v,n}(T,P) \f$ is the heat capacity of the nth lattice.
216  *
217  * units J/kmol/K
218  */
219  virtual doublereal cv_mole() const {
220  return cp_mole();
221  }
222 
223  //! Report the Pressure. Units: Pa.
224  /*!
225  * This method simply returns the stored pressure value.
226  */
227  virtual doublereal pressure() const {
228  return m_press;
229  }
230 
231  //! Set the pressure at constant temperature. Units: Pa.
232  /*!
233  * @param p Pressure (units - Pa)
234  */
235  virtual void setPressure(doublereal p);
236 
237  //! Calculate the density of the solid mixture
238  /*!
239  * The formula for this is
240  *
241  * \f[
242  * \rho = \sum_n{ \rho_n \theta_n }
243  * \f]
244  *
245  * where \f$ \rho_n \f$ is the density of the nth sublattice
246  */
247  doublereal calcDensity();
248 
249  //! Set the mole fractions to the specified values, and then normalize them
250  //! so that they sum to 1.0 for each of the subphases
251  /*!
252  * On input, the mole fraction vector is assumed to sum to one for each of
253  * the sublattices. The sublattices are updated with this mole fraction
254  * vector. The mole fractions are also stored within this object, after they
255  * are normalized to one by dividing by the number of sublattices.
256  *
257  * @param x Input vector of mole fractions. There is no restriction on the
258  * sum of the mole fraction vector. Internally, this object will
259  * pass portions of this vector to the sublattices which assume
260  * that the portions individually sum to one. Length is m_kk.
261  */
262  virtual void setMoleFractions(const doublereal* const x);
263 
264  //! Get the species mole fraction vector.
265  /*!
266  * On output the mole fraction vector will sum to one for each of the
267  * subphases which make up this phase.
268  *
269  * @param x On return, x contains the mole fractions. Must have a length
270  * greater than or equal to the number of species.
271  */
272  virtual void getMoleFractions(doublereal* const x) const;
273 
274  virtual doublereal moleFraction(const int k) const {
275  throw NotImplementedError("LatticeSolidPhase::moleFraction");
276  }
277 
278  virtual void getMassFractions(doublereal* const y) const {
279  throw NotImplementedError("LatticeSolidPhase::getMassFractions");
280  }
281 
282  virtual doublereal massFraction(const int k) const {
283  throw NotImplementedError("LatticeSolidPhase::massFraction");
284  }
285 
286  virtual void setMassFractions(const doublereal* const y) {
287  throw NotImplementedError("LatticeSolidPhase::setMassFractions");
288  }
289 
290  virtual void setMassFractions_NoNorm(const doublereal* const y) {
291  throw NotImplementedError("LatticeSolidPhase::setMassFractions_NoNorm");
292  }
293 
294  virtual void getConcentrations(doublereal* const c) const {
295  throw NotImplementedError("LatticeSolidPhase::getConcentrations");
296  }
297 
298  virtual doublereal concentration(int k) const {
299  throw NotImplementedError("LatticeSolidPhase::concentration");
300  }
301 
302  virtual void setConcentrations(const doublereal* const conc) {
303  throw NotImplementedError("LatticeSolidPhase::setConcentrations");
304  }
305 
306  virtual void getActivityConcentrations(doublereal* c) const;
307 
308  virtual void getActivityCoefficients(doublereal* ac) const;
309 
310  //! Get the species chemical potentials. Units: J/kmol.
311  /*!
312  * This function returns a vector of chemical potentials of the species in
313  * solution at the current temperature, pressure and mole fraction of the
314  * solution.
315  *
316  * This returns the underlying lattice chemical potentials, as the units are
317  * kmol-1 of the sublattice species.
318  *
319  * @param mu Output vector of species chemical potentials. Length: m_kk.
320  * Units: J/kmol
321  */
322  virtual void getChemPotentials(doublereal* mu) const;
323 
324  //! Returns an array of partial molar enthalpies for the species in the
325  //! mixture.
326  /*!
327  * Units (J/kmol). For this phase, the partial molar enthalpies are equal to
328  * the pure species enthalpies
329  * \f[
330  * \bar h_k(T,P) = \hat h^{ref}_k(T) + (P - P_{ref}) \hat V^0_k
331  * \f]
332  * The reference-state pure-species enthalpies, \f$ \hat h^{ref}_k(T) \f$,
333  * at the reference pressure,\f$ P_{ref} \f$, are computed by the species
334  * thermodynamic property manager. They are polynomial functions of
335  * temperature.
336  * @see MultiSpeciesThermo
337  *
338  * @param hbar Output vector containing partial molar enthalpies.
339  * Length: m_kk.
340  */
341  virtual void getPartialMolarEnthalpies(doublereal* hbar) const;
342 
343  /**
344  * Returns an array of partial molar entropies of the species in the
345  * solution. Units: J/kmol/K. For this phase, the partial molar entropies
346  * are equal to the pure species entropies plus the ideal solution
347  * contribution.
348  * \f[
349  * \bar s_k(T,P) = \hat s^0_k(T) - R log(X_k)
350  * \f]
351  * The reference-state pure-species entropies,\f$ \hat s^{ref}_k(T) \f$, at
352  * the reference pressure, \f$ P_{ref} \f$, are computed by the species
353  * thermodynamic property manager. They are polynomial functions of
354  * temperature.
355  * @see MultiSpeciesThermo
356  *
357  * @param sbar Output vector containing partial molar entropies.
358  * Length: m_kk.
359  */
360  virtual void getPartialMolarEntropies(doublereal* sbar) const;
361 
362  /**
363  * Returns an array of partial molar Heat Capacities at constant pressure of
364  * the species in the solution. Units: J/kmol/K. For this phase, the partial
365  * molar heat capacities are equal to the standard state heat capacities.
366  *
367  * @param cpbar Output vector of partial heat capacities. Length: m_kk.
368  */
369  virtual void getPartialMolarCp(doublereal* cpbar) const;
370 
371  /**
372  * returns an array of partial molar volumes of the species in the solution.
373  * Units: m^3 kmol-1.
374  *
375  * For this solution, the partial molar volumes are equal to the constant
376  * species molar volumes.
377  *
378  * @param vbar Output vector of partial molar volumes. Length: m_kk.
379  */
380  virtual void getPartialMolarVolumes(doublereal* vbar) const;
381 
382  //! Get the array of standard state chemical potentials at unit activity for
383  //! the species at their standard states at the current *T* and *P* of the
384  //! solution.
385  /*!
386  * These are the standard state chemical potentials \f$ \mu^0_k(T,P) \f$.
387  * The values are evaluated at the current temperature and pressure of the
388  * solution.
389  *
390  * This returns the underlying lattice standard chemical potentials, as the
391  * units are kmol-1 of the sublattice species.
392  *
393  * @param mu0 Output vector of chemical potentials.
394  * Length: m_kk. Units: J/kmol
395  */
396  virtual void getStandardChemPotentials(doublereal* mu0) const;
397 
398  virtual doublereal standardConcentration(size_t k=0) const;
399  virtual doublereal logStandardConc(size_t k=0) const;
400 
401  //@}
402  /// @name Thermodynamic Values for the Species Reference States
403  //@{
404 
405  virtual void getGibbs_RT_ref(doublereal* grt) const;
406  virtual void getGibbs_ref(doublereal* g) const;
407 
408  virtual bool addSpecies(shared_ptr<Species> spec);
409 
410  //! Add a lattice to this phase
411  void addLattice(shared_ptr<ThermoPhase> lattice);
412 
413  //! Set the lattice stoichiometric coefficients, \f$ \theta_i \f$
414  void setLatticeStoichiometry(const compositionMap& comp);
415 
416  virtual void initThermo();
417 
418  virtual void setParametersFromXML(const XML_Node& eosdata);
419 
420  //! Set the Lattice mole fractions using a string
421  /*!
422  * @param n Integer value of the lattice whose mole fractions are being set
423  * @param x string containing Name:value pairs that will specify the mole
424  * fractions of species on a particular lattice
425  */
426  void setLatticeMoleFractionsByName(int n, const std::string& x);
427 
428  virtual void modifyOneHf298SS(const size_t k, const doublereal Hf298New);
429  virtual void resetHf298(const size_t k=npos);
430 
431 protected:
432  //! Current value of the pressure
433  doublereal m_press;
434 
435  //! Current value of the molar density
436  doublereal m_molar_density;
437 
438  //! Vector of sublattic ThermoPhase objects
439  std::vector<shared_ptr<ThermoPhase>> m_lattice;
440 
441  //! Vector of mole fractions
442  /*!
443  * Note these mole fractions sum to one when summed over all phases.
444  * However, this is not what's passed down to the lower m_lattice objects.
445  */
446  mutable vector_fp m_x;
447 
448  //! Lattice stoichiometric coefficients
450 
451  //! Temporary vector
452  mutable vector_fp tmpV_;
453 
454  std::vector<size_t> lkstart_;
455 
456 private:
457  //! Update the reference thermodynamic functions
458  void _updateThermo() const;
459 };
460 }
461 
462 #endif
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
Definition: ct_defs.h:149
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 modifyOneHf298SS(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1) ...
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
doublereal calcDensity()
Calculate the density of the solid mixture.
virtual std::string type() const
String indicating the thermodynamic model implemented.
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:165
vector_fp theta_
Lattice stoichiometric coefficients.
LatticeSolidPhase()
Base empty constructor.
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 setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values, and then normalize them so that they sum to 1...
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
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 intEnergy_mole() const
Return the Molar Internal Energy. Units: J/kmol.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void setMassFractions_NoNorm(const doublereal *const y)
Set the mass fractions to the specified values without normalizing.
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
void _updateThermo() const
Update the reference thermodynamic functions.
virtual void resetHf298(const size_t k=npos)
Restore the original heat of formation of one or more species.
doublereal m_molar_density
Current value of the molar density.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
vector_fp tmpV_
Temporary vector.
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
doublereal m_press
Current value of the pressure.
virtual doublereal entropy_mole() const
Return the Molar Entropy. Units: J/kmol/K.
void addLattice(shared_ptr< ThermoPhase > lattice)
Add a lattice to this phase.
void setLatticeStoichiometry(const compositionMap &comp)
Set the lattice stoichiometric coefficients, .
void setLatticeMoleFractionsByName(int n, const std::string &x)
Set the Lattice mole fractions using a string.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
vector_fp m_x
Vector of mole fractions.
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
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
A phase that is comprised of a fixed additive combination of other lattice phases.
virtual int standardStateConvention() const
This method returns the convention used in specification of the standard state, of which there are cu...
virtual bool addSpecies(shared_ptr< Species > spec)
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
std::vector< shared_ptr< ThermoPhase > > m_lattice
Vector of sublattic ThermoPhase objects.
virtual doublereal cv_mole() const
Return the constant volume heat capacity. Units: J/kmol/K.
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
virtual doublereal pressure() const
Report the Pressure. Units: Pa.
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid...
virtual void getPartialMolarVolumes(doublereal *vbar) const
returns an array of partial molar volumes of the species in the solution.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
virtual doublereal cp_mole() const
Return the constant pressure heat capacity. Units: J/kmol/K.
virtual void getStandardChemPotentials(doublereal *mu0) const
Get the array of standard state chemical potentials at unit activity for the species at their standar...
Header file for class ThermoPhase, the base class for phases with thermodynamic properties, and the text for the Module thermoprops (see Thermodynamic Properties and class ThermoPhase).
virtual doublereal enthalpy_mole() const
Return the Molar Enthalpy. Units: J/kmol.
virtual doublereal gibbs_mole() const
Return the Molar Gibbs energy. Units: J/kmol.
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values and normalize them.
const int cSS_CONVENTION_SLAVE
Standard state thermodynamics is obtained from slave ThermoPhase objects.
Definition: ThermoPhase.h:40
virtual void setConcentrations(const doublereal *const conc)
Set the concentrations to the specified values within the phase.