Cantera  3.3.0a1
Loading...
Searching...
No Matches
vcs_solve.h
Go to the documentation of this file.
1/**
2 * @file vcs_solve.h Header file for the internal object that holds the vcs
3 * equilibrium problem (see Class @link Cantera::VCS_SOLVE
4 * VCS_SOLVE@endlink and @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 _VCS_SOLVE_H
11#define _VCS_SOLVE_H
12
13/*
14* Index of Symbols
15* -------------------
16* irxn -> refers to the species or rxn between the species and
17* the components in the problem
18* k -> refers to the species
19* j -> refers to the element or component
20*
21* ### -> to be eliminated
22*/
23
27#include "cantera/base/Array.h"
28
29namespace Cantera
30{
31
32class vcs_VolPhase;
33class VCS_COUNTERS;
34class MultiPhase;
35
36//! This is the main structure used to hold the internal data
37//! used in vcs_solve_TP(), and to solve TP systems.
38/*!
39 * The indices of information in this structure may change when the species
40 * basis changes or when phases pop in and out of existence. Both of these
41 * operations change the species ordering.
42 */
44{
45public:
46 //! Initialize the sizes within the VCS_SOLVE object
47 /*!
48 * This resizes all of the internal arrays within the object.
49 */
50 VCS_SOLVE(MultiPhase* mphase, int printLvl=0);
51
52 ~VCS_SOLVE();
53
54 //! Main routine that solves for equilibrium at constant T and P using a
55 //! variant of the VCS method
56 /*!
57 * Any number of single-species phases and multi-species phases, including non-ideal
58 * phases, can be handled by the present version.
59 *
60 * @param print_lvl 1 -> Print results to standard output;
61 * 0 -> don't report on anything
62 * @param printDetails 1 -> Print intermediate results.
63 * @param maxit Maximum number of iterations for the algorithm
64 * @return
65 * * 0 = Equilibrium Achieved
66 * * 1 = Range space error encountered. The element abundance criteria
67 * are only partially satisfied. Specifically, the first NC= (number
68 * of components) conditions are satisfied. However, the full NE
69 * (number of elements) conditions are not satisfied. The
70 * equilibrium condition is returned.
71 * * -1 = Maximum number of iterations is exceeded. Convergence was
72 * not found.
73 */
74 int solve_TP(int print_lvl, int printDetails, int maxit);
75
76 /**
77 * We make decisions on the initial mole number, and major-minor status
78 * here. We also fix up the total moles in a phase.
79 *
80 * irxn = id of the noncomponent species formation reaction for the
81 * species to be added in.
82 *
83 * The algorithm proceeds to implement these decisions in the previous
84 * position of the species. Then, vcs_switch_pos is called to move the
85 * species into the last active species slot, incrementing the number of
86 * active species at the same time.
87 *
88 * This routine is responsible for the global data manipulation only.
89 */
90 void vcs_reinsert_deleted(size_t kspec);
91
92 //! Choose the optimum species basis for the calculations
93 /*!
94 * This is done by choosing the species with the largest mole fraction not
95 * currently a linear combination of the previous components. Then,
96 * calculate the stoichiometric coefficient matrix for that basis.
97 *
98 * Rearranges the solution data to put the component data at the
99 * front of the species list.
100 *
101 * Then, calculates `m_stoichCoeffRxnMatrix(jcomp,irxn)` the formation
102 * reactions for all noncomponent species in the mechanism. Also
103 * calculates DNG(I) and DNL(I), the net mole change for each formation
104 * reaction. Also, initializes IR(I) to the default state.
105 *
106 * @param[in] doJustComponents If true, the #m_stoichCoeffRxnMatrix and
107 * #m_deltaMolNumPhase are not calculated.
108 * @param[in] test This is a small negative number dependent upon whether
109 * an estimate is supplied or not.
110 *
111 * ### Internal Variables calculated by this routine:
112 *
113 * - #m_numComponents: Number of component species. This routine
114 * calculates the #m_numComponents species. It switches their positions
115 * in the species vector so that they occupy the first #m_numComponents
116 * spots in the species vector.
117 * - `m_stoichCoeffRxnMatrix(jcomp,irxn)` Stoichiometric coefficient
118 * matrix for the reaction mechanism expressed in Reduced Canonical
119 * Form. jcomp refers to the component number, and irxn refers to the
120 * irxn_th non-component species.
121 * - `m_deltaMolNumPhase(iphase,irxn)`: Change in the number of moles in
122 * phase, iphase, due to the noncomponent formation reaction, irxn.
123 * - `m_phaseParticipation(iphase,irxn)`: This is 1 if the phase, iphase,
124 * participates in the formation reaction, irxn, and zero otherwise.
125 */
126 void vcs_basopt(const bool doJustComponents, double test);
127
128 //! Evaluate the species category for the indicated species
129 /*!
130 * All evaluations are done using the "old" version of the solution.
131 *
132 * @param kspec Species to be evaluated
133 * @returns the calculated species type
134 */
135 int vcs_species_type(const size_t kspec) const;
136
137 //! This routine evaluates the species type for all species
138 /*!
139 * - #VCS_SPECIES_MAJOR: Major species
140 * - #VCS_SPECIES_MINOR: Minor species
141 * - #VCS_SPECIES_ZEROEDMS: The species lies in a multicomponent phase
142 * which currently doesn't exist. Its concentration is currently zero.
143 * - #VCS_SPECIES_ZEROEDSS: Species lies in a single-species phase which
144 * is currently zeroed out.
145 * - #VCS_SPECIES_DELETED: Species has such a small mole fraction it is
146 * deleted even though its phase may possibly exist. The species is
147 * believed to have such a small mole fraction that it best to throw
148 * the calculation of it out. It will be added back in at the end of
149 * the calculation.
150 * - #VCS_SPECIES_INTERFACIALVOLTAGE: Species refers to an electron in
151 * the metal The unknown is equal to the interfacial voltage drop
152 * across the interface on the SHE (standard hydrogen electrode) scale
153 * (volts).
154 * - #VCS_SPECIES_ZEROEDPHASE: Species lies in a multicomponent phase
155 * that is zeroed atm and will stay deleted due to a choice from a
156 * higher level. These species will formally always have zero mole
157 * numbers in the solution vector.
158 * - #VCS_SPECIES_ACTIVEBUTZERO: The species lies in a multicomponent
159 * phase which currently does exist. Its concentration is currently
160 * identically zero, though the phase exists. Note, this is a temporary
161 * condition that exists at the start of an equilibrium problem. The
162 * species is soon "birthed" or "deleted".
163 * - #VCS_SPECIES_STOICHZERO: The species lies in a multicomponent phase
164 * which currently does exist. Its concentration is currently
165 * identically zero, though the phase exists. This is a permanent
166 * condition due to stoich constraints
167 */
169
170 //! Calculate the dimensionless chemical potentials of all species or
171 //! of certain groups of species, at a fixed temperature and pressure.
172 /*!
173 * We calculate the dimensionless chemical potentials of all species or
174 * certain groups of species here, at a fixed temperature and pressure, for
175 * the input mole vector z[] in the parameter list. Nondimensionalization is
176 * achieved by division by RT.
177 *
178 * Note, for multispecies phases which are currently zeroed out, the
179 * chemical potential is filled out with the standard chemical potential.
180 *
181 * For species in multispecies phases whose concentration is zero, we need
182 * to set the mole fraction to a very low value. Its chemical potential is
183 * then calculated using the VCS_DELETE_MINORSPECIES_CUTOFF concentration
184 * to keep numbers positive.
185 *
186 * For formulas, see vcs_chemPotPhase().
187 *
188 * Handling of Small Species:
189 * ------------------------------
190 * As per the discussion above, for small species where the mole fraction
191 *
192 * z(i) < VCS_DELETE_MINORSPECIES_CUTOFF
193 *
194 * The chemical potential is calculated as:
195 *
196 * m_feSpecies(I)(I) = m_SSfeSpecies(I) + ln(ActCoeff[i](VCS_DELETE_MINORSPECIES_CUTOFF))
197 *
198 * Species in the following categories are treated as "small species"
199 * - #VCS_SPECIES_DELETED
200 * - #VCS_SPECIES_ACTIVEBUTZERO
201 *
202 * For species in multispecies phases which are currently not active, the
203 * treatment is different. These species are in the following species
204 * categories:
205 * - #VCS_SPECIES_ZEROEDMS
206 * - #VCS_SPECIES_ZEROEDPHASE
207 *
208 * For these species, the `ln( ActCoeff[I] X[I])` term is dropped
209 * altogether. The following equation is used:
210 *
211 * m_feSpecies(I) = m_SSfeSpecies(I)
212 * + Charge[I] * Faraday_dim * phasePhi[iphase];
213 *
214 * Handling of "Species" Representing Interfacial Voltages
215 * ---------------------------------------------------------
216 *
217 * These species have species types of
218 * #VCS_SPECIES_TYPE_INTERFACIALVOLTAGE The chemical potentials for these
219 * "species" refer to electrons in metal electrodes. They have the
220 * following formula
221 *
222 * m_feSpecies(I) = m_SSfeSpecies(I) - F z[I] / RT
223 *
224 * - `F` is Faraday's constant.
225 * - `R` = gas constant
226 * - `T` = temperature
227 * - `V` = potential of the interface = phi_electrode - phi_solution
228 *
229 * For these species, the solution vector unknown, z[I], is V, the phase
230 * voltage, in volts.
231 *
232 * @param ll Determine which group of species gets updated
233 * - `ll = 0`: Calculate for all species
234 * - `ll < 0`: calculate for components and for major non-components
235 * - `ll = 1`: calculate for components and for minor non-components
236 *
237 * @param lbot Restricts the calculation of the chemical potential
238 * to the species between LBOT <= i < LTOP. Usually
239 * LBOT and LTOP will be equal to 0 and MR, respectively.
240 * @param ltop Top value of the loops
241 *
242 * @param stateCalc Determines whether z is old or new or tentative:
243 * - 1: Use the tentative values for the total number of
244 * moles in the phases, that is, use TG1 instead of TG etc.
245 * - 0: Use the base values of the total number of
246 * moles in each system.
247 *
248 * Also needed:
249 * ff : standard state chemical potentials. These are the
250 * chemical potentials of the standard states at
251 * the same T and P as the solution.
252 * tg : Total Number of moles in the phase.
253 */
254 void vcs_dfe(const int stateCalc, const int ll, const size_t lbot, const size_t ltop);
255
256 //! This routine uploads the state of the system into all of the
257 //! vcs_VolumePhase objects in the current problem.
258 /*!
259 * @param stateCalc Determines where to get the mole numbers from.
260 * - VCS_STATECALC_OLD -> from m_molNumSpecies_old
261 * - VCS_STATECALC_NEW -> from m_molNumSpecies_new
262 */
263 void vcs_updateVP(const int stateCalc);
264
265 //! Utility function that evaluates whether a phase can be popped
266 //! into existence
267 /*!
268 * A phase can be popped iff the stoichiometric coefficients for the
269 * component species, whose concentrations will be lowered during the
270 * process, are positive by at least a small degree.
271 *
272 * If one of the phase species is a zeroed component, then the phase can
273 * be popped if the component increases in mole number as the phase moles
274 * are increased.
275 *
276 * @param iphasePop id of the phase, which is currently zeroed,
277 * @returns true if the phase can come into existence and false otherwise.
278 */
279 bool vcs_popPhasePossible(const size_t iphasePop) const;
280
281 //! Decision as to whether a phase pops back into existence
282 /*!
283 * @param phasePopPhaseIDs Vector containing the phase ids of the phases
284 * that will be popped this step.
285 * @returns the phase id of the phase that pops back into existence. Returns
286 * -1 if there are no phases
287 */
288 size_t vcs_popPhaseID(vector<size_t> &phasePopPhaseIDs);
289
290 //! Calculates the deltas of the reactions due to phases popping
291 //! into existence
292 /*!
293 * Updates #m_deltaMolNumSpecies[irxn] : reaction adjustments, where irxn
294 * refers to the irxn'th species formation reaction. This adjustment is
295 * for species irxn + M, where M is the number of components.
296 *
297 * @param iphasePop Phase id of the phase that will come into existence
298 * @returns an int representing the status of the step
299 * - 0 : normal return
300 * - 1 : A single species phase species has been zeroed out
301 * in this routine. The species is a noncomponent
302 * - 2 : Same as one but, the zeroed species is a component.
303 * - 3 : Nothing was done because the phase couldn't be birthed
304 * because a needed component is zero.
305 */
306 int vcs_popPhaseRxnStepSizes(const size_t iphasePop);
307
308 //! Calculates formation reaction step sizes.
309 /*!
310 * This is equation 6.4-16, p. 143 in Smith and Missen @cite smith1982.
311 *
312 * Output
313 * -------
314 * m_deltaMolNumSpecies(irxn) : reaction adjustments, where irxn refers to
315 * the irxn'th species formation reaction.
316 * This adjustment is for species irxn + M,
317 * where M is the number of components.
318 *
319 * Special branching occurs sometimes. This causes the component basis
320 * to be reevaluated
321 *
322 * @param forceComponentCalc integer flagging whether a component
323 * recalculation needs to be carried out.
324 * @param kSpecial species number of phase being zeroed.
325 * @returns an int representing which phase may need to be zeroed
326 */
327 size_t vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial);
328
329 //! Calculates the total number of moles of species in all phases.
330 /*!
331 * Also updates the variable m_totalMolNum and Reconciles Phase existence
332 * flags with total moles in each phase.
333 */
334 double vcs_tmoles();
335
336 void check_tmoles() const;
337
338 //! This subroutine calculates reaction free energy changes for
339 //! all noncomponent formation reactions.
340 /*!
341 * Formation reactions are
342 * reactions which create each noncomponent species from the component
343 * species. `m_stoichCoeffRxnMatrix(jcomp,irxn)` are the stoichiometric
344 * coefficients for these reactions. A stoichiometric coefficient of
345 * one is assumed for species irxn in this reaction.
346 *
347 * @param L
348 * - `L < 0`: Calculate reactions corresponding to major noncomponent
349 * and zeroed species only
350 * - `L = 0`: Do all noncomponent reactions, i, between
351 * 0 <= i < irxnl
352 * - `L > 0`: Calculate reactions corresponding to minor noncomponent
353 * and zeroed species only
354 *
355 * @param doDeleted Do deleted species
356 * @param vcsState Calculate deltaG corresponding to either old or new
357 * free energies
358 * @param alterZeroedPhases boolean indicating whether we should
359 * add in a special section for zeroed phases.
360 *
361 * Note we special case one important issue. If the component has zero
362 * moles, then we do not allow deltaG < 0.0 for formation reactions which
363 * would lead to the loss of more of that same component. This dG < 0.0
364 * condition feeds back into the algorithm in several places, and leads
365 * to a infinite loop in at least one case.
366 */
367 void vcs_deltag(const int L, const bool doDeleted, const int vcsState,
368 const bool alterZeroedPhases = true);
369
370 //! Swaps the indices for all of the global data for two species, k1
371 //! and k2.
372 /*!
373 * @param ifunc If true, switch the species data and the noncomponent
374 * reaction data. This must be called for a non-component species only.
375 * If false, switch the species data only. Typically, we use this option
376 * when determining the component species and at the end of the
377 * calculation, when we want to return unscrambled results. All rxn data
378 * will be out-of-date.
379 * @param k1 First species index
380 * @param k2 Second species index
381 */
382 void vcs_switch_pos(const bool ifunc, const size_t k1, const size_t k2);
383
384 //! Main program to test whether a deleted phase should be brought
385 //! back into existence
386 /*!
387 * @param iph Phase id of the deleted phase
388 */
389 double vcs_phaseStabilityTest(const size_t iph);
390
391 /**
392 * Evaluate the standard state free energies at the current temperature
393 * and pressure. Ideal gas pressure contribution is added in here.
394 *
395 * @param ipr 1 -> Print results to standard output; 0 -> don't report
396 * on anything
397 * @param ip1 1 -> Print intermediate results; 0 -> don't.
398 * @param Temp Temperature (Kelvin)
399 * @param pres Pressure (Pascal)
400 */
401 int vcs_evalSS_TP(int ipr, int ip1, double Temp, double pres);
402
403 //! This routine is mostly concerned with changing the private data to be
404 //! consistent with what's needed for solution. It is called one time for
405 //! each new problem structure definition.
406 /*!
407 * The problem structure refers to:
408 *
409 * - the number and identity of the species.
410 * - the formula matrix and thus the number of components.
411 * - the number and identity of the phases.
412 * - the equation of state
413 * - the method and parameters for determining the standard state
414 * - The method and parameters for determining the activity coefficients.
415 *
416 * Tasks:
417 * 1. Fill in the SSPhase[] array.
418 * 2. Check to see if any multispecies phases actually have only one
419 * species in that phase. If true, reassign that phase and species
420 * to be a single-species phase.
421 * 3. Determine the number of components in the problem if not already
422 * done so. During this process the order of the species is changed
423 * in the private data structure. All references to the species
424 * properties must employ the ind[] index vector.
425 * 4. Initialization of arrays to zero.
426 * 5. Check to see if the problem is well posed (If all the element
427 * abundances are zero, the algorithm will fail)
428 *
429 * @param printLvl Print level of the routine
430 */
431 void vcs_prep(int printLvl);
432
433 //! Rearrange the constraint equations represented by the Formula
434 //! Matrix so that the operational ones are in the front
435 /*!
436 * This subroutine handles the rearrangement of the constraint equations
437 * represented by the Formula Matrix. Rearrangement is only necessary when
438 * the number of components is less than the number of elements. For this
439 * case, some constraints can never be satisfied exactly, because the
440 * range space represented by the Formula Matrix of the components can't
441 * span the extra space. These constraints, which are out of the range
442 * space of the component Formula matrix entries, are migrated to the back
443 * of the Formula matrix.
444 *
445 * A prototypical example is an extra element column in FormulaMatrix[],
446 * which is identically zero. For example, let's say that argon is has an
447 * element column in FormulaMatrix[], but no species in the mechanism
448 * actually contains argon. Then, nc < ne. Also, without perturbation of
449 * FormulaMatrix[] vcs_basopt[] would produce a zero pivot because the
450 * matrix would be singular (unless the argon element column was already
451 * the last column of FormulaMatrix[].
452 *
453 * This routine borrows heavily from vcs_basopt's algorithm. It finds nc
454 * constraints which span the range space of the Component Formula matrix,
455 * and assigns them as the first nc components in the formula matrix. This
456 * guarantees that vcs_basopt[] has a nonsingular matrix to invert.
457 */
458 void vcs_elem_rearrange();
459
460 //! Swaps the indices for all of the global data for two elements, ipos
461 //! and jpos.
462 /*!
463 * This function knows all of the element information with VCS_SOLVE, and
464 * can therefore switch element positions
465 *
466 * @param ipos first global element index
467 * @param jpos second global element index
468 */
469 void vcs_switch_elem_pos(size_t ipos, size_t jpos);
470
471 //! Calculates the diagonal contribution to the Hessian due to
472 //! the dependence of the activity coefficients on the mole numbers.
473 /*!
474 * (See framemaker notes, Eqn. 20 - VCS Equations document)
475 *
476 * We allow the diagonal to be increased positively to any degree.
477 * We allow the diagonal to be decreased to 1/3 of the ideal solution
478 * value, but no more -> it must remain positive.
479 */
480 double vcs_Hessian_diag_adj(size_t irxn, double hessianDiag_Ideal);
481
482 //! Calculates the diagonal contribution to the Hessian due to
483 //! the dependence of the activity coefficients on the mole numbers.
484 /*!
485 * (See framemaker notes, Eqn. 20 - VCS Equations document)
486 */
487 double vcs_Hessian_actCoeff_diag(size_t irxn);
488
489 //! Recalculate all of the activity coefficients in all of the phases
490 //! based on input mole numbers
491 /**
492 * @param moleSpeciesVCS kmol of species to be used in the update.
493 *
494 * NOTE: This routine needs to be regulated.
495 */
496 void vcs_CalcLnActCoeffJac(const double* const moleSpeciesVCS);
497
498 //! Print out a report on the state of the equilibrium problem to
499 //! standard output.
500 /*!
501 * @param iconv Indicator of convergence, to be printed out in the report:
502 * - 0 converged
503 * - 1 range space error
504 * - -1 not converged
505 */
506 void vcs_report(int iconv);
507
508 //! Computes the current elemental abundances vector
509 /*!
510 * Computes the elemental abundances vector, m_elemAbundances[], and stores
511 * it back into the global structure
512 */
513 void vcs_elab();
514
515 /**
516 * Checks to see if the element abundances are in compliance. If they are,
517 * then TRUE is returned. If not, FALSE is returned. Note the number of
518 * constraints checked is usually equal to the number of components in the
519 * problem. This routine can check satisfaction of all of the constraints
520 * in the problem, which is equal to ne. However, the solver can't fix
521 * breakage of constraints above nc, because that nc is the range space by
522 * definition. Satisfaction of extra constraints would have had to occur
523 * in the problem specification.
524 *
525 * The constraints should be broken up into 2 sections. If a constraint
526 * involves a formula matrix with positive and negative signs, and eaSet =
527 * 0.0, then you can't expect that the sum will be zero. There may be
528 * roundoff that inhibits this. However, if the formula matrix is all of
529 * one sign, then this requires that all species with nonzero entries in
530 * the formula matrix be identically zero. We put this into the logic
531 * below.
532 *
533 * @param ibound 1: Checks constraints up to the number of elements;
534 * 0: Checks constraints up to the number of components.
535 */
536 bool vcs_elabcheck(int ibound);
537
538
539 /**
540 * This subroutine corrects for element abundances. At the end of the
541 * subroutine, the total moles in all phases are recalculated again,
542 * because we have changed the number of moles in this routine.
543 *
544 * @param aa temporary work vector, length ne*ne
545 * @param x temporary work vector, length ne
546 *
547 * @returns
548 * - 0 = Nothing of significance happened, Element abundances were and
549 * still are good.
550 * - 1 = The solution changed significantly; The element abundances are
551 * now good.
552 * - 2 = The solution changed significantly, The element abundances are
553 * still bad.
554 * - 3 = The solution changed significantly, The element abundances are
555 * still bad and a component species got zeroed out.
556 *
557 * Internal data to be worked on::
558 * - ga Current element abundances
559 * - m_elemAbundancesGoal Required elemental abundances
560 * - m_molNumSpecies_old Current mole number of species.
561 * - m_formulaMatrix[][] Formula matrix of the species
562 * - ne Number of elements
563 * - nc Number of components.
564 *
565 * NOTES:
566 * This routine is turning out to be very problematic. There are
567 * lots of special cases and problems with zeroing out species.
568 *
569 * Still need to check out when we do loops over nc vs. ne.
570 */
571 int vcs_elcorr(double aa[], double x[]);
572
573 //! Create an initial estimate of the solution to the equilibrium problem.
574 void vcs_inest();
575
576 //! Estimate the initial mole numbers by constrained linear programming
577 /*!
578 * This is done by running each reaction as far forward or backward as
579 * possible, subject to the constraint that all mole numbers remain non-
580 * negative. Reactions for which @f$ \Delta \mu^0 @f$ are positive are run
581 * in reverse, and ones for which it is negative are run in the forward
582 * direction. The end result is equivalent to solving the linear
583 * programming problem of minimizing the linear Gibbs function subject to
584 * the element and non-negativity constraints.
585 */
587
588 //! Calculate the total dimensionless Gibbs free energy
589 /*!
590 * Note, for this algorithm this function should be monotonically decreasing.
591 */
592 double vcs_Total_Gibbs(double* w, double* fe, double* tPhMoles);
593
594 //! Fully specify the problem to be solved
596
597private:
598 //! Zero out the concentration of a species.
599 /*!
600 * Make sure to conserve elements and keep track of the total moles in all
601 * phases.
602 * - w[]
603 * - m_tPhaseMoles_old[]
604 *
605 * @param kspec Species index
606 * @return:
607 * 1: succeeded
608 * 0: failed.
609 */
610 int vcs_zero_species(const size_t kspec);
611
612 //! Change a single species from active to inactive status
613 /*!
614 * Rearrange data when species is added or removed. The Lth species is
615 * moved to the back of the species vector. The back of the species
616 * vector is indicated by the value of MR, the current number of
617 * active species in the mechanism.
618 *
619 * @param kspec Species Index
620 * @return
621 * Returns 0 unless.
622 * The return is 1 when the current number of
623 * noncomponent species is equal to zero. A recheck of deleted species
624 * is carried out in the main code.
625 */
626 int vcs_delete_species(const size_t kspec);
627
628 //! This routine handles the bookkeeping involved with the deletion of
629 //! multiphase phases from the problem.
630 /*!
631 * When they are deleted, all of their species become active species, even
632 * though their mole numbers are set to zero. The routine does not make the
633 * decision to eliminate multiphases.
634 *
635 * Note, species in phases with zero mole numbers are still considered
636 * active. Whether the phase pops back into existence or not is checked as
637 * part of the main iteration loop.
638 *
639 * @param iph Phase to be deleted
640 * @returns whether the operation was successful or not
641 */
642 bool vcs_delete_multiphase(const size_t iph);
643
644 //! Change the concentration of a species by delta moles.
645 /*!
646 * Make sure to conserve elements and keep track of the total kmoles in
647 * all phases.
648 *
649 * @param kspec The species index
650 * @param delta_ptr pointer to the delta for the species. This may
651 * change during the calculation
652 * @return
653 * 1: succeeded without change of dx
654 * 0: Had to adjust dx, perhaps to zero, in order to do the delta.
655 */
656 int delta_species(const size_t kspec, double* const delta_ptr);
657
658 //! Provide an estimate for the deleted species in phases that are not
659 //! zeroed out
660 /*!
661 * Try to add back in all deleted species. An estimate of the kmol numbers
662 * are obtained and the species is added back into the equation system, into
663 * the old state vector.
664 *
665 * This routine is called at the end of the calculation, just before
666 * returning to the user.
667 */
668 size_t vcs_add_all_deleted();
669
670 //! Recheck deleted species in multispecies phases.
671 /*!
672 * We are checking the equation:
673 *
674 * sum_u = sum_j_comp [ sigma_i_j * u_j ]
675 * = u_i_O + \ln((AC_i * W_i)/m_tPhaseMoles_old)
676 *
677 * by first evaluating:
678 *
679 * DG_i_O = u_i_O - sum_u.
680 *
681 * Then, if TL is zero, the phase pops into existence if DG_i_O < 0. Also,
682 * if the phase exists, then we check to see if the species can have a mole
683 * number larger than VCS_DELETE_SPECIES_CUTOFF (default value = 1.0E-32).
684 */
686
687 //! Minor species alternative calculation
688 /*!
689 * This is based upon the following approximation: The mole fraction
690 * changes due to these reactions don't affect the mole numbers of the
691 * component species. Therefore the following approximation is valid for
692 * a small component of an ideal phase:
693 *
694 * 0 = m_deltaGRxn_old(I) + log(molNum_new(I)/molNum_old(I))
695 *
696 * `m_deltaGRxn_old` contains the contribution from
697 *
698 * m_feSpecies_old(I) =
699 * m_SSfeSpecies(I) +
700 * log(ActCoeff[i] * molNum_old(I) / m_tPhaseMoles_old(iph))
701 * Thus,
702 *
703 * molNum_new(I)= molNum_old(I) * EXP(-m_deltaGRxn_old(I))
704 *
705 * Most of this section is mainly restricting the update to reasonable
706 * values. We restrict the update a factor of 1.0E10 up and 1.0E-10 down
707 * because we run into trouble with the addition operator due to roundoff if
708 * we go larger than ~1.0E15. Roundoff will then sometimes produce zero mole
709 * fractions.
710 *
711 * Note: This routine was generalized to incorporate nonideal phases and
712 * phases on the molality basis
713 *
714 * @param[in] kspec The current species and corresponding formation
715 * reaction number.
716 * @param[in] irxn The current species and corresponding formation
717 * reaction number.
718 * @param[out] do_delete: BOOLEAN which if true on return, then we
719 * branch to the section that deletes a species
720 * from the current set of active species.
721 */
722 double vcs_minor_alt_calc(size_t kspec, size_t irxn, bool* do_delete) const;
723
724 //! This routine optimizes the minimization of the total Gibbs free energy
725 //! by making sure the slope of the following functional stays negative:
726 /*!
727 * The slope of the following functional is equivalent to the slope of the
728 * total Gibbs free energy of the system:
729 *
730 * d_Gibbs/ds = sum_k( m_deltaGRxn * m_deltaMolNumSpecies[k] )
731 *
732 * along the current direction m_deltaMolNumSpecies[], by choosing a value, al: (0<al<1)
733 * such that the a parabola approximation to Gibbs(al) fit to the
734 * end points al = 0 and al = 1 is minimized.
735 * - s1 = slope of Gibbs function at al = 0, which is the previous
736 * solution = d(Gibbs)/d(al).
737 * - s2 = slope of Gibbs function at al = 1, which is the current
738 * solution = d(Gibbs)/d(al).
739 *
740 * Only if there has been an inflection point (that is, s1 < 0 and s2 > 0),
741 * does this code section kick in. It finds the point on the parabola
742 * where the slope is equal to zero.
743 */
744 bool vcs_globStepDamp();
745
746 //! Calculate the norm of a deltaGibbs free energy vector
747 /*!
748 * Positive DG for species which don't exist are ignored.
749 *
750 * @param dg Vector of local delta G's.
751 */
752 double l2normdg(double dg[]) const;
753
754 void checkDelta1(double* const ds, double* const delTPhMoles, size_t kspec);
755
756 //! Calculate the status of single species phases.
757 void vcs_SSPhase();
758
759 //! Initialize the internal counters
760 /*!
761 * Initialize the internal counters tracking subroutine calls.
762 *
763 * ifunc = 0 Initialize only those counters appropriate for the top of
764 * vcs_solve_TP().
765 * = 1 Initialize all counters.
766 */
767 void vcs_counters_init(int ifunc);
768
769 //! Create a report on the plog file containing iteration counters
771
772 void vcs_setFlagsVolPhases(const bool upToDate, const int stateCalc);
773
774 //! Update all underlying vcs_VolPhase objects
775 /*!
776 * Update the mole numbers and the phase voltages of all phases in the vcs
777 * problem
778 *
779 * @param stateCalc Location of the update (either VCS_STATECALC_NEW or
780 * VCS_STATECALC_OLD).
781 */
782 void vcs_updateMolNumVolPhases(const int stateCalc);
783
784 // Helper functions used internally by vcs_solve_TP
785 void solve_tp_component_calc(bool& allMinorZeroedSpecies);
786 void solve_tp_inner(size_t& iti, size_t& it1, bool& uptodate_minors,
787 bool& allMinorZeroedSpecies, int& forceComponentCalc,
788 int& stage, bool printDetails);
789 void solve_tp_equilib_check(bool& allMinorZeroedSpecies, bool& uptodate_minors,
790 bool& giveUpOnElemAbund, int& solveFail,
791 size_t& iti, size_t& it1, int maxit,
792 int& stage, bool& lec);
793 void solve_tp_elem_abund_check(size_t& iti, int& stage, bool& lec,
794 bool& giveUpOnElemAbund,
795 int& finalElemAbundAttempts,
796 int& rangeErrorFound);
797
798 vector<double> m_sm; //!< QR matrix work space used in vcs_basopt()
799 vector<double> m_ss; //!< Gram-Schmidt work space used in vcs_basopt()
800 vector<double> m_sa; //!< Gram-Schmidt work space used in vcs_basopt()
801 vector<double> m_aw; //!< work array of mole fractions used in vcs_basopt()
802 vector<double> m_wx;
803
804public:
805 //! Print level for print routines
807
808 MultiPhase* m_mix;
809
810 //! Print out the problem specification in all generality as it currently
811 //! exists in the VCS_SOLVE object
812 /*!
813 * @param print_lvl Parameter lvl for printing
814 * * 0 - no printing
815 * * 1 - all printing
816 */
817 void prob_report(int print_lvl);
818
819 //! Add elements to the local element list
820 //! This routines adds entries for the formula matrix for one species
821 /*!
822 * This routines adds entries for the formula matrix for this object for one
823 * species
824 *
825 * This object also fills in the index filed, IndSpecies, within the
826 * volPhase object.
827 *
828 * @param volPhase object containing the species
829 * @param k Species number within the volPhase k
830 * @param kT global Species number within this object
831 *
832 */
833 size_t addOnePhaseSpecies(vcs_VolPhase* volPhase, size_t k, size_t kT);
834
835 //! This routine resizes the number of elements in the VCS_SOLVE object by
836 //! adding a new element to the end of the element list
837 /*!
838 * The element name is added. Formula vector entries ang element abundances
839 * for the new element are set to zero.
840 *
841 * @param elNameNew New name of the element
842 * @param elType Type of the element
843 * @param elactive boolean indicating whether the element is active
844 * @returns the index number of the new element
845 */
846 size_t addElement(const char* elNameNew, int elType, int elactive);
847
848 //! Return the index of an element by name, or npos if not found
849 size_t elementIndex(const string& elementName) const;
850
851 //! Total number of species in the problems
852 size_t m_nsp;
853
854 //! Number of element constraints in the problem
855 size_t m_nelem = 0;
856
857 //! Number of components calculated for the problem
858 size_t m_numComponents = 0;
859
860 //! Total number of non-component species in the problem
861 size_t m_numRxnTot = 0;
862
863 //! Current number of species in the problems. Species can be deleted if
864 //! they aren't stable under the current conditions
866
867 //! Current number of non-component species in the problem. Species can be
868 //! deleted if they aren't stable under the current conditions
869 size_t m_numRxnRdc = 0;
870
871 //! Number of active species which are currently either treated as
872 //! minor species
874
875 //! Number of Phases in the problem
877
878 //! Formula matrix for the problem
879 /*!
880 * FormulaMatrix(kspec,j) = Number of elements, j, in the kspec species
881 *
882 * Both element and species indices are swapped.
883 */
885
886 //! Stoichiometric coefficient matrix for the reaction mechanism expressed
887 //! in Reduced Canonical Form.
888 /*!
889 * This is the stoichiometric coefficient matrix for the reaction which
890 * forms species kspec from the component species. A stoichiometric
891 * coefficient of one is assumed for the species kspec in this mechanism.
892 *
893 * NOTE: kspec = irxn + m_numComponents
894 *
895 * `m_stoichCoeffRxnMatrix(j,irxn)` : j refers to the component number, and
896 * irxn refers to the irxn_th non-component species. The stoichiometric
897 * coefficients multiplied by the Formula coefficients of the component
898 * species add up to the negative value of the number of elements in the
899 * species kspec.
900 *
901 * size = nelements0 x nspecies0
902 */
904
905 //! Absolute size of the stoichiometric coefficients
906 /*!
907 * scSize[irxn] = abs(Size) of the stoichiometric coefficients. These are
908 * used to determine whether a given species should be
909 * handled by the alt_min treatment or should be handled as a
910 * major species.
911 */
912 vector<double> m_scSize;
913
914 //! total size of the species
915 /*!
916 * This is used as a multiplier to the mole number in figuring out which
917 * species should be components.
918 */
919 vector<double> m_spSize;
920
921 //! Standard state chemical potentials for species K at the current
922 //! temperature and pressure.
923 /*!
924 * The first NC entries are for components. The following NR entries are
925 * for the current non-component species in the mechanism.
926 */
927 vector<double> m_SSfeSpecies;
928
929 //! Free energy vector from the start of the current iteration
930 /*!
931 * The free energies are saved at the start of the current iteration.
932 * Length = number of species
933 */
934 vector<double> m_feSpecies_old;
935
936 //! Dimensionless new free energy for all the species in the mechanism
937 //! at the new tentative T, P, and mole numbers.
938 /*!
939 * The first NC entries are for components. The following
940 * NR entries are for the current non-component species in the mechanism.
941 * Length = number of species
942 */
943 vector<double> m_feSpecies_new;
944
945 //! Setting for whether to do an initial estimate
946 /*!
947 * Initial estimate:
948 * 0 Do not estimate the solution at all. Use the
949 * supplied mole numbers as is.
950 * 1 Only do an estimate if the element abundances aren't satisfied.
951 * -1 Force an estimate of the soln. Throw out the input mole numbers.
952 */
954
955 //! Total moles of the species
956 /*!
957 * Total number of moles of the kth species.
958 * Length = Total number of species = m
959 */
960 vector<double> m_molNumSpecies_old;
961
962 //! Specifies the species unknown type
963 /*!
964 * There are two types. One is the straightforward species, with the mole
965 * number w[k], as the unknown. The second is the an interfacial voltage
966 * where w[k] refers to the interfacial voltage in volts.
967 *
968 * These species types correspond to metallic electrons corresponding to
969 * electrodes. The voltage and other interfacial conditions sets up an
970 * interfacial current, which is set to zero in this initial treatment.
971 * Later we may have non-zero interfacial currents.
972 */
974
975 //! Change in the number of moles of phase, iphase, due to the
976 //! noncomponent formation reaction, irxn, for species, k:
977 /*!
978 * m_deltaMolNumPhase(iphase,irxn) = k = nc + irxn
979 */
981
982 //! This is 1 if the phase, iphase, participates in the formation reaction
983 //! irxn, and zero otherwise. PhaseParticipation(iphase,irxn)
985
986 //! electric potential of the iph phase
987 vector<double> m_phasePhi;
988
989 //! Tentative value of the mole number vector. It's also used to store the
990 //! mole fraction vector.
991 vector<double> m_molNumSpecies_new;
992
993 //! Delta G(irxn) for the noncomponent species in the mechanism.
994 /*!
995 * Computed by the subroutine deltaG. m_deltaGRxn is the free energy change
996 * for the reaction which forms species K from the component species. This
997 * vector has length equal to the number of noncomponent species in the
998 * mechanism. It starts with the first current noncomponent species in the
999 * mechanism.
1000 */
1001 vector<double> m_deltaGRxn_new;
1002
1003 //! Last deltag[irxn] from the previous step
1004 vector<double> m_deltaGRxn_old;
1005
1006 //! Last deltag[irxn] from the previous step with additions for
1007 //! possible births of zeroed phases.
1009
1010 //! Temporary vector of Rxn DeltaG's
1011 /*!
1012 * This is used from time to time, for printing purposes
1013 */
1014 vector<double> m_deltaGRxn_tmp;
1015
1016 //! Reaction Adjustments for each species during the current step
1017 /*!
1018 * delta Moles for each species during the current step.
1019 * Length = number of species
1020 */
1021 vector<double> m_deltaMolNumSpecies;
1022
1023 //! Element abundances vector
1024 /*!
1025 * Vector of moles of each element actually in the solution vector. Except
1026 * for certain parts of the algorithm, this is a constant. Note other
1027 * constraint conditions are added to this vector. This is input from the
1028 * input file and is considered a constant from thereon. units = kmoles
1029 */
1030 vector<double> m_elemAbundances;
1031
1032 //! Element abundances vector Goals
1033 /*!
1034 * Vector of moles of each element that are the goals of the simulation.
1035 * This is a constant in the problem. Note other constraint conditions are
1036 * added to this vector. This is input from the input file and is considered
1037 * a constant from thereon. units = kmoles
1038 */
1039 vector<double> m_elemAbundancesGoal;
1040
1041 //! Total number of kmoles in all phases
1042 /*!
1043 * Don't use this except for scaling purposes
1044 */
1045 double m_totalMolNum = 0.0;
1046
1047 //! Total kmols of species in each phase
1048 /*!
1049 * This contains the total number of moles of species in each phase
1050 *
1051 * Length = number of phases
1052 */
1053 vector<double> m_tPhaseMoles_old;
1054
1055 //! total kmols of species in each phase in the tentative soln vector
1056 /*!
1057 * This contains the total number of moles of species in each phase
1058 * in the tentative solution vector
1059 *
1060 * Length = number of phases
1061 */
1062 vector<double> m_tPhaseMoles_new;
1063
1064 //! Temporary vector of length NPhase
1065 mutable vector<double> m_TmpPhase;
1066
1067 //! Temporary vector of length NPhase
1068 mutable vector<double> m_TmpPhase2;
1069
1070 //! Change in the total moles in each phase
1071 /*!
1072 * Length number of phases.
1073 */
1074 vector<double> m_deltaPhaseMoles;
1075
1076 //! Temperature (Kelvin)
1078
1079 //! Pressure
1081
1082 //! Tolerance requirement for major species
1083 double m_tolmaj= 1e-8;
1084
1085 //! Tolerance requirements for minor species
1086 double m_tolmin = 1e-6;
1087
1088 //! Below this, major species aren't refined any more
1089 double m_tolmaj2 = 1e-10;
1090
1091 //! Below this, minor species aren't refined any more
1092 double m_tolmin2 = 1e-8;
1093
1094 //! Index vector that keeps track of the species vector rearrangement
1095 /*!
1096 * At the end of each run, the species vector and associated data gets put
1097 * back in the original order.
1098 *
1099 * Example
1100 *
1101 * k = m_speciesMapIndex[kspec]
1102 *
1103 * kspec = current order in the vcs_solve object
1104 * k = original order in the MultiPhase object
1105 */
1106 vector<size_t> m_speciesMapIndex;
1107
1108 //! Index that keeps track of the index of the species within the local
1109 //! phase
1110 /*!
1111 * This returns the local index of the species within the phase. Its
1112 * argument is the global species index within the VCS problem.
1113 *
1114 * k = m_speciesLocalPhaseIndex[kspec]
1115 *
1116 * k varies between 0 and the nSpecies in the phase
1117 *
1118 * Length = number of species
1119 */
1121
1122 //! Index vector that keeps track of the rearrangement of the elements
1123 /*!
1124 * At the end of each run, the element vector and associated data gets
1125 * put back in the original order.
1126 *
1127 * Example
1128 *
1129 * e = m_elementMapIndex[eNum]
1130 * eNum = current order in the vcs_solve object
1131 * e = original order in the MultiPhase object
1132 */
1133 vector<size_t> m_elementMapIndex;
1134
1135 //! Mapping between the species index for noncomponent species and the
1136 //! full species index.
1137 /*!
1138 * ir[irxn] = Mapping between the reaction index for noncomponent
1139 * formation reaction of a species and the full species
1140 * index.
1141 *
1142 * Initially set to a value of K = NC + I This vector has length equal to
1143 * number of noncomponent species in the mechanism. It starts with the
1144 * first current noncomponent species in the mechanism. kspec = ir[irxn]
1145 */
1146 vector<size_t> m_indexRxnToSpecies;
1147
1148 //! Major -Minor status vector for the species in the problem
1149 /*!
1150 * The index for this is species. The reaction that this is referring to
1151 * is `kspec = irxn + m_numComponents`. For possible values and their
1152 * meanings, see vcs_evaluate_speciesType().
1153 */
1154 vector<int> m_speciesStatus;
1155
1156 //! Mapping from the species number to the phase number
1157 vector<size_t> m_phaseID;
1158
1159 //! Boolean indicating whether a species belongs to a single-species phase
1160 // vector<bool> can't be used here because it doesn't work with std::swap
1161 vector<char> m_SSPhase;
1162
1163 //! Species string name for the kth species
1164 vector<string> m_speciesName;
1165
1166 //! Vector of strings containing the element names
1167 /*!
1168 * ElName[j] = String containing element names
1169 */
1170 vector<string> m_elementName;
1171
1172 //! Type of the element constraint
1173 /*!
1174 * * 0 - #VCS_ELEM_TYPE_ABSPOS Normal element that is positive or zero in
1175 * all species.
1176 * * 1 - #VCS_ELEM_TYPE_ELECTRONCHARGE element dof that corresponds to
1177 * the electronic charge DOF.
1178 * * 2 - #VCS_ELEM_TYPE_CHARGENEUTRALITY element dof that corresponds to
1179 * a required charge neutrality constraint on the phase. The element
1180 * abundance is always exactly zero.
1181 */
1182 vector<int> m_elType;
1183
1184 //! Specifies whether an element constraint is active
1185 /*!
1186 * The default is true. Length = nelements
1187 */
1188 vector<int> m_elementActive;
1189
1190 //! Array of Phase Structures. Length = number of phases.
1191 vector<unique_ptr<vcs_VolPhase>> m_VolPhaseList;
1192
1193 //! specifies the activity convention of the phase containing the species
1194 /*!
1195 * * 0 = molar based
1196 * * 1 = molality based
1197 *
1198 * length = number of species
1199 */
1201
1202 //! specifies the activity convention of the phase.
1203 /*!
1204 * * 0 = molar based
1205 * * 1 = molality based
1206 *
1207 * length = number of phases
1208 */
1210
1211 //! specifies the ln(Mnaught) used to calculate the chemical potentials
1212 /*!
1213 * For molar based activity conventions this will be equal to 0.0.
1214 * length = number of species.
1215 */
1216 vector<double> m_lnMnaughtSpecies;
1217
1218 //! Molar-based Activity Coefficients for Species.
1219 //! Length = number of species
1221
1222 //! Molar-based Activity Coefficients for Species based on old mole numbers
1223 /*!
1224 * These activity coefficients are based on the m_molNumSpecies_old
1225 * values Molar based activity coefficients. Length = number of species
1226 */
1228
1229 //! Change in the log of the activity coefficient with respect to the mole
1230 //! number multiplied by the phase mole number
1231 /*!
1232 * size = nspecies x nspecies
1233 *
1234 * This is a temporary array that gets regenerated every time it's needed.
1235 * It is not swapped wrt species.
1236 */
1238
1239 //! Molecular weight of each species
1240 /*!
1241 * units = kg/kmol. length = number of species.
1242 *
1243 * note: this is a candidate for removal. I don't think we use it.
1244 */
1245 vector<double> m_wtSpecies;
1246
1247 //! Charge of each species. Length = number of species.
1248 vector<double> m_chargeSpecies;
1249
1250 vector<vector<size_t>> phasePopProblemLists_;
1251
1252 //! Choice of Hessians
1253 /*!
1254 * If this is true, then we will use a better approximation to the Hessian
1255 * based on Jacobian of the ln(ActCoeff) with respect to mole numbers
1256 */
1258
1259 //! Partial molar volumes of the species
1260 /*!
1261 * units = mks (m^3/kmol)
1262 * Length = number of species
1263 */
1264 vector<double> m_PMVolumeSpecies;
1265
1266 //! dimensionless value of Faraday's constant, F / RT (1/volt)
1268
1269 //! Timing and iteration counters for the vcs object
1271
1272 //! Debug printing lvl
1273 /*!
1274 * Levels correspond to the following guidelines
1275 * * 0 No printing at all
1276 * * 1 Serious warnings or fatal errors get one line
1277 * * 2 one line per each successful vcs package call
1278 * * 3 one line per every successful solve_TP calculation
1279 * * 4 one line for every successful operation -> solve_TP gets a summary report
1280 * * 5 each iteration in solve_TP gets a report with one line per species
1281 * * 6 Each decision in solve_TP gets a line per species in addition to 4
1282 * * 10 Additionally Hessian matrix is printed out
1283 */
1285
1286 friend class vcs_phaseStabilitySolve;
1287};
1288
1289}
1290#endif
Header file for class Cantera::Array2D.
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition Array.h:32
A class for multiphase mixtures.
Definition MultiPhase.h:62
Class to keep track of time and iterations.
This is the main structure used to hold the internal data used in vcs_solve_TP(), and to solve TP sys...
Definition vcs_solve.h:44
size_t vcs_popPhaseID(vector< size_t > &phasePopPhaseIDs)
Decision as to whether a phase pops back into existence.
vector< double > m_deltaPhaseMoles
Change in the total moles in each phase.
Definition vcs_solve.h:1074
size_t m_numPhases
Number of Phases in the problem.
Definition vcs_solve.h:876
int m_doEstimateEquil
Setting for whether to do an initial estimate.
Definition vcs_solve.h:953
vector< double > m_deltaMolNumSpecies
Reaction Adjustments for each species during the current step.
Definition vcs_solve.h:1021
vector< double > m_spSize
total size of the species
Definition vcs_solve.h:919
vector< double > m_scSize
Absolute size of the stoichiometric coefficients.
Definition vcs_solve.h:912
int vcs_evalSS_TP(int ipr, int ip1, double Temp, double pres)
Evaluate the standard state free energies at the current temperature and pressure.
vector< double > m_sm
QR matrix work space used in vcs_basopt()
Definition vcs_solve.h:798
vector< double > m_wtSpecies
Molecular weight of each species.
Definition vcs_solve.h:1245
vector< size_t > m_indexRxnToSpecies
Mapping between the species index for noncomponent species and the full species index.
Definition vcs_solve.h:1146
void vcs_prep(int printLvl)
This routine is mostly concerned with changing the private data to be consistent with what's needed f...
vector< double > m_sa
Gram-Schmidt work space used in vcs_basopt()
Definition vcs_solve.h:800
vector< size_t > m_phaseID
Mapping from the species number to the phase number.
Definition vcs_solve.h:1157
vector< string > m_speciesName
Species string name for the kth species.
Definition vcs_solve.h:1164
void vcs_deltag(const int L, const bool doDeleted, const int vcsState, const bool alterZeroedPhases=true)
This subroutine calculates reaction free energy changes for all noncomponent formation reactions.
double m_tolmaj2
Below this, major species aren't refined any more.
Definition vcs_solve.h:1089
vector< double > m_deltaGRxn_new
Delta G(irxn) for the noncomponent species in the mechanism.
Definition vcs_solve.h:1001
Array2D m_np_dLnActCoeffdMolNum
Change in the log of the activity coefficient with respect to the mole number multiplied by the phase...
Definition vcs_solve.h:1237
void vcs_updateMolNumVolPhases(const int stateCalc)
Update all underlying vcs_VolPhase objects.
void vcs_report(int iconv)
Print out a report on the state of the equilibrium problem to standard output.
size_t m_nelem
Number of element constraints in the problem.
Definition vcs_solve.h:855
vector< double > m_PMVolumeSpecies
Partial molar volumes of the species.
Definition vcs_solve.h:1264
vector< int > m_elementActive
Specifies whether an element constraint is active.
Definition vcs_solve.h:1188
int m_useActCoeffJac
Choice of Hessians.
Definition vcs_solve.h:1257
vector< size_t > m_speciesLocalPhaseIndex
Index that keeps track of the index of the species within the local phase.
Definition vcs_solve.h:1120
void vcs_updateVP(const int stateCalc)
This routine uploads the state of the system into all of the vcs_VolumePhase objects in the current p...
size_t vcs_add_all_deleted()
Provide an estimate for the deleted species in phases that are not zeroed out.
bool vcs_globStepDamp()
This routine optimizes the minimization of the total Gibbs free energy by making sure the slope of th...
void vcs_basopt(const bool doJustComponents, double test)
Choose the optimum species basis for the calculations.
vector< string > m_elementName
Vector of strings containing the element names.
Definition vcs_solve.h:1170
vector< int > m_speciesUnknownType
Specifies the species unknown type.
Definition vcs_solve.h:973
int vcs_elcorr(double aa[], double x[])
This subroutine corrects for element abundances.
vector< double > m_TmpPhase
Temporary vector of length NPhase.
Definition vcs_solve.h:1065
vector< size_t > m_speciesMapIndex
Index vector that keeps track of the species vector rearrangement.
Definition vcs_solve.h:1106
Array2D m_phaseParticipation
This is 1 if the phase, iphase, participates in the formation reaction irxn, and zero otherwise.
Definition vcs_solve.h:984
vector< int > m_actConventionSpecies
specifies the activity convention of the phase containing the species
Definition vcs_solve.h:1200
double vcs_phaseStabilityTest(const size_t iph)
Main program to test whether a deleted phase should be brought back into existence.
void vcs_inest()
Create an initial estimate of the solution to the equilibrium problem.
vector< double > m_elemAbundances
Element abundances vector.
Definition vcs_solve.h:1030
vector< double > m_tPhaseMoles_new
total kmols of species in each phase in the tentative soln vector
Definition vcs_solve.h:1062
vector< double > m_actCoeffSpecies_old
Molar-based Activity Coefficients for Species based on old mole numbers.
Definition vcs_solve.h:1227
double vcs_minor_alt_calc(size_t kspec, size_t irxn, bool *do_delete) const
Minor species alternative calculation.
vector< double > m_SSfeSpecies
Standard state chemical potentials for species K at the current temperature and pressure.
Definition vcs_solve.h:927
bool vcs_popPhasePossible(const size_t iphasePop) const
Utility function that evaluates whether a phase can be popped into existence.
double l2normdg(double dg[]) const
Calculate the norm of a deltaGibbs free energy vector.
int delta_species(const size_t kspec, double *const delta_ptr)
Change the concentration of a species by delta moles.
int solve_TP(int print_lvl, int printDetails, int maxit)
Main routine that solves for equilibrium at constant T and P using a variant of the VCS method.
double m_tolmin2
Below this, minor species aren't refined any more.
Definition vcs_solve.h:1092
vector< double > m_lnMnaughtSpecies
specifies the ln(Mnaught) used to calculate the chemical potentials
Definition vcs_solve.h:1216
vector< int > m_elType
Type of the element constraint.
Definition vcs_solve.h:1182
void vcs_elab()
Computes the current elemental abundances vector.
void prob_report(int print_lvl)
Print out the problem specification in all generality as it currently exists in the VCS_SOLVE object.
int vcs_setMolesLinProg()
Estimate the initial mole numbers by constrained linear programming.
vector< double > m_molNumSpecies_old
Total moles of the species.
Definition vcs_solve.h:960
double vcs_Total_Gibbs(double *w, double *fe, double *tPhMoles)
Calculate the total dimensionless Gibbs free energy.
void vcs_CalcLnActCoeffJac(const double *const moleSpeciesVCS)
Recalculate all of the activity coefficients in all of the phases based on input mole numbers.
size_t m_numRxnMinorZeroed
Number of active species which are currently either treated as minor species.
Definition vcs_solve.h:873
vector< size_t > m_elementMapIndex
Index vector that keeps track of the rearrangement of the elements.
Definition vcs_solve.h:1133
vector< double > m_aw
work array of mole fractions used in vcs_basopt()
Definition vcs_solve.h:801
size_t m_numSpeciesRdc
Current number of species in the problems.
Definition vcs_solve.h:865
int vcs_delete_species(const size_t kspec)
Change a single species from active to inactive status.
vector< double > m_feSpecies_old
Free energy vector from the start of the current iteration.
Definition vcs_solve.h:934
int m_debug_print_lvl
Debug printing lvl.
Definition vcs_solve.h:1284
void vcs_counters_init(int ifunc)
Initialize the internal counters.
void vcs_reinsert_deleted(size_t kspec)
We make decisions on the initial mole number, and major-minor status here.
vector< double > m_ss
Gram-Schmidt work space used in vcs_basopt()
Definition vcs_solve.h:799
vector< double > m_chargeSpecies
Charge of each species. Length = number of species.
Definition vcs_solve.h:1248
Array2D m_formulaMatrix
Formula matrix for the problem.
Definition vcs_solve.h:884
size_t addOnePhaseSpecies(vcs_VolPhase *volPhase, size_t k, size_t kT)
Add elements to the local element list This routines adds entries for the formula matrix for one spec...
Array2D m_stoichCoeffRxnMatrix
Stoichiometric coefficient matrix for the reaction mechanism expressed in Reduced Canonical Form.
Definition vcs_solve.h:903
size_t m_numRxnRdc
Current number of non-component species in the problem.
Definition vcs_solve.h:869
VCS_COUNTERS * m_VCount
Timing and iteration counters for the vcs object.
Definition vcs_solve.h:1270
vector< double > m_deltaGRxn_Deficient
Last deltag[irxn] from the previous step with additions for possible births of zeroed phases.
Definition vcs_solve.h:1008
vector< unique_ptr< vcs_VolPhase > > m_VolPhaseList
Array of Phase Structures. Length = number of phases.
Definition vcs_solve.h:1191
double vcs_Hessian_diag_adj(size_t irxn, double hessianDiag_Ideal)
Calculates the diagonal contribution to the Hessian due to the dependence of the activity coefficient...
size_t m_numComponents
Number of components calculated for the problem.
Definition vcs_solve.h:858
void vcs_prob_specifyFully()
Fully specify the problem to be solved.
int vcs_species_type(const size_t kspec) const
Evaluate the species category for the indicated species.
double m_pressurePA
Pressure.
Definition vcs_solve.h:1080
void vcs_SSPhase()
Calculate the status of single species phases.
vector< double > m_feSpecies_new
Dimensionless new free energy for all the species in the mechanism at the new tentative T,...
Definition vcs_solve.h:943
double m_Faraday_dim
dimensionless value of Faraday's constant, F / RT (1/volt)
Definition vcs_solve.h:1267
int vcs_recheck_deleted()
Recheck deleted species in multispecies phases.
void vcs_elem_rearrange()
Rearrange the constraint equations represented by the Formula Matrix so that the operational ones are...
double m_tolmin
Tolerance requirements for minor species.
Definition vcs_solve.h:1086
size_t m_nsp
Total number of species in the problems.
Definition vcs_solve.h:852
vector< double > m_actCoeffSpecies_new
Molar-based Activity Coefficients for Species.
Definition vcs_solve.h:1220
bool vcs_elabcheck(int ibound)
Checks to see if the element abundances are in compliance.
vector< char > m_SSPhase
Boolean indicating whether a species belongs to a single-species phase.
Definition vcs_solve.h:1161
bool vcs_delete_multiphase(const size_t iph)
This routine handles the bookkeeping involved with the deletion of multiphase phases from the problem...
vector< double > m_phasePhi
electric potential of the iph phase
Definition vcs_solve.h:987
double vcs_Hessian_actCoeff_diag(size_t irxn)
Calculates the diagonal contribution to the Hessian due to the dependence of the activity coefficient...
int vcs_zero_species(const size_t kspec)
Zero out the concentration of a species.
vector< double > m_elemAbundancesGoal
Element abundances vector Goals.
Definition vcs_solve.h:1039
size_t vcs_RxnStepSizes(int &forceComponentCalc, size_t &kSpecial)
Calculates formation reaction step sizes.
Array2D m_deltaMolNumPhase
Change in the number of moles of phase, iphase, due to the noncomponent formation reaction,...
Definition vcs_solve.h:980
vector< int > m_phaseActConvention
specifies the activity convention of the phase.
Definition vcs_solve.h:1209
vector< int > m_speciesStatus
Major -Minor status vector for the species in the problem.
Definition vcs_solve.h:1154
vector< double > m_deltaGRxn_tmp
Temporary vector of Rxn DeltaG's.
Definition vcs_solve.h:1014
vector< double > m_TmpPhase2
Temporary vector of length NPhase.
Definition vcs_solve.h:1068
void vcs_switch_elem_pos(size_t ipos, size_t jpos)
Swaps the indices for all of the global data for two elements, ipos and jpos.
double vcs_tmoles()
Calculates the total number of moles of species in all phases.
size_t elementIndex(const string &elementName) const
Return the index of an element by name, or npos if not found.
void vcs_switch_pos(const bool ifunc, const size_t k1, const size_t k2)
Swaps the indices for all of the global data for two species, k1 and k2.
int m_printLvl
Print level for print routines.
Definition vcs_solve.h:806
void vcs_dfe(const int stateCalc, const int ll, const size_t lbot, const size_t ltop)
Calculate the dimensionless chemical potentials of all species or of certain groups of species,...
vector< double > m_tPhaseMoles_old
Total kmols of species in each phase.
Definition vcs_solve.h:1053
int vcs_popPhaseRxnStepSizes(const size_t iphasePop)
Calculates the deltas of the reactions due to phases popping into existence.
size_t m_numRxnTot
Total number of non-component species in the problem.
Definition vcs_solve.h:861
vector< double > m_molNumSpecies_new
Tentative value of the mole number vector.
Definition vcs_solve.h:991
double m_temperature
Temperature (Kelvin)
Definition vcs_solve.h:1077
double m_tolmaj
Tolerance requirement for major species.
Definition vcs_solve.h:1083
vector< double > m_deltaGRxn_old
Last deltag[irxn] from the previous step.
Definition vcs_solve.h:1004
bool vcs_evaluate_speciesType()
This routine evaluates the species type for all species.
void vcs_TCounters_report()
Create a report on the plog file containing iteration counters.
size_t addElement(const char *elNameNew, int elType, int elactive)
This routine resizes the number of elements in the VCS_SOLVE object by adding a new element to the en...
double m_totalMolNum
Total number of kmoles in all phases.
Definition vcs_solve.h:1045
Phase information and Phase calculations for vcs.
This file contains definitions of constants, types and terms that are used in internal routines and a...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
Defines and definitions within the vcs package.
Internal declarations for the VCSnonideal package.