24 vcs_VolPhase::vcs_VolPhase(VCS_SOLVE* owningSolverObject) :
25 m_owningSolverObject(0),
27 m_singleSpecies(true),
29 m_eqnState(VCS_EOS_CONSTANT),
30 ChargeNeutralityElement(
npos),
31 p_VCS_UnitsFormat(VCS_UNITS_MKS),
32 p_activityConvention(0),
33 m_numElemConstraints(0),
36 m_totalMolesInert(0.0),
41 m_useCanteraCalls(false),
44 creationMoleNumbers_(0),
45 creationGlobalRxnNumbers_(0),
52 m_UpToDate_VolStar(false),
53 m_UpToDate_VolPM(false),
54 m_UpToDate_GStar(false),
59 m_owningSolverObject = owningSolverObject;
62 vcs_VolPhase::~vcs_VolPhase()
64 for (
size_t k = 0; k < m_numSpecies; k++) {
65 vcs_SpeciesProperties* sp = ListSpeciesPtr[k];
71 vcs_VolPhase::vcs_VolPhase(
const vcs_VolPhase& b) :
72 m_owningSolverObject(b.m_owningSolverObject),
74 m_singleSpecies(b.m_singleSpecies),
75 m_gasPhase(b.m_gasPhase),
76 m_eqnState(b.m_eqnState),
77 ChargeNeutralityElement(b.ChargeNeutralityElement),
78 p_VCS_UnitsFormat(b.p_VCS_UnitsFormat),
79 p_activityConvention(b.p_activityConvention),
80 m_numElemConstraints(b.m_numElemConstraints),
81 m_numSpecies(b.m_numSpecies),
82 m_totalMolesInert(b.m_totalMolesInert),
83 m_isIdealSoln(b.m_isIdealSoln),
84 m_existence(b.m_existence),
85 m_MFStartIndex(b.m_MFStartIndex),
86 m_useCanteraCalls(b.m_useCanteraCalls),
88 v_totalMoles(b.v_totalMoles),
89 creationMoleNumbers_(0),
90 creationGlobalRxnNumbers_(0),
92 m_totalVol(b.m_totalVol),
97 m_UpToDate_VolStar(false),
98 m_UpToDate_VolPM(false),
99 m_UpToDate_GStar(false),
100 m_UpToDate_G0(false),
109 vcs_VolPhase& vcs_VolPhase::operator=(
const vcs_VolPhase& b)
112 size_t old_num = m_numSpecies;
120 m_singleSpecies = b.m_singleSpecies;
121 m_gasPhase = b.m_gasPhase;
122 m_eqnState = b.m_eqnState;
123 ChargeNeutralityElement = b.ChargeNeutralityElement;
124 p_VCS_UnitsFormat = b.p_VCS_UnitsFormat;
125 p_activityConvention= b.p_activityConvention;
126 m_numSpecies = b.m_numSpecies;
127 m_numElemConstraints = b.m_numElemConstraints;
128 m_elementNames.resize(b.m_numElemConstraints);
129 for (
size_t e = 0; e < b.m_numElemConstraints; e++) {
130 m_elementNames[e] = b.m_elementNames[e];
132 m_elementActive = b.m_elementActive;
133 m_elementType = b.m_elementType;
134 m_formulaMatrix.resize(m_numElemConstraints, m_numSpecies, 0.0);
135 for (
size_t e = 0; e < m_numElemConstraints; e++) {
136 for (
size_t k = 0; k < m_numSpecies; k++) {
137 m_formulaMatrix[e][k] = b.m_formulaMatrix[e][k];
140 m_speciesUnknownType = b.m_speciesUnknownType;
141 m_elemGlobalIndex = b.m_elemGlobalIndex;
142 PhaseName = b.PhaseName;
143 m_totalMolesInert = b.m_totalMolesInert;
144 m_isIdealSoln = b.m_isIdealSoln;
145 m_existence = b.m_existence;
146 m_MFStartIndex = b.m_MFStartIndex;
150 IndSpecies = b.IndSpecies;
153 for (
size_t k = 0; k < old_num; k++) {
154 if (ListSpeciesPtr[k]) {
155 delete ListSpeciesPtr[k];
156 ListSpeciesPtr[k] = 0;
159 ListSpeciesPtr.resize(m_numSpecies, 0);
160 for (
size_t k = 0; k < m_numSpecies; k++) {
162 new vcs_SpeciesProperties(*(b.ListSpeciesPtr[k]));
164 m_useCanteraCalls = b.m_useCanteraCalls;
173 v_totalMoles = b.v_totalMoles;
175 creationMoleNumbers_ = b.creationMoleNumbers_;
176 creationGlobalRxnNumbers_ = b.creationGlobalRxnNumbers_;
177 m_phiVarIndex = b.m_phiVarIndex;
178 m_totalVol = b.m_totalVol;
179 SS0ChemicalPotential = b.SS0ChemicalPotential;
180 StarChemicalPotential = b.StarChemicalPotential;
181 StarMolarVol = b.StarMolarVol;
182 PartialMolarVol = b.PartialMolarVol;
183 ActCoeff = b.ActCoeff;
184 np_dLnActCoeffdMolNumber = b.np_dLnActCoeffdMolNumber;
185 m_vcsStateStatus = b.m_vcsStateStatus;
188 m_UpToDate_AC =
false;
189 m_UpToDate_VolStar =
false;
190 m_UpToDate_VolPM =
false;
191 m_UpToDate_GStar =
false;
192 m_UpToDate_G0 =
false;
196 setState_TP(Temp_, Pres_);
197 _updateMoleFractionDependencies();
202 void vcs_VolPhase::resize(
const size_t phaseNum,
const size_t nspecies,
203 const size_t numElem,
const char*
const phaseName,
204 const double molesInert)
208 plogf(
"nspecies Error\n");
212 plogf(
"phaseNum should be greater than 0\n");
216 setTotalMolesInert(molesInert);
218 m_phiVarIndex =
npos;
220 if (phaseNum == VP_ID_) {
221 if (strcmp(PhaseName.c_str(), phaseName)) {
222 plogf(
"Strings are different: %s %s :unknown situation\n",
223 PhaseName.c_str(), phaseName);
229 std::stringstream sstmp;
230 sstmp <<
"Phase_" << VP_ID_;
231 PhaseName = sstmp.str();
233 PhaseName = phaseName;
237 m_singleSpecies =
false;
239 m_singleSpecies =
true;
242 if (m_numSpecies == nspecies && numElem == m_numElemConstraints) {
246 m_numSpecies = nspecies;
248 m_singleSpecies =
false;
252 IndSpecies.resize(nspecies,
npos);
254 if (ListSpeciesPtr.size() >= m_numSpecies) {
255 for (
size_t i = 0; i < m_numSpecies; i++) {
256 if (ListSpeciesPtr[i]) {
257 delete ListSpeciesPtr[i];
258 ListSpeciesPtr[i] = 0;
262 ListSpeciesPtr.resize(nspecies, 0);
263 for (
size_t i = 0; i < nspecies; i++) {
267 Xmol_.resize(nspecies, 0.0);
268 creationMoleNumbers_.resize(nspecies, 0.0);
269 creationGlobalRxnNumbers_.resize(nspecies,
npos);
270 for (
size_t i = 0; i < nspecies; i++) {
271 Xmol_[i] = 1.0/nspecies;
272 creationMoleNumbers_[i] = 1.0/nspecies;
273 if (IndSpecies[i] - m_numElemConstraints >= 0) {
274 creationGlobalRxnNumbers_[i] = IndSpecies[i] - m_numElemConstraints;
276 creationGlobalRxnNumbers_[i] =
npos;
280 SS0ChemicalPotential.resize(nspecies, -1.0);
281 StarChemicalPotential.resize(nspecies, -1.0);
282 StarMolarVol.resize(nspecies, -1.0);
283 PartialMolarVol.resize(nspecies, -1.0);
284 ActCoeff.resize(nspecies, 1.0);
285 np_dLnActCoeffdMolNumber.resize(nspecies, nspecies, 0.0);
291 m_UpToDate_AC =
false;
292 m_UpToDate_VolStar =
false;
293 m_UpToDate_VolPM =
false;
294 m_UpToDate_GStar =
false;
295 m_UpToDate_G0 =
false;
302 void vcs_VolPhase::elemResize(
const size_t numElemConstraints)
305 m_elementNames.resize(numElemConstraints);
307 m_elementActive.resize(numElemConstraints+1, 1);
309 m_formulaMatrix.resize(numElemConstraints, m_numSpecies, 0.0);
311 m_elementNames.resize(numElemConstraints,
"");
312 m_elemGlobalIndex.resize(numElemConstraints,
npos);
314 m_numElemConstraints = numElemConstraints;
317 void vcs_VolPhase::_updateActCoeff()
const
320 m_UpToDate_AC =
true;
323 if (m_useCanteraCalls) {
324 TP_ptr->getActivityCoefficients(
VCS_DATA_PTR(ActCoeff));
326 m_UpToDate_AC =
true;
329 double vcs_VolPhase::AC_calc_one(
size_t kspec)
const
331 if (! m_UpToDate_AC) {
334 return ActCoeff[kspec];
337 void vcs_VolPhase::_updateG0()
const
339 if (m_useCanteraCalls) {
340 TP_ptr->getGibbs_ref(
VCS_DATA_PTR(SS0ChemicalPotential));
343 for (
size_t k = 0; k < m_numSpecies; k++) {
344 size_t kglob = IndSpecies[k];
347 SS0ChemicalPotential[k] =
351 m_UpToDate_G0 =
true;
354 double vcs_VolPhase::G0_calc_one(
size_t kspec)
const
356 if (!m_UpToDate_G0) {
359 return SS0ChemicalPotential[kspec];
362 void vcs_VolPhase::_updateGStar()
const
364 if (m_useCanteraCalls) {
365 TP_ptr->getStandardChemPotentials(
VCS_DATA_PTR(StarChemicalPotential));
368 for (
size_t k = 0; k < m_numSpecies; k++) {
369 size_t kglob = IndSpecies[k];
372 StarChemicalPotential[k] =
376 m_UpToDate_GStar =
true;
379 double vcs_VolPhase::GStar_calc_one(
size_t kspec)
const
381 if (!m_UpToDate_GStar) {
384 return StarChemicalPotential[kspec];
387 void vcs_VolPhase::setMoleFractions(
const double*
const xmol)
390 for (
size_t k = 0; k < m_numSpecies; k++) {
394 if (std::fabs(sum) > 1.0E-13) {
395 for (
size_t k = 0; k < m_numSpecies; k++) {
399 _updateMoleFractionDependencies();
404 void vcs_VolPhase::_updateMoleFractionDependencies()
406 if (m_useCanteraCalls) {
408 TP_ptr->setState_PX(Pres_, &(Xmol_[m_MFStartIndex]));
411 if (!m_isIdealSoln) {
412 m_UpToDate_AC =
false;
413 m_UpToDate_VolPM =
false;
417 const std::vector<double> & vcs_VolPhase::moleFractions()
const
422 double vcs_VolPhase::moleFraction(
size_t k)
const
427 void vcs_VolPhase::setMoleFractionsState(
const double totalMoles,
428 const double*
const moleFractions,
429 const int vcsStateStatus)
432 if (totalMoles != 0.0) {
436 printf(
"vcs_VolPhase::setMolesFractionsState: inappropriate usage\n");
442 printf(
"vcs_VolPhase::setMolesFractionsState: inappropriate usage\n");
448 m_vcsStateStatus = vcsStateStatus;
453 double fractotal = 1.0;
454 v_totalMoles = totalMoles;
455 if (m_totalMolesInert > 0.0) {
456 if (m_totalMolesInert > v_totalMoles) {
457 printf(
"vcs_VolPhase::setMolesFractionsState: inerts greater than total: %g %g\n",
458 v_totalMoles, m_totalMolesInert);
461 fractotal = 1.0 - m_totalMolesInert/v_totalMoles;
464 for (
size_t k = 0; k < m_numSpecies; k++) {
465 Xmol_[k] = moleFractions[k];
466 sum += moleFractions[k];
469 printf(
"vcs_VolPhase::setMolesFractionsState: inappropriate usage\n");
472 if (sum != fractotal) {
473 for (
size_t k = 0; k < m_numSpecies; k++) {
474 Xmol_[k] *= (fractotal /sum);
477 _updateMoleFractionDependencies();
481 void vcs_VolPhase::setMolesFromVCS(
const int stateCalc,
482 const double* molesSpeciesVCS)
486 v_totalMoles = m_totalMolesInert;
488 if (molesSpeciesVCS == 0) {
490 if (m_owningSolverObject == 0) {
491 printf(
"vcs_VolPhase::setMolesFromVCS shouldn't be here\n");
496 molesSpeciesVCS =
VCS_DATA_PTR(m_owningSolverObject->m_molNumSpecies_old);
498 molesSpeciesVCS =
VCS_DATA_PTR(m_owningSolverObject->m_molNumSpecies_new);
502 printf(
"vcs_VolPhase::setMolesFromVCS shouldn't be here\n");
509 if (m_owningSolverObject) {
511 if (molesSpeciesVCS !=
VCS_DATA_PTR(m_owningSolverObject->m_molNumSpecies_old)) {
512 printf(
"vcs_VolPhase::setMolesFromVCS shouldn't be here\n");
516 if (molesSpeciesVCS !=
VCS_DATA_PTR(m_owningSolverObject->m_molNumSpecies_new)) {
517 printf(
"vcs_VolPhase::setMolesFromVCS shouldn't be here\n");
525 for (
size_t k = 0; k < m_numSpecies; k++) {
527 kglob = IndSpecies[k];
528 v_totalMoles += std::max(0.0, molesSpeciesVCS[kglob]);
531 if (v_totalMoles > 0.0) {
532 for (
size_t k = 0; k < m_numSpecies; k++) {
534 kglob = IndSpecies[k];
535 tmp = std::max(0.0, molesSpeciesVCS[kglob]);
536 Xmol_[k] = tmp / v_totalMoles;
553 if (m_phiVarIndex !=
npos) {
554 kglob = IndSpecies[m_phiVarIndex];
555 if (m_numSpecies == 1) {
556 Xmol_[m_phiVarIndex] = 1.0;
558 Xmol_[m_phiVarIndex] = 0.0;
560 double phi = molesSpeciesVCS[kglob];
561 setElectricPotential(phi);
562 if (m_numSpecies == 1) {
566 _updateMoleFractionDependencies();
567 if (m_totalMolesInert > 0.0) {
577 if (v_totalMoles > 0.0) {
587 m_vcsStateStatus = stateCalc;
590 void vcs_VolPhase::setMolesFromVCSCheck(
const int vcsStateStatus,
591 const double* molesSpeciesVCS,
592 const double*
const TPhMoles)
594 setMolesFromVCS(vcsStateStatus, molesSpeciesVCS);
598 double Tcheck = TPhMoles[VP_ID_];
599 if (Tcheck != v_totalMoles) {
601 Tcheck = v_totalMoles;
603 plogf(
"vcs_VolPhase::setMolesFromVCSCheck: "
604 "We have a consistency problem: %21.16g %21.16g\n",
605 Tcheck, v_totalMoles);
611 void vcs_VolPhase::updateFromVCS_MoleNumbers(
const int vcsStateStatus)
613 if (!m_UpToDate || (vcsStateStatus != m_vcsStateStatus)) {
615 if (m_owningSolverObject) {
616 setMolesFromVCS(vcsStateStatus);
622 void vcs_VolPhase::sendToVCS_ActCoeff(
const int vcsStateStatus,
625 updateFromVCS_MoleNumbers(vcsStateStatus);
626 if (!m_UpToDate_AC) {
629 for (
size_t k = 0; k < m_numSpecies; k++) {
630 size_t kglob = IndSpecies[k];
631 AC[kglob] = ActCoeff[k];
635 double vcs_VolPhase::sendToVCS_VolPM(
double*
const VolPM)
const
637 if (!m_UpToDate_VolPM) {
638 (void) _updateVolPM();
640 for (
size_t k = 0; k < m_numSpecies; k++) {
641 size_t kglob = IndSpecies[k];
642 VolPM[kglob] = PartialMolarVol[k];
647 void vcs_VolPhase::sendToVCS_GStar(
double*
const gstar)
const
649 if (!m_UpToDate_GStar) {
652 for (
size_t k = 0; k < m_numSpecies; k++) {
653 size_t kglob = IndSpecies[k];
654 gstar[kglob] = StarChemicalPotential[k];
658 void vcs_VolPhase::setElectricPotential(
const double phi)
661 if (m_useCanteraCalls) {
662 TP_ptr->setElectricPotential(m_phi);
665 m_UpToDate_AC =
false;
666 m_UpToDate_VolStar =
false;
667 m_UpToDate_VolPM =
false;
668 m_UpToDate_GStar =
false;
671 double vcs_VolPhase::electricPotential()
const
676 void vcs_VolPhase::setState_TP(
const double temp,
const double pres)
683 if (m_useCanteraCalls) {
684 TP_ptr->setElectricPotential(m_phi);
685 TP_ptr->setState_TP(temp, pres);
689 m_UpToDate_AC =
false;
690 m_UpToDate_VolStar =
false;
691 m_UpToDate_VolPM =
false;
692 m_UpToDate_GStar =
false;
693 m_UpToDate_G0 =
false;
696 void vcs_VolPhase::setState_T(
const double temp)
698 setState_TP(temp, Pres_);
701 void vcs_VolPhase::_updateVolStar()
const
703 if (m_useCanteraCalls) {
706 for (
size_t k = 0; k < m_numSpecies; k++) {
707 size_t kglob = IndSpecies[k];
710 StarMolarVol[k] = (sTherm->
VolStar_calc(kglob, Temp_, Pres_));
713 m_UpToDate_VolStar =
true;
716 double vcs_VolPhase::VolStar_calc_one(
size_t kspec)
const
718 if (!m_UpToDate_VolStar) {
721 return StarMolarVol[kspec];
724 double vcs_VolPhase::_updateVolPM()
const
726 if (m_useCanteraCalls) {
727 TP_ptr->getPartialMolarVolumes(
VCS_DATA_PTR(PartialMolarVol));
729 for (
size_t k = 0; k < m_numSpecies; k++) {
730 size_t kglob = IndSpecies[k];
733 StarMolarVol[k] = (sTherm->
VolStar_calc(kglob, Temp_, Pres_));
735 for (
size_t k = 0; k < m_numSpecies; k++) {
736 PartialMolarVol[k] = StarMolarVol[k];
741 for (
size_t k = 0; k < m_numSpecies; k++) {
742 m_totalVol += PartialMolarVol[k] * Xmol_[k];
744 m_totalVol *= v_totalMoles;
746 if (m_totalMolesInert > 0.0) {
751 printf(
"unknown situation\n");
755 m_UpToDate_VolPM =
true;
759 void vcs_VolPhase::_updateLnActCoeffJac()
761 double phaseTotalMoles = v_totalMoles;
762 if (phaseTotalMoles < 1.0E-14) {
763 phaseTotalMoles = 1.0;
769 if (!m_UpToDate_AC) {
775 TP_ptr->getdlnActCoeffdlnN(m_numSpecies, &np_dLnActCoeffdMolNumber[0][0]);
776 for (
size_t j = 0; j < m_numSpecies; j++) {
777 double moles_j_base = phaseTotalMoles * Xmol_[j];
778 double*
const np_lnActCoeffCol = np_dLnActCoeffdMolNumber[j];
779 if (moles_j_base < 1.0E-200) {
780 moles_j_base = 1.0E-7 * moles_j_base + 1.0E-13 * phaseTotalMoles + 1.0E-150;
782 for (
size_t k = 0; k < m_numSpecies; k++) {
783 np_lnActCoeffCol[k] = np_lnActCoeffCol[k] * phaseTotalMoles / moles_j_base;
787 double deltaMoles_j = 0.0;
789 std::vector<double> ActCoeff_Base(ActCoeff);
790 std::vector<double> Xmol_Base(Xmol_);
791 double TMoles_base = phaseTotalMoles;
796 for (
size_t j = 0; j < m_numSpecies; j++) {
802 double moles_j_base = phaseTotalMoles * Xmol_Base[j];
803 deltaMoles_j = 1.0E-7 * moles_j_base + 1.0E-13 * phaseTotalMoles + 1.0E-150;
808 phaseTotalMoles = TMoles_base + deltaMoles_j;
809 for (
size_t k = 0; k < m_numSpecies; k++) {
810 Xmol_[k] = Xmol_Base[k] * TMoles_base / phaseTotalMoles;
812 Xmol_[j] = (moles_j_base + deltaMoles_j) / phaseTotalMoles;
818 _updateMoleFractionDependencies();
823 double*
const np_lnActCoeffCol = np_dLnActCoeffdMolNumber[j];
824 for (
size_t k = 0; k < m_numSpecies; k++) {
826 tmp = (ActCoeff[k] - ActCoeff_Base[k]) /
827 ((ActCoeff[k] + ActCoeff_Base[k]) * 0.5 * deltaMoles_j);
828 if (fabs(tmp - np_lnActCoeffCol[k]) > 1.0E-4 * fabs(tmp) + fabs(np_lnActCoeffCol[k])) {
838 v_totalMoles = TMoles_base;
839 vcs_vdcopy(Xmol_, Xmol_Base, m_numSpecies);
848 _updateMoleFractionDependencies();
852 void vcs_VolPhase::sendToVCS_LnActCoeffJac(
double*
const*
const np_LnACJac_VCS)
859 _updateLnActCoeffJac();
864 for (
size_t j = 0; j < m_numSpecies; j++) {
865 size_t jglob = IndSpecies[j];
866 double*
const np_lnACJacVCS_col = np_LnACJac_VCS[jglob];
867 const double*
const np_lnACJac_col = np_dLnActCoeffdMolNumber[j];
868 for (
size_t k = 0; k < m_numSpecies; k++) {
869 size_t kglob = IndSpecies[k];
870 np_lnACJacVCS_col[kglob] = np_lnACJac_col[k];
879 m_useCanteraCalls =
true;
881 Pres_ = TP_ptr->pressure();
882 setState_TP(Temp_, Pres_);
883 p_VCS_UnitsFormat = VCS_UNITS_MKS;
884 m_phi = TP_ptr->electricPotential();
885 size_t nsp = TP_ptr->nSpecies();
886 size_t nelem = TP_ptr->nElements();
887 if (nsp != m_numSpecies) {
888 if (m_numSpecies != 0) {
889 plogf(
"Warning Nsp != NVolSpeces: %d %d \n", nsp, m_numSpecies);
891 resize(VP_ID_, nsp, nelem, PhaseName.c_str());
895 _updateMoleFractionDependencies();
901 m_isIdealSoln =
true;
903 int eos = TP_ptr->eosType();
906 case Cantera::cIncompressible:
909 case Cantera::cStoichSubstance:
910 case Cantera::cSemiconductor:
911 case Cantera::cLatticeSolid:
912 case Cantera::cLattice:
915 m_isIdealSoln =
true;
918 m_isIdealSoln =
false;
922 m_useCanteraCalls =
false;
931 double vcs_VolPhase::totalMoles()
const
936 double vcs_VolPhase::molefraction(
size_t k)
const
941 void vcs_VolPhase::setCreationMoleNumbers(
const double*
const n_k,
942 const std::vector<size_t> &creationGlobalRxnNumbers)
944 vcs_dcopy(
VCS_DATA_PTR(creationMoleNumbers_), n_k, m_numSpecies);
945 for (
size_t k = 0; k < m_numSpecies; k++) {
946 creationGlobalRxnNumbers_[k] = creationGlobalRxnNumbers[k];
950 const std::vector<double> & vcs_VolPhase::creationMoleNumbers(std::vector<size_t> &creationGlobalRxnNumbers)
const
952 creationGlobalRxnNumbers = creationGlobalRxnNumbers_;
953 return creationMoleNumbers_;
956 void vcs_VolPhase::setTotalMoles(
const double totalMols)
958 v_totalMoles = totalMols;
959 if (m_totalMolesInert > 0.0) {
962 if (totalMols < m_totalMolesInert) {
963 printf(
" vcs_VolPhase::setTotalMoles:: ERROR totalMoles "
964 "less than inert moles: %g %g\n",
965 totalMols, m_totalMolesInert);
970 if (m_singleSpecies && (m_phiVarIndex == 0)) {
973 if (totalMols > 0.0) {
982 void vcs_VolPhase::setMolesOutOfDate(
int stateCalc)
985 if (stateCalc != -1) {
986 m_vcsStateStatus = stateCalc;
990 void vcs_VolPhase::setMolesCurrent(
int stateCalc)
993 m_vcsStateStatus = stateCalc;
1001 case VCS_EOS_CONSTANT:
1002 sprintf(st,
"Constant ");
1004 case VCS_EOS_IDEAL_GAS:
1005 sprintf(st,
"Ideal Gas ");
1007 case VCS_EOS_STOICH_SUB:
1008 sprintf(st,
"Stoich Sub ");
1010 case VCS_EOS_IDEAL_SOLN:
1011 sprintf(st,
"Ideal Soln ");
1013 case VCS_EOS_DEBEYE_HUCKEL:
1014 sprintf(st,
"Debeye Huckel ");
1016 case VCS_EOS_REDLICK_KWONG:
1017 sprintf(st,
"Redlick_Kwong ");
1019 case VCS_EOS_REGULAR_SOLN:
1020 sprintf(st,
"Regular Soln ");
1023 sprintf(st,
"UnkType: %-7d", EOSType);
1030 bool vcs_VolPhase::isIdealSoln()
const
1032 return m_isIdealSoln;
1035 bool vcs_VolPhase::usingCanteraCalls()
const
1037 return m_useCanteraCalls;
1040 size_t vcs_VolPhase::phiVarIndex()
const
1042 return m_phiVarIndex;
1045 void vcs_VolPhase::setPhiVarIndex(
size_t phiVarIndex)
1047 m_phiVarIndex = phiVarIndex;
1049 if (m_singleSpecies) {
1050 if (m_phiVarIndex == 0) {
1058 return ListSpeciesPtr[kindex];
1061 int vcs_VolPhase::exists()
const
1066 void vcs_VolPhase::setExistence(
const int existence)
1069 if (v_totalMoles != 0.0) {
1071 plogf(
"vcs_VolPhase::setExistence setting false existence for phase with moles");
1081 if (m_totalMolesInert == 0.0) {
1082 if (v_totalMoles == 0.0) {
1083 if (!m_singleSpecies || m_phiVarIndex != 0) {
1084 plogf(
"vcs_VolPhase::setExistence setting true existence for phase with no moles");
1093 if (m_singleSpecies) {
1094 if (m_phiVarIndex == 0) {
1096 plogf(
"vcs_VolPhase::Trying to set existence of an electron phase to false");
1103 m_existence = existence;
1106 size_t vcs_VolPhase::spGlobalIndexVCS(
const size_t spIndex)
const
1108 return IndSpecies[spIndex];
1111 void vcs_VolPhase::setSpGlobalIndexVCS(
const size_t spIndex,
1112 const size_t spGlobalIndex)
1114 IndSpecies[spIndex] = spGlobalIndex;
1115 if (spGlobalIndex >= m_numElemConstraints) {
1116 creationGlobalRxnNumbers_[spIndex] = spGlobalIndex - m_numElemConstraints;
1120 void vcs_VolPhase::setTotalMolesInert(
const double tMolesInert)
1122 if (m_totalMolesInert != tMolesInert) {
1124 m_UpToDate_AC =
false;
1125 m_UpToDate_VolStar =
false;
1126 m_UpToDate_VolPM =
false;
1127 m_UpToDate_GStar =
false;
1128 m_UpToDate_G0 =
false;
1129 v_totalMoles += (tMolesInert - m_totalMolesInert);
1130 m_totalMolesInert = tMolesInert;
1132 if (m_totalMolesInert > 0.0) {
1134 }
else if (m_singleSpecies && (m_phiVarIndex == 0)) {
1137 if (v_totalMoles > 0.0) {
1145 double vcs_VolPhase::totalMolesInert()
const
1147 return m_totalMolesInert;
1150 size_t vcs_VolPhase::elemGlobalIndex(
const size_t e)
const
1152 AssertThrow(e < m_numElemConstraints,
" vcs_VolPhase::elemGlobalIndex");
1153 return m_elemGlobalIndex[e];
1156 void vcs_VolPhase::setElemGlobalIndex(
const size_t eLocal,
const size_t eGlobal)
1159 "vcs_VolPhase::setElemGlobalIndex");
1160 m_elemGlobalIndex[eLocal] = eGlobal;
1163 size_t vcs_VolPhase::nElemConstraints()
const
1165 return m_numElemConstraints;
1168 std::string vcs_VolPhase::elementName(
const size_t e)
const
1170 return m_elementNames[e];
1176 for (
size_t k = 0; k < tPhase->
nSpecies(); k++) {
1177 if (tPhase->
charge(k) != 0.0) {
1205 size_t eFound =
npos;
1216 ChargeNeutralityElement = ne;
1226 if (ChargeNeutralityElement !=
npos) {
1241 for (eT = 0; eT < nebase; eT++) {
1245 m_elementActive[eT] = 0;
1250 for (eT = 0; eT < nebase; eT++) {
1258 if (eFound ==
npos) {
1261 m_elementActive[ne] = 0;
1262 std::string ename =
"E";
1263 m_elementNames[ne] = ename;
1270 m_formulaMatrix.resize(ne, ns, 0.0);
1277 for (eT = 0; eT < nebase; eT++) {
1279 m_elementNames[e] = ename;
1285 std::string pname = tPhase->
id();
1287 std::stringstream sss;
1288 sss <<
"phase" << VP_ID_;
1291 ename =
"cn_" + pname;
1292 e = ChargeNeutralityElement;
1293 m_elementNames[e] = ename;
1296 double*
const*
const fm = m_formulaMatrix.baseDataAddr();
1297 for (k = 0; k < ns; k++) {
1299 for (eT = 0; eT < nebase; eT++) {
1300 fm[e][k] = tPhase->
nAtoms(k, eT);
1303 if (eFound !=
npos) {
1304 fm[eFound][k] = - tPhase->
charge(k);
1309 for (k = 0; k < ns; k++) {
1310 fm[ChargeNeutralityElement][k] = tPhase->
charge(k);
1321 if (tPhase->
charge(0) != 0.0) {
1330 int vcs_VolPhase::elementType(
const size_t e)
const
1332 return m_elementType[e];
1335 void vcs_VolPhase::setElementType(
const size_t e,
const int eType)
1337 m_elementType[e] = eType;
1340 double const*
const* vcs_VolPhase::getFormulaMatrix()
const
1342 return m_formulaMatrix.constBaseDataAddr();
1345 int vcs_VolPhase::speciesUnknownType(
const size_t k)
const
1347 return m_speciesUnknownType[k];
1350 int vcs_VolPhase::elementActive(
const size_t e)
const
1352 return m_elementActive[e];
1355 size_t vcs_VolPhase::nSpecies()
const
1357 return m_numSpecies;
#define VCS_ELEM_TYPE_ELECTRONCHARGE
This refers to conservation of electrons.
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
#define VCS_PHASE_EXIST_NO
Phase doesn't currently exist in the mixture.
double vcsUtil_gasConstant(int mu_units)
Returns the value of the gas constant in the units specified by parameter.
size_t nElements() const
Number of elements.
static bool hasChargedSpecies(const Cantera::ThermoPhase *const tPhase)
This function decides whether a phase has charged species or not.
#define VCS_PHASE_EXIST_ALWAYS
Always exists because it contains inerts which can't exist in any other phase.
#define VCS_PHASE_EXIST_ZEROEDPHASE
Phase currently is zeroed due to a programmatic issue.
const size_t npos
index returned by functions to indicate "no position"
#define VCS_DATA_PTR(vvv)
Points to the data in a std::vector<> object.
static bool chargeNeutralityElement(const Cantera::ThermoPhase *const tPhase)
Properties of a single species.
#define VCS_PHASE_EXIST_YES
Phase is a normal phase that currently exists.
Base class for a phase with thermodynamic properties.
const int cSurf
A surface phase. Used by class SurfPhase.
Header file for the internal object that holds the vcs equilibrium problem (see Class VCS_SOLVE and E...
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.
Internal declarations for the VCSnonideal package.
virtual double G0_R_calc(size_t kspec, double TKelvin)
This function calculates the standard state Gibbs free energy for species, kspec, at the temperature ...
bool chargeNeutralityNecessary() const
Returns the chargeNeutralityNecessity boolean.
const int cMetal
A metal phase.
#define VCS_ELEM_TYPE_CHARGENEUTRALITY
This refers to a charge neutrality of a single phase.
#define AssertThrow(expr, procedure)
Assertion must be true or an error is thrown.
std::string id() const
Return the string id for the phase.
#define VCS_STATECALC_NEW
State Calculation based on the new or tentative mole numbers.
const int cEdge
An edge between two 2D surfaces.
virtual double VolStar_calc(size_t kglob, double TKelvin, double Pres)
This function calculates the standard state molar volume for species, kspec, at the temperature TKelv...
size_t nSpecies() const
Returns the number of species in the phase.
virtual double GStar_R_calc(size_t kspec, double TKelvin, double pres)
This function calculates the standard state Gibbs free energy for species, kspec, at the temperature ...
doublereal temperature() const
Temperature (K).
bool vcs_doubleEqual(double d1, double d2)
Simple routine to check whether two doubles are equal up to roundoff error.
#define VCS_STATECALC_OLD
State Calculation based on the old or base mole numbers.
#define plogendl()
define this Cantera function to replace cout << endl;
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
std::string elementName(size_t m) const
Name of the element with index m.
std::string string16_EOSType(int EOSType)
Return a string representing the equation of state.
#define plogf
define this Cantera function to replace printf
int elementType(size_t m) const
Return the element constraint type Possible types include:
#define VCS_SPECIES_TYPE_INTERFACIALVOLTAGE
Unknown refers to the voltage level of a phase.
#define VCS_STATECALC_TMP
State Calculation based on a temporary set of mole numbers.
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).
const int cIdealGas
Equation of state types:
const int cIdealSolidSolnPhase
Constant partial molar volume solution IdealSolidSolnPhase.h.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...