24 VCS_PROB::VCS_PROB(
size_t nsp,
size_t nel,
size_t nph) :
41 m_NumBasisOptimizations(0),
43 vcs_debug_print_lvl(0)
48 "number of species is zero or neg");
53 "number of elements is zero or neg");
58 "number of phases is zero or neg");
62 "number of species is less than number of phases");
80 for (
size_t kspec = 0; kspec <
nspecies; kspec++) {
84 "Failed to init a ts struct");
89 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
96 for (
size_t i = 0; i <
nspecies; i++) {
99 for (
size_t iph = 0; iph <
NPhase; iph++) {
107 "Unused. To be removed after Cantera 2.3.");
108 if (force || nPhase >
NPHASE0) {
116 "Unused. To be removed after Cantera 2.3.");
123 VolPM.resize(nsp, 0.0);
130 throw CanteraError(
"VCS_PROB::resizeSpecies",
"shouldn't be here");
137 if (force || nel >
NE0) {
138 gai.resize(nel, 0.0);
150 gai.assign(
gai.size(), 0.0);
151 for (
size_t j = 0; j <
ne; j++) {
152 for (
size_t kspec = 0; kspec <
nspecies; kspec++) {
166 writeline(
'=', 80,
true,
true);
167 writeline(
'=', 20,
false);
168 plogf(
" VCS_PROB: PROBLEM STATEMENT ");
173 plogf(
"\tSolve a constant T, P problem:\n");
174 plogf(
"\t\tT = %g K\n",
T);
175 double pres_atm =
PresPA / 1.01325E5;
177 plogf(
"\t\tPres = %g atm\n", pres_atm);
179 throw CanteraError(
"VCS_PROB::prob_report",
"Unknown problem type");
182 plogf(
" Phase IDs of species\n");
183 plogf(
" species phaseID phaseName ");
184 plogf(
" Initial_Estimated_Moles Species_Type\n");
185 for (
size_t i = 0; i <
nspecies; i++) {
205 writeline(
'-', 80,
true,
true);
206 plogf(
" Information about phases\n");
207 plogf(
" PhaseName PhaseNum SingSpec GasPhase " 208 " EqnState NumSpec");
209 plogf(
" TMolesInert TKmoles\n");
211 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
224 plogf(
"\nElemental Abundances: ");
225 plogf(
" Target_kmol ElemType ElActive\n");
226 for (
size_t i = 0; i <
ne; ++i) {
227 writeline(
' ', 26,
false);
233 plogf(
"\nChemical Potentials: (J/kmol)\n");
234 plogf(
" Species (phase) " 235 " SS0ChemPot StarChemPot\n");
236 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
239 for (
size_t kindex = 0; kindex < Vphase->
nSpecies(); kindex++) {
252 writeline(
'=', 80,
true,
true);
253 writeline(
'=', 20,
false);
254 plogf(
" VCS_PROB: END OF PROBLEM STATEMENT ");
266 for (
size_t eVP = 0; eVP < neVP; eVP++) {
267 size_t foundPos =
npos;
272 for (
size_t e = 0; e <
ne; e++) {
273 std::string en =
ElName[e];
274 if (!strcmp(enVP.c_str(), en.c_str())) {
279 if (foundPos ==
npos) {
281 int elactive = volPhase->elementActive(eVP);
282 size_t e =
addElement(enVP.c_str(), elType, elactive);
292 "error: element must have a name");
307 throw CanteraError(
"VCS_PROB::addOnePhaseSpecies",
"Shouldn't be here");
313 "element not found");
323 void VCS_PROB::reportCSV(
const std::string& reportFile)
325 FILE* FP = fopen(reportFile.c_str(),
"w");
327 throw CanteraError(
"VCS_PROB::reportCSV",
"Failure to open file");
338 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
341 size_t nSpeciesPhase = volP->nSpecies();
342 volPM.resize(nSpeciesPhase, 0.0);
343 volP->sendToVCS_VolPM(&volPM[0]);
345 double TMolesPhase = volP->totalMoles();
346 double VolPhaseVolumes = 0.0;
347 for (
size_t k = 0; k < nSpeciesPhase; k++) {
349 VolPhaseVolumes += volPM[istart + k] *
mf[istart + k];
351 VolPhaseVolumes *= TMolesPhase;
352 vol += VolPhaseVolumes;
355 fprintf(FP,
"--------------------- VCS_MULTIPHASE_EQUIL FINAL REPORT" 356 " -----------------------------\n");
357 fprintf(FP,
"Temperature = %11.5g kelvin\n",
T);
358 fprintf(FP,
"Pressure = %11.5g Pascal\n",
PresPA);
359 fprintf(FP,
"Total Volume = %11.5g m**3\n", vol);
361 fprintf(FP,
"Number VCS iterations = %d\n",
m_Iterations);
364 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
368 const ThermoPhase* tp = volP->ptrThermoPhase();
369 string phaseName = volP->PhaseName;
370 size_t nSpeciesPhase = volP->nSpecies();
371 volP->sendToVCS_VolPM(&volPM[0]);
372 double TMolesPhase = volP->totalMoles();
373 activity.resize(nSpeciesPhase, 0.0);
374 ac.resize(nSpeciesPhase, 0.0);
375 mu0.resize(nSpeciesPhase, 0.0);
376 mu.resize(nSpeciesPhase, 0.0);
377 volPM.resize(nSpeciesPhase, 0.0);
378 molalities.resize(nSpeciesPhase, 0.0);
379 int actConvention = tp->activityConvention();
380 tp->getActivities(&activity[0]);
381 tp->getActivityCoefficients(&ac[0]);
382 tp->getStandardChemPotentials(&mu0[0]);
383 tp->getPartialMolarVolumes(&volPM[0]);
384 tp->getChemPotentials(&mu[0]);
385 double VolPhaseVolumes = 0.0;
386 for (
size_t k = 0; k < nSpeciesPhase; k++) {
387 VolPhaseVolumes += volPM[k] *
mf[istart + k];
389 VolPhaseVolumes *= TMolesPhase;
390 vol += VolPhaseVolumes;
392 if (actConvention == 1) {
393 const MolalityVPSSTP* mTP =
static_cast<const MolalityVPSSTP*
>(tp);
394 tp->getChemPotentials(&mu[0]);
395 mTP->getMolalities(&molalities[0]);
396 tp->getChemPotentials(&mu[0]);
399 fprintf(FP,
" Name, Phase, PhaseMoles, Mole_Fract, " 400 "Molalities, ActCoeff, Activity," 401 "ChemPot_SS0, ChemPot, mole_num, PMVol, Phase_Volume\n");
403 fprintf(FP,
" , , (kmol), , " 405 " (J/kmol), (J/kmol), (kmol), (m**3/kmol), (m**3)\n");
407 for (
size_t k = 0; k < nSpeciesPhase; k++) {
408 std::string sName = tp->speciesName(k);
409 fprintf(FP,
"%12s, %11s, %11.3e, %11.3e, %11.3e, %11.3e, %11.3e," 410 "%11.3e, %11.3e, %11.3e, %11.3e, %11.3e\n",
412 phaseName.c_str(), TMolesPhase,
413 mf[istart + k], molalities[k], ac[k], activity[k],
414 mu0[k]*1.0E-6, mu[k]*1.0E-6,
415 mf[istart + k] * TMolesPhase,
416 volPM[k], VolPhaseVolumes);
420 fprintf(FP,
" Name, Phase, PhaseMoles, Mole_Fract, " 421 "Molalities, ActCoeff, Activity," 422 " ChemPotSS0, ChemPot, mole_num, PMVol, Phase_Volume\n");
424 fprintf(FP,
" , , (kmol), , " 426 " (J/kmol), (J/kmol), (kmol), (m**3/kmol), (m**3)\n");
428 for (
size_t k = 0; k < nSpeciesPhase; k++) {
431 for (
size_t k = 0; k < nSpeciesPhase; k++) {
432 std::string sName = tp->speciesName(k);
433 fprintf(FP,
"%12s, %11s, %11.3e, %11.3e, %11.3e, %11.3e, %11.3e, " 434 "%11.3e, %11.3e,% 11.3e, %11.3e, %11.3e\n",
436 phaseName.c_str(), TMolesPhase,
437 mf[istart + k], molalities[k], ac[k],
438 activity[k], mu0[k]*1.0E-6, mu[k]*1.0E-6,
439 mf[istart + k] * TMolesPhase,
440 volPM[k], VolPhaseVolumes);
vector_fp VolPM
Partial Molar Volumes of species.
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'.
size_t nElemConstraints() const
Returns the number of element constraints.
const size_t npos
index returned by functions to indicate "no position"
std::vector< std::string > ElName
vector of strings containing the element names
int iest
Specification of the initial estimate method.
size_t NSPECIES0
Species number used to size data structures.
const Array2D & getFormulaMatrix() const
Get a constant form of the Species Formula Matrix.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
size_t spGlobalIndexVCS(const size_t spIndex) const
Return the Global VCS index of the kth 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 elementName(const size_t e) const
Name of the element constraint with index e.
std::string PhaseName
String name for the phase.
size_t elemGlobalIndex(const size_t e) const
Returns the global index of the local element index for the phase.
std::vector< vcs_VolPhase * > VPhaseList
Array of phase structures.
int m_Iterations
Number of iterations. This is an output variable.
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.
Header for the object representing each phase within vcs.
double GStar_calc_one(size_t kspec) const
Gibbs free energy calculation for standard state of one species.
#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.
vector_fp gai
Element abundances for jth element.
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.
vector_int ElActive
Specifies whether an element constraint is active.
std::string eos_name() const
Return the name corresponding to the equation of state.
vector_int SpeciesUnknownType
Specifies the species unknown type.
Header for the Interface class for the vcs thermo equilibrium solver package,.
size_t NPHASE0
Number of phases used to size data structures.
vector_fp Charge
Charge of each species.
size_t nspecies
Total number of species in the problems.
vector_fp w
Total number of moles of the kth species.
size_t nSpecies() const
Return the number of species in the phase.
Base class for exceptions thrown by Cantera classes.
int elementType(const size_t e) const
Type of the element constraint with index e.
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.
double totalMoles() const
Return the total moles in the phase.
vector_fp WtSpecies
Molecular weight of species.
vector_fp mf
Mole fraction vector.
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.
size_t ne
Number of element constraints in the equilibrium problem.
vector_fp m_gibbsSpecies
Vector of chemical potentials of the species.
int prob_type
Problem type.
#define AssertThrowMsg(expr, procedure,...)
Assertion must be true or an error is thrown.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
std::vector< std::string > SpName
Vector of strings containing the species names.
vector_int m_elType
vector of Element types
size_t NE0
Number of element constraints used to size 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
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 NPhase
Number of phases in the problem.
Namespace for the Cantera kernel.
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.
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.
void setElemGlobalIndex(const size_t eLocal, const size_t eGlobal)
sets a local phase element to a global index value