23 MixtureFugacityTP::MixtureFugacityTP() :
26 forcedState_(FLUID_UNDEFINED),
35 forcedState_(FLUID_UNDEFINED),
100 doublereal invRT = 1.0 /
_RT();
101 for (
size_t k = 0; k <
m_kk; k++) {
114 doublereal RT =
_RT();
116 for (
size_t k = 0; k <
m_kk; k++) {
117 g[k] = RT * (g[k] + tmp);
137 for (
size_t k = 0; k <
m_kk; k++) {
147 for (
size_t k = 0; k <
m_kk; k++) {
157 for (
size_t k = 0; k <
m_kk; k++) {
166 for (
size_t i = 0; i <
m_kk; i++) {
181 for (
size_t i = 0; i <
m_kk; i++) {
206 scale(gibbsrt.begin(), gibbsrt.end(), g,
_RT());
231 for (
size_t i = 0; i <
m_kk; i++) {
253 if (state.
hasChild(
"temperature")) {
254 t =
getFloat(state,
"temperature",
"temperature");
258 double p =
getFloat(state,
"pressure",
"pressure");
260 }
else if (state.
hasChild(
"density")) {
261 double rho =
getFloat(state,
"density",
"density");
326 void MixtureFugacityTP::setMoleFractions_NoState(
const doublereal*
const x)
330 updateMixingExpressions();
336 "called, but EOS for phase is not known");
356 updateMixingExpressions();
368 rho =
densityCalc(t, pres, FLUID_UNDEFINED , rhoNow);
374 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"neg rho");
377 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"neg rho");
385 if (
iState_ < FLUID_LIQUID_0) {
392 if (
iState_ >= FLUID_LIQUID_0) {
393 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"wrong state");
396 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"neg rho");
403 if (
iState_ >= FLUID_LIQUID_0) {
411 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"wrong state");
414 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"neg rho");
429 updateMixingExpressions();
437 setMoleFractions_NoState(x);
454 throw CanteraError(
"MixtureFugacityTP::sresid()",
"Base Class: not implemented");
459 throw CanteraError(
"MixtureFugacityTP::hresid()",
"Base Class: not implemented");
469 doublereal lpr = -0.8734*tt*tt - 3.4522*tt + 4.2918;
470 return pcrit*exp(lpr);
475 throw CanteraError(
"MixtureFugacityTP::liquidVolEst()",
"unimplemented");
479 int phase, doublereal rhoguess)
483 if (rhoguess == -1.0) {
485 if (TKelvin > tcrit) {
488 if (phase == FLUID_GAS || phase == FLUID_SUPERCRIT) {
490 }
else if (phase >= FLUID_LIQUID_0) {
492 rhoguess = mmw / lqvol;
505 double molarVolBase = mmw / rhoguess;
506 double molarVolLast = molarVolBase;
512 double molarVolSpinodal = vc;
517 bool gasSide = molarVolBase > vc;
528 for (
int n = 0; n < 200; n++) {
541 double dpdVBase =
dpdVCalc(TKelvin, molarVolBase, presBase);
548 if (dpdVBase >= 0.0) {
549 if (TKelvin > tcrit) {
551 "T > tcrit unexpectedly");
559 if (molarVolBase >= vc) {
560 molarVolSpinodal = molarVolBase;
561 molarVolBase = 0.5 * (molarVolLast + molarVolSpinodal);
563 molarVolBase = 0.5 * (molarVolLast + molarVolSpinodal);
566 if (molarVolBase <= vc) {
567 molarVolSpinodal = molarVolBase;
568 molarVolBase = 0.5 * (molarVolLast + molarVolSpinodal);
570 molarVolBase = 0.5 * (molarVolLast + molarVolSpinodal);
579 if (fabs(presBase-presPa) < 1.0E-30 + 1.0E-8 * presPa) {
587 doublereal dpdV = dpdVBase;
589 dpdV = dpdVBase * 1.5;
597 double delMV = - (presBase - presPa) / dpdV;
598 if (!gasSide || delMV < 0.0) {
599 if (fabs(delMV) > 0.2 * molarVolBase) {
600 delMV = delMV / fabs(delMV) * 0.2 * molarVolBase;
606 if (TKelvin < tcrit) {
609 if (-delMV > 0.5 * (molarVolBase - molarVolSpinodal)) {
610 delMV = - 0.5 * (molarVolBase - molarVolSpinodal);
615 if (delMV > 0.5 * (molarVolSpinodal - molarVolBase)) {
616 delMV = 0.5 * (molarVolSpinodal - molarVolBase);
624 molarVolLast = molarVolBase;
625 molarVolBase += delMV;
628 if (fabs(delMV/molarVolBase) < 1.0E-14) {
636 if (molarVolBase <= 0.0) {
637 molarVolBase = std::min(1.0E-30, fabs(delMV*1.0E-4));
646 double densBase = 0.0;
649 throw CanteraError(
"MixtureFugacityTP::densityCalc()",
"Process did not converge");
651 densBase = mmw / molarVolBase;
656 void MixtureFugacityTP::updateMixingExpressions()
660 MixtureFugacityTP::spinodalFunc::spinodalFunc(MixtureFugacityTP* tp) :
665 int MixtureFugacityTP::spinodalFunc::evalSS(
const doublereal t,
const doublereal*
const y,
668 doublereal molarVol = y[0];
670 r[0] = m_tp->dpdVCalc(m_tp->temperature(), molarVol, pp);
675 doublereal& densGasGuess, doublereal& liqGRT, doublereal& gasGRT)
679 doublereal densLiq =
densityCalc(TKelvin, pres, FLUID_LIQUID_0, densLiqGuess);
680 if (densLiq <= 0.0) {
683 densLiqGuess = densLiq;
688 doublereal densGas =
densityCalc(TKelvin, pres, FLUID_GAS, densGasGuess);
689 if (densGas <= 0.0) {
692 "Error occurred trying to find gas density at (T,P) = "
697 densGasGuess = densGas;
712 return FLUID_SUPERCRIT;
714 double tmid = tcrit - 100.;
722 double densLiqTmid = mmw / molVolLiqTmid;
723 double densGasTmid = mmw / molVolGasTmid;
724 double densMidTmid = 0.5 * (densLiqTmid + densGasTmid);
725 doublereal rhoMid = rhocrit + (t - tcrit) * (rhocrit - densMidTmid) / (tcrit - tmid);
728 int iStateGuess = FLUID_LIQUID_0;
730 iStateGuess = FLUID_GAS;
732 double molarVol = mmw / rho;
735 double dpdv =
dpdVCalc(t, molarVol, presCalc);
748 throw CanteraError(
"MixtureFugacityTP::densSpinodalLiquid",
"unimplemented");
753 throw CanteraError(
"MixtureFugacityTP::densSpinodalGas",
"unimplemented");
758 doublereal molarVolGas;
759 doublereal molarVolLiquid;
764 doublereal& molarVolLiquid)
796 double RhoLiquidGood = mw / volLiquid;
797 double RhoGasGood = pres * mw / (
GasConstant * TKelvin);
798 doublereal delGRT = 1.0E6;
799 doublereal liqGRT, gasGRT;
805 doublereal presLiquid = 0.;
807 doublereal presBase = pres;
808 bool foundLiquid =
false;
809 bool foundGas =
false;
811 doublereal densLiquid =
densityCalc(TKelvin, presBase, FLUID_LIQUID_0, RhoLiquidGood);
812 if (densLiquid > 0.0) {
815 RhoLiquidGood = densLiquid;
818 for (
int i = 0; i < 50; i++) {
820 densLiquid =
densityCalc(TKelvin, pres, FLUID_LIQUID_0, RhoLiquidGood);
821 if (densLiquid > 0.0) {
824 RhoLiquidGood = densLiquid;
831 doublereal densGas =
densityCalc(TKelvin, pres, FLUID_GAS, RhoGasGood);
832 if (densGas <= 0.0) {
837 RhoGasGood = densGas;
840 for (
int i = 0; i < 50; i++) {
842 densGas =
densityCalc(TKelvin, pres, FLUID_GAS, RhoGasGood);
846 RhoGasGood = densGas;
852 if (foundGas && foundLiquid) {
853 if (presGas != presLiquid) {
854 pres = 0.5 * (presLiquid + presGas);
857 for (
int i = 0; i < 50; i++) {
858 densLiquid =
densityCalc(TKelvin, pres, FLUID_LIQUID_0, RhoLiquidGood);
859 if (densLiquid <= 0.0) {
863 RhoLiquidGood = densLiquid;
866 densGas =
densityCalc(TKelvin, pres, FLUID_GAS, RhoGasGood);
867 if (densGas <= 0.0) {
871 RhoGasGood = densGas;
874 if (goodGas && goodLiq) {
877 if (!goodLiq && !goodGas) {
878 pres = 0.5 * (pres + presLiquid);
880 if (goodLiq || goodGas) {
881 pres = 0.5 * (presLiquid + presGas);
886 if (!foundGas || !foundLiquid) {
887 printf(
"error couldn't find a starting pressure\n");
890 if (presGas != presLiquid) {
891 printf(
"error couldn't find a starting pressure\n");
896 double presLast = pres;
897 double RhoGas = RhoGasGood;
898 double RhoLiquid = RhoLiquidGood;
905 for (
int i = 0; i < 20; i++) {
906 int stab =
corr0(TKelvin, pres, RhoLiquid, RhoGas, liqGRT, gasGRT);
909 delGRT = liqGRT - gasGRT;
910 doublereal delV = mw * (1.0/RhoLiquid - 1.0/RhoGas);
911 doublereal dp = - delGRT *
GasConstant * TKelvin / delV;
913 if (fabs(dp) > 0.1 * pres) {
922 }
else if (stab == -1) {
924 if (presLast > pres) {
925 pres = 0.5 * (presLast + pres);
930 }
else if (stab == -2) {
931 if (presLast < pres) {
932 pres = 0.5 * (presLast + pres);
938 molarVolGas = mw / RhoGas;
939 molarVolLiquid = mw / RhoLiquid;
942 if (fabs(delGRT) < 1.0E-8) {
948 molarVolGas = mw / RhoGas;
949 molarVolLiquid = mw / RhoLiquid;
960 molarVolLiquid = molarVolGas;
968 throw CanteraError(
"MixtureFugacityTP::pressureCalc",
"unimplemented");
973 throw CanteraError(
"MixtureFugacityTP::dpdVCalc",
"unimplemented");
987 for (
size_t k = 0; k <
m_kk; k++) {
992 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).
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.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
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...
An error indicating that an unimplemented function has been called.
virtual void getGibbs_ref(doublereal *g) const
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.
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...
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.
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...
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.
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.
void modifyOneHf298SS(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of the standard state of one species in the phase (J ...
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.
void setMoleFractionsByName(const compositionMap &xMap)
Set the species mole fractions by name.
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.
void setMassFractionsByName(const compositionMap &yMap)
Set the species mass fractions by name.
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.
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.
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.
Templates for operations on vector-like objects.
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.
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
virtual void modifyOneHf298(const size_t k, const doublereal Hf298New)=0
Modify the value of the 298 K Heat of Formation of the standard state of one species in the phase (J ...
#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.
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.