26 VCS_PROB::VCS_PROB(
size_t nsp,
size_t nel,
size_t nph) :
37 m_VCS_UnitsFormat(VCS_UNITS_UNITLESS),
45 m_NumBasisOptimizations(0),
47 vcs_debug_print_lvl(0)
52 "number of species is zero or neg");
57 "number of elements is zero or neg");
62 "number of phases is zero or neg");
66 "number of species is less than number of phases");
84 for (
size_t kspec = 0; kspec <
nspecies; kspec++) {
88 "Failed to init a ts struct");
93 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
100 for (
size_t i = 0; i <
nspecies; i++) {
104 for (
size_t iph = 0; iph <
NPhase; iph++) {
112 if (force || nPhase >
NPHASE0) {
125 VolPM.resize(nsp, 0.0);
132 throw CanteraError(
"VCS_PROB::resizeSpecies",
"shouldn't be here");
139 if (force || nel >
NE0) {
140 gai.resize(nel, 0.0);
152 gai.assign(
gai.size(), 0.0);
155 for (
size_t j = 0; j <
ne; j++) {
156 for (
size_t kspec = 0; kspec <
nspecies; kspec++) {
171 writeline(
'=', 80,
true,
true);
172 writeline(
'=', 20,
false);
173 plogf(
" VCS_PROB: PROBLEM STATEMENT ");
178 plogf(
"\tSolve a constant T, P problem:\n");
179 plogf(
"\t\tT = %g K\n",
T);
180 double pres_atm =
PresPA / 1.01325E5;
182 plogf(
"\t\tPres = %g atm\n", pres_atm);
184 throw CanteraError(
"VCS_PROB::prob_report",
"Unknown problem type");
187 plogf(
" Phase IDs of species\n");
188 plogf(
" species phaseID phaseName ");
189 plogf(
" Initial_Estimated_Moles Species_Type\n");
190 for (
size_t i = 0; i <
nspecies; i++) {
192 plogf(
"%16s %5d %16s",
SpName[i].c_str(), PhaseID[i],
212 writeline(
'-', 80,
true,
true);
213 plogf(
" Information about phases\n");
214 plogf(
" PhaseName PhaseNum SingSpec GasPhase "
215 " EqnState NumSpec");
216 plogf(
" TMolesInert TKmoles\n");
218 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
223 plogf(
"%16s %8d %16e ", EOS_cstr.c_str(),
232 plogf(
"\nElemental Abundances: ");
233 plogf(
" Target_kmol ElemType ElActive\n");
238 for (
size_t i = 0; i <
ne; ++i) {
239 writeline(
' ', 26,
false);
245 plogf(
"\nChemical Potentials: ");
249 plogf(
"(kcal/gmol)");
258 plogf(
" Species (phase) "
259 " SS0ChemPot StarChemPot\n");
260 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
263 for (
size_t kindex = 0; kindex < Vphase->
nSpecies(); kindex++) {
276 writeline(
'=', 80,
true,
true);
277 writeline(
'=', 20,
false);
278 plogf(
" VCS_PROB: END OF PROBLEM STATEMENT ");
291 for (
size_t eVP = 0; eVP < neVP; eVP++) {
292 size_t foundPos =
npos;
299 for (
size_t e = 0; e <
ne; e++) {
300 std::string en =
ElName[e];
301 if (!strcmp(enVP.c_str(), en.c_str())) {
306 if (foundPos ==
npos) {
308 int elactive = volPhase->elementActive(eVP);
309 size_t e =
addElement(enVP.c_str(), elType, elactive);
319 "error: element must have a name");
336 throw CanteraError(
"VCS_PROB::addOnePhaseSpecies",
"Shouldn't be here");
342 "element not found");
353 void VCS_PROB::reportCSV(
const std::string& reportFile)
355 FILE* FP = fopen(reportFile.c_str(),
"w");
357 throw CanteraError(
"VCS_PROB::reportCSV",
"Failure to open file");
360 std::vector<double> volPM(nspecies, 0.0);
361 std::vector<double> activity(nspecies, 0.0);
362 std::vector<double> ac(nspecies, 0.0);
363 std::vector<double> mu(nspecies, 0.0);
364 std::vector<double> mu0(nspecies, 0.0);
365 std::vector<double> molalities(nspecies, 0.0);
369 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
372 size_t nSpeciesPhase = volP->nSpecies();
373 volPM.resize(nSpeciesPhase, 0.0);
376 double TMolesPhase = volP->totalMoles();
377 double VolPhaseVolumes = 0.0;
378 for (
size_t k = 0; k < nSpeciesPhase; k++) {
380 VolPhaseVolumes += volPM[istart + k] *
mf[istart + k];
382 VolPhaseVolumes *= TMolesPhase;
383 vol += VolPhaseVolumes;
386 fprintf(FP,
"--------------------- VCS_MULTIPHASE_EQUIL FINAL REPORT"
387 " -----------------------------\n");
388 fprintf(FP,
"Temperature = %11.5g kelvin\n",
T);
389 fprintf(FP,
"Pressure = %11.5g Pascal\n",
PresPA);
390 fprintf(FP,
"Total Volume = %11.5g m**3\n", vol);
392 fprintf(FP,
"Number VCS iterations = %d\n",
m_Iterations);
395 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
399 const ThermoPhase* tp = volP->ptrThermoPhase();
400 string phaseName = volP->PhaseName;
401 size_t nSpeciesPhase = volP->nSpecies();
403 double TMolesPhase = volP->totalMoles();
404 activity.resize(nSpeciesPhase, 0.0);
405 ac.resize(nSpeciesPhase, 0.0);
407 mu0.resize(nSpeciesPhase, 0.0);
408 mu.resize(nSpeciesPhase, 0.0);
409 volPM.resize(nSpeciesPhase, 0.0);
410 molalities.resize(nSpeciesPhase, 0.0);
412 int actConvention = tp->activityConvention();
419 double VolPhaseVolumes = 0.0;
420 for (
size_t k = 0; k < nSpeciesPhase; k++) {
421 VolPhaseVolumes += volPM[k] *
mf[istart + k];
423 VolPhaseVolumes *= TMolesPhase;
424 vol += VolPhaseVolumes;
426 if (actConvention == 1) {
427 const MolalityVPSSTP* mTP =
static_cast<const MolalityVPSSTP*
>(tp);
433 fprintf(FP,
" Name, Phase, PhaseMoles, Mole_Fract, "
434 "Molalities, ActCoeff, Activity,"
435 "ChemPot_SS0, ChemPot, mole_num, PMVol, Phase_Volume\n");
437 fprintf(FP,
" , , (kmol), , "
439 " (J/kmol), (J/kmol), (kmol), (m**3/kmol), (m**3)\n");
441 for (
size_t k = 0; k < nSpeciesPhase; k++) {
442 std::string sName = tp->speciesName(k);
443 fprintf(FP,
"%12s, %11s, %11.3e, %11.3e, %11.3e, %11.3e, %11.3e,"
444 "%11.3e, %11.3e, %11.3e, %11.3e, %11.3e\n",
446 phaseName.c_str(), TMolesPhase,
447 mf[istart + k], molalities[k], ac[k], activity[k],
448 mu0[k]*1.0E-6, mu[k]*1.0E-6,
449 mf[istart + k] * TMolesPhase,
450 volPM[k], VolPhaseVolumes);
455 fprintf(FP,
" Name, Phase, PhaseMoles, Mole_Fract, "
456 "Molalities, ActCoeff, Activity,"
457 " ChemPotSS0, ChemPot, mole_num, PMVol, Phase_Volume\n");
459 fprintf(FP,
" , , (kmol), , "
461 " (J/kmol), (J/kmol), (kmol), (m**3/kmol), (m**3)\n");
463 for (
size_t k = 0; k < nSpeciesPhase; k++) {
466 for (
size_t k = 0; k < nSpeciesPhase; k++) {
467 std::string sName = tp->speciesName(k);
468 fprintf(FP,
"%12s, %11s, %11.3e, %11.3e, %11.3e, %11.3e, %11.3e, "
469 "%11.3e, %11.3e,% 11.3e, %11.3e, %11.3e\n",
471 phaseName.c_str(), TMolesPhase,
472 mf[istart + k], molalities[k], ac[k],
473 activity[k], mu0[k]*1.0E-6, mu[k]*1.0E-6,
474 mf[istart + k] * TMolesPhase,
475 volPM[k], VolPhaseVolumes);
479 if (DEBUG_MODE_ENABLED) {
484 for (
size_t k = 0; k < nSpeciesPhase; k++) {
487 throw CanteraError(
"VCS_PROB::reportCSV",
"incompatibility");
std::vector< int > ElActive
Specifies whether an element constraint is active.
double G0_calc_one(size_t kspec) const
Gibbs free energy calculation at a temperature for the reference state of a species, return a value for one species.
std::vector< double > WtSpecies
Molecular weight of species.
double GStar_calc_one(size_t kspec) const
Gibbs free energy calculation for standard state of one species.
size_t nElemConstraints() const
Returns the number of element constraints.
bool vcs_doubleEqual(double d1, double d2)
Simple routine to check whether two doubles are equal up to roundoff error.
int m_printLvl
Print level for print routines.
bool m_singleSpecies
If true, this phase consists of a single species.
double totalMolesInert() const
returns the value of the total kmol of inert in the phase
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the array, and fill the new entries with 'v'.
const size_t npos
index returned by functions to indicate "no position"
std::vector< int > SpeciesUnknownType
Specifies the species unknown type.
#define VCS_DATA_PTR(vvv)
Points to the data in a std::vector<> object.
int elementType(const size_t e) const
Type of the element constraint with index e.
std::vector< std::string > ElName
vector of strings containing the element names
int iest
Specification of the initial estimate method.
std::vector< double > w
Total number of moles of the kth species.
size_t NSPECIES0
Species number used to malloc data structures.
size_t nSpecies() const
Return the number of species in the phase.
size_t addOnePhaseSpecies(vcs_VolPhase *volPhase, size_t k, size_t kT)
This routines adds entries for the formula matrix for one species.
void resizePhase(size_t nPhase, int force)
Resizes all of the phase lists within the structure.
std::string PhaseName
String name for the phase.
double totalMoles() const
Return the total moles in the phase.
Pure Virtual base class for the species thermo manager classes.
std::vector< vcs_VolPhase * > VPhaseList
Array of phase structures.
int m_Iterations
Number of iterations. This is an output variable.
#define AssertThrowMsg(expr, procedure, message)
Assertion must be true or an error is thrown.
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Header for intermediate ThermoPhase object for phases which employ molality based activity coefficien...
#define VCS_PROBTYPE_TP
Current, it is always done holding T and P constant.
void resizeElements(size_t nel, int force)
Resizes all of the element lists within the structure.
std::vector< size_t > PhaseID
Mapping between the species and the phases.
size_t VP_ID_
Original ID of the phase in the problem.
std::vector< double > VolPM
Partial Molar Volumes of species.
Header for the object representing each phase within vcs.
#define VCS_SPECIES_TYPE_MOLNUM
Unknown refers to mole number of a single species.
#define VCS_ELEM_TYPE_ABSPOS
Normal element constraint consisting of positive coefficients for the formula matrix.
Defines and definitions within the vcs package.
void addPhaseElements(vcs_VolPhase *volPhase)
Add elements to the local element list.
Array2D FormulaMatrix
Formula Matrix for the problem.
void setDebugPrintLvl(int vcs_debug_print_lvl)
Set the debug level.
Internal declarations for the VCSnonideal package.
int m_VCS_UnitsFormat
Units for the chemical potential data, pressure data, volume, and species amounts.
const Array2D & getFormulaMatrix() const
Get a constant form of the Species Formula Matrix.
Header for the Interface class for the vcs thermo equilibrium solver package,.
size_t NPHASE0
Number of phases used to malloc data structures.
int m_eqnState
Type of the equation of state.
size_t nspecies
Total number of species in the problems.
std::vector< double > mf
Mole fraction vector.
Base class for exceptions thrown by Cantera classes.
void prob_report(int print_lvl)
Print out the problem specification in all generality as it currently exists in the VCS_PROB object...
bool m_gasPhase
If true, this phase is a gas-phase like phase.
std::string string16_EOSType(int EOSType)
Return a string representing the equation of state.
std::vector< double > Charge
Charge of each species.
int m_NumBasisOptimizations
Number of basis optimizations used. This is an output variable.
size_t addElement(const char *elNameNew, int elType, int elactive)
This routine resizes the number of elements in the VCS_PROB object by adding a new element to the end...
Phase information and Phase calculations for vcs.
std::vector< int > m_elType
vector of Element types
size_t ne
Number of element constraints in the equilibrium problem.
int prob_type
Problem type. I.e., the identity of what is held constant.
std::vector< double > gai
Element abundances for jth element.
std::vector< std::string > SpName
Vector of strings containing the species names.
size_t NE0
Number of element constraints used to malloc data structures involving elements.
void setSpGlobalIndexVCS(const size_t spIndex, const size_t spGlobalIndex)
set the Global VCS index of the kth species in the phase
std::vector< double > m_gibbsSpecies
Vector of chemical potentials of the species.
double T
Temperature (Kelvin)
void resizeSpecies(size_t nsp, int force)
Resizes all of the species lists within the structure.
#define plogf
define this Cantera function to replace printf
#define VCS_SPECIES_TYPE_INTERFACIALVOLTAGE
Unknown refers to the voltage level of a phase.
void set_gai()
Calculate the element abundance vector from the mole numbers.
size_t elemGlobalIndex(const size_t e) const
Returns the global index of the local element index for the phase.
std::string elementName(const size_t e) const
Name of the element constraint with index e.
size_t NPhase
Number of phases in the problem.
size_t spGlobalIndexVCS(const size_t spIndex) const
Return the Global VCS index of the kth species in the phase.
void setState_TP(const double temperature_Kelvin, const double pressure_PA)
Sets the temperature and pressure in this object and underlying ThermoPhase objects.
int vcs_debug_print_lvl
Debug print lvl.
void setElemGlobalIndex(const size_t eLocal, const size_t eGlobal)
sets a local phase element to a global index value