Cantera  2.3.0
MolarityIonicVPSSTP.h
Go to the documentation of this file.
1 /**
2  * @file MolarityIonicVPSSTP.h (see \ref thermoprops and class \link
3  * Cantera::MolarityIonicVPSSTP MolarityIonicVPSSTP\endlink).
4  *
5  * Header file for a derived class of ThermoPhase that handles variable pressure
6  * standard state methods for calculating thermodynamic properties that are
7  * further based upon activities based on the molarity scale. In this class, we
8  * expect that there are ions, but they are treated on the molarity scale.
9  */
10 
11 // This file is part of Cantera. See License.txt in the top-level directory or
12 // at http://www.cantera.org/license.txt for license and copyright information.
13 
14 #ifndef CT_MOLARITYIONICVPSSTP_H
15 #define CT_MOLARITYIONICVPSSTP_H
16 
17 #include "GibbsExcessVPSSTP.h"
18 
19 namespace Cantera
20 {
21 
22 /*!
23  * MolarityIonicVPSSTP is a derived class of GibbsExcessVPSSTP that handles
24  * variable pressure standard state methods for calculating thermodynamic
25  * properties that are further based on expressing the Excess Gibbs free energy
26  * as a function of the mole fractions (or pseudo mole fractions) of the
27  * constituents. This category is the workhorse for describing ionic systems
28  * which are not on the molality scale.
29  *
30  * @attention This class currently does not have any test cases or examples. Its
31  * implementation may be incomplete, and future changes to Cantera may
32  * unexpectedly cause this class to stop working. If you use this class,
33  * please consider contributing examples or test cases. In the absence of
34  * new tests or examples, this class may be deprecated and removed in a
35  * future version of Cantera. See
36  * https://github.com/Cantera/cantera/issues/267 for additional information.
37  *
38  * This class adds additional functions onto the ThermoPhase interface that
39  * handles the calculation of the excess Gibbs free energy. The ThermoPhase
40  * class includes a member function, ThermoPhase::activityConvention() that
41  * indicates which convention the activities are based on. The default is to
42  * assume activities are based on the molar convention. That default is used
43  * here.
44  *
45  * All of the Excess Gibbs free energy formulations in this area employ
46  * symmetrical formulations.
47  *
48  * This layer will massage the mole fraction vector to implement cation and
49  * anion based mole numbers in an optional manner, such that it is expected that
50  * there exists a charge balance at all times. One of the ions must be a
51  * "special ion" in the sense that its' thermodynamic functions are set to zero,
52  * and the thermo functions of all other ions are based on a valuation relative
53  * to that special ion.
54  */
56 {
57 public:
59 
60  //! Construct and initialize a MolarityIonicVPSSTP ThermoPhase object
61  //! directly from an XML input file
62  /*!
63  * @param inputFile Name of the input file containing the phase XML data
64  * to set up the object
65  * @param id ID of the phase in the input file. Defaults to the
66  * empty string.
67  */
68  MolarityIonicVPSSTP(const std::string& inputFile, const std::string& id = "");
69 
70  //! Construct and initialize a MolarityIonicVPSSTP ThermoPhase object
71  //! directly from an XML database
72  /*!
73  * @param phaseRef XML phase node containing the description of the phase
74  * @param id id attribute containing the name of the phase.
75  * (default is the empty string)
76  */
77  MolarityIonicVPSSTP(XML_Node& phaseRef, const std::string& id = "");
78 
80  MolarityIonicVPSSTP& operator=(const MolarityIonicVPSSTP& b);
81  virtual ThermoPhase* duplMyselfAsThermoPhase() const;
82 
83  virtual std::string type() const {
84  return "MolarityIonic";
85  }
86 
87  /**
88  * @name Activities, Standard States, and Activity Concentrations
89  *
90  * The activity \f$a_k\f$ of a species in solution is
91  * related to the chemical potential by \f[ \mu_k = \mu_k^0(T)
92  * + \hat R T \log a_k. \f] The quantity \f$\mu_k^0(T,P)\f$ is
93  * the chemical potential at unit activity, which depends only
94  * on temperature and pressure.
95  * @{
96  */
97 
98  virtual void getLnActivityCoefficients(doublereal* lnac) const;
99 
100  //@}
101  /// @name Partial Molar Properties of the Solution
102  //@{
103 
104  virtual void getChemPotentials(doublereal* mu) const;
105 
106  //! Returns an array of partial molar enthalpies for the species
107  //! in the mixture.
108  /*!
109  * Units (J/kmol)
110  *
111  * For this phase, the partial molar enthalpies are equal to the standard
112  * state enthalpies modified by the derivative of the molality-based
113  * activity coefficient wrt temperature
114  *
115  * \f[
116  * \bar h_k(T,P) = h^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
117  * \f]
118  *
119  * @param hbar Vector of returned partial molar enthalpies
120  * (length m_kk, units = J/kmol)
121  */
122  virtual void getPartialMolarEnthalpies(doublereal* hbar) const;
123 
124  //! Returns an array of partial molar entropies for the species in the
125  //! mixture.
126  /*!
127  * Units (J/kmol)
128  *
129  * For this phase, the partial molar enthalpies are equal to the standard
130  * state enthalpies modified by the derivative of the activity coefficient
131  * wrt temperature
132  *
133  * \f[
134  * \bar s_k(T,P) = s^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
135  * - R \ln( \gamma_k X_k)
136  * - R T \frac{d \ln(\gamma_k) }{dT}
137  * \f]
138  *
139  * @param sbar Vector of returned partial molar entropies
140  * (length m_kk, units = J/kmol/K)
141  */
142  virtual void getPartialMolarEntropies(doublereal* sbar) const;
143 
144  //! Returns an array of partial molar entropies for the species
145  //! in the mixture.
146  /*!
147  * Units (J/kmol)
148  *
149  * For this phase, the partial molar enthalpies are equal to the standard
150  * state enthalpies modified by the derivative of the activity coefficient
151  * wrt temperature
152  *
153  * \f[
154  * ???????????????
155  * \bar s_k(T,P) = s^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
156  * - R \ln( \gamma_k X_k)
157  * - R T \frac{d \ln(\gamma_k) }{dT}
158  * ???????????????
159  * \f]
160  *
161  * @param cpbar Vector of returned partial molar heat capacities
162  * (length m_kk, units = J/kmol/K)
163  */
164  virtual void getPartialMolarCp(doublereal* cpbar) const;
165 
166  virtual void getPartialMolarVolumes(doublereal* vbar) const;
167 
168  //@}
169 
170  //! Calculate pseudo binary mole fractions
171  virtual void calcPseudoBinaryMoleFractions() const;
172 
173  /// @name Initialization
174  /// The following methods are used in the process of constructing
175  /// the phase and setting its parameters from a specification in an
176  /// input file. They are not normally used in application programs.
177  /// To see how they are used, see importPhase().
178  /// @{
179 
180  virtual void initThermo();
181  virtual void initThermoXML(XML_Node& phaseNode, const std::string& id);
182  //! @}
183 
184  virtual std::string report(bool show_thermo=true,
185  doublereal threshold=1e-14) const;
186 
187 private:
188  //! Initialize lengths of local variables after all species have been
189  //! identified.
190  void initLengths();
191 
192  //! Process an XML node called "binaryNeutralSpeciesParameters"
193  /*!
194  * This node contains all of the parameters necessary to describe the
195  * Redlich-Kister model for a particular binary interaction. This function
196  * reads the XML file and writes the coefficients it finds to an internal
197  * data structures.
198  *
199  * @param xmlBinarySpecies Reference to the XML_Node named
200  * "binaryNeutralSpeciesParameters" containing the binary interaction
201  */
202  void readXMLBinarySpecies(XML_Node& xmlBinarySpecies);
203 
204  //! Update the activity coefficients
205  /*!
206  * This function will be called to update the internally stored natural
207  * logarithm of the activity coefficients
208  */
209  void s_update_lnActCoeff() const;
210 
211  //! Update the derivative of the log of the activity coefficients wrt T
212  /*!
213  * This function will be called to update the internally stored derivative
214  * of the natural logarithm of the activity coefficients wrt temperature.
215  */
216  void s_update_dlnActCoeff_dT() const;
217 
218  //! Internal routine that calculates the derivative of the activity
219  //! coefficients wrt the mole fractions.
220  /*!
221  * This routine calculates the the derivative of the activity coefficients
222  * wrt to mole fraction with all other mole fractions held constant. This is
223  * strictly not permitted. However, if the resulting matrix is multiplied by
224  * a permissible deltaX vector then everything is ok.
225  *
226  * This is the natural way to handle concentration derivatives in this
227  * routine.
228  */
229  void s_update_dlnActCoeff_dX_() const;
230 
231 protected:
232  // Pseudobinary type
233  /*!
234  * - `PBTYPE_PASSTHROUGH` - All species are passthrough species
235  * - `PBTYPE_SINGLEANION` - there is only one anion in the mixture
236  * - `PBTYPE_SINGLECATION` - there is only one cation in the mixture
237  * - `PBTYPE_MULTICATIONANION` - Complex mixture
238  */
239  int PBType_;
240 
241  //! Number of pseudo binary species
243 
244  //! index of special species
246 
247  mutable vector_fp PBMoleFractions_;
248 
249  //! Vector of cation indices in the mixture
250  std::vector<size_t> cationList_;
251 
252  std::vector<size_t> anionList_;
253 
254  std::vector<size_t> passThroughList_;
255  size_t neutralPBindexStart;
256 
257  mutable vector_fp moleFractionsTmp_;
258 };
259 
260 #define PBTYPE_PASSTHROUGH 0
261 #define PBTYPE_SINGLEANION 1
262 #define PBTYPE_SINGLECATION 2
263 #define PBTYPE_MULTICATIONANION 3
264 
265 }
266 
267 #endif
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
virtual void calcPseudoBinaryMoleFractions() const
Calculate pseudo binary mole fractions.
void s_update_dlnActCoeff_dT() const
Update the derivative of the log of the activity coefficients wrt T.
void readXMLBinarySpecies(XML_Node &xmlBinarySpecies)
Process an XML node called "binaryNeutralSpeciesParameters".
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
std::vector< size_t > cationList_
Vector of cation indices in the mixture.
void s_update_lnActCoeff() const
Update the activity coefficients.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies for the species in the mixture.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
Header for intermediate ThermoPhase object for phases which employ Gibbs excess free energy based for...
virtual std::string type() const
String indicating the thermodynamic model implemented.
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
void initLengths()
Initialize lengths of local variables after all species have been identified.
void s_update_dlnActCoeff_dX_() const
Internal routine that calculates the derivative of the activity coefficients wrt the mole fractions...
virtual void getLnActivityCoefficients(doublereal *lnac) const
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
virtual void getPartialMolarCp(doublereal *cpbar) const
Returns an array of partial molar entropies for the species in the mixture.
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 std::string report(bool show_thermo=true, doublereal threshold=1e-14) const
returns a summary of the state of the phase as a string
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
size_t numPBSpecies_
Number of pseudo binary species.
Namespace for the Cantera kernel.
Definition: application.cpp:29
size_t indexSpecialSpecies_
index of special species