Cantera  2.1.2
IonsFromNeutralVPSSTP.h
Go to the documentation of this file.
1 /**
2  * @file IonsFromNeutralVPSSTP.h
3  * Header for intermediate ThermoPhase object for phases which
4  * consist of ions whose thermodynamics is calculated from neutral molecule thermodynamics.
5  * (see \ref thermoprops
6  * and class \link Cantera::IonsFromNeutralVPSSTP IonsFromNeutralVPSSTP\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 molality scale. These include most of the methods for
12  * calculating liquid electrolyte thermodynamics.
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 #ifndef CT_IONSFROMNEUTRALVPSSTP_H
20 #define CT_IONSFROMNEUTRALVPSSTP_H
21 
22 #include "GibbsExcessVPSSTP.h"
23 
24 namespace Cantera
25 {
26 
27 //! enums for molten salt ion solution types
28 /*!
29  * Types identify how complicated the solution is. If there
30  * is just mixing on one of the sublattices but not the other,
31  * then the math is considerably simpler.
32  */
34  cIonSolnType_PASSTHROUGH = 2000 ,
35  cIonSolnType_SINGLEANION ,
36  cIonSolnType_SINGLECATION ,
37  cIonSolnType_MULTICATIONANION
38 };
39 
40 /*!
41  * The IonsFromNeutralVPSSTP is a derived class of ThermoPhase
42  * that handles the specification of the chemical potentials for
43  * ionic species, given a specification of the chemical potentials
44  * for the same phase expressed in terms of combinations of the
45  * ionic species that represent neutral molecules. It's expected
46  * that the neutral molecules will be represented in terms of
47  * an excess gibbs free energy approximation that is a derivative
48  * of the GbbsExcessVPSSTP object. All of the e Excess Gibbs free
49  * energy formulations in this area employ
50  * symmetrical formulations.
51  *
52  * This class is used for molten salts.
53  *
54  * This object actually employs 4 different mole fraction types.
55  *
56  * 1. There is a mole fraction associated the the cations and
57  * anions and neutrals from this ThermoPhase object. This
58  * is the normal mole fraction vector for this object.
59  * Note, however, it isn't the appropriate mole fraction
60  * vector to use even for obtaining the correct ideal
61  * free energies of mixing.
62  * 2. There is a mole fraction vector associated with the
63  * neutral molecule ThermoPhase object.
64  * 3. There is a mole fraction vector associated with the
65  * cation lattice.
66  * 4. There is a mole fraction vector associated with the
67  * anion lattice
68  *
69  * This object can translate between any of the four mole
70  * fraction representations.
71  */
73 {
74 public:
75 
76  //! @name Constructors
77  //! @{
78 
79  /*!
80  * Default constructor
81  */
83 
84  //! Construct and initialize an IonsFromNeutralVPSSTP object
85  //! directly from an ASCII input file
86  /*!
87  * This constructor is a shell around the routine initThermo(), with a
88  * reference to the XML database to get the info for the phase.
89  *
90  * @param inputFile Name of the input file containing the phase XML data
91  * to set up the object
92  * @param id ID of the phase in the input file. Defaults to the
93  * empty string.
94  * @param neutralPhase The object takes a neutralPhase ThermoPhase
95  * object as input. It can either take a pointer
96  * to an existing object in the parameter list,
97  * in which case it does not own the object, or
98  * it can construct a neutral Phase as a slave
99  * object, in which case, it does own the slave
100  * object, for purposes of who gets to destroy
101  * the object.
102  * If this parameter is zero, then a slave
103  * neutral phase object is created and used.
104  */
105  IonsFromNeutralVPSSTP(const std::string& inputFile,
106  const std::string& id = "",
107  ThermoPhase* neutralPhase = 0);
108 
109  //! Construct and initialize an IonsFromNeutralVPSSTP object
110  //! directly from an XML database
111  /*!
112  * @param phaseRoot XML phase node containing the description of the phase
113  * @param id id attribute containing the name of the phase.
114  * (default is the empty string)
115  * @param neutralPhase The object takes a neutralPhase ThermoPhase
116  * object as input. It can either take a pointer
117  * to an existing object in the parameter list,
118  * in which case it does not own the object, or
119  * it can construct a neutral Phase as a slave
120  * object, in which case, it does own the slave
121  * object, for purposes of who gets to destroy
122  * the object.
123  * If this parameter is zero, then a slave
124  * neutral phase object is created and used.
125  */
126  IonsFromNeutralVPSSTP(XML_Node& phaseRoot, const std::string& id = "",
127  ThermoPhase* neutralPhase = 0);
128 
129 
130  //! Copy constructor
131  /*!
132  * @param b class to be copied
133  */
135 
136  /// Assignment operator
137  /*!
138  * @param b class to be copied.
139  */
141 
142  /// Destructor.
143  virtual ~IonsFromNeutralVPSSTP();
144 
145  //! Duplication routine for objects which inherit from ThermoPhase.
146  /*!
147  * This virtual routine can be used to duplicate ThermoPhase objects
148  * inherited from ThermoPhase even if the application only has
149  * a pointer to ThermoPhase to work with.
150  */
151  virtual ThermoPhase* duplMyselfAsThermoPhase() const;
152 
153  // @}
154 
155  /// The following methods are used in the process of constructing
156  /// the phase and setting its parameters from a specification in an
157  /// input file.
158 
159  //! Initialization of an IonsFromNeutralVPSSTP phase using an xml file
160  /*!
161  * This routine is a precursor to initThermo(XML_Node*)
162  * routine, which does most of the work.
163  *
164  * @param inputFile XML file containing the description of the phase
165  *
166  * @param id Optional parameter identifying the name of the
167  * phase. If none is given, the first XML
168  * phase element will be used.
169  */
170  void constructPhaseFile(std::string inputFile, std::string id);
171 
172  //! Import and initialize an IonsFromNeutralVPSSTP phase
173  //! specification in an XML tree into the current object.
174  /*!
175  * Here we read an XML description of the phase.
176  * We import descriptions of the elements that make up the
177  * species in a phase.
178  * We import information about the species, including their
179  * reference state thermodynamic polynomials. We then freeze
180  * the state of the species.
181  *
182  * Then, we read the species molar volumes from the xml
183  * tree to finish the initialization.
184  *
185  * @param phaseNode This object must be the phase node of a complete XML tree
186  * description of the phase, including all of the
187  * species data. In other words while "phase" must
188  * point to an XML phase object, it must have
189  * sibling nodes "speciesData" that describe
190  * the species in the phase.
191  *
192  * @param id ID of the phase. If nonnull, a check is done
193  * to see if phaseNode is pointing to the phase
194  * with the correct id.
195  */
196  void constructPhaseXML(XML_Node& phaseNode, std::string id);
197 
198  //! @name Utilities
199  //! @{
200 
201  //! Equation of state type flag.
202  /*!
203  * The ThermoPhase base class returns
204  * zero. Subclasses should define this to return a unique
205  * non-zero value. Known constants defined for this purpose are
206  * listed in mix_defs.h. The MolalityVPSSTP class also returns
207  * zero, as it is a non-complete class.
208  */
209  virtual int eosType() const;
210 
211  //! @}
212  //! @name Molar Thermodynamic Properties
213  //! @{
214 
215  //! Return the Molar enthalpy. Units: J/kmol.
216  /*!
217  * This is calculated from the partial molar enthalpies of the species.
218  */
219  virtual doublereal enthalpy_mole() const;
220 
221  /**
222  * Molar internal energy. J/kmol.
223  *
224  * This is calculated from the soln enthalpy and then
225  * subtracting pV.
226  */
227  virtual doublereal intEnergy_mole() const;
228 
229  //! Molar entropy. Units: J/kmol/K.
230  virtual doublereal entropy_mole() const;
231 
232  //! Molar Gibbs free Energy for an ideal gas. Units = J/kmol.
233  virtual doublereal gibbs_mole() const;
234 
235  //! Molar heat capacity at constant pressure. Units: J/kmol/K.
236  virtual doublereal cp_mole() const;
237 
238  //! Molar heat capacity at constant volume. Units: J/kmol/K.
239  virtual doublereal cv_mole() const;
240 
241  /**
242  * @}
243  * @name Activities, Standard States, and Activity Concentrations
244  *
245  * The activity \f$a_k\f$ of a species in solution is
246  * related to the chemical potential by \f[ \mu_k = \mu_k^0(T)
247  * + \hat R T \log a_k. \f] The quantity \f$\mu_k^0(T,P)\f$ is
248  * the chemical potential at unit activity, which depends only
249  * on temperature and pressure.
250  * @{
251  */
252 
253  //! Get the array of non-dimensional molar-based activity coefficients at
254  //! the current solution temperature, pressure, and solution concentration.
255  /*!
256  * @param ac Output vector of activity coefficients. Length: m_kk.
257  */
258  virtual void getActivityCoefficients(doublereal* ac) const;
259 
260  //@}
261  /// @name Partial Molar Properties of the Solution
262  //@{
263 
264  //! Get the species chemical potentials. Units: J/kmol.
265  /*!
266  * This function returns a vector of chemical potentials of the
267  * species in solution at the current temperature, pressure
268  * and mole fraction of the solution.
269  *
270  * @param mu Output vector of species chemical
271  * potentials. Length: m_kk. Units: J/kmol
272  */
273  virtual void getChemPotentials(doublereal* mu) const;
274 
275  //! Returns an array of partial molar enthalpies for the species
276  //! in the mixture.
277  /*!
278  * Units (J/kmol)
279  *
280  * For this phase, the partial molar enthalpies are equal to the
281  * standard state enthalpies modified by the derivative of the
282  * molality-based activity coefficient wrt temperature
283  *
284  * \f[
285  * \bar h_k(T,P) = h^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
286  * \f]
287  *
288  * @param hbar Output vector of species partial molar enthalpies.
289  * Length: m_kk. Units: J/kmol
290  */
291  virtual void getPartialMolarEnthalpies(doublereal* hbar) const;
292 
293  //! Returns an array of partial molar entropies for the species
294  //! in the mixture.
295  /*!
296  * Units (J/kmol)
297  *
298  * For this phase, the partial molar enthalpies are equal to the
299  * standard state enthalpies modified by the derivative of the
300  * activity coefficient wrt temperature
301  *
302  * \f[
303  * \bar s_k(T,P) = s^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT}
304  * - R \ln( \gamma_k X_k)
305  * - R T \frac{d \ln(\gamma_k) }{dT}
306  * \f]
307  *
308  *
309  * @param sbar Output vector of species partial molar entropies.
310  * Length: m_kk. Units: J/kmol/K
311  */
312  virtual void getPartialMolarEntropies(doublereal* sbar) const;
313 
314 
315  //! Get the change in activity coefficients w.r.t. change in state (temp, mole fraction, etc.) along
316  //! a line in parameter space or along a line in physical space
317  /*!
318  *
319  * @param dTds Input of temperature change along the path
320  * @param dXds Input vector of changes in mole fraction along the path. length = m_kk
321  * Along the path length it must be the case that the mole fractions sum to one.
322  * @param dlnActCoeffds Output vector of the directional derivatives of the
323  * log Activity Coefficients along the path. length = m_kk
324  */
325  virtual void getdlnActCoeffds(const doublereal dTds, const doublereal* const dXds,
326  doublereal* dlnActCoeffds) const;
327 
328  //! Get the array of log concentration-like derivatives of the
329  //! log activity coefficients - diagonal component
330  /*!
331  * For ideal mixtures (unity activity coefficients), this can return zero.
332  * Implementations should take the derivative of the logarithm of the
333  * activity coefficient with respect to the logarithm of the mole
334  * fraction. This quantity is to be used in conjunction with derivatives
335  * of that concentration-like variable when the derivative of the chemical
336  * potential is taken.
337  *
338  * units = dimensionless
339  *
340  * @param dlnActCoeffdlnX_diag Output vector of log(mole fraction)
341  * derivatives of the log Activity Coefficients.
342  * length = m_kk
343  */
344  virtual void getdlnActCoeffdlnX_diag(doublereal* dlnActCoeffdlnX_diag) const;
345 
346  //! Get the array of log concentration-like derivatives of the
347  //! log activity coefficients - diagonal components
348  /*!
349  * For ideal mixtures (unity activity coefficients), this can return zero.
350  * Implementations should take the derivative of the logarithm of the
351  * activity coefficient with respect to the logarithm of the species mole
352  * numbe. This routine just does the diagonal entries.
353  *
354  * units = dimensionless
355  *
356  * @param dlnActCoeffdlnN_diag Output vector of diagonal components of the log(mole fraction)
357  * derivatives of the log Activity Coefficients.
358  * length = m_kk
359  */
360  virtual void getdlnActCoeffdlnN_diag(doublereal* dlnActCoeffdlnN_diag) const;
361 
362  //! Get the array of derivatives of the ln activity coefficients with respect to the ln species mole numbers
363  /*!
364  * Implementations should take the derivative of the logarithm of the activity coefficient with respect to a
365  * log of a species mole number (with all other species mole numbers held constant)
366  *
367  * units = 1 / kmol
368  *
369  * dlnActCoeffdlnN[ ld * k + m] will contain the derivative of log act_coeff for the <I>m</I><SUP>th</SUP>
370  * species with respect to the number of moles of the <I>k</I><SUP>th</SUP> species.
371  *
372  * \f[
373  * \frac{d \ln(\gamma_m) }{d \ln( n_k ) }\Bigg|_{n_i}
374  * \f]
375  *
376  * @param ld Number of rows in the matrix
377  * @param dlnActCoeffdlnN Output vector of derivatives of the
378  * log Activity Coefficients. length = m_kk * m_kk
379  */
380  virtual void getdlnActCoeffdlnN(const size_t ld, doublereal* const dlnActCoeffdlnN) ;
381  //! @}
382 
383  //! Get the Salt Dissociation Coefficients
384  //! Returns the vector of dissociation coefficients and vector of charges
385  /*!
386  * @param fm_neutralMolec_ions Returns the formula matrix for the composition of neutral molecules
387  * in terms of the ions.
388  * @param charges Returns a vector containing the charges of all species in this phase
389  * @param neutMolIndex Returns the vector fm_invert_ionForNeutral
390  * This is the mapping between ion species and neutral molecule for quick invert.
391  */
392  void getDissociationCoeffs(vector_fp& fm_neutralMolec_ions, vector_fp& charges, std::vector<size_t>& neutMolIndex) const;
393 
394  //! Return the current value of the neutral mole fraction vector
395  /*!
396  * @param neutralMoleculeMoleFractions Vector of neutral molecule mole fractions.
397  */
398  void getNeutralMolecMoleFractions(vector_fp& neutralMoleculeMoleFractions) const {
399  neutralMoleculeMoleFractions = NeutralMolecMoleFractions_;
400  }
401 
402  //! Calculate neutral molecule mole fractions
403  /*!
404  * This routine calculates the neutral molecule mole
405  * fraction given the vector of ion mole fractions,
406  * i.e., the mole fractions from this ThermoPhase.
407  * Note, this routine basically assumes that there
408  * is charge neutrality. If there isn't, then it wouldn't
409  * make much sense.
410  *
411  * for the case of cIonSolnType_SINGLEANION, some slough
412  * in the charge neutrality is allowed. The cation number
413  * is followed, while the difference in charge neutrality
414  * is dumped into the anion mole number to fix the imbalance.
415  *
416  * @param dx input vector of ion mole fraction gradients
417  * @param dy output Vector of neutral molecule mole fraction gradients
418  */
419  void getNeutralMoleculeMoleGrads(const doublereal* const dx, doublereal* const dy) const;
420 
421  //! Get the list of cations in this object
422  /*!
423  * @param cation List of cations
424  */
425  void getCationList(std::vector<size_t>& cation) const {
426  cation=cationList_;
427  }
428 
429  //! Get the list of anions in this object
430  /*!
431  * @param anion List of anions
432  */
433  void getAnionList(std::vector<size_t>& anion) const {
434  anion=anionList_;
435  }
436 
437  /**
438  * @name Setting the State
439  * These methods set all or part of the thermodynamic state.
440  * @{
441  */
442 
443  virtual void setTemperature(const doublereal t);
444  virtual void setPressure(doublereal p);
445 
446  //! Set the temperature (K) and pressure (Pa)
447  /*!
448  * Setting the pressure may involve the solution of a nonlinear equation.
449  *
450  * @param t Temperature (K)
451  * @param p Pressure (Pa)
452  */
453  virtual void setState_TP(doublereal t, doublereal p);
454 
455 
456  //! Calculate ion mole fractions from neutral molecule mole fractions.
457  /*!
458  * @param mf Dump the mole fractions into this vector.
459  */
460  virtual void calcIonMoleFractions(doublereal* const mf) const;
461 
462  //! Calculate neutral molecule mole fractions
463  /*!
464  * This routine calculates the neutral molecule mole
465  * fraction given the vector of ion mole fractions,
466  * i.e., the mole fractions from this ThermoPhase.
467  * Note, this routine basically assumes that there
468  * is charge neutrality. If there isn't, then it wouldn't
469  * make much sense.
470  *
471  * for the case of cIonSolnType_SINGLEANION, some slough
472  * in the charge neutrality is allowed. The cation number
473  * is followed, while the difference in charge neutrality
474  * is dumped into the anion mole number to fix the imbalance.
475  */
476  virtual void calcNeutralMoleculeMoleFractions() const;
477 
478  /**
479  * Set the mass fractions to the specified values, and then
480  * normalize them so that they sum to 1.0.
481  * @param y Array of unnormalized mass fraction values (input).
482  * Must have a length greater than or equal to the number of
483  * species.
484  *
485  * @param y Input vector of mass fractions.
486  * Length is m_kk.
487  */
488  virtual void setMassFractions(const doublereal* const y);
489 
490  /**
491  * Set the mass fractions to the specified values without
492  * normalizing. This is useful when the normalization
493  * condition is being handled by some other means, for example
494  * by a constraint equation as part of a larger set of
495  * equations.
496  *
497  * @param y Input vector of mass fractions.
498  * Length is m_kk.
499  */
500  virtual void setMassFractions_NoNorm(const doublereal* const y);
501 
502  /**
503  * Set the mole fractions to the specified values, and then
504  * normalize them so that they sum to 1.0.
505  * @param x Array of unnormalized mole fraction values (input).
506  * Must have a length greater than or equal to the number of
507  * species.
508  *
509  * @param x Input vector of mole fractions.
510  * Length is m_kk.
511  */
512  virtual void setMoleFractions(const doublereal* const x);
513 
514  /**
515  * Set the mole fractions to the specified values without
516  * normalizing. This is useful when the normalization
517  * condition is being handled by some other means, for example
518  * by a constraint equation as part of a larger set of
519  * equations.
520  *
521  * @param x Input vector of mole fractions.
522  * Length is m_kk.
523  */
524  virtual void setMoleFractions_NoNorm(const doublereal* const x);
525 
526  /**
527  * Set the concentrations to the specified values within the phase.
528  *
529  * @param c The input vector to this routine is in dimensional
530  * units. For volumetric phases c[k] is the
531  * concentration of the kth species in kmol/m3.
532  * For surface phases, c[k] is the concentration
533  * in kmol/m2. The length of the vector is the number
534  * of species in the phase.
535  */
536  virtual void setConcentrations(const doublereal* const c);
537 
538  //@}
539 
540  /*!
541  * @internal Initialize. This method is provided to allow
542  * subclasses to perform any initialization required after all
543  * species have been added. For example, it might be used to
544  * resize internal work arrays that must have an entry for
545  * each species. The base class implementation does nothing,
546  * and subclasses that do not require initialization do not
547  * need to overload this method. When importing a CTML phase
548  * description, this method is called just prior to returning
549  * from function importPhase.
550  *
551  * @see importCTML.cpp
552  */
553  virtual void initThermo();
554 
555  /**
556  * Import and initialize a ThermoPhase object
557  *
558  * @param phaseNode This object must be the phase node of a
559  * complete XML tree
560  * description of the phase, including all of the
561  * species data. In other words while "phase" must
562  * point to an XML phase object, it must have
563  * sibling nodes "speciesData" that describe
564  * the species in the phase.
565  * @param id ID of the phase. If nonnull, a check is done
566  * to see if phaseNode is pointing to the phase
567  * with the correct id.
568  */
569  void initThermoXML(XML_Node& phaseNode, const std::string& id);
570 
571 
572 private:
573  //! Initialize lengths of local variables after all species have
574  //! been identified.
575  void initLengths();
576 
577  //! Update the activity coefficients
578  /*!
579  * This function will be called to update the internally stored
580  * natural logarithm of the activity coefficients
581  */
582  void s_update_lnActCoeff() const;
583 
584  //! Update the temperature derivative of the ln activity coefficients
585  /*!
586  * This function will be called to update the internally stored
587  * temperature derivative of the natural logarithm of the activity coefficients
588  */
589  void s_update_dlnActCoeffdT() const;
590 
591  //! Update the change in the ln activity coefficients
592  /*!
593  * This function will be called to update the internally stored
594  * change of the natural logarithm of the activity coefficients
595  * w.r.t a change in state (temp, mole fraction, etc)
596  */
597  void s_update_dlnActCoeff() const;
598 
599  //! Update the derivative of the log of the activity coefficients
600  //! wrt log(mole fraction)
601  /*!
602  * This function will be called to update the internally stored
603  * derivative of the natural logarithm of the activity coefficients
604  * wrt logarithm of the mole fractions.
605  */
606  void s_update_dlnActCoeff_dlnX_diag() const;
607 
608  //! Update the derivative of the log of the activity coefficients
609  //! wrt log(number of moles) - diagonal components
610  /*!
611  * This function will be called to update the internally stored
612  * derivative of the natural logarithm of the activity coefficients
613  * wrt logarithm of the number of moles of given species.
614  */
615  void s_update_dlnActCoeff_dlnN_diag() const;
616 
617  //! Update the derivative of the log of the activity coefficients
618  //! wrt log(number of moles) - diagonal components
619  /*!
620  * This function will be called to update the internally stored
621  * derivative of the natural logarithm of the activity coefficients
622  * wrt logarithm of the number of moles of given species.
623  */
624  void s_update_dlnActCoeff_dlnN() const;
625 
626 
627 private:
628  //! Error function
629  /*!
630  * Print an error string and exit
631  *
632  * @param msg Message to be printed
633  */
634  doublereal err(const std::string& msg) const;
635 
636 protected:
637 
638  //! Ion solution type
639  /*!
640  * There is either mixing on the anion, cation, or both lattices.
641  * There is also a passthrough option
642  *
643  * Defaults to cIonSolnType_SINGLEANION, so that LiKCl can be hardwired
644  */
646 
647  //! Number of neutral molecule species
648  /*!
649  * This is equal to the number of species in the
650  * neutralMoleculePhase_ ThermoPhase.
651  */
653 
654  //! Index of special species
656 
657  //! Index of special species
659 
660  //! Formula Matrix for composition of neutral molecules
661  //! in terms of the molecules in this ThermoPhase
662  /*!
663  * fm_neutralMolec_ions[ i + jNeut * m_kk ]
664  *
665  * This is the number of ions of type i in the neutral
666  * molecule jNeut.
667  */
668  std::vector<double> fm_neutralMolec_ions_;
669 
670  //! Mapping between ion species and neutral molecule for quick invert.
671  /*!
672  * fm_invert_ionForNeutral returns vector of int. Each element represents
673  * an ionic species and stores the value of the corresponding neutral
674  * molecule
675  *
676  * For the case of fm_invert_simple_ = true, we assume that there
677  * is a quick way to invert the formula matrix so that we can
678  * quickly calculate the neutral molecule mole fraction
679  * given the ion mole fraction vector.
680  *
681  * We assume that for a selected set of ion species, that that
682  * ion is only in the neutral molecule, jNeut.
683  *
684  * therefore,
685  *
686  * NeutralMolecMoleFractions_[jNeut] += moleFractions_[i_ion] / fmij;
687  *
688  * where fmij is the number of ions in neutral molecule jNeut.
689  *
690  * Thus, we formulate the neutral molecule mole fraction NeutralMolecMoleFractions_[]
691  * vector from this association. We further assume that there are
692  * no other associations. If fm_invert_simple_ is not true,
693  * then we need to do a formal inversion which takes a great
694  * deal of time and is not currently implemented.
695  */
696  std::vector<size_t> fm_invert_ionForNeutral;
697 
698  //! Mole fractions using the Neutral Molecule Mole fraction basis
699  mutable std::vector<doublereal> NeutralMolecMoleFractions_;
700 
701  //! List of the species in this ThermoPhase which are cation species
702  std::vector<size_t> cationList_;
703 
704  //! Number of cation species
706 
707  //! List of the species in this ThermoPhase which are anion species
708  std::vector<size_t> anionList_;
709 
710  //! Number of anion species
712 
713  //! List of the species in this ThermoPhase which are passed
714  //! through to the neutralMoleculePhase ThermoPhase.
715  /*!
716  * These have neutral charges.
717  */
718  std::vector<size_t> passThroughList_;
719 
720  //! Number of the species in this ThermoPhase which are passed
721  //! through to the neutralMoleculePhase ThermoPhase
723 
724 public:
725  //! This is a pointer to the neutral Molecule Phase
726  /*!
727  * If the variable, IOwnNThermoPhase_ is true, then we own
728  * the pointer. If not, then this is considered a shallow pointer.
729  */
731 
732 private:
733  GibbsExcessVPSSTP* geThermo;
734  // Temporary vectors that I don't want to allocate every time the function is called
735  mutable vector_fp y_;
736  mutable vector_fp dlnActCoeff_NeutralMolecule_;
737  mutable vector_fp dX_NeutralMolecule_;
738 
739  //! If true then we own the underlying neutral Molecule Phase
740  /*!
741  * If this is false, then the neutral molecule phase is considered
742  * as a shallow pointer.
743  */
745 
746  //! Temporary mole fraction vector
747  mutable std::vector<doublereal> moleFractionsTmp_;
748 
749  //! Storage vector for the neutral molecule chemical potentials
750  /*!
751  * This vector is used as a temporary storage area when calculating the ion chemical
752  * potentials.
753  *
754  * - Units = Joules/kmol
755  * - Length = numNeutralMoleculeSpecies_
756  */
757  mutable std::vector<doublereal> muNeutralMolecule_;
758 
759  //! Storage vector for the neutral molecule ln activity coefficients
760  /*!
761  * This vector is used as a temporary storage area when calculating the ion chemical
762  * potentials and activity coefficients
763  *
764  * - Units = none
765  * - Length = numNeutralMoleculeSpecies_
766  */
767  mutable std::vector<doublereal> lnActCoeff_NeutralMolecule_;
768 
769  //! Storage vector for the neutral molecule d ln activity coefficients dT
770  /*!
771  * This vector is used as a temporary storage area when calculating the ion derivatives
772  *
773  * - Units = 1/Kelvin
774  * - Length = numNeutralMoleculeSpecies_
775  */
776  mutable std::vector<doublereal> dlnActCoeffdT_NeutralMolecule_;
777 
778  //! Storage vector for the neutral molecule d ln activity coefficients dX - diagonal component
779  /*!
780  * This vector is used as a temporary storage area when calculating the ion derivatives
781  *
782  * - Units = none
783  * - Length = numNeutralMoleculeSpecies_
784  */
785  mutable std::vector<doublereal> dlnActCoeffdlnX_diag_NeutralMolecule_;
786 
787  //! Storage vector for the neutral molecule d ln activity coefficients dlnN - diagonal component
788  /*!
789  * This vector is used as a temporary storage area when calculating the ion derivatives
790  *
791  * - Units = none
792  * - Length = numNeutralMoleculeSpecies_
793  */
794  mutable std::vector<doublereal> dlnActCoeffdlnN_diag_NeutralMolecule_;
795 
796  //! Storage vector for the neutral molecule d ln activity coefficients dlnN
797  /*!
798  * This vector is used as a temporary storage area when calculating the ion derivatives
799  *
800  * - Units = none
801  * - Length = numNeutralMoleculeSpecies_
802  */
804 };
805 
806 }
807 
808 #endif
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values, and then normalize them so that they sum to 1...
virtual ~IonsFromNeutralVPSSTP()
Destructor.
void s_update_dlnActCoeff() const
Update the change in the ln activity coefficients.
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
virtual void setConcentrations(const doublereal *const c)
Set the concentrations to the specified values within the phase.
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
void getNeutralMolecMoleFractions(vector_fp &neutralMoleculeMoleFractions) const
Return the current value of the neutral mole fraction vector.
IonsFromNeutralVPSSTP & operator=(const IonsFromNeutralVPSSTP &b)
Assignment operator.
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
std::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.
virtual void calcNeutralMoleculeMoleFractions() const
Calculate neutral molecule mole fractions.
virtual doublereal intEnergy_mole() const
Molar internal energy.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
virtual void calcIonMoleFractions(doublereal *const mf) const
Calculate ion mole fractions from neutral molecule mole fractions.
void constructPhaseFile(std::string inputFile, std::string id)
The following methods are used in the process of constructing the phase and setting its parameters fr...
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 getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
bool IOwnNThermoPhase_
If true then we own the underlying neutral Molecule Phase.
void getDissociationCoeffs(vector_fp &fm_neutralMolec_ions, vector_fp &charges, std::vector< size_t > &neutMolIndex) const
Get the Salt Dissociation Coefficients Returns the vector of dissociation coefficients and vector of ...
void constructPhaseXML(XML_Node &phaseNode, std::string id)
Import and initialize an IonsFromNeutralVPSSTP phase specification in an XML tree into the current ob...
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:33
virtual int eosType() const
Equation of state type flag.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
doublereal err(const std::string &msg) const
Error function.
virtual void getdlnActCoeffdlnN_diag(doublereal *dlnActCoeffdlnN_diag) const
Get the array of log concentration-like derivatives of the log activity coefficients - diagonal compo...
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
virtual doublereal enthalpy_mole() const
Return the Molar enthalpy. Units: J/kmol.
virtual void setTemperature(const doublereal t)
Set the temperature of the phase.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
void getCationList(std::vector< size_t > &cation) const
Get the list of cations in this object.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies for the species in the mixture.
IonSolnType_enumType ionSolnType_
Ion solution type.
virtual void getdlnActCoeffdlnN(const size_t ld, doublereal *const dlnActCoeffdlnN)
Get the array of derivatives of the ln activity coefficients with respect to the ln species mole numb...
Array2D dlnActCoeffdlnN_NeutralMolecule_
Storage vector for the neutral molecule d ln activity coefficients dlnN.
Header for intermediate ThermoPhase object for phases which employ gibbs excess free energy based for...
std::vector< doublereal > dlnActCoeffdT_NeutralMolecule_
Storage vector for the neutral molecule d ln activity coefficients dT.
void initLengths()
Initialize lengths of local variables after all species have been identified.
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values, and then normalize them so that they sum to 1...
std::vector< doublereal > muNeutralMolecule_
Storage vector for the neutral molecule chemical potentials.
void s_update_dlnActCoeffdT() const
Update the temperature derivative of the ln activity coefficients.
void s_update_dlnActCoeff_dlnX_diag() const
Update the derivative of the log of the activity coefficients wrt log(mole fraction) ...
std::vector< size_t > anionList_
List of the species in this ThermoPhase which are anion species.
std::vector< size_t > passThroughList_
List of the species in this ThermoPhase which are passed through to the neutralMoleculePhase ThermoPh...
void s_update_dlnActCoeff_dlnN() const
Update the derivative of the log of the activity coefficients wrt log(number of moles) - diagonal com...
std::vector< doublereal > lnActCoeff_NeutralMolecule_
Storage vector for the neutral molecule ln activity coefficients.
int numCationSpecies_
Number of cation species.
void getNeutralMoleculeMoleGrads(const doublereal *const dx, doublereal *const dy) const
Calculate neutral molecule mole fractions.
size_t numPassThroughSpecies_
Number of the species in this ThermoPhase which are passed through to the neutralMoleculePhase Thermo...
void getAnionList(std::vector< size_t > &anion) const
Get the list of anions in this object.
virtual void getdlnActCoeffdlnX_diag(doublereal *dlnActCoeffdlnX_diag) const
Get the array of log concentration-like derivatives of the log activity coefficients - diagonal compo...
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:165
std::vector< size_t > fm_invert_ionForNeutral
Mapping between ion species and neutral molecule for quick invert.
virtual void setMoleFractions_NoNorm(const doublereal *const x)
Set the mole fractions to the specified values without normalizing.
std::vector< doublereal > dlnActCoeffdlnN_diag_NeutralMolecule_
Storage vector for the neutral molecule d ln activity coefficients dlnN - diagonal component...
std::vector< size_t > cationList_
List of the species in this ThermoPhase which are cation species.
virtual doublereal gibbs_mole() const
Molar Gibbs free Energy for an ideal gas. Units = J/kmol.
void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object.
int numAnionSpecies_
Number of anion species.
std::vector< doublereal > dlnActCoeffdlnX_diag_NeutralMolecule_
Storage vector for the neutral molecule d ln activity coefficients dX - diagonal component.
virtual void getdlnActCoeffds(const doublereal dTds, const doublereal *const dXds, doublereal *dlnActCoeffds) const
Get the change in activity coefficients w.r.t.
std::vector< doublereal > NeutralMolecMoleFractions_
Mole fractions using the Neutral Molecule Mole fraction basis.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void setMassFractions_NoNorm(const doublereal *const y)
Set the mass fractions to the specified values without normalizing.
size_t indexSecondSpecialSpecies_
Index of special species.
size_t numNeutralMoleculeSpecies_
Number of neutral molecule species.
ThermoPhase * neutralMoleculePhase_
This is a pointer to the neutral Molecule Phase.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
void s_update_lnActCoeff() const
Update the activity coefficients.
std::vector< doublereal > moleFractionsTmp_
Temporary mole fraction vector.
IonSolnType_enumType
enums for molten salt ion solution types
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.