Skip to content

Commit

Permalink
ENH: Update python wrappers for r797_.
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanSkocic committed Jun 29, 2024
1 parent 0a54a45 commit 2b3cf3e
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 7 deletions.
10 changes: 5 additions & 5 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@



print("########################## IAPWS G7-04 ##########################")
print("########################## IAPWS R7-97 ##########################")
Ts = np.asarray([-1.0, 25.0, 100.0, 200.0, 300.0, 360.0, 374.0])
Ts = Ts + 273.15


ps = np.asarray(pyiapws.r797.psat(Ts))
ps = pyiapws.r797.psat(Ts)
for i in range(Ts.size):
print(f"{Ts[i]:23.3f} K {ps[i]:23.3f} MPa.")

Ts = np.asarray(pyiapws.r797.Tsat(ps))
Ts = pyiapws.r797.Tsat(ps)
for i in range(Ts.size):
print(f"{Ts[i]:23.3f} K {ps[i]:23.3f} MPa.")

Expand All @@ -114,10 +114,10 @@
Ts = np.linspace(0.0, 370.0, 500)
Ts = Ts + 273.15

ps = np.asarray(pyiapws.r797.psat(Ts))
ps = pyiapws.r797.psat(Ts)
ax.plot(Ts, ps, "r-", label="ps(Ts)")

Ts = np.asarray(pyiapws.r797.Tsat(ps))
Ts = pyiapws.r797.Tsat(ps)
ax.plot(Ts, ps, "b--", label="Ts(ps)")

ax.legend()
Expand Down
9 changes: 8 additions & 1 deletion py/src/pyiapws/g704.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def kd(T: np.ndarray, gas: str, heavywater: bool=False)->Union[np.ndarray, float
kd: float or 1d-array
Adimensional liquid-vapor constant.
"""
scalar = False
if isinstance(T, (int, float)):
T_ = np.asarray((T,), dtype="f8")
scalar = True
elif isinstance(T, np.ndarray):
if T.ndim == 1:
T_ = np.asarray(T, dtype="f8")
Expand All @@ -83,7 +85,12 @@ def kd(T: np.ndarray, gas: str, heavywater: bool=False)->Union[np.ndarray, float
gas_ = str(gas)
heavywater_ = bool(heavywater)

return g704_.kd(T_, gas_, heavywater_)
k = g704_.kd(T_, gas_, heavywater_)

if scalar:
return k[0]
else:
return k


def ngases(heavywater:bool=False)->int:
Expand Down
78 changes: 77 additions & 1 deletion py/src/pyiapws/r797.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,78 @@
"""IAPWS R797"""
from .r797_ import *
import array
import numpy as np
from . import r797_


def psat(Ts):
"""
Compute the saturation pressure at temperature Ts.
Validity range 273.13 K <= Ts <= 647.096 K.
Parameters
----------
Ts: int, float or 1d-array.
Saturation temperature in K.
Returns
-------
ps: float or 1d-array
Saturation pressure in MPa.
"""
scalar = False
if isinstance(Ts, (int, float)):
Ts_ = np.asarray((Ts,), dtype="f8")
scalar = True
elif isinstance(Ts, np.ndarray):
if Ts.ndim == 1:
Ts_ = np.asarray(Ts, dtype="f8")
else:
raise TypeError("Ts must be a 1d-array of floats.")
elif isinstance(Ts, array.array):
Ts_ = np.asarray(Ts, dtype="f8")
else:
raise TypeError("Ts must be a 1d-array of floats.")

ps = np.asarray( r797_.psat(Ts_) )

if scalar:
return ps[0]
else:
return ps


def Tsat(ps):
"""
Compute the saturation temperature at pressure ps.
Validity range 611.213 Pa <= ps <= 22.064 MPa.
Parameters
----------
ps: int, float or 1d-array.
Saturation pressure in MPa.
Returns
-------
Ts: float or 1d-array
Saturation temperatur in K.
"""
scalar = False
if isinstance(ps, (int, float)):
ps_ = np.asarray((ps,), dtype="f8")
scalar = True
elif isinstance(ps, np.ndarray):
if ps.ndim == 1:
ps_ = np.asarray(ps, dtype="f8")
else:
raise TypeError("ps must be a 1d-array of floats.")
elif isinstance(ps, array.array):
ps_ = np.asarray(ps, dtype="f8")
else:
raise TypeError("ps must be a 1d-array of floats.")

Ts = np.asarray( r797_.Tsat(ps_) )

if scalar:
return Ts[0]
else:
return Ts

0 comments on commit 2b3cf3e

Please sign in to comment.