21 vcs_VolPhase::vcs_VolPhase(VCS_SOLVE* owningSolverObject) :
22 m_owningSolverObject(0),
24 m_singleSpecies(true),
26 m_eqnState(VCS_EOS_CONSTANT),
27 ChargeNeutralityElement(
npos),
28 p_activityConvention(0),
29 m_numElemConstraints(0),
32 m_totalMolesInert(0.0),
45 m_UpToDate_VolStar(false),
46 m_UpToDate_VolPM(false),
47 m_UpToDate_GStar(false),
52 m_owningSolverObject = owningSolverObject;
55 vcs_VolPhase::~vcs_VolPhase()
57 for (
size_t k = 0; k < m_numSpecies; k++) {
58 delete ListSpeciesPtr[k];
62 vcs_VolPhase::vcs_VolPhase(
const vcs_VolPhase& b) :
63 m_owningSolverObject(b.m_owningSolverObject),
65 m_singleSpecies(b.m_singleSpecies),
66 m_gasPhase(b.m_gasPhase),
67 m_eqnState(b.m_eqnState),
68 ChargeNeutralityElement(b.ChargeNeutralityElement),
69 p_activityConvention(b.p_activityConvention),
70 m_numElemConstraints(b.m_numElemConstraints),
71 m_numSpecies(b.m_numSpecies),
72 m_totalMolesInert(b.m_totalMolesInert),
73 m_isIdealSoln(b.m_isIdealSoln),
74 m_existence(b.m_existence),
75 m_MFStartIndex(b.m_MFStartIndex),
77 v_totalMoles(b.v_totalMoles),
78 creationMoleNumbers_(0),
79 creationGlobalRxnNumbers_(0),
81 m_totalVol(b.m_totalVol),
86 m_UpToDate_VolStar(false),
87 m_UpToDate_VolPM(false),
88 m_UpToDate_GStar(false),
98 vcs_VolPhase& vcs_VolPhase::operator=(
const vcs_VolPhase& b)
101 size_t old_num = m_numSpecies;
109 m_singleSpecies = b.m_singleSpecies;
110 m_gasPhase = b.m_gasPhase;
111 m_eqnState = b.m_eqnState;
112 ChargeNeutralityElement = b.ChargeNeutralityElement;
113 p_activityConvention= b.p_activityConvention;
114 m_numSpecies = b.m_numSpecies;
115 m_numElemConstraints = b.m_numElemConstraints;
116 m_elementNames.resize(b.m_numElemConstraints);
117 for (
size_t e = 0; e < b.m_numElemConstraints; e++) {
118 m_elementNames[e] = b.m_elementNames[e];
120 m_elementActive = b.m_elementActive;
121 m_elementType = b.m_elementType;
122 m_formulaMatrix = b.m_formulaMatrix;
123 m_speciesUnknownType = b.m_speciesUnknownType;
124 m_elemGlobalIndex = b.m_elemGlobalIndex;
125 PhaseName = b.PhaseName;
126 m_totalMolesInert = b.m_totalMolesInert;
127 m_isIdealSoln = b.m_isIdealSoln;
128 m_existence = b.m_existence;
129 m_MFStartIndex = b.m_MFStartIndex;
132 IndSpecies = b.IndSpecies;
134 for (
size_t k = 0; k < old_num; k++) {
135 if (ListSpeciesPtr[k]) {
136 delete ListSpeciesPtr[k];
137 ListSpeciesPtr[k] = 0;
140 ListSpeciesPtr.resize(m_numSpecies, 0);
141 for (
size_t k = 0; k < m_numSpecies; k++) {
143 new vcs_SpeciesProperties(*(b.ListSpeciesPtr[k]));
153 v_totalMoles = b.v_totalMoles;
155 creationMoleNumbers_ = b.creationMoleNumbers_;
156 creationGlobalRxnNumbers_ = b.creationGlobalRxnNumbers_;
157 m_phiVarIndex = b.m_phiVarIndex;
158 m_totalVol = b.m_totalVol;
159 SS0ChemicalPotential = b.SS0ChemicalPotential;
160 StarChemicalPotential = b.StarChemicalPotential;
161 StarMolarVol = b.StarMolarVol;
162 PartialMolarVol = b.PartialMolarVol;
163 ActCoeff = b.ActCoeff;
164 np_dLnActCoeffdMolNumber = b.np_dLnActCoeffdMolNumber;
165 m_vcsStateStatus = b.m_vcsStateStatus;
168 m_UpToDate_AC =
false;
169 m_UpToDate_VolStar =
false;
170 m_UpToDate_VolPM =
false;
171 m_UpToDate_GStar =
false;
172 m_UpToDate_G0 =
false;
176 setState_TP(Temp_, Pres_);
177 _updateMoleFractionDependencies();
182 void vcs_VolPhase::resize(
const size_t phaseNum,
const size_t nspecies,
183 const size_t numElem,
const char*
const phaseName,
184 const double molesInert)
186 AssertThrowMsg(nspecies > 0,
"vcs_VolPhase::resize",
"nspecies Error");
187 setTotalMolesInert(molesInert);
189 m_phiVarIndex =
npos;
191 if (phaseNum == VP_ID_) {
192 if (strcmp(PhaseName.c_str(), phaseName)) {
194 "Strings are different: " + PhaseName +
" " +
195 phaseName +
" :unknown situation");
200 PhaseName = fmt::format(
"Phase_{}", VP_ID_);
202 PhaseName = phaseName;
206 m_singleSpecies =
false;
208 m_singleSpecies =
true;
211 if (m_numSpecies == nspecies && numElem == m_numElemConstraints) {
215 m_numSpecies = nspecies;
217 m_singleSpecies =
false;
220 IndSpecies.resize(nspecies,
npos);
222 if (ListSpeciesPtr.size() >= m_numSpecies) {
223 for (
size_t i = 0; i < m_numSpecies; i++) {
224 if (ListSpeciesPtr[i]) {
225 delete ListSpeciesPtr[i];
226 ListSpeciesPtr[i] = 0;
230 ListSpeciesPtr.resize(nspecies, 0);
231 for (
size_t i = 0; i < nspecies; i++) {
235 Xmol_.resize(nspecies, 0.0);
236 creationMoleNumbers_.resize(nspecies, 0.0);
237 creationGlobalRxnNumbers_.resize(nspecies,
npos);
238 for (
size_t i = 0; i < nspecies; i++) {
239 Xmol_[i] = 1.0/nspecies;
240 creationMoleNumbers_[i] = 1.0/nspecies;
241 if (IndSpecies[i] >= m_numElemConstraints) {
242 creationGlobalRxnNumbers_[i] = IndSpecies[i] - m_numElemConstraints;
244 creationGlobalRxnNumbers_[i] =
npos;
248 SS0ChemicalPotential.resize(nspecies, -1.0);
249 StarChemicalPotential.resize(nspecies, -1.0);
250 StarMolarVol.resize(nspecies, -1.0);
251 PartialMolarVol.resize(nspecies, -1.0);
252 ActCoeff.resize(nspecies, 1.0);
253 np_dLnActCoeffdMolNumber.resize(nspecies, nspecies, 0.0);
258 m_UpToDate_AC =
false;
259 m_UpToDate_VolStar =
false;
260 m_UpToDate_VolPM =
false;
261 m_UpToDate_GStar =
false;
262 m_UpToDate_G0 =
false;
267 void vcs_VolPhase::elemResize(
const size_t numElemConstraints)
269 m_elementNames.resize(numElemConstraints);
270 m_elementActive.resize(numElemConstraints+1, 1);
272 m_formulaMatrix.resize(m_numSpecies, numElemConstraints, 0.0);
273 m_elementNames.resize(numElemConstraints,
"");
274 m_elemGlobalIndex.resize(numElemConstraints,
npos);
275 m_numElemConstraints = numElemConstraints;
278 void vcs_VolPhase::_updateActCoeff()
const 281 m_UpToDate_AC =
true;
284 TP_ptr->getActivityCoefficients(&ActCoeff[0]);
285 m_UpToDate_AC =
true;
288 double vcs_VolPhase::AC_calc_one(
size_t kspec)
const 291 "Unused. To be removed after Cantera 2.3.");
292 if (! m_UpToDate_AC) {
295 return ActCoeff[kspec];
298 void vcs_VolPhase::_updateG0()
const 300 TP_ptr->getGibbs_ref(&SS0ChemicalPotential[0]);
301 m_UpToDate_G0 =
true;
304 double vcs_VolPhase::G0_calc_one(
size_t kspec)
const 306 if (!m_UpToDate_G0) {
309 return SS0ChemicalPotential[kspec];
312 void vcs_VolPhase::_updateGStar()
const 314 TP_ptr->getStandardChemPotentials(&StarChemicalPotential[0]);
315 m_UpToDate_GStar =
true;
318 double vcs_VolPhase::GStar_calc_one(
size_t kspec)
const 320 if (!m_UpToDate_GStar) {
323 return StarChemicalPotential[kspec];
326 void vcs_VolPhase::setMoleFractions(
const double*
const xmol)
329 for (
size_t k = 0; k < m_numSpecies; k++) {
333 if (std::fabs(sum) > 1.0E-13) {
334 for (
size_t k = 0; k < m_numSpecies; k++) {
338 _updateMoleFractionDependencies();
343 void vcs_VolPhase::_updateMoleFractionDependencies()
346 TP_ptr->setState_PX(Pres_, &Xmol_[m_MFStartIndex]);
348 if (!m_isIdealSoln) {
349 m_UpToDate_AC =
false;
350 m_UpToDate_VolPM =
false;
359 double vcs_VolPhase::moleFraction(
size_t k)
const 364 void vcs_VolPhase::setMoleFractionsState(
const double totalMoles,
365 const double*
const moleFractions,
366 const int vcsStateStatus)
368 if (totalMoles != 0.0) {
372 throw CanteraError(
"vcs_VolPhase::setMolesFractionsState",
373 "inappropriate usage");
378 throw CanteraError(
"vcs_VolPhase::setMolesFractionsState",
379 "inappropriate usage");
384 m_vcsStateStatus = vcsStateStatus;
387 double fractotal = 1.0;
388 v_totalMoles = totalMoles;
389 if (m_totalMolesInert > 0.0) {
390 if (m_totalMolesInert > v_totalMoles) {
391 throw CanteraError(
"vcs_VolPhase::setMolesFractionsState",
392 "inerts greater than total: {} {}",
393 v_totalMoles, m_totalMolesInert);
395 fractotal = 1.0 - m_totalMolesInert/v_totalMoles;
398 for (
size_t k = 0; k < m_numSpecies; k++) {
399 Xmol_[k] = moleFractions[k];
400 sum += moleFractions[k];
403 throw CanteraError(
"vcs_VolPhase::setMolesFractionsState",
404 "inappropriate usage");
406 if (sum != fractotal) {
407 for (
size_t k = 0; k < m_numSpecies; k++) {
408 Xmol_[k] *= (fractotal /sum);
411 _updateMoleFractionDependencies();
414 void vcs_VolPhase::setMolesFromVCS(
const int stateCalc,
415 const double* molesSpeciesVCS)
417 v_totalMoles = m_totalMolesInert;
419 if (molesSpeciesVCS == 0) {
420 AssertThrowMsg(m_owningSolverObject,
"vcs_VolPhase::setMolesFromVCS",
421 "shouldn't be here");
423 molesSpeciesVCS = &m_owningSolverObject->m_molNumSpecies_old[0];
425 molesSpeciesVCS = &m_owningSolverObject->m_molNumSpecies_new[0];
427 throw CanteraError(
"vcs_VolPhase::setMolesFromVCS",
"shouldn't be here");
429 }
else if (m_owningSolverObject) {
431 if (molesSpeciesVCS != &m_owningSolverObject->m_molNumSpecies_old[0]) {
432 throw CanteraError(
"vcs_VolPhase::setMolesFromVCS",
"shouldn't be here");
435 if (molesSpeciesVCS != &m_owningSolverObject->m_molNumSpecies_new[0]) {
436 throw CanteraError(
"vcs_VolPhase::setMolesFromVCS",
"shouldn't be here");
441 for (
size_t k = 0; k < m_numSpecies; k++) {
443 size_t kglob = IndSpecies[k];
444 v_totalMoles += std::max(0.0, molesSpeciesVCS[kglob]);
447 if (v_totalMoles > 0.0) {
448 for (
size_t k = 0; k < m_numSpecies; k++) {
450 size_t kglob = IndSpecies[k];
451 double tmp = std::max(0.0, molesSpeciesVCS[kglob]);
452 Xmol_[k] = tmp / v_totalMoles;
465 if (m_phiVarIndex !=
npos) {
466 size_t kglob = IndSpecies[m_phiVarIndex];
467 if (m_numSpecies == 1) {
468 Xmol_[m_phiVarIndex] = 1.0;
470 Xmol_[m_phiVarIndex] = 0.0;
472 double phi = molesSpeciesVCS[kglob];
473 setElectricPotential(phi);
474 if (m_numSpecies == 1) {
478 _updateMoleFractionDependencies();
479 if (m_totalMolesInert > 0.0) {
487 creationMoleNumbers_ = Xmol_;
492 m_vcsStateStatus = stateCalc;
495 void vcs_VolPhase::setMolesFromVCSCheck(
const int vcsStateStatus,
496 const double* molesSpeciesVCS,
497 const double*
const TPhMoles)
499 setMolesFromVCS(vcsStateStatus, molesSpeciesVCS);
502 double Tcheck = TPhMoles[VP_ID_];
503 if (Tcheck != v_totalMoles) {
505 Tcheck = v_totalMoles;
507 throw CanteraError(
"vcs_VolPhase::setMolesFromVCSCheck",
508 "We have a consistency problem: {} {}", Tcheck, v_totalMoles);
513 void vcs_VolPhase::updateFromVCS_MoleNumbers(
const int vcsStateStatus)
515 if ((!m_UpToDate || vcsStateStatus != m_vcsStateStatus) && m_owningSolverObject &&
517 setMolesFromVCS(vcsStateStatus);
521 void vcs_VolPhase::sendToVCS_ActCoeff(
const int vcsStateStatus,
524 updateFromVCS_MoleNumbers(vcsStateStatus);
525 if (!m_UpToDate_AC) {
528 for (
size_t k = 0; k < m_numSpecies; k++) {
529 size_t kglob = IndSpecies[k];
530 AC[kglob] = ActCoeff[k];
534 double vcs_VolPhase::sendToVCS_VolPM(
double*
const VolPM)
const 536 if (!m_UpToDate_VolPM) {
539 for (
size_t k = 0; k < m_numSpecies; k++) {
540 size_t kglob = IndSpecies[k];
541 VolPM[kglob] = PartialMolarVol[k];
546 void vcs_VolPhase::sendToVCS_GStar(
double*
const gstar)
const 548 if (!m_UpToDate_GStar) {
551 for (
size_t k = 0; k < m_numSpecies; k++) {
552 size_t kglob = IndSpecies[k];
553 gstar[kglob] = StarChemicalPotential[k];
557 void vcs_VolPhase::setElectricPotential(
const double phi)
560 TP_ptr->setElectricPotential(m_phi);
562 m_UpToDate_AC =
false;
563 m_UpToDate_VolStar =
false;
564 m_UpToDate_VolPM =
false;
565 m_UpToDate_GStar =
false;
568 double vcs_VolPhase::electricPotential()
const 573 void vcs_VolPhase::setState_TP(
const double temp,
const double pres)
575 if (Temp_ == temp && Pres_ == pres) {
578 TP_ptr->setElectricPotential(m_phi);
579 TP_ptr->setState_TP(temp, pres);
582 m_UpToDate_AC =
false;
583 m_UpToDate_VolStar =
false;
584 m_UpToDate_VolPM =
false;
585 m_UpToDate_GStar =
false;
586 m_UpToDate_G0 =
false;
589 void vcs_VolPhase::setState_T(
const double temp)
591 setState_TP(temp, Pres_);
594 void vcs_VolPhase::_updateVolStar()
const 596 TP_ptr->getStandardVolumes(&StarMolarVol[0]);
597 m_UpToDate_VolStar =
true;
600 double vcs_VolPhase::VolStar_calc_one(
size_t kspec)
const 602 if (!m_UpToDate_VolStar) {
605 return StarMolarVol[kspec];
608 double vcs_VolPhase::_updateVolPM()
const 610 TP_ptr->getPartialMolarVolumes(&PartialMolarVol[0]);
612 for (
size_t k = 0; k < m_numSpecies; k++) {
613 m_totalVol += PartialMolarVol[k] * Xmol_[k];
615 m_totalVol *= v_totalMoles;
617 if (m_totalMolesInert > 0.0) {
619 double volI = m_totalMolesInert * GasConstant * Temp_ / Pres_;
622 throw CanteraError(
"vcs_VolPhase::_updateVolPM",
"unknown situation");
625 m_UpToDate_VolPM =
true;
629 void vcs_VolPhase::_updateLnActCoeffJac()
631 double phaseTotalMoles = v_totalMoles;
632 if (phaseTotalMoles < 1.0E-14) {
633 phaseTotalMoles = 1.0;
637 if (!m_UpToDate_AC) {
643 TP_ptr->getdlnActCoeffdlnN(m_numSpecies, &np_dLnActCoeffdMolNumber(0,0));
644 for (
size_t j = 0; j < m_numSpecies; j++) {
645 double moles_j_base = phaseTotalMoles * Xmol_[j];
646 double*
const np_lnActCoeffCol = np_dLnActCoeffdMolNumber.ptrColumn(j);
647 if (moles_j_base < 1.0E-200) {
648 moles_j_base = 1.0E-7 * moles_j_base + 1.0E-13 * phaseTotalMoles + 1.0E-150;
650 for (
size_t k = 0; k < m_numSpecies; k++) {
651 np_lnActCoeffCol[k] = np_lnActCoeffCol[k] * phaseTotalMoles / moles_j_base;
655 double deltaMoles_j = 0.0;
659 double TMoles_base = phaseTotalMoles;
662 for (
size_t j = 0; j < m_numSpecies; j++) {
665 double moles_j_base = phaseTotalMoles * Xmol_Base[j];
666 deltaMoles_j = 1.0E-7 * moles_j_base + 1.0E-13 * phaseTotalMoles + 1.0E-150;
670 phaseTotalMoles = TMoles_base + deltaMoles_j;
671 for (
size_t k = 0; k < m_numSpecies; k++) {
672 Xmol_[k] = Xmol_Base[k] * TMoles_base / phaseTotalMoles;
674 Xmol_[j] = (moles_j_base + deltaMoles_j) / phaseTotalMoles;
678 _updateMoleFractionDependencies();
682 v_totalMoles = TMoles_base;
689 setMoleFractions(&Xmol_Base[0]);
690 _updateMoleFractionDependencies();
694 void vcs_VolPhase::sendToVCS_LnActCoeffJac(
Array2D& np_LnACJac_VCS)
698 _updateLnActCoeffJac();
701 for (
size_t j = 0; j < m_numSpecies; j++) {
702 size_t jglob = IndSpecies[j];
703 for (
size_t k = 0; k < m_numSpecies; k++) {
704 size_t kglob = IndSpecies[k];
705 np_LnACJac_VCS(kglob,jglob) = np_dLnActCoeffdMolNumber(k,j);
714 Pres_ = TP_ptr->pressure();
715 setState_TP(Temp_, Pres_);
716 m_phi = TP_ptr->electricPotential();
717 size_t nsp = TP_ptr->nSpecies();
718 size_t nelem = TP_ptr->nElements();
719 if (nsp != m_numSpecies) {
720 if (m_numSpecies != 0) {
721 plogf(
"Warning Nsp != NVolSpeces: %d %d \n", nsp, m_numSpecies);
723 resize(VP_ID_, nsp, nelem, PhaseName.c_str());
725 TP_ptr->getMoleFractions(&Xmol_[0]);
726 creationMoleNumbers_ = Xmol_;
727 _updateMoleFractionDependencies();
731 m_isIdealSoln =
true;
733 std::string eos = TP_ptr->type();
734 if (eos ==
"IdealGas" || eos ==
"ConstDensity" || eos ==
"Surf" 735 || eos ==
"Metal" || eos ==
"StoichSubstance" 736 || eos ==
"Semiconductor" || eos ==
"LatticeSolid" 737 || eos ==
"Lattice" || eos ==
"Edge" || eos ==
"IdealSolidSoln") {
738 m_isIdealSoln =
true;
740 m_isIdealSoln =
false;
750 double vcs_VolPhase::totalMoles()
const 755 double vcs_VolPhase::molefraction(
size_t k)
const 760 void vcs_VolPhase::setCreationMoleNumbers(
const double*
const n_k,
761 const std::vector<size_t> &creationGlobalRxnNumbers)
763 creationMoleNumbers_.assign(n_k, n_k+m_numSpecies);
764 for (
size_t k = 0; k < m_numSpecies; k++) {
765 creationGlobalRxnNumbers_[k] = creationGlobalRxnNumbers[k];
769 const vector_fp& vcs_VolPhase::creationMoleNumbers(std::vector<size_t> &creationGlobalRxnNumbers)
const 771 creationGlobalRxnNumbers = creationGlobalRxnNumbers_;
772 return creationMoleNumbers_;
775 void vcs_VolPhase::setTotalMoles(
const double totalMols)
777 v_totalMoles = totalMols;
778 if (m_totalMolesInert > 0.0) {
781 "vcs_VolPhase::setTotalMoles",
782 "totalMoles less than inert moles: {} {}",
783 totalMols, m_totalMolesInert);
785 if (m_singleSpecies && (m_phiVarIndex == 0)) {
788 if (totalMols > 0.0) {
797 void vcs_VolPhase::setMolesOutOfDate(
int stateCalc)
800 if (stateCalc != -1) {
801 m_vcsStateStatus = stateCalc;
805 void vcs_VolPhase::setMolesCurrent(
int stateCalc)
808 m_vcsStateStatus = stateCalc;
813 warn_deprecated(
"string16_EOSType",
"Use vcs_VolPhase::eos_name instead." 814 " To be removed after Cantera 2.3.");
818 case VCS_EOS_CONSTANT:
819 sprintf(st,
"Constant ");
821 case VCS_EOS_IDEAL_GAS:
822 sprintf(st,
"Ideal Gas ");
824 case VCS_EOS_STOICH_SUB:
825 sprintf(st,
"Stoich Sub ");
827 case VCS_EOS_IDEAL_SOLN:
828 sprintf(st,
"Ideal Soln ");
830 case VCS_EOS_DEBEYE_HUCKEL:
831 sprintf(st,
"Debeye Huckel ");
833 case VCS_EOS_REDLICH_KWONG:
834 sprintf(st,
"Redlick_Kwong ");
836 case VCS_EOS_REGULAR_SOLN:
837 sprintf(st,
"Regular Soln ");
840 sprintf(st,
"UnkType: %-7d", EOSType);
847 bool vcs_VolPhase::isIdealSoln()
const 849 return m_isIdealSoln;
852 size_t vcs_VolPhase::phiVarIndex()
const 854 return m_phiVarIndex;
857 void vcs_VolPhase::setPhiVarIndex(
size_t phiVarIndex)
859 m_phiVarIndex = phiVarIndex;
861 if (m_singleSpecies && m_phiVarIndex == 0) {
868 return ListSpeciesPtr[kindex];
871 int vcs_VolPhase::exists()
const 876 void vcs_VolPhase::setExistence(
const int existence)
879 if (v_totalMoles != 0.0) {
881 "setting false existence for phase with moles");
883 }
else if (m_totalMolesInert == 0.0) {
884 if (v_totalMoles == 0.0 && (!m_singleSpecies || m_phiVarIndex != 0)) {
886 "setting true existence for phase with no moles");
891 "Trying to set existence of an electron phase to false");
893 m_existence = existence;
896 size_t vcs_VolPhase::spGlobalIndexVCS(
const size_t spIndex)
const 898 return IndSpecies[spIndex];
901 void vcs_VolPhase::setSpGlobalIndexVCS(
const size_t spIndex,
902 const size_t spGlobalIndex)
904 IndSpecies[spIndex] = spGlobalIndex;
905 if (spGlobalIndex >= m_numElemConstraints) {
906 creationGlobalRxnNumbers_[spIndex] = spGlobalIndex - m_numElemConstraints;
910 void vcs_VolPhase::setTotalMolesInert(
const double tMolesInert)
912 if (m_totalMolesInert != tMolesInert) {
914 m_UpToDate_AC =
false;
915 m_UpToDate_VolStar =
false;
916 m_UpToDate_VolPM =
false;
917 m_UpToDate_GStar =
false;
918 m_UpToDate_G0 =
false;
919 v_totalMoles += (tMolesInert - m_totalMolesInert);
920 m_totalMolesInert = tMolesInert;
922 if (m_totalMolesInert > 0.0) {
924 }
else if (m_singleSpecies && (m_phiVarIndex == 0)) {
927 if (v_totalMoles > 0.0) {
935 double vcs_VolPhase::totalMolesInert()
const 937 return m_totalMolesInert;
940 size_t vcs_VolPhase::elemGlobalIndex(
const size_t e)
const 942 AssertThrow(e < m_numElemConstraints,
" vcs_VolPhase::elemGlobalIndex");
943 return m_elemGlobalIndex[e];
946 void vcs_VolPhase::setElemGlobalIndex(
const size_t eLocal,
const size_t eGlobal)
949 "vcs_VolPhase::setElemGlobalIndex");
950 m_elemGlobalIndex[eLocal] = eGlobal;
953 size_t vcs_VolPhase::nElemConstraints()
const 955 return m_numElemConstraints;
958 std::string vcs_VolPhase::elementName(
const size_t e)
const 960 return m_elementNames[e];
966 for (
size_t k = 0; k < tPhase->
nSpecies(); k++) {
967 if (tPhase->
charge(k) != 0.0) {
987 size_t vcs_VolPhase::transferElementsFM(
const ThermoPhase*
const tPhase)
997 ChargeNeutralityElement = ne;
1004 if (ChargeNeutralityElement !=
npos) {
1008 size_t eFound =
npos;
1017 for (
size_t eT = 0; eT < nebase; eT++) {
1020 m_elementActive[eT] = 0;
1025 for (
size_t eT = 0; eT < nebase; eT++) {
1032 if (eFound ==
npos) {
1035 m_elementActive[ne] = 0;
1036 std::string ename =
"E";
1037 m_elementNames[ne] = ename;
1043 m_formulaMatrix.resize(ns, ne, 0.0);
1048 for (
size_t eT = 0; eT < nebase; eT++) {
1055 std::string pname = tPhase->
id();
1057 pname = fmt::format(
"phase{}", VP_ID_);
1059 e = ChargeNeutralityElement;
1060 m_elementNames[e] =
"cn_" + pname;
1063 for (
size_t k = 0; k < ns; k++) {
1065 for (
size_t eT = 0; eT < nebase; eT++) {
1066 m_formulaMatrix(k,e) = tPhase->
nAtoms(k, eT);
1069 if (eFound !=
npos) {
1070 m_formulaMatrix(k,eFound) = - tPhase->
charge(k);
1075 for (
size_t k = 0; k < ns; k++) {
1076 m_formulaMatrix(k,ChargeNeutralityElement) = tPhase->
charge(k);
1083 if (ns == 1 && tPhase->
charge(0) != 0.0) {
1091 int vcs_VolPhase::elementType(
const size_t e)
const 1093 return m_elementType[e];
1096 void vcs_VolPhase::setElementType(
const size_t e,
const int eType)
1099 "Unused. To be removed after Cantera 2.3.");
1100 m_elementType[e] = eType;
1103 const Array2D& vcs_VolPhase::getFormulaMatrix()
const 1105 return m_formulaMatrix;
1108 int vcs_VolPhase::speciesUnknownType(
const size_t k)
const 1110 return m_speciesUnknownType[k];
1113 int vcs_VolPhase::elementActive(
const size_t e)
const 1115 return m_elementActive[e];
1118 size_t vcs_VolPhase::nSpecies()
const 1120 return m_numSpecies;
1123 std::string vcs_VolPhase::eos_name()
const 1125 switch (m_eqnState) {
1126 case VCS_EOS_CONSTANT:
1128 case VCS_EOS_IDEAL_GAS:
1130 case VCS_EOS_STOICH_SUB:
1131 return "Stoich Sub";
1132 case VCS_EOS_IDEAL_SOLN:
1133 return "Ideal Soln";
1134 case VCS_EOS_DEBEYE_HUCKEL:
1135 return "Debeye Huckel";
1136 case VCS_EOS_REDLICH_KWONG:
1137 return "Redlich_Kwong";
1138 case VCS_EOS_REGULAR_SOLN:
1139 return "Regular Soln";
1141 return fmt::format(
"UnkType: {:7d}", m_eqnState);
#define VCS_ELEM_TYPE_ELECTRONCHARGE
This refers to conservation of electrons.
#define VCS_PHASE_EXIST_NO
Phase doesn't currently exist in the mixture.
bool vcs_doubleEqual(double d1, double d2)
Simple routine to check whether two doubles are equal up to roundoff error.
size_t nElements() const
Number of elements.
doublereal temperature() const
Temperature (K).
#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"
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
size_t nSpecies() const
Returns the number of species in the phase.
static bool hasChargedSpecies(const ThermoPhase *const tPhase)
This function decides whether a phase has charged species or not.
static bool chargeNeutralityElement(const ThermoPhase *const tPhase)
This utility routine decides whether a Cantera ThermoPhase needs a constraint equation representing t...
#define VCS_PHASE_EXIST_YES
Phase is a normal phase that currently exists.
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Base class for a phase with thermodynamic properties.
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.
Properties of a single species.
#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.
#define VCS_STATECALC_NEW
State Calculation based on the new or tentative mole numbers.
Base class for exceptions thrown by Cantera classes.
std::string string16_EOSType(int EOSType)
Return a string representing the equation of state.
#define AssertThrowMsg(expr, procedure,...)
Assertion must be true or an error is thrown.
#define VCS_STATECALC_OLD
State Calculation based on the old or base mole numbers.
std::string id() const
Return the string id for the phase.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
int elementType(size_t m) const
Return the element constraint type Possible types include:
Contains declarations for string manipulation functions within Cantera.
#define plogf
define this Cantera function to replace printf
bool chargeNeutralityNecessary() const
Returns the chargeNeutralityNecessity boolean.
#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.
Namespace for the Cantera kernel.
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
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).
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
std::string elementName(size_t m) const
Name of the element with index m.