1 /**
2  * @file vcs_VolPhase.h
3  *   Header for the object representing each phase within vcs
4  */
5 
6 // This file is part of Cantera. See License.txt in the top-level directory or
7 // at https://cantera.org/license.txt for license and copyright information.
8 
9 #ifndef VCS_VOLPHASE_H
10 #define VCS_VOLPHASE_H
11 
12 #include "cantera/equil/vcs_SpeciesProperties.h"
13 #include "cantera/base/Array.h"
14 
15 namespace Cantera
16 {
17 
18 class ThermoPhase;
19 
20 /*
21  * DEFINITIONS FOR THE vcs_VolPhase structure
22  *
23  * Equation of State Types
24  * - Permissible values for the EqnState variable in CPC_PHASE structure
25  */
26 #define VCS_EOS_CONSTANT 0
27 #define VCS_EOS_IDEAL_GAS 1
28 #define VCS_EOS_STOICH_SUB 5
29 #define VCS_EOS_IDEAL_SOLN 22
30 #define VCS_EOS_DEBEYE_HUCKEL 23
31 #define VCS_EOS_REDLICH_KWONG 24
32 #define VCS_EOS_REGULAR_SOLN 25
33 #define VCS_EOS_UNK_CANTERA -1
34 
35 struct VCS_SPECIES;
36 class vcs_SpeciesProperties;
37 class VCS_SOLVE;
38 
39 //!  Phase information and Phase calculations for vcs.
40 /*!
41  * Each phase in a vcs calculation has a vcs_VolPhase object associated with it.
42  * This object helps to coordinate property evaluations for species within the
43  * phase. Usually these evaluations must be carried out on a per phase basis.
44  * However, vcs frequently needs per species quantities. Therefore, we need an
45  * interface layer between vcs and Cantera's ThermoPhase.
46  *
47  * The species stay in the same ordering within this structure. The vcs
48  * algorithm will change the ordering of species in the global species list.
49  * However, the indexing of species in this list stays the same. This structure
50  * contains structures that point to the species belonging to this phase in the
51  * global vcs species list.
52  *
53  * This object is considered not to own the underlying Cantera ThermoPhase
54  * object for the phase.
55  *
56  * This object contains an idea of the temperature and pressure. It checks to
57  * see if if the temperature and pressure has changed before calling underlying
58  * property evaluation routines.
59  *
60  * The object contains values for the electric potential of a phase. It
61  * coordinates the evaluation of properties wrt when the electric potential of a
62  * phase has changed.
63  *
64  * The object knows about the mole fractions of the phase. It controls the
65  * values of mole fractions, and coordinates the property evaluation wrt to
66  * changes in the mole fractions. It also will keep track of the likely values
67  * of mole fractions in multicomponent phases even when the phase doesn't
68  * actually exist within the thermo program.
69  *
70  * The object knows about the total moles of a phase. It checks to see if the
71  * phase currently exists or not, and modifies its behavior accordingly.
72  *
73  * Activity coefficients and volume calculations are lagged. They are only
74  * called when they are needed (and when the state has changed so that they need
75  * to be recalculated).
76  */
77 class vcs_VolPhase
78 {
79 public:
80     vcs_VolPhase(VCS_SOLVE* owningSolverObject = 0);
81 
82     vcs_VolPhase(const vcs_VolPhase& b) = delete;
83     vcs_VolPhase& operator=(const vcs_VolPhase& b) = delete;
84     ~vcs_VolPhase();
85 
86     //! The resize() function fills in all of the initial information if it
87     //! is not given in the constructor.
88     /*!
89      * @param phaseNum    index of the phase in the vcs problem
90      * @param numSpecies  Number of species in the phase
91      * @param phaseName   String name for the phase
92      * @param molesInert  kmoles of inert in the phase (defaults to zero)
93      */
94     void resize(const size_t phaseNum, const size_t numSpecies,
95                 const size_t numElem, const char* const phaseName,
96                 const double molesInert = 0.0);
97 
98     void elemResize(const size_t numElemConstraints);
99 
100     //! Set the moles and/or mole fractions within the phase
101     /*!
102      * @param molNum           total moles in the phase
103      * @param moleFracVec      Vector of input mole fractions
104      * @param vcsStateStatus   Status flag for this update
105      */
106     void setMoleFractionsState(const double molNum, const double* const moleFracVec,
107                                const int vcsStateStatus);
108 
109     //! Set the moles within the phase
110     /*!
111      * This function takes as input the mole numbers in vcs format, and then
112      * updates this object with their values. This is essentially a gather
113      * routine.
114      *
115      * @param molesSpeciesVCS  Array of mole numbers. Note, the indices for
116      *     species in this array may not be contiguous. IndSpecies[] is needed
117      *     to gather the species into the local contiguous vector format.
118      */
119     void setMolesFromVCS(const int stateCalc,
120                          const double* molesSpeciesVCS = 0);
121 
122     //! Set the moles within the phase
123     /*!
124      * This function takes as input the mole numbers in vcs format, and then
125      * updates this object with their values. This is essentially a gather
126      * routine.
127      *
128      * Additionally it checks to see that the total moles value in
129      * TPhMoles[iplace] is equal to the internally computed value. If this isn't
130      * the case, an error exit is carried out.
131      *
132      * @param vcsStateStatus  State calc value either `VCS_STATECALC_OLD` or
133      *     `VCS_STATECALC_NEW`. With any other value nothing is done.
134      * @param molesSpeciesVCS  array of mole numbers. Note, the indices for
135      *     species in this array may not be contiguous. IndSpecies[] is needed
136      *     to gather the species into the local contiguous vector format.
137      * @param TPhMoles  VCS's array containing the number of moles in each phase.
138      */
139     void setMolesFromVCSCheck(const int vcsStateStatus,
140                               const double* molesSpeciesVCS,
141                               const double* const TPhMoles);
142 
143     //! Update the moles within the phase, if necessary
144     /*!
145      * This function takes as input the stateCalc value, which determines where
146      * within VCS_SOLVE to fetch the mole numbers. It then updates this object
147      * with their values. This is essentially a gather routine.
148      *
149      * @param stateCalc  State calc value either VCS_STATECALC_OLD or
150      *     VCS_STATECALC_NEW. With any other value nothing is done.
151      */
152     void updateFromVCS_MoleNumbers(const int stateCalc);
153 
154     //! Fill in an activity coefficients vector within a VCS_SOLVE object
155     /*!
156      * This routine will calculate the activity coefficients for the current
157      * phase, and fill in the corresponding entries in the VCS activity
158      * coefficients vector.
159      *
160      * @param AC  vector of activity coefficients for all of the species in all
161      *     of the phases in a VCS problem. Only the entries for the current
162      *     phase are filled in.
163      */
164     void sendToVCS_ActCoeff(const int stateCalc, double* const AC);
165 
166     //! set the electric potential of the phase
167     /*!
168      * @param phi electric potential (volts)
169      */
170     void setElectricPotential(const double phi);
171 
172     //! Returns the electric field of the phase
173     /*!
174      *  Units are potential
175      */
176     double electricPotential() const;
177 
178     //! Gibbs free energy calculation for standard state of one species
179     /*!
180      * Calculate the Gibbs free energies for the standard state of the kth
181      * species. The results are held internally within the object.
182      *
183      * @param kspec   Species number (within the phase)
184      * @returns the Gibbs free energy for the standard state of the kth species.
185      */
186     double GStar_calc_one(size_t kspec) const;
187 
188     //! Gibbs free energy calculation at a temperature for the reference state
189     //! of a species, return a value for one species
190     /*!
191      *  @param kspec   species index
192      *  @returns       value of the Gibbs free energy
193      */
194     double G0_calc_one(size_t kspec) const;
195 
196     //! Molar volume calculation for standard state of one species
197     /*!
198      * Calculate the molar volume for the standard states. The results are held
199      * internally within the object.
200      *
201      * @param kspec Species number (within the phase)
202      * @return molar volume of the kspec species's standard state (m**3/kmol)
203      */
204     double VolStar_calc_one(size_t kspec) const;
205 
206     //! Fill in the partial molar volume vector for VCS
207     /*!
208      * This routine will calculate the partial molar volumes for the current
209      * phase (if needed), and fill in the corresponding entries in the VCS
210      * partial molar volumes vector.
211      *
212      * @param VolPM  vector of partial molar volumes for all of the species in
213      *     all of the phases in a VCS problem. Only the entries for the current
214      *     phase are filled in.
215      */
216     double sendToVCS_VolPM(double* const VolPM) const;
217 
218     //! Fill in the partial molar volume vector for VCS
219     /*!
220      * This routine will calculate the partial molar volumes for the
221      * current phase (if needed), and fill in the corresponding entries in the
222      * VCS partial molar volumes vector.
223      *
224      * @param VolPM  vector of partial molar volumes for all of the species in
225      *     all of the phases in a VCS problem. Only the entries for the current
226      *     phase are filled in.
227      *
228      * @todo This function's documentation is incorrect.
229      */
230     void sendToVCS_GStar(double* const gstar) const;
231 
232     //! Sets the temperature and pressure in this object and underlying
233     //! ThermoPhase objects
234     /*!
235      * @param temperature_Kelvin    (Kelvin)
236      * @param pressure_PA  Pressure (MKS units - Pascal)
237      */
238     void setState_TP(const double temperature_Kelvin, const double pressure_PA);
239 
240     //! Sets the temperature in this object and underlying ThermoPhase objects
241     /*!
242      * @param temperature_Kelvin    (Kelvin)
243      */
244     void setState_T(const double temperature_Kelvin);
245 
246     // Downloads the ln ActCoeff Jacobian into the VCS version of the
247     // ln ActCoeff Jacobian.
248     /*
249      * This is essentially a scatter operation.
250      *
251      * @param LnAcJac_VCS Jacobian parameter
252      *     The Jacobians are actually d( lnActCoeff) / d (MolNumber);
253      *     dLnActCoeffdMolNumber(k,j)
254      *
255      *      j = id of the species mole number
256      *      k = id of the species activity coefficient
257      */
258     void sendToVCS_LnActCoeffJac(Array2D& LnACJac_VCS);
259 
260     //! Set the pointer for Cantera's ThermoPhase parameter
261     /*!
262      * When we first initialize the ThermoPhase object, we read the state of the
263      * ThermoPhase into vcs_VolPhase object.
264      *
265      * @param tp_ptr Pointer to the ThermoPhase object corresponding
266      *               to this phase.
267      */
268     void setPtrThermoPhase(ThermoPhase* tp_ptr);
269 
270     //! Return a const ThermoPhase pointer corresponding to this phase
271     /*!
272      *  @return pointer to the ThermoPhase.
273      */
274     const ThermoPhase* ptrThermoPhase() const;
275 
276     //! Return the total moles in the phase
277     double totalMoles() const;
278 
279     //! Returns the mole fraction of the kspec species
280     /*!
281      * @param kspec    Index of the species in the phase
282      *
283      * @return  Value of the mole fraction
284      */
285     double molefraction(size_t kspec) const;
286 
287     //! Sets the total moles in the phase
288     /*!
289      * We don't have to flag the internal state as changing here because we have
290      * just changed the total moles.
291      *
292      * @param totalMols   Total moles in the phase (kmol)
293      */
294     void setTotalMoles(const double totalMols);
295 
296     //! Sets the mole flag within the object to out of date
297     /*!
298      * This will trigger the object to go get the current mole numbers when it
299      * needs it.
300      */
301     void setMolesOutOfDate(int stateCalc = -1);
302 
303     //! Sets the mole flag within the object to be current
304     void setMolesCurrent(int vcsStateStatus);
305 
306 private:
307     //! Set the mole fractions from a conventional mole fraction vector
308     /*!
309      * @param xmol Value of the mole fractions for the species in the phase.
310      *             These are contiguous.
311      */
312     void setMoleFractions(const double* const xmol);
313 
314 public:
315     //! Return a const reference to the mole fractions stored in the object.
316     const vector_fp & moleFractions() const;
317 
318     double moleFraction(size_t klocal) const;
319 
320     //! Sets the creationMoleNum's within the phase object
321     /*!
322      * @param F_k Pointer to a vector of n_k's
323      */
324     void setCreationMoleNumbers(const double* const n_k, const std::vector<size_t> &creationGlobalRxnNumbers);
325 
326     //! Return a const reference to the creationMoleNumbers stored in the object.
327     /*!
328      * @returns a const reference to the vector of creationMoleNumbers
329      */
330     const vector_fp & creationMoleNumbers(std::vector<size_t> &creationGlobalRxnNumbers) const;
331 
332     //! Returns whether the phase is an ideal solution phase
333     bool isIdealSoln() const;
334 
335     //! Return the index of the species that represents the the voltage of the
336     //! phase
337     size_t phiVarIndex() const;
338 
339     void setPhiVarIndex(size_t phiVarIndex);
340 
341     //! Retrieve the kth Species structure for the species belonging to this
342     //! phase
343     /*!
344      * The index into this vector is the species index within the phase.
345      *
346      * @param kindex kth species index.
347      */
348     vcs_SpeciesProperties* speciesProperty(const size_t kindex);
349 
350     //! int indicating whether the phase exists or not
351     /*!
352      * returns the m_existence int for the phase
353      *
354      * - VCS_PHASE_EXIST_ZEROEDPHASE = -6: Set to not exist by fiat from a
355      *   higher level. This is used in phase stability boundary calculations
356      * - VCS_PHASE_EXIST_NO = 0:   Doesn't exist currently
357      * - VCS_PHASE_EXIST_MINORCONC = 1:  Exists, but the concentration is so low
358      *   that an alternate method is used to calculate the total phase
359      *   concentrations.
360      * - VCS_PHASE_EXIST_YES = 2 : Does exist currently
361      * - VCS_PHASE_EXIST_ALWAYS = 3: Always exists because it contains inerts
362      *   which can't exist in any other phase. Or, the phase exists always
363      *   because it consists of a single species, which is identified with the
364      *   voltage, i.e., it's an electron metal phase.
365      */
366     int exists() const;
367 
368     //! Set the existence flag in the object
369     /*!
370      * Note the total moles of the phase must have been set appropriately before
371      * calling this routine.
372      *
373      * @param existence Phase existence flag
374      *
375      * @note try to eliminate this routine
376      */
377     void setExistence(const int existence);
378 
379     //! Return the Global VCS index of the kth species in the phase
380     /*!
381      * @param spIndex local species index (0 to the number of species in the
382      *                phase)
383      *
384      * @returns the VCS_SOLVE species index of the species. This changes as
385      *         rearrangements are carried out.
386      */
387     size_t spGlobalIndexVCS(const size_t spIndex) const;
388 
389 
390     //! set the Global VCS index of the kth species in the phase
391     /*!
392      * @param spIndex local species index (0 to the number of species
393      *                in the phase)
394      *
395      * @returns the VCS_SOLVE species index of the that species This changes as
396      *         rearrangements are carried out.
397      */
398     void setSpGlobalIndexVCS(const size_t spIndex, const size_t spGlobalIndex);
399 
400     //! Sets the total moles of inert in the phase
401     /*!
402      * @param tMolesInert Value of the total kmols of inert species in the
403      *     phase.
404      */
405     void setTotalMolesInert(const double tMolesInert);
406 
407     //! Returns the value of the total kmol of inert in the phase
408     double totalMolesInert() const;
409 
410     //! Returns the global index of the local element index for the phase
411     size_t elemGlobalIndex(const size_t e) const;
412 
413     //! sets a local phase element to a global index value
414     /*!
415      * @param eLocal Local phase element index
416      * @param eGlobal Global phase element index
417      */
418     void setElemGlobalIndex(const size_t eLocal, const size_t eGlobal);
419 
420     //! Returns the number of element constraints
421     size_t nElemConstraints() const;
422 
423     //! Name of the element constraint with index \c e.
424     /*!
425      * @param e Element index.
426      */
427     std::string elementName(const size_t e) const;
428 
429     //! Type of the element constraint with index \c e.
430     /*!
431      * @param e Element index.
432      */
433     int elementType(const size_t e) const;
434 
435     //! Transfer all of the element information from the ThermoPhase object to
436     //! the vcs_VolPhase object.
437     /*!
438      * Also decide whether we need a new charge neutrality element in the phase
439      * to enforce a charge neutrality constraint.
440      *
441      * @param tPhase Pointer to the ThermoPhase object
442      */
443     size_t transferElementsFM(const ThermoPhase* const tPhase);
444 
445     //! Get a constant form of the Species Formula Matrix
446     /*!
447      *  Returns a `double**` pointer such that `fm[e][f]` is the formula
448      *  matrix entry for element `e` for species `k`
449      */
450     const Array2D& getFormulaMatrix() const;
451 
452     //! Returns the type of the species unknown
453     /*!
454      * @param k species index
455      * @return the SpeciesUnknownType[k] = type of species
456      *      - Normal -> VCS_SPECIES_TYPE_MOLUNK (unknown is the mole number in
457      *        the phase)
458      *      - metal electron -> VCS_SPECIES_INTERFACIALVOLTAGE (unknown is the
459      *        interfacial voltage (volts))
460      */
461     int speciesUnknownType(const size_t k) const;
462 
463     int elementActive(const size_t e) const;
464 
465     //! Return the number of species in the phase
466     size_t nSpecies() const;
467 
468     //! Return the name corresponding to the equation of state
469     std::string eos_name() const;
470 
471 private:
472     //! Evaluate the activity coefficients at the current conditions
473     /*!
474      * We carry out a calculation whenever #m_UpToDate_AC is false. Specifically
475      * whenever a phase goes zero, we do not carry out calculations on it.
476      */
477     void _updateActCoeff() const;
478 
479     //! Gibbs free energy calculation for standard states
480     /*!
481      * Calculate the Gibbs free energies for the standard states The results are
482      * held internally within the object.
483      */
484     void _updateGStar() const;
485 
486     //! Gibbs free energy calculation at a temperature for the reference state
487     //! of each species
488     void _updateG0() const;
489 
490     //! Molar volume calculation for standard states
491     /*!
492      * Calculate the molar volume for the standard states. The results are held
493      * internally within the object. Units are in m**3/kmol.
494      */
495     void _updateVolStar() const;
496 
497     //! Calculate the partial molar volumes of all species and return the
498     //! total volume
499     /*!
500      * Calculates these quantities internally and then stores them
501      *
502      * @return total volume [m^3]
503      */
504     double _updateVolPM() const;
505 
506     //! Evaluation of Activity Coefficient Jacobians
507     /*!
508      * This is the derivative of the ln of the activity coefficient with respect
509      * to mole number of jth species. (temp, pressure, and other mole numbers
510      * held constant)
511      *
512      * We employ a finite difference derivative approach here. Because we have
513      * to change the mole numbers, this is not a const function, even though the
514      * paradigm would say that it should be.
515      */
516     void _updateLnActCoeffJac();
517 
518     //! Updates the mole fraction dependencies
519     /*!
520      * Whenever the mole fractions change, this routine should be called.
521      */
522     void _updateMoleFractionDependencies();
523 
524 private:
525     //! Backtrack value of VCS_SOLVE *
526     VCS_SOLVE* m_owningSolverObject;
527 
528 public:
529     //! Original ID of the phase in the problem.
530     /*!
531      * If a non-ideal phase splits into two due to a miscibility gap, these
532      * numbers will stay the same after the split.
533      */
534     size_t VP_ID_;
535 
536     //! If true, this phase consists of a single species
537     bool m_singleSpecies;
538 
539     //! If true, this phase is a gas-phase like phase
540     /*!
541      * A RTlog(p/1atm) term is added onto the chemical potential for inert
542      * species if this is true.
543      */
544     bool m_gasPhase;
545 
546     //! Type of the equation of state
547     /*!
548      * The known types are listed at the top of this file.
549      */
550     int m_eqnState;
551 
552     //! This is the element number for the charge neutrality condition of the
553     //! phase
554     /*!
555      *  If it has one.  If it does not have a charge neutrality
556      * constraint, then this value is equal to -1
557      */
558     size_t ChargeNeutralityElement;
559 
560     //! Convention for the activity formulation
561     /*!
562      *  * 0 = molar based activities (default)
563      *  * 1 = Molality based activities, mu = mu_0 + ln a_molality. Standard
564      *    state is based on unity molality
565      */
566     int p_activityConvention;
567 
568 private:
569     //! Number of element constraints within the problem
570     /*!
571      *  This is usually equal to the number of elements.
572      */
573     size_t m_numElemConstraints;
574 
575     //! vector of strings containing the element constraint names
576     /*!
577      * Length =  nElemConstraints
578      */
579     std::vector<std::string> m_elementNames;
580 
581     //! boolean indicating whether an element constraint is active
582     //! for the current  problem
583     vector_int m_elementActive;
584 
585     //! Type of the element constraint
586     /*!
587      * m_elType[j] = type of the element:
588      * * 0  VCS_ELEM_TYPE_ABSPOS Normal element that is positive or zero in
589      *   all species.
590      * * 1  VCS_ELEM_TYPE_ELECTRONCHARGE element dof that corresponds to the
591      *   charge DOF.
592      * * 2  VCS_ELEM_TYPE_OTHERCONSTRAINT Other constraint which may mean that
593      *   a species has neg 0 or pos value of that constraint (other than
594      *   charge)
595      */
596     vector_int m_elementType;
597 
598     //! Formula Matrix for the phase
599     /*!
600      *  FormulaMatrix(kspec,j) = Formula Matrix for the species
601      *  Number of elements, j, in the kspec species
602      */
603     Array2D m_formulaMatrix;
604 
605     //! Type of the species unknown
606     /*!
607      *  SpeciesUnknownType[k] = type of species
608      *  - Normal -> VCS_SPECIES_TYPE_MOLUNK.
609      *    (unknown is the mole number in the phase)
610      *  - metal electron -> VCS_SPECIES_INTERFACIALVOLTAGE.
611      *    (unknown is the interfacial voltage (volts))
612      */
613     vector_int m_speciesUnknownType;
614 
615     //! Index of the element number in the global list of elements stored in VCS_SOLVE
616     std::vector<size_t> m_elemGlobalIndex;
617 
618     //! Number of species in the phase
619     size_t m_numSpecies;
620 
621 public:
622     //! String name for the phase
623     std::string PhaseName;
624 
625 private:
626     //!  Total moles of inert in the phase
627     double m_totalMolesInert;
628 
629     //! Boolean indicating whether the phase is an ideal solution
630     //! and therefore its molar-based activity coefficients are
631     //! uniformly equal to one.
632     bool m_isIdealSoln;
633 
634     //! Current state of existence:
635     /*!
636      * - VCS_PHASE_EXIST_ZEROEDPHASE = -6: Set to not exist by fiat from a
637      *   higher level. This is used in phase stability boundary calculations
638      * - VCS_PHASE_EXIST_NO = 0:   Doesn't exist currently
639      * - VCS_PHASE_EXIST_MINORCONC = 1:  Exists, but the concentration is so
640      *   low that an alternate method is used to calculate the total phase
641      *   concentrations.
642      * - VCS_PHASE_EXIST_YES = 2 : Does exist currently
643      * - VCS_PHASE_EXIST_ALWAYS = 3: Always exists because it contains inerts
644      *   which can't exist in any other phase. Or, the phase exists always
645      *   because it consists of a single species, which is identified with the
646      *   voltage, i.e., its an electron metal phase.
647      */
648     int m_existence;
649 
650     // Index of the first MF species in the list of unknowns for this phase
651     /*!
652      *  This is always equal to zero.
653      *  Am anticipating the case where the phase potential is species # 0,
654      *  for multiphase phases. Right now we have the phase potential equal
655      *  to 0 for single species phases, where we set by hand the mole fraction
656      *  of species 0 to one.
657      */
658     int m_MFStartIndex;
659 
660     //! Index into the species vectors
661     /*!
662      *  Maps the phase species number into the global species number.
663      *  Note, as part of the vcs algorithm, the order of the species
664      *  vector is changed during the algorithm
665      */
666     std::vector<size_t> IndSpecies;
667 
668     //! Vector of Species structures for the species belonging to this phase
669     /*!
670      * The index into this vector is the species index within the phase.
671      */
672     std::vector<vcs_SpeciesProperties*> ListSpeciesPtr;
673 
674     /**
675      *  If we are using Cantera, this is the pointer to the ThermoPhase
676      *  object. If not, this is null.
677      */
678     ThermoPhase* TP_ptr;
679 
680     //!  Total mols in the phase. units are kmol
681     double v_totalMoles;
682 
683     //! Vector of the current mole fractions for species in the phase
684     vector_fp Xmol_;
685 
686     //! Vector of current creationMoleNumbers_
687     /*!
688      *  These are the actual unknowns in the phase stability problem
689      */
690     vector_fp creationMoleNumbers_;
691 
692     //! Vector of creation global reaction numbers for the phase stability problem
693     /*!
694      * The phase stability problem requires a global reaction number for each
695      * species in the phase. Usually this is the krxn = kglob - M for species in
696      * the phase that are not components. For component species, the choice of
697      * the reaction is one which maximizes the chance that the phase pops into
698      * (or remains in) existence.
699      *
700      * The index here is the local phase species index. the value of the
701      * variable is the global vcs reaction number. Note, that the global
702      * reaction number will go out of order when the species positions are
703      * swapped. So, this number has to be recalculated.
704      *
705      * Length = number of species in phase
706      */
707     std::vector<size_t> creationGlobalRxnNumbers_;
708 
709     //! If the potential is a solution variable in VCS, it acts as a species.
710     //! This is the species index in the phase for the potential
711     size_t m_phiVarIndex;
712 
713     //! Total Volume of the phase. Units are m**3.
714     mutable double m_totalVol;
715 
716     //! Vector of calculated SS0 chemical potentials for the
717     //! current Temperature.
718     /*!
719      * Note, This is the chemical potential derived strictly from the polynomial
720      * in temperature. Pressure effects have to be added in to get to the
721      * standard state. Units are J/kmol.
722      */
723     mutable vector_fp SS0ChemicalPotential;
724 
725     //! Vector of calculated Star chemical potentials for the
726     //! current Temperature and pressure.
727     /*!
728      * Note, This is the chemical potential at unit activity. Thus, we can call
729      * it the standard state chemical potential as well. Units are J/kmol.
730      */
731     mutable vector_fp StarChemicalPotential;
732 
733     //! Vector of the Star molar Volumes of the species. units  m3 / kmol
734     mutable vector_fp StarMolarVol;
735 
736     //! Vector of the Partial molar Volumes of the species. units  m3 / kmol
737     mutable vector_fp PartialMolarVol;
738 
739     //! Vector of calculated activity coefficients for the current state
740     /*!
741      * Whether or not this vector is current is determined by the bool
742      * #m_UpToDate_AC.
743      */
744     mutable vector_fp ActCoeff;
745 
746     //! Vector of the derivatives of the ln activity coefficient wrt to the
747     //! current mole number multiplied by the current phase moles
748     /*!
749      * np_dLnActCoeffdMolNumber(k,j);
750      * - j = id of the species mole number
751      * - k = id of the species activity coefficient
752      */
753     mutable Array2D np_dLnActCoeffdMolNumber;
754 
755     //! Status
756     /*!
757      *  valid values are
758      *  - VCS_STATECALC_OLD
759      *  - VCS_STATECALC_NEW
760      *  - VCS_STATECALC_TMP
761      */
762     int m_vcsStateStatus;
763 
764     //! Value of the potential for the phase (Volts)
765     double m_phi;
766 
767     //! Boolean indicating whether the object has an up-to-date mole number vector
768     //! and potential with respect to the current vcs state calc status
769     bool m_UpToDate;
770 
771     //! Boolean indicating whether activity coefficients are up to date.
772     /*!
773      * Activity coefficients and volume calculations are lagged. They are only
774      * called when they are needed (and when the state has changed so that they
775      * need to be recalculated).
776      */
777     mutable bool m_UpToDate_AC;
778 
779     //! Boolean indicating whether Star volumes are up to date.
780     /*!
781      * Activity coefficients and volume calculations are lagged. They are only
782      * called when they are needed (and when the state has changed so that they
783      * need to be recalculated). Star volumes are sensitive to temperature and
784      * pressure
785      */
786     mutable bool m_UpToDate_VolStar;
787 
788     //! Boolean indicating whether partial molar volumes are up to date.
789     /*!
790      * Activity coefficients and volume calculations are lagged. They are only
791      * called when they are needed (and when the state has changed so that they
792      * need to be recalculated). partial molar volumes are sensitive to
793      * everything
794      */
795     mutable bool m_UpToDate_VolPM;
796 
797     //! Boolean indicating whether GStar is up to date.
798     /*!
799      * GStar is sensitive to the temperature and the pressure, only
800      */
801     mutable bool m_UpToDate_GStar;
802 
803     //! Boolean indicating whether G0 is up to date.
804     /*!
805      * G0 is sensitive to the temperature and the pressure, only
806      */
807     mutable bool m_UpToDate_G0;
808 
809     //! Current value of the temperature for this object, and underlying objects
810     double Temp_;
811 
812     //! Current value of the pressure for this object, and underlying objects
813     double Pres_;
814 };
815 
816 }
817 
818 #endif
819