Cantera  2.1.2
MolarityIonicVPSSTP.h
Go to the documentation of this file.
1 /**
2  * @file MolarityIonicVPSSTP.h
3  * Header for intermediate ThermoPhase object for phases which
4  * employ gibbs excess free energy based formulations
5  * (see \ref thermoprops
6  * and class \link Cantera::MolarityIonicVPSSTP MolarityIonicVPSSTP\endlink).
7  *
8  * Header file for a derived class of ThermoPhase that handles
9  * variable pressure standard state methods for calculating
10  * thermodynamic properties that are further based upon activities
11  * based on the molarity scale. In this class, we expect that there are
12  * ions, but they are treated on the molarity scale.
13  */
14 /*
15  * Copyright (2006) Sandia Corporation. Under the terms of
16  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
17  * U.S. Government retains certain rights in this software.
18  */
19 
20 #ifndef CT_MOLARITYIONICVPSSTP_H
21 #define CT_MOLARITYIONICVPSSTP_H
22 
23 #include "GibbsExcessVPSSTP.h"
24 
25 namespace Cantera
26 {
27 
28 /**
29  * @ingroup thermoprops
30  */
31 
32 /*!
33  * MolarityIonicVPSSTP is a derived class of GibbsExcessVPSSTP that handles
34  * variable pressure standard state methods for calculating
35  * thermodynamic properties that are further based on
36  * expressing the Excess Gibbs free energy as a function of
37  * the mole fractions (or pseudo mole fractions) of the constituents.
38  * This category is the workhorse for describing ionic systems which are not on the molality scale.
39  *
40  * This class adds additional functions onto the ThermoPhase interface
41  * that handles the calculation of the excess Gibbs free energy. The ThermoPhase
42  * class includes a member function, ThermoPhase::activityConvention()
43  * that indicates which convention the activities are based on. The
44  * default is to assume activities are based on the molar convention.
45  * That default is used 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
51  * cation and anion based mole numbers in an optional manner, such that
52  * it is expected that there exists a charge balance at all times.
53  * One of the ions must be a "special ion" in the sense that its' thermodynamic
54  * functions are set to zero, and the thermo functions of all other
55  * ions are based on a valuation relative to that special ion.
56  *
57  */
59 {
60 
61 public:
62  /// Constructor
63  /*!
64  * This doesn't do much more than initialize constants with
65  * default values for water at 25C. Water molecular weight
66  * comes from the default elements.xml file. It actually
67  * differs slightly from the IAPWS95 value of 18.015268. However,
68  * density conservation and therefore element conservation
69  * is the more important principle to follow.
70  */
72 
73  //! Construct and initialize a MolarityIonicVPSSTP ThermoPhase object
74  //! directly from an XML input file
75  /*!
76  * @param inputFile Name of the input file containing the phase XML data
77  * to set up the object
78  * @param id ID of the phase in the input file. Defaults to the
79  * empty string.
80  */
81  MolarityIonicVPSSTP(const std::string& inputFile, const std::string& id = "");
82 
83  //! Construct and initialize a MolarityIonicVPSSTP ThermoPhase object
84  //! directly from an XML database
85  /*!
86  * @param phaseRef XML phase node containing the description of the phase
87  * @param id id attribute containing the name of the phase.
88  * (default is the empty string)
89  */
90  MolarityIonicVPSSTP(XML_Node& phaseRef, const std::string& id = "");
91 
92  //! Copy constructor
93  /*!
94  * @param b class to be copied
95  */
97 
98  /// Assignment operator
99  /*!
100  * @param b class to be copied.
101  */
103 
104  //! Duplication routine for objects which inherit from ThermoPhase.
105  /*!
106  * This virtual routine can be used to duplicate thermophase objects
107  * inherited from ThermoPhase even if the application only has
108  * a pointer to ThermoPhase to work with.
109  */
110  virtual ThermoPhase* duplMyselfAsThermoPhase() const;
111 
112  //! @name Utilities
113  //! @{
114 
115  //! Equation of state type flag.
116  /*!
117  * The ThermoPhase base class returns
118  * zero. Subclasses should define this to return a unique
119  * non-zero value. Known constants defined for this purpose are
120  * listed in mix_defs.h. The MolalityVPSSTP class also returns
121  * zero, as it is a non-complete class.
122  */
123  virtual int eosType() const;
124 
125  /**
126  * @}
127  * @name Activities, Standard States, and Activity Concentrations
128  *
129  * The activity \f$a_k\f$ of a species in solution is
130  * related to the chemical potential by \f[ \mu_k = \mu_k^0(T)
131  * + \hat R T \log a_k. \f] The quantity \f$\mu_k^0(T,P)\f$ is
132  * the chemical potential at unit activity, which depends only
133  * on temperature and pressure.
134  * @{
135  */
136 
137  //! Get the array of non-dimensional molar-based ln activity coefficients at
138  //! the current solution temperature, pressure, and solution concentration.
139  /*!
140  * @param lnac Output vector of ln activity coefficients. Length: m_kk.
141  */
142  virtual void getLnActivityCoefficients(doublereal* lnac) const;
143 
144  //@}
145  /// @name Partial Molar Properties of the Solution
146  //@{
147 
148  //! Get the species chemical potentials. Units: J/kmol.
149  /*!
150  * This function returns a vector of chemical potentials of the
151  * species in solution at the current temperature, pressure
152  * and mole fraction of the solution.
153  *
154  * @param mu Output vector of species chemical
155  * potentials. Length: m_kk. Units: J/kmol
156  */
157  virtual void getChemPotentials(doublereal* mu) const;
158 
159  /**
160  * Get the species electrochemical potentials.
161  * These are partial molar quantities.
162  * This method adds a term \f$ Fz_k \phi_k \f$ to the
163  * to each chemical potential.
164  *
165  * Units: J/kmol
166  *
167  * @param mu output vector containing the species electrochemical potentials.
168  * Length: m_kk.
169  */
170  void getElectrochemPotentials(doublereal* mu) const;
171 
172  //! Returns an array of partial molar enthalpies for the species
173  //! in the mixture.
174  /*!
175  * Units (J/kmol)
176  *
177  * For this phase, the partial molar enthalpies are equal to the
178  * standard state enthalpies modified by the derivative of the
179  * molality-based activity coefficient wrt temperature
180  *
181  * \f[
182  * \bar h_k(T,P) = h^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
183  * \f]
184  *
185  * @param hbar Vector of returned partial molar enthalpies
186  * (length m_kk, units = J/kmol)
187  */
188  virtual void getPartialMolarEnthalpies(doublereal* hbar) const;
189 
190  //! Returns an array of partial molar entropies for the species
191  //! in the mixture.
192  /*!
193  * Units (J/kmol)
194  *
195  * For this phase, the partial molar enthalpies are equal to the
196  * standard state enthalpies modified by the derivative of the
197  * activity coefficient wrt temperature
198  *
199  * \f[
200  * \bar s_k(T,P) = s^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
201  * - R \ln( \gamma_k X_k)
202  * - R T \frac{d \ln(\gamma_k) }{dT}
203  * \f]
204  *
205  * @param sbar Vector of returned partial molar entropies
206  * (length m_kk, units = J/kmol/K)
207  */
208  virtual void getPartialMolarEntropies(doublereal* sbar) const;
209 
210  //! Returns an array of partial molar entropies for the species
211  //! in the mixture.
212  /*!
213  * Units (J/kmol)
214  *
215  * For this phase, the partial molar enthalpies are equal to the
216  * standard state enthalpies modified by the derivative of the
217  * activity coefficient wrt temperature
218  *
219  * \f[
220  * ???????????????
221  * \bar s_k(T,P) = s^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
222  * - R \ln( \gamma_k X_k)
223  * - R T \frac{d \ln(\gamma_k) }{dT}
224  * ???????????????
225  * \f]
226  *
227  * @param cpbar Vector of returned partial molar heat capacities
228  * (length m_kk, units = J/kmol/K)
229  */
230  virtual void getPartialMolarCp(doublereal* cpbar) const;
231 
232  //! Return an array of partial molar volumes for the
233  //! species in the mixture. Units: m^3/kmol.
234  /*!
235  * Frequently, for this class of thermodynamics representations,
236  * the excess Volume due to mixing is zero. Here, we set it as
237  * a default. It may be overridden in derived classes.
238  *
239  * @param vbar Output vector of species partial molar volumes.
240  * Length = m_kk. units are m^3/kmol.
241  */
242  virtual void getPartialMolarVolumes(doublereal* vbar) const;
243 
244  //@}
245 
246  //! Calculate pseudo binary mole fractions
247  virtual void calcPseudoBinaryMoleFractions() const;
248 
249  /// @name Initialization
250  /// The following methods are used in the process of constructing
251  /// the phase and setting its parameters from a specification in an
252  /// input file. They are not normally used in application programs.
253  /// To see how they are used, see files importCTML.cpp and
254  /// ThermoFactory.cpp.
255  /// @{
256 
257  /*!
258  * @internal Initialize. This method is provided to allow
259  * subclasses to perform any initialization required after all
260  * species have been added. For example, it might be used to
261  * resize internal work arrays that must have an entry for
262  * each species. The base class implementation does nothing,
263  * and subclasses that do not require initialization do not
264  * need to overload this method. When importing a CTML phase
265  * description, this method is called just prior to returning
266  * from function importPhase.
267  *
268  * @see importCTML.cpp
269  */
270  virtual void initThermo();
271 
272  /**
273  * Import and initialize a ThermoPhase object
274  *
275  * @param phaseNode This object must be the phase node of a
276  * complete XML tree
277  * description of the phase, including all of the
278  * species data. In other words while "phase" must
279  * point to an XML phase object, it must have
280  * sibling nodes "speciesData" that describe
281  * the species in the phase.
282  * @param id ID of the phase. If nonnull, a check is done
283  * to see if phaseNode is pointing to the phase
284  * with the correct id.
285  */
286  void initThermoXML(XML_Node& phaseNode, const std::string& id);
287  //! @}
288 
289  //! returns a summary of the state of the phase as a string
290  /*!
291  * @param show_thermo If true, extra information is printed out
292  * about the thermodynamic state of the system.
293  */
294  virtual std::string report(bool show_thermo = true) const;
295 
296 private:
297  //! Initialize lengths of local variables after all species have been identified.
298  void initLengths();
299 
300  //! Process an XML node called "binaryNeutralSpeciesParameters"
301  /*!
302  * This node contains all of the parameters necessary to describe
303  * the Redlich-Kister model for a particular binary interaction.
304  * This function reads the XML file and writes the coefficients
305  * it finds to an internal data structures.
306  *
307  * @param xmlBinarySpecies Reference to the XML_Node named "binaryNeutralSpeciesParameters"
308  * containing the binary interaction
309  */
310  void readXMLBinarySpecies(XML_Node& xmlBinarySpecies);
311 
312  //! Update the activity coefficients
313  /*!
314  * This function will be called to update the internally stored
315  * natural logarithm of the activity coefficients
316  */
317  void s_update_lnActCoeff() const;
318 
319  //! Update the derivative of the log of the activity coefficients wrt T
320  /*!
321  * This function will be called to update the internally stored
322  * derivative of the natural logarithm of the activity coefficients
323  * wrt temperature.
324  */
325  void s_update_dlnActCoeff_dT() const;
326 
327  //! Internal routine that calculates the derivative of the activity coefficients wrt
328  //! the mole fractions.
329  /*!
330  * This routine calculates the the derivative of the activity coefficients wrt to mole fraction
331  * with all other mole fractions held constant. This is strictly not permitted. However, if the
332  * resulting matrix is multiplied by a permissible deltaX vector then everything is ok.
333  *
334  * This is the natural way to handle concentration derivatives in this routine.
335  */
336  void s_update_dlnActCoeff_dX_() const;
337 
338 private:
339  //! Error function
340  /*!
341  * Print an error string and exit
342  *
343  * @param msg Message to be printed
344  */
345  doublereal err(const std::string& msg) const;
346 
347 protected:
348  // Pseudobinary type
349  /*!
350  * - `PBTYPE_PASSTHROUGH` - All species are passthrough species
351  * - `PBTYPE_SINGLEANION` - there is only one anion in the mixture
352  * - `PBTYPE_SINGLECATION` - there is only one cation in the mixture
353  * - `PBTYPE_MULTICATIONANION` - Complex mixture
354  */
355  int PBType_;
356 
357  //! Number of pseudo binary species
359 
360  //! index of special species
362 
363  mutable std::vector<doublereal> PBMoleFractions_;
364 
365  //! Vector of cation indices in the mixture
366  std::vector<size_t> cationList_;
367 
368  //! Number of cations in the mixture
370 
371  std::vector<size_t> anionList_;
372  size_t numAnionSpecies_;
373 
374  std::vector<size_t> passThroughList_;
375  size_t numPassThroughSpecies_;
376  size_t neutralPBindexStart;
377 
378  mutable std::vector<doublereal> moleFractionsTmp_;
379 };
380 
381 #define PBTYPE_PASSTHROUGH 0
382 #define PBTYPE_SINGLEANION 1
383 #define PBTYPE_SINGLECATION 2
384 #define PBTYPE_MULTICATIONANION 3
385 
386 }
387 
388 #endif
size_t numCationSpecies_
Number of cations in the mixture.
virtual void calcPseudoBinaryMoleFractions() const
Calculate pseudo binary mole fractions.
virtual void getPartialMolarCp(doublereal *cpbar) const
Returns an array of partial molar entropies for the species in the mixture.
virtual void getLnActivityCoefficients(doublereal *lnac) const
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
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:100
std::vector< size_t > cationList_
Vector of cation indices in the mixture.
MolarityIonicVPSSTP & operator=(const MolarityIonicVPSSTP &b)
Assignment operator.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
virtual std::string report(bool show_thermo=true) const
returns a summary of the state of the phase as a string
void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
void s_update_dlnActCoeff_dT() const
Update the derivative of the log of the activity coefficients wrt T.
Header for intermediate ThermoPhase object for phases which employ gibbs excess free energy based for...
doublereal err(const std::string &msg) const
Error function.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
void initLengths()
Initialize lengths of local variables after all species have been identified.
virtual int eosType() const
Equation of state type flag.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies for the species in the mixture.
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.
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
size_t indexSpecialSpecies_
index of special species
void s_update_dlnActCoeff_dX_() const
Internal routine that calculates the derivative of the activity coefficients wrt the mole fractions...
void s_update_lnActCoeff() const
Update the activity coefficients.