| Cantera 3.0.0

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