Cantera 2.6.0
IonsFromNeutralVPSSTP.h
Go to the documentation of this file.
1/**
2 * @file IonsFromNeutralVPSSTP.h Header for intermediate ThermoPhase object for
3 * phases which consist of ions whose thermodynamics is calculated from
4 * neutral molecule thermodynamics. (see \ref thermoprops and class \link
5 * Cantera::IonsFromNeutralVPSSTP IonsFromNeutralVPSSTP\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_IONSFROMNEUTRALVPSSTP_H
12#define CT_IONSFROMNEUTRALVPSSTP_H
13
14#include "GibbsExcessVPSSTP.h"
15
16namespace Cantera
17{
18
19//! enums for molten salt ion solution types
20/*!
21 * Types identify how complicated the solution is. If there is just mixing on
22 * one of the sublattices but not the other, then the math is considerably
23 * simpler.
24 */
26 cIonSolnType_PASSTHROUGH = 2000 ,
27 cIonSolnType_SINGLEANION ,
28 cIonSolnType_SINGLECATION ,
29 cIonSolnType_MULTICATIONANION
30};
31
32/*!
33 * The IonsFromNeutralVPSSTP is a derived class of ThermoPhase that handles the
34 * specification of the chemical potentials for ionic species, given a
35 * specification of the chemical potentials for the same phase expressed in
36 * terms of combinations of the ionic species that represent neutral molecules.
37 * It's expected that the neutral molecules will be represented in terms of an
38 * excess Gibbs free energy approximation that is a derivative of the
39 * GibbsExcessVPSSTP object. All of the excess Gibbs free energy formulations in
40 * this area employ symmetrical formulations.
41 *
42 * @attention This class currently does not have any test cases or examples. Its
43 * implementation may be incomplete, and future changes to Cantera may
44 * unexpectedly cause this class to stop working. If you use this class,
45 * please consider contributing examples or test cases. In the absence of
46 * new tests or examples, this class may be deprecated and removed in a
47 * future version of Cantera. See
48 * https://github.com/Cantera/cantera/issues/267 for additional information.
49 *
50 * This class is used for molten salts.
51 *
52 * This object actually employs 4 different mole fraction types.
53 *
54 * 1. There is a mole fraction associated the the cations and anions and
55 * neutrals from this ThermoPhase object. This is the normal mole fraction
56 * vector for this object. Note, however, it isn't the appropriate mole
57 * fraction vector to use even for obtaining the correct ideal free energies
58 * of mixing.
59 * 2. There is a mole fraction vector associated with the neutral molecule
60 * ThermoPhase object.
61 * 3. There is a mole fraction vector associated with the cation lattice.
62 * 4. There is a mole fraction vector associated with the anion lattice
63 *
64 * This object can translate between any of the four mole fraction
65 * representations.
66 */
68{
69public:
70 //! @name Constructors
71 //! @{
72
73 //! Construct an IonsFromNeutralVPSSTP object from an input file
74 /*!
75 * @param inputFile Name of the input file containing the phase definition.
76 * If blank, an empty phase will be created.
77 * @param id name (ID) of the phase in the input file. If empty, the
78 * first phase definition in the input file will be used.
79 */
80 explicit IonsFromNeutralVPSSTP(const std::string& inputFile="",
81 const std::string& id="");
82
83 //! Construct and initialize an IonsFromNeutralVPSSTP object
84 //! directly from an XML database
85 /*!
86 * @param phaseRoot 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 * @deprecated The XML input format is deprecated and will be removed in
91 * Cantera 3.0.
92 */
93 IonsFromNeutralVPSSTP(XML_Node& phaseRoot, const std::string& id = "");
94
95 //! @}
96 //! @name Utilities
97 //! @{
98
99 virtual std::string type() const {
100 return "IonsFromNeutral";
101 }
102
103 //! @}
104 //! @name Molar Thermodynamic Properties
105 //! @{
106
107 //! Return the Molar enthalpy. Units: J/kmol.
108 /*!
109 * This is calculated from the partial molar enthalpies of the species.
110 */
111 virtual doublereal enthalpy_mole() const;
112
113 virtual doublereal entropy_mole() const;
114 virtual doublereal gibbs_mole() const;
115 virtual doublereal cp_mole() const;
116 virtual doublereal cv_mole() const;
117
118 /**
119 * @}
120 * @name Activities, Standard States, and Activity Concentrations
121 *
122 * The activity \f$a_k\f$ of a species in solution is
123 * related to the chemical potential by \f[ \mu_k = \mu_k^0(T)
124 * + \hat R T \log a_k. \f] The quantity \f$\mu_k^0(T,P)\f$ is
125 * the chemical potential at unit activity, which depends only
126 * on temperature and pressure.
127 * @{
128 */
129
130 virtual void getActivityCoefficients(doublereal* ac) const;
131
132 //! @}
133 //! @name Partial Molar Properties of the Solution
134 //! @{
135
136 virtual void getChemPotentials(doublereal* mu) const;
137
138 //! Returns an array of partial molar enthalpies for the species in the
139 //! mixture.
140 /*!
141 * Units (J/kmol)
142 *
143 * For this phase, the partial molar enthalpies are equal to the standard
144 * state enthalpies modified by the derivative of the molality-based
145 * activity coefficient wrt temperature
146 *
147 * \f[
148 * \bar h_k(T,P) = h^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
149 * \f]
150 *
151 * @param hbar Output vector of species partial molar enthalpies.
152 * Length: m_kk. Units: J/kmol
153 */
154 virtual void getPartialMolarEnthalpies(doublereal* hbar) const;
155
156 //! Returns an array of partial molar entropies for the species in the
157 //! mixture.
158 /*!
159 * Units (J/kmol)
160 *
161 * For this phase, the partial molar enthalpies are equal to the standard
162 * state enthalpies modified by the derivative of the activity coefficient
163 * wrt temperature
164 *
165 * \f[
166 * \bar s_k(T,P) = s^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
167 * - R \ln( \gamma_k X_k)
168 * - R T \frac{d \ln(\gamma_k) }{dT}
169 * \f]
170 *
171 * @param sbar Output vector of species partial molar entropies.
172 * Length: m_kk. Units: J/kmol/K
173 */
174 virtual void getPartialMolarEntropies(doublereal* sbar) const;
175
176 virtual void getdlnActCoeffds(const doublereal dTds, const doublereal* const dXds,
177 doublereal* dlnActCoeffds) const;
178 virtual void getdlnActCoeffdlnX_diag(doublereal* dlnActCoeffdlnX_diag) const;
179 virtual void getdlnActCoeffdlnN_diag(doublereal* dlnActCoeffdlnN_diag) const;
180 virtual void getdlnActCoeffdlnN(const size_t ld, doublereal* const dlnActCoeffdlnN);
181 //! @}
182
183 //! Get the Salt Dissociation Coefficients.
184 //! Returns the vector of dissociation coefficients and vector of charges
185 /*!
186 * @param fm_neutralMolec_ions Returns the formula matrix for the
187 * composition of neutral molecules in terms of the ions.
188 * @param charges Returns a vector containing the charges of
189 * all species in this phase
190 * @param neutMolIndex Returns the vector fm_invert_ionForNeutral
191 * This is the mapping between ion species and neutral molecule for
192 * quick invert.
193 */
194 void getDissociationCoeffs(vector_fp& fm_neutralMolec_ions, vector_fp& charges, std::vector<size_t>& neutMolIndex) const;
195
196 //! Return the current value of the neutral mole fraction vector
197 /*!
198 * @param neutralMoleculeMoleFractions Vector of neutral molecule mole
199 * fractions.
200 */
201 void getNeutralMolecMoleFractions(vector_fp& neutralMoleculeMoleFractions) const {
202 neutralMoleculeMoleFractions = NeutralMolecMoleFractions_;
203 }
204
205 //! Calculate neutral molecule mole fractions
206 /*!
207 * This routine calculates the neutral molecule mole fraction given the
208 * vector of ion mole fractions, that is, the mole fractions from this
209 * ThermoPhase. Note, this routine basically assumes that there is charge
210 * neutrality. If there isn't, then it wouldn't make much sense.
211 *
212 * for the case of cIonSolnType_SINGLEANION, some slough in the charge
213 * neutrality is allowed. The cation number is followed, while the
214 * difference in charge neutrality is dumped into the anion mole number to
215 * fix the imbalance.
216 *
217 * @param dx input vector of ion mole fraction gradients
218 * @param dy output Vector of neutral molecule mole fraction gradients
219 */
220 void getNeutralMoleculeMoleGrads(const doublereal* const dx, doublereal* const dy) const;
221
222 //! Get the list of cations in this object
223 /*!
224 * @param cation List of cations
225 */
226 void getCationList(std::vector<size_t>& cation) const {
227 cation=cationList_;
228 }
229
230 //! Get the list of anions in this object
231 /*!
232 * @param anion List of anions
233 */
234 void getAnionList(std::vector<size_t>& anion) const {
235 anion=anionList_;
236 }
237
238 /**
239 * @name Setting the State
240 * These methods set all or part of the thermodynamic state.
241 * @{
242 */
243
244 virtual void calcDensity();
245
246 //! Calculate ion mole fractions from neutral molecule mole fractions.
247 /*!
248 * @param mf Dump the mole fractions into this vector.
249 */
250 virtual void calcIonMoleFractions(doublereal* const mf) const;
251
252 //! Calculate neutral molecule mole fractions
253 /*!
254 * This routine calculates the neutral molecule mole fraction given the
255 * vector of ion mole fractions, that is, the mole fractions from this
256 * ThermoPhase. Note, this routine basically assumes that there is charge
257 * neutrality. If there isn't, then it wouldn't make much sense.
258 *
259 * for the case of cIonSolnType_SINGLEANION, some slough in the charge
260 * neutrality is allowed. The cation number is followed, while the
261 * difference in charge neutrality is dumped into the anion mole number to
262 * fix the imbalance.
263 */
264 virtual void calcNeutralMoleculeMoleFractions() const;
265
266 //! @}
267
268 virtual bool addSpecies(shared_ptr<Species> spec);
269 void setNeutralMoleculePhase(shared_ptr<ThermoPhase> neutral);
270 shared_ptr<ThermoPhase> getNeutralMoleculePhase();
271
272 virtual void setParameters(const AnyMap& phaseNode,
273 const AnyMap& rootNode=AnyMap());
274 virtual void initThermo();
275 virtual void getParameters(AnyMap& phaseNode) const;
276 virtual void setParametersFromXML(const XML_Node& thermoNode);
277
278private:
279 //! Update the activity coefficients
280 /*!
281 * This function will be called to update the internally stored natural
282 * logarithm of the activity coefficients
283 */
284 void s_update_lnActCoeff() const;
285
286 //! Update the temperature derivative of the ln activity coefficients
287 /*!
288 * This function will be called to update the internally stored temperature
289 * derivative of the natural logarithm of the activity coefficients
290 */
291 void s_update_dlnActCoeffdT() const;
292
293 //! Update the change in the ln activity coefficients
294 /*!
295 * This function will be called to update the internally stored change of
296 * the natural logarithm of the activity coefficients w.r.t a change in
297 * state (temp, mole fraction, etc)
298 */
300
301 //! Update the derivative of the log of the activity coefficients wrt
302 //! log(mole fraction)
303 /*!
304 * This function will be called to update the internally stored
305 * derivative of the natural logarithm of the activity coefficients
306 * wrt logarithm of the mole fractions.
307 */
309
310 //! Update the derivative of the log of the activity coefficients wrt
311 //! log(number of moles) - diagonal components
312 /*!
313 * This function will be called to update the internally stored derivative
314 * of the natural logarithm of the activity coefficients wrt logarithm of
315 * the number of moles of given species.
316 */
318
319 //! Update the derivative of the log of the activity coefficients
320 //! wrt log(number of moles) - diagonal components
321 /*!
322 * This function will be called to update the internally stored derivative
323 * of the natural logarithm of the activity coefficients wrt logarithm of
324 * the number of moles of given species.
325 */
326 void s_update_dlnActCoeff_dlnN() const;
327
328protected:
329 virtual void compositionChanged();
330
331 //! Ion solution type
332 /*!
333 * There is either mixing on the anion, cation, or both lattices.
334 * There is also a passthrough option
335 *
336 * Defaults to cIonSolnType_SINGLEANION, so that LiKCl can be hardwired
337 */
339
340 //! Number of neutral molecule species
341 /*!
342 * This is equal to the number of species in the neutralMoleculePhase_
343 * ThermoPhase.
344 */
346
347 //! Index of special species
349
350 //! Formula Matrix for composition of neutral molecules
351 //! in terms of the molecules in this ThermoPhase
352 /*!
353 * fm_neutralMolec_ions[ i + jNeut * m_kk ]
354 *
355 * This is the number of ions of type i in the neutral molecule jNeut.
356 */
358
359 //! Mapping between ion species and neutral molecule for quick invert.
360 /*!
361 * fm_invert_ionForNeutral returns vector of int. Each element represents an
362 * ionic species and stores the value of the corresponding neutral molecule
363 *
364 * For the case of fm_invert_simple_ = true, we assume that there is a quick
365 * way to invert the formula matrix so that we can quickly calculate the
366 * neutral molecule mole fraction given the ion mole fraction vector.
367 *
368 * We assume that for a selected set of ion species, that that ion is only
369 * in the neutral molecule, jNeut.
370 *
371 * therefore,
372 *
373 * NeutralMolecMoleFractions_[jNeut] += moleFractions_[i_ion] / fmij;
374 *
375 * where fmij is the number of ions in neutral molecule jNeut.
376 *
377 * Thus, we formulate the neutral molecule mole fraction
378 * NeutralMolecMoleFractions_[] vector from this association. We further
379 * assume that there are no other associations. If fm_invert_simple_ is not
380 * true, then we need to do a formal inversion which takes a great deal of
381 * time and is not currently implemented.
382 */
383 std::vector<size_t> fm_invert_ionForNeutral;
384
385 //! Mole fractions using the Neutral Molecule Mole fraction basis
387
388 //! List of the species in this ThermoPhase which are cation species
389 std::vector<size_t> cationList_;
390
391 //! List of the species in this ThermoPhase which are anion species
392 std::vector<size_t> anionList_;
393
394 //! List of the species in this ThermoPhase which are passed through to the
395 //! neutralMoleculePhase ThermoPhase. These have neutral charges.
396 std::vector<size_t> passThroughList_;
397
398 //! This is a pointer to the neutral Molecule Phase
399 shared_ptr<ThermoPhase> neutralMoleculePhase_;
400
401 //! Root node of the AnyMap which contains this phase definition.
402 //! Used to look up the phase definition for the embedded neutral phase.
404
405private:
406 GibbsExcessVPSSTP* geThermo;
407 // Temporary vectors that I don't want to allocate every time the function
408 // is called
409 mutable vector_fp y_;
410 mutable vector_fp dlnActCoeff_NeutralMolecule_;
411 mutable vector_fp dX_NeutralMolecule_;
412 mutable vector_fp m_work; // length m_kk
413
414 //! Temporary mole fraction vector
416
417 //! Storage vector for the neutral molecule chemical potentials
418 /*!
419 * This vector is used as a temporary storage area when calculating the ion
420 * chemical potentials.
421 *
422 * - Units = Joules/kmol
423 * - Length = numNeutralMoleculeSpecies_
424 */
426
427 //! Storage vector for the neutral molecule ln activity coefficients
428 /*!
429 * This vector is used as a temporary storage area when calculating the ion
430 * chemical potentials and activity coefficients
431 *
432 * - Units = none
433 * - Length = numNeutralMoleculeSpecies_
434 */
436
437 //! Storage vector for the neutral molecule d ln activity coefficients dT
438 /*!
439 * This vector is used as a temporary storage area when calculating the ion
440 * derivatives
441 *
442 * - Units = 1/Kelvin
443 * - Length = numNeutralMoleculeSpecies_
444 */
446
447 //! Storage vector for the neutral molecule d ln activity coefficients dX -
448 //! diagonal component
449 /*!
450 * This vector is used as a temporary storage area when calculating the ion
451 * derivatives
452 *
453 * - Units = none
454 * - Length = numNeutralMoleculeSpecies_
455 */
457
458 //! Storage vector for the neutral molecule d ln activity coefficients dlnN
459 //! - diagonal component
460 /*!
461 * This vector is used as a temporary storage area when calculating the ion
462 * derivatives
463 *
464 * - Units = none
465 * - Length = numNeutralMoleculeSpecies_
466 */
468
469 //! Storage vector for the neutral molecule d ln activity coefficients dlnN
470 /*!
471 * This vector is used as a temporary storage area when calculating the ion
472 * derivatives
473 *
474 * - Units = none
475 * - Length = numNeutralMoleculeSpecies_
476 */
478};
479
480}
481
482#endif
Header for intermediate ThermoPhase object for phases which employ Gibbs excess free energy based for...
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:30
AnyMap m_rootNode
Root node of the AnyMap which contains this phase definition.
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void setParameters(const AnyMap &phaseNode, const AnyMap &rootNode=AnyMap())
Set equation of state parameters from an AnyMap phase description.
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
vector_fp dlnActCoeffdT_NeutralMolecule_
Storage vector for the neutral molecule d ln activity coefficients dT.
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
void getAnionList(std::vector< size_t > &anion) const
Get the list of anions in this object.
vector_fp lnActCoeff_NeutralMolecule_
Storage vector for the neutral molecule ln activity coefficients.
virtual void calcNeutralMoleculeMoleFractions() const
Calculate neutral molecule mole fractions.
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
void getNeutralMoleculeMoleGrads(const doublereal *const dx, doublereal *const dy) const
Calculate neutral molecule mole fractions.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies for the species in the mixture.
vector_fp moleFractionsTmp_
Temporary mole fraction vector.
std::vector< size_t > passThroughList_
List of the species in this ThermoPhase which are passed through to the neutralMoleculePhase ThermoPh...
virtual doublereal enthalpy_mole() const
Return the Molar enthalpy. Units: J/kmol.
void s_update_dlnActCoeff_dlnN_diag() const
Update the derivative of the log of the activity coefficients wrt log(number of moles) - diagonal com...
virtual void getdlnActCoeffdlnN(const size_t ld, doublereal *const dlnActCoeffdlnN)
Get the array of derivatives of the log activity coefficients with respect to the log of the species ...
vector_fp muNeutralMolecule_
Storage vector for the neutral molecule chemical potentials.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
virtual void getdlnActCoeffdlnX_diag(doublereal *dlnActCoeffdlnX_diag) const
Get the array of ln mole fraction derivatives of the log activity coefficients - diagonal component o...
IonsFromNeutralVPSSTP(const std::string &inputFile="", const std::string &id="")
Construct an IonsFromNeutralVPSSTP object from an input file.
virtual void calcIonMoleFractions(doublereal *const mf) const
Calculate ion mole fractions from neutral molecule mole fractions.
size_t indexSpecialSpecies_
Index of special species.
vector_fp NeutralMolecMoleFractions_
Mole fractions using the Neutral Molecule Mole fraction basis.
vector_fp fm_neutralMolec_ions_
Formula Matrix for composition of neutral molecules in terms of the molecules in this ThermoPhase.
void getDissociationCoeffs(vector_fp &fm_neutralMolec_ions, vector_fp &charges, std::vector< size_t > &neutMolIndex) const
Get the Salt Dissociation Coefficients.
vector_fp dlnActCoeffdlnN_diag_NeutralMolecule_
Storage vector for the neutral molecule d ln activity coefficients dlnN.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
std::vector< size_t > cationList_
List of the species in this ThermoPhase which are cation species.
Array2D dlnActCoeffdlnN_NeutralMolecule_
Storage vector for the neutral molecule d ln activity coefficients dlnN.
void s_update_dlnActCoeff_dlnN() const
Update the derivative of the log of the activity coefficients wrt log(number of moles) - diagonal com...
shared_ptr< ThermoPhase > neutralMoleculePhase_
This is a pointer to the neutral Molecule Phase.
virtual std::string type() const
String indicating the thermodynamic model implemented.
size_t numNeutralMoleculeSpecies_
Number of neutral molecule species.
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
std::vector< size_t > fm_invert_ionForNeutral
Mapping between ion species and neutral molecule for quick invert.
vector_fp dlnActCoeffdlnX_diag_NeutralMolecule_
Storage vector for the neutral molecule d ln activity coefficients dX - diagonal component.
virtual void getdlnActCoeffdlnN_diag(doublereal *dlnActCoeffdlnN_diag) const
Get the array of log species mole number derivatives of the log activity coefficients.
void getCationList(std::vector< size_t > &cation) const
Get the list of cations in this object.
virtual void getdlnActCoeffds(const doublereal dTds, const doublereal *const dXds, doublereal *dlnActCoeffds) const
Get the change in activity coefficients wrt changes in state (temp, mole fraction,...
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
void s_update_dlnActCoeff_dlnX_diag() const
Update the derivative of the log of the activity coefficients wrt log(mole fraction)
void s_update_lnActCoeff() const
Update the activity coefficients.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
void s_update_dlnActCoeffdT() const
Update the temperature derivative of the ln activity coefficients.
IonSolnType_enumType ionSolnType_
Ion solution type.
void s_update_dlnActCoeff() const
Update the change in the ln activity coefficients.
virtual void setParametersFromXML(const XML_Node &thermoNode)
Set equation of state parameter values from XML entries.
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
void getNeutralMolecMoleFractions(vector_fp &neutralMoleculeMoleFractions) const
Return the current value of the neutral mole fraction vector.
std::vector< size_t > anionList_
List of the species in this ThermoPhase which are anion species.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
IonSolnType_enumType
enums for molten salt ion solution types
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:184