32 m_chargeNeutralityNecessary(false),
38ThermoPhase::~ThermoPhase()
49 for (
size_t k = 0; k <
nSpecies(); k++) {
69 return Units(1.0, 0, -
static_cast<double>(
nDim()), 0, 0, 0, 1);
80 for (
size_t k = 0; k <
nSpecies(); k++) {
88 for (
size_t k = 0; k <
m_kk; k++) {
89 lnac[k] = std::log(lnac[k]);
97 for (
size_t k = 0; k <
m_kk; k++) {
212 AnyMap state = input_state;
215 if (state.
hasKey(
"mass-fractions")) {
216 state[
"Y"] = state[
"mass-fractions"];
217 state.
erase(
"mass-fractions");
219 if (state.
hasKey(
"mole-fractions")) {
220 state[
"X"] = state[
"mole-fractions"];
221 state.
erase(
"mole-fractions");
223 if (state.
hasKey(
"temperature")) {
224 state[
"T"] = state[
"temperature"];
226 if (state.
hasKey(
"pressure")) {
227 state[
"P"] = state[
"pressure"];
229 if (state.
hasKey(
"enthalpy")) {
230 state[
"H"] = state[
"enthalpy"];
232 if (state.
hasKey(
"int-energy")) {
233 state[
"U"] = state[
"int-energy"];
235 if (state.
hasKey(
"internal-energy")) {
236 state[
"U"] = state[
"internal-energy"];
238 if (state.
hasKey(
"specific-volume")) {
239 state[
"V"] = state[
"specific-volume"];
241 if (state.
hasKey(
"entropy")) {
242 state[
"S"] = state[
"entropy"];
244 if (state.
hasKey(
"density")) {
245 state[
"D"] = state[
"density"];
247 if (state.
hasKey(
"vapor-fraction")) {
248 state[
"Q"] = state[
"vapor-fraction"];
253 if (state[
"X"].is<string>()) {
259 }
else if (state.
hasKey(
"Y")) {
260 if (state[
"Y"].is<string>()) {
268 if (state.
size() == 0) {
271 double T = state.
convert(
"T",
"K");
272 double P = state.
convert(
"P",
"Pa");
308 }
else if (state.
hasKey(
"T")) {
310 }
else if (state.
hasKey(
"P")) {
314 "'state' did not specify a recognized set of properties.\n"
315 "Keys provided were: {}", input_state.
keys_str());
328 double rtol,
bool doUV)
338 "Input specific volume is too small or negative. v = {}", v);
344 "Input pressure is too small or negative. p = {}", p);
357 }
else if (Tnew < Tmin) {
371 bool ignoreBounds =
false;
374 bool unstablePhase =
false;
377 double Tunstable = -1.0;
378 bool unstablePhaseNew =
false;
381 for (
int n = 0; n < 500; n++) {
386 unstablePhase =
true;
390 dt =
clip((Htarget - Hold)/cpd, -100.0, 100.0);
397 if ((dt > 0.0 && unstablePhase) || (dt <= 0.0 && !unstablePhase)) {
398 if (Hbot < Htarget && Tnew < (0.75 * Tbot + 0.25 * Told)) {
399 dt = 0.75 * (Tbot - Told);
402 }
else if (Htop > Htarget && Tnew > (0.75 * Ttop + 0.25 * Told)) {
403 dt = 0.75 * (Ttop - Told);
408 if (Tnew > Tmax && !ignoreBounds) {
411 if (Hmax >= Htarget) {
412 if (Htop < Htarget) {
421 if (Tnew < Tmin && !ignoreBounds) {
424 if (Hmin <= Htarget) {
425 if (Hbot > Htarget) {
438 for (
int its = 0; its < 10; its++) {
440 if (Tnew < Told / 3.0) {
442 dt = -2.0 * Told / 3.0;
453 unstablePhaseNew =
true;
456 unstablePhaseNew =
false;
459 if (unstablePhase ==
false && unstablePhaseNew ==
true) {
464 if (Hnew == Htarget) {
466 }
else if (Hnew > Htarget && (Htop < Htarget || Hnew < Htop)) {
469 }
else if (Hnew < Htarget && (Hbot > Htarget || Hnew > Hbot)) {
474 double Herr = Htarget - Hnew;
475 double acpd = std::max(fabs(cpd), 1.0E-5);
476 double denom = std::max(fabs(Htarget), acpd * Tnew);
477 double HConvErr = fabs((Herr)/denom);
478 if (HConvErr < rtol || fabs(dt/Tnew) < rtol) {
486 string ErrString =
"No convergence in 500 iterations\n";
488 ErrString += fmt::format(
489 "\tTarget Internal Energy = {}\n"
490 "\tCurrent Specific Volume = {}\n"
491 "\tStarting Temperature = {}\n"
492 "\tCurrent Temperature = {}\n"
493 "\tCurrent Internal Energy = {}\n"
494 "\tCurrent Delta T = {}\n",
495 Htarget, v, Tinit, Tnew, Hnew, dt);
497 ErrString += fmt::format(
498 "\tTarget Enthalpy = {}\n"
499 "\tCurrent Pressure = {}\n"
500 "\tStarting Temperature = {}\n"
501 "\tCurrent Temperature = {}\n"
502 "\tCurrent Enthalpy = {}\n"
503 "\tCurrent Delta T = {}\n",
504 Htarget, p, Tinit, Tnew, Hnew, dt);
507 ErrString += fmt::format(
508 "\t - The phase became unstable (Cp < 0) T_unstable_last = {}\n",
512 throw CanteraError(
"ThermoPhase::setState_HPorUV (UV)", ErrString);
514 throw CanteraError(
"ThermoPhase::setState_HPorUV (HP)", ErrString);
530 double rtol,
bool doSV)
538 "Input specific volume is too small or negative. v = {}", v);
544 "Input pressure is too small or negative. p = {}", p);
557 }
else if (Tnew < Tmin) {
571 bool ignoreBounds =
false;
574 bool unstablePhase =
false;
575 double Tunstable = -1.0;
576 bool unstablePhaseNew =
false;
579 for (
int n = 0; n < 500; n++) {
584 unstablePhase =
true;
588 dt =
clip((Starget - Sold)*Told/cpd, -100.0, 100.0);
592 if ((dt > 0.0 && unstablePhase) || (dt <= 0.0 && !unstablePhase)) {
593 if (Sbot < Starget && Tnew < Tbot) {
594 dt = 0.75 * (Tbot - Told);
597 }
else if (Stop > Starget && Tnew > Ttop) {
598 dt = 0.75 * (Ttop - Told);
603 if (Tnew > Tmax && !ignoreBounds) {
606 if (Smax >= Starget) {
607 if (Stop < Starget) {
615 }
else if (Tnew < Tmin && !ignoreBounds) {
618 if (Smin <= Starget) {
619 if (Sbot > Starget) {
632 for (
int its = 0; its < 10; its++) {
638 unstablePhaseNew =
true;
641 unstablePhaseNew =
false;
644 if (unstablePhase ==
false && unstablePhaseNew ==
true) {
649 if (Snew == Starget) {
651 }
else if (Snew > Starget && (Stop < Starget || Snew < Stop)) {
654 }
else if (Snew < Starget && (Sbot > Starget || Snew > Sbot)) {
659 double Serr = Starget - Snew;
660 double acpd = std::max(fabs(cpd), 1.0E-5);
661 double denom = std::max(fabs(Starget), acpd * Tnew);
662 double SConvErr = fabs((Serr * Tnew)/denom);
663 if (SConvErr < rtol || fabs(dt/Tnew) < rtol) {
671 string ErrString =
"No convergence in 500 iterations\n";
673 ErrString += fmt::format(
674 "\tTarget Entropy = {}\n"
675 "\tCurrent Specific Volume = {}\n"
676 "\tStarting Temperature = {}\n"
677 "\tCurrent Temperature = {}\n"
678 "\tCurrent Entropy = {}\n"
679 "\tCurrent Delta T = {}\n",
680 Starget, v, Tinit, Tnew, Snew, dt);
682 ErrString += fmt::format(
683 "\tTarget Entropy = {}\n"
684 "\tCurrent Pressure = {}\n"
685 "\tStarting Temperature = {}\n"
686 "\tCurrent Temperature = {}\n"
687 "\tCurrent Entropy = {}\n"
688 "\tCurrent Delta T = {}\n",
689 Starget, p, Tinit, Tnew, Snew, dt);
692 ErrString += fmt::format(
"\t - The phase became unstable (Cp < 0) T_unstable_last = {}\n",
696 throw CanteraError(
"ThermoPhase::setState_SPorSV (SV)", ErrString);
698 throw CanteraError(
"ThermoPhase::setState_SPorSV (SP)", ErrString);
711 for (
size_t k = 0; k !=
m_kk; ++k) {
715 o2req += x *
nAtoms(k, iC);
718 o2req += x *
nAtoms(k, iS);
721 o2req += x * 0.25 *
nAtoms(k, iH);
726 "No composition specified");
736 for (
size_t k = 0; k !=
m_kk; ++k) {
742 "No composition specified");
744 return 0.5 * o2pres / sum;
757 const std::string& oxComp,
767 const double* oxComp,
771 if (basis == ThermoBasis::molar) {
776 fuelComp = fuel.data();
783 if (o2_required_fuel < 0.0 || o2_required_ox > 0.0) {
785 "Fuel composition contains too much oxygen or "
786 "oxidizer contains not enough oxygen. "
787 "Fuel and oxidizer composition mixed up?");
790 if (o2_required_ox == 0.0) {
791 return std::numeric_limits<double>::infinity();
794 return o2_required_fuel / (-o2_required_ox);
802 "Equivalence ratio phi must be >= 0");
808 if (basis == ThermoBasis::molar) {
813 fuelComp = fuel.data();
819 double sum_f = std::accumulate(fuelComp, fuelComp+
m_kk, 0.0);
820 double sum_o = std::accumulate(oxComp, oxComp+
m_kk, 0.0);
823 for (
size_t k = 0; k !=
m_kk; ++k) {
824 y[k] = phi * fuelComp[k]/sum_f + AFR_st * oxComp[k]/sum_o;
853 if (o2_present == 0.0) {
854 return std::numeric_limits<double>::infinity();
857 return o2_required / o2_present;
870 const std::string& oxComp,
880 const double* oxComp,
890 return std::numeric_limits<double>::infinity();
894 if (basis == ThermoBasis::molar) {
899 fuelComp = fuel.data();
905 return std::max(Z / (1.0 - Z) * AFR_st, 0.0);
928 if (mixFrac < 0.0 || mixFrac > 1.0) {
930 "Mixture fraction must be between 0 and 1");
934 if (basis == ThermoBasis::molar) {
939 fuelComp = fuel.data();
943 double sum_yf = std::accumulate(fuelComp, fuelComp+
m_kk, 0.0);
944 double sum_yo = std::accumulate(oxComp, oxComp+
m_kk, 0.0);
946 if (sum_yf == 0.0 || sum_yo == 0.0) {
948 "No fuel and/or oxidizer composition specified");
955 for (
size_t k = 0; k !=
m_kk; ++k) {
956 y[k] = mixFrac * fuelComp[k]/sum_yf + (1.0-mixFrac) * oxComp[k]/sum_yo;
966 const std::string& element)
const
974 const std::string& oxComp,
976 const std::string& element)
const
985 const double* oxComp,
987 const std::string& element)
const
990 if (basis == ThermoBasis::molar) {
995 fuelComp = fuel.data();
999 if (element ==
"Bilger")
1005 if (o2_required_fuel < 0.0 || o2_required_ox > 0.0) {
1007 "Fuel composition contains too much oxygen or "
1008 "oxidizer contains not enough oxygen. "
1009 "Fuel and oxidizer composition mixed up?");
1012 double denominator = o2_required_fuel - o2_required_ox;
1014 if (denominator == 0.0) {
1016 "Fuel and oxidizer have the same composition");
1019 double Z = (o2_required_mix - o2_required_ox) / denominator;
1021 return std::min(std::max(Z, 0.0), 1.0);
1024 double sum_yf = std::accumulate(fuelComp, fuelComp+
m_kk, 0.0);
1025 double sum_yo = std::accumulate(oxComp, oxComp+
m_kk, 0.0);
1027 if (sum_yf == 0.0 || sum_yo == 0.0) {
1029 "No fuel and/or oxidizer composition specified");
1032 auto elementalFraction = [
this](
size_t m,
const double* y) {
1034 for (
size_t k = 0; k !=
m_kk; ++k) {
1041 double Z_m_fuel = elementalFraction(m, fuelComp)/sum_yf;
1042 double Z_m_ox = elementalFraction(m, oxComp)/sum_yo;
1045 if (Z_m_fuel == Z_m_ox) {
1047 "Fuel and oxidizer have the same composition for element {}",
1050 double Z = (Z_m_mix - Z_m_ox) / (Z_m_fuel - Z_m_ox);
1051 return std::min(std::max(Z, 0.0), 1.0);
1067 const std::string&
id)
1069 if (inputFile.empty()) {
1073 size_t dot = inputFile.find_last_of(
".");
1076 extension = inputFile.substr(
dot+1);
1079 if (extension ==
"yml" || extension ==
"yaml") {
1081 auto& phase = root[
"phases"].getMapWhere(
"name",
id);
1088 "ERROR: Can not find phase named {} in file"
1089 " named {}",
id, inputFile);
1107 "Missing species thermo data");
1119 "Temperature ({}), pressure ({}) and vapor fraction ({}) "
1120 "are inconsistent, above the critical temperature.",
1126 if (std::abs(Psat / P - 1) < 1e-6) {
1128 }
else if ((Q == 0 && P >= Psat) || (Q == 1 && P <= Psat)) {
1132 "Temperature ({}), pressure ({}) and vapor fraction ({}) "
1133 "are inconsistent.\nPsat at this T: {}\n"
1134 "Consider specifying the state using two fully independent "
1135 "properties (for example, temperature and density)",
1142 if (!spec->thermo) {
1144 "Species {} has no thermo data", spec->name);
1148 spec->thermo->validate(spec->name);
1156 if (!spec->thermo) {
1158 "Species {} has no thermo data", spec->name);
1163 "New species '{}' does not match existing species '{}' at index {}",
1166 spec->thermo->validate(spec->name);
1182 "m_speciesData is the wrong size");
1190 "To be removed after Cantera 2.6.");
1196 "To be removed after Cantera 2.6.");
1217 phaseNode[
"name"] =
name();
1220 for (
size_t i = 0; i <
nElements(); i++) {
1228 if (stateVars.count(
"T")) {
1232 if (stateVars.count(
"D")) {
1233 state[
"density"].setQuantity(
density(),
"kg/m^3");
1234 }
else if (stateVars.count(
"P")) {
1235 state[
"P"].setQuantity(
pressure(),
"Pa");
1238 if (stateVars.count(
"Y")) {
1239 map<string, double> Y;
1240 for (
size_t k = 0; k <
m_kk; k++) {
1248 }
else if (stateVars.count(
"X")) {
1249 map<string, double> X;
1250 for (
size_t k = 0; k <
m_kk; k++) {
1260 phaseNode[
"state"] = std::move(state);
1264 phaseNode[
"__type__"] =
"Phase";
1289 if (state.
hasChild(
"temperature")) {
1290 double t =
getFloat(state,
"temperature",
"temperature");
1294 double p =
getFloat(state,
"pressure",
"pressure");
1298 double rho =
getFloat(state,
"density",
"density");
1309 double rtol,
int max_steps,
int max_iter,
1310 int estimate_equil,
int log_level)
1312 if (solver ==
"auto" || solver ==
"element_potential") {
1315 debuglog(
"Trying ChemEquil solver\n", log_level);
1320 int ret = E.
equilibrate(*
this, XY.c_str(), log_level-1);
1323 "ChemEquil solver failed. Return code: {}", ret);
1325 debuglog(
"ChemEquil solver succeeded\n", log_level);
1327 }
catch (std::exception& err) {
1328 debuglog(
"ChemEquil solver failed.\n", log_level);
1331 if (solver ==
"auto") {
1338 if (solver ==
"auto" || solver ==
"vcs" || solver ==
"gibbs") {
1342 M.
equilibrate(XY, solver, rtol, max_steps, max_iter,
1343 estimate_equil, log_level);
1347 if (solver !=
"auto") {
1349 "Invalid solver specified: '{}'", solver);
1355 for (
size_t m = 0; m <
m_kk; m++) {
1356 for (
size_t k = 0; k <
m_kk; k++) {
1357 dlnActCoeffdlnN[ld * k + m] = 0.0;
1363void ThermoPhase::getdlnActCoeffdlnN_numderiv(
const size_t ld, doublereal*
const dlnActCoeffdlnN)
1365 double deltaMoles_j = 0.0;
1377 double v_totalMoles = 1.0;
1378 double TMoles_base = v_totalMoles;
1381 for (
size_t j = 0; j <
m_kk; j++) {
1387 double moles_j_base = v_totalMoles * Xmol_Base[j];
1388 deltaMoles_j = 1.0E-7 * moles_j_base + v_totalMoles * 1.0E-13 + 1.0E-150;
1392 v_totalMoles = TMoles_base + deltaMoles_j;
1393 for (
size_t k = 0; k <
m_kk; k++) {
1394 Xmol[k] = Xmol_Base[k] * TMoles_base / v_totalMoles;
1396 Xmol[j] = (moles_j_base + deltaMoles_j) / v_totalMoles;
1404 double*
const lnActCoeffCol = dlnActCoeffdlnN + ld * j;
1405 for (
size_t k = 0; k <
m_kk; k++) {
1406 lnActCoeffCol[k] = (2*moles_j_base + deltaMoles_j) *(ActCoeff[k] - ActCoeff_Base[k]) /
1407 ((ActCoeff[k] + ActCoeff_Base[k]) * deltaMoles_j);
1410 v_totalMoles = TMoles_base;
1419 if (
type() ==
"None") {
1421 "Not implemented for thermo model 'None'");
1424 fmt::memory_buffer b;
1426 int name_width = 18;
1428 string blank_leader = fmt::format(
"{:{}}",
"", name_width);
1430 string string_property = fmt::format(
"{{:>{}}} {{}}\n", name_width);
1432 string one_property = fmt::format(
"{{:>{}}} {{:<.5g}} {{}}\n", name_width);
1434 string two_prop_header =
"{} {:^15} {:^15}\n";
1435 string kg_kmol_header = fmt::format(
1436 two_prop_header, blank_leader,
"1 kg",
"1 kmol"
1438 string Y_X_header = fmt::format(
1439 two_prop_header, blank_leader,
"mass frac. Y",
"mole frac. X"
1441 string two_prop_sep = fmt::format(
1442 "{} {:-^15} {:-^15}\n", blank_leader,
"",
""
1444 string two_property = fmt::format(
1445 "{{:>{}}} {{:15.5g}} {{:15.5g}} {{}}\n", name_width
1448 string three_prop_header = fmt::format(
1449 "{} {:^15} {:^15} {:^15}\n", blank_leader,
"mass frac. Y",
1450 "mole frac. X",
"chem. pot. / RT"
1452 string three_prop_sep = fmt::format(
1453 "{} {:-^15} {:-^15} {:-^15}\n", blank_leader,
"",
"",
""
1455 string three_property = fmt::format(
1456 "{{:>{}}} {{:15.5g}} {{:15.5g}} {{:15.5g}}\n", name_width
1461 fmt_append(b,
"\n {}:\n",
name());
1463 fmt_append(b,
"\n");
1464 fmt_append(b, one_property,
"temperature",
temperature(),
"K");
1465 fmt_append(b, one_property,
"pressure",
pressure(),
"Pa");
1466 fmt_append(b, one_property,
"density",
density(),
"kg/m^3");
1467 fmt_append(b, one_property,
1472 fmt_append(b, one_property,
"potential", phi,
"V");
1475 fmt_append(b, string_property,
"phase of matter",
phaseOfMatter());
1478 fmt_append(b,
"\n");
1479 fmt_append(b, kg_kmol_header);
1480 fmt_append(b, two_prop_sep);
1481 fmt_append(b, two_property,
1483 fmt_append(b, two_property,
1485 fmt_append(b, two_property,
1487 fmt_append(b, two_property,
1489 fmt_append(b, two_property,
1492 fmt_append(b, two_property,
1495 fmt_append(b, string_property,
1496 "heat capacity c_v",
"<not implemented>");
1507 double xMinor = 0.0;
1508 double yMinor = 0.0;
1509 fmt_append(b,
"\n");
1511 fmt_append(b, three_prop_header);
1512 fmt_append(b, three_prop_sep);
1513 for (
size_t k = 0; k <
m_kk; k++) {
1514 if (abs(x[k]) >= threshold) {
1516 fmt_append(b, three_property,
1519 fmt_append(b, two_property,
speciesName(k), y[k], x[k],
"");
1528 fmt_append(b, Y_X_header);
1529 fmt_append(b, two_prop_sep);
1530 for (
size_t k = 0; k <
m_kk; k++) {
1531 if (abs(x[k]) >= threshold) {
1532 fmt_append(b, two_property,
speciesName(k), y[k], x[k],
"");
1541 string minor = fmt::format(
"[{:+5d} minor]", nMinor);
1542 fmt_append(b, two_property, minor, yMinor, xMinor,
"");
1545 return to_string(b) + err.
what();
1547 return to_string(b);
1554 csvFile.precision(8);
1557 std::vector<std::string> pNames;
1558 std::vector<vector_fp> data;
1561 csvFile << setw(tabS) <<
"Species,";
1562 for (
size_t i = 0; i < pNames.size(); i++) {
1563 csvFile << setw(tabM) << pNames[i] <<
",";
1566 for (
size_t k = 0; k <
nSpecies(); k++) {
1569 for (
size_t i = 0; i < pNames.size(); i++) {
1570 csvFile << setw(tabM) << data[i][k] <<
",";
1574 for (
size_t i = 0; i < pNames.size(); i++) {
1575 csvFile << setw(tabM) << 0 <<
",";
1583 std::vector<vector_fp>& data)
const
1588 names.push_back(
"X");
1591 names.push_back(
"Y");
1594 names.push_back(
"Chem. Pot (J/kmol)");
1597 names.push_back(
"Activity");
1600 names.push_back(
"Act. Coeff.");
1603 names.push_back(
"Part. Mol Enthalpy (J/kmol)");
1606 names.push_back(
"Part. Mol. Entropy (J/K/kmol)");
1609 names.push_back(
"Part. Mol. Energy (J/kmol)");
1612 names.push_back(
"Part. Mol. Cp (J/K/kmol");
1615 names.push_back(
"Part. Mol. Cv (J/K/kmol)");
Headers for the MultiPhase object that is used to set up multiphase equilibrium problems (see Classes...
Pure Virtual Base class for individual species reference state thermodynamic managers and text for th...
Declaration for class Cantera::Species.
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
A map of string keys to values whose type can vary at runtime.
size_t size() const
Returns the number of elements in this map.
double convert(const std::string &key, const std::string &units) const
Convert the item stored by the given key to the units specified in units.
static AnyMap fromYamlFile(const std::string &name, const std::string &parent_name="")
Create an AnyMap from a YAML file.
void erase(const std::string &key)
Erase the value held by key.
static bool addOrderingRules(const std::string &objectType, const std::vector< std::vector< std::string > > &specs)
Add global rules for setting the order of elements when outputting AnyMap objects to YAML.
void setFlowStyle(bool flow=true)
Use "flow" style when outputting this AnyMap to YAML.
std::string keys_str() const
Return a string listing the keys in this AnyMap, for use in error messages, for example.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
void update(const AnyMap &other, bool keepExisting=true)
Add items from other to this AnyMap.
Base class for exceptions thrown by Cantera classes.
const char * what() const
Get a description of the error.
Class ChemEquil implements a chemical equilibrium solver for single-phase solutions.
int equilibrate(ThermoPhase &s, const char *XY, int loglevel=0)
EquilOpt options
Options controlling how the calculation is carried out.
doublereal relTolerance
Relative tolerance.
int maxIterations
Maximum number of iterations.
std::string canonicalize(const std::string &name)
Get the canonical name registered for a type.
A class for multiphase mixtures.
void init()
Process phases and build atomic composition array.
void addPhase(ThermoPhase *p, doublereal moles)
Add a phase to the mixture.
A species thermodynamic property manager for a phase.
bool ready(size_t nSpecies)
Check if data for all species (0 through nSpecies-1) has been installed.
virtual void install_STIT(size_t index, shared_ptr< SpeciesThermoInterpType > stit)
Install a new species thermodynamic property parameterization for one species.
virtual void modifySpecies(size_t index, shared_ptr< SpeciesThermoInterpType > spec)
Modify the species thermodynamic property parameterization for a species.
virtual void resetHf298(const size_t k)
Restore the original heat of formation of one or more species.
An error indicating that an unimplemented function has been called.
double massFraction(size_t k) const
Return the mass fraction of a single species.
virtual bool addSpecies(shared_ptr< Species > spec)
Add a Species to this Phase.
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
std::string name() const
Return the name of the phase.
size_t nSpecies() const
Returns the number of species in the phase.
void setMoleFractionsByName(const compositionMap &xMap)
Set the species mole fractions by name.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
virtual void setMassFractions_NoNorm(const double *const y)
Set the mass fractions to the specified values without normalizing.
void assertCompressible(const std::string &setter) const
Ensure that phase is compressible.
vector_fp getCompositionFromMap(const compositionMap &comp) const
Converts a compositionMap to a vector with entries for each species Species that are not specified ar...
size_t m_kk
Number of species in the phase.
virtual void modifySpecies(size_t k, shared_ptr< Species > spec)
Modify the thermodynamic data associated with a species.
size_t nDim() const
Returns the number of spatial dimensions (1, 2, or 3)
void saveState(vector_fp &state) const
Save the current internal state of the phase.
virtual std::map< std::string, size_t > nativeState() const
Return a map of properties defining the native state of a substance.
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
virtual void setPressure(double p)
Set the internally stored pressure (Pa) at constant temperature and composition.
void moleFractionsToMassFractions(const double *X, double *Y) const
Converts a mixture composition from mass fractions to mole fractions.
size_t elementIndex(const std::string &name) const
Return the index of element named 'name'.
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
std::string speciesName(size_t k) const
Name of the species with index k.
virtual void setDensity(const double density_)
Set the internally stored density (kg/m^3) of the phase.
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
const double * massFractions() const
Return a const pointer to the mass fraction array.
double moleFraction(size_t k) const
Return the mole fraction of a single species.
void setState_TR(doublereal t, doublereal rho)
Set the internally stored temperature (K) and density (kg/m^3)
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
const std::vector< std::string > & elementNames() const
Return a read-only reference to the vector of element names.
virtual double density() const
Density (kg/m^3).
doublereal temperature() const
Temperature (K).
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
size_t nElements() const
Number of elements.
virtual void setMassFractions(const double *const y)
Set the mass fractions to the specified values and normalize them.
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
void setMassFractionsByName(const compositionMap &yMap)
Set the species mass fractions by name.
void getMassFractions(double *const y) const
Get the species mass fractions.
virtual double pressure() const
Return the thermodynamic pressure (Pa).
std::string elementName(size_t m) const
Name of the element with index m.
static ThermoFactory * factory()
Static function that creates a static instance of the factory.
virtual void setStateFromXML(const XML_Node &state)
Set the initial state of the phase to the conditions specified in the state XML element.
int m_ssConvention
Contains the standard state convention.
virtual std::string report(bool show_thermo=true, doublereal threshold=-1e-14) const
returns a summary of the state of the phase as a string
virtual void setState_TPY(doublereal t, doublereal p, const doublereal *y)
Set the internally stored temperature (K), pressure (Pa), and mass fractions of the phase.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual void setState_PY(doublereal p, doublereal *y)
Set the internally stored pressure (Pa) and mass fractions.
virtual void setState_HP(double h, double p, double tol=1e-9)
Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of the phase.
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
virtual void setState_UV(double u, double v, double tol=1e-9)
Set the specific internal energy (J/kg) and specific volume (m^3/kg).
virtual bool addSpecies(shared_ptr< Species > spec)
double equivalenceRatio() const
Compute the equivalence ratio for the current mixture from available oxygen and required oxygen.
doublereal entropy_mass() const
Specific entropy. Units: J/kg/K.
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
virtual doublereal critPressure() const
Critical pressure (Pa).
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
virtual void getActivities(doublereal *a) const
Get the array of non-dimensional activities at the current solution temperature, pressure,...
virtual void getLnActivityCoefficients(doublereal *lnac) const
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
doublereal m_tlast
last value of the temperature processed by reference state
virtual doublereal critTemperature() const
Critical temperature (K).
virtual void setState_TV(double t, double v, double tol=1e-9)
Set the temperature (K) and specific volume (m^3/kg).
double o2Present(const double *y) const
Helper function for computing the amount of oxygen available in the current mixture.
virtual void setState_Tsat(doublereal t, doublereal x)
Set the state to a saturated system at a particular temperature.
virtual void setState_PV(double p, double v, double tol=1e-9)
Set the pressure (Pa) and specific volume (m^3/kg).
virtual doublereal satPressure(doublereal t)
Return the saturation pressure given the temperature.
virtual void setState(const AnyMap &state)
Set the state using an AnyMap containing any combination of properties supported by the thermodynamic...
void setState_SPorSV(double s, double p, double tol=1e-9, bool doSV=false)
Carry out work in SP and SV calculations.
void setState_HPorUV(doublereal h, doublereal p, doublereal tol=1e-9, bool doUV=false)
Carry out work in HP and UV calculations.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
void initThermoFile(const std::string &inputFile, const std::string &id)
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
doublereal gibbs_mass() const
Specific Gibbs function. Units: J/kg.
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
virtual void modifySpecies(size_t k, shared_ptr< Species > spec)
Modify the thermodynamic data associated with a species.
virtual void getdlnActCoeffdlnN(const size_t ld, doublereal *const dlnActCoeffdlnN)
Get the array of derivatives of the log activity coefficients with respect to the log of the species ...
virtual void setState_ST(double s, double t, double tol=1e-9)
Set the specific entropy (J/kg/K) and temperature (K).
double stoichAirFuelRatio(const double *fuelComp, const double *oxComp, ThermoBasis basis=ThermoBasis::molar) const
Compute the stoichiometric air to fuel ratio (kg oxidizer / kg fuel) given fuel and oxidizer composit...
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
AnyMap parameters(bool withInput=true) const
Returns the parameters of a ThermoPhase object such that an identical one could be reconstructed usin...
virtual void setState_RPY(doublereal rho, doublereal p, const doublereal *y)
Set the density (kg/m**3), pressure (Pa) and mass fractions.
virtual void setState_TPX(doublereal t, doublereal p, const doublereal *x)
Set the temperature (K), pressure (Pa), and mole fractions.
const std::vector< const XML_Node * > & speciesData() const
Return a pointer to the vector of XML nodes containing the species data for this phase.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
doublereal cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
virtual void getCsvReportData(std::vector< std::string > &names, std::vector< vector_fp > &data) const
Fills names and data with the column names and species thermo properties to be included in the output...
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
virtual void setState_PX(doublereal p, doublereal *x)
Set the pressure (Pa) and mole fractions.
virtual std::string phaseOfMatter() const
String indicating the mechanical phase of the matter in this Phase.
double o2Required(const double *y) const
Helper function for computing the amount of oxygen required for complete oxidation.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
ThermoPhase()
Constructor.
virtual doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
virtual int activityConvention() const
This method returns the convention used in specification of the activities, of which there are curren...
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
void saveSpeciesData(const size_t k, const XML_Node *const data)
Store a reference pointer to the XML tree containing the species data for this phase.
virtual MultiSpeciesThermo & speciesThermo(int k=-1)
Return a changeable reference to the calculation manager for species reference-state thermodynamic pr...
virtual void setState_UP(double u, double p, double tol=1e-9)
Set the specific internal energy (J/kg) and pressure (Pa).
virtual void setState_SP(double s, double p, double tol=1e-9)
Set the specific entropy (J/kg/K) and pressure (Pa).
virtual int standardStateConvention() const
This method returns the convention used in specification of the standard state, of which there are cu...
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
virtual void setState_SH(double s, double h, double tol=1e-9)
Set the specific entropy (J/kg/K) and the specific enthalpy (J/kg)
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
virtual std::string type() const
String indicating the thermodynamic model implemented.
doublereal cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
virtual void setState_RP(doublereal rho, doublereal p)
Set the density (kg/m**3) and pressure (Pa) at constant composition.
void setMixtureFraction(double mixFrac, const double *fuelComp, const double *oxComp, ThermoBasis basis=ThermoBasis::molar)
Set the mixture composition according to the mixture fraction = kg fuel / (kg oxidizer + kg fuel)
virtual void resetHf298(const size_t k=npos)
Restore the original heat of formation of one or more species.
virtual void setState_TH(double t, double h, double tol=1e-9)
Set the temperature (K) and the specific enthalpy (J/kg)
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
virtual void setState_Psat(doublereal p, doublereal x)
Set the state to a saturated system at a particular pressure.
std::vector< const XML_Node * > m_speciesData
Vector of pointers to the species databases.
doublereal intEnergy_mass() const
Specific internal energy. Units: J/kg.
virtual void setState_RPX(doublereal rho, doublereal p, const doublereal *x)
Set the density (kg/m**3), pressure (Pa) and mole fractions.
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
doublereal enthalpy_mass() const
Specific enthalpy. Units: J/kg.
double mixtureFraction(const double *fuelComp, const double *oxComp, ThermoBasis basis=ThermoBasis::molar, const std::string &element="Bilger") const
Compute the mixture fraction = kg fuel / (kg oxidizer + kg fuel) for the current mixture given fuel a...
AnyMap m_input
Data supplied via setParameters.
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid.
virtual void reportCSV(std::ofstream &csvFile) const
returns a summary of the state of the phase to a comma separated file.
void setEquivalenceRatio(double phi, const double *fuelComp, const double *oxComp, ThermoBasis basis=ThermoBasis::molar)
Set the mixture composition according to the equivalence ratio.
void setState_TPQ(double T, double P, double Q)
Set the temperature, pressure, and vapor fraction (quality).
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
void setState_conditional_TP(doublereal t, doublereal p, bool set_p)
Helper function used by setState_HPorUV and setState_SPorSV.
virtual void setState_VH(double v, double h, double tol=1e-9)
Set the specific volume (m^3/kg) and the specific enthalpy (J/kg)
doublereal electricPotential() const
Returns the electric potential of this phase (V).
virtual void setState_SV(double s, double v, double tol=1e-9)
Set the specific entropy (J/kg/K) and specific volume (m^3/kg).
const AnyMap & input() const
Access input data associated with the phase description.
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
A representation of the units associated with a dimensional quantity.
Class XML_Node is a tree-based representation of the contents of an XML file.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
void equilibrate(const std::string &XY, const std::string &solver="auto", double rtol=1e-9, int max_steps=50000, int max_iter=100, int estimate_equil=0, int log_level=0)
Equilibrate a ThermoPhase object.
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
const double Faraday
Faraday constant [C/kmol].
XML_Node * get_XML_File(const std::string &file, int debug=0)
Return a pointer to the XML tree for a Cantera input file.
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type="")
Get a floating-point value from a child element.
XML_Node * findXMLPhase(XML_Node *root, const std::string &phaseId)
Search an XML_Node tree for a named phase XML_Node.
std::string getChildValue(const XML_Node &parent, const std::string &nameString)
This function reads a child node with the name, nameString, and returns its XML value as the return s...
void setupPhase(ThermoPhase &phase, const AnyMap &phaseNode, const AnyMap &rootNode=AnyMap())
Initialize a ThermoPhase object.
const int cAC_CONVENTION_MOLAR
const double OneAtm
One atmosphere [Pa].
void warn_deprecated(const std::string &source, const AnyBase &node, const std::string &message)
A deprecation warning for syntax in an input file.
void debuglog(const std::string &msg, int loglevel)
Write a message to the log only if loglevel > 0.
const double SmallNumber
smallest number to compare to zero.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
T clip(const T &value, const T &lower, const T &upper)
Clip value such that lower <= value <= upper.
const int cSS_CONVENTION_TEMPERATURE
ThermoBasis
Differentiate between mole fractions and mass fractions for input mixture composition.
std::map< std::string, double > compositionMap
Map connecting a string name with a double.
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names=std::vector< std::string >())
Parse a composition string into a map consisting of individual key:composition pairs.
Contains declarations for string manipulation functions within Cantera.