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