Skip to content

Commit

Permalink
add support for convinience math methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Sep 11, 2023
1 parent b6b0d6e commit 4c9cbb0
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion thermosteam/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import biosteam as bst
# from .constants import g

__all__ = ('Stream', )
__all__ = ('Stream',)

# %% Utilities

Expand Down Expand Up @@ -2757,3 +2757,53 @@ def print(self, units: Optional[str]=None):
price = utils.repr_kwarg('price', self.price)
print(f"{type(self).__name__}(ID={repr(self.ID)}, phase={repr(self.phase)}, T={self.T:.2f}, "
f"P={self.P:.6g}{price}{chemical_flows}, units={repr(units)})")

# Convinience math methods for scripting

def __add__(self, other):
return Stream.sum([self, other])

def __radd__(self, other):
return Stream.sum([self, other])

def __sub__(self, other):
new = self.copy()
new.separate_out(other)
return new

def __iadd__(self, other):
self.mix_from([self, other])
return self

def __isub__(self, other):
self.separate_out(other)
return self

def __neg__(self):
new = self.copy()
new._imol.data *= -1
return new

def __mul__(self, other):
new = self.copy()
new._imol.data *= other
return new

def __rmul__(self, other):
new = self.copy()
new._imol.data *= other
return new

def __truediv__(self, other):
new = self.copy()
new._imol.data /= other
return new

def __imul__(self, other):
self._imol.data *= other
return self

def __itruediv__(self, other):
self._imol.data /= other
return self

0 comments on commit 4c9cbb0

Please sign in to comment.