7 #include "cantera/equil/MultiPhaseEquil.h"
21 MultiPhase::MultiPhase() :
97 for (n = 0; n < mix.
m_np; n++) {
107 for (n = 0; n < np; n++) {
118 "phases cannot be added after init() has been called.");
140 for (m = 0; m < nel; m++) {
153 if (ename ==
"E" || ename ==
"e") {
210 for (m = 0; m <
m_nel; m++) {
214 for (ip = 0; ip <
m_np; ip++) {
218 for (kp = 0; kp < nsp; kp++) {
219 if (mlocal !=
npos) {
236 for (k = 0; k <
m_nsp; k++) {
238 for (m = 0; m <
m_nel; m++) {
299 doublereal sum = 0.0, phasesum;
301 for (i = 0; i <
m_np; i++) {
304 for (ik = 0; ik < nsp; ik++) {
316 doublereal sum = 0.0;
318 for (i = 0; i <
m_np; i++) {
331 throw CanteraError(
"MultiPhase::speciesIndex",
"phase not found: " + phaseName);
333 size_t k =
m_phase[p]->speciesIndex(speciesName);
335 throw CanteraError(
"MultiPhase::speciesIndex",
"species not found: " + speciesName);
346 doublereal phasesum = 0.0;
347 size_t ik, k, nsp =
m_phase[p]->nSpecies();
348 for (ik = 0; ik < nsp; ik++) {
352 return Faraday*phasesum*
m_moles[p];
361 for (i = 0; i <
m_np; i++) {
362 m_phase[i]->getChemPotentials(mu + loc);
395 doublereal* mu,
bool standard)
const
401 for (i = 0; i <
m_np; i++) {
404 m_phase[i]->getChemPotentials(mu + loc);
406 m_phase[i]->getStandardChemPotentials(mu + loc);
429 doublereal sum = 0.0;
431 for (i = 0; i <
m_np; i++) {
443 doublereal sum = 0.0;
445 for (i = 0; i <
m_np; i++) {
457 doublereal sum = 0.0;
459 for (i = 0; i <
m_np; i++) {
471 doublereal sum = 0.0;
473 for (i = 0; i <
m_np; i++) {
487 doublereal sum = 0.0;
489 for (i = 0; i <
m_np; i++) {
509 for (
size_t k = 0; k < p->
nSpecies(); k++) {
522 for (
size_t k = 0; k < kk; k++) {
540 for (
size_t k = 0; k <
nSpecies(); k++) {
559 doublereal* dtmp = molNum;
561 doublereal phasemoles =
m_moles[ip];
564 for (ik = 0; ik < nsp; ik++) {
565 *(dtmp++) *= phasemoles;
580 doublereal phasemoles;
581 for (ip = 0; ip <
m_np; ip++) {
585 for (ik = 0; ik < nsp; ik++) {
591 if (phasemoles > 0.0) {
608 tmpMoles[indexS] += addedMoles;
609 if (tmpMoles[indexS] < 0.0) {
610 tmpMoles[indexS] = 0.0;
637 for (eGlobal = 0; eGlobal <
m_nel; eGlobal++) {
649 for (eGlobal = 0; eGlobal <
m_nel; eGlobal++) {
655 doublereal phasemoles =
m_moles[ip];
656 for (ik = 0; ik < nspPhase; ik++) {
659 for (eGlobal = 0; eGlobal <
m_nel; eGlobal++) {
672 for (i = 0; i < int(
m_np); i++) {
673 double vol = 1.0/
m_phase[i]->molarDensity();
680 int maxsteps,
int maxiter,
int loglevel)
686 doublereal hnow, herr = 1.0;
687 doublereal snow, serr = 1.0, s0;
688 doublereal Tlow = -1.0, Thigh = -1.0;
690 doublereal dta=0.0, dtmax, cpb;
710 e->equilibrate(XY, err, maxsteps, loglevel);
731 for (n = 0; n < maxiter; n++) {
747 e->equilibrate(TP, err, maxsteps, loglevel);
767 cpb = (Hhigh - Hlow)/(Thigh - Tlow);
768 dt = (h0 - hnow)/cpb;
770 dtmax = 0.5*fabs(Thigh - Tlow);
775 tnew = sqrt(Tlow*Thigh);
780 herr = fabs((h0 - hnow)/h0);
819 "try estimating starting composition");
822 tnew = 0.5*(
m_temp + Thigh);
823 if (fabs(tnew -
m_temp) < 1.0) {
843 "No convergence for T");
844 }
else if (XY == SP) {
854 for (n = 0; n < maxiter; n++) {
864 e->equilibrate(TP, err, maxsteps, loglevel);
875 serr = fabs((s0 - snow)/s0);
883 dtmax = 0.5*fabs(Thigh - Tlow);
884 dtmax = (dtmax > 500.0 ? 500.0 : dtmax);
889 if (herr < err || dta < 1.0e-4) {
912 "setting strt to True");
916 tnew = 0.5*(
m_temp + Thigh);
935 "No convergence for T");
936 }
else if (XY == TV) {
943 doublereal vnow, pnow, verr;
944 for (n = 0; n < maxiter; n++) {
950 e.equilibrate(TP, err, maxsteps, loglevel);
952 verr = fabs((v0 - vnow)/v0);
965 dVdP = (
volume() - vnow)/(0.01*pnow);
974 throw CanteraError(
"MultiPhase::equilibrate",
"unknown option");
986 #ifdef MULTIPHASE_DEVEL
987 void importFromXML(
string infile,
string id)
994 if (x.name() !=
"multiphase")
995 throw CanteraError(
"MultiPhase::importFromXML",
996 "Current XML_Node is not a multiphase element.");
997 vector<XML_Node*> phases;
998 x.getChildren(
"phase",phases);
999 int np = phases.size();
1002 for (n = 0; n < np; n++) {
1003 XML_Node& ph = *phases[n];
1005 if (ph.hasAttrib(
"src")) {
1006 srcfile = ph[
"src"];
1011 addPhase(p, ph.value());
1050 for (
size_t e = 0; e <
m_nel; e++) {
1098 for (
int iph = 0; iph < (int)
m_np; iph++) {
1144 for (ip = 0; ip <
m_np; ip++) {
1167 for (p = 0; p <
m_np; p++) {