23 vcs_VolPhase::vcs_VolPhase(VCS_SOLVE* owningSolverObject) :
24 m_owningSolverObject(0),
26 m_singleSpecies(true),
28 m_eqnState(VCS_EOS_CONSTANT),
29 ChargeNeutralityElement(
npos),
30 p_VCS_UnitsFormat(VCS_UNITS_MKS),
31 p_activityConvention(0),
32 m_numElemConstraints(0),
35 m_totalMolesInert(0.0),
40 m_useCanteraCalls(false),
49 m_UpToDate_VolStar(false),
50 m_UpToDate_VolPM(false),
51 m_UpToDate_GStar(false),
56 m_owningSolverObject = owningSolverObject;
59 vcs_VolPhase::~vcs_VolPhase()
61 for (
size_t k = 0; k < m_numSpecies; k++) {
62 vcs_SpeciesProperties* sp = ListSpeciesPtr[k];
68 vcs_VolPhase::vcs_VolPhase(
const vcs_VolPhase& b) :
69 m_owningSolverObject(b.m_owningSolverObject),
71 m_singleSpecies(b.m_singleSpecies),
72 m_gasPhase(b.m_gasPhase),
73 m_eqnState(b.m_eqnState),
74 ChargeNeutralityElement(b.ChargeNeutralityElement),
75 p_VCS_UnitsFormat(b.p_VCS_UnitsFormat),
76 p_activityConvention(b.p_activityConvention),
77 m_numElemConstraints(b.m_numElemConstraints),
78 m_numSpecies(b.m_numSpecies),
79 m_totalMolesInert(b.m_totalMolesInert),
80 m_isIdealSoln(b.m_isIdealSoln),
81 m_existence(b.m_existence),
82 m_MFStartIndex(b.m_MFStartIndex),
83 m_useCanteraCalls(b.m_useCanteraCalls),
85 v_totalMoles(b.v_totalMoles),
86 creationMoleNumbers_(0),
87 creationGlobalRxnNumbers_(0),
89 m_totalVol(b.m_totalVol),
94 m_UpToDate_VolStar(false),
95 m_UpToDate_VolPM(false),
96 m_UpToDate_GStar(false),
106 vcs_VolPhase& vcs_VolPhase::operator=(
const vcs_VolPhase& b)
109 size_t old_num = m_numSpecies;
117 m_singleSpecies = b.m_singleSpecies;
118 m_gasPhase = b.m_gasPhase;
119 m_eqnState = b.m_eqnState;
120 ChargeNeutralityElement = b.ChargeNeutralityElement;
121 p_VCS_UnitsFormat = b.p_VCS_UnitsFormat;
122 p_activityConvention= b.p_activityConvention;
123 m_numSpecies = b.m_numSpecies;
124 m_numElemConstraints = b.m_numElemConstraints;
125 m_elementNames.resize(b.m_numElemConstraints);
126 for (
size_t e = 0; e < b.m_numElemConstraints; e++) {
127 m_elementNames[e] = b.m_elementNames[e];
129 m_elementActive = b.m_elementActive;
130 m_elementType = b.m_elementType;
131 m_formulaMatrix = b.m_formulaMatrix;
132 m_speciesUnknownType = b.m_speciesUnknownType;
133 m_elemGlobalIndex = b.m_elemGlobalIndex;
134 PhaseName = b.PhaseName;
135 m_totalMolesInert = b.m_totalMolesInert;
136 m_isIdealSoln = b.m_isIdealSoln;
137 m_existence = b.m_existence;
138 m_MFStartIndex = b.m_MFStartIndex;
142 IndSpecies = b.IndSpecies;
144 for (
size_t k = 0; k < old_num; k++) {
145 if (ListSpeciesPtr[k]) {
146 delete ListSpeciesPtr[k];
147 ListSpeciesPtr[k] = 0;
150 ListSpeciesPtr.resize(m_numSpecies, 0);
151 for (
size_t k = 0; k < m_numSpecies; k++) {
153 new vcs_SpeciesProperties(*(b.ListSpeciesPtr[k]));
155 m_useCanteraCalls = b.m_useCanteraCalls;
164 v_totalMoles = b.v_totalMoles;
166 creationMoleNumbers_ = b.creationMoleNumbers_;
167 creationGlobalRxnNumbers_ = b.creationGlobalRxnNumbers_;
168 m_phiVarIndex = b.m_phiVarIndex;
169 m_totalVol = b.m_totalVol;
170 SS0ChemicalPotential = b.SS0ChemicalPotential;
171 StarChemicalPotential = b.StarChemicalPotential;
172 StarMolarVol = b.StarMolarVol;
173 PartialMolarVol = b.PartialMolarVol;
174 ActCoeff = b.ActCoeff;
175 np_dLnActCoeffdMolNumber = b.np_dLnActCoeffdMolNumber;
176 m_vcsStateStatus = b.m_vcsStateStatus;
179 m_UpToDate_AC =
false;
180 m_UpToDate_VolStar =
false;
181 m_UpToDate_VolPM =
false;
182 m_UpToDate_GStar =
false;
183 m_UpToDate_G0 =
false;
187 setState_TP(Temp_, Pres_);
188 _updateMoleFractionDependencies();
193 void vcs_VolPhase::resize(
const size_t phaseNum,
const size_t nspecies,
194 const size_t numElem,
const char*
const phaseName,
195 const double molesInert)
197 AssertThrowMsg(nspecies > 0,
"vcs_VolPhase::resize",
"nspecies Error");
198 setTotalMolesInert(molesInert);
200 m_phiVarIndex =
npos;
202 if (phaseNum == VP_ID_) {
203 if (strcmp(PhaseName.c_str(), phaseName)) {
205 "Strings are different: " + PhaseName +
" " +
206 phaseName +
" :unknown situation");
211 std::stringstream sstmp;
212 sstmp <<
"Phase_" << VP_ID_;
213 PhaseName = sstmp.str();
215 PhaseName = phaseName;
219 m_singleSpecies =
false;
221 m_singleSpecies =
true;
224 if (m_numSpecies == nspecies && numElem == m_numElemConstraints) {
228 m_numSpecies = nspecies;
230 m_singleSpecies =
false;
234 IndSpecies.resize(nspecies,
npos);
236 if (ListSpeciesPtr.size() >= m_numSpecies) {
237 for (
size_t i = 0; i < m_numSpecies; i++) {
238 if (ListSpeciesPtr[i]) {
239 delete ListSpeciesPtr[i];
240 ListSpeciesPtr[i] = 0;
244 ListSpeciesPtr.resize(nspecies, 0);
245 for (
size_t i = 0; i < nspecies; i++) {
249 Xmol_.resize(nspecies, 0.0);
250 creationMoleNumbers_.resize(nspecies, 0.0);
251 creationGlobalRxnNumbers_.resize(nspecies,
npos);
252 for (
size_t i = 0; i < nspecies; i++) {
253 Xmol_[i] = 1.0/nspecies;
254 creationMoleNumbers_[i] = 1.0/nspecies;
255 if (IndSpecies[i] >= m_numElemConstraints) {
256 creationGlobalRxnNumbers_[i] = IndSpecies[i] - m_numElemConstraints;
258 creationGlobalRxnNumbers_[i] =
npos;
262 SS0ChemicalPotential.resize(nspecies, -1.0);
263 StarChemicalPotential.resize(nspecies, -1.0);
264 StarMolarVol.resize(nspecies, -1.0);
265 PartialMolarVol.resize(nspecies, -1.0);
266 ActCoeff.resize(nspecies, 1.0);
267 np_dLnActCoeffdMolNumber.resize(nspecies, nspecies, 0.0);
273 m_UpToDate_AC =
false;
274 m_UpToDate_VolStar =
false;
275 m_UpToDate_VolPM =
false;
276 m_UpToDate_GStar =
false;
277 m_UpToDate_G0 =
false;
284 void vcs_VolPhase::elemResize(
const size_t numElemConstraints)
287 m_elementNames.resize(numElemConstraints);
289 m_elementActive.resize(numElemConstraints+1, 1);
291 m_formulaMatrix.resize(m_numSpecies, numElemConstraints, 0.0);
293 m_elementNames.resize(numElemConstraints,
"");
294 m_elemGlobalIndex.resize(numElemConstraints,
npos);
296 m_numElemConstraints = numElemConstraints;
299 void vcs_VolPhase::_updateActCoeff()
const
302 m_UpToDate_AC =
true;
305 if (m_useCanteraCalls) {
306 TP_ptr->getActivityCoefficients(
VCS_DATA_PTR(ActCoeff));
308 warn_deprecated(
"m_useCanteraCalls",
"Setting this flag to 'false' is "
309 "deprecated and will not work after Cantera 2.2.");
311 m_UpToDate_AC =
true;
314 double vcs_VolPhase::AC_calc_one(
size_t kspec)
const
316 if (! m_UpToDate_AC) {
319 return ActCoeff[kspec];
322 void vcs_VolPhase::_updateG0()
const
324 if (m_useCanteraCalls) {
325 TP_ptr->getGibbs_ref(
VCS_DATA_PTR(SS0ChemicalPotential));
327 warn_deprecated(
"m_useCanteraCalls",
"Setting this flag to 'false' is "
328 "deprecated and will not work after Cantera 2.2.");
330 for (
size_t k = 0; k < m_numSpecies; k++) {
331 size_t kglob = IndSpecies[k];
334 SS0ChemicalPotential[k] =
338 m_UpToDate_G0 =
true;
341 double vcs_VolPhase::G0_calc_one(
size_t kspec)
const
343 if (!m_UpToDate_G0) {
346 return SS0ChemicalPotential[kspec];
349 void vcs_VolPhase::_updateGStar()
const
351 if (m_useCanteraCalls) {
352 TP_ptr->getStandardChemPotentials(
VCS_DATA_PTR(StarChemicalPotential));
354 warn_deprecated(
"m_useCanteraCalls",
"Setting this flag to 'false' is "
355 "deprecated and will not work after Cantera 2.2.");
357 for (
size_t k = 0; k < m_numSpecies; k++) {
358 size_t kglob = IndSpecies[k];
361 StarChemicalPotential[k] =
365 m_UpToDate_GStar =
true;
368 double vcs_VolPhase::GStar_calc_one(
size_t kspec)
const
370 if (!m_UpToDate_GStar) {
373 return StarChemicalPotential[kspec];
376 void vcs_VolPhase::setMoleFractions(
const double*
const xmol)
379 for (
size_t k = 0; k < m_numSpecies; k++) {
383 if (std::fabs(sum) > 1.0E-13) {
384 for (
size_t k = 0; k < m_numSpecies; k++) {
388 _updateMoleFractionDependencies();
393 void vcs_VolPhase::_updateMoleFractionDependencies()
395 if (m_useCanteraCalls) {
397 TP_ptr->setState_PX(Pres_, &(Xmol_[m_MFStartIndex]));
400 warn_deprecated(
"m_useCanteraCalls",
"Setting this flag to 'false' is "
401 "deprecated and will not work after Cantera 2.2.");
403 if (!m_isIdealSoln) {
404 m_UpToDate_AC =
false;
405 m_UpToDate_VolPM =
false;
409 const std::vector<double> & vcs_VolPhase::moleFractions()
const
414 double vcs_VolPhase::moleFraction(
size_t k)
const
419 void vcs_VolPhase::setMoleFractionsState(
const double totalMoles,
420 const double*
const moleFractions,
421 const int vcsStateStatus)
424 if (totalMoles != 0.0) {
428 throw CanteraError(
"vcs_VolPhase::setMolesFractionsState",
429 "inappropriate usage");
434 throw CanteraError(
"vcs_VolPhase::setMolesFractionsState",
435 "inappropriate usage");
440 m_vcsStateStatus = vcsStateStatus;
443 double fractotal = 1.0;
444 v_totalMoles = totalMoles;
445 if (m_totalMolesInert > 0.0) {
446 if (m_totalMolesInert > v_totalMoles) {
447 throw CanteraError(
"vcs_VolPhase::setMolesFractionsState",
448 "inerts greater than total: " +
fp2str(v_totalMoles) +
" " +
449 fp2str(m_totalMolesInert));
451 fractotal = 1.0 - m_totalMolesInert/v_totalMoles;
454 for (
size_t k = 0; k < m_numSpecies; k++) {
455 Xmol_[k] = moleFractions[k];
456 sum += moleFractions[k];
459 throw CanteraError(
"vcs_VolPhase::setMolesFractionsState",
460 "inappropriate usage");
462 if (sum != fractotal) {
463 for (
size_t k = 0; k < m_numSpecies; k++) {
464 Xmol_[k] *= (fractotal /sum);
467 _updateMoleFractionDependencies();
471 void vcs_VolPhase::setMolesFromVCS(
const int stateCalc,
472 const double* molesSpeciesVCS)
474 v_totalMoles = m_totalMolesInert;
476 if (molesSpeciesVCS == 0) {
477 AssertThrowMsg(m_owningSolverObject,
"vcs_VolPhase::setMolesFromVCS",
478 "shouldn't be here");
480 molesSpeciesVCS =
VCS_DATA_PTR(m_owningSolverObject->m_molNumSpecies_old);
482 molesSpeciesVCS =
VCS_DATA_PTR(m_owningSolverObject->m_molNumSpecies_new);
483 }
else if (DEBUG_MODE_ENABLED) {
484 throw CanteraError(
"vcs_VolPhase::setMolesFromVCS",
"shouldn't be here"); }
485 }
else if (DEBUG_MODE_ENABLED && m_owningSolverObject) {
487 if (molesSpeciesVCS !=
VCS_DATA_PTR(m_owningSolverObject->m_molNumSpecies_old)) {
488 throw CanteraError(
"vcs_VolPhase::setMolesFromVCS",
"shouldn't be here");
491 if (molesSpeciesVCS !=
VCS_DATA_PTR(m_owningSolverObject->m_molNumSpecies_new)) {
492 throw CanteraError(
"vcs_VolPhase::setMolesFromVCS",
"shouldn't be here");
497 for (
size_t k = 0; k < m_numSpecies; k++) {
499 size_t kglob = IndSpecies[k];
500 v_totalMoles += std::max(0.0, molesSpeciesVCS[kglob]);
503 if (v_totalMoles > 0.0) {
504 for (
size_t k = 0; k < m_numSpecies; k++) {
506 size_t kglob = IndSpecies[k];
507 double tmp = std::max(0.0, molesSpeciesVCS[kglob]);
508 Xmol_[k] = tmp / v_totalMoles;
522 if (m_phiVarIndex !=
npos) {
523 size_t kglob = IndSpecies[m_phiVarIndex];
524 if (m_numSpecies == 1) {
525 Xmol_[m_phiVarIndex] = 1.0;
527 Xmol_[m_phiVarIndex] = 0.0;
529 double phi = molesSpeciesVCS[kglob];
530 setElectricPotential(phi);
531 if (m_numSpecies == 1) {
535 _updateMoleFractionDependencies();
536 if (m_totalMolesInert > 0.0) {
546 if (v_totalMoles > 0.0) {
547 creationMoleNumbers_ = Xmol_;
555 m_vcsStateStatus = stateCalc;
558 void vcs_VolPhase::setMolesFromVCSCheck(
const int vcsStateStatus,
559 const double* molesSpeciesVCS,
560 const double*
const TPhMoles)
562 setMolesFromVCS(vcsStateStatus, molesSpeciesVCS);
566 double Tcheck = TPhMoles[VP_ID_];
567 if (Tcheck != v_totalMoles) {
569 Tcheck = v_totalMoles;
571 throw CanteraError(
"vcs_VolPhase::setMolesFromVCSCheck",
572 "We have a consistency problem: " +
fp2str(Tcheck) +
" " +
578 void vcs_VolPhase::updateFromVCS_MoleNumbers(
const int vcsStateStatus)
580 if (!m_UpToDate || (vcsStateStatus != m_vcsStateStatus)) {
582 if (m_owningSolverObject) {
583 setMolesFromVCS(vcsStateStatus);
589 void vcs_VolPhase::sendToVCS_ActCoeff(
const int vcsStateStatus,
592 updateFromVCS_MoleNumbers(vcsStateStatus);
593 if (!m_UpToDate_AC) {
596 for (
size_t k = 0; k < m_numSpecies; k++) {
597 size_t kglob = IndSpecies[k];
598 AC[kglob] = ActCoeff[k];
602 double vcs_VolPhase::sendToVCS_VolPM(
double*
const VolPM)
const
604 if (!m_UpToDate_VolPM) {
605 (void) _updateVolPM();
607 for (
size_t k = 0; k < m_numSpecies; k++) {
608 size_t kglob = IndSpecies[k];
609 VolPM[kglob] = PartialMolarVol[k];
614 void vcs_VolPhase::sendToVCS_GStar(
double*
const gstar)
const
616 if (!m_UpToDate_GStar) {
619 for (
size_t k = 0; k < m_numSpecies; k++) {
620 size_t kglob = IndSpecies[k];
621 gstar[kglob] = StarChemicalPotential[k];
625 void vcs_VolPhase::setElectricPotential(
const double phi)
628 if (m_useCanteraCalls) {
629 TP_ptr->setElectricPotential(m_phi);
631 warn_deprecated(
"m_useCanteraCalls",
"Setting this flag to 'false' is "
632 "deprecated and will not work after Cantera 2.2.");
635 m_UpToDate_AC =
false;
636 m_UpToDate_VolStar =
false;
637 m_UpToDate_VolPM =
false;
638 m_UpToDate_GStar =
false;
641 double vcs_VolPhase::electricPotential()
const
646 void vcs_VolPhase::setState_TP(
const double temp,
const double pres)
653 if (m_useCanteraCalls) {
654 TP_ptr->setElectricPotential(m_phi);
655 TP_ptr->setState_TP(temp, pres);
657 warn_deprecated(
"m_useCanteraCalls",
"Setting this flag to 'false' is "
658 "deprecated and will not work after Cantera 2.2.");
662 m_UpToDate_AC =
false;
663 m_UpToDate_VolStar =
false;
664 m_UpToDate_VolPM =
false;
665 m_UpToDate_GStar =
false;
666 m_UpToDate_G0 =
false;
669 void vcs_VolPhase::setState_T(
const double temp)
671 setState_TP(temp, Pres_);
674 void vcs_VolPhase::_updateVolStar()
const
676 if (m_useCanteraCalls) {
679 warn_deprecated(
"m_useCanteraCalls",
"Setting this flag to 'false' is "
680 "deprecated and will not work after Cantera 2.2.");
681 for (
size_t k = 0; k < m_numSpecies; k++) {
682 size_t kglob = IndSpecies[k];
685 StarMolarVol[k] = (sTherm->
VolStar_calc(kglob, Temp_, Pres_));
688 m_UpToDate_VolStar =
true;
691 double vcs_VolPhase::VolStar_calc_one(
size_t kspec)
const
693 if (!m_UpToDate_VolStar) {
696 return StarMolarVol[kspec];
699 double vcs_VolPhase::_updateVolPM()
const
701 if (m_useCanteraCalls) {
702 TP_ptr->getPartialMolarVolumes(
VCS_DATA_PTR(PartialMolarVol));
704 warn_deprecated(
"m_useCanteraCalls",
"Setting this flag to 'false' is "
705 "deprecated and will not work after Cantera 2.2.");
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_));
712 for (
size_t k = 0; k < m_numSpecies; k++) {
713 PartialMolarVol[k] = StarMolarVol[k];
718 for (
size_t k = 0; k < m_numSpecies; k++) {
719 m_totalVol += PartialMolarVol[k] * Xmol_[k];
721 m_totalVol *= v_totalMoles;
723 if (m_totalMolesInert > 0.0) {
725 double volI = m_totalMolesInert * GasConstant * Temp_ / Pres_;
728 throw CanteraError(
"vcs_VolPhase::_updateVolPM",
"unknown situation");
731 m_UpToDate_VolPM =
true;
735 void vcs_VolPhase::_updateLnActCoeffJac()
737 double phaseTotalMoles = v_totalMoles;
738 if (phaseTotalMoles < 1.0E-14) {
739 phaseTotalMoles = 1.0;
745 if (!m_UpToDate_AC) {
751 TP_ptr->getdlnActCoeffdlnN(m_numSpecies, &np_dLnActCoeffdMolNumber(0,0));
752 for (
size_t j = 0; j < m_numSpecies; j++) {
753 double moles_j_base = phaseTotalMoles * Xmol_[j];
754 double*
const np_lnActCoeffCol = np_dLnActCoeffdMolNumber.ptrColumn(j);
755 if (moles_j_base < 1.0E-200) {
756 moles_j_base = 1.0E-7 * moles_j_base + 1.0E-13 * phaseTotalMoles + 1.0E-150;
758 for (
size_t k = 0; k < m_numSpecies; k++) {
759 np_lnActCoeffCol[k] = np_lnActCoeffCol[k] * phaseTotalMoles / moles_j_base;
763 double deltaMoles_j = 0.0;
765 std::vector<double> ActCoeff_Base(ActCoeff);
766 std::vector<double> Xmol_Base(Xmol_);
767 double TMoles_base = phaseTotalMoles;
772 for (
size_t j = 0; j < m_numSpecies; j++) {
778 double moles_j_base = phaseTotalMoles * Xmol_Base[j];
779 deltaMoles_j = 1.0E-7 * moles_j_base + 1.0E-13 * phaseTotalMoles + 1.0E-150;
784 phaseTotalMoles = TMoles_base + deltaMoles_j;
785 for (
size_t k = 0; k < m_numSpecies; k++) {
786 Xmol_[k] = Xmol_Base[k] * TMoles_base / phaseTotalMoles;
788 Xmol_[j] = (moles_j_base + deltaMoles_j) / phaseTotalMoles;
794 _updateMoleFractionDependencies();
799 v_totalMoles = TMoles_base;
809 _updateMoleFractionDependencies();
813 void vcs_VolPhase::sendToVCS_LnActCoeffJac(
Array2D& np_LnACJac_VCS)
820 _updateLnActCoeffJac();
825 for (
size_t j = 0; j < m_numSpecies; j++) {
826 size_t jglob = IndSpecies[j];
827 for (
size_t k = 0; k < m_numSpecies; k++) {
828 size_t kglob = IndSpecies[k];
829 np_LnACJac_VCS(kglob,jglob) = np_dLnActCoeffdMolNumber(k,j);
838 m_useCanteraCalls =
true;
840 Pres_ = TP_ptr->pressure();
841 setState_TP(Temp_, Pres_);
842 p_VCS_UnitsFormat = VCS_UNITS_MKS;
843 m_phi = TP_ptr->electricPotential();
844 size_t nsp = TP_ptr->nSpecies();
845 size_t nelem = TP_ptr->nElements();
846 if (nsp != m_numSpecies) {
847 if (m_numSpecies != 0) {
848 plogf(
"Warning Nsp != NVolSpeces: %d %d \n", nsp, m_numSpecies);
850 resize(VP_ID_, nsp, nelem, PhaseName.c_str());
853 creationMoleNumbers_ = Xmol_;
854 _updateMoleFractionDependencies();
860 m_isIdealSoln =
true;
862 int eos = TP_ptr->eosType();
865 case cIncompressible:
868 case cStoichSubstance:
874 m_isIdealSoln =
true;
877 m_isIdealSoln =
false;
881 m_useCanteraCalls =
false;
882 warn_deprecated(
"m_useCanteraCalls",
"Setting this flag to 'false' is "
883 "deprecated and will not work after Cantera 2.2.");
893 double vcs_VolPhase::totalMoles()
const
898 double vcs_VolPhase::molefraction(
size_t k)
const
903 void vcs_VolPhase::setCreationMoleNumbers(
const double*
const n_k,
904 const std::vector<size_t> &creationGlobalRxnNumbers)
906 creationMoleNumbers_.assign(n_k, n_k+m_numSpecies);
907 for (
size_t k = 0; k < m_numSpecies; k++) {
908 creationGlobalRxnNumbers_[k] = creationGlobalRxnNumbers[k];
912 const std::vector<double> & vcs_VolPhase::creationMoleNumbers(std::vector<size_t> &creationGlobalRxnNumbers)
const
914 creationGlobalRxnNumbers = creationGlobalRxnNumbers_;
915 return creationMoleNumbers_;
918 void vcs_VolPhase::setTotalMoles(
const double totalMols)
920 v_totalMoles = totalMols;
921 if (m_totalMolesInert > 0.0) {
924 "vcs_VolPhase::setTotalMoles",
925 "totalMoles less than inert moles: " +
928 if (m_singleSpecies && (m_phiVarIndex == 0)) {
931 if (totalMols > 0.0) {
940 void vcs_VolPhase::setMolesOutOfDate(
int stateCalc)
943 if (stateCalc != -1) {
944 m_vcsStateStatus = stateCalc;
948 void vcs_VolPhase::setMolesCurrent(
int stateCalc)
951 m_vcsStateStatus = stateCalc;
959 case VCS_EOS_CONSTANT:
960 sprintf(st,
"Constant ");
962 case VCS_EOS_IDEAL_GAS:
963 sprintf(st,
"Ideal Gas ");
965 case VCS_EOS_STOICH_SUB:
966 sprintf(st,
"Stoich Sub ");
968 case VCS_EOS_IDEAL_SOLN:
969 sprintf(st,
"Ideal Soln ");
971 case VCS_EOS_DEBEYE_HUCKEL:
972 sprintf(st,
"Debeye Huckel ");
974 case VCS_EOS_REDLICK_KWONG:
975 sprintf(st,
"Redlick_Kwong ");
977 case VCS_EOS_REGULAR_SOLN:
978 sprintf(st,
"Regular Soln ");
981 sprintf(st,
"UnkType: %-7d", EOSType);
988 bool vcs_VolPhase::isIdealSoln()
const
990 return m_isIdealSoln;
993 bool vcs_VolPhase::usingCanteraCalls()
const
995 return m_useCanteraCalls;
998 size_t vcs_VolPhase::phiVarIndex()
const
1000 return m_phiVarIndex;
1003 void vcs_VolPhase::setPhiVarIndex(
size_t phiVarIndex)
1005 m_phiVarIndex = phiVarIndex;
1007 if (m_singleSpecies) {
1008 if (m_phiVarIndex == 0) {
1016 return ListSpeciesPtr[kindex];
1019 int vcs_VolPhase::exists()
const
1024 void vcs_VolPhase::setExistence(
const int existence)
1027 if (v_totalMoles != 0.0) {
1028 if (DEBUG_MODE_ENABLED) {
1030 "setting false existence for phase with moles");
1035 }
else if (DEBUG_MODE_ENABLED && m_totalMolesInert == 0.0) {
1036 if (v_totalMoles == 0.0) {
1037 if (!m_singleSpecies || m_phiVarIndex != 0) {
1039 "setting true existence for phase with no moles");
1043 if (DEBUG_MODE_ENABLED && m_singleSpecies) {
1044 if (m_phiVarIndex == 0) {
1047 "Trying to set existence of an electron phase to false");
1051 m_existence = existence;
1054 size_t vcs_VolPhase::spGlobalIndexVCS(
const size_t spIndex)
const
1056 return IndSpecies[spIndex];
1059 void vcs_VolPhase::setSpGlobalIndexVCS(
const size_t spIndex,
1060 const size_t spGlobalIndex)
1062 IndSpecies[spIndex] = spGlobalIndex;
1063 if (spGlobalIndex >= m_numElemConstraints) {
1064 creationGlobalRxnNumbers_[spIndex] = spGlobalIndex - m_numElemConstraints;
1068 void vcs_VolPhase::setTotalMolesInert(
const double tMolesInert)
1070 if (m_totalMolesInert != tMolesInert) {
1072 m_UpToDate_AC =
false;
1073 m_UpToDate_VolStar =
false;
1074 m_UpToDate_VolPM =
false;
1075 m_UpToDate_GStar =
false;
1076 m_UpToDate_G0 =
false;
1077 v_totalMoles += (tMolesInert - m_totalMolesInert);
1078 m_totalMolesInert = tMolesInert;
1080 if (m_totalMolesInert > 0.0) {
1082 }
else if (m_singleSpecies && (m_phiVarIndex == 0)) {
1085 if (v_totalMoles > 0.0) {
1093 double vcs_VolPhase::totalMolesInert()
const
1095 return m_totalMolesInert;
1098 size_t vcs_VolPhase::elemGlobalIndex(
const size_t e)
const
1100 AssertThrow(e < m_numElemConstraints,
" vcs_VolPhase::elemGlobalIndex");
1101 return m_elemGlobalIndex[e];
1104 void vcs_VolPhase::setElemGlobalIndex(
const size_t eLocal,
const size_t eGlobal)
1107 "vcs_VolPhase::setElemGlobalIndex");
1108 m_elemGlobalIndex[eLocal] = eGlobal;
1111 size_t vcs_VolPhase::nElemConstraints()
const
1113 return m_numElemConstraints;
1116 std::string vcs_VolPhase::elementName(
const size_t e)
const
1118 return m_elementNames[e];
1124 for (
size_t k = 0; k < tPhase->
nSpecies(); k++) {
1125 if (tPhase->
charge(k) != 0.0) {
1149 size_t vcs_VolPhase::transferElementsFM(
const ThermoPhase*
const tPhase)
1161 ChargeNeutralityElement = ne;
1171 if (ChargeNeutralityElement !=
npos) {
1175 size_t eFound =
npos;
1187 for (
size_t eT = 0; eT < nebase; eT++) {
1190 m_elementActive[eT] = 0;
1195 for (
size_t eT = 0; eT < nebase; eT++) {
1202 if (eFound ==
npos) {
1205 m_elementActive[ne] = 0;
1206 std::string ename =
"E";
1207 m_elementNames[ne] = ename;
1214 m_formulaMatrix.resize(ns, ne, 0.0);
1221 for (
size_t eT = 0; eT < nebase; eT++) {
1228 std::string pname = tPhase->
id();
1230 std::stringstream sss;
1231 sss <<
"phase" << VP_ID_;
1234 e = ChargeNeutralityElement;
1235 m_elementNames[e] =
"cn_" + pname;
1238 for (
size_t k = 0; k < ns; k++) {
1240 for (
size_t eT = 0; eT < nebase; eT++) {
1241 m_formulaMatrix(k,e) = tPhase->
nAtoms(k, eT);
1244 if (eFound !=
npos) {
1245 m_formulaMatrix(k,eFound) = - tPhase->
charge(k);
1250 for (
size_t k = 0; k < ns; k++) {
1251 m_formulaMatrix(k,ChargeNeutralityElement) = tPhase->
charge(k);
1262 if (tPhase->
charge(0) != 0.0) {
1271 int vcs_VolPhase::elementType(
const size_t e)
const
1273 return m_elementType[e];
1276 void vcs_VolPhase::setElementType(
const size_t e,
const int eType)
1278 m_elementType[e] = eType;
1281 const Array2D& vcs_VolPhase::getFormulaMatrix()
const
1283 return m_formulaMatrix;
1286 int vcs_VolPhase::speciesUnknownType(
const size_t k)
const
1288 return m_speciesUnknownType[k];
1291 int vcs_VolPhase::elementActive(
const size_t e)
const
1293 return m_elementActive[e];
1296 size_t vcs_VolPhase::nSpecies()
const
1298 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.
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.
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 ...
#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.
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...
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
double vcsUtil_gasConstant(int mu_units)
Returns the value of the gas constant in the units specified by parameter.
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)
#define VCS_PHASE_EXIST_YES
Phase is a normal phase that currently exists.
#define AssertThrowMsg(expr, procedure, message)
Assertion must be true or an error is thrown.
A class for 2D arrays stored in column-major (Fortran-compatible) form.
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.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Properties of a single species.
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.
Base class for exceptions thrown by Cantera classes.
const int cEdge
An edge between two 2D surfaces.
std::string string16_EOSType(int EOSType)
Return a string representing the equation of state.
virtual double G0_R_calc(size_t kglob, double TKelvin)
This function calculates the standard state Gibbs free energy for species, kspec, at the temperature ...
size_t nSpecies() const
Returns the number of species in the phase.
doublereal temperature() const
Temperature (K).
#define VCS_STATECALC_OLD
State Calculation based on the old or base mole numbers.
Contains declarations for string manipulation functions within Cantera.
std::string elementName(size_t m) const
Name of the element with index m.
#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...