20 MixtureFugacityTP::MixtureFugacityTP() :
23 forcedState_(FLUID_UNDEFINED),
31 forcedState_(FLUID_UNDEFINED),
34 MixtureFugacityTP::operator=(b);
37 MixtureFugacityTP& MixtureFugacityTP::operator=(
const MixtureFugacityTP& b)
87 for (
size_t k = 0; k <
m_kk; k++) {
88 muRT[k] *= 1.0 /
RT();
99 for (
size_t k = 0; k <
m_kk; k++) {
100 g[k] =
RT() * (g[k] + tmp);
114 for (
size_t k = 0; k <
m_kk; k++) {
124 for (
size_t k = 0; k <
m_kk; k++) {
134 for (
size_t k = 0; k <
m_kk; k++) {
143 for (
size_t i = 0; i <
m_kk; i++) {
157 for (
size_t i = 0; i <
m_kk; i++) {
179 scale(gibbsrt.begin(), gibbsrt.end(), g,
RT());
203 for (
size_t i = 0; i <
m_kk; i++) {
225 if (state.
hasChild(
"temperature")) {
226 t =
getFloat(state,
"temperature",
"temperature");
230 double p =
getFloat(state,
"pressure",
"pressure");
232 }
else if (state.
hasChild(
"density")) {
233 double rho =
getFloat(state,
"density",
"density");
275 void MixtureFugacityTP::setMoleFractions_NoState(
const doublereal*
const x)
279 updateMixingExpressions();
285 "called, but EOS for phase is not known");
300 updateMixingExpressions();
312 rho =
densityCalc(t, pres, FLUID_UNDEFINED , rhoNow);
318 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"neg rho");
321 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"neg rho");
326 if (
iState_ < FLUID_LIQUID_0) {
333 if (
iState_ >= FLUID_LIQUID_0) {
334 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"wrong state");
337 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"neg rho");
341 if (
iState_ >= FLUID_LIQUID_0) {
349 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"wrong state");
352 throw CanteraError(
"MixtureFugacityTP::setState_TP()",
"neg rho");
358 void MixtureFugacityTP::setState_TR(doublereal T, doublereal rho)
366 updateMixingExpressions();
374 setMoleFractions_NoState(x);
385 throw CanteraError(
"MixtureFugacityTP::sresid()",
"Base Class: not implemented");
390 throw CanteraError(
"MixtureFugacityTP::hresid()",
"Base Class: not implemented");
400 doublereal lpr = -0.8734*tt*tt - 3.4522*tt + 4.2918;
401 return pcrit*exp(lpr);
406 throw CanteraError(
"MixtureFugacityTP::liquidVolEst()",
"unimplemented");
410 int phase, doublereal rhoguess)
414 if (rhoguess == -1.0) {
416 if (TKelvin > tcrit) {
419 if (phase == FLUID_GAS || phase == FLUID_SUPERCRIT) {
421 }
else if (phase >= FLUID_LIQUID_0) {
423 rhoguess = mmw / lqvol;
433 double molarVolBase = mmw / rhoguess;
434 double molarVolLast = molarVolBase;
439 double molarVolSpinodal = vc;
443 bool gasSide = molarVolBase > vc;
452 for (
int n = 0; n < 200; n++) {
457 double dpdVBase =
dpdVCalc(TKelvin, molarVolBase, presBase);
462 if (dpdVBase >= 0.0) {
463 if (TKelvin > tcrit) {
465 "T > tcrit unexpectedly");
472 if (molarVolBase >= vc) {
473 molarVolSpinodal = molarVolBase;
474 molarVolBase = 0.5 * (molarVolLast + molarVolSpinodal);
476 molarVolBase = 0.5 * (molarVolLast + molarVolSpinodal);
479 if (molarVolBase <= vc) {
480 molarVolSpinodal = molarVolBase;
481 molarVolBase = 0.5 * (molarVolLast + molarVolSpinodal);
483 molarVolBase = 0.5 * (molarVolLast + molarVolSpinodal);
490 if (fabs(presBase-presPa) < 1.0E-30 + 1.0E-8 * presPa) {
496 doublereal dpdV = dpdVBase;
498 dpdV = dpdVBase * 1.5;
503 double delMV = - (presBase - presPa) / dpdV;
504 if ((!gasSide || delMV < 0.0) && fabs(delMV) > 0.2 * molarVolBase) {
505 delMV = delMV / fabs(delMV) * 0.2 * molarVolBase;
508 if (TKelvin < tcrit) {
510 if (delMV < 0.0 && -delMV > 0.5 * (molarVolBase - molarVolSpinodal)) {
511 delMV = - 0.5 * (molarVolBase - molarVolSpinodal);
514 if (delMV > 0.0 && delMV > 0.5 * (molarVolSpinodal - molarVolBase)) {
515 delMV = 0.5 * (molarVolSpinodal - molarVolBase);
520 molarVolLast = molarVolBase;
521 molarVolBase += delMV;
523 if (fabs(delMV/molarVolBase) < 1.0E-14) {
529 if (molarVolBase <= 0.0) {
530 molarVolBase = std::min(1.0E-30, fabs(delMV*1.0E-4));
535 double densBase = 0.0;
538 throw CanteraError(
"MixtureFugacityTP::densityCalc()",
"Process did not converge");
540 densBase = mmw / molarVolBase;
545 void MixtureFugacityTP::updateMixingExpressions()
550 doublereal& densGasGuess, doublereal& liqGRT, doublereal& gasGRT)
553 doublereal densLiq =
densityCalc(TKelvin, pres, FLUID_LIQUID_0, densLiqGuess);
554 if (densLiq <= 0.0) {
557 densLiqGuess = densLiq;
558 setState_TR(TKelvin, densLiq);
562 doublereal densGas =
densityCalc(TKelvin, pres, FLUID_GAS, densGasGuess);
563 if (densGas <= 0.0) {
566 "Error occurred trying to find gas density at (T,P) = {} {}",
571 densGasGuess = densGas;
572 setState_TR(TKelvin, densGas);
586 return FLUID_SUPERCRIT;
588 double tmid = tcrit - 100.;
596 double densLiqTmid = mmw / molVolLiqTmid;
597 double densGasTmid = mmw / molVolGasTmid;
598 double densMidTmid = 0.5 * (densLiqTmid + densGasTmid);
599 doublereal rhoMid = rhocrit + (t - tcrit) * (rhocrit - densMidTmid) / (tcrit - tmid);
602 int iStateGuess = FLUID_LIQUID_0;
604 iStateGuess = FLUID_GAS;
606 double molarVol = mmw / rho;
609 double dpdv =
dpdVCalc(t, molarVol, presCalc);
621 throw CanteraError(
"MixtureFugacityTP::densSpinodalLiquid",
"unimplemented");
626 throw CanteraError(
"MixtureFugacityTP::densSpinodalGas",
"unimplemented");
631 doublereal molarVolGas;
632 doublereal molarVolLiquid;
637 doublereal& molarVolLiquid)
667 double RhoLiquidGood = mw / volLiquid;
668 double RhoGasGood = pres * mw / (
GasConstant * TKelvin);
669 doublereal delGRT = 1.0E6;
670 doublereal liqGRT, gasGRT;
674 doublereal presLiquid = 0.;
676 doublereal presBase = pres;
677 bool foundLiquid =
false;
678 bool foundGas =
false;
680 doublereal densLiquid =
densityCalc(TKelvin, presBase, FLUID_LIQUID_0, RhoLiquidGood);
681 if (densLiquid > 0.0) {
684 RhoLiquidGood = densLiquid;
687 for (
int i = 0; i < 50; i++) {
689 densLiquid =
densityCalc(TKelvin, pres, FLUID_LIQUID_0, RhoLiquidGood);
690 if (densLiquid > 0.0) {
693 RhoLiquidGood = densLiquid;
700 doublereal densGas =
densityCalc(TKelvin, pres, FLUID_GAS, RhoGasGood);
701 if (densGas <= 0.0) {
706 RhoGasGood = densGas;
709 for (
int i = 0; i < 50; i++) {
711 densGas =
densityCalc(TKelvin, pres, FLUID_GAS, RhoGasGood);
715 RhoGasGood = densGas;
721 if (foundGas && foundLiquid && presGas != presLiquid) {
722 pres = 0.5 * (presLiquid + presGas);
725 for (
int i = 0; i < 50; i++) {
726 densLiquid =
densityCalc(TKelvin, pres, FLUID_LIQUID_0, RhoLiquidGood);
727 if (densLiquid <= 0.0) {
731 RhoLiquidGood = densLiquid;
734 densGas =
densityCalc(TKelvin, pres, FLUID_GAS, RhoGasGood);
735 if (densGas <= 0.0) {
739 RhoGasGood = densGas;
742 if (goodGas && goodLiq) {
745 if (!goodLiq && !goodGas) {
746 pres = 0.5 * (pres + presLiquid);
748 if (goodLiq || goodGas) {
749 pres = 0.5 * (presLiquid + presGas);
753 if (!foundGas || !foundLiquid) {
754 writelog(
"error couldn't find a starting pressure\n");
757 if (presGas != presLiquid) {
758 writelog(
"error couldn't find a starting pressure\n");
763 double presLast = pres;
764 double RhoGas = RhoGasGood;
765 double RhoLiquid = RhoLiquidGood;
768 for (
int i = 0; i < 20; i++) {
769 int stab =
corr0(TKelvin, pres, RhoLiquid, RhoGas, liqGRT, gasGRT);
772 delGRT = liqGRT - gasGRT;
773 doublereal delV = mw * (1.0/RhoLiquid - 1.0/RhoGas);
774 doublereal dp = - delGRT *
GasConstant * TKelvin / delV;
776 if (fabs(dp) > 0.1 * pres) {
784 }
else if (stab == -1) {
786 if (presLast > pres) {
787 pres = 0.5 * (presLast + pres);
792 }
else if (stab == -2) {
793 if (presLast < pres) {
794 pres = 0.5 * (presLast + pres);
800 molarVolGas = mw / RhoGas;
801 molarVolLiquid = mw / RhoLiquid;
803 if (fabs(delGRT) < 1.0E-8) {
809 molarVolGas = mw / RhoGas;
810 molarVolLiquid = mw / RhoLiquid;
812 setState_TR(tempSave, densSave);
818 molarVolLiquid = molarVolGas;
819 setState_TR(tempSave, densSave);
826 throw CanteraError(
"MixtureFugacityTP::pressureCalc",
"unimplemented");
831 throw CanteraError(
"MixtureFugacityTP::dpdVCalc",
"unimplemented");
845 for (
size_t k = 0; k <
m_kk; k++) {
850 throw CanteraError(
"MixtureFugacityTP::_updateReferenceStateThermo()",
"neg ref pressure");
virtual int forcedSolutionBranch() const
Report the solution branch which the solution is restricted to.
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.
doublereal molarVolume() const
Molar volume (m^3/kmol).
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
virtual bool addSpecies(shared_ptr< Species > spec)
virtual doublereal sresid() const
Calculate the deviation terms for the total entropy of the mixture from the ideal gas mixture...
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 int standardStateConvention() const
This method returns the convention used in specification of the standard state, of which there are cu...
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
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...
doublereal temperature() const
Temperature (K).
virtual doublereal hresid() const
Calculate the deviation terms for the total enthalpy of the mixture from the ideal gas mixture...
An error indicating that an unimplemented function has been called.
virtual void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials These are partial molar Gibbs free energ...
virtual doublereal psatEst(doublereal TKelvin) const
Estimate for the saturation pressure.
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
virtual doublereal dpdVCalc(doublereal TKelvin, doublereal molarVol, doublereal &presCalc) const
Calculate the pressure and the pressure derivative given the temperature and the molar volume...
ThermoPhase & operator=(const ThermoPhase &right)
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
doublereal z() const
Calculate the value of z.
int forcedState_
Force the system to be on a particular side of the spinodal curve.
void writelog(const std::string &fmt, const Args &... args)
Write a formatted message to the screen.
const int cSS_CONVENTION_TEMPERATURE
Standard state uses the molar convention.
vector_fp m_g0_RT
Temporary storage for dimensionless reference state Gibbs energies.
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...
virtual doublereal density() const
Density (kg/m^3).
virtual doublereal refPressure(size_t k=npos) const
The reference-state pressure for species k.
doublereal calculatePsat(doublereal TKelvin, doublereal &molarVolGas, doublereal &molarVolLiquid)
Calculate the saturation pressure at the current mixture content for the given temperature.
MixtureFugacityTP()
Constructor.
#define FLUID_UNSTABLE
Various states of the Fugacity object.
virtual void getPureGibbs(doublereal *gpure) const
Get the pure Gibbs free energies of each species.
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
virtual int reportSolnBranchActual() const
Report the solution branch which the solution is actually on.
Base class for a phase with thermodynamic properties.
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected...
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected...
vector_fp m_s0_R
Temporary storage for dimensionless reference state entropies.
virtual void getGibbs_ref(doublereal *g) const
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
doublereal m_Pcurrent
Current value of the pressure.
virtual doublereal critPressure() const
Critical pressure (Pa).
virtual void setTemperature(const doublereal temp)
Set the temperature of the phase.
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
Header file for a derived class of ThermoPhase that handles non-ideal mixtures based on the fugacity ...
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
virtual void _updateReferenceStateThermo() const
Updates the reference state thermodynamic functions at the current T of the solution.
virtual doublereal densSpinodalLiquid() const
Return the value of the density at the liquid spinodal point (on the liquid side) for the current tem...
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
void setMoleFractionsByName(const compositionMap &xMap)
Set the species mole fractions by name.
void setMassFractionsByName(const compositionMap &yMap)
Set the species mass fractions by name.
Base class for exceptions thrown by Cantera classes.
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values.
virtual void setForcedSolutionBranch(int solnBranch)
Set the solution branch to force the ThermoPhase to exist on one branch or another.
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity.
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
virtual doublereal densSpinodalGas() const
Return the value of the density at the gas spinodal point (on the gas side) for the current temperatu...
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
MultiSpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
virtual doublereal pressure() const
Returns the current pressure of the phase.
virtual doublereal critTemperature() const
Critical temperature (K).
virtual doublereal pressureCalc(doublereal TKelvin, doublereal molarVol) const
Calculate the pressure given the temperature and the molar volume.
int iState_
Current state of the fluid.
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
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...
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
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.
const vector_fp & gibbs_RT_ref() const
Returns the vector of nondimensional Gibbs free energies of the reference state at the current temper...
vector_fp moleFractions_
Storage for the current values of the mole fractions of the species.
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 getStandardVolumes(doublereal *vol) const
Get the molar volumes of each species in their standard states at the current T and P of the solution...
size_t m_kk
Number of species in the phase.
virtual void setState_TP(doublereal T, doublereal pres)
Set the temperature (K) and pressure (Pa)
virtual void getStandardVolumes_ref(doublereal *vol) const
Get the molar volumes of the species reference states at the current T and P_ref of the solution...
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species at their standard states of solution at the cu...
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the standard state of the species at ...
Namespace for the Cantera kernel.
virtual doublereal critDensity() const
Critical density (kg/m3).
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the standard state at the current temperatu...
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase.
vector_fp m_h0_RT
Temporary storage for dimensionless reference state enthalpies.
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Enthalpy functions for the standard state species at the current T an...
vector_fp m_cp0_R
Temporary storage for dimensionless reference state heat capacities.
virtual void setStateFromXML(const XML_Node &state)
Set the initial state of the phase to the conditions specified in the state XML element.
virtual doublereal liquidVolEst(doublereal TKelvin, doublereal &pres) const
Estimate for the molar volume of the liquid.