Skip to content

Commit

Permalink
thermoprops working on python - Need to automatize tests for them and…
Browse files Browse the repository at this point in the history
… complete API documentation
  • Loading branch information
SalvadorBrandolin committed Dec 7, 2024
1 parent 390fa43 commit 3356074
Showing 1 changed file with 106 additions and 3 deletions.
109 changes: 106 additions & 3 deletions python/yaeos/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
class GeModel(ABC):
"""Excess Gibbs (Ge) model abstract class."""

def ln_gamma(self, moles, temperature):
r"""Calculate activity coefficients.
def ln_gamma(
self, moles, temperature: float, dt: bool = False, dn: bool = False
) -> Union[np.ndarray, tuple[np.ndarray, dict]]:
r"""Calculate natural logarithm of activity coefficients.
Calculate :math:`\ln \gamma_i(n,T)` vector.
Expand Down Expand Up @@ -49,7 +51,108 @@ def ln_gamma(self, moles, temperature):
print(nrtl.ln_gamma([5.0, 5.6], 300.0))
"""
return yaeos_c.ln_gamma(self.id, moles, temperature)
nc = len(moles)

dt = np.empty(nc, order="F") if dt else None
dn = np.empty((nc, nc), order="F") if dn else None

res = yaeos_c.ln_gamma_ge(
self.id,
moles,
temperature,
dlngamma_dt=dt,
dlngamma_dn=dn,
)

if dt is None and dn is None:
...
else:
res = (res, {"dt": dt, "dn": dn})
return res

def excess_enthalpy(
self, moles, temperature: float, dt: bool = False, dn: bool = False
) -> Union[np.ndarray, tuple[np.ndarray, dict]]:
"""Calculate excess enthalpy [bar L].
Parameters
----------
moles : array_like
Moles number vector [mol]
temperature : float
Temperature [K]
dt : bool, optional
Calculate temperature derivative, by default False
dn : bool, optional
Calculate moles derivative, by default False
Returns
-------
Union[np.ndarray, tuple[np.ndarray, dict]]
Excess enthalpy or tuple with excess enthalpy and derivatives
dictionary if any derivative is asked [bar L]
"""
nc = len(moles)

dt = np.empty(1, order="F") if dt else None
dn = np.empty(nc, order="F") if dn else None

res = yaeos_c.excess_enthalpy_ge(
self.id,
moles,
temperature,
het=dt,
hen=dn,
)

if dt is None and dn is None:
...
else:
res = (res, {"dt": dt, "dn": dn})

return res

def excess_entropy(
self, moles, temperature: float, dt: bool = False, dn: bool = False
) -> Union[np.ndarray, tuple[np.ndarray, dict]]:
"""Calculate excess entropy [bar L / K].
Parameters
----------
moles : array_like
Moles number vector [mol]
temperature : float
Temperature [K]
dt : bool, optional
Calculate temperature derivative, by default False
dn : bool, optional
Calculate moles derivative, by default False
Returns
-------
Union[np.ndarray, tuple[np.ndarray, dict]]
Excess entropy or tuple with excess entropy and derivatives
dictionary if any derivative is asked [bar L / K]
"""
nc = len(moles)

dt = np.empty(1, order="F") if dt else None
dn = np.empty(nc, order="F") if dn else None

res = yaeos_c.excess_entropy_ge(
self.id,
moles,
temperature,
set=dt,
sen=dn,
)

if dt is None and dn is None:
...
else:
res = (res, {"dt": dt, "dn": dn})

return res

def __del__(self) -> None:
"""Delete the model from the available models list (Fortran side)."""
Expand Down

0 comments on commit 3356074

Please sign in to comment.