14 #include "vcs_species_thermo.h"
35 VCS_PROB::VCS_PROB(
size_t nsp,
size_t nel,
size_t nph) :
46 m_VCS_UnitsFormat(VCS_UNITS_UNITLESS),
54 m_NumBasisOptimizations(0),
56 vcs_debug_print_lvl(0)
60 plogf(
"number of species is zero or neg\n");
65 plogf(
"number of elements is zero or neg\n");
70 plogf(
"number of phases is zero or neg\n");
74 plogf(
"number of species is less than number of phases\n");
93 for (
size_t kspec = 0; kspec <
nspecies; kspec++) {
94 VCS_SPECIES_THERMO* ts_tmp =
new VCS_SPECIES_THERMO(0, 0);
96 plogf(
"Failed to init a ts struct\n");
102 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
116 for (
size_t i = 0; i <
nspecies; i++) {
120 for (
size_t iph = 0; iph <
NPhase; iph++) {
137 if (force || nPhase >
NPHASE0) {
159 VolPM.resize(nsp, 0.0);
167 plogf(
"shouldn't be here\n");
185 if (force || nel >
NE0) {
186 gai.resize(nel, 0.0);
207 vcs_dzero(ElemAbund,
ne);
209 for (
size_t j = 0; j <
ne; j++) {
210 for (
size_t kspec = 0; kspec <
nspecies; kspec++) {
211 ElemAbund[j] += fm[j][kspec] *
w[kspec];
217 static void print_space(
int num)
219 for (
int j = 0; j < num; j++) {
224 static void print_char(
const char letter,
const int num)
226 for (
int i = 0; i < num; i++) {
250 plogf(
" VCS_PROB: PROBLEM STATEMENT ");
258 plogf(
"\tSolve a constant T, P problem:\n");
259 plogf(
"\t\tT = %g K\n",
T);
260 double pres_atm =
PresPA / 1.01325E5;
262 plogf(
"\t\tPres = %g atm\n", pres_atm);
264 plogf(
"\tUnknown problem type\n");
268 plogf(
" Phase IDs of species\n");
269 plogf(
" species phaseID phaseName ");
270 plogf(
" Initial_Estimated_Moles Species_Type\n");
271 for (
size_t i = 0; i <
nspecies; i++) {
273 plogf(
"%16s %5d %16s",
SpName[i].c_str(), PhaseID[i],
296 plogf(
" Information about phases\n");
297 plogf(
" PhaseName PhaseNum SingSpec GasPhase "
298 " EqnState NumSpec");
299 plogf(
" TMolesInert TKmoles\n");
301 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
303 std::string EOS_cstr = string16_EOSType(Vphase->
m_eqnState);
306 plogf(
"%16s %8d %16e ", EOS_cstr.c_str(),
315 plogf(
"\nElemental Abundances: ");
316 plogf(
" Target_kmol ElemType ElActive\n");
322 for (
size_t i = 0; i <
ne; ++i) {
329 plogf(
"\nChemical Potentials: ");
333 plogf(
"(kcal/gmol)");
342 plogf(
" Species (phase) "
343 " SS0ChemPot StarChemPot\n");
344 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
347 for (
size_t kindex = 0; kindex < Vphase->
nSpecies(); kindex++) {
364 plogf(
" VCS_PROB: END OF PROBLEM STATEMENT ");
392 size_t foundPos =
npos;
399 for (eVP = 0; eVP < neVP; eVP++) {
407 for (e = 0; e <
ne; e++) {
409 if (!strcmp(enVP.c_str(), en.c_str())) {
414 if (foundPos ==
npos) {
416 int elactive = volPhase->elementActive(eVP);
417 e =
addElement(enVP.c_str(), elType, elactive);
441 plogf(
"error: element must have a name\n");
473 plogf(
"Shouldn't be here\n");
494 void VCS_PROB::reportCSV(
const std::string& reportFile)
502 FILE* FP = fopen(reportFile.c_str(),
"w");
504 plogf(
"Failure to open file\n");
509 std::vector<double> volPM(
nspecies, 0.0);
510 std::vector<double> activity(
nspecies, 0.0);
511 std::vector<double> ac(
nspecies, 0.0);
512 std::vector<double> mu(
nspecies, 0.0);
513 std::vector<double> mu0(
nspecies, 0.0);
514 std::vector<double> molalities(
nspecies, 0.0);
518 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
522 size_t nSpeciesPhase = volP->nSpecies();
523 volPM.resize(nSpeciesPhase, 0.0);
526 double TMolesPhase = volP->totalMoles();
527 double VolPhaseVolumes = 0.0;
528 for (k = 0; k < nSpeciesPhase; k++) {
530 VolPhaseVolumes += volPM[istart + k] *
mf[istart + k];
532 VolPhaseVolumes *= TMolesPhase;
533 vol += VolPhaseVolumes;
536 fprintf(FP,
"--------------------- VCS_MULTIPHASE_EQUIL FINAL REPORT"
537 " -----------------------------\n");
538 fprintf(FP,
"Temperature = %11.5g kelvin\n", Temp);
539 fprintf(FP,
"Pressure = %11.5g Pascal\n",
PresPA);
540 fprintf(FP,
"Total Volume = %11.5g m**3\n", vol);
542 fprintf(FP,
"Number VCS iterations = %d\n",
m_Iterations);
545 for (
size_t iphase = 0; iphase <
NPhase; iphase++) {
550 string phaseName = volP->PhaseName;
551 size_t nSpeciesPhase = volP->
nSpecies();
553 double TMolesPhase = volP->totalMoles();
555 activity.resize(nSpeciesPhase, 0.0);
556 ac.resize(nSpeciesPhase, 0.0);
558 mu0.resize(nSpeciesPhase, 0.0);
559 mu.resize(nSpeciesPhase, 0.0);
560 volPM.resize(nSpeciesPhase, 0.0);
561 molalities.resize(nSpeciesPhase, 0.0);
570 double VolPhaseVolumes = 0.0;
571 for (k = 0; k < nSpeciesPhase; k++) {
572 VolPhaseVolumes += volPM[k] *
mf[istart + k];
574 VolPhaseVolumes *= TMolesPhase;
575 vol += VolPhaseVolumes;
578 if (actConvention == 1) {
585 fprintf(FP,
" Name, Phase, PhaseMoles, Mole_Fract, "
586 "Molalities, ActCoeff, Activity,"
587 "ChemPot_SS0, ChemPot, mole_num, PMVol, Phase_Volume\n");
589 fprintf(FP,
" , , (kmol), , "
591 " (J/kmol), (J/kmol), (kmol), (m**3/kmol), (m**3)\n");
593 for (k = 0; k < nSpeciesPhase; k++) {
595 fprintf(FP,
"%12s, %11s, %11.3e, %11.3e, %11.3e, %11.3e, %11.3e,"
596 "%11.3e, %11.3e, %11.3e, %11.3e, %11.3e\n",
598 phaseName.c_str(), TMolesPhase,
599 mf[istart + k], molalities[k], ac[k], activity[k],
600 mu0[k]*1.0E-6, mu[k]*1.0E-6,
601 mf[istart + k] * TMolesPhase,
602 volPM[k], VolPhaseVolumes);
607 fprintf(FP,
" Name, Phase, PhaseMoles, Mole_Fract, "
608 "Molalities, ActCoeff, Activity,"
609 " ChemPotSS0, ChemPot, mole_num, PMVol, Phase_Volume\n");
611 fprintf(FP,
" , , (kmol), , "
613 " (J/kmol), (J/kmol), (kmol), (m**3/kmol), (m**3)\n");
615 for (k = 0; k < nSpeciesPhase; k++) {
618 for (k = 0; k < nSpeciesPhase; k++) {
620 fprintf(FP,
"%12s, %11s, %11.3e, %11.3e, %11.3e, %11.3e, %11.3e, "
621 "%11.3e, %11.3e,% 11.3e, %11.3e, %11.3e\n",
623 phaseName.c_str(), TMolesPhase,
624 mf[istart + k], molalities[k], ac[k],
625 activity[k], mu0[k]*1.0E-6, mu[k]*1.0E-6,
626 mf[istart + k] * TMolesPhase,
627 volPM[k], VolPhaseVolumes);
636 for (k = 0; k < nSpeciesPhase; k++) {
638 fprintf(FP,
"ERROR: incompatibility!\n");
640 plogf(
"ERROR: incompatibility!\n");