Cantera  2.5.1
BinarySolutionTabulatedThermo.h
Go to the documentation of this file.
1 /**
2  * @file BinarySolutionTabulatedThermo.h
3  * Header file for an binary solution model with tabulated standard state
4  * thermodynamic data (see \ref thermoprops and class
5  * \link Cantera::BinarySolutionTabulatedThermo BinarySolutionTabulatedThermo\endlink).
6  */
7 
8 // This file is part of Cantera. See License.txt in the top-level directory or
9 // at https://cantera.org/license.txt for license and copyright information.
10 
11 #ifndef CT_BINARYSOLUTIONTABULATEDTHERMO_H
12 #define CT_BINARYSOLUTIONTABULATEDTHERMO_H
13 
14 #include "IdealSolidSolnPhase.h"
15 #include "cantera/base/utilities.h"
16 
17 namespace Cantera
18 {
19 
20 //! Overloads the virtual methods of class IdealSolidSolnPhase to implement
21 //! tabulated standard state thermodynamics for one species in a binary
22 //! solution.
23 /**
24  *
25  * BinarySolutionTabulatedThermo is derived from IdealSolidSolnPhase, but
26  * overwrites the standard state thermodynamic data using tabulated data,
27  * as provided by the user in the input file. This ends up being useful for
28  * certain non-ideal / non-dilute species where the interaction potentials, as
29  * a function of composition / solute mole fraction, are not easily represented
30  * by any closed-form equation of state.
31  *
32  * A good example of this type of phase is intercalation-based lithium storage
33  * materials used for lithium-ion battery electrodes. Measuring the open
34  * circuit voltage \f$ E_eq \f$, relative to a reference electrode, as a
35  * function of lithium mole fraction and as a function of temperature, provides
36  * a means to evaluate the gibbs free energy of reaction:
37  *
38  * \f[
39  * \Delta g_{\rm rxn} = -\frac{E_eq}{nF}
40  * \f]
41  *
42  * where \f$ n\f$ is the charge number transferred to the phase, via the
43  * reaction, and \f$ F \f$ is Faraday's constant. The gibbs energy of
44  * reaction, in turn, can be separated into enthalpy and entropy of reaction
45  * components:
46  *
47  * \f[
48  * \Delta g_{\rm rxn} = \Delta h_{\rm rxn} - T\Delta s_{\rm rxn}
49  * \f]
50  * \f[
51  * \frac{d\Delta g_{\rm rxn}}{dT} = - \Delta s_{\rm rxn}
52  * \f]
53  *
54  * For the tabulated binary phase, the user identifies a 'tabulated' species,
55  * while the other is considered the 'reference' species. The standard state
56  * thermo variables for the tabulated species therefore incorporate any and all
57  * excess energy contributions, and are calculated according to the reaction
58  * energy terms:
59  *
60  * \f[
61  * \Delta h_{\rm rxn} = \sum_k \nu_k h^{\rm o}_k
62  * \f]
63  * \f[
64  * \Delta s_{\rm rxn} = \sum_k \nu_k s^{\rm o}_k + RT\ln\left(\prod_k\left(\frac{c_k}{c^{\rm o}_k} \right)^{\nu_k}\right)
65  * \f]
66  *
67  * Where the 'reference' species is automatically assigned standard state
68  * thermo variables \f$ h^{\rm o} = 0\f$ and \f$ s^{\rm o} = 0\f$, and standard
69  * state thermo variables for species in any other phases are calculated
70  * according to the rules specified in that phase definition.
71  *
72  * The present model is intended for modeling non-ideal, tabulated
73  * thermodynamics for binary solutions where the tabulated species is
74  * incorporated via an electrochemical reaction, such that the open circuit
75  * voltage can be measured, relative to a counter electrode species with
76  * standard state thermo properties \f$ h^{\rm o} = 0\f$.
77  * It is possible that this can be generalized such that this assumption about
78  * the counter-electrode is not required. At present, this is left as future
79  * work.
80  *
81  * The user therefore provides a table of three equally-sized vectors of
82  * tabulated data:
83  *
84  * - \f$ x_{\rm tab}\f$ = array of mole fractions for the tabulated species
85  * at which measurements were conducted and thermo
86  * data are provided.
87  * - \f$ h_{\rm tab}\f$ = \f$ F\left(-E_{\rm eq}\left(x,T^{\rm o} \right) + T^{\rm o} \frac{dE_{\rm eq}\left(x,T^{\rm o} \right)}{dT}\right) \f$
88  * - \f$ s_{\rm tab}\f$ = \f$ F \left(\frac{dE_{\rm eq}\left(x,T^{\rm o} \right)}{dT} + s_{\rm counter}^{\rm o} \right) \f$
89  *
90  * where \f$ E_{\rm eq}\left(x,T^{\rm o} \right) \f$ and \f$ \frac{dE_{\rm eq}\left(x,T^{\rm o} \right)}{dT} \f$
91  * are the experimentally-measured open circuit voltage and derivative in
92  * open circuit voltage with respect to temperature, respectively, both
93  * measured as a mole fraction of \f$ x \f$ for the tabulated species and at a
94  * temperature of \f$ T^{\rm o} \f$. The arrays \f$ h_{\rm tab}\f$ and
95  * \f$ s_{\rm tab}\f$ must be the same length as the \f$ x_{\rm tab}\f$ array.
96  *
97  * From these tabulated inputs, the standard state thermodynamic properties
98  * for the tabulated species (subscript \f$ k\f$, tab) are calculated as:
99  *
100  * \f[
101  * h^{\rm o}_{k,\,{\rm tab}} = h_{\rm tab}
102  * \f]
103  * \f[
104  * s^{\rm o}_{k,\,{\rm tab}} = s_{\rm tab} + R\ln\frac{x_{k,\,{\rm tab}}}{1-x_{k,\,{\rm tab}}} + \frac{R}{F} \ln\left(\frac{c^{\rm o}_{k,\,{\rm ref}}}{c^{\rm o}_{k,\,{\rm tab}}}\right)
105  * \f]
106  *
107  * Now, whenever the composition has changed, the lookup/interpolation of the
108  * tabulated thermo data is performed to update the standard state
109  * thermodynamic data for the tabulated species.
110  *
111  * @ingroup thermoprops
112  */
114 {
115 public:
116  //! Default constructor for BinarySolutionTabulatedThermo
118 
119  //! Construct and initialize an BinarySolutionTabulatedThermo ThermoPhase object
120  //! directly from an input file
121  /*!
122  * This constructor will also fully initialize the object.
123  *
124  * @param infile File name for the input file containing information
125  * for this phase
126  * @param id The name of this phase. This is used to look up
127  * the phase in the input file.
128  */
129  BinarySolutionTabulatedThermo(const std::string& infile, const std::string& id="");
130 
131  //! Construct and initialize an BinarySolutionTabulatedThermo ThermoPhase object
132  //! directly from an XML database
133  /*!
134  * @param root XML tree containing a description of the phase.
135  * The tree must be positioned at the XML element
136  * named phase with id, "id", on input to this routine.
137  * @param id The name of this phase. This is used to look up
138  * the phase in the XML datafile.
139  *
140  * @deprecated The XML input format is deprecated and will be removed in
141  * Cantera 3.0.
142  */
143  BinarySolutionTabulatedThermo(XML_Node& root, const std::string& id="");
144 
145  virtual std::string type() const {
146  return "BinarySolutionTabulatedThermo";
147  }
148 
149  virtual void initThermo();
150  virtual void initThermoXML(XML_Node& phaseNode, const std::string& id_);
151 
152 protected:
153  //! If the compositions have changed, update the tabulated thermo lookup
154  virtual void compositionChanged();
155 
156  //! Species thermodynamics interpolation functions
157  std::pair<double,double> interpolate(double x) const;
158 
159  //! Current tabulated species index
160  size_t m_kk_tab;
161 
162  //! Current tabulated species mole fraction
163  mutable double m_xlast;
164 
165  //! Tabulated contribution to h0[m_kk_tab] at the current composition
166  mutable double m_h0_tab;
167 
168  //! Tabulated contribution to s0[m_kk_tab] at the current composition
169  mutable double m_s0_tab;
170 
171  //! Vector for storing tabulated thermo
173  vector_fp m_enthalpy_tab;
174  vector_fp m_entropy_tab;
175 
176 private:
177  virtual void _updateThermo() const;
178 };
179 }
180 
181 #endif
Header file for an ideal solid solution model with incompressible thermodynamics (see Thermodynamic P...
Overloads the virtual methods of class IdealSolidSolnPhase to implement tabulated standard state ther...
double m_xlast
Current tabulated species mole fraction.
BinarySolutionTabulatedThermo()
Default constructor for BinarySolutionTabulatedThermo.
double m_s0_tab
Tabulated contribution to s0[m_kk_tab] at the current composition.
vector_fp m_molefrac_tab
Vector for storing tabulated thermo.
size_t m_kk_tab
Current tabulated species index.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
std::pair< double, double > interpolate(double x) const
Species thermodynamics interpolation functions.
virtual std::string type() const
String indicating the thermodynamic model implemented.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id_)
Import and initialize a ThermoPhase object using an XML tree.
double m_h0_tab
Tabulated contribution to h0[m_kk_tab] at the current composition.
virtual void compositionChanged()
If the compositions have changed, update the tabulated thermo lookup.
virtual void _updateThermo() const
This function gets called for every call to functions in this class.
Class IdealSolidSolnPhase represents a condensed phase ideal solution compound.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:104
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
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
Various templated functions that carry out common vector operations (see Templated Utility Functions)...