如何使用 UliEngineering 在 Python 中计算 Swindells 粘度

你可以使用 UliEngineering Python 库轻松计算 Swindells 粘度关联式。Swindells 关联式是一个常用于水粘度的经验模型:

swindells_viscosity.py
from UliEngineering.Physics.Viscosity import swindells_viscosity, CommonLiquids
from UliEngineering.EngineerIO import *

# 计算 20°C 时水的 Swindells 粘度
T = 20 + 273.15  # 转换为开尔文
eta = swindells_viscosity(T, CommonLiquids.Water.swindells)
print(f"20°C 时水的粘度:{format_value(eta, 'Pa·s')}")

# 计算 50°C 时水的 Swindells 粘度
T = 50 + 273.15
eta = swindells_viscosity(T, CommonLiquids.Water.swindells)
print(f"50°C 时水的粘度:{format_value(eta, 'Pa·s')}")

# 使用自定义的 Swindells 常数
from UliEngineering.Physics.Viscosity import SwindellsConstants
custom = SwindellsConstants(name="Custom liquid", eta_ref=1.0e-3, T_ref=293.15, a=1.5, b=-150.0)
eta = swindells_viscosity(300.0, custom)
print(f"300K 时自定义液体的粘度:{format_value(eta, 'Pa·s')}")

示例输出

swindells_viscosity_output.txt
Water viscosity at 20°C: 1.00 mPa·s
Water viscosity at 50°C: 546 µPa·s
Custom liquid viscosity at 300K: 1.00 mPa·s

Swindells 粘度图

Swindells 关联式由下式给出:

$$ \eta = \eta_{ref} \cdot 10^{\left(-\frac{a \cdot (T - T_{ref})}{T + b}\right)} $$

其中 $\eta$ 是动力粘度,$T$ 是以开尔文为单位的绝对温度,$\eta_{ref}$ 是参考温度 $T_{ref}$ 下的参考粘度,$a$ 和 $b$ 是与流体相关的经验参数。

Swindells 关联式是专门为水开发的,在很宽的温度范围内具有出色的精度。它特别适用于需要在各种温度下计算水粘度的工程应用。

上图展示了水在 0°C 到 100°C 温度范围内的 Swindells 关联式。注意粘度随温度升高而呈指数下降的特征。

UliEngineering 库通过 CommonLiquids.Water.swindells 为水提供了预定义的 Swindells 常数。对于其他流体,可以使用 SwindellsConstants dataclass 定义自定义常数。

相关文章


绘图生成脚本

plot_swindells_viscosity.py
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import numpy as np
import sys
sys.path.insert(0, '/home/uli/dev/UliEngineering')

from UliEngineering.Physics.Viscosity import (
    swindells_viscosity,
    CommonLiquids,
)

# 用于绘图的摄氏温度范围
T_C = np.linspace(0, 100, 200)  # 0 到 100°C
T_K = T_C + 273.15  # 转换为开尔文

# 创建绘图
plt.figure(figsize=(10, 6))

# 使用 Swindells 关联式绘制水的曲线
eta = swindells_viscosity(T_K, CommonLiquids.Water.swindells) * 1000  # 转换为 mPa·s
plt.plot(T_C, eta, label='Water', color='blue', linewidth=2)

plt.xlabel('Temperature (°C)', fontsize=12)
plt.ylabel('Dynamic Viscosity (mPa·s)', fontsize=12)
plt.title('Swindells Viscosity Correlation for Water', fontsize=14, fontweight='bold')
plt.legend(loc='upper right', fontsize=10)
plt.grid(True, alpha=0.3)

plt.tight_layout()
plt.savefig('swindells_viscosity_plot.svg', format='svg', dpi=300)
print("Plot saved to swindells_viscosity_plot.svg")

Check out similar posts by category: Physics, Python