11 #include "vcs_SpeciesProperties.h"
12 #include "vcs_species_thermo.h"
16 #include "cantera/thermo/mix_defs.h"
34 m_owningSolverObject(0),
37 m_singleSpecies(true),
39 m_eqnState(VCS_EOS_CONSTANT),
40 ChargeNeutralityElement(
npos),
41 p_VCS_UnitsFormat(VCS_UNITS_MKS),
42 p_activityConvention(0),
43 m_numElemConstraints(0),
46 m_totalMolesInert(0.0),
51 m_useCanteraCalls(false),
54 creationMoleNumbers_(0),
55 creationGlobalRxnNumbers_(0),
62 m_UpToDate_VolStar(false),
63 m_UpToDate_VolPM(false),
64 m_UpToDate_GStar(false),
98 m_owningSolverObject(b.m_owningSolverObject),
100 Domain_ID(b.Domain_ID),
101 m_singleSpecies(b.m_singleSpecies),
102 m_gasPhase(b.m_gasPhase),
103 m_eqnState(b.m_eqnState),
104 ChargeNeutralityElement(b.ChargeNeutralityElement),
105 p_VCS_UnitsFormat(b.p_VCS_UnitsFormat),
106 p_activityConvention(b.p_activityConvention),
107 m_numElemConstraints(b.m_numElemConstraints),
108 m_numSpecies(b.m_numSpecies),
109 m_totalMolesInert(b.m_totalMolesInert),
110 m_isIdealSoln(b.m_isIdealSoln),
111 m_existence(b.m_existence),
112 m_MFStartIndex(b.m_MFStartIndex),
113 m_useCanteraCalls(b.m_useCanteraCalls),
115 v_totalMoles(b.v_totalMoles),
116 creationMoleNumbers_(0),
117 creationGlobalRxnNumbers_(0),
119 m_totalVol(b.m_totalVol),
123 m_UpToDate_AC(false),
124 m_UpToDate_VolStar(false),
125 m_UpToDate_VolPM(false),
126 m_UpToDate_GStar(false),
127 m_UpToDate_G0(false),
189 for (
size_t k = 0; k < old_num; k++) {
240 const size_t numElem,
const char*
const phaseName,
241 const double molesInert)
245 plogf(
"nspecies Error\n");
249 plogf(
"phaseNum should be greater than 0\n");
258 if (strcmp(
PhaseName.c_str(), phaseName)) {
259 plogf(
"Strings are different: %s %s :unknown situation\n",
266 std::stringstream sstmp;
267 sstmp <<
"Phase_" <<
VP_ID_;
300 for (
size_t i = 0; i < nspecies; i++) {
304 Xmol_.resize(nspecies, 0.0);
307 for (
size_t i = 0; i < nspecies; i++) {
308 Xmol_[i] = 1.0/nspecies;
336 void vcs_VolPhase::elemResize(
const size_t numElemConstraints)
399 VCS_SPECIES_THERMO* sTherm = sProp->SpeciesThermo;
401 R * (sTherm->G0_R_calc(kglob,
Temp_));
426 VCS_SPECIES_THERMO* sTherm = sProp->SpeciesThermo;
428 R * (sTherm->GStar_R_calc(kglob,
Temp_,
Pres_));
457 if (std::fabs(sum) > 1.0E-13) {
493 double vcs_VolPhase::moleFraction(
size_t k)
const
501 const double*
const moleFractions,
502 const int vcsStateStatus)
505 if (totalMoles != 0.0) {
509 printf(
"vcs_VolPhase::setMolesFractionsState: inappropriate usage\n");
515 printf(
"vcs_VolPhase::setMolesFractionsState: inappropriate usage\n");
526 double fractotal = 1.0;
530 printf(
"vcs_VolPhase::setMolesFractionsState: inerts greater than total: %g %g\n",
538 Xmol_[k] = moleFractions[k];
539 sum += moleFractions[k];
542 printf(
"vcs_VolPhase::setMolesFractionsState: inappropriate usage\n");
545 if (sum != fractotal) {
547 Xmol_[k] *= (fractotal /sum);
569 const double* molesSpeciesVCS)
575 if (molesSpeciesVCS == 0) {
578 printf(
"vcs_VolPhase::setMolesFromVCS shouldn't be here\n");
589 printf(
"vcs_VolPhase::setMolesFromVCS shouldn't be here\n");
599 printf(
"vcs_VolPhase::setMolesFromVCS shouldn't be here\n");
604 printf(
"vcs_VolPhase::setMolesFromVCS shouldn't be here\n");
622 tmp =
std::max(0.0, molesSpeciesVCS[kglob]);
642 if (m_numSpecies == 1) {
647 double phi = molesSpeciesVCS[kglob];
649 if (m_numSpecies == 1) {
680 const double* molesSpeciesVCS,
681 const double*
const TPhMoles)
687 double Tcheck = TPhMoles[
VP_ID_];
692 plogf(
"vcs_VolPhase::setMolesFromVCSCheck: "
693 "We have a consistency problem: %21.16g %21.16g\n",
859 VCS_SPECIES_THERMO* sTherm = sProp->SpeciesThermo;
891 VCS_SPECIES_THERMO* sTherm = sProp->SpeciesThermo;
910 printf(
"unknown situation\n");
934 if (moles_j_base < 1.0E-200) {
935 moles_j_base = 1.0E-7 * moles_j_base + 1.0E-20 *
v_totalMoles + 1.0E-150;
938 lnActCoeffCol[k] /= moles_j_base;
942 double deltaMoles_j = 0.0;
944 std::vector<double> ActCoeff_Base(
ActCoeff);
945 std::vector<double> Xmol_Base(
Xmol_);
958 deltaMoles_j = 1.0E-7 * moles_j_base + 1.0E-13 *
v_totalMoles + 1.0E-150;
981 tmp = (
ActCoeff[k] - ActCoeff_Base[k]) /
982 ((
ActCoeff[k] + ActCoeff_Base[k]) * 0.5 * deltaMoles_j);
983 if (fabs(tmp - lnActCoeffCol[k]) > 1.0E-4 * fabs(tmp) + fabs(lnActCoeffCol[k])) {
994 vcs_vdcopy(
Xmol_, Xmol_Base, m_numSpecies);
1021 vcs_VolPhase::sendToVCS_LnActCoeffJac(
double*
const*
const LnACJac_VCS)
1035 double*
const lnACJacVCS_col = LnACJac_VCS[jglob];
1039 lnACJacVCS_col[kglob] = lnACJac_col[k];
1065 if (nsp != m_numSpecies) {
1066 if (m_numSpecies != 0) {
1067 plogf(
"Warning Nsp != NVolSpeces: %d %d \n", nsp, m_numSpecies);
1084 case Cantera::cIncompressible:
1087 case Cantera::cStoichSubstance:
1088 case Cantera::cSemiconductor:
1089 case Cantera::cLatticeSolid:
1090 case Cantera::cLattice:
1128 const std::vector<size_t> &creationGlobalRxnNumbers)
1157 printf(
" vcs_VolPhase::setTotalMoles:: ERROR totalMoles "
1158 "less than inert moles: %g %g\n",
1167 if (totalMols > 0.0) {
1185 if (stateCalc != -1) {
1207 std::string string16_EOSType(
int EOSType)
1212 case VCS_EOS_CONSTANT:
1213 sprintf(st,
"Constant ");
1215 case VCS_EOS_IDEAL_GAS:
1216 sprintf(st,
"Ideal Gas ");
1218 case VCS_EOS_STOICH_SUB:
1219 sprintf(st,
"Stoich Sub ");
1221 case VCS_EOS_IDEAL_SOLN:
1222 sprintf(st,
"Ideal Soln ");
1224 case VCS_EOS_DEBEYE_HUCKEL:
1225 sprintf(st,
"Debeye Huckel ");
1227 case VCS_EOS_REDLICK_KWONG:
1228 sprintf(st,
"Redlick_Kwong ");
1230 case VCS_EOS_REGULAR_SOLN:
1231 sprintf(st,
"Regular Soln ");
1234 sprintf(st,
"UnkType: %-7d", EOSType);
1264 void vcs_VolPhase::setPhiVarIndex(
size_t phiVarIndex)
1301 plogf(
"vcs_VolPhase::setExistence setting false existence for phase with moles");
1314 plogf(
"vcs_VolPhase::setExistence setting true existence for phase with no moles");
1326 plogf(
"vcs_VolPhase::Trying to set existence of an electron phase to false");
1360 const size_t spGlobalIndex)
1419 "vcs_VolPhase::setElemGlobalIndex");
1442 for (
size_t k = 0; k < tPhase->
nSpecies(); k++) {
1443 if (tPhase->
charge(k) != 0.0) {
1460 int hasCharge = hasChargedSpecies(tPhase);
1473 size_t eFound =
npos;
1482 bool cne = chargeNeutralityElement(tPhase);
1498 if (hasChargedSpecies(tPhase)) {
1509 for (eT = 0; eT < nebase; eT++) {
1518 for (eT = 0; eT < nebase; eT++) {
1526 if (eFound ==
npos) {
1530 std::string ename =
"E";
1545 for (eT = 0; eT < nebase; eT++) {
1553 std::string pname = tPhase->
id();
1555 std::stringstream sss;
1556 sss <<
"phase" <<
VP_ID_;
1559 ename =
"cn_" + pname;
1565 for (k = 0; k < ns; k++) {
1567 for (eT = 0; eT < nebase; eT++) {
1568 fm[e][k] = tPhase->
nAtoms(k, eT);
1571 if (eFound !=
npos) {
1572 fm[eFound][k] = - tPhase->
charge(k);
1577 for (k = 0; k < ns; k++) {
1589 if (tPhase->
charge(0) != 0.0) {
1633 int vcs_VolPhase::elementActive(
const size_t e)
const