Cantera  2.4.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  * @deprecated To be removed after Cantera 2.4
39  *
40  * This class adds additional functions onto the ThermoPhase interface that
41  * handles the calculation of the excess Gibbs free energy. The ThermoPhase
42  * class includes a member function, ThermoPhase::activityConvention() that
43  * indicates which convention the activities are based on. The default is to
44  * assume activities are based on the molar convention. That default is used
45  * here.
46  *
47  * All of the Excess Gibbs free energy formulations in this area employ
48  * symmetrical formulations.
49  *
50  * This layer will massage the mole fraction vector to implement cation and
51  * anion based mole numbers in an optional manner, such that it is expected that
52  * there exists a charge balance at all times. One of the ions must be a
53  * "special ion" in the sense that its' thermodynamic functions are set to zero,
54  * and the thermo functions of all other ions are based on a valuation relative
55  * to that special ion.
56  */
58 {
59 public:
61 
62  //! Construct and initialize a MolarityIonicVPSSTP ThermoPhase object
63  //! directly from an XML input file
64  /*!
65  * @param inputFile Name of the input file containing the phase XML data
66  * to set up the object
67  * @param id ID of the phase in the input file. Defaults to the
68  * empty string.
69  */
70  MolarityIonicVPSSTP(const std::string& inputFile, const std::string& id = "");
71 
72  //! Construct and initialize a MolarityIonicVPSSTP ThermoPhase object
73  //! directly from an XML database
74  /*!
75  * @param phaseRef XML phase node containing the description of the phase
76  * @param id id attribute containing the name of the phase.
77  * (default is the empty string)
78  */
79  MolarityIonicVPSSTP(XML_Node& phaseRef, const std::string& id = "");
80 
81  virtual std::string type() const {
82  return "MolarityIonic";
83  }
84 
85  /**
86  * @name Activities, Standard States, and Activity Concentrations
87  *
88  * The activity \f$a_k\f$ of a species in solution is
89  * related to the chemical potential by \f[ \mu_k = \mu_k^0(T)
90  * + \hat R T \log a_k. \f] The quantity \f$\mu_k^0(T,P)\f$ is
91  * the chemical potential at unit activity, which depends only
92  * on temperature and pressure.
93  * @{
94  */
95 
96  virtual void getLnActivityCoefficients(doublereal* lnac) const;
97 
98  //@}
99  /// @name Partial Molar Properties of the Solution
100  //@{
101 
102  virtual void getChemPotentials(doublereal* mu) const;
103 
104  //! Returns an array of partial molar enthalpies for the species
105  //! in the mixture.
106  /*!
107  * Units (J/kmol)
108  *
109  * For this phase, the partial molar enthalpies are equal to the standard
110  * state enthalpies modified by the derivative of the molality-based
111  * activity coefficient wrt temperature
112  *
113  * \f[
114  * \bar h_k(T,P) = h^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
115  * \f]
116  *
117  * @param hbar Vector of returned partial molar enthalpies
118  * (length m_kk, units = J/kmol)
119  */
120  virtual void getPartialMolarEnthalpies(doublereal* hbar) const;
121 
122  //! Returns an array of partial molar entropies for the species in the
123  //! mixture.
124  /*!
125  * Units (J/kmol)
126  *
127  * For this phase, the partial molar enthalpies are equal to the standard
128  * state enthalpies modified by the derivative of the activity coefficient
129  * wrt temperature
130  *
131  * \f[
132  * \bar s_k(T,P) = s^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
133  * - R \ln( \gamma_k X_k)
134  * - R T \frac{d \ln(\gamma_k) }{dT}
135  * \f]
136  *
137  * @param sbar Vector of returned partial molar entropies
138  * (length m_kk, units = J/kmol/K)
139  */
140  virtual void getPartialMolarEntropies(doublereal* sbar) const;
141 
142  //! Returns an array of partial molar entropies for the species
143  //! in the mixture.
144  /*!
145  * Units (J/kmol)
146  *
147  * For this phase, the partial molar enthalpies are equal to the standard
148  * state enthalpies modified by the derivative of the activity coefficient
149  * wrt temperature
150  *
151  * \f[
152  * ???????????????
153  * \bar s_k(T,P) = s^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
154  * - R \ln( \gamma_k X_k)
155  * - R T \frac{d \ln(\gamma_k) }{dT}
156  * ???????????????
157  * \f]
158  *
159  * @param cpbar Vector of returned partial molar heat capacities
160  * (length m_kk, units = J/kmol/K)
161  */
162  virtual void getPartialMolarCp(doublereal* cpbar) const;
163 
164  virtual void getPartialMolarVolumes(doublereal* vbar) const;
165 
166  //@}
167 
168  //! Calculate pseudo binary mole fractions
169  virtual void calcPseudoBinaryMoleFractions() const;
170 
171  /// @name Initialization
172  /// The following methods are used in the process of constructing
173  /// the phase and setting its parameters from a specification in an
174  /// input file. They are not normally used in application programs.
175  /// To see how they are used, see importPhase().
176  /// @{
177 
178  virtual void initThermo();
179  virtual void initThermoXML(XML_Node& phaseNode, const std::string& id);
180  //! @}
181 
182  virtual std::string report(bool show_thermo=true,
183  doublereal threshold=1e-14) const;
184 
185 private:
186  //! Initialize lengths of local variables after all species have been
187  //! identified.
188  void initLengths();
189 
190  //! Process an XML node called "binaryNeutralSpeciesParameters"
191  /*!
192  * This node contains all of the parameters necessary to describe the
193  * Redlich-Kister model for a particular binary interaction. This function
194  * reads the XML file and writes the coefficients it finds to an internal
195  * data structures.
196  *
197  * @param xmlBinarySpecies Reference to the XML_Node named
198  * "binaryNeutralSpeciesParameters" containing the binary interaction
199  */
200  void readXMLBinarySpecies(XML_Node& xmlBinarySpecies);
201 
202  //! Update the activity coefficients
203  /*!
204  * This function will be called to update the internally stored natural
205  * logarithm of the activity coefficients
206  */
207  void s_update_lnActCoeff() const;
208 
209  //! Update the derivative of the log of the activity coefficients wrt T
210  /*!
211  * This function will be called to update the internally stored derivative
212  * of the natural logarithm of the activity coefficients wrt temperature.
213  */
214  void s_update_dlnActCoeff_dT() const;
215 
216  //! Internal routine that calculates the derivative of the activity
217  //! coefficients wrt the mole fractions.
218  /*!
219  * This routine calculates the the derivative of the activity coefficients
220  * wrt to mole fraction with all other mole fractions held constant. This is
221  * strictly not permitted. However, if the resulting matrix is multiplied by
222  * a permissible deltaX vector then everything is ok.
223  *
224  * This is the natural way to handle concentration derivatives in this
225  * routine.
226  */
227  void s_update_dlnActCoeff_dX_() const;
228 
229 protected:
230  // Pseudobinary type
231  /*!
232  * - `PBTYPE_PASSTHROUGH` - All species are passthrough species
233  * - `PBTYPE_SINGLEANION` - there is only one anion in the mixture
234  * - `PBTYPE_SINGLECATION` - there is only one cation in the mixture
235  * - `PBTYPE_MULTICATIONANION` - Complex mixture
236  */
237  int PBType_;
238 
239  //! Number of pseudo binary species
241 
242  mutable vector_fp PBMoleFractions_;
243 
244  //! Vector of cation indices in the mixture
245  std::vector<size_t> cationList_;
246 
247  std::vector<size_t> anionList_;
248 
249  std::vector<size_t> passThroughList_;
250  size_t neutralPBindexStart;
251 
252  mutable vector_fp moleFractionsTmp_;
253 };
254 
255 #define PBTYPE_PASSTHROUGH 0
256 #define PBTYPE_SINGLEANION 1
257 #define PBTYPE_SINGLECATION 2
258 #define PBTYPE_MULTICATIONANION 3
259 
260 }
261 
262 #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.
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.
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: AnyMap.cpp:8