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