Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EOS mixture options #93

Merged
merged 7 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions thermosteam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,26 @@
from ._chemical import Chemical
from ._chemicals import Chemicals, CompiledChemicals
from ._thermal_condition import ThermalCondition
from . import mixture
from .mixture import Mixture
from ._thermo import Thermo, IdealThermo
from ._settings import settings, ProcessSettings
from ._thermo_data import ThermoData
from . import (
indexer,
reaction,
equilibrium
equilibrium,
mixture,
)
from ._stream import Stream
from ._heat_and_power import Heat, Power
from ._multi_stream import MultiStream
from .base import functor
from .reaction import *
from .equilibrium import *
from .mixture import *

__all__ = ('Chemical', 'ChemicalData', 'Chemicals', 'CompiledChemicals', 'Mixture', 'Thermo',
'IdealThermo', 'Stream', 'MultiStream', 'Heat', 'Power', 'ThermalCondition', 'ProcessSettings',
'mixture', 'ThermoData', *reaction.__all__, *equilibrium.__all__,
'mixture', 'ThermoData', *reaction.__all__, *equilibrium.__all__, *mixture.__all__,
'indexer', 'settings', 'functor', 'functors', 'chemicals', 'base',
'equilibrium', 'units_of_measure', 'exceptions', 'functional',
'reaction', 'constants', 'utils', 'separations')
Expand Down
6 changes: 2 additions & 4 deletions thermosteam/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ class ProcessSettings:
>>> settings.thermo.show()
Thermo(
chemicals=CompiledChemicals([Water]),
mixture=Mixture(
rule='ideal', ...
mixture=IdealMixture(...
include_excess_energies=False
),
Gamma=DortmundActivityCoefficients,
Expand All @@ -80,8 +79,7 @@ class ProcessSettings:
Access defined mixture property algorithm:

>>> settings.mixture.show()
Mixture(
rule='ideal', ...
IdealMixture(...
include_excess_energies=False
)

Expand Down
17 changes: 7 additions & 10 deletions thermosteam/_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from . import equilibrium as eq
from ._chemical import Chemical
from ._chemicals import Chemicals
from .mixture import Mixture
from .mixture import Mixture, IdealMixture
from .utils import read_only, cucumber

__all__ = ('Thermo', 'IdealThermo')
Expand Down Expand Up @@ -49,8 +49,7 @@ class Thermo:
>>> thermo.show()
Thermo(
chemicals=CompiledChemicals([Ethanol, Water]),
mixture=Mixture(
rule='ideal', ...
mixture=IdealMixture(...
include_excess_energies=False
),
Gamma=DortmundActivityCoefficients,
Expand All @@ -66,8 +65,7 @@ class Thermo:
>>> ideal.show()
IdealThermo(
chemicals=CompiledChemicals([Ethanol, Water]),
mixture=Mixture(
rule='ideal', ...
mixture=IdealMixture(...
include_excess_energies=False
),
)
Expand All @@ -88,10 +86,10 @@ class Thermo:
>>> # Modified Roult's law:
>>> tmo.settings.set_thermo(thermo)
>>> stream = tmo.Stream('stream', Water=100, Ethanol=100)
>>> stream.vle(T=360, P=101325)
>>> stream.vle(T=361, P=101325)
>>> stream.show()
MultiStream: stream
phases: ('g', 'l'), T: 360 K, P: 101325 Pa
phases: ('g', 'l'), T: 361 K, P: 101325 Pa
flow (kmol/hr): (g) Ethanol 100
Water 100

Expand All @@ -102,8 +100,7 @@ class Thermo:
>>> thermo.show()
Thermo(
chemicals=CompiledChemicals([Ethanol, Water]),
mixture=Mixture(
rule='ideal', ...
mixture=IdealMixture(...
include_excess_energies=False
),
Gamma=DortmundActivityCoefficients,
Expand Down Expand Up @@ -138,7 +135,7 @@ def __init__(self, chemicals, mixture=None,
if PCF is None: PCF = eq.MockPoyintingCorrectionFactors
if not isinstance(chemicals, Chemicals): chemicals = Chemicals(chemicals, cache)
if not mixture:
mixture = Mixture.from_chemicals(chemicals)
mixture = IdealMixture.from_chemicals(chemicals)
elif not isinstance(mixture, Mixture): # pragma: no cover
raise ValueError(f"mixture must be a '{Mixture.__name__}' object")
chemicals.compile(skip_checks=skip_checks)
Expand Down
19 changes: 16 additions & 3 deletions thermosteam/equilibrium/poyinting_correction_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,20 @@ class IdealGasPoyintingCorrectionFactors(PoyintingCorrectionFactors):
__slots__ = ('_chemicals',)

def __call__(self, T, P, Psats=None):
vls = np.array([i.V('l', T, P) for i in self._chemicals], dtype=float)
vls = []
chemicals = []
index = []
for i, chemical in enumerate(self._chemicals):
try: vls.append(chemical.V('l', T, P))
except: continue
chemicals.append(chemical)
index.append(i)
vls = np.array(vls, 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)
Psats = np.array([i.Psat(T) for i in chemicals], dtype=float)
else:
Psats = Psats[index]
pcf = np.ones(len(self._chemicals))
pcf[index] = ideal_gas_poyinting_correction_factors(T, P, vls, Psats)
return pcf

6 changes: 4 additions & 2 deletions thermosteam/equilibrium/vle.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,8 @@ def set_TV(self, T, V):

self._P = thermal_condition.P = P
set_flows(self._vapor_mol, self._liquid_mol, self._index, v, mol)
self._H_hat = self.mixture.xH(self._phase_data, T, P) / self._F_mass
try: self._H_hat = self.mixture.xH(self._phase_data, T, P) / self._F_mass
except: pass

def set_TH(self, T, H):
self._setup()
Expand Down Expand Up @@ -914,7 +915,8 @@ def set_PV(self, P, V):
v = self._v
self._T = thermal_condition.T = T
set_flows(vapor_mol, liquid_mol, index, v, mol)
self._H_hat = self.mixture.xH(self._phase_data, T, P)/self._F_mass
try: self._H_hat = self.mixture.xH(self._phase_data, T, P)/self._F_mass
except: pass

def set_PS(self, P, S, stacklevel=0):
self._setup()
Expand Down
Loading
Loading