Skip to content

Commit

Permalink
improve doc, docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMVale committed Nov 19, 2023
1 parent cbd78ab commit 0955cdc
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 93 deletions.
4 changes: 2 additions & 2 deletions docs/reference/properties/thermal_conductivity/KLMX2_li.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ w = np.array([0.5, 0.5])
k = np.array([0.172, 0.124]) # W/(m·K), from literature
rho = np.array([0.909, 0.681]) # kg/L

KL = KLMX2_li(w=w, k=k, rho=rho)
k_mix = KLMX2_li(w=w, k=k, rho=rho)

print(KL, "W/(m·K)")
print(k_mix, "W/(m·K)")
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Vc = 130.4 # cm3/mol
V = 2.8e3 # cm3/mol, @ 350K, 10 bar
rhor = Vc/V

KVPC = KVPC_stiel_thodos(rhor=rhor, M=28.05e-3, Tc=282.4, Pc=50.4e5, Zc=0.280)
k_residual = KVPC_stiel_thodos(rhor=rhor, M=28.05e-3, Tc=282.4, Pc=50.4e5, Zc=0.280)

print(KVPC, "W/(m·K)")
print(k_residual, "W/(m·K)")
```
6 changes: 3 additions & 3 deletions docs/reference/properties/viscosity/MULMX2_perry.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ from polykin.properties.viscosity import MULMX2_perry
import numpy as np

x = np.array([0.5, 0.5])
visc = np.array([0.76, 0.59]) # cP, from literature
MU = MULMX2_perry(x, visc)
mu = np.array([0.76, 0.59]) # cP, from literature
mu_mix = MULMX2_perry(x, mu)

print(MU, "cP")
print(mu_mix, "cP")
```
7 changes: 4 additions & 3 deletions docs/reference/properties/viscosity/MUVMX2_herning.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import numpy as np

y = np.array([0.5, 0.5])
M = np.array([28.e-3, 56.e-3])
visc = np.array([130e-7, 100e-7]) # from literature
MU = MUVMX2_herning(y, visc, M)
mu = np.array([130e-7, 100e-7]) # from literature

print(MU, "Pa.s")
mu_mix = MUVMX2_herning(y, mu, M)

print(mu_mix, "Pa.s")
```
6 changes: 3 additions & 3 deletions docs/reference/properties/viscosity/MUVMX_lucas.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ M = np.array([28.e-3, 28.e-3])
Tc = np.array([282.4, 126.2])
Pc = np.array([50.4e5, 33.9e5])
Zc = np.array([0.280, 0.290])
mu = np.array([0., 0.])
dm = np.array([0., 0.])

MU = MUVMX_lucas(T=350., P=10e5, y=y, M=M, Tc=Tc, Pc=Pc, Zc=Zc, mu=mu)
mu_mix = MUVMX_lucas(T=350., P=10e5, y=y, M=M, Tc=Tc, Pc=Pc, Zc=Zc, dm=dm)

print(MU, "Pa.s")
print(mu_mix, "Pa.s")
```
7 changes: 4 additions & 3 deletions docs/reference/properties/viscosity/MUVPC_jossi.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ from polykin.properties.viscosity import MUVPC_jossi

Vc = 130.4 # cm3/mol
V = 2.8e3 # cm3/mol, @ 350K, 10 bar
dr = Vc/V
MUPC = MUVPC_jossi(dr=dr, Tc=282.4, Pc=50.4e5, M=28.05e-3)
rhor = Vc/V

print(MUPC, "Pa.s")
mu_residual = MUVPC_jossi(rhor=rhor, Tc=282.4, Pc=50.4e5, M=28.05e-3)

print(mu_residual, "Pa.s")
```
2 changes: 1 addition & 1 deletion docs/reference/properties/viscosity/MUV_lucas.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Estimate the viscosity of ethylene at 350 K and 10 bar.
from polykin.properties.viscosity import MUV_lucas

MU = MUV_lucas(T=350., P=10e5, M=28.05e-3,
Tc=282.4, Pc=50.4e5, Zc=0.280, mu=0.)
Tc=282.4, Pc=50.4e5, Zc=0.280, dm=0.)

print(MU, "Pa.s")
```
7 changes: 4 additions & 3 deletions src/polykin/properties/thermal_conductivity/vapor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def KVPC_stiel_thodos(rhor: float,
where $k$ is the dense gas thermal conductivity, $k^\circ$ is the
low-pressure thermal conductivtiy, $\Gamma$ is a group of constants, $Z_c$
is the critical compressibility factor, and
$\rho_r = \rho / \rho_c = V_c / V$ is the reduced gas density.
$\rho_r = \rho / \rho_c = V_c / V$ is the reduced gas density. This
equation is valid in the range $0 \leq \rho_r < 2.8$.
Reference:
Expand Down Expand Up @@ -52,9 +53,9 @@ def KVPC_stiel_thodos(rhor: float,

if rhor < 0.5:
a = 1.22e-2*(np.exp(0.535*rhor) - 1)
elif rhor >= 0.5 and rhor < 2.0:
elif rhor < 2.0:
a = 1.14e-2*(np.exp(0.67*rhor) - 1.069)
elif rhor >= 2.0 and rhor < 2.8:
elif rhor < 2.8:
a = 2.60e-3*(np.exp(1.155*rhor) + 2.016)
else:
raise ValueError("Invalid `rhor` input. Valid range: `rhor` < 2.8.")
Expand Down
16 changes: 8 additions & 8 deletions src/polykin/properties/viscosity/liquid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@


def MULMX2_perry(x: FloatVector,
visc: FloatVector,
mu: FloatVector,
hydrocarbons: bool = False,
) -> float:
r"""Calculate the viscosity of a liquid mixture from the viscosities of the
pure components using the mixing rules recommended in Perry's.
For hydrocarbon mixtures:
$$ \eta_m = \left ( \sum_i x_i \eta_i^{1/3} \right )^3 $$
$$ \mu_m = \left ( \sum_i x_i \mu_i^{1/3} \right )^3 $$
and for nonhydrocarbon mixtures:
$$ \eta_m = \sum_i x_i \ln{\eta_i} $$
$$ \mu_m = \sum_i x_i \ln{\mu_i} $$
where the meaning of the parameters is as defined below.
Expand All @@ -35,19 +35,19 @@ def MULMX2_perry(x: FloatVector,
----------
x : FloatVector
Mole fractions of all components. Unit = Any.
visc : FloatVector
Viscosities of all components, $\eta$. Unit = Any.
mu : FloatVector
Viscosities of all components, $\mu$. Unit = Any.
hydrocarbons : bool
Method selection. `True` for hydrocarbon mixtures, `False` for
nonhydrocarbon mixtures.
Returns
-------
float
Mixture viscosity, $\eta_m$. Unit = [visc].
Mixture viscosity, $\mu_m$. Unit = [mu].
"""
if hydrocarbons:
result = np.dot(x, np.cbrt(visc))**3
result = np.dot(x, np.cbrt(mu))**3
else:
result = np.exp(np.dot(x, np.log(visc)))
result = np.exp(np.dot(x, np.log(mu)))
return result
93 changes: 48 additions & 45 deletions src/polykin/properties/viscosity/vapor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@


def MUVMX2_herning(y: FloatVector,
visc: FloatVector,
mu: FloatVector,
M: FloatVector
) -> float:
r"""Calculate the viscosity of a gas mixture from the viscosities of the
pure components using the mixing rule of Herning and Zipperer.
$$ \eta _m = \frac{\sum _i y_i M_i^{1/2} \eta_i}{\sum _i y_i M_i^{1/2}} $$
$$ \mu_m = \frac{\sum _i y_i M_i^{1/2} \mu_i}{\sum _i y_i M_i^{1/2}} $$
where the meaning of the parameters is as defined below.
Expand All @@ -33,35 +33,36 @@ def MUVMX2_herning(y: FloatVector,
----------
y : FloatVector
Mole fractions of all components. Unit = Any.
visc : FloatVector
Viscosities of all components, $\eta$. Unit = Any.
mu : FloatVector
Viscosities of all components, $\mu$. Unit = Any.
M : FloatVector
Molar masses of all components. Unit = Any.
Returns
-------
float
Mixture viscosity, $\eta_m$. Unit = [visc].
Mixture viscosity, $\mu_m$. Unit = [mu].
"""
a = y*np.sqrt(M)
a *= visc/np.sum(a)
a *= mu/np.sum(a)
return np.sum(a, dtype=np.float64)


def MUVPC_jossi(dr: float,
def MUVPC_jossi(rhor: float,
M: float,
Tc: float,
Pc: float,
M: float
Pc: float
) -> float:
r"""Calculate the effect of pressure (or density) on gas viscosity using
the method of Jossi, Stiel and Thodos for non-polar gases.
the method of Jossi, Stiel and Thodos for nonpolar gases.
$$ \left[(\eta -\eta^\circ)\xi + 1\right]^{1/4} = 1.0230 + 0.23364\rho_r
$$ \left[(\mu -\mu^\circ)\xi + 1\right]^{1/4} = 1.0230 + 0.23364\rho_r
+ 0.58533\rho_r^2 - 0.40758\rho_r^3 + 0.093324\rho_r^4 $$
where $\eta$ is the dense gas viscosity, $\eta^\circ$ is the is the
where $\mu$ is the dense gas viscosity, $\mu^\circ$ is the is the
low-pressure viscosity, $\xi$ is a group of constants, and
$\rho_r = \rho / \rho_c = V_c / V$.
$\rho_r = \rho / \rho_c = V_c / V$ is the reduced gas density. This
equation is valid in the range $0.1 < \rho_r < 3.0$.
Reference:
Expand All @@ -70,21 +71,22 @@ def MUVPC_jossi(dr: float,
Parameters
----------
dr : float
rhor : float
Reduced gas density, $\rho_r$.
M : float
Molar mass. Unit = kg/mol.
Tc : float
Critical temperature. Unit = K.
Pc : float
Critical pressure. Unit = Pa.
M : float
Molar mass. Unit = kg/mol.
Returns
-------
float
Residual viscosity, $\eta - \eta_0$. Unit = Pa.s.
Residual viscosity, $(\mu - \mu_0)$. Unit = Pa.s.
"""
a = 1.0230 + 0.23364*dr + 0.58533*dr**2 - 0.40758*dr**3 + 0.093324*dr**4
a = 1.0230 + 0.23364*rhor + 0.58533*rhor**2 - 0.40758*rhor**3 \
+ 0.093324*rhor**4
# 1e7*(1/((1e3)**3 * (1/101325)**4))**(1/6)
xi = 6.872969367e8*(Tc/(M**3 * Pc**4))**(1/6)
return (a**4 - 1)/xi
Expand All @@ -96,7 +98,7 @@ def MUV_lucas(T: float,
Tc: float,
Pc: float,
Zc: float,
mu: float
dm: float
) -> float:
r"""Calculate the viscosity of a pure gas at a given pressure using the
method of Lucas.
Expand All @@ -120,19 +122,19 @@ def MUV_lucas(T: float,
Critical pressure. Unit = Pa.
Zc : float
Critical compressibility factor.
mu : float
dm : float
Dipole moment. Unit = debye.
Returns
-------
float
Gas viscosity, $\eta$. Unit = Pa.s.
Gas viscosity, $\mu$. Unit = Pa.s.
"""
Tr = T/Tc
Pr = P/Pc
FP0 = _MUV_lucas_FP0(Tr, Tc, Pc, Zc, mu)
eta = _MUV_lucas_eta(Tr, Pr, M, Tc, Pc, FP0) # type: ignore
return eta
FP0 = _MUV_lucas_FP0(Tr, Tc, Pc, Zc, dm)
mu = _MUV_lucas_mu(Tr, Pr, M, Tc, Pc, FP0) # type: ignore
return mu


def MUVMX_lucas(T: float,
Expand All @@ -142,7 +144,7 @@ def MUVMX_lucas(T: float,
Tc: FloatVector,
Pc: FloatVector,
Zc: FloatVector,
mu: FloatVector
dm: FloatVector
) -> float:
r"""Calculate the viscosity of a gas mixture at a given pressure using the
method of Lucas.
Expand All @@ -168,30 +170,30 @@ def MUVMX_lucas(T: float,
Critical pressures of all components. Unit = Pa.
Zc : FloatVector
Critical compressibility factors of all components.
mu : FloatVector
dm : FloatVector
Dipole moments of all components. Unit = debye.
Returns
-------
float
Gas mixture viscosity, $\eta_m$. Unit = Pa.s.
Gas mixture viscosity, $\mu_m$. Unit = Pa.s.
"""
Tc_mix = np.dot(y, Tc)
M_mix = np.dot(y, M)
Pc_mix = R*Tc_mix*np.dot(y, Zc)/np.dot(y, R*Tc*Zc/Pc)
FP0_mix = np.dot(y, _MUV_lucas_FP0(T/Tc, Tc, Pc, Zc, mu))
eta = _MUV_lucas_eta(
FP0_mix = np.dot(y, _MUV_lucas_FP0(T/Tc, Tc, Pc, Zc, dm))
mu = _MUV_lucas_mu(
T/Tc_mix, P/Pc_mix, M_mix, Tc_mix, Pc_mix, FP0_mix)
return eta
return mu


def _MUV_lucas_eta(Tr: float,
Pr: float,
M: float,
Tc: float,
Pc: float,
FP0: float
) -> float:
def _MUV_lucas_mu(Tr: float,
Pr: float,
M: float,
Tc: float,
Pc: float,
FP0: float
) -> float:
"""Calculate the viscosity of a pure gas or gas mixture at a given pressure
using the method of Lucas.
"""
Expand Down Expand Up @@ -241,29 +243,30 @@ def _MUV_lucas_FP0(Tr: FloatOrArray,
Tc: FloatOrArray,
Pc: FloatOrArray,
Zc: FloatOrArray,
mu: FloatOrArray
dm: FloatOrArray
) -> FloatOrArray:
"Compute FP0 for Lucas method of estimating gas viscosity."
mur = 52.46 * mu**2 * (Pc / 1e5) / Tc**2
FP0 = np.where(mur <= 0.022, 0.0, 30.55 * (0.292 - Zc) ** 1.72)
FP0 = np.where(mur >= 0.075, FP0 * np.abs(0.96 + 0.1 * (Tr - 0.7)), FP0)
dmr = 52.46 * dm**2 * (Pc / 1e5) / Tc**2
FP0 = np.where(dmr <= 0.022, 0.0, 30.55 * (0.292 - Zc) ** 1.72)
FP0 = np.where(dmr >= 0.075, FP0 * np.abs(0.96 + 0.1 * (Tr - 0.7)), FP0)
FP0 += 1.0
return FP0


# @np.vectorize
# def _visc_gas_lucas_FP0(T: float,
# Tc: float,
# Pc: float,
# Zc: float,
# mu: float
# dm: float
# ) -> float:
# "Compute FP0 for Lucas method of gas viscosity estimation."
# mur = 52.46*mu**2*(Pc/1e5)/Tc**2
# if mur <= 0.022:
# dmr = 52.46*dm**2*(Pc/1e5)/Tc**2
# if dmr <= 0.022:
# FP0 = 1.
# else:
# FP0 = 30.55*(0.292 - Zc)**1.72
# if mur >= 0.075:
# if dmr >= 0.075:
# FP0 *= np.abs(0.96 + 0.1*(T/Tc - 0.7))
# FP0 += 1.
# return FP0
Loading

0 comments on commit 0955cdc

Please sign in to comment.