Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  /**
113  * @name Activities, Standard States, and Activity Concentrations
114  *
115  * The activity \f$a_k\f$ of a species in solution is
116  * related to the chemical potential by \f[ \mu_k = \mu_k^0(T)
117  * + \hat R T \log a_k. \f] The quantity \f$\mu_k^0(T,P)\f$ is
118  * the chemical potential at unit activity, which depends only
119  * on temperature and pressure.
120  * @{
121  */
122 
123  //! Get the array of non-dimensional molar-based ln activity coefficients at
124  //! the current solution temperature, pressure, and solution concentration.
125  /*!
126  * @param lnac Output vector of ln activity coefficients. Length: m_kk.
127  */
128  virtual void getLnActivityCoefficients(doublereal* lnac) const;
129 
130  //@}
131  /// @name Partial Molar Properties of the Solution
132  //@{
133 
134  //! Get the species chemical potentials. Units: J/kmol.
135  /*!
136  * This function returns a vector of chemical potentials of the
137  * species in solution at the current temperature, pressure
138  * and mole fraction of the solution.
139  *
140  * @param mu Output vector of species chemical
141  * potentials. Length: m_kk. Units: J/kmol
142  */
143  virtual void getChemPotentials(doublereal* mu) const;
144 
145  /**
146  * Get the species electrochemical potentials.
147  * These are partial molar quantities.
148  * This method adds a term \f$ Fz_k \phi_k \f$ to the
149  * to each chemical potential.
150  *
151  * Units: J/kmol
152  *
153  * @param mu output vector containing the species electrochemical potentials.
154  * Length: m_kk.
155  */
156  void getElectrochemPotentials(doublereal* mu) const;
157 
158  //! Returns an array of partial molar enthalpies for the species
159  //! in the mixture.
160  /*!
161  * Units (J/kmol)
162  *
163  * For this phase, the partial molar enthalpies are equal to the
164  * standard state enthalpies modified by the derivative of the
165  * molality-based activity coefficient wrt temperature
166  *
167  * \f[
168  * \bar h_k(T,P) = h^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
169  * \f]
170  *
171  * @param hbar Vector of returned partial molar enthalpies
172  * (length m_kk, units = J/kmol)
173  */
174  virtual void getPartialMolarEnthalpies(doublereal* hbar) const;
175 
176  //! Returns an array of partial molar entropies for the species
177  //! in the mixture.
178  /*!
179  * Units (J/kmol)
180  *
181  * For this phase, the partial molar enthalpies are equal to the
182  * standard state enthalpies modified by the derivative of the
183  * activity coefficient wrt temperature
184  *
185  * \f[
186  * \bar s_k(T,P) = s^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
187  * - R \ln( \gamma_k X_k)
188  * - R T \frac{d \ln(\gamma_k) }{dT}
189  * \f]
190  *
191  * @param sbar Vector of returned partial molar entropies
192  * (length m_kk, units = J/kmol/K)
193  */
194  virtual void getPartialMolarEntropies(doublereal* sbar) const;
195 
196  //! Returns an array of partial molar entropies for the species
197  //! in the mixture.
198  /*!
199  * Units (J/kmol)
200  *
201  * For this phase, the partial molar enthalpies are equal to the
202  * standard state enthalpies modified by the derivative of the
203  * activity coefficient wrt temperature
204  *
205  * \f[
206  * ???????????????
207  * \bar s_k(T,P) = s^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
208  * - R \ln( \gamma_k X_k)
209  * - R T \frac{d \ln(\gamma_k) }{dT}
210  * ???????????????
211  * \f]
212  *
213  * @param cpbar Vector of returned partial molar heat capacities
214  * (length m_kk, units = J/kmol/K)
215  */
216  virtual void getPartialMolarCp(doublereal* cpbar) const;
217 
218  //! Return an array of partial molar volumes for the
219  //! species in the mixture. Units: m^3/kmol.
220  /*!
221  * Frequently, for this class of thermodynamics representations,
222  * the excess Volume due to mixing is zero. Here, we set it as
223  * a default. It may be overridden in derived classes.
224  *
225  * @param vbar Output vector of species partial molar volumes.
226  * Length = m_kk. units are m^3/kmol.
227  */
228  virtual void getPartialMolarVolumes(doublereal* vbar) const;
229 
230  //@}
231 
232  //! Calculate pseudo binary mole fractions
233  virtual void calcPseudoBinaryMoleFractions() const;
234 
235  /// @name Initialization
236  /// The following methods are used in the process of constructing
237  /// the phase and setting its parameters from a specification in an
238  /// input file. They are not normally used in application programs.
239  /// To see how they are used, see importPhase().
240  /// @{
241 
242  /*!
243  * @internal Initialize. This method is provided to allow
244  * subclasses to perform any initialization required after all
245  * species have been added. For example, it might be used to
246  * resize internal work arrays that must have an entry for
247  * each species. The base class implementation does nothing,
248  * and subclasses that do not require initialization do not
249  * need to overload this method. When importing a CTML phase
250  * description, this method is called just prior to returning
251  * from function importPhase().
252  */
253  virtual void initThermo();
254 
255  /**
256  * Import and initialize a ThermoPhase object
257  *
258  * @param phaseNode This object must be the phase node of a
259  * complete XML tree
260  * description of the phase, including all of the
261  * species data. In other words while "phase" must
262  * point to an XML phase object, it must have
263  * sibling nodes "speciesData" that describe
264  * the species in the phase.
265  * @param id ID of the phase. If nonnull, a check is done
266  * to see if phaseNode is pointing to the phase
267  * with the correct id.
268  */
269  void initThermoXML(XML_Node& phaseNode, const std::string& id);
270  //! @}
271 
272  //! returns a summary of the state of the phase as a string
273  /*!
274  * @param show_thermo If true, extra information is printed out
275  * about the thermodynamic state of the system.
276  * @param threshold Show information about species with mole fractions
277  * greater than *threshold*.
278  */
279  virtual std::string report(bool show_thermo=true,
280  doublereal threshold=1e-14) const;
281 
282 private:
283  //! Initialize lengths of local variables after all species have been identified.
284  void initLengths();
285 
286  //! Process an XML node called "binaryNeutralSpeciesParameters"
287  /*!
288  * This node contains all of the parameters necessary to describe
289  * the Redlich-Kister model for a particular binary interaction.
290  * This function reads the XML file and writes the coefficients
291  * it finds to an internal data structures.
292  *
293  * @param xmlBinarySpecies Reference to the XML_Node named "binaryNeutralSpeciesParameters"
294  * containing the binary interaction
295  */
296  void readXMLBinarySpecies(XML_Node& xmlBinarySpecies);
297 
298  //! Update the activity coefficients
299  /*!
300  * This function will be called to update the internally stored
301  * natural logarithm of the activity coefficients
302  */
303  void s_update_lnActCoeff() const;
304 
305  //! Update the derivative of the log of the activity coefficients wrt T
306  /*!
307  * This function will be called to update the internally stored
308  * derivative of the natural logarithm of the activity coefficients
309  * wrt temperature.
310  */
311  void s_update_dlnActCoeff_dT() const;
312 
313  //! Internal routine that calculates the derivative of the activity coefficients wrt
314  //! the mole fractions.
315  /*!
316  * This routine calculates the the derivative of the activity coefficients wrt to mole fraction
317  * with all other mole fractions held constant. This is strictly not permitted. However, if the
318  * resulting matrix is multiplied by a permissible deltaX vector then everything is ok.
319  *
320  * This is the natural way to handle concentration derivatives in this routine.
321  */
322  void s_update_dlnActCoeff_dX_() const;
323 
324 protected:
325  // Pseudobinary type
326  /*!
327  * - `PBTYPE_PASSTHROUGH` - All species are passthrough species
328  * - `PBTYPE_SINGLEANION` - there is only one anion in the mixture
329  * - `PBTYPE_SINGLECATION` - there is only one cation in the mixture
330  * - `PBTYPE_MULTICATIONANION` - Complex mixture
331  */
332  int PBType_;
333 
334  //! Number of pseudo binary species
336 
337  //! index of special species
339 
340  mutable std::vector<doublereal> PBMoleFractions_;
341 
342  //! Vector of cation indices in the mixture
343  std::vector<size_t> cationList_;
344 
345  std::vector<size_t> anionList_;
346 
347  std::vector<size_t> passThroughList_;
348  size_t neutralPBindexStart;
349 
350  mutable std::vector<doublereal> moleFractionsTmp_;
351 };
352 
353 #define PBTYPE_PASSTHROUGH 0
354 #define PBTYPE_SINGLEANION 1
355 #define PBTYPE_SINGLECATION 2
356 #define PBTYPE_MULTICATIONANION 3
357 
358 }
359 
360 #endif
virtual void calcPseudoBinaryMoleFractions() const
Calculate pseudo binary mole fractions.
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 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:97
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...
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 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.