32 vector<AnyMap> speciesDefs;
35 speciesDefs.emplace_back(
species(
name)->parameters(
this));
37 root[
"species"] = std::move(speciesDefs);
47 for (
size_t k = 0; k <
nSpecies(); k++) {
67 return Units(1.0, 0, -
static_cast<double>(
nDim()), 0, 0, 0, 1);
78 for (
size_t k = 0; k <
nSpecies(); k++) {
86 for (
size_t k = 0; k <
m_kk; k++) {
87 lnac[k] = std::log(lnac[k]);
95 for (
size_t k = 0; k <
m_kk; k++) {
143 }
catch (std::exception&) {
155 }
catch (std::exception&) {
168 }
catch (std::exception&) {
176 AnyMap state = input_state;
179 if (state.
hasKey(
"mass-fractions")) {
180 state[
"Y"] = state[
"mass-fractions"];
181 state.
erase(
"mass-fractions");
183 if (state.
hasKey(
"mole-fractions")) {
184 state[
"X"] = state[
"mole-fractions"];
185 state.
erase(
"mole-fractions");
187 if (state.
hasKey(
"temperature")) {
188 state[
"T"] = state[
"temperature"];
190 if (state.
hasKey(
"pressure")) {
191 state[
"P"] = state[
"pressure"];
193 if (state.
hasKey(
"enthalpy")) {
194 state[
"H"] = state[
"enthalpy"];
196 if (state.
hasKey(
"int-energy")) {
197 state[
"U"] = state[
"int-energy"];
199 if (state.
hasKey(
"internal-energy")) {
200 state[
"U"] = state[
"internal-energy"];
202 if (state.
hasKey(
"specific-volume")) {
203 state[
"V"] = state[
"specific-volume"];
205 if (state.
hasKey(
"entropy")) {
206 state[
"S"] = state[
"entropy"];
208 if (state.
hasKey(
"density")) {
209 state[
"D"] = state[
"density"];
211 if (state.
hasKey(
"vapor-fraction")) {
212 state[
"Q"] = state[
"vapor-fraction"];
217 if (state[
"X"].is<string>()) {
223 }
else if (state.
hasKey(
"Y")) {
224 if (state[
"Y"].is<string>()) {
232 if (state.
size() == 0) {
235 double T = state.
convert(
"T",
"K");
236 double P = state.
convert(
"P",
"Pa");
272 }
else if (state.
hasKey(
"T")) {
274 }
else if (state.
hasKey(
"P")) {
278 "'state' did not specify a recognized set of properties.\n"
279 "Keys provided were: {}", input_state.
keys_str());
292 double rtol,
bool doUV)
302 "Input specific volume is too small or negative. v = {}", v);
308 "Input pressure is too small or negative. p = {}", p);
321 }
else if (Tnew < Tmin) {
335 bool ignoreBounds =
false;
338 bool unstablePhase =
false;
341 double Tunstable = -1.0;
342 bool unstablePhaseNew =
false;
345 for (
int n = 0; n < 500; n++) {
350 unstablePhase =
true;
354 dt =
clip((Htarget - Hold)/cpd, -100.0, 100.0);
361 if ((dt > 0.0 && unstablePhase) || (dt <= 0.0 && !unstablePhase)) {
362 if (Hbot < Htarget && Tnew < (0.75 * Tbot + 0.25 * Told)) {
363 dt = 0.75 * (Tbot - Told);
366 }
else if (Htop > Htarget && Tnew > (0.75 * Ttop + 0.25 * Told)) {
367 dt = 0.75 * (Ttop - Told);
372 if (Tnew > Tmax && !ignoreBounds) {
375 if (Hmax >= Htarget) {
376 if (Htop < Htarget) {
385 if (Tnew < Tmin && !ignoreBounds) {
388 if (Hmin <= Htarget) {
389 if (Hbot > Htarget) {
402 for (
int its = 0; its < 10; its++) {
404 if (Tnew < Told / 3.0) {
406 dt = -2.0 * Told / 3.0;
417 unstablePhaseNew =
true;
420 unstablePhaseNew =
false;
423 if (unstablePhase ==
false && unstablePhaseNew ==
true) {
428 if (Hnew == Htarget) {
430 }
else if (Hnew > Htarget && (Htop < Htarget || Hnew < Htop)) {
433 }
else if (Hnew < Htarget && (Hbot > Htarget || Hnew > Hbot)) {
438 double Herr = Htarget - Hnew;
439 double acpd = std::max(fabs(cpd), 1.0E-5);
440 double denom = std::max(fabs(Htarget), acpd * Tnew);
441 double HConvErr = fabs((Herr)/denom);
442 if (HConvErr < rtol || fabs(dt/Tnew) < rtol) {
450 string ErrString =
"No convergence in 500 iterations\n";
452 ErrString += fmt::format(
453 "\tTarget Internal Energy = {}\n"
454 "\tCurrent Specific Volume = {}\n"
455 "\tStarting Temperature = {}\n"
456 "\tCurrent Temperature = {}\n"
457 "\tCurrent Internal Energy = {}\n"
458 "\tCurrent Delta T = {}\n",
459 Htarget, v, Tinit, Tnew, Hnew, dt);
461 ErrString += fmt::format(
462 "\tTarget Enthalpy = {}\n"
463 "\tCurrent Pressure = {}\n"
464 "\tStarting Temperature = {}\n"
465 "\tCurrent Temperature = {}\n"
466 "\tCurrent Enthalpy = {}\n"
467 "\tCurrent Delta T = {}\n",
468 Htarget, p, Tinit, Tnew, Hnew, dt);
471 ErrString += fmt::format(
472 "\t - The phase became unstable (Cp < 0) T_unstable_last = {}\n",
476 throw CanteraError(
"ThermoPhase::setState_HPorUV (UV)", ErrString);
478 throw CanteraError(
"ThermoPhase::setState_HPorUV (HP)", ErrString);
488 }
catch (std::exception&) {
501 }
catch (std::exception&) {
508 double rtol,
bool doSV)
516 "Input specific volume is too small or negative. v = {}", v);
522 "Input pressure is too small or negative. p = {}", p);
535 }
else if (Tnew < Tmin) {
549 bool ignoreBounds =
false;
552 bool unstablePhase =
false;
553 double Tunstable = -1.0;
554 bool unstablePhaseNew =
false;
557 for (
int n = 0; n < 500; n++) {
562 unstablePhase =
true;
566 dt =
clip((Starget - Sold)*Told/cpd, -100.0, 100.0);
570 if ((dt > 0.0 && unstablePhase) || (dt <= 0.0 && !unstablePhase)) {
571 if (Sbot < Starget && Tnew < Tbot) {
572 dt = 0.75 * (Tbot - Told);
575 }
else if (Stop > Starget && Tnew > Ttop) {
576 dt = 0.75 * (Ttop - Told);
581 if (Tnew > Tmax && !ignoreBounds) {
584 if (Smax >= Starget) {
585 if (Stop < Starget) {
593 }
else if (Tnew < Tmin && !ignoreBounds) {
596 if (Smin <= Starget) {
597 if (Sbot > Starget) {
610 for (
int its = 0; its < 10; its++) {
616 unstablePhaseNew =
true;
619 unstablePhaseNew =
false;
622 if (unstablePhase ==
false && unstablePhaseNew ==
true) {
627 if (Snew == Starget) {
629 }
else if (Snew > Starget && (Stop < Starget || Snew < Stop)) {
632 }
else if (Snew < Starget && (Sbot > Starget || Snew > Sbot)) {
637 double Serr = Starget - Snew;
638 double acpd = std::max(fabs(cpd), 1.0E-5);
639 double denom = std::max(fabs(Starget), acpd * Tnew);
640 double SConvErr = fabs((Serr * Tnew)/denom);
641 if (SConvErr < rtol || fabs(dt/Tnew) < rtol) {
649 string ErrString =
"No convergence in 500 iterations\n";
651 ErrString += fmt::format(
652 "\tTarget Entropy = {}\n"
653 "\tCurrent Specific Volume = {}\n"
654 "\tStarting Temperature = {}\n"
655 "\tCurrent Temperature = {}\n"
656 "\tCurrent Entropy = {}\n"
657 "\tCurrent Delta T = {}\n",
658 Starget, v, Tinit, Tnew, Snew, dt);
660 ErrString += fmt::format(
661 "\tTarget Entropy = {}\n"
662 "\tCurrent Pressure = {}\n"
663 "\tStarting Temperature = {}\n"
664 "\tCurrent Temperature = {}\n"
665 "\tCurrent Entropy = {}\n"
666 "\tCurrent Delta T = {}\n",
667 Starget, p, Tinit, Tnew, Snew, dt);
670 ErrString += fmt::format(
"\t - The phase became unstable (Cp < 0) T_unstable_last = {}\n",
674 throw CanteraError(
"ThermoPhase::setState_SPorSV (SV)", ErrString);
676 throw CanteraError(
"ThermoPhase::setState_SPorSV (SP)", ErrString);
689 for (
size_t k = 0; k !=
m_kk; ++k) {
693 o2req += x *
nAtoms(k, iC);
696 o2req += x *
nAtoms(k, iS);
699 o2req += x * 0.25 *
nAtoms(k, iH);
704 "No composition specified");
714 for (
size_t k = 0; k !=
m_kk; ++k) {
720 "No composition specified");
722 return 0.5 * o2pres / sum;
738 parseCompString(fuelComp.find(
":") != string::npos ? fuelComp : fuelComp+
":1.0"),
739 parseCompString(oxComp.find(
":") != string::npos ? oxComp : oxComp+
":1.0"),
744 const double* oxComp,
747 vector<double> fuel, ox;
748 if (basis == ThermoBasis::molar) {
753 fuelComp = fuel.data();
760 if (o2_required_fuel < 0.0 || o2_required_ox > 0.0) {
762 "Fuel composition contains too much oxygen or "
763 "oxidizer contains not enough oxygen. "
764 "Fuel and oxidizer composition mixed up?");
767 if (o2_required_ox == 0.0) {
768 return std::numeric_limits<double>::infinity();
771 return o2_required_fuel / (-o2_required_ox);
779 "Equivalence ratio phi must be >= 0");
784 vector<double> fuel, ox;
785 if (basis == ThermoBasis::molar) {
790 fuelComp = fuel.data();
796 double sum_f = std::accumulate(fuelComp, fuelComp+
m_kk, 0.0);
797 double sum_o = std::accumulate(oxComp, oxComp+
m_kk, 0.0);
799 vector<double> y(
m_kk);
800 for (
size_t k = 0; k !=
m_kk; ++k) {
801 y[k] = phi * fuelComp[k]/sum_f + AFR_st * oxComp[k]/sum_o;
812 parseCompString(fuelComp.find(
":") != string::npos ? fuelComp : fuelComp+
":1.0"),
813 parseCompString(oxComp.find(
":") != string::npos ? oxComp : oxComp+
":1.0"),
830 if (o2_present == 0.0) {
831 return std::numeric_limits<double>::infinity();
834 return o2_required / o2_present;
850 parseCompString(fuelComp.find(
":") != string::npos ? fuelComp : fuelComp+
":1.0"),
851 parseCompString(oxComp.find(
":") != string::npos ? oxComp : oxComp+
":1.0"),
856 const double* oxComp,
866 return std::numeric_limits<double>::infinity();
869 vector<double> fuel, ox;
870 if (basis == ThermoBasis::molar) {
875 fuelComp = fuel.data();
881 return std::max(Z / (1.0 - Z) * AFR_st, 0.0);
896 parseCompString(fuelComp.find(
":") != string::npos ? fuelComp : fuelComp+
":1.0"),
897 parseCompString(oxComp.find(
":") != string::npos ? oxComp : oxComp+
":1.0"),
904 if (mixFrac < 0.0 || mixFrac > 1.0) {
906 "Mixture fraction must be between 0 and 1");
909 vector<double> fuel, ox;
910 if (basis == ThermoBasis::molar) {
915 fuelComp = fuel.data();
919 double sum_yf = std::accumulate(fuelComp, fuelComp+
m_kk, 0.0);
920 double sum_yo = std::accumulate(oxComp, oxComp+
m_kk, 0.0);
922 if (sum_yf == 0.0 || sum_yo == 0.0) {
924 "No fuel and/or oxidizer composition specified");
929 vector<double> y(
m_kk);
931 for (
size_t k = 0; k !=
m_kk; ++k) {
932 y[k] = mixFrac * fuelComp[k]/sum_yf + (1.0-mixFrac) * oxComp[k]/sum_yo;
942 const string& element)
const
953 parseCompString(fuelComp.find(
":") != string::npos ? fuelComp : fuelComp+
":1.0"),
954 parseCompString(oxComp.find(
":") != string::npos ? oxComp : oxComp+
":1.0"),
961 vector<double> fuel, ox;
962 if (basis == ThermoBasis::molar) {
967 fuelComp = fuel.data();
971 if (element ==
"Bilger")
977 if (o2_required_fuel < 0.0 || o2_required_ox > 0.0) {
979 "Fuel composition contains too much oxygen or "
980 "oxidizer contains not enough oxygen. "
981 "Fuel and oxidizer composition mixed up?");
984 double denominator = o2_required_fuel - o2_required_ox;
986 if (denominator == 0.0) {
988 "Fuel and oxidizer have the same composition");
991 double Z = (o2_required_mix - o2_required_ox) / denominator;
993 return std::min(std::max(Z, 0.0), 1.0);
996 double sum_yf = std::accumulate(fuelComp, fuelComp+
m_kk, 0.0);
997 double sum_yo = std::accumulate(oxComp, oxComp+
m_kk, 0.0);
999 if (sum_yf == 0.0 || sum_yo == 0.0) {
1001 "No fuel and/or oxidizer composition specified");
1004 auto elementalFraction = [
this](
size_t m,
const double* y) {
1006 for (
size_t k = 0; k !=
m_kk; ++k) {
1013 double Z_m_fuel = elementalFraction(m, fuelComp)/sum_yf;
1014 double Z_m_ox = elementalFraction(m, oxComp)/sum_yo;
1017 if (Z_m_fuel == Z_m_ox) {
1019 "Fuel and oxidizer have the same composition for element {}",
1022 double Z = (Z_m_mix - Z_m_ox) / (Z_m_fuel - Z_m_ox);
1023 return std::min(std::max(Z, 0.0), 1.0);
1040 if (inputFile.empty()) {
1044 size_t dot = inputFile.find_last_of(
".");
1047 extension = inputFile.substr(
dot+1);
1049 if (extension ==
"xml" || extension ==
"cti") {
1051 "The CTI and XML formats are no longer supported.");
1055 auto& phase =
root[
"phases"].getMapWhere(
"name",
id);
1064 "Missing species thermo data");
1076 "Temperature ({}), pressure ({}) and vapor fraction ({}) "
1077 "are inconsistent, above the critical temperature.",
1083 if (std::abs(Psat / P - 1) < 1e-6) {
1085 }
else if ((Q == 0 && P >= Psat) || (Q == 1 && P <= Psat)) {
1089 "Temperature ({}), pressure ({}) and vapor fraction ({}) "
1090 "are inconsistent.\nPsat at this T: {}\n"
1091 "Consider specifying the state using two fully independent "
1092 "properties (for example, temperature and density)",
1099 if (!spec->thermo) {
1101 "Species {} has no thermo data", spec->name);
1105 spec->thermo->validate(spec->name);
1113 if (!spec->thermo) {
1115 "Species {} has no thermo data", spec->name);
1120 "New species '{}' does not match existing species '{}' at index {}",
1123 spec->thermo->validate(spec->name);
1144 phaseNode[
"name"] =
name();
1147 for (
size_t i = 0; i <
nElements(); i++) {
1155 if (stateVars.count(
"T")) {
1159 if (stateVars.count(
"D")) {
1160 state[
"density"].setQuantity(
density(),
"kg/m^3");
1161 }
else if (stateVars.count(
"P")) {
1162 state[
"P"].setQuantity(
pressure(),
"Pa");
1165 if (stateVars.count(
"Y")) {
1166 map<string, double> Y;
1167 for (
size_t k = 0; k <
m_kk; k++) {
1175 }
else if (stateVars.count(
"X")) {
1176 map<string, double> X;
1177 for (
size_t k = 0; k <
m_kk; k++) {
1187 phaseNode[
"state"] = std::move(state);
1191 phaseNode[
"__type__"] =
"Phase";
1211 double rtol,
int max_steps,
int max_iter,
1212 int estimate_equil,
int log_level)
1214 if (solver ==
"auto" || solver ==
"element_potential") {
1215 vector<double> initial_state;
1217 debuglog(
"Trying ChemEquil solver\n", log_level);
1222 int ret = E.
equilibrate(*
this, XY.c_str(), log_level-1);
1225 "ChemEquil solver failed. Return code: {}", ret);
1227 debuglog(
"ChemEquil solver succeeded\n", log_level);
1229 }
catch (std::exception& err) {
1230 debuglog(
"ChemEquil solver failed.\n", log_level);
1233 if (solver ==
"auto") {
1240 if (solver ==
"auto" || solver ==
"vcs" || solver ==
"gibbs") {
1244 M.
equilibrate(XY, solver, rtol, max_steps, max_iter,
1245 estimate_equil, log_level);
1249 if (solver !=
"auto") {
1251 "Invalid solver specified: '{}'", solver);
1257 for (
size_t m = 0; m <
m_kk; m++) {
1258 for (
size_t k = 0; k <
m_kk; k++) {
1259 dlnActCoeffdlnN[ld * k + m] = 0.0;
1265void ThermoPhase::getdlnActCoeffdlnN_numderiv(
const size_t ld,
1266 double*
const dlnActCoeffdlnN)
1268 double deltaMoles_j = 0.0;
1272 vector<double> ActCoeff_Base(
m_kk);
1274 vector<double> Xmol_Base(
m_kk);
1278 vector<double> ActCoeff(
m_kk);
1279 vector<double> Xmol(
m_kk);
1280 double v_totalMoles = 1.0;
1281 double TMoles_base = v_totalMoles;
1284 for (
size_t j = 0; j <
m_kk; j++) {
1290 double moles_j_base = v_totalMoles * Xmol_Base[j];
1291 deltaMoles_j = 1.0E-7 * moles_j_base + v_totalMoles * 1.0E-13 + 1.0E-150;
1295 v_totalMoles = TMoles_base + deltaMoles_j;
1296 for (
size_t k = 0; k <
m_kk; k++) {
1297 Xmol[k] = Xmol_Base[k] * TMoles_base / v_totalMoles;
1299 Xmol[j] = (moles_j_base + deltaMoles_j) / v_totalMoles;
1307 double*
const lnActCoeffCol = dlnActCoeffdlnN + ld * j;
1308 for (
size_t k = 0; k <
m_kk; k++) {
1309 lnActCoeffCol[k] = (2*moles_j_base + deltaMoles_j) *(ActCoeff[k] - ActCoeff_Base[k]) /
1310 ((ActCoeff[k] + ActCoeff_Base[k]) * deltaMoles_j);
1313 v_totalMoles = TMoles_base;
1322 if (
type() ==
"none") {
1324 "Not implemented for thermo model 'none'");
1327 fmt::memory_buffer b;
1329 int name_width = 18;
1331 string blank_leader = fmt::format(
"{:{}}",
"", name_width);
1333 string string_property = fmt::format(
"{{:>{}}} {{}}\n", name_width);
1335 string one_property = fmt::format(
"{{:>{}}} {{:<.5g}} {{}}\n", name_width);
1337 constexpr auto two_prop_header =
"{} {:^15} {:^15}\n";
1338 string kg_kmol_header = fmt::format(
1339 two_prop_header, blank_leader,
"1 kg",
"1 kmol"
1341 string Y_X_header = fmt::format(
1342 two_prop_header, blank_leader,
"mass frac. Y",
"mole frac. X"
1344 string two_prop_sep = fmt::format(
1345 "{} {:-^15} {:-^15}\n", blank_leader,
"",
""
1347 string two_property = fmt::format(
1348 "{{:>{}}} {{:15.5g}} {{:15.5g}} {{}}\n", name_width
1351 string three_prop_header = fmt::format(
1352 "{} {:^15} {:^15} {:^15}\n", blank_leader,
"mass frac. Y",
1353 "mole frac. X",
"chem. pot. / RT"
1355 string three_prop_sep = fmt::format(
1356 "{} {:-^15} {:-^15} {:-^15}\n", blank_leader,
"",
"",
""
1358 string three_property = fmt::format(
1359 "{{:>{}}} {{:15.5g}} {{:15.5g}} {{:15.5g}}\n", name_width
1364 fmt_append(b,
"\n {}:\n",
name());
1366 fmt_append(b,
"\n");
1367 fmt_append(b, one_property,
"temperature",
temperature(),
"K");
1368 fmt_append(b, one_property,
"pressure",
pressure(),
"Pa");
1369 fmt_append(b, one_property,
"density",
density(),
"kg/m^3");
1370 fmt_append(b, one_property,
1375 fmt_append(b, one_property,
"potential", phi,
"V");
1378 fmt_append(b, string_property,
"phase of matter",
phaseOfMatter());
1381 fmt_append(b,
"\n");
1382 fmt_append(b, kg_kmol_header);
1383 fmt_append(b, two_prop_sep);
1384 fmt_append(b, two_property,
1386 fmt_append(b, two_property,
1388 fmt_append(b, two_property,
1390 fmt_append(b, two_property,
1392 fmt_append(b, two_property,
1395 fmt_append(b, two_property,
1398 fmt_append(b, string_property,
1399 "heat capacity c_v",
"<not implemented>");
1403 vector<double> x(
m_kk);
1404 vector<double> y(
m_kk);
1405 vector<double> mu(
m_kk);
1410 double xMinor = 0.0;
1411 double yMinor = 0.0;
1412 fmt_append(b,
"\n");
1414 fmt_append(b, three_prop_header);
1415 fmt_append(b, three_prop_sep);
1416 for (
size_t k = 0; k <
m_kk; k++) {
1417 if (abs(x[k]) >= threshold) {
1419 fmt_append(b, three_property,
1422 fmt_append(b, two_property,
speciesName(k), y[k], x[k],
"");
1431 fmt_append(b, Y_X_header);
1432 fmt_append(b, two_prop_sep);
1433 for (
size_t k = 0; k <
m_kk; k++) {
1434 if (abs(x[k]) >= threshold) {
1435 fmt_append(b, two_property,
speciesName(k), y[k], x[k],
"");
1444 string minor = fmt::format(
"[{:+5d} minor]", nMinor);
1445 fmt_append(b, two_property, minor, yMinor, xMinor,
"");
1448 return to_string(b) + err.
what();
1450 return to_string(b);
Headers for the MultiPhase object that is used to set up multiphase equilibrium problems (see Chemica...
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.
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
void applyUnits()
Use the supplied UnitSystem to set the default units, and recursively process overrides from nodes na...
double convert(const string &key, const string &units) const
Convert the item stored by the given key to the units specified in units.
void setFlowStyle(bool flow=true)
Use "flow" style when outputting this AnyMap to YAML.
void erase(const string &key)
Erase the value held by key.
static AnyMap fromYamlFile(const string &name, const string &parent_name="")
Create an AnyMap from a YAML file.
void update(const AnyMap &other, bool keepExisting=true)
Add items from other to this AnyMap.
static bool addOrderingRules(const string &objectType, const vector< vector< string > > &specs)
Add global rules for setting the order of elements when outputting AnyMap objects to YAML.
string keys_str() const
Return a string listing the keys in this AnyMap, for use in error messages, for example.
Base class for exceptions thrown by Cantera classes.
const char * what() const override
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)
Equilibrate a phase, holding the elemental composition fixed at the initial value found within the Th...
EquilOpt options
Options controlling how the calculation is carried out.
double relTolerance
Relative tolerance.
int maxIterations
Maximum number of iterations.
string canonicalize(const 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(shared_ptr< ThermoPhase > p, double 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.
void assertCompressible(const string &setter) const
Ensure that phase is compressible.
void restoreState(const vector< double > &state)
Restore a state saved on a previous call to saveState.
virtual void restorePartialState(size_t lenstate, const double *state)
Set the internal thermodynamic state of the phase, excluding composition.
size_t nSpecies() const
Returns the number of species in the phase.
virtual void setMassFractions_NoNorm(const double *const y)
Set the mass fractions to the specified values without normalizing.
virtual map< string, size_t > nativeState() const
Return a map of properties defining the native state of a substance.
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 setState_TD(double t, double rho)
Set the internally stored temperature (K) and density (kg/m^3)
double temperature() const
Temperature (K).
virtual void setPressure(double p)
Set the internally stored pressure (Pa) at constant temperature and composition.
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
void moleFractionsToMassFractions(const double *X, double *Y) const
Converts a mixture composition from mass fractions to mole fractions.
void saveState(vector< double > &state) const
Save the current internal state of the phase.
size_t elementIndex(const string &name) const
Return the index of element named 'name'.
void setMassFractionsByName(const Composition &yMap)
Set the species mass fractions by name.
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.
vector< double > getCompositionFromMap(const Composition &comp) const
Converts a Composition to a vector with entries for each species Species that are not specified are s...
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
void setMoleFractionsByName(const Composition &xMap)
Set the species mole fractions by name.
const double * massFractions() const
Return a const pointer to the mass fraction array.
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
double moleFraction(size_t k) const
Return the mole fraction of a single species.
const vector< string > & elementNames() const
Return a read-only reference to the vector of element names.
virtual double density() const
Density (kg/m^3).
double nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
size_t nElements() const
Number of elements.
virtual void savePartialState(size_t lenstate, double *state) const
Save the current thermodynamic state of the phase, excluding composition.
virtual void setMassFractions(const double *const y)
Set the mass fractions to the specified values and normalize them.
const vector< string > & speciesNames() const
Return a const reference to the vector of species names.
double molecularWeight(size_t k) const
Molecular weight of species k.
shared_ptr< Species > species(const string &name) const
Return the Species object for the named species.
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
void getMassFractions(double *const y) const
Get the species mass fractions.
virtual size_t partialStateSize() const
Get the size of the partial state vector of the phase.
virtual double pressure() const
Return the thermodynamic pressure (Pa).
string elementName(size_t m) const
Name of the element with index m.
double charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
string name() const
Return the name of the phase.
static ThermoFactory * factory()
Static function that creates a static instance of the factory.
int m_ssConvention
Contains the standard state convention.
virtual double critTemperature() const
Critical temperature (K).
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.
double electricPotential() const
Returns the electric potential of this phase (V).
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 double cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
double equivalenceRatio() const
Compute the equivalence ratio for the current mixture from available oxygen and required oxygen.
virtual void setParameters(const AnyMap &phaseNode, const AnyMap &rootNode=AnyMap())
Set equation of state parameters from an AnyMap phase description.
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
virtual double enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
virtual void setState_TP(double t, double p)
Set the temperature (K) and pressure (Pa)
virtual double standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
virtual void setState_TV(double t, double v, double tol=1e-9)
Set the temperature (K) and specific volume (m^3/kg).
virtual double logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
double o2Present(const double *y) const
Helper function for computing the amount of oxygen available in the current mixture.
virtual void setState_PV(double p, double v, double tol=1e-9)
Set the pressure (Pa) and specific volume (m^3/kg).
virtual void setState(const AnyMap &state)
Set the state using an AnyMap containing any combination of properties supported by the thermodynamic...
virtual double minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid.
virtual void setState_TPX(double t, double p, const double *x)
Set the temperature (K), pressure (Pa), and mole fractions.
void setState_SPorSV(double s, double p, double tol=1e-9, bool doSV=false)
Carry out work in SP and SV calculations.
double RT() const
Return the Gas Constant multiplied by the current temperature.
virtual double critPressure() const
Critical pressure (Pa).
virtual void setState_TPY(double t, double p, const double *y)
Set the internally stored temperature (K), pressure (Pa), and mass fractions of the phase.
double m_tlast
last value of the temperature processed by reference state
virtual void setState_ST(double s, double t, double tol=1e-9)
Set the specific entropy (J/kg/K) and temperature (K).
void setState_HPorUV(double h, double p, double tol=1e-9, bool doUV=false)
Carry out work in HP and UV calculations.
double gibbs_mass() const
Specific Gibbs function. Units: J/kg.
virtual void getActivityConcentrations(double *c) const
This method returns an array of generalized concentrations.
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...
string type() const override
String indicating the thermodynamic model implemented.
AnyMap parameters(bool withInput=true) const
Returns the parameters of a ThermoPhase object such that an identical one could be reconstructed usin...
virtual string report(bool show_thermo=true, double threshold=-1e-14) const
returns a summary of the state of the phase as a string
virtual double maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
double mixtureFraction(const double *fuelComp, const double *oxComp, ThermoBasis basis=ThermoBasis::molar, const string &element="Bilger") const
Compute the mixture fraction = kg fuel / (kg oxidizer + kg fuel) for the current mixture given fuel a...
double o2Required(const double *y) const
Helper function for computing the amount of oxygen required for complete oxidation.
void getElectrochemPotentials(double *mu) const
Get the species electrochemical potentials.
virtual void getdlnActCoeffdlnN(const size_t ld, double *const dlnActCoeffdlnN)
Get the array of derivatives of the log activity coefficients with respect to the log of the species ...
virtual void getActivityCoefficients(double *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
virtual string phaseOfMatter() const
String indicating the mechanical phase of the matter in this Phase.
virtual void setState_Tsat(double t, double x)
Set the state to a saturated system at a particular temperature.
virtual double entropy_mole() const
Molar entropy. Units: J/kmol/K.
double cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
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.
double entropy_mass() const
Specific entropy. Units: J/kg/K.
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).
void initThermoFile(const string &inputFile, const string &id)
Initialize a ThermoPhase object using an input file.
shared_ptr< Solution > root() const
Get the Solution object containing this ThermoPhase object and linked Kinetics and Transport objects.
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...
void modifySpecies(size_t k, shared_ptr< Species > spec) override
Modify the thermodynamic data associated with a species.
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 invalidateCache() override
Invalidate any cached values which are normally updated only when a change in state is detected.
virtual void getActivities(double *a) const
Get the array of non-dimensional activities at the current solution temperature, pressure,...
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 getChemPotentials(double *mu) const
Get the species chemical potentials. Units: J/kmol.
double cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
virtual void setState_TH(double t, double h, double tol=1e-9)
Set the temperature (K) and the specific enthalpy (J/kg)
virtual void getLnActivityCoefficients(double *lnac) const
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
double intEnergy_mass() const
Specific internal energy. Units: J/kg.
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
virtual double cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
virtual double satPressure(double t)
Return the saturation pressure given the temperature.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
AnyMap m_input
Data supplied via setParameters.
virtual double intEnergy_mole() const
Molar internal energy. Units: J/kmol.
virtual void setState_DP(double rho, double p)
Set the density (kg/m**3) and pressure (Pa) at constant composition.
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 setState_VH(double v, double h, double tol=1e-9)
Set the specific volume (m^3/kg) and the specific enthalpy (J/kg)
virtual double gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
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 setState_Psat(double p, double x)
Set the state to a saturated system at a particular pressure.
void setState_conditional_TP(double t, double p, bool set_p)
Helper function used by setState_HPorUV and setState_SPorSV.
shared_ptr< ThermoPhase > clone() const
Create a new ThermoPhase object using the same species definitions, thermodynamic parameters,...
double enthalpy_mass() const
Specific enthalpy. Units: J/kg.
A representation of the units associated with a dimensional quantity.
Composition parseCompString(const string &ss, const vector< string > &names)
Parse a composition string into a map consisting of individual key:composition pairs.
void equilibrate(const string &XY, const 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 debuglog(const string &msg, int loglevel)
Write a message to the log only if loglevel > 0.
double dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
T clip(const T &value, const T &lower, const T &upper)
Clip value such that lower <= value <= upper.
const double Faraday
Faraday constant [C/kmol].
const double OneAtm
One atmosphere [Pa].
shared_ptr< ThermoPhase > newThermo(const AnyMap &phaseNode, const AnyMap &rootNode)
Create a new ThermoPhase object and initialize it.
void setupPhase(ThermoPhase &thermo, const AnyMap &phaseNode, const AnyMap &rootNode)
Initialize a ThermoPhase object.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
const int cAC_CONVENTION_MOLAR
Standard state uses the molar convention.
const double SmallNumber
smallest number to compare to zero.
ThermoBasis
Differentiate between mole fractions and mass fractions for input mixture composition.
map< string, double > Composition
Map from string names to doubles.
Contains declarations for string manipulation functions within Cantera.