24 MixtureFugacityTP::MixtureFugacityTP() :
29 forcedState_(FLUID_UNDEFINED),
44 forcedState_(FLUID_UNDEFINED),
112 throw CanteraError(
"MixtureFugacityTP",
"Base class method "
124 doublereal invRT = 1.0 /
_RT();
125 for (
size_t k = 0; k <
m_kk; k++) {
138 doublereal RT =
_RT();
140 for (
size_t k = 0; k <
m_kk; k++) {
141 g[k] = RT * (g[k] + tmp);
150 #ifdef H298MODIFY_CAPABILITY
163 for (
size_t k = 0; k <
m_kk; k++) {
173 for (
size_t k = 0; k <
m_kk; k++) {
184 for (
size_t k = 0; k <
m_kk; k++) {
194 doublereal tmp = p /
_RT();
195 doublereal v0 =
_RT() / p;
196 for (
size_t i = 0; i <
m_kk; i++) {
211 for (
size_t i = 0; i <
m_kk; i++) {
236 scale(gibbsrt.begin(), gibbsrt.end(), g,
_RT());
262 doublereal v0 =
_RT() / pp;
263 for (
size_t i = 0; i <
m_kk; i++) {
285 if (state.
hasChild(
"temperature")) {
292 }
else if (state.
hasChild(
"density")) {
365 void MixtureFugacityTP::setMoleFractions_NoState(
const doublereal*
const x)
369 updateMixingExpressions();
374 err(
"MixtureFugacityTP::calcDensity() called, but EOS for phase is not known");
394 updateMixingExpressions();
408 rho =
densityCalc(t, pres, FLUID_UNDEFINED , rhoNow);
414 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"neg rho");
417 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"neg rho");
425 if (
iState_ < FLUID_LIQUID_0) {
432 if (
iState_ >= FLUID_LIQUID_0) {
433 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"wrong state");
436 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"neg rho");
443 if (
iState_ >= FLUID_LIQUID_0) {
451 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"wrong state");
454 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"neg rho");
475 updateMixingExpressions();
485 setMoleFractions_NoState(x);
504 doublereal molarV = mmw / rho;
505 doublereal rt =
_RT();
506 return p * molarV / rt;
511 throw CanteraError(
"MixtureFugacityTP::sresid()",
"Base Class: not implemented");
517 throw CanteraError(
"MixtureFugacityTP::hresid()",
"Base Class: not implemented");
525 doublereal tt = tcrit/TKelvin;
529 doublereal lpr = -0.8734*tt*tt - 3.4522*tt + 4.2918;
530 return pcrit*exp(lpr);
535 throw CanteraError(
"MixtureFugacityTP::liquidVolEst()",
"unimplemented");
540 int phase, doublereal rhoguess)
546 if (rhoguess == -1.0) {
548 if (TKelvin > tcrit) {
551 if (phase == FLUID_GAS || phase == FLUID_SUPERCRIT) {
553 }
else if (phase >= FLUID_LIQUID_0) {
555 rhoguess = mmw / lqvol;
568 double molarVolBase = mmw / rhoguess;
569 double molarVolLast = molarVolBase;
575 double molarVolSpinodal = vc;
576 doublereal pcheck = 1.0E-30 + 1.0E-8 * presPa;
577 doublereal presBase, dpdVBase, delMV;
582 bool gasSide = molarVolBase > vc;
593 for (
int n = 0; n < 200; n++) {
605 dpdVBase =
dpdVCalc(TKelvin, molarVolBase, presBase);
612 if (dpdVBase >= 0.0) {
613 if (TKelvin > tcrit) {
622 if (molarVolBase >= vc) {
623 molarVolSpinodal = molarVolBase;
624 molarVolBase = 0.5 * (molarVolLast + molarVolSpinodal);
626 molarVolBase = 0.5 * (molarVolLast + molarVolSpinodal);
629 if (molarVolBase <= vc) {
630 molarVolSpinodal = molarVolBase;
631 molarVolBase = 0.5 * (molarVolLast + molarVolSpinodal);
633 molarVolBase = 0.5 * (molarVolLast + molarVolSpinodal);
642 if (fabs(presBase-presPa) < pcheck) {
650 doublereal dpdV = dpdVBase;
652 dpdV = dpdVBase * 1.5;
661 delMV = - (presBase - presPa) / dpdV;
662 if (!gasSide || delMV < 0.0) {
663 if (fabs(delMV) > 0.2 * molarVolBase) {
664 delMV = delMV / fabs(delMV) * 0.2 * molarVolBase;
670 if (TKelvin < tcrit) {
673 if (-delMV > 0.5 * (molarVolBase - molarVolSpinodal)) {
674 delMV = - 0.5 * (molarVolBase - molarVolSpinodal);
679 if (delMV > 0.5 * (molarVolSpinodal - molarVolBase)) {
680 delMV = 0.5 * (molarVolSpinodal - molarVolBase);
688 molarVolLast = molarVolBase;
689 molarVolBase += delMV;
692 if (fabs(delMV/molarVolBase) < 1.0E-14) {
700 if (molarVolBase <= 0.0) {
701 molarVolBase = std::min(1.0E-30, fabs(delMV*1.0E-4));
710 double densBase = 0.0;
713 throw CanteraError(
"MixtureFugacityTP::densityCalc()",
"Process didnot converge");
715 densBase = mmw / molarVolBase;
720 void MixtureFugacityTP::updateMixingExpressions()
724 MixtureFugacityTP::spinodalFunc::spinodalFunc(MixtureFugacityTP* tp) :
730 int MixtureFugacityTP::spinodalFunc::evalSS(
const doublereal t,
const doublereal*
const y,
734 doublereal molarVol = y[0];
735 doublereal tt = m_tp->temperature();
737 doublereal val = m_tp->dpdVCalc(tt, molarVol, pp);
743 doublereal& densGasGuess, doublereal& liqGRT, doublereal& gasGRT)
747 doublereal densLiq =
densityCalc(TKelvin, pres, FLUID_LIQUID_0, densLiqGuess);
748 if (densLiq <= 0.0) {
754 densLiqGuess = densLiq;
759 doublereal densGas =
densityCalc(TKelvin, pres, FLUID_GAS, densGasGuess);
760 if (densGas <= 0.0) {
766 "Error occurred trying to find gas density at (T,P) = "
771 densGasGuess = densGas;
787 return FLUID_SUPERCRIT;
789 double tmid = tcrit - 100.;
797 double densLiqTmid = mmw / molVolLiqTmid;
798 double densGasTmid = mmw / molVolGasTmid;
799 double densMidTmid = 0.5 * (densLiqTmid + densGasTmid);
800 doublereal rhoMid = rhocrit + (t - tcrit) * (rhocrit - densMidTmid) / (tcrit - tmid);
803 int iStateGuess = FLUID_LIQUID_0;
805 iStateGuess = FLUID_GAS;
807 double molarVol = mmw / rho;
810 double dpdv =
dpdVCalc(t, molarVol, presCalc);
835 doublereal molarVolGas;
836 doublereal molarVolLiquid;
842 doublereal& molarVolLiquid)
866 double RhoLiquid, RhoGas;
867 double RhoLiquidGood, RhoGasGood;
872 if (TKelvin < tcrit) {
877 RhoLiquidGood = mw / volLiquid;
879 doublereal delGRT = 1.0E6;
880 doublereal liqGRT, gasGRT;
882 doublereal presLast = pres;
888 doublereal presLiquid = 0.;
890 doublereal presBase = pres;
891 bool foundLiquid =
false;
892 bool foundGas =
false;
894 doublereal densLiquid =
densityCalc(TKelvin, presBase, FLUID_LIQUID_0, RhoLiquidGood);
895 if (densLiquid > 0.0) {
898 RhoLiquidGood = densLiquid;
901 for (
int i = 0; i < 50; i++) {
903 densLiquid =
densityCalc(TKelvin, pres, FLUID_LIQUID_0, RhoLiquidGood);
904 if (densLiquid > 0.0) {
907 RhoLiquidGood = densLiquid;
914 doublereal densGas =
densityCalc(TKelvin, pres, FLUID_GAS, RhoGasGood);
915 if (densGas <= 0.0) {
920 RhoGasGood = densGas;
923 for (
int i = 0; i < 50; i++) {
925 densGas =
densityCalc(TKelvin, pres, FLUID_GAS, RhoGasGood);
929 RhoGasGood = densGas;
935 if (foundGas && foundLiquid) {
936 if (presGas != presLiquid) {
937 pres = 0.5 * (presLiquid + presGas);
940 for (
int i = 0; i < 50; i++) {
941 densLiquid =
densityCalc(TKelvin, pres, FLUID_LIQUID_0, RhoLiquidGood);
942 if (densLiquid <= 0.0) {
946 RhoLiquidGood = densLiquid;
949 densGas =
densityCalc(TKelvin, pres, FLUID_GAS, RhoGasGood);
950 if (densGas <= 0.0) {
954 RhoGasGood = densGas;
957 if (goodGas && goodLiq) {
960 if (!goodLiq && !goodGas) {
961 pres = 0.5 * (pres + presLiquid);
963 if (goodLiq || goodGas) {
964 pres = 0.5 * (presLiquid + presGas);
969 if (!foundGas || !foundLiquid) {
970 printf(
"error coundn't find a starting pressure\n");
973 if (presGas != presLiquid) {
974 printf(
"error coundn't find a starting pressure\n");
981 RhoLiquid = RhoLiquidGood;
988 for (
int i = 0; i < 20; i++) {
990 stab =
corr0(TKelvin, pres, RhoLiquid, RhoGas, liqGRT, gasGRT);
993 delGRT = liqGRT - gasGRT;
994 doublereal delV = mw * (1.0/RhoLiquid - 1.0/RhoGas);
995 doublereal dp = - delGRT *
GasConstant * TKelvin / delV;
997 if (fabs(dp) > 0.1 * pres) {
1006 }
else if (stab == -1) {
1008 if (presLast > pres) {
1009 pres = 0.5 * (presLast + pres);
1014 }
else if (stab == -2) {
1015 if (presLast < pres) {
1016 pres = 0.5 * (presLast + pres);
1022 molarVolGas = mw / RhoGas;
1023 molarVolLiquid = mw / RhoLiquid;
1026 if (fabs(delGRT) < 1.0E-8) {
1032 molarVolGas = mw / RhoGas;
1033 molarVolLiquid = mw / RhoLiquid;
1044 molarVolGas = mw / RhoGas;
1045 molarVolLiquid = molarVolGas;
1053 throw CanteraError(
"MixtureFugacityTP::pressureCalc",
"unimplemented");
1059 throw CanteraError(
"MixtureFugacityTP::dpdVCalc",
"unimplemented");
1074 for (
size_t k = 0; k <
m_kk; k++) {
1079 throw CanteraError(
"MixtureFugacityTP::_updateReferenceStateThermo()",
"neg ref pressure");
virtual void setMoleFractions_NoNorm(const doublereal *const x)
Set the mole fractions to the specified values without normalizing.
virtual doublereal satPressure(doublereal TKelvin)
Calculate the saturation pressure at the current mixture content for the given temperature.
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input...
virtual void setState_TPX(doublereal t, doublereal p, const doublereal *x)
Set the temperature (K), pressure (Pa), and mole fractions.
virtual doublereal densSpinodalGas() const
Return the value of the density at the gas spinodal point (on the gas side) for the current temperatu...
virtual doublereal density() const
Density (kg/m^3).
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Initialize a ThermoPhase object, potentially reading activity coefficient information from an XML dat...
virtual doublereal densityCalc(doublereal TKelvin, doublereal pressure, int phaseRequested, doublereal rhoguess)
Calculates the density given the temperature and the pressure and a guess at the density.
virtual doublereal liquidVolEst(doublereal TKelvin, doublereal &pres) const
Estimate for the molar volume of the liquid.
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
virtual int eosType() const
Equation of state type flag.
virtual void getGibbs_ref(doublereal *g) const
Declaration file for a virtual base class that manages the calculation of standard state properties f...
doublereal _RT() const
Return the Gas Constant multiplied by the current temperature.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
ThermoPhase & operator=(const ThermoPhase &right)
Assignment operator.
int forcedState_
Force the system to be on a particular side of the spinodal curve.
void getPureGibbs(doublereal *gpure) const
Get the pure Gibbs free energies of each species.
virtual void modifyOneHf298SS(const int k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1) ...
doublereal z() const
Calculate the value of z.
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the standard state of the species at ...
const int cSS_CONVENTION_TEMPERATURE
Standard state uses the molar convention.
vector_fp m_g0_RT
Temporary storage for dimensionless reference state gibbs energies.
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values, and then normalize them so that they sum to 1...
doublereal err(const std::string &msg) const
MixtureFugacityTP has its own err routine.
Class XML_Node is a tree-based representation of the contents of an XML file.
This is a filter class for ThermoPhase that implements some preparatory steps for efficiently handlin...
MixtureFugacityTP & operator=(const MixtureFugacityTP &b)
Assignment operator.
doublereal getFloat(const Cantera::XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
virtual int standardStateConvention() const
This method returns the convention used in specification of the standard state, of which there are cu...
doublereal calculatePsat(doublereal TKelvin, doublereal &molarVolGas, doublereal &molarVolLiquid)
Calculate the saturation pressure at the current mixture content for the given temperature.
virtual doublereal critTemperature() const
Critical temperature (K).
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs free energies of the reference state at the current temper...
MixtureFugacityTP()
Constructor.
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
doublereal pressure() const
Returns the current pressure of the phase.
virtual void getStandardVolumes_ref(doublereal *vol) const
Get the molar volumes of the species reference states at the current T and reference pressure of the ...
#define FLUID_UNSTABLE
Various states of the Fugacity object.
virtual void initThermo()
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species at their standard states of solution at the cu...
Base class for a phase with thermodynamic properties.
virtual void setState_TR(doublereal T, doublereal rho)
Set the internally stored temperature (K) and density (kg/m^3)
vector_fp m_s0_R
Temporary storage for dimensionless reference state entropies.
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of each species in their standard states at the current T and P of the solution...
void setMassFractionsByName(compositionMap &yMap)
Set the species mass fractions by name.
doublereal m_Pcurrent
Current value of the pressures.
virtual void setMassFractions_NoNorm(const doublereal *const y)
Set the mass fractions to the specified values without normalizing.
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values, and then normalize them so that they sum to 1...
virtual void setTemperature(const doublereal temp)
Set the temperature of the phase.
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
virtual doublereal psatEst(doublereal TKelvin) const
Estimate for the saturation pressure.
virtual doublereal densSpinodalLiquid() const
Return the value of the density at the liquid spinodal point (on the liquid side) for the current tem...
virtual doublereal critDensity() const
Critical density (kg/m3).
Header file for a derived class of ThermoPhase that handles non-ideal mixtures based on the fugacity ...
doublereal molarVolume() const
Molar volume (m^3/kmol).
virtual void setConcentrations(const doublereal *const c)
Set the concentrations to the specified values within the phase.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
doublereal m_logc0
Temporary storage for log of p/rt.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Classes providing support for XML data files.
const vector_fp & gibbs_RT_ref() const
Returns the vector of nondimensional Gibbs free energies of the reference state at the current temper...
std::vector< doublereal > moleFractions_
Storage for the current values of the mole fractions of the species.
virtual doublereal refPressure(size_t k=npos) const =0
The reference-state pressure for species k.
virtual doublereal pressureCalc(doublereal TKelvin, doublereal molarVol) const
Calculate the pressure given the temperature and the molar volume.
Base class for exceptions thrown by Cantera classes.
void setMoleFractionsByName(compositionMap &xMap)
Set the species mole fractions by name.
virtual void setConcentrations(const doublereal *const conc)
Set the concentrations to the specified values within the phase.
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values There is no restriction on the sum of the mole fractio...
void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials These are partial molar Gibbs free energ...
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
virtual doublereal hresid() const
Calculate the deviation terms for the total enthalpy of the mixture from the ideal gas mixture...
virtual void setForcedSolutionBranch(int solnBranch)
Set the solution branch to force the ThermoPhase to exist on one branch or another.
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
virtual int forcedSolutionBranch() const
Report the solution branch which the solution is restricted to.
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the standard state at the current temperatu...
virtual void setMoleFractions_NoNorm(const doublereal *const x)
Set the mole fractions to the specified values without normalizing.
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
virtual void setMassFractions_NoNorm(const doublereal *const y)
Set the mass fractions to the specified values without normalizing.
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Enthalpy functions for the standard state species.
size_t nSpecies() const
Returns the number of species in the phase.
virtual doublereal critPressure() const
Critical pressure (Pa).
doublereal temperature() const
Temperature (K).
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
int iState_
Current state of the fluid.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
doublereal m_Tlast_ref
The last temperature at which the reference state thermodynamic properties were calculated at...
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Contains declarations for string manipulation functions within Cantera.
int corr0(doublereal TKelvin, doublereal pres, doublereal &densLiq, doublereal &densGas, doublereal &liqGRT, doublereal &gasGRT)
Utility routine in the calculation of the saturation pressure.
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values and normalize them.
size_t m_kk
Number of species in the phase.
virtual void setState_TP(doublereal T, doublereal pres)
Set the temperature and pressure at the same time.
virtual void getEntropy_R_ref(doublereal *er) const
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const =0
Compute the reference-state properties for all species.
virtual doublereal sresid() const
Calculate the deviation terms for the total entropy of the mixture from the ideal gas mixture...
virtual void _updateReferenceStateThermo() const
Updates the reference state thermodynamic functions at the current T of the solution.
std::string getChildValue(const Cantera::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...
virtual int reportSolnBranchActual() const
Report the solution branch which the solution is actually on.
SpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
virtual void getCp_R_ref(doublereal *cprt) const
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase Note the density of a phase is an independent...
vector_fp m_h0_RT
Temporary storage for dimensionless reference state enthalpies.
vector_fp m_cp0_R
Temporary storage for dimensionless reference state heat capacities.
virtual doublereal dpdVCalc(doublereal TKelvin, doublereal molarVol, doublereal &presCalc) const
Calculate the pressure and the pressure derivative given the temperature and the molar volume...
virtual void setStateFromXML(const XML_Node &state)
Set the initial state of the phase to the conditions specified in the state XML element.