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