Cantera  4.0.0a1
Loading...
Searching...
No Matches
MultiPhase.h
Go to the documentation of this file.
1/**
2 * @file MultiPhase.h
3 * Headers for the @link Cantera::MultiPhase MultiPhase@endlink
4 * object that is used to set up multiphase equilibrium problems (see @ref equilGroup).
5 */
6
7// This file is part of Cantera. See License.txt in the top-level directory or
8// at https://cantera.org/license.txt for license and copyright information.
9
10#ifndef CT_MULTIPHASE_H
11#define CT_MULTIPHASE_H
12
14
15namespace Cantera
16{
17
18class ThermoPhase;
19
20//! A class for multiphase mixtures. The mixture can contain any
21//! number of phases of any type.
22/*!
23 * This object is the basic tool used by %Cantera for use in Multiphase
24 * equilibrium calculations.
25 *
26 * It is a container for a set of phases. Each phase has a given number of
27 * kmoles. Therefore, MultiPhase may be considered an "extrinsic"
28 * thermodynamic object, in contrast to the ThermoPhase object, which is an
29 * "intrinsic" thermodynamic object.
30 *
31 * @warning The multiphase equilibrium solvers currently have a number of problems that
32 * lead to solver failures or incorrect results for some inputs. See the
33 * [list of issues on GitHub](https://github.com/Cantera/cantera/issues?q=is%3Aopen+is%3Aissue+label%3AEquilibrium)
34 * for more information.
35 *
36 * MultiPhase may be considered to be "upstream" of the ThermoPhase objects in
37 * the sense that setting a property within MultiPhase, such as temperature,
38 * pressure, or species mole number, affects the underlying ThermoPhase
39 * object, but not the other way around.
40 *
41 * All phases have the same temperature and pressure, and a specified number
42 * of moles for each phase. The phases do not need to have the same elements.
43 * For example, a mixture might consist of a gaseous phase with elements (H,
44 * C, O, N), a solid carbon phase containing only element C, etc. A master
45 * element set will be constructed for the mixture that is the intersection of
46 * the elements of each phase.
47 *
48 * Below, reference is made to global species and global elements. These refer
49 * to the collective species and elements encompassing all of the phases
50 * tracked by the object.
51 *
52 * The global element list kept by this object is an intersection of the
53 * element lists of all the phases that comprise the MultiPhase.
54 *
55 * The global species list kept by this object is a concatenated list of all
56 * of the species in all the phases that comprise the MultiPhase. The ordering
57 * of species is contiguous with respect to the phase id.
58 *
59 * @ingroup equilGroup
60 */
62{
63public:
64 //! Constructor.
65 /*!
66 * The constructor takes no arguments, since phases are added using
67 * method addPhase().
68 */
69 MultiPhase() = default;
70 MultiPhase(const MultiPhase&) = delete;
71 MultiPhase& operator=(const MultiPhase&) = delete;
72 virtual ~MultiPhase();
73
74 //! Add a phase to the mixture.
75 /*!
76 * This function must be called before the init() function is called,
77 * which serves to freeze the MultiPhase.
78 *
79 * @param p pointer to the phase object
80 * @param moles total number of moles of all species in this phase
81 * @since New in %Cantera 3.2.
82 */
83 void addPhase(shared_ptr<ThermoPhase> p, double moles);
84
85 //! Number of elements.
86 size_t nElements() const {
87 return m_nel;
88 }
89
90 //! Check that the specified element index is in range.
91 /*!
92 * @since Starting in %Cantera 3.2, returns the input element index, if valid.
93 * @exception Throws an IndexError if m is greater than nElements()-1
94 */
95 size_t checkElementIndex(size_t m) const;
96
97 //! Returns the name of the global element *m*.
98 /*!
99 * @param m index of the global element
100 */
101 string elementName(size_t m) const;
102
103 //! Returns the index of the element with name @e name.
104 /*!
105 * @param name String name of the global element.
106 * @param raise If `true`, raise exception if the specified element is not found;
107 * otherwise, return @ref npos.
108 * @since Added the `raise` argument in %Cantera 3.2. In %Cantera 4.0, changed the
109 * default value of `raise` to `true`.
110 * @exception Throws a CanteraError if the specified element is not found and
111 * `raise` is `true`.
112 */
113 size_t elementIndex(const string& name, bool raise=true) const;
114
115 //! Number of species, summed over all phases.
116 size_t nSpecies() const {
117 return m_nsp;
118 }
119
120 //! Name of species with global index @e kGlob
121 /*!
122 * @param kGlob global species index
123 */
124 string speciesName(size_t kGlob) const;
125
126 //! Returns the Number of atoms of global element @e mGlob in
127 //! global species @e kGlob.
128 /*!
129 * @param kGlob global species index
130 * @param mGlob global element index
131 * @returns the number of atoms.
132 */
133 double nAtoms(const size_t kGlob, const size_t mGlob) const;
134
135 //! Returns the global Species mole fractions.
136 /*!
137 * Write the array of species mole
138 * fractions into array @c x. The mole fractions are
139 * normalized to sum to one in each phase.
140 *
141 * @param x vector of mole fractions. Length = number of global species.
142 */
143 void getMoleFractions(span<double> x) const;
144
145 //! Process phases and build atomic composition array.
146 /*!
147 * This method must be called after all phases are added, before doing
148 * anything else with the mixture. After init() has been called, no more
149 * phases may be added.
150 */
151 void init();
152
153 //! Returns the name of the n'th phase
154 /*!
155 * @param iph phase Index
156 */
157 string phaseName(size_t iph) const;
158
159 //! Returns the index, given the phase name
160 /*!
161 * @param pName Name of the phase
162 * @param raise If `true`, raise exception if the specified phase is not found.
163 * @returns the index. A value of -1 means the phase isn't in the object.
164 * @since Added the `raise` argument in %Cantera 3.2 and changed return type.
165 * Changed the default value of `raise` to `true` in %Cantera 4.0.
166 * @exception Throws a CanteraError if the specified phase is not found and
167 * `raise` is `true`.
168 */
169 size_t phaseIndex(const string& pName, bool raise=true) const;
170
171 //! Return the number of moles in phase n.
172 /*!
173 * @param n Index of the phase.
174 */
175 double phaseMoles(const size_t n) const;
176
177 //! Set the number of moles of phase with index n.
178 /*!
179 * @param n Index of the phase
180 * @param moles Number of moles in the phase (kmol)
181 */
182 void setPhaseMoles(const size_t n, const double moles);
183
184 //! Return a reference to phase n.
185 /*!
186 * The state of phase n is also updated to match the state stored locally
187 * in the mixture object.
188 *
189 * @param n Phase Index
190 * @return Reference to the ThermoPhase object for the phase
191 */
192 ThermoPhase& phase(size_t n);
193
194 //! Returns the moles of global species @c k. units = kmol
195 /*!
196 * @param kGlob Global species index k
197 */
198 double speciesMoles(size_t kGlob) const;
199
200 //! Return the global index of the species belonging to phase number @c p
201 //! with local index @c k within the phase.
202 /*!
203 * @param k local index of the species within the phase
204 * @param p index of the phase
205 */
206 size_t speciesIndex(size_t k, size_t p) const {
207 return m_spstart[p] + k;
208 }
209
210 //! Return the global index of the species belonging to phase name @c phaseName
211 //! with species name @c speciesName
212 /*!
213 * @param speciesName Species Name
214 * @param phaseName Phase Name
215 *
216 * @returns the global index
217 *
218 * If the species or phase name is not recognized, this routine throws a
219 * CanteraError.
220 */
221 size_t speciesIndex(const string& speciesName, const string& phaseName);
222
223 //! Minimum temperature for which all solution phases have valid thermo
224 //! data. Stoichiometric phases are not considered, since they may have
225 //! thermo data only valid for conditions for which they are stable.
226 double minTemp() const {
227 return m_Tmin;
228 }
229
230 //! Maximum temperature for which all solution phases have valid thermo
231 //! data. Stoichiometric phases are not considered, since they may have
232 //! thermo data only valid for conditions for which they are stable.
233 double maxTemp() const {
234 return m_Tmax;
235 }
236
237 //! Total charge summed over all phases (Coulombs).
238 double charge() const;
239
240 //! Charge (Coulombs) of phase with index @e p.
241 /*!
242 * The net charge is computed as @f[ Q_p = N_p \sum_k F z_k X_k @f]
243 * where the sum runs only over species in phase @e p.
244 * @param p index of the phase for which the charge is desired.
245 */
246 double phaseCharge(size_t p) const;
247
248 //! Total moles of global element @e m, summed over all phases.
249 /*!
250 * @param m Index of the global element
251 */
252 double elementMoles(size_t m) const;
253
254 //! Returns a vector of Chemical potentials.
255 /*!
256 * Write into array @e mu the chemical potentials of all species
257 * [J/kmol]. The chemical potentials are related to the activities by
258 *
259 * @f$
260 * \mu_k = \mu_k^0(T, P) + RT \ln a_k.
261 * @f$.
262 *
263 * @param mu Chemical potential vector. Length = num global species. Units
264 * = J/kmol.
265 */
266 void getChemPotentials(span<double> mu) const;
267
268 //! Returns a vector of Valid chemical potentials.
269 /*!
270 * Write into array @e mu the chemical potentials of all species with
271 * thermo data valid for the current temperature [J/kmol]. For other
272 * species, set the chemical potential to the value @e not_mu. If @e
273 * standard is set to true, then the values returned are standard chemical
274 * potentials.
275 *
276 * This method is designed for use in computing chemical equilibrium by
277 * Gibbs minimization. For solution phases (more than one species), this
278 * does the same thing as getChemPotentials. But for stoichiometric
279 * phases, this writes into array @e mu the user-specified value @e not_mu
280 * instead of the chemical potential if the temperature is outside the
281 * range for which the thermo data for the one species in the phase are
282 * valid. The need for this arises since many condensed phases have thermo
283 * data fit only for the temperature range for which they are stable. For
284 * example, in the NASA database, the fits for H2O(s) are only done up to
285 * 0 C, the fits for H2O(L) are only done from 0 C to 100 C, etc. Using
286 * the polynomial fits outside the range for which the fits were done can
287 * result in spurious chemical potentials, and can lead to condensed
288 * phases appearing when in fact they should be absent.
289 *
290 * By setting @e not_mu to a large positive value, it is possible to force
291 * routines which seek to minimize the Gibbs free energy of the mixture to
292 * zero out any phases outside the temperature range for which their
293 * thermo data are valid.
294 *
295 * @param not_mu Value of the chemical potential to set species in phases,
296 * for which the thermo data is not valid
297 * @param mu Vector of chemical potentials. length = Global species,
298 * units = J kmol-1
299 * @param standard If this method is called with @e standard set to true,
300 * then the composition-independent standard chemical
301 * potentials are returned instead of the composition-
302 * dependent chemical potentials.
303 */
304 void getValidChemPotentials(double not_mu, span<double> mu,
305 bool standard = false) const;
306
307 //! Temperature [K].
308 double temperature() const {
309 return m_temp;
310 }
311
312 //! Equilibrate a MultiPhase object
313 /*!
314 * Set this mixture to chemical equilibrium by calling one of Cantera's
315 * equilibrium solvers. The XY parameter indicates what two thermodynamic
316 * quantities are to be held constant during the equilibration process.
317 *
318 * @param XY String representation of what two properties are being
319 * held constant
320 * @param solver Name of the solver to be used to equilibrate the phase.
321 * If solver = 'vcs', the vcs_MultiPhaseEquil solver will be used. If
322 * solver = 'gibbs', the MultiPhaseEquil solver will be used. If solver
323 * = 'auto', the 'vcs' solver will be tried first, followed by the
324 * 'gibbs' solver if the first one fails.
325 * @param rtol Relative tolerance
326 * @param max_steps Maximum number of steps to take to find the solution
327 * @param max_iter The maximum number of outer temperature or pressure
328 * iterations to take when T and/or P is not held fixed.
329 * @param estimate_equil integer indicating whether the solver should
330 * estimate its own initial condition. If 0, the initial mole fraction
331 * vector in the ThermoPhase object is used as the initial condition.
332 * If 1, the initial mole fraction vector is used if the element
333 * abundances are satisfied. If -1, the initial mole fraction vector is
334 * thrown out, and an estimate is formulated.
335 * @param log_level loglevel Controls amount of diagnostic output.
336 * log_level=0 suppresses diagnostics, and increasingly-verbose
337 * messages are written as loglevel increases.
338 *
339 * @ingroup equilGroup
340 */
341 void equilibrate(const string& XY, const string& solver="auto",
342 double rtol=1e-9, int max_steps=50000, int max_iter=100,
343 int estimate_equil=0, int log_level=0);
344
345 //! Set the temperature [K].
346 /*!
347 * @param T value of the temperature (Kelvin)
348 */
349 void setTemperature(const double T);
350
351 //! Pressure [Pa].
352 double pressure() const {
353 return m_press;
354 }
355
356 //! The total mixture volume [m^3].
357 /*!
358 * Returns the cumulative sum of the volumes of all the phases in the
359 * mixture.
360 */
361 double volume() const;
362
363 //! Set the pressure [Pa].
364 /*!
365 * @param P Set the pressure in the MultiPhase object (Pa)
366 */
367 void setPressure(double P) {
368 m_press = P;
369 updatePhases();
370 }
371
372 //! The enthalpy of the mixture [J].
373 double enthalpy() const;
374
375 //! The internal energy of the mixture [J].
376 double IntEnergy() const;
377
378 //! The entropy of the mixture [J/K].
379 double entropy() const;
380
381 //! The Gibbs function of the mixture [J].
382 double gibbs() const;
383
384 //! Heat capacity at constant pressure [J/K]. Note that this does not
385 //! account for changes in composition of the mixture with temperature.
386 double cp() const;
387
388 //! Number of phases.
389 size_t nPhases() const {
390 return m_phase.size();
391 }
392
393 //! Return true is species @e kGlob is a species in a multicomponent
394 //! solution phase.
395 /*!
396 * @param kGlob index of the global species
397 */
398 bool solutionSpecies(size_t kGlob) const;
399
400 //! Returns the phase index of the Kth "global" species
401 /*!
402 * @param kGlob Global species index.
403 * @returns the index of the owning phase.
404 */
405 size_t speciesPhaseIndex(const size_t kGlob) const;
406
407 //! Returns the mole fraction of global species k
408 /*!
409 * @param kGlob Index of the global species.
410 */
411 double moleFraction(const size_t kGlob) const;
412
413 //! Set the Mole fractions of the nth phase
414 /*!
415 * This function sets the mole fractions of the nth phase. Note, the mole
416 * number of the phase stays constant
417 *
418 * @param n index of the phase
419 * @param x Vector of input mole fractions.
420 */
421 void setPhaseMoleFractions(const size_t n, span<const double> x);
422
423 //! Set the number of moles of species in the mixture
424 /*!
425 * @param xMap Composition of the species with nonzero mole numbers.
426 * Mole numbers that are less than or equal to zero will be
427 * set to zero. units = kmol.
428 */
429 void setMolesByName(const Composition& xMap);
430
431 //! Set the moles via a string containing their names.
432 /*!
433 * The string x is in the form of a composition map. Species which are not
434 * listed are set to zero.
435 *
436 * @param x string x in the form of a composition map
437 * where values are the moles of the species.
438 */
439 void setMolesByName(const string& x);
440
441 //! Get the mole numbers of all species in the multiphase object
442 /*!
443 * @param[out] molNum Vector of doubles of length nSpecies() containing the
444 * global mole numbers (kmol).
445 */
446 void getMoles(span<double> molNum) const;
447
448 //! Sets all of the global species mole numbers
449 /*!
450 * The state of each phase object is also updated to have the specified
451 * composition and the mixture temperature and pressure.
452 *
453 * @param n Vector of doubles of length nSpecies() containing the global
454 * mole numbers (kmol).
455 */
456 void setMoles(span<const double> n);
457
458 //! Retrieves a vector of element abundances
459 /*!
460 * @param elemAbundances Vector of element abundances
461 * Length = number of elements in the MultiPhase object.
462 * Index is the global element index. Units is in kmol.
463 */
464 void getElemAbundances(span<double> elemAbundances) const;
465
466 //! Return true if the phase @e p has valid thermo data for the current
467 //! temperature.
468 /*!
469 * @param p Index of the phase.
470 */
471 bool tempOK(size_t p) const;
472
473 // These methods are meant for internal use.
474
475 //! Update the locally-stored composition within this object to match the
476 //! current compositions of the phase objects.
477 /*!
478 * Query the underlying ThermoPhase objects for their mole fractions and
479 * fill in the mole fraction vector of this current object. Adjust element
480 * compositions within this object to match.
481 *
482 * This is an upload operation in the sense that we are taking downstream
483 * information (ThermoPhase object info) and applying it to an upstream
484 * object (MultiPhase object).
485 */
487
488 //! Set the states of the phase objects to the locally-stored
489 //! state within this MultiPhase object.
490 /*!
491 * This method sets each phase to the mixture temperature and pressure,
492 * and sets the phase mole fractions based on the mixture mole numbers.
493 *
494 * This is an download operation in the sense that we are taking upstream
495 * object information (MultiPhase object) and applying it to downstream
496 * objects (ThermoPhase object information)
497 *
498 * Therefore, the term, "update", is appropriate for a downstream operation.
499 */
500 void updatePhases() const;
501
502private:
503 //! Calculate the element abundance vector
504 void calcElemAbundances() const;
505
506 //! Set the mixture to a state of chemical equilibrium using the
507 //! MultiPhaseEquil solver.
508 /*!
509 * @param XY Integer flag specifying properties to hold fixed.
510 * @param err Error tolerance for @f$ \Delta \mu/RT @f$ for all reactions.
511 * Also used as the relative error tolerance for the outer loop.
512 * @param maxsteps Maximum number of steps to take in solving the fixed TP
513 * problem.
514 * @param maxiter Maximum number of "outer" iterations for problems holding
515 * fixed something other than (T,P).
516 * @param loglevel Level of diagnostic output
517 */
518 double equilibrate_MultiPhaseEquil(int XY, double err, int maxsteps,
519 int maxiter, int loglevel);
520
521 //! Vector of the number of moles in each phase.
522 /*!
523 * Length = m_np, number of phases.
524 */
525 vector<double> m_moles;
526
527 //! Vector of phase objects.
528 vector<shared_ptr<ThermoPhase>> m_phase;
529
530 //! Global Stoichiometric Coefficient array
531 /*!
532 * This is a two dimensional array m_atoms(m, k). The first index is the
533 * global element index. The second index, k, is the global species index.
534 * The value is the number of atoms of type m in species k.
535 */
537
538 //! Locally stored vector of mole fractions of all species comprising the
539 //! MultiPhase object.
540 vector<double> m_moleFractions;
541
542 //! Mapping between the global species number and the phase ID
543 /*!
544 * m_spphase[kGlobal] = iPhase
545 * Length = number of global species
546 */
547 vector<size_t> m_spphase;
548
549 //! Vector of ints containing of first species index in the global list of
550 //! species for each phase
551 /*!
552 * kfirst = m_spstart[ip], kfirst is the index of the first species in
553 * the ip'th phase.
554 */
555 vector<size_t> m_spstart;
556
557 //! String names of the global elements. This has a length equal to the
558 //! number of global elements.
559 vector<string> m_enames;
560
561 //! Atomic number of each global element.
562 vector<int> m_atomicNumber;
563
564 //! Vector of species names in the problem. Vector is over all species
565 //! defined in the object, the global species index.
566 vector<string> m_snames;
567
568 //! Returns the global element index, given the element string name
569 /*!
570 * -> used in the construction. However, wonder if it needs to be global.
571 */
572 map<string, size_t> m_enamemap;
573
574 //! Current value of the temperature (kelvin)
575 double m_temp = 298.15;
576
577 //! Current value of the pressure (Pa)
578 double m_press = OneBar;
579
580 //! Number of distinct elements in all of the phases
581 size_t m_nel = 0;
582
583 //! Number of distinct species in all of the phases
584 size_t m_nsp = 0;
585
586 //! True if the init() routine has been called, and the MultiPhase frozen
587 bool m_init = false;
588
589 //! Global ID of the element corresponding to the electronic charge. If
590 //! there is none, then this is equal to -1
591 size_t m_eloc = npos;
592
593 //! Vector of bools indicating whether temperatures are ok for phases.
594 /*!
595 * If the current temperature is outside the range of valid temperatures
596 * for the phase thermodynamics, the phase flag is set to false.
597 */
598 mutable vector<bool> m_temp_OK;
599
600 //! Minimum temperature for which thermo parameterizations are valid.
601 //! Stoichiometric phases are ignored in this determination. units Kelvin
602 double m_Tmin = 1.0;
603
604 //! Minimum temperature for which thermo parameterizations are valid.
605 //! Stoichiometric phases are ignored in this determination. units Kelvin
606 double m_Tmax = 100000.0;
607
608 //! Vector of element abundances
609 /*!
610 * m_elemAbundances[mGlobal] = kmol of element mGlobal summed over all
611 * species in all phases.
612 */
613 mutable vector<double> m_elemAbundances;
614};
615
616//! Function to output a MultiPhase description to a stream
617/*!
618 * Writes out a description of the contents of each phase of the
619 * MultiPhase using the report function.
620 *
621 * @param s ostream
622 * @param x Reference to a MultiPhase
623 * @returns a reference to the ostream
624 */
625std::ostream& operator<<(std::ostream& s, MultiPhase& x);
626
627//! Choose the optimum basis of species for the equilibrium calculations.
628/*!
629 * This is done by choosing the species with the largest mole fraction not
630 * currently a linear combination of the previous components. Then, calculate
631 * the stoichiometric coefficient matrix for that basis.
632 *
633 * Calculates the identity of the component species in the mechanism. Rearranges
634 * the solution data to put the component data at the front of the species list.
635 *
636 * Then, calculates SC(J,I) the formation reactions for all noncomponent
637 * species in the mechanism.
638 *
639 * @param[in] mphase Pointer to the multiphase object. Contains the species
640 * mole fractions, which are used to pick the current optimal species
641 * component basis.
642 * @param[in] orderVectorElements Order vector for the elements. The element
643 * rows in the formula matrix are rearranged according to this vector.
644 * @param[in] orderVectorSpecies Order vector for the species. The species are
645 * rearranged according to this formula. The first nComponents of this
646 * vector contain the calculated species components on exit.
647 * @param[in] doFormRxn If true, the routine calculates the formation
648 * reaction matrix based on the calculated component species. If
649 * false, this step is skipped.
650 * @param[out] usedZeroedSpecies = If true, then a species with a zero
651 * concentration was used as a component. The problem may be converged.
652 * @param[out] formRxnMatrix
653 * @return The number of components.
654 *
655 * @ingroup equilGroup
656 */
657size_t BasisOptimize(bool& usedZeroedSpecies, bool doFormRxn, MultiPhase* mphase,
658 span<size_t> orderVectorSpecies, span<size_t> orderVectorElements,
659 span<double> formRxnMatrix);
660
661//! Handles the potential rearrangement of the constraint equations
662//! represented by the Formula Matrix.
663/*!
664 * Rearrangement is only necessary when the number of components is less
665 * than the number of elements. For this case, some constraints can never
666 * be satisfied exactly, because the range space represented by the Formula
667 * Matrix of the components can't span the extra space. These constraints,
668 * which are out of the range space of the component Formula matrix
669 * entries, are migrated to the back of the Formula matrix.
670 *
671 * A prototypical example is an extra element column in FormulaMatrix[], which
672 * is identically zero. For example, let's say that argon is has an element
673 * column in FormulaMatrix[], but no species in the mechanism actually
674 * contains argon. Then, nc < ne. Unless the entry for desired element
675 * abundance vector for Ar is zero, then this element abundance constraint can
676 * never be satisfied. The constraint vector is not in the range space of the
677 * formula matrix.
678 *
679 * Also, without perturbation of FormulaMatrix[], BasisOptimize[] would
680 * produce a zero pivot because the matrix would be singular (unless the argon
681 * element column was already the last column of FormulaMatrix[].
682 *
683 * This routine borrows heavily from BasisOptimize algorithm. It finds nc
684 * constraints which span the range space of the Component Formula matrix, and
685 * assigns them as the first nc components in the formula matrix. This
686 * guarantees that BasisOptimize has a nonsingular matrix to invert.
687 *
688 * @param[in] nComponents Number of components calculated previously.
689 * @param[in] elementAbundances Current value of the element abundances
690 * @param[in] mphase Input pointer to a MultiPhase object
691 * @param[in] orderVectorSpecies input vector containing the ordering of the
692 * global species in mphase. This is used to extract the component
693 * basis of the mphase object.
694 * @param[out] orderVectorElements Output vector containing the order of the
695 * elements that is necessary for calculation of the formula matrix.
696 *
697 * @ingroup equilGroup
698 */
699void ElemRearrange(size_t nComponents, span<const double> elementAbundances,
700 MultiPhase* mphase, span<size_t> orderVectorSpecies,
701 span<size_t> orderVectorElements);
702
703//! External int that is used to turn on debug printing for the
704//! BasisOptimize program.
705/*!
706 * Set this to 1 if you want debug printing from BasisOptimize.
707 */
708extern int BasisOptimize_print_lvl;
709}
710
711#endif
Headers for the DenseMatrix object, which deals with dense rectangular matrices and description of th...
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operat...
Definition DenseMatrix.h:42
A class for multiphase mixtures.
Definition MultiPhase.h:62
void getMoleFractions(span< double > x) const
Returns the global Species mole fractions.
void init()
Process phases and build atomic composition array.
size_t speciesIndex(size_t k, size_t p) const
Return the global index of the species belonging to phase number p with local index k within the phas...
Definition MultiPhase.h:206
bool solutionSpecies(size_t kGlob) const
Return true is species kGlob is a species in a multicomponent solution phase.
void getMoles(span< double > molNum) const
Get the mole numbers of all species in the multiphase object.
double nAtoms(const size_t kGlob, const size_t mGlob) const
Returns the Number of atoms of global element mGlob in global species kGlob.
void setMolesByName(const Composition &xMap)
Set the number of moles of species in the mixture.
DenseMatrix m_atoms
Global Stoichiometric Coefficient array.
Definition MultiPhase.h:536
double gibbs() const
The Gibbs function of the mixture [J].
void setMoles(span< const double > n)
Sets all of the global species mole numbers.
size_t m_nel
Number of distinct elements in all of the phases.
Definition MultiPhase.h:581
double speciesMoles(size_t kGlob) const
Returns the moles of global species k. units = kmol.
double m_temp
Current value of the temperature (kelvin)
Definition MultiPhase.h:575
void calcElemAbundances() const
Calculate the element abundance vector.
size_t nSpecies() const
Number of species, summed over all phases.
Definition MultiPhase.h:116
size_t checkElementIndex(size_t m) const
Check that the specified element index is in range.
double enthalpy() const
The enthalpy of the mixture [J].
double pressure() const
Pressure [Pa].
Definition MultiPhase.h:352
vector< size_t > m_spstart
Vector of ints containing of first species index in the global list of species for each phase.
Definition MultiPhase.h:555
vector< size_t > m_spphase
Mapping between the global species number and the phase ID.
Definition MultiPhase.h:547
double minTemp() const
Minimum temperature for which all solution phases have valid thermo data.
Definition MultiPhase.h:226
vector< double > m_moleFractions
Locally stored vector of mole fractions of all species comprising the MultiPhase object.
Definition MultiPhase.h:540
size_t phaseIndex(const string &pName, bool raise=true) const
Returns the index, given the phase name.
void getElemAbundances(span< double > elemAbundances) const
Retrieves a vector of element abundances.
vector< double > m_elemAbundances
Vector of element abundances.
Definition MultiPhase.h:613
void setPhaseMoleFractions(const size_t n, span< const double > x)
Set the Mole fractions of the nth phase.
double equilibrate_MultiPhaseEquil(int XY, double err, int maxsteps, int maxiter, int loglevel)
Set the mixture to a state of chemical equilibrium using the MultiPhaseEquil solver.
vector< bool > m_temp_OK
Vector of bools indicating whether temperatures are ok for phases.
Definition MultiPhase.h:598
double phaseCharge(size_t p) const
Charge (Coulombs) of phase with index p.
size_t nPhases() const
Number of phases.
Definition MultiPhase.h:389
size_t m_eloc
Global ID of the element corresponding to the electronic charge.
Definition MultiPhase.h:591
double entropy() const
The entropy of the mixture [J/K].
double temperature() const
Temperature [K].
Definition MultiPhase.h:308
double moleFraction(const size_t kGlob) const
Returns the mole fraction of global species k.
void getChemPotentials(span< double > mu) const
Returns a vector of Chemical potentials.
string speciesName(size_t kGlob) const
Name of species with global index kGlob.
vector< shared_ptr< ThermoPhase > > m_phase
Vector of phase objects.
Definition MultiPhase.h:528
double m_press
Current value of the pressure (Pa)
Definition MultiPhase.h:578
bool tempOK(size_t p) const
Return true if the phase p has valid thermo data for the current temperature.
map< string, size_t > m_enamemap
Returns the global element index, given the element string name.
Definition MultiPhase.h:572
size_t speciesPhaseIndex(const size_t kGlob) const
Returns the phase index of the Kth "global" species.
void getValidChemPotentials(double not_mu, span< double > mu, bool standard=false) const
Returns a vector of Valid chemical potentials.
void setPressure(double P)
Set the pressure [Pa].
Definition MultiPhase.h:367
vector< string > m_enames
String names of the global elements.
Definition MultiPhase.h:559
void addPhase(shared_ptr< ThermoPhase > p, double moles)
Add a phase to the mixture.
double phaseMoles(const size_t n) const
Return the number of moles in phase n.
MultiPhase()=default
Constructor.
size_t m_nsp
Number of distinct species in all of the phases.
Definition MultiPhase.h:584
vector< int > m_atomicNumber
Atomic number of each global element.
Definition MultiPhase.h:562
double volume() const
The total mixture volume [m^3].
void uploadMoleFractionsFromPhases()
Update the locally-stored composition within this object to match the current compositions of the pha...
bool m_init
True if the init() routine has been called, and the MultiPhase frozen.
Definition MultiPhase.h:587
vector< string > m_snames
Vector of species names in the problem.
Definition MultiPhase.h:566
double m_Tmin
Minimum temperature for which thermo parameterizations are valid.
Definition MultiPhase.h:602
void updatePhases() const
Set the states of the phase objects to the locally-stored state within this MultiPhase object.
size_t nElements() const
Number of elements.
Definition MultiPhase.h:86
double charge() const
Total charge summed over all phases (Coulombs).
double cp() const
Heat capacity at constant pressure [J/K].
size_t elementIndex(const string &name, bool raise=true) const
Returns the index of the element with name name.
void setTemperature(const double T)
Set the temperature [K].
ThermoPhase & phase(size_t n)
Return a reference to phase n.
double maxTemp() const
Maximum temperature for which all solution phases have valid thermo data.
Definition MultiPhase.h:233
double IntEnergy() const
The internal energy of the mixture [J].
string elementName(size_t m) const
Returns the name of the global element m.
vector< double > m_moles
Vector of the number of moles in each phase.
Definition MultiPhase.h:525
void setPhaseMoles(const size_t n, const double moles)
Set the number of moles of phase with index n.
double elementMoles(size_t m) const
Total moles of global element m, summed over all phases.
string phaseName(size_t iph) const
Returns the name of the n'th phase.
double m_Tmax
Minimum temperature for which thermo parameterizations are valid.
Definition MultiPhase.h:606
Base class for a phase with thermodynamic properties.
void equilibrate(const string &XY, const string &solver="auto", double rtol=1e-9, int max_steps=50000, int max_iter=100, int estimate_equil=0, int log_level=0)
Equilibrate a MultiPhase object.
size_t BasisOptimize(bool &usedZeroedSpecies, bool doFormRxn, MultiPhase *mphase, span< size_t > orderVectorSpecies, span< size_t > orderVectorElements, span< double > formRxnMatrix)
Choose the optimum basis of species for the equilibrium calculations.
void ElemRearrange(size_t nComponents, span< const double > elementAbundances, MultiPhase *mphase, span< size_t > orderVectorSpecies, span< size_t > orderVectorElements)
Handles the potential rearrangement of the constraint equations represented by the Formula Matrix.
const double OneBar
One bar [Pa].
Definition ct_defs.h:102
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:183
int BasisOptimize_print_lvl
External int that is used to turn on debug printing for the BasisOptimize program.
std::ostream & operator<<(std::ostream &s, const Array2D &m)
Output the current contents of the Array2D object.
Definition Array.cpp:101
map< string, double > Composition
Map from string names to doubles.
Definition ct_defs.h:180