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