Skip to content

Commit

Permalink
enhancements to setting thermo
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Sep 5, 2022
1 parent 4e29f5e commit 6145f3a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
20 changes: 16 additions & 4 deletions thermosteam/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,14 @@ def electricity_price(self, electricity_price):
bst.PowerUtility.price = electricity_price

def set_thermo(self, thermo: tmo.Thermo|Iterable[str|tmo.Chemical],
cache: Optional[bool]=None,
skip_checks: Optional[bool]=False,
ideal: Optional[bool]=False):
mixture: Optional=None,
Gamma: Optional=None,
Phi: Optional=None,
PCF: Optional=None,
cache: Optional[bool]=None,
skip_checks: Optional[bool]=False,
ideal: Optional[bool]=False,
):
"""
Set the default :class:`~thermosteam.Thermo` object. If `thermo` is
not a :class:`~thermosteam.Thermo` object, an attempt is made to
Expand All @@ -174,10 +179,17 @@ def set_thermo(self, thermo: tmo.Thermo|Iterable[str|tmo.Chemical],
ideal :
Whether to use ideal phase equilibrium and mixture property
algorithms.
Gamma : :class:`~thermosteam.equilibrium.activity_coefficients.ActivityCoefficients` subclass, optional
Class for computing activity coefficients.
Phi : :class:`~thermosteam.equilibrium.fugacity_coefficients.FugacityCoefficients` subclass, optional
Class for computing fugacity coefficients.
PCF : :class:`~thermosteam.equilibrium.poyinting_correction_factors.PoyintingCorrectionFactors` subclass, optional
Class for computing poynting correction factors.
"""
if not isinstance(thermo, (tmo.Thermo, tmo.IdealThermo)):
thermo = tmo.Thermo(thermo, cache=cache, skip_checks=skip_checks)
thermo = tmo.Thermo(thermo, mixture=mixture, cache=cache, skip_checks=skip_checks,
Gamma=Gamma, Phi=Phi, PCF=PCF)
if ideal: thermo = thermo.ideal()
self._thermo = thermo

Expand Down
9 changes: 6 additions & 3 deletions thermosteam/_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,14 @@ class Thermo:
__slots__ = ('chemicals', 'mixture', 'Gamma', 'Phi', 'PCF', '_ideal', '_original_thermo')

def __init__(self, chemicals, mixture=None,
Gamma=eq.DortmundActivityCoefficients,
Phi=eq.IdealFugacityCoefficients,
PCF=eq.MockPoyintingCorrectionFactors,
Gamma=None,
Phi=None,
PCF=None,
cache=None,
skip_checks=False):
if Gamma is None: Gamma = eq.DortmundActivityCoefficients
if Phi is None: Phi = eq.IdealFugacityCoefficients
if PCF is None: PCF = eq.MockPoyintingCorrectionFactors
if not isinstance(chemicals, Chemicals): chemicals = Chemicals(chemicals, cache)
if not mixture:
mixture = Mixture.from_chemicals(chemicals)
Expand Down
12 changes: 8 additions & 4 deletions thermosteam/equilibrium/poyinting_correction_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ class MockPoyintingCorrectionFactors(PoyintingCorrectionFactors):
"""
__slots__ = ('_chemicals',)

def __call__(self, T, P, Psats):
def __call__(self, T, P, Psats=None):
return 1.


@njit(cache=True)
def ideal_gas_poyinting_correction_factors(T, P, vls, Psats):
return np.exp(vls / (R * T) * (P - Psats))
dP = P - Psats
dP[dP < 0.] = 0.
return np.exp(vls / (R * T) * dP)

class IdealGasPoyintingCorrectionFactors(PoyintingCorrectionFactors):
"""Create an IdealGasPoyintingCorrectionFactors object that estimates
Expand All @@ -81,6 +83,8 @@ class IdealGasPoyintingCorrectionFactors(PoyintingCorrectionFactors):
"""
__slots__ = ('_chemicals',)

def __call__(self, T, P, Psats):
vls = np.array([i.V('l', T, P) for i in self._chemicals])
def __call__(self, T, P, Psats=None):
vls = np.array([i.V('l', T, P) for i in self._chemicals], dtype=float)
if Psats is None:
Psats = np.array([i.Psat(T) for i in self._chemicals], dtype=float)
return ideal_gas_poyinting_correction_factors(T, P, vls, Psats)

0 comments on commit 6145f3a

Please sign in to comment.