Cantera  3.0.0
Loading...
Searching...
No Matches
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 *
67 * @deprecated To be removed after %Cantera 3.0.
68 */
70{
71public:
72 //! @name Constructors
73 //! @{
74
75 //! Construct an IonsFromNeutralVPSSTP object from an input file
76 /*!
77 * @param inputFile Name of the input file containing the phase definition.
78 * If blank, an empty phase will be created.
79 * @param id name (ID) of the phase in the input file. If empty, the
80 * first phase definition in the input file will be used.
81 */
82 explicit IonsFromNeutralVPSSTP(const string& inputFile="", const string& id="");
83
84 //! @}
85 //! @name Utilities
86 //! @{
87
88 string type() const override {
89 return "IonsFromNeutral";
90 }
91
92 //! @}
93 //! @name Molar Thermodynamic Properties
94 //! @{
95
96 //! Return the Molar enthalpy. Units: J/kmol.
97 /*!
98 * This is calculated from the partial molar enthalpies of the species.
99 */
100 double enthalpy_mole() const override;
101
102 double entropy_mole() const override;
103 double gibbs_mole() const override;
104 double cp_mole() const override;
105 double cv_mole() const override;
106
107 //! @}
108 //! @name Activities, Standard States, and Activity Concentrations
109 //!
110 //! The activity @f$ a_k @f$ of a species in solution is
111 //! related to the chemical potential by @f[ \mu_k = \mu_k^0(T)
112 //! + \hat R T \ln a_k. @f] The quantity @f$ \mu_k^0(T,P) @f$ is
113 //! the chemical potential at unit activity, which depends only
114 //! on temperature and pressure.
115 //! @{
116
117 void getActivityCoefficients(double* ac) const override;
118
119 //! @}
120 //! @name Partial Molar Properties of the Solution
121 //! @{
122
123 void getChemPotentials(double* mu) const override;
124
125 //! Returns an array of partial molar enthalpies for the species in the
126 //! mixture.
127 /*!
128 * Units (J/kmol)
129 *
130 * For this phase, the partial molar enthalpies are equal to the standard
131 * state enthalpies modified by the derivative of the molality-based
132 * activity coefficient wrt temperature
133 *
134 * @f[
135 * \bar h_k(T,P) = h^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
136 * @f]
137 *
138 * @param hbar Output vector of species partial molar enthalpies.
139 * Length: m_kk. Units: J/kmol
140 */
141 void getPartialMolarEnthalpies(double* hbar) const override;
142
143 //! Returns an array of partial molar entropies for the species in the
144 //! mixture.
145 /*!
146 * Units (J/kmol)
147 *
148 * For this phase, the partial molar enthalpies are equal to the standard
149 * state enthalpies modified by the derivative of the activity coefficient
150 * wrt temperature
151 *
152 * @f[
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 * @f]
157 *
158 * @param sbar Output vector of species partial molar entropies.
159 * Length: m_kk. Units: J/kmol/K
160 */
161 void getPartialMolarEntropies(double* sbar) const override;
162
163 void getdlnActCoeffds(const double dTds, const double* const dXds,
164 double* dlnActCoeffds) const override;
165 void getdlnActCoeffdlnX_diag(double* dlnActCoeffdlnX_diag) const override;
166 void getdlnActCoeffdlnN_diag(double* dlnActCoeffdlnN_diag) const override;
167 void getdlnActCoeffdlnN(const size_t ld, double* const dlnActCoeffdlnN) override;
168 //! @}
169
170 //! Get the Salt Dissociation Coefficients.
171 //! Returns the vector of dissociation coefficients and vector of charges
172 /*!
173 * @param fm_neutralMolec_ions Returns the formula matrix for the
174 * composition of neutral molecules in terms of the ions.
175 * @param charges Returns a vector containing the charges of
176 * all species in this phase
177 * @param neutMolIndex Returns the vector fm_invert_ionForNeutral
178 * This is the mapping between ion species and neutral molecule for
179 * quick invert.
180 */
181 void getDissociationCoeffs(vector<double>& fm_neutralMolec_ions,
182 vector<double>& charges, vector<size_t>& neutMolIndex) const;
183
184 //! Return the current value of the neutral mole fraction vector
185 /*!
186 * @param neutralMoleculeMoleFractions Vector of neutral molecule mole
187 * fractions.
188 */
189 void getNeutralMolecMoleFractions(vector<double>& neutralMoleculeMoleFractions) const {
190 neutralMoleculeMoleFractions = NeutralMolecMoleFractions_;
191 }
192
193 //! Calculate neutral molecule mole fractions
194 /*!
195 * This routine calculates the neutral molecule mole fraction given the
196 * vector of ion mole fractions, that is, the mole fractions from this
197 * ThermoPhase. Note, this routine basically assumes that there is charge
198 * neutrality. If there isn't, then it wouldn't make much sense.
199 *
200 * for the case of cIonSolnType_SINGLEANION, some slough in the charge
201 * neutrality is allowed. The cation number is followed, while the
202 * difference in charge neutrality is dumped into the anion mole number to
203 * fix the imbalance.
204 *
205 * @param dx input vector of ion mole fraction gradients
206 * @param dy output Vector of neutral molecule mole fraction gradients
207 */
208 void getNeutralMoleculeMoleGrads(const double* const dx, double* const dy) const;
209
210 //! Get the list of cations in this object
211 /*!
212 * @param cation List of cations
213 */
214 void getCationList(vector<size_t>& cation) const {
215 cation=cationList_;
216 }
217
218 //! Get the list of anions in this object
219 /*!
220 * @param anion List of anions
221 */
222 void getAnionList(vector<size_t>& anion) const {
223 anion=anionList_;
224 }
225
226 //! @name Setting the State
227 //!
228 //! These methods set all or part of the thermodynamic state.
229 //! @{
230
231 void calcDensity() override;
232
233 //! Calculate ion mole fractions from neutral molecule mole fractions.
234 /*!
235 * @param mf Dump the mole fractions into this vector.
236 */
237 virtual void calcIonMoleFractions(double* const mf) const;
238
239 //! Calculate neutral molecule mole fractions
240 /*!
241 * This routine calculates the neutral molecule mole fraction given the
242 * vector of ion mole fractions, that is, the mole fractions from this
243 * ThermoPhase. Note, this routine basically assumes that there is charge
244 * neutrality. If there isn't, then it wouldn't make much sense.
245 *
246 * for the case of cIonSolnType_SINGLEANION, some slough in the charge
247 * neutrality is allowed. The cation number is followed, while the
248 * difference in charge neutrality is dumped into the anion mole number to
249 * fix the imbalance.
250 */
251 virtual void calcNeutralMoleculeMoleFractions() const;
252
253 //! @}
254
255 bool addSpecies(shared_ptr<Species> spec) override;
256 void setNeutralMoleculePhase(shared_ptr<ThermoPhase> neutral);
257 shared_ptr<ThermoPhase> getNeutralMoleculePhase();
258
259 void setParameters(const AnyMap& phaseNode,
260 const AnyMap& rootNode=AnyMap()) override;
261 void initThermo() override;
262 void getParameters(AnyMap& phaseNode) const override;
263
264private:
265 //! Update the activity coefficients
266 /*!
267 * This function will be called to update the internally stored natural
268 * logarithm of the activity coefficients
269 */
270 void s_update_lnActCoeff() const;
271
272 //! Update the temperature derivative of the ln activity coefficients
273 /*!
274 * This function will be called to update the internally stored temperature
275 * derivative of the natural logarithm of the activity coefficients
276 */
277 void s_update_dlnActCoeffdT() const;
278
279 //! Update the change in the ln activity coefficients
280 /*!
281 * This function will be called to update the internally stored change of
282 * the natural logarithm of the activity coefficients w.r.t a change in
283 * state (temp, mole fraction, etc)
284 */
286
287 //! Update the derivative of the log of the activity coefficients wrt
288 //! log(mole fraction)
289 /*!
290 * This function will be called to update the internally stored
291 * derivative of the natural logarithm of the activity coefficients
292 * wrt logarithm of the mole fractions.
293 */
295
296 //! Update the derivative of the log of the activity coefficients wrt
297 //! log(number of moles) - diagonal components
298 /*!
299 * This function will be called to update the internally stored derivative
300 * of the natural logarithm of the activity coefficients wrt logarithm of
301 * the number of moles of given species.
302 */
304
305 //! Update the derivative of the log of the activity coefficients
306 //! wrt log(number of moles) - diagonal components
307 /*!
308 * This function will be called to update the internally stored derivative
309 * of the natural logarithm of the activity coefficients wrt logarithm of
310 * the number of moles of given species.
311 */
312 void s_update_dlnActCoeff_dlnN() const;
313
314protected:
315 void compositionChanged() override;
316
317 //! Ion solution type
318 /*!
319 * There is either mixing on the anion, cation, or both lattices.
320 * There is also a passthrough option
321 *
322 * Defaults to cIonSolnType_SINGLEANION, so that LiKCl can be hardwired
323 */
324 IonSolnType_enumType ionSolnType_ = cIonSolnType_SINGLEANION;
325
326 //! Number of neutral molecule species
327 /*!
328 * This is equal to the number of species in the neutralMoleculePhase_
329 * ThermoPhase.
330 */
332
333 //! Index of special species
335
336 //! Formula Matrix for composition of neutral molecules
337 //! in terms of the molecules in this ThermoPhase
338 /*!
339 * fm_neutralMolec_ions[ i + jNeut * m_kk ]
340 *
341 * This is the number of ions of type i in the neutral molecule jNeut.
342 */
343 vector<double> fm_neutralMolec_ions_;
344
345 //! Mapping between ion species and neutral molecule for quick invert.
346 /*!
347 * fm_invert_ionForNeutral returns vector of int. Each element represents an
348 * ionic species and stores the value of the corresponding neutral molecule
349 *
350 * For the case of fm_invert_simple_ = true, we assume that there is a quick
351 * way to invert the formula matrix so that we can quickly calculate the
352 * neutral molecule mole fraction given the ion mole fraction vector.
353 *
354 * We assume that for a selected set of ion species, that that ion is only
355 * in the neutral molecule, jNeut.
356 *
357 * therefore,
358 *
359 * NeutralMolecMoleFractions_[jNeut] += moleFractions_[i_ion] / fmij;
360 *
361 * where fmij is the number of ions in neutral molecule jNeut.
362 *
363 * Thus, we formulate the neutral molecule mole fraction
364 * NeutralMolecMoleFractions_[] vector from this association. We further
365 * assume that there are no other associations. If fm_invert_simple_ is not
366 * true, then we need to do a formal inversion which takes a great deal of
367 * time and is not currently implemented.
368 */
370
371 //! Mole fractions using the Neutral Molecule Mole fraction basis
372 mutable vector<double> NeutralMolecMoleFractions_;
373
374 //! List of the species in this ThermoPhase which are cation species
375 vector<size_t> cationList_;
376
377 //! List of the species in this ThermoPhase which are anion species
378 vector<size_t> anionList_;
379
380 //! List of the species in this ThermoPhase which are passed through to the
381 //! neutralMoleculePhase ThermoPhase. These have neutral charges.
382 vector<size_t> passThroughList_;
383
384 //! This is a pointer to the neutral Molecule Phase
385 shared_ptr<ThermoPhase> neutralMoleculePhase_;
386
387 //! Root node of the AnyMap which contains this phase definition.
388 //! Used to look up the phase definition for the embedded neutral phase.
390
391private:
392 GibbsExcessVPSSTP* geThermo;
393 // Temporary vectors that I don't want to allocate every time the function
394 // is called
395 mutable vector<double> y_;
396 mutable vector<double> dlnActCoeff_NeutralMolecule_;
397 mutable vector<double> dX_NeutralMolecule_;
398 mutable vector<double> m_work; // length m_kk
399
400 //! Temporary mole fraction vector
401 mutable vector<double> moleFractionsTmp_;
402
403 //! Storage vector for the neutral molecule chemical potentials
404 /*!
405 * This vector is used as a temporary storage area when calculating the ion
406 * chemical potentials.
407 *
408 * - Units = Joules/kmol
409 * - Length = numNeutralMoleculeSpecies_
410 */
411 mutable vector<double> muNeutralMolecule_;
412
413 //! Storage vector for the neutral molecule ln activity coefficients
414 /*!
415 * This vector is used as a temporary storage area when calculating the ion
416 * chemical potentials and activity coefficients
417 *
418 * - Units = none
419 * - Length = numNeutralMoleculeSpecies_
420 */
421 mutable vector<double> lnActCoeff_NeutralMolecule_;
422
423 //! Storage vector for the neutral molecule d ln activity coefficients dT
424 /*!
425 * This vector is used as a temporary storage area when calculating the ion
426 * derivatives
427 *
428 * - Units = 1/Kelvin
429 * - Length = numNeutralMoleculeSpecies_
430 */
431 mutable vector<double> dlnActCoeffdT_NeutralMolecule_;
432
433 //! Storage vector for the neutral molecule d ln activity coefficients dX -
434 //! diagonal component
435 /*!
436 * This vector is used as a temporary storage area when calculating the ion
437 * derivatives
438 *
439 * - Units = none
440 * - Length = numNeutralMoleculeSpecies_
441 */
443
444 //! Storage vector for the neutral molecule d ln activity coefficients dlnN
445 //! - diagonal component
446 /*!
447 * This vector is used as a temporary storage area when calculating the ion
448 * derivatives
449 *
450 * - Units = none
451 * - Length = numNeutralMoleculeSpecies_
452 */
454
455 //! Storage vector for the neutral molecule d ln activity coefficients dlnN
456 /*!
457 * This vector is used as a temporary storage area when calculating the ion
458 * derivatives
459 *
460 * - Units = none
461 * - Length = numNeutralMoleculeSpecies_
462 */
464};
465
466}
467
468#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:427
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition Array.h:32
GibbsExcessVPSSTP is a derived class of ThermoPhase that handles variable pressure standard state met...
The IonsFromNeutralVPSSTP is a derived class of ThermoPhase that handles the specification of the che...
vector< double > lnActCoeff_NeutralMolecule_
Storage vector for the neutral molecule ln activity coefficients.
vector< size_t > anionList_
List of the species in this ThermoPhase which are anion species.
void getdlnActCoeffds(const double dTds, const double *const dXds, double *dlnActCoeffds) const override
Get the change in activity coefficients wrt changes in state (temp, mole fraction,...
double enthalpy_mole() const override
Return the Molar enthalpy. Units: J/kmol.
AnyMap m_rootNode
Root node of the AnyMap which contains this phase definition.
vector< double > dlnActCoeffdlnX_diag_NeutralMolecule_
Storage vector for the neutral molecule d ln activity coefficients dX - diagonal component.
void getPartialMolarEnthalpies(double *hbar) const override
Returns an array of partial molar enthalpies for the species in the mixture.
void getChemPotentials(double *mu) const override
Get the species chemical potentials. Units: J/kmol.
void getDissociationCoeffs(vector< double > &fm_neutralMolec_ions, vector< double > &charges, vector< size_t > &neutMolIndex) const
Get the Salt Dissociation Coefficients.
virtual void calcNeutralMoleculeMoleFractions() const
Calculate neutral molecule mole fractions.
void getCationList(vector< size_t > &cation) const
Get the list of cations in this object.
virtual void calcIonMoleFractions(double *const mf) const
Calculate ion mole fractions from neutral molecule mole fractions.
vector< size_t > fm_invert_ionForNeutral
Mapping between ion species and neutral molecule for quick invert.
vector< double > muNeutralMolecule_
Storage vector for the neutral molecule chemical potentials.
void s_update_dlnActCoeff_dlnN_diag() const
Update the derivative of the log of the activity coefficients wrt log(number of moles) - diagonal com...
void getParameters(AnyMap &phaseNode) const override
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
string type() const override
String indicating the thermodynamic model implemented.
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
void getNeutralMolecMoleFractions(vector< double > &neutralMoleculeMoleFractions) const
Return the current value of the neutral mole fraction vector.
vector< double > fm_neutralMolec_ions_
Formula Matrix for composition of neutral molecules in terms of the molecules in this ThermoPhase.
size_t indexSpecialSpecies_
Index of special species.
double cv_mole() const override
Molar heat capacity at constant volume. Units: J/kmol/K.
vector< double > dlnActCoeffdlnN_diag_NeutralMolecule_
Storage vector for the neutral molecule d ln activity coefficients dlnN.
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...
void getAnionList(vector< size_t > &anion) const
Get the list of anions in this object.
double entropy_mole() const override
Molar entropy. Units: J/kmol/K.
void calcDensity() override
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
shared_ptr< ThermoPhase > neutralMoleculePhase_
This is a pointer to the neutral Molecule Phase.
vector< double > dlnActCoeffdT_NeutralMolecule_
Storage vector for the neutral molecule d ln activity coefficients dT.
size_t numNeutralMoleculeSpecies_
Number of neutral molecule species.
double cp_mole() const override
Molar heat capacity at constant pressure. Units: J/kmol/K.
void compositionChanged() override
Apply changes to the state which are needed after the composition changes.
vector< double > moleFractionsTmp_
Temporary mole fraction vector.
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.
double gibbs_mole() const override
Molar Gibbs function. Units: J/kmol.
vector< size_t > passThroughList_
List of the species in this ThermoPhase which are passed through to the neutralMoleculePhase ThermoPh...
void getdlnActCoeffdlnX_diag(double *dlnActCoeffdlnX_diag) const override
Get the array of ln mole fraction derivatives of the log activity coefficients - diagonal component o...
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
void getdlnActCoeffdlnN_diag(double *dlnActCoeffdlnN_diag) const override
Get the array of log species mole number derivatives of the log activity coefficients.
void getActivityCoefficients(double *ac) const override
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
void s_update_dlnActCoeffdT() const
Update the temperature derivative of the ln activity coefficients.
void setParameters(const AnyMap &phaseNode, const AnyMap &rootNode=AnyMap()) override
Set equation of state parameters from an AnyMap phase description.
vector< double > NeutralMolecMoleFractions_
Mole fractions using the Neutral Molecule Mole fraction basis.
void getNeutralMoleculeMoleGrads(const double *const dx, double *const dy) const
Calculate neutral molecule mole fractions.
IonSolnType_enumType ionSolnType_
Ion solution type.
void getPartialMolarEntropies(double *sbar) const override
Returns an array of partial molar entropies for the species in the mixture.
void s_update_dlnActCoeff() const
Update the change in the ln activity coefficients.
void getdlnActCoeffdlnN(const size_t ld, double *const dlnActCoeffdlnN) override
Get the array of derivatives of the log activity coefficients with respect to the log of the species ...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:195
IonSolnType_enumType
enums for molten salt ion solution types