Cantera  3.1.0a1
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
13#include "vcs_defs.h"
14#include "cantera/base/Array.h"
15
16namespace Cantera
17{
18
19class 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
36struct VCS_SPECIES;
37class vcs_SpeciesProperties;
38class 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 */
79{
80public:
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;
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
310private:
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
318public:
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
474private:
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 */
520
521 //! Updates the mole fraction dependencies
522 /*!
523 * Whenever the mole fractions change, this routine should be called.
524 */
526
527private:
528 //! Backtrack value of VCS_SOLVE *
530
531public:
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 */
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 */
570
571private:
572 //! Number of element constraints within the problem
573 /*!
574 * This is usually equal to the number of elements.
575 */
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 */
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 */
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
624public:
625 //! String name for the phase
626 string PhaseName;
627
628private:
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 */
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 */
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 */
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
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 */
757
758 //! Status
759 /*!
760 * valid values are
761 * - VCS_STATECALC_OLD
762 * - VCS_STATECALC_NEW
763 * - VCS_STATECALC_TMP
764 */
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
Header file for class Cantera::Array2D.
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition Array.h:32
Base class for a phase with thermodynamic properties.
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
Properties of a single species.
Phase information and Phase calculations for vcs.
vector< double > StarChemicalPotential
Vector of calculated Star chemical potentials for the current Temperature and pressure.
void setCreationMoleNumbers(const double *const n_k, const vector< size_t > &creationGlobalRxnNumbers)
Sets the creationMoleNum's within the phase object.
void setElectricPotential(const double phi)
set the electric potential of the phase
bool m_UpToDate_GStar
Boolean indicating whether GStar is up to date.
double electricPotential() const
Returns the electric field of the phase.
size_t m_phiVarIndex
If the potential is a solution variable in VCS, it acts as a species.
vector< double > Xmol_
Vector of the current mole fractions for species in the phase.
double Temp_
Current value of the temperature for this object, and underlying objects.
int speciesUnknownType(const size_t k) const
Returns the type of the species unknown.
size_t elemGlobalIndex(const size_t e) const
Returns the global index of the local element index for the phase.
void _updateGStar() const
Gibbs free energy calculation for standard states.
vector< double > SS0ChemicalPotential
Vector of calculated SS0 chemical potentials for the current Temperature.
size_t nSpecies() const
Return the number of species in the phase.
string PhaseName
String name for the phase.
void setMolesFromVCSCheck(const int vcsStateStatus, const double *molesSpeciesVCS, const double *const TPhMoles)
Set the moles within the phase.
void setMoleFractionsState(const double molNum, const double *const moleFracVec, const int vcsStateStatus)
Set the moles and/or mole fractions within the phase.
void setMolesOutOfDate(int stateCalc=-1)
Sets the mole flag within the object to out of date.
vector< string > m_elementNames
vector of strings containing the element constraint names
vector< int > m_elementActive
boolean indicating whether an element constraint is active for the current problem
vector< double > creationMoleNumbers_
Vector of current creationMoleNumbers_.
double _updateVolPM() const
Calculate the partial molar volumes of all species and return the total volume.
double m_totalVol
Total Volume of the phase. Units are m**3.
size_t ChargeNeutralityElement
This is the element number for the charge neutrality condition of the phase.
vector< size_t > m_elemGlobalIndex
Index of the element number in the global list of elements stored in VCS_SOLVE.
size_t VP_ID_
Original ID of the phase in the problem.
Array2D np_dLnActCoeffdMolNumber
Vector of the derivatives of the ln activity coefficient wrt to the current mole number multiplied by...
const Array2D & getFormulaMatrix() const
Get a constant form of the Species Formula Matrix.
vector< int > m_speciesUnknownType
Type of the species unknown.
bool m_UpToDate_VolStar
Boolean indicating whether Star volumes are up to date.
void updateFromVCS_MoleNumbers(const int stateCalc)
Update the moles within the phase, if necessary.
vcs_SpeciesProperties * speciesProperty(const size_t kindex)
Retrieve the kth Species structure for the species belonging to this phase.
size_t phiVarIndex() const
Return the index of the species that represents the the voltage of the phase.
double totalMolesInert() const
Returns the value of the total kmol of inert in the phase.
double v_totalMoles
Total mols in the phase. units are kmol.
bool m_singleSpecies
If true, this phase consists of a single species.
void setMolesFromVCS(const int stateCalc, const double *molesSpeciesVCS=0)
Set the moles within the phase.
void setElemGlobalIndex(const size_t eLocal, const size_t eGlobal)
sets a local phase element to a global index value
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_isIdealSoln
Boolean indicating whether the phase is an ideal solution and therefore its molar-based activity coef...
vector< double > ActCoeff
Vector of calculated activity coefficients for the current state.
int exists() const
int indicating whether the phase exists or not
vector< size_t > IndSpecies
Index into the species vectors.
const vector< double > & moleFractions() const
Return a const reference to the mole fractions stored in the object.
size_t nElemConstraints() const
Returns the number of element constraints.
double m_phi
Value of the potential for the phase (Volts)
size_t spGlobalIndexVCS(const size_t spIndex) const
Return the Global VCS index of the kth species in the phase.
size_t transferElementsFM(const ThermoPhase *const tPhase)
Transfer all of the element information from the ThermoPhase object to the vcs_VolPhase object.
vector< int > m_elementType
Type of the element constraint.
double VolStar_calc_one(size_t kspec) const
Molar volume calculation for standard state of one species.
double GStar_calc_one(size_t kspec) const
Gibbs free energy calculation for standard state of one species.
bool m_gasPhase
If true, this phase is a gas-phase like phase.
void _updateVolStar() const
Molar volume calculation for standard states.
int m_vcsStateStatus
Status.
bool m_UpToDate_G0
Boolean indicating whether G0 is up to date.
void _updateG0() const
Gibbs free energy calculation at a temperature for the reference state of each species.
double Pres_
Current value of the pressure for this object, and underlying objects.
vector< double > PartialMolarVol
Vector of the Partial molar Volumes of the species. units m3 / kmol.
double molefraction(size_t kspec) const
Returns the mole fraction of the kspec species.
Array2D m_formulaMatrix
Formula Matrix for the phase.
void _updateLnActCoeffJac()
Evaluation of Activity Coefficient Jacobians.
void setTotalMoles(const double totalMols)
Sets the total moles in the phase.
int p_activityConvention
Convention for the activity formulation.
void setMolesCurrent(int vcsStateStatus)
Sets the mole flag within the object to be current.
void sendToVCS_GStar(double *const gstar) const
Fill in the standard state Gibbs free energy vector for VCS.
void sendToVCS_ActCoeff(const int stateCalc, double *const AC)
Fill in an activity coefficients vector within a VCS_SOLVE object.
size_t m_numElemConstraints
Number of element constraints within the problem.
vector< double > StarMolarVol
Vector of the Star molar Volumes of the species. units m3 / kmol.
double sendToVCS_VolPM(double *const VolPM) const
Fill in the partial molar volume vector for VCS.
void sendToVCS_LnActCoeffJac(Array2D &LnACJac_VCS)
Downloads the ln ActCoeff Jacobian into the VCS version of the ln ActCoeff Jacobian.
int m_eqnState
Type of the equation of state.
void setTotalMolesInert(const double tMolesInert)
Sets the total moles of inert in the phase.
double G0_calc_one(size_t kspec) const
Gibbs free energy calculation at a temperature for the reference state of a species,...
void _updateActCoeff() const
Evaluate the activity coefficients at the current conditions.
void setState_TP(const double temperature_Kelvin, const double pressure_PA)
Sets the temperature and pressure in this object and underlying ThermoPhase objects.
int m_existence
Current state of existence:
string eos_name() const
Return the name corresponding to the equation of state.
bool m_UpToDate_AC
Boolean indicating whether activity coefficients are up to date.
VCS_SOLVE * m_owningSolverObject
Backtrack value of VCS_SOLVE *.
ThermoPhase * TP_ptr
If we are using Cantera, this is the pointer to the ThermoPhase object.
void _updateMoleFractionDependencies()
Updates the mole fraction dependencies.
double m_totalMolesInert
Total moles of inert in the phase.
int elementType(const size_t e) const
Type of the element constraint with index e.
const ThermoPhase * ptrThermoPhase() const
Return a const ThermoPhase pointer corresponding to this phase.
vector< size_t > creationGlobalRxnNumbers_
Vector of creation global reaction numbers for the phase stability problem.
void setSpGlobalIndexVCS(const size_t spIndex, const size_t spGlobalIndex)
set the Global VCS index of the kth species in the phase
size_t m_numSpecies
Number of species in the phase.
void setExistence(const int existence)
Set the existence flag in the object.
void setMoleFractions(const double *const xmol)
Set the mole fractions from a conventional mole fraction vector.
bool m_UpToDate
Boolean indicating whether the object has an up-to-date mole number vector and potential with respect...
vector< vcs_SpeciesProperties * > ListSpeciesPtr
Vector of Species structures for the species belonging to this phase.
void setState_T(const double temperature_Kelvin)
Sets the temperature in this object and underlying ThermoPhase objects.
const vector< double > & creationMoleNumbers(vector< size_t > &creationGlobalRxnNumbers) const
Return a const reference to the creationMoleNumbers stored in the object.
string elementName(const size_t e) const
Name of the element constraint with index e.
bool m_UpToDate_VolPM
Boolean indicating whether partial molar volumes are up to date.
bool isIdealSoln() const
Returns whether the phase is an ideal solution phase.
double totalMoles() const
Return the total moles in the phase.
void setPtrThermoPhase(ThermoPhase *tp_ptr)
Set the pointer for Cantera's ThermoPhase parameter.
const double OneAtm
One atmosphere [Pa].
Definition ct_defs.h:96
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:180
Defines and definitions within the vcs package.
#define VCS_STATECALC_OLD
State Calculation based on the old or base mole numbers.
Definition vcs_defs.h:297
#define VCS_PHASE_EXIST_NO
Phase doesn't currently exist in the mixture.
Definition vcs_defs.h:200