27 m_nsp(mphase->nSpecies()),
31 m_numSpeciesRdc(mphase->nSpecies()),
33 m_numRxnMinorZeroed(0),
34 m_numPhases(mphase->nPhases()),
35 m_doEstimateEquil(-1),
37 m_temperature(mphase->temperature()),
38 m_pressurePA(mphase->pressure()),
44 m_totalVol(mphase->volume()),
51 for (
size_t kspec = 0; kspec <
m_nsp; kspec++) {
55 string ser =
"VCS_SOLVE: ERROR:\n\t";
57 plogf(
"%s Number of species is nonpositive\n", ser);
59 " Number of species is nonpositive\n");
62 plogf(
"%s Number of phases is nonpositive\n", ser);
64 " Number of phases is nonpositive\n");
145 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
151 std::string eos = tPhase->
type();
152 bool gasPhase = (eos ==
"IdealGas");
155 size_t nSpPhase = tPhase->
nSpecies();
157 string phaseName = tPhase->
name();
167 VolPhase->
resize(iphase, nSpPhase, nelem, phaseName.c_str(), 0.0);
183 if (eos ==
"IdealGas") {
185 }
else if (eos ==
"ConstDensity") {
187 }
else if (eos ==
"StoichSubstance") {
189 }
else if (eos ==
"IdealSolidSoln") {
191 }
else if (eos ==
"Surf" || eos ==
"Edge") {
193 "Surface/edge phase not handled yet.");
196 writelog(
"Unknown Cantera EOS to VCSnonideal: '{}'\n", eos);
215 for (
size_t k = 0; k < nSpPhase; k++) {
255 for (
size_t e = 0; e <
m_nelem; e++) {
276 double minTemp, maxTemp, refPressure;
277 sp.
reportParams(k, spType, c, minTemp, maxTemp, refPressure);
292 plogf(
"vcs_Cantera_convert: Species Type %d not known \n",
317 for (
size_t k = 0; k < nSpPhase; k++) {
326 for (
size_t j = 0; j <
m_nelem; j++) {
327 for (
size_t kspec = 0; kspec <
m_nsp; kspec++) {
339 writeline(
'=', 80,
true,
true);
340 writeline(
'=', 16,
false);
341 plogf(
" Cantera_to_vprob: START OF PROBLEM STATEMENT ");
344 plogf(
" Phase IDs of species\n");
345 plogf(
" species phaseID phaseName ");
346 plogf(
" Initial_Estimated_kMols\n");
347 for (
size_t i = 0; i <
m_nsp; i++) {
361 writeline(
'-', 80,
true,
true);
362 plogf(
" Information about phases\n");
363 plogf(
" PhaseName PhaseNum SingSpec GasPhase EqnState NumSpec");
364 plogf(
" TMolesInert Tmoles(kmol)\n");
366 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
368 plogf(
"%16s %5d %5d %8d %16s %8d %16e ", VolPhase->
PhaseName.c_str(),
375 writeline(
'=', 80,
true,
true);
376 writeline(
'=', 16,
false);
377 plogf(
" Cantera_to_vprob: END OF PROBLEM STATEMENT ");
391 for (
size_t i = 0; i <
m_nsp; i++) {
396 for (
size_t i = 0; i <
m_nelem; i++) {
403 for (
size_t kspec = 0; kspec <
m_nsp; kspec++) {
407 "Species to Phase Mapping, PhaseID, has a bad value\n"
408 "\tm_phaseID[{}] = {}\n"
409 "Allowed values: 0 to {}", kspec, iph,
m_numPhases - 1);
417 if (numPhSp[iph] != Vphase->
nSpecies()) {
419 "Number of species in phase {}, {}, doesn't match ({} != {}) [vphase = {}]",
424 for (
size_t i = 0; i <
m_nelem; i++) {
429 "Charge neutrality condition {} is signicantly "
430 "nonzero, {}. Giving up",
434 plogf(
"Charge neutrality condition %s not zero, %g. Setting it zero\n",
444 for (
size_t i = 0; i <
m_nsp; i++) {
461 for (
size_t k = 1; k < Vphase->
nSpecies(); k++) {
471 VCS_SOLVE::~VCS_SOLVE()
502 plogf(
"vcs_prep_oneTime returned a bad status, %d: bailing!\n",
526 if (ipr > 0 || ip1 > 0) {
533 }
else if (iconv == 1) {
534 plogf(
"WARNING: RANGE SPACE ERROR encountered\n");
548 vector<size_t> invSpecies(
m_nsp);
549 for (
size_t k = 0; k <
m_nsp; k++) {
553 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
560 size_t nSpPhase = tPhase->
nSpecies();
561 if ((nSpPhase == 1) && (volPhase->
phiVarIndex() == 0)) {
572 writeline(
'=', 80,
true,
true);
573 writeline(
'=', 20,
false);
574 plogf(
" Cantera_to_vprob: START OF PROBLEM STATEMENT ");
578 plogf(
" Phase IDs of species\n");
579 plogf(
" species phaseID phaseName ");
580 plogf(
" Initial_Estimated_kMols\n");
581 for (
size_t i = 0; i <
m_nsp; i++) {
594 writeline(
'-', 80,
true,
true);
595 plogf(
" Information about phases\n");
596 plogf(
" PhaseName PhaseNum SingSpec GasPhase EqnState NumSpec");
597 plogf(
" TMolesInert Tmoles(kmol)\n");
599 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
601 plogf(
"%16s %5d %5d %8d %16s %8d %16e ", VolPhase->
PhaseName.c_str(),
608 writeline(
'=', 80,
true,
true);
609 writeline(
'=', 20,
false);
610 plogf(
" Cantera_to_vprob: END OF PROBLEM STATEMENT ");
660 const double w[],
double volPM[])
663 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
Headers for the MultiPhase object that is used to set up multiphase equilibrium problems (see Equilfu...
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the array, and fill the new entries with 'v'.
Base class for exceptions thrown by Cantera classes.
A class for multiphase mixtures.
doublereal pressure() const
Pressure [Pa].
doublereal speciesMoles(size_t kGlob) const
Returns the moles of global species k. units = kmol.
std::string speciesName(const size_t kGlob) const
Name of species with global index kGlob.
void uploadMoleFractionsFromPhases()
Update the locally-stored composition within this object to match the current compositions of the pha...
doublereal volume() const
The total mixture volume [m^3].
void setPhaseMoles(const size_t n, const doublereal moles)
Set the number of moles of phase with index n.
doublereal temperature() const
Temperature [K].
thermo_t & phase(size_t n)
Return a reference to phase n.
A species thermodynamic property manager for a phase.
virtual int reportType(size_t index) const
This utility function reports the type of parameterization used for the species with index number ind...
virtual void reportParams(size_t index, int &type, doublereal *const c, doublereal &minTemp, doublereal &maxTemp, doublereal &refPressure) const
This utility function reports back the type of parameterization and all of the parameters for the spe...
std::string name() const
Return the name of the phase.
size_t nSpecies() const
Returns the number of species in the phase.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
size_t nElements() const
Number of elements.
Base class for a phase with thermodynamic properties.
virtual int activityConvention() const
This method returns the convention used in specification of the activities, of which there are curren...
virtual MultiSpeciesThermo & speciesThermo(int k=-1)
Return a changeable reference to the calculation manager for species reference-state thermodynamic pr...
virtual std::string type() const
String indicating the thermodynamic model implemented.
doublereal electricPotential() const
Returns the electric potential of this phase (V).
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
Class to keep track of time and iterations.
int Its
Current number of iterations in the main loop of vcs_TP() to solve for thermo equilibrium.
int T_Calls_Inest
Current number of times the initial thermo equilibrium estimator has been called.
double T_Time_basopt
Total Time spent in basopt.
double T_Time_inest
Time spent in initial estimator.
int T_Basis_Opts
Total number of optimizations of the components basis set done.
double T_Time_vcs_TP
Current time spent in vcs_TP.
int Basis_Opts
number of optimizations of the components basis set done
double T_Time_vcs
Time spent in the vcs suite of programs.
int T_Its
Total number of iterations in the main loop of vcs_TP() to solve for thermo equilibrium.
int T_Calls_vcs_TP
Current number of calls to vcs_TP.
double Time_basopt
Current Time spent in basopt.
double Time_vcs_TP
Current time spent in vcs_TP.
size_t m_numPhases
Number of Phases in the problem.
vector_fp m_phasePhi
electric potential of the iph phase
vector_fp m_scSize
Absolute size of the stoichiometric coefficients.
double vcs_VolTotal(const double tkelvin, const double pres, const double w[], double volPM[])
Calculation of the total volume and the partial molar volumes.
std::vector< std::string > m_speciesName
Species string name for the kth species.
Array2D m_np_dLnActCoeffdMolNum
Change in the log of the activity coefficient with respect to the mole number multiplied by the phase...
vector_fp m_TmpPhase2
Temporary vector of length NPhase.
vector_int m_elType
Type of the element constraint.
size_t m_nelem
Number of element constraints in the problem.
int m_useActCoeffJac
Choice of Hessians.
double m_totalVol
Total volume of all phases. Units are m^3.
vector_int m_speciesStatus
Major -Minor status vector for the species in the problem.
int vcs_prep(int printLvl)
This routine is mostly concerned with changing the private data to be consistent with what's needed f...
vector_int m_actConventionSpecies
specifies the activity convention of the phase containing the species
vector_fp m_molNumSpecies_old
Total moles of the species.
void vcs_TCounters_report(int timing_print_lvl=1)
Create a report on the plog file containing timing and its information.
Array2D m_phaseParticipation
This is 1 if the phase, iphase, participates in the formation reaction irxn, and zero otherwise.
static void disableTiming()
Disable printing of timing information.
vector_fp m_molNumSpecies_new
Tentative value of the mole number vector.
vector_int m_speciesUnknownType
Specifies the species unknown type.
vector_fp m_deltaGRxn_tmp
Temporary vector of Rxn DeltaG's.
vector_fp m_deltaGRxn_old
Last deltag[irxn] from the previous step.
int vcs_TP(int ipr, int ip1, int maxit, double T, double pres)
Solve an equilibrium problem at a particular fixed temperature and pressure.
void prob_report(int print_lvl)
Print out the problem specification in all generality as it currently exists in the VCS_SOLVE object.
int m_timing_print_lvl
printing level of timing information
vector_fp m_tPhaseMoles_new
total kmols of species in each phase in the tentative soln vector
vector_fp m_feSpecies_new
Dimensionless new free energy for all the species in the mechanism at the new tentative T,...
vector_fp m_tPhaseMoles_old
Total kmols of species in each phase.
int m_debug_print_lvl
Debug printing lvl.
void vcs_counters_init(int ifunc)
Initialize the internal counters.
vector_fp m_elemAbundancesGoal
Element abundances vector Goals.
vector_fp TPhInertMoles
Total kmoles of inert to add to each phase.
std::vector< size_t > m_phaseID
Mapping from the species number to the phase number.
std::vector< size_t > m_indexRxnToSpecies
Mapping between the species index for noncomponent species and the full species index.
Array2D m_formulaMatrix
Formula matrix for the problem.
vector_fp m_wtSpecies
Molecular weight of each species.
vector_fp m_deltaPhaseMoles
Change in the total moles in each phase.
void addPhaseElements(vcs_VolPhase *volPhase)
Add elements to the local element list.
std::vector< size_t > m_speciesLocalPhaseIndex
Index that keeps track of the index of the species within the local phase.
size_t addOnePhaseSpecies(vcs_VolPhase *volPhase, size_t k, size_t kT)
This routines adds entries for the formula matrix for one species.
size_t m_numRxnRdc
Current number of non-component species in the problem.
VCS_COUNTERS * m_VCount
Timing and iteration counters for the vcs object.
int vcs(int ipr, int ip1, int maxit)
Solve an equilibrium problem.
std::vector< std::unique_ptr< VCS_SPECIES_THERMO > > m_speciesThermoList
Vector of pointers to thermo structures which identify the model and parameters for evaluating the th...
size_t m_numComponents
Number of components calculated for the problem.
void vcs_prob_specifyFully()
Fully specify the problem to be solved.
double m_pressurePA
Pressure.
vector_fp m_chargeSpecies
Charge of each species. Length = number of species.
vector_fp m_feSpecies_old
Free energy vector from the start of the current iteration.
int vcs_report(int iconv)
Print out a report on the state of the equilibrium problem to standard output.
double m_Faraday_dim
dimensionless value of Faraday's constant, F / RT (1/volt)
std::vector< char > m_SSPhase
Boolean indicating whether a species belongs to a single-species phase.
size_t m_nsp
Total number of species in the problems.
std::vector< std::unique_ptr< vcs_VolPhase > > m_VolPhaseList
Array of Phase Structures. Length = number of phases.
vector_fp m_spSize
total size of the species
std::vector< size_t > m_elementMapIndex
Index vector that keeps track of the rearrangement of the elements.
void vcs_delete_memory()
Delete memory that isn't just resizable STL containers.
void vcs_prob_update()
Transfer the results of the equilibrium calculation back from VCS_SOLVE.
vector_fp m_deltaMolNumSpecies
Reaction Adjustments for each species during the current step.
vector_fp m_SSfeSpecies
Standard state chemical potentials for species K at the current temperature and pressure.
Array2D m_deltaMolNumPhase
Change in the number of moles of phase, iphase, due to the noncomponent formation reaction,...
std::vector< size_t > m_speciesMapIndex
Index vector that keeps track of the species vector rearrangement.
vector_fp m_actCoeffSpecies_old
Molar-based Activity Coefficients for Species based on old mole numbers.
vector_fp m_PMVolumeSpecies
Partial molar volumes of the species.
vector_fp m_deltaGRxn_new
Delta G(irxn) for the noncomponent species in the mechanism.
int m_printLvl
Print level for print routines.
vector_fp m_lnMnaughtSpecies
specifies the ln(Mnaught) used to calculate the chemical potentials
vector_int m_phaseActConvention
specifies the activity convention of the phase.
size_t m_numRxnTot
Total number of non-component species in the problem.
vector_fp m_deltaGRxn_Deficient
Last deltag[irxn] from the previous step with additions for possible births of zeroed phases.
double m_temperature
Temperature (Kelvin)
vector_fp m_TmpPhase
Temporary vector of length NPhase.
vector_fp m_actCoeffSpecies_new
Molar-based Activity Coefficients for Species.
std::vector< std::string > m_elementName
Vector of strings containing the element names.
size_t IndexSpeciesPhase
Index of this species in the current phase.
int SSStar_Vol_Model
Models for the standard state volume of each species.
double SS0_Cp0
Base heat capacity used in the VCS_SS0_CONSTANT_CP model.
double SSStar_Vol0
parameter that is used in the VCS_SSVOL_CONSTANT model.
double SS0_H0
Base enthalpy used in the VCS_SS0_CONSTANT_CP model.
double SS0_T0
Base temperature used in the VCS_SS0_CONSTANT_CP model.
double SS0_TSave
Internal storage of the last temperature used in the calculation of the reference naught Gibbs free e...
int SSStar_Model
Integer value representing the star state model.
double SS0_S0
Base entropy used in the VCS_SS0_CONSTANT_CP model.
int SS0_Model
Integer representing the models for the species standard state Naught temperature dependence.
double SS0_feSave
Internal storage of the last calculation of the reference naught Gibbs free energy at SS0_TSave.
size_t IndexPhase
Index of the phase that this species belongs to.
vcs_VolPhase * OwningPhase
Pointer to the owning phase object.
The class provides the wall clock timer in seconds.
double secondsWC()
Returns the wall clock time in seconds since the last reset.
Properties of a single species.
double VolPM
Partial molar volume of the species.
vector_fp FormulaMatrixCol
Column of the formula matrix, comprising the element composition of the species.
int SurfaceSpecies
True if this species belongs to a surface phase.
std::string SpName
Name of the species.
double WtSpecies
Molecular Weight of the species (gm/mol)
VCS_SPECIES_THERMO * SpeciesThermo
Pointer to the thermo structure for this species.
double Charge
Charge state of the species -> This may be duplication of what's in the FormulaMatrixCol entries.
Phase information and Phase calculations for vcs.
void setElectricPotential(const double phi)
set the electric potential of the phase
std::string eos_name() const
Return the name corresponding to the equation of state.
int speciesUnknownType(const size_t k) const
Returns the type of the species unknown.
size_t nSpecies() const
Return the number of species in the phase.
size_t VP_ID_
Original ID of the phase in the problem.
vcs_SpeciesProperties * speciesProperty(const size_t kindex)
Retrieve the kth Species structure for the species belonging to this phase.
size_t phiVarIndex() const
Return the index of the species that represents the the voltage of the phase.
double totalMolesInert() const
Returns the value of the total kmol of inert in the phase.
bool m_singleSpecies
If true, this phase consists of a single species.
void setMolesFromVCS(const int stateCalc, const double *molesSpeciesVCS=0)
Set the moles within the phase.
void resize(const size_t phaseNum, const size_t numSpecies, const size_t numElem, const char *const phaseName, const double molesInert=0.0)
The resize() function fills in all of the initial information if it is not given in the constructor.
size_t spGlobalIndexVCS(const size_t spIndex) const
Return the Global VCS index of the kth species in the phase.
size_t transferElementsFM(const ThermoPhase *const tPhase)
Transfer all of the element information from the ThermoPhase object to the vcs_VolPhase object.
bool m_gasPhase
If true, this phase is a gas-phase like phase.
std::string PhaseName
String name for the phase.
void setTotalMoles(const double totalMols)
Sets the total moles in the phase.
int p_activityConvention
Convention for the activity formulation.
double sendToVCS_VolPM(double *const VolPM) const
Fill in the partial molar volume vector for VCS.
int m_eqnState
Type of the equation of state.
double G0_calc_one(size_t kspec) const
Gibbs free energy calculation at a temperature for the reference state of a species,...
void setState_TP(const double temperature_Kelvin, const double pressure_PA)
Sets the temperature and pressure in this object and underlying ThermoPhase objects.
void setExistence(const int existence)
Set the existence flag in the object.
double totalMoles() const
Return the total moles in the phase.
void setPtrThermoPhase(ThermoPhase *tp_ptr)
Set the pointer for Cantera's ThermoPhase parameter.
Declarations for a simple class that implements an Ansi C wall clock timer (see Cantera::clockWC).
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
const double Faraday
Faraday constant [C/kmol].
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
const double GasConstant
Universal Gas Constant [J/kmol/K].
void writelog(const std::string &fmt, const Args &... args)
Write a formatted message to the screen.
Namespace for the Cantera kernel.
int vcs_timing_print_lvl
Global hook for turning on and off time printing.
#define SIMPLE
Constant Cp thermo.
Contains declarations for string manipulation functions within Cantera.
Header for the object representing each phase within vcs.
#define VCS_SSVOL_IDEALGAS
Models for the standard state volume of each species.
#define VCS_SPECIES_TYPE_INTERFACIALVOLTAGE
Unknown refers to the voltage level of a phase.
#define VCS_STATECALC_OLD
State Calculation based on the old or base mole numbers.
#define VCS_SPECIES_MAJOR
Species is a major species.
#define VCS_PHASE_EXIST_NO
Phase doesn't currently exist in the mixture.
#define VCS_PHASE_EXIST_ALWAYS
Always exists because it contains inerts which can't exist in any other phase.
#define VCS_SPECIES_TYPE_MOLNUM
Unknown refers to mole number of a single species.
#define VCS_ELEM_TYPE_LATTICERATIO
Constraint associated with maintaining a fixed lattice stoichiometry in the solids.
#define VCS_ELEM_TYPE_CHARGENEUTRALITY
This refers to a charge neutrality of a single phase.
#define VCS_PHASE_EXIST_YES
Phase is a normal phase that currently exists.
#define plogf
define this Cantera function to replace printf
Header file for the internal object that holds the vcs equilibrium problem (see Class VCS_SOLVE and E...