27 ThermoPhase::ThermoPhase() :
30 m_chargeNeutralityNecessary(false),
36 ThermoPhase::~ThermoPhase()
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++) {
210 AnyMap state = input_state;
213 if (state.
hasKey(
"mass-fractions")) {
214 state[
"Y"] = state[
"mass-fractions"];
215 state.
erase(
"mass-fractions");
217 if (state.
hasKey(
"mole-fractions")) {
218 state[
"X"] = state[
"mole-fractions"];
219 state.
erase(
"mole-fractions");
221 if (state.
hasKey(
"temperature")) {
222 state[
"T"] = state[
"temperature"];
224 if (state.
hasKey(
"pressure")) {
225 state[
"P"] = state[
"pressure"];
227 if (state.
hasKey(
"enthalpy")) {
228 state[
"H"] = state[
"enthalpy"];
230 if (state.
hasKey(
"int-energy")) {
231 state[
"U"] = state[
"int-energy"];
233 if (state.
hasKey(
"internal-energy")) {
234 state[
"U"] = state[
"internal-energy"];
236 if (state.
hasKey(
"specific-volume")) {
237 state[
"V"] = state[
"specific-volume"];
239 if (state.
hasKey(
"entropy")) {
240 state[
"S"] = state[
"entropy"];
242 if (state.
hasKey(
"density")) {
243 state[
"D"] = state[
"density"];
245 if (state.
hasKey(
"vapor-fraction")) {
246 state[
"Q"] = state[
"vapor-fraction"];
251 if (state[
"X"].is<string>()) {
257 }
else if (state.
hasKey(
"Y")) {
258 if (state[
"Y"].is<string>()) {
266 if (state.
size() == 0) {
269 double T = state.
convert(
"T",
"K");
270 double P = state.
convert(
"P",
"Pa");
306 }
else if (state.
hasKey(
"T")) {
308 }
else if (state.
hasKey(
"P")) {
312 "'state' did not specify a recognized set of properties.\n"
313 "Keys provided were: {}", input_state.
keys_str());
326 double rtol,
bool doUV)
336 "Input specific volume is too small or negative. v = {}", v);
342 "Input pressure is too small or negative. p = {}", p);
355 }
else if (Tnew < Tmin) {
369 bool ignoreBounds =
false;
372 bool unstablePhase =
false;
375 double Tunstable = -1.0;
376 bool unstablePhaseNew =
false;
379 for (
int n = 0; n < 500; n++) {
384 unstablePhase =
true;
388 dt =
clip((Htarget - Hold)/cpd, -100.0, 100.0);
395 if ((dt > 0.0 && unstablePhase) || (dt <= 0.0 && !unstablePhase)) {
396 if (Hbot < Htarget && Tnew < (0.75 * Tbot + 0.25 * Told)) {
397 dt = 0.75 * (Tbot - Told);
400 }
else if (Htop > Htarget && Tnew > (0.75 * Ttop + 0.25 * Told)) {
401 dt = 0.75 * (Ttop - Told);
406 if (Tnew > Tmax && !ignoreBounds) {
409 if (Hmax >= Htarget) {
410 if (Htop < Htarget) {
419 if (Tnew < Tmin && !ignoreBounds) {
422 if (Hmin <= Htarget) {
423 if (Hbot > Htarget) {
436 for (
int its = 0; its < 10; its++) {
438 if (Tnew < Told / 3.0) {
440 dt = -2.0 * Told / 3.0;
451 unstablePhaseNew =
true;
454 unstablePhaseNew =
false;
457 if (unstablePhase ==
false && unstablePhaseNew ==
true) {
462 if (Hnew == Htarget) {
464 }
else if (Hnew > Htarget && (Htop < Htarget || Hnew < Htop)) {
467 }
else if (Hnew < Htarget && (Hbot > Htarget || Hnew > Hbot)) {
472 double Herr = Htarget - Hnew;
473 double acpd = std::max(fabs(cpd), 1.0E-5);
474 double denom = std::max(fabs(Htarget), acpd * Tnew);
475 double HConvErr = fabs((Herr)/denom);
476 if (HConvErr < rtol || fabs(dt/Tnew) < rtol) {
484 string ErrString =
"No convergence in 500 iterations\n";
486 ErrString += fmt::format(
487 "\tTarget Internal Energy = {}\n"
488 "\tCurrent Specific Volume = {}\n"
489 "\tStarting Temperature = {}\n"
490 "\tCurrent Temperature = {}\n"
491 "\tCurrent Internal Energy = {}\n"
492 "\tCurrent Delta T = {}\n",
493 Htarget, v, Tinit, Tnew, Hnew, dt);
495 ErrString += fmt::format(
496 "\tTarget Enthalpy = {}\n"
497 "\tCurrent Pressure = {}\n"
498 "\tStarting Temperature = {}\n"
499 "\tCurrent Temperature = {}\n"
500 "\tCurrent Enthalpy = {}\n"
501 "\tCurrent Delta T = {}\n",
502 Htarget, p, Tinit, Tnew, Hnew, dt);
505 ErrString += fmt::format(
506 "\t - The phase became unstable (Cp < 0) T_unstable_last = {}\n",
510 throw CanteraError(
"ThermoPhase::setState_HPorUV (UV)", ErrString);
512 throw CanteraError(
"ThermoPhase::setState_HPorUV (HP)", ErrString);
528 double rtol,
bool doSV)
536 "Input specific volume is too small or negative. v = {}", v);
542 "Input pressure is too small or negative. p = {}", p);
555 }
else if (Tnew < Tmin) {
569 bool ignoreBounds =
false;
572 bool unstablePhase =
false;
573 double Tunstable = -1.0;
574 bool unstablePhaseNew =
false;
577 for (
int n = 0; n < 500; n++) {
582 unstablePhase =
true;
586 dt =
clip((Starget - Sold)*Told/cpd, -100.0, 100.0);
590 if ((dt > 0.0 && unstablePhase) || (dt <= 0.0 && !unstablePhase)) {
591 if (Sbot < Starget && Tnew < Tbot) {
592 dt = 0.75 * (Tbot - Told);
595 }
else if (Stop > Starget && Tnew > Ttop) {
596 dt = 0.75 * (Ttop - Told);
601 if (Tnew > Tmax && !ignoreBounds) {
604 if (Smax >= Starget) {
605 if (Stop < Starget) {
613 }
else if (Tnew < Tmin && !ignoreBounds) {
616 if (Smin <= Starget) {
617 if (Sbot > Starget) {
630 for (
int its = 0; its < 10; its++) {
636 unstablePhaseNew =
true;
639 unstablePhaseNew =
false;
642 if (unstablePhase ==
false && unstablePhaseNew ==
true) {
647 if (Snew == Starget) {
649 }
else if (Snew > Starget && (Stop < Starget || Snew < Stop)) {
652 }
else if (Snew < Starget && (Sbot > Starget || Snew > Sbot)) {
657 double Serr = Starget - Snew;
658 double acpd = std::max(fabs(cpd), 1.0E-5);
659 double denom = std::max(fabs(Starget), acpd * Tnew);
660 double SConvErr = fabs((Serr * Tnew)/denom);
661 if (SConvErr < rtol || fabs(dt/Tnew) < rtol) {
669 string ErrString =
"No convergence in 500 iterations\n";
671 ErrString += fmt::format(
672 "\tTarget Entropy = {}\n"
673 "\tCurrent Specific Volume = {}\n"
674 "\tStarting Temperature = {}\n"
675 "\tCurrent Temperature = {}\n"
676 "\tCurrent Entropy = {}\n"
677 "\tCurrent Delta T = {}\n",
678 Starget, v, Tinit, Tnew, Snew, dt);
680 ErrString += fmt::format(
681 "\tTarget Entropy = {}\n"
682 "\tCurrent Pressure = {}\n"
683 "\tStarting Temperature = {}\n"
684 "\tCurrent Temperature = {}\n"
685 "\tCurrent Entropy = {}\n"
686 "\tCurrent Delta T = {}\n",
687 Starget, p, Tinit, Tnew, Snew, dt);
690 ErrString += fmt::format(
"\t - The phase became unstable (Cp < 0) T_unstable_last = {}\n",
694 throw CanteraError(
"ThermoPhase::setState_SPorSV (SV)", ErrString);
696 throw CanteraError(
"ThermoPhase::setState_SPorSV (SP)", ErrString);
709 for (
size_t k = 0; k !=
m_kk; ++k) {
713 o2req += x *
nAtoms(k, iC);
716 o2req += x *
nAtoms(k, iS);
719 o2req += x * 0.25 *
nAtoms(k, iH);
724 "No composition specified");
734 for (
size_t k = 0; k !=
m_kk; ++k) {
740 "No composition specified");
742 return 0.5 * o2pres / sum;
755 const std::string& oxComp,
765 const double* oxComp,
769 if (basis == ThermoBasis::molar) {
774 fuelComp = fuel.data();
781 if (o2_required_fuel < 0.0 || o2_required_ox > 0.0) {
783 "Fuel composition contains too much oxygen or "
784 "oxidizer contains not enough oxygen. "
785 "Fuel and oxidizer composition mixed up?");
788 if (o2_required_ox == 0.0) {
789 return std::numeric_limits<double>::infinity();
792 return o2_required_fuel / (-o2_required_ox);
800 "Equivalence ratio phi must be >= 0");
806 if (basis == ThermoBasis::molar) {
811 fuelComp = fuel.data();
817 double sum_f = std::accumulate(fuelComp, fuelComp+
m_kk, 0.0);
818 double sum_o = std::accumulate(oxComp, oxComp+
m_kk, 0.0);
821 for (
size_t k = 0; k !=
m_kk; ++k) {
822 y[k] = phi * fuelComp[k]/sum_f + AFR_st * oxComp[k]/sum_o;
851 if (o2_present == 0.0) {
852 return std::numeric_limits<double>::infinity();
855 return o2_required / o2_present;
868 const std::string& oxComp,
878 const double* oxComp,
888 return std::numeric_limits<double>::infinity();
892 if (basis == ThermoBasis::molar) {
897 fuelComp = fuel.data();
903 return std::max(Z / (1.0 - Z) * AFR_st, 0.0);
926 if (mixFrac < 0.0 || mixFrac > 1.0) {
928 "Mixture fraction must be between 0 and 1");
932 if (basis == ThermoBasis::molar) {
937 fuelComp = fuel.data();
941 double sum_yf = std::accumulate(fuelComp, fuelComp+
m_kk, 0.0);
942 double sum_yo = std::accumulate(oxComp, oxComp+
m_kk, 0.0);
944 if (sum_yf == 0.0 || sum_yo == 0.0) {
946 "No fuel and/or oxidizer composition specified");
953 for (
size_t k = 0; k !=
m_kk; ++k) {
954 y[k] = mixFrac * fuelComp[k]/sum_yf + (1.0-mixFrac) * oxComp[k]/sum_yo;
964 const std::string& element)
const
972 const std::string& oxComp,
974 const std::string& element)
const
983 const double* oxComp,
985 const std::string& element)
const
988 if (basis == ThermoBasis::molar) {
993 fuelComp = fuel.data();
997 if (element ==
"Bilger")
1003 if (o2_required_fuel < 0.0 || o2_required_ox > 0.0) {
1005 "Fuel composition contains too much oxygen or "
1006 "oxidizer contains not enough oxygen. "
1007 "Fuel and oxidizer composition mixed up?");
1010 double denominator = o2_required_fuel - o2_required_ox;
1012 if (denominator == 0.0) {
1014 "Fuel and oxidizer have the same composition");
1017 double Z = (o2_required_mix - o2_required_ox) / denominator;
1019 return std::min(std::max(Z, 0.0), 1.0);
1022 double sum_yf = std::accumulate(fuelComp, fuelComp+
m_kk, 0.0);
1023 double sum_yo = std::accumulate(oxComp, oxComp+
m_kk, 0.0);
1025 if (sum_yf == 0.0 || sum_yo == 0.0) {
1027 "No fuel and/or oxidizer composition specified");
1030 auto elementalFraction = [
this](
size_t m,
const double* y) {
1032 for (
size_t k = 0; k !=
m_kk; ++k) {
1039 double Z_m_fuel = elementalFraction(m, fuelComp)/sum_yf;
1040 double Z_m_ox = elementalFraction(m, oxComp)/sum_yo;
1043 if (Z_m_fuel == Z_m_ox) {
1045 "Fuel and oxidizer have the same composition for element {}",
1048 double Z = (Z_m_mix - Z_m_ox) / (Z_m_fuel - Z_m_ox);
1049 return std::min(std::max(Z, 0.0), 1.0);
1065 const std::string&
id)
1067 size_t dot = inputFile.find_last_of(
".");
1070 extension = inputFile.substr(
dot+1);
1073 if (extension ==
"yml" || extension ==
"yaml") {
1075 auto& phase = root[
"phases"].getMapWhere(
"name",
id);
1082 "ERROR: Can not find phase named {} in file"
1083 " named {}",
id, inputFile);
1101 "Missing species thermo data");
1113 "Temperature ({}), pressure ({}) and vapor fraction ({}) "
1114 "are inconsistent, above the critical temperature.",
1120 if (std::abs(Psat / P - 1) < 1e-6) {
1122 }
else if ((Q == 0 && P >= Psat) || (Q == 1 && P <= Psat)) {
1126 "Temperature ({}), pressure ({}) and vapor fraction ({}) "
1127 "are inconsistent.\nPsat at this T: {}\n"
1128 "Consider specifying the state using two fully independent "
1129 "properties (e.g. temperature and density)",
1136 if (!spec->thermo) {
1138 "Species {} has no thermo data", spec->name);
1142 spec->thermo->validate(spec->name);
1150 if (!spec->thermo) {
1152 "Species {} has no thermo data", spec->name);
1157 "New species '{}' does not match existing species '{}' at index {}",
1160 spec->thermo->validate(spec->name);
1176 "m_speciesData is the wrong size");
1207 if (state.
hasChild(
"temperature")) {
1208 double t =
getFloat(state,
"temperature",
"temperature");
1212 double p =
getFloat(state,
"pressure",
"pressure");
1216 double rho =
getFloat(state,
"density",
"density");
1227 double rtol,
int max_steps,
int max_iter,
1228 int estimate_equil,
int log_level)
1230 if (solver ==
"auto" || solver ==
"element_potential") {
1233 debuglog(
"Trying ChemEquil solver\n", log_level);
1238 int ret = E.
equilibrate(*
this, XY.c_str(), log_level-1);
1241 "ChemEquil solver failed. Return code: {}", ret);
1243 debuglog(
"ChemEquil solver succeeded\n", log_level);
1245 }
catch (std::exception& err) {
1246 debuglog(
"ChemEquil solver failed.\n", log_level);
1249 if (solver ==
"auto") {
1256 if (solver ==
"auto" || solver ==
"vcs" || solver ==
"gibbs") {
1260 M.
equilibrate(XY, solver, rtol, max_steps, max_iter,
1261 estimate_equil, log_level);
1265 if (solver !=
"auto") {
1267 "Invalid solver specified: '{}'", solver);
1273 for (
size_t m = 0; m <
m_kk; m++) {
1274 for (
size_t k = 0; k <
m_kk; k++) {
1275 dlnActCoeffdlnN[ld * k + m] = 0.0;
1281 void ThermoPhase::getdlnActCoeffdlnN_numderiv(
const size_t ld, doublereal*
const dlnActCoeffdlnN)
1283 double deltaMoles_j = 0.0;
1295 double v_totalMoles = 1.0;
1296 double TMoles_base = v_totalMoles;
1299 for (
size_t j = 0; j <
m_kk; j++) {
1305 double moles_j_base = v_totalMoles * Xmol_Base[j];
1306 deltaMoles_j = 1.0E-7 * moles_j_base + v_totalMoles * 1.0E-13 + 1.0E-150;
1310 v_totalMoles = TMoles_base + deltaMoles_j;
1311 for (
size_t k = 0; k <
m_kk; k++) {
1312 Xmol[k] = Xmol_Base[k] * TMoles_base / v_totalMoles;
1314 Xmol[j] = (moles_j_base + deltaMoles_j) / v_totalMoles;
1322 double*
const lnActCoeffCol = dlnActCoeffdlnN + ld * j;
1323 for (
size_t k = 0; k <
m_kk; k++) {
1324 lnActCoeffCol[k] = (2*moles_j_base + deltaMoles_j) *(ActCoeff[k] - ActCoeff_Base[k]) /
1325 ((ActCoeff[k] + ActCoeff_Base[k]) * deltaMoles_j);
1328 v_totalMoles = TMoles_base;
1337 fmt::memory_buffer b;
1339 int name_width = 18;
1341 string blank_leader = fmt::format(
"{:{}}",
"", name_width);
1343 string one_property =
"{:>{}} {:<.5g} {}\n";
1345 string two_prop_header =
"{} {:^15} {:^15}\n";
1346 string kg_kmol_header = fmt::format(
1347 two_prop_header, blank_leader,
"1 kg",
"1 kmol"
1349 string Y_X_header = fmt::format(
1350 two_prop_header, blank_leader,
"mass frac. Y",
"mole frac. X"
1352 string two_prop_sep = fmt::format(
1353 "{} {:-^15} {:-^15}\n", blank_leader,
"",
""
1355 string two_property =
"{:>{}} {:15.5g} {:15.5g} {}\n";
1357 string three_prop_header = fmt::format(
1358 "{} {:^15} {:^15} {:^15}\n", blank_leader,
"mass frac. Y",
1359 "mole frac. X",
"chem. pot. / RT"
1361 string three_prop_sep = fmt::format(
1362 "{} {:-^15} {:-^15} {:-^15}\n", blank_leader,
"",
"",
""
1364 string three_property =
"{:>{}} {:15.5g} {:15.5g} {:15.5g}\n";
1368 format_to(b,
"\n {}:\n",
name());
1371 format_to(b, one_property,
"temperature", name_width,
temperature(),
"K");
1372 format_to(b, one_property,
"pressure", name_width,
pressure(),
"Pa");
1373 format_to(b, one_property,
"density", name_width,
density(),
"kg/m^3");
1374 format_to(b, one_property,
"mean mol. weight", name_width,
meanMolecularWeight(),
"kg/kmol");
1378 format_to(b, one_property,
"potential", name_width, phi,
"V");
1381 format_to(b,
"{:>{}} {}\n",
"phase of matter", name_width,
phaseOfMatter());
1385 format_to(b, kg_kmol_header);
1386 format_to(b, two_prop_sep);
1391 format_to(b, two_property,
"heat capacity c_p", name_width,
cp_mass(),
cp_mole(),
"J/K");
1393 format_to(b, two_property,
"heat capacity c_v", name_width,
cv_mass(),
cv_mole(),
"J/K");
1395 format_to(b,
"{:>{}} <not implemented> \n",
"heat capacity c_v", name_width);
1406 double xMinor = 0.0;
1407 double yMinor = 0.0;
1410 format_to(b, three_prop_header);
1411 format_to(b, three_prop_sep);
1412 for (
size_t k = 0; k <
m_kk; k++) {
1413 if (abs(x[k]) >= threshold) {
1415 format_to(b, three_property,
speciesName(k), name_width, y[k], x[k], mu[k]/
RT());
1417 format_to(b, two_property,
speciesName(k), name_width, y[k], x[k],
"");
1426 format_to(b, Y_X_header);
1427 format_to(b, two_prop_sep);
1428 for (
size_t k = 0; k <
m_kk; k++) {
1429 if (abs(x[k]) >= threshold) {
1430 format_to(b, two_property,
speciesName(k), name_width, y[k], x[k],
"");
1439 string minor = fmt::format(
"[{:+5d} minor]", nMinor);
1440 format_to(b, two_property, minor, name_width, yMinor, xMinor,
"");
1443 return to_string(b) + err.
what();
1445 return to_string(b);
1452 csvFile.precision(8);
1455 std::vector<std::string> pNames;
1456 std::vector<vector_fp> data;
1459 csvFile << setw(tabS) <<
"Species,";
1460 for (
size_t i = 0; i < pNames.size(); i++) {
1461 csvFile << setw(tabM) << pNames[i] <<
",";
1464 for (
size_t k = 0; k <
nSpecies(); k++) {
1467 for (
size_t i = 0; i < pNames.size(); i++) {
1468 csvFile << setw(tabM) << data[i][k] <<
",";
1472 for (
size_t i = 0; i < pNames.size(); i++) {
1473 csvFile << setw(tabM) << 0 <<
",";
1481 std::vector<vector_fp>& data)
const
1486 names.push_back(
"X");
1489 names.push_back(
"Y");
1492 names.push_back(
"Chem. Pot (J/kmol)");
1495 names.push_back(
"Activity");
1498 names.push_back(
"Act. Coeff.");
1501 names.push_back(
"Part. Mol Enthalpy (J/kmol)");
1504 names.push_back(
"Part. Mol. Entropy (J/K/kmol)");
1507 names.push_back(
"Part. Mol. Energy (J/kmol)");
1510 names.push_back(
"Part. Mol. Cp (J/K/kmol");
1513 names.push_back(
"Part. Mol. Cv (J/K/kmol)");
Headers for the MultiPhase object that is used to set up multiphase equilibrium problems (see Equilfu...
Pure Virtual Base class for individual species reference state thermodynamic managers and text for th...
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.
std::string keys_str() const
Return a string listing the keys in this AnyMap, e.g.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
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(thermo_t &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.
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.
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.
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.
const double * massFractions() const
Return a const pointer to the mass fraction array.
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
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.
virtual double density() const
Density (kg/m^3).
doublereal temperature() const
Temperature (K).
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.
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
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).
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...
virtual 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.
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.
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.
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.
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
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 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.
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.
const size_t npos
index returned by functions to indicate "no position"
const double Faraday
Faraday constant [C/kmol].
const double OneAtm
One atmosphere [Pa].
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.
std::map< std::string, double > compositionMap
Map connecting a string name with a double.
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Namespace for the Cantera kernel.
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...
const int cAC_CONVENTION_MOLAR
Standard state uses the molar convention.
void setupPhase(ThermoPhase &thermo, AnyMap &phaseNode, const AnyMap &rootNode)
Initialize a ThermoPhase object.
const int cSS_CONVENTION_TEMPERATURE
Standard state uses the molar convention.
ThermoBasis
Differentiate between mole fractions and mass fractions for input mixture composition.
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names)
Parse a composition string into a map consisting of individual key:composition pairs.
Contains declarations for string manipulation functions within Cantera.