27 VCS_PROB::VCS_PROB(
size_t nsp,
size_t nel,
size_t nph) :
38 m_VCS_UnitsFormat(VCS_UNITS_UNITLESS),
46 m_NumBasisOptimizations(0),
48 vcs_debug_print_lvl(0)
52 plogf(
"number of species is zero or neg\n");
57 plogf(
"number of elements is zero or neg\n");
62 plogf(
"number of phases is zero or neg\n");
66 plogf(
"number of species is less than number of phases\n");
85 for (
size_t kspec = 0; kspec <
nspecies; kspec++) {
88 plogf(
"Failed to init a ts struct\n");
94 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
101 for (
size_t i = 0; i <
nspecies; i++) {
105 for (
size_t iph = 0; iph <
NPhase; iph++) {
113 if (force || nPhase >
NPHASE0) {
126 VolPM.resize(nsp, 0.0);
134 plogf(
"shouldn't be here\n");
142 if (force || nel >
NE0) {
143 gai.resize(nel, 0.0);
159 vcs_dzero(ElemAbund,
ne);
161 for (
size_t j = 0; j <
ne; j++) {
162 for (
size_t kspec = 0; kspec <
nspecies; kspec++) {
164 ElemAbund[j] += fm[j][kspec] *
w[kspec];
170 static void print_space(
int num)
172 for (
int j = 0; j < num; j++) {
177 static void print_char(
const char letter,
const int num)
179 for (
int i = 0; i < num; i++) {
196 plogf(
" VCS_PROB: PROBLEM STATEMENT ");
204 plogf(
"\tSolve a constant T, P problem:\n");
205 plogf(
"\t\tT = %g K\n",
T);
206 double pres_atm =
PresPA / 1.01325E5;
208 plogf(
"\t\tPres = %g atm\n", pres_atm);
210 plogf(
"\tUnknown problem type\n");
214 plogf(
" Phase IDs of species\n");
215 plogf(
" species phaseID phaseName ");
216 plogf(
" Initial_Estimated_Moles Species_Type\n");
217 for (
size_t i = 0; i <
nspecies; i++) {
219 plogf(
"%16s %5d %16s",
SpName[i].c_str(), PhaseID[i],
242 plogf(
" Information about phases\n");
243 plogf(
" PhaseName PhaseNum SingSpec GasPhase "
244 " EqnState NumSpec");
245 plogf(
" TMolesInert TKmoles\n");
247 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
252 plogf(
"%16s %8d %16e ", EOS_cstr.c_str(),
261 plogf(
"\nElemental Abundances: ");
262 plogf(
" Target_kmol ElemType ElActive\n");
268 for (
size_t i = 0; i <
ne; ++i) {
275 plogf(
"\nChemical Potentials: ");
279 plogf(
"(kcal/gmol)");
288 plogf(
" Species (phase) "
289 " SS0ChemPot StarChemPot\n");
290 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
293 for (
size_t kindex = 0; kindex < Vphase->
nSpecies(); kindex++) {
310 plogf(
" VCS_PROB: END OF PROBLEM STATEMENT ");
321 size_t foundPos =
npos;
328 for (eVP = 0; eVP < neVP; eVP++) {
336 for (e = 0; e <
ne; e++) {
338 if (!strcmp(enVP.c_str(), en.c_str())) {
343 if (foundPos ==
npos) {
345 int elactive = volPhase->elementActive(eVP);
346 e =
addElement(enVP.c_str(), elType, elactive);
355 plogf(
"error: element must have a name\n");
374 plogf(
"Shouldn't be here\n");
395 void VCS_PROB::reportCSV(
const std::string& reportFile)
403 FILE* FP = fopen(reportFile.c_str(),
"w");
405 plogf(
"Failure to open file\n");
410 std::vector<double> volPM(nspecies, 0.0);
411 std::vector<double> activity(nspecies, 0.0);
412 std::vector<double> ac(nspecies, 0.0);
413 std::vector<double> mu(nspecies, 0.0);
414 std::vector<double> mu0(nspecies, 0.0);
415 std::vector<double> molalities(nspecies, 0.0);
419 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
423 size_t nSpeciesPhase = volP->nSpecies();
424 volPM.resize(nSpeciesPhase, 0.0);
427 double TMolesPhase = volP->totalMoles();
428 double VolPhaseVolumes = 0.0;
429 for (k = 0; k < nSpeciesPhase; k++) {
431 VolPhaseVolumes += volPM[istart + k] *
mf[istart + k];
433 VolPhaseVolumes *= TMolesPhase;
434 vol += VolPhaseVolumes;
437 fprintf(FP,
"--------------------- VCS_MULTIPHASE_EQUIL FINAL REPORT"
438 " -----------------------------\n");
439 fprintf(FP,
"Temperature = %11.5g kelvin\n", Temp);
440 fprintf(FP,
"Pressure = %11.5g Pascal\n",
PresPA);
441 fprintf(FP,
"Total Volume = %11.5g m**3\n", vol);
443 fprintf(FP,
"Number VCS iterations = %d\n",
m_Iterations);
446 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
451 string phaseName = volP->PhaseName;
452 size_t nSpeciesPhase = volP->
nSpecies();
454 double TMolesPhase = volP->totalMoles();
456 activity.resize(nSpeciesPhase, 0.0);
457 ac.resize(nSpeciesPhase, 0.0);
459 mu0.resize(nSpeciesPhase, 0.0);
460 mu.resize(nSpeciesPhase, 0.0);
461 volPM.resize(nSpeciesPhase, 0.0);
462 molalities.resize(nSpeciesPhase, 0.0);
471 double VolPhaseVolumes = 0.0;
472 for (k = 0; k < nSpeciesPhase; k++) {
473 VolPhaseVolumes += volPM[k] *
mf[istart + k];
475 VolPhaseVolumes *= TMolesPhase;
476 vol += VolPhaseVolumes;
479 if (actConvention == 1) {
486 fprintf(FP,
" Name, Phase, PhaseMoles, Mole_Fract, "
487 "Molalities, ActCoeff, Activity,"
488 "ChemPot_SS0, ChemPot, mole_num, PMVol, Phase_Volume\n");
490 fprintf(FP,
" , , (kmol), , "
492 " (J/kmol), (J/kmol), (kmol), (m**3/kmol), (m**3)\n");
494 for (k = 0; k < nSpeciesPhase; k++) {
496 fprintf(FP,
"%12s, %11s, %11.3e, %11.3e, %11.3e, %11.3e, %11.3e,"
497 "%11.3e, %11.3e, %11.3e, %11.3e, %11.3e\n",
499 phaseName.c_str(), TMolesPhase,
500 mf[istart + k], molalities[k], ac[k], activity[k],
501 mu0[k]*1.0E-6, mu[k]*1.0E-6,
502 mf[istart + k] * TMolesPhase,
503 volPM[k], VolPhaseVolumes);
508 fprintf(FP,
" Name, Phase, PhaseMoles, Mole_Fract, "
509 "Molalities, ActCoeff, Activity,"
510 " ChemPotSS0, ChemPot, mole_num, PMVol, Phase_Volume\n");
512 fprintf(FP,
" , , (kmol), , "
514 " (J/kmol), (J/kmol), (kmol), (m**3/kmol), (m**3)\n");
516 for (k = 0; k < nSpeciesPhase; k++) {
519 for (k = 0; k < nSpeciesPhase; k++) {
521 fprintf(FP,
"%12s, %11s, %11.3e, %11.3e, %11.3e, %11.3e, %11.3e, "
522 "%11.3e, %11.3e,% 11.3e, %11.3e, %11.3e\n",
524 phaseName.c_str(), TMolesPhase,
525 mf[istart + k], molalities[k], ac[k],
526 activity[k], mu0[k]*1.0E-6, mu[k]*1.0E-6,
527 mf[istart + k] * TMolesPhase,
528 volPM[k], VolPhaseVolumes);
537 for (k = 0; k < nSpeciesPhase; k++) {
539 fprintf(FP,
"ERROR: incompatibility!\n");
541 plogf(
"ERROR: incompatibility!\n");
std::vector< VCS_SPECIES_THERMO * > SpeciesThermo
Vector of pointers to thermo structures which identify the model and parameters for evaluating the th...
size_t NPHASE0
Number of phases used to malloc data structures.
std::vector< double > WtSpecies
Molecular weight of species.
size_t VP_ID_
Original ID of the phase in the problem.
int iest
Specification of the initial estimate method.
void resizePhase(size_t nPhase, int force)
Resizes all of the phase lists within the structure.
std::vector< double > w
Total number of moles of the kth species.
void setElemGlobalIndex(const size_t eLocal, const size_t eGlobal)
sets a local phase element to a global index value
std::string PhaseName
String name for the phase.
const size_t npos
index returned by functions to indicate "no position"
void prob_report(int print_lvl)
Print out the problem specification in all generality as it currently exists in the VCS_PROB object...
void setDebugPrintLvl(int vcs_debug_print_lvl)
Set the debug level.
#define VCS_DATA_PTR(vvv)
Points to the data in a std::vector<> object.
std::string elementName(const size_t e) const
Name of the element constraint with index e.
int m_NumBasisOptimizations
Number of basis optimizations used. This is an output variable.
size_t NE0
Number of element constraints used to malloc data structures involving elements.
std::vector< int > SpeciesUnknownType
Specifies the species unknown type.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void set_gai()
Calculate the element abundance vector from the mole numbers.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
std::vector< double > m_gibbsSpecies
Vector of chemical potentials of the species.
std::vector< int > ElActive
Specifies whether an element constraint is active.
int vcs_debug_print_lvl
Debug print lvl.
std::vector< double > Charge
Charge of each species.
Header for intermediate ThermoPhase object for phases which employ molality based activity coefficien...
size_t elemGlobalIndex(const size_t e) const
Returns the global index of the local element index for the phase.
#define VCS_PROBTYPE_TP
Current, it is always done holding T and P constant.
double GStar_calc_one(size_t kspec) const
Gibbs free energy calculation for standard state of one species.
Base class for a phase with thermodynamic properties.
double *const * baseDataAddr()
Returns a double** pointer to the base address.
size_t NPhase
Number of phases in the problem.
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.
Phase information and Phase calculations for vcs.
void resize(size_t mcol, size_t nrow, double v=0.0)
Resize the array, and fill the new entries with v
virtual void getActivities(doublereal *a) const
Get the array of non-dimensional activities at the current solution temperature, pressure, and solution concentration.
void addPhaseElements(vcs_VolPhase *volPhase)
Add elements to the local element list.
Internal declarations for the VCSnonideal package.
std::vector< std::string > ElName
vector of strings containing the element names
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
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.
Header for the Interface class for the vcs thermo equilibrium solver package,.
int prob_type
Problem type. I.e., the identity of what is held constant.
std::vector< size_t > PhaseID
Mapping between the species and the phases.
double const *const * getFormulaMatrix() const
Get a constant form of the Species Formula Matrix.
size_t nspecies
Total number of species in the problems.
DoubleStarStar FormulaMatrix
Formula Matrix for the problem.
size_t spGlobalIndexVCS(const size_t spIndex) const
Return the Global VCS index of the kth species in the phase.
int m_VCS_UnitsFormat
Units for the chemical potential data, pressure data, volume, and species amounts.
void resizeElements(size_t nel, int force)
Resizes all of the element lists within the structure.
int m_printLvl
Print level for print routines.
void setSpGlobalIndexVCS(const size_t spIndex, const size_t spGlobalIndex)
set the Global VCS index of the kth species in the phase
size_t nSpecies() const
Returns the number of species in the phase.
size_t nSpecies() const
Return the number of species in the phase.
std::vector< vcs_VolPhase * > VPhaseList
Array of phase structures.
bool m_singleSpecies
If true, this phase consists of a single species.
bool vcs_doubleEqual(double d1, double d2)
Simple routine to check whether two doubles are equal up to roundoff error.
size_t addOnePhaseSpecies(vcs_VolPhase *volPhase, size_t k, size_t kT)
This routines adds entries for the formula matrix for one species.
void resizeSpecies(size_t nsp, int force)
Resizes all of the species lists within the structure.
static void print_char(const char letter, const int num)
print char repeatedly to log file
double totalMolesInert() const
returns the value of the total kmol of inert in the phase
size_t nElemConstraints() const
Returns the number of element constraints.
size_t NSPECIES0
Species number used to malloc data structures.
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
void getMolalities(doublereal *const molal) const
This function will return the molalities of the species.
virtual int activityConvention() const
This method returns the convention used in specification of the activities, of which there are curren...
std::vector< std::string > SpName
Vector of strings containing the species names.
std::string string16_EOSType(int EOSType)
Return a string representing the equation of state.
std::vector< int > m_elType
vector of Element types
int m_Iterations
Number of iterations. This is an output variable.
double totalMoles() const
Return the total moles in the phase.
#define plogf
define this Cantera function to replace printf
int elementType(const size_t e) const
Type of the element constraint with index e.
std::vector< double > gai
Element abundances for jth element.
#define VCS_SPECIES_TYPE_INTERFACIALVOLTAGE
Unknown refers to the voltage level of a phase.
void setState_TP(const double temperature_Kelvin, const double pressure_PA)
Sets the temperature and pressure in this object and underlying ThermoPhase objects.
size_t ne
Number of element constraints in the equilibrium problem.
int m_eqnState
Type of the equation of state.
double T
Temperature (Kelvin)
Header file for class ThermoPhase, the base class for phases with thermodynamic properties, and the text for the Module thermoprops (see Thermodynamic Properties and class ThermoPhase).
std::vector< double > VolPM
Partial Molar Volumes of species.
std::string speciesName(size_t k) const
Name of the species with index k.
bool m_gasPhase
If true, this phase is a gas-phase like phase.
std::vector< double > mf
Mole fraction vector.
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...