Skip to content

Commit

Permalink
0.46.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Nov 6, 2024
1 parent 69ec92b commit efd191a
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 156 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
name='thermosteam',
packages=['thermosteam'],
license='MIT',
version='0.45.0',
version='0.46.0',
description="BioSTEAM's Premier Thermodynamic Engine",
long_description=open('README.rst', encoding='utf-8').read(),
author='Yoel Cortes-Pena',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class Split(tmo.AbstractUnit):

# Test ins size not fixed
M.ins[0].disconnect_sink()
assert len(M.ins) == 1 and isinstance(M.ins[0], tmo.AbstractStream)
assert len(M.ins) == 2 and isinstance(M.ins[0], tmo.AbstractMissingStream) and isinstance(M.ins[1], tmo.AbstractStream)

# Test ins size fixed
S.ins[0].disconnect_sink()
assert len(S.ins) == 1 and isinstance(S.ins[0], tmo.AbstractMissingStream)

# Test outs size not fixed
S.outs[0].disconnect_source()
assert len(S.outs) == 1 and isinstance(S.outs[0], tmo.AbstractStream)
assert len(S.outs) == 2 and isinstance(S.outs[0], tmo.AbstractMissingStream) and isinstance(S.outs[1], tmo.AbstractStream)


if __name__ == '__main__':
Expand Down
253 changes: 131 additions & 122 deletions tests/test_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,130 +265,139 @@ def test_reactive_phase_equilibrium_no_kinetics():
)

# TODO: Fix kinetics!
# def test_reactive_phase_equilibrium_with_kinetics():
# import thermosteam as tmo
# from math import exp
# from numpy.testing import assert_allclose
# tmo.settings.set_thermo(['EthylLactate', 'LacticAcid', 'H2O', 'Ethanol'], cache=True)
def test_reactive_phase_equilibrium_with_kinetics():
import thermosteam as tmo
from math import exp
from numpy.testing import assert_allclose
tmo.settings.set_thermo(['EthylLactate', 'LacticAcid', 'H2O', 'Ethanol'], cache=True)

# class Esterification(tmo.KineticReaction):
class Esterification(tmo.KineticReaction):

# def volume(self, stream):
# return 0.01 # Kg of catalyst
def volume(self, stream):
return 0.001 # Kg of catalyst

# def rate(self, stream):
# T = stream.T
# if T > 370: return 0 # Prevents multiple steady states.
# R = tmo.constants.R
# kf = 6.52e3 * exp(-4.8e4 / (R * T))
# kr = 2.72e3 * exp(-4.8e4 / (R * T))
# LaEt, La, H2O, EtOH = stream.mol / stream.F_mol
# return 3600 * (kf * La * EtOH - kr * LaEt * H2O) # kmol / kg-catalyst / hr

# rxn = Esterification('LacticAcid + Ethanol -> H2O + EthylLactate', reactant='LacticAcid')
# stream = tmo.Stream(
# H2O=2, Ethanol=5, LacticAcid=1, T=355,
# )
# mol_original = stream.mol
# F_mass = stream.F_mass
# stream.vle(T=360, P=101325, liquid_conversion=rxn)
# liq_new = tmo.Stream(flow=stream.imol['l'].copy())
# dliq = rxn.conversion(liq_new)
# assert_allclose(stream.F_mass, F_mass)
# assert_allclose(stream.mol, mol_original + dliq, rtol=1e-6)
# rxn(stream)
# assert_allclose(
# stream.mol,
# [0.0015876828181456534,
# 0.9984123171818543,
# 2.001587682818146,
# 4.998412317181854],
# atol=1e-3,
# rtol=1e-3,
# )
# stream = tmo.Stream(
# H2O=2, Ethanol=5, LacticAcid=1, T=355,
# )
# T = 360
# P = 101325
# stream.vle(T=T, P=P, liquid_conversion=rxn)
# assert_allclose(
# stream.imol['l'],
# [0.026512250430257022,
# 0.9451332614822996,
# 0.8872670426652305,
# 1.7832800372000892],
# rtol=1e-3,
# atol=1e-3,
# )
# assert_allclose(
# stream.imol['g'],
# [0.0, 0.028354488087443397, 1.1392452077650264, 3.1902077123696535],
# rtol=1e-3,
# atol=1e-3,
# )
# V = stream.vapor_fraction
# H = stream.H + stream.Hf
# stream = tmo.Stream(
# H2O=2, Ethanol=5, LacticAcid=1, T=T,
# )
# stream.vle(V=V, P=P, liquid_conversion=rxn)
# assert_allclose(
# stream.imol['l'],
# [0.0265122504353963,
# 0.9451332614841681,
# 0.8872670426420364,
# 1.7832800356800504],
# rtol=1e-3,
# atol=1e-3,
# )
# assert_allclose(
# stream.imol['g'],
# [0.0, 0.028354488080435617, 1.13924520779336, 3.1902077138845533],
# rtol=1e-3,
# atol=1e-3,
# )
# stream = tmo.Stream(
# H2O=2, Ethanol=5, LacticAcid=1, T=T,
# )
# stream.vle(V=V, T=T, liquid_conversion=rxn)
# assert_allclose(
# stream.imol['l'],
# [0.026512250408482565,
# 0.9451332615716925,
# 0.8872670442912585,
# 1.7832800377855502],
# rtol=1e-3,
# atol=1e-3,
# )
# assert_allclose(
# stream.imol['g'],
# [0.0, 0.02835448801982482, 1.1392452061172242, 3.190207711805967],
# rtol=1e-3,
# atol=1e-3,
# )
# stream = tmo.Stream(
# H2O=2, Ethanol=5, LacticAcid=1, T=T,
# )
# stream.vle(H=H, P=P, liquid_conversion=rxn)
# assert_allclose(
# stream.imol['l'],
# [0.026512250412710874,
# 0.945133261339238,
# 0.8872670433265364,
# 1.7832800367594983],
# rtol=1e-3,
# atol=1e-3,
# )
# assert_allclose(
# stream.imol['g'],
# [4.9752893699702054e-12,
# 0.0283544882430759,
# 1.1392452070911496,
# 3.190207712822816],
# rtol=1e-3,
# atol=1e-3,
# )
def rate(self, stream):
T = stream.T
if T > 370: return 0 # Prevents multiple steady states.
R = tmo.constants.R
kf = 6.52e3 * exp(-4.8e4 / (R * T))
kr = 2.72e3 * exp(-4.8e4 / (R * T))
LaEt, La, H2O, EtOH = stream.mol / stream.F_mol
return 3600 * (kf * La * EtOH - kr * LaEt * H2O) # kmol / kg-catalyst / hr

rxn = Esterification('LacticAcid + Ethanol -> H2O + EthylLactate', reactant='LacticAcid')
stream = tmo.Stream(
H2O=2, Ethanol=5, LacticAcid=1, T=355,
)
mol_original = stream.mol
F_mass = stream.F_mass
stream.vle(T=360, P=101325, liquid_conversion=rxn)
liq_new = tmo.Stream(flow=stream.imol['l'].copy(), T=360, P=101325)
dliq = rxn.conversion(liq_new)
assert_allclose(stream.F_mass, F_mass)
assert_allclose(stream.mol, mol_original + dliq, atol=1e-2, rtol=1e-6)
rxn(stream)
assert_allclose(
stream.mol,
[0.0027372232703874026,
0.9972627767296126,
2.0027372232703873,
4.997262776729612],
atol=1e-3,
rtol=1e-3,
)
stream = tmo.Stream(
H2O=2, Ethanol=5, LacticAcid=1, T=355,
)
T = 360
P = 101325
stream.vle(T=T, P=P, liquid_conversion=rxn)
assert_allclose(
stream.imol['l'],
[0.0025656299861595427,
0.9953743460341485,
0.8534956958780036,
1.814963260010252],
rtol=1e-3,
atol=1e-3,
)
assert_allclose(
stream.imol['g'],
[0.0001715932842278598,
0.0018884306954640294,
1.1492415273923837,
3.18229951671936],
rtol=1e-3,
atol=1e-3,
)
V = stream.vapor_fraction
H = stream.H + stream.Hf
stream = tmo.Stream(
H2O=2, Ethanol=5, LacticAcid=1, T=T,
)
stream.vle(V=V, P=P, liquid_conversion=rxn)
assert_allclose(
stream.imol['l'],
[0.002565629805882328,
0.9953743462470112,
0.853495772294828,
1.8149631824466637],
rtol=1e-3,
atol=1e-3,
)
assert_allclose(
stream.imol['g'],
[0.0001715933162454465,
0.0018884306308610292,
1.1492414508272997,
3.1822995944312087],
rtol=1e-3,
atol=1e-3,
)
stream = tmo.Stream(
H2O=2, Ethanol=5, LacticAcid=1, T=T,
)
stream.vle(V=V, T=T, liquid_conversion=rxn)
assert_allclose(
stream.imol['l'],
[0.0025656303993929954,
0.9953743433287133,
0.853495226089156,
1.814961876362787],
rtol=1e-3,
atol=1e-3,
)
assert_allclose(
stream.imol['g'],
[0.0001715935470026392,
0.0018884327248910547,
1.1492419978572395,
3.1823008996908175],
rtol=1e-3,
atol=1e-3,
)
stream = tmo.Stream(
H2O=2, Ethanol=5, LacticAcid=1, T=T,
)
stream.vle(H=H, P=P, liquid_conversion=rxn)
assert_allclose(
stream.imol['l'],
[0.0025656298107399112,
0.995374346155454,
0.853495769770851,
1.814963176478684],
rtol=1e-3,
atol=1e-3,
)
assert_allclose(
stream.imol['g'],
[0.00017159331767585686,
0.0018884307161302612,
1.149241453357565,
3.1822996003929],
rtol=1e-3,
atol=1e-3,
)


def test_repr():
Expand Down Expand Up @@ -420,5 +429,5 @@ def test_repr():
test_reaction_enthalpy_balance()
test_reaction_enthalpy_with_phases()
test_reactive_phase_equilibrium_no_kinetics()
# test_reactive_phase_equilibrium_with_kinetics()
test_reactive_phase_equilibrium_with_kinetics()
test_repr()
2 changes: 1 addition & 1 deletion thermosteam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# update_module(chemicals, numba)
# use_numba_chemicals()
# del use_numba_chemicals
__version__ = "0.45.0"
__version__ = "0.46.0"

from . import thermo
del thermo
Expand Down
6 changes: 3 additions & 3 deletions thermosteam/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,12 @@ def _create_material_balance_equations(self):
def _create_energy_departure_equations(self):
return [i() for i in self.energy_equations]

def _update_energy_departure_coefficient(self, coefficients, temperature_only):
def _update_energy_departure_coefficient(self, coefficients):
source = self.source
if source is None: return
if source is None or not source.system.recycle: return
if not source._get_energy_departure_coefficient:
raise NotImplementedError(f'{source!r} has no method `_get_energy_departure_coefficient`')
coeff = source._get_energy_departure_coefficient(self, temperature_only)
coeff = source._get_energy_departure_coefficient(self)
if coeff is None: return
key, value = coeff
coefficients[key] = value
Expand Down
4 changes: 2 additions & 2 deletions thermosteam/equilibrium/bubble_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def solve_Ty(self, z, P, liquid_conversion=None):
N = positives.sum()
if N == 0:
raise ValueError('no components present')
if N == 1:
if N == 1 and liquid_conversion is None:
chemical = self.chemicals[fn.first_true_index(positives)]
T = chemical.Tsat(P, check_validity=False) if P <= chemical.Pc else chemical.Tc
y = z.copy()
Expand Down Expand Up @@ -320,7 +320,7 @@ def solve_Py(self, z, T, liquid_conversion=None):
N = positives.sum()
if N == 0:
raise ValueError('no components present')
if N == 1:
if N == 1 and liquid_conversion is None:
chemical = self.chemicals[fn.first_true_index(positives)]
P = chemical.Psat(T) if T <= chemical.Tc else chemical.Pc
y = z.copy()
Expand Down
2 changes: 1 addition & 1 deletion thermosteam/equilibrium/dew_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# %% Solvers

@njit(cache=True)
# @njit(cache=True)
def gamma_iter(gamma, x_gamma, T, P, f_gamma, gamma_args):
# Add back trace amounts for activity coefficients at infinite dilution
x = x_gamma / gamma
Expand Down
24 changes: 0 additions & 24 deletions thermosteam/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,30 +1468,6 @@ def add_bounded_numerical_specification(self, f=None, *args, **kwargs):
self._specifications.append(BoundedNumericalSpecification(f, *args, **kwargs))
return f

def run_phenomena(self):
"""
Run mass and energy balance without converging phenomena. This method also runs specifications
user defined specifications unless it is being run within a
specification (to avoid infinite loops).
See Also
--------
_run
specifications
add_specification
add_bounded_numerical_specification
"""
if self._skip_simulation_when_inlets_are_empty and all([i.isempty() for i in self._ins]):
for i in self._outs: i.empty()
return
if hasattr(self, '_run_phenomena'):
self._run = self._run_phenomena
try: self._run_with_specifications()
finally: del self._run
else:
self._run_with_specifications()

def run(self):
"""
Run mass and energy balance. This method also runs specifications
Expand Down

0 comments on commit efd191a

Please sign in to comment.