How to compute Swindells viscosity in Python using UliEngineering
You can easily compute the Swindells viscosity correlation using the UliEngineering Python library. The Swindells correlation is an empirical model commonly used for water viscosity:
from UliEngineering.Physics.Viscosity import swindells_viscosity, CommonLiquids
from UliEngineering.EngineerIO import *
# Compute Swindells viscosity of water at 20°C
T = 20 + 273.15 # Convert to Kelvin
eta = swindells_viscosity(T, CommonLiquids.Water.swindells)
print(f"Water viscosity at 20°C: {format_value(eta, 'Pa·s')}")
# Compute Swindells viscosity of water at 50°C
T = 50 + 273.15
eta = swindells_viscosity(T, CommonLiquids.Water.swindells)
print(f"Water viscosity at 50°C: {format_value(eta, 'Pa·s')}")
# Using custom Swindells constants
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"Custom liquid viscosity at 300K: {format_value(eta, 'Pa·s')}")Example output
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·sThe Swindells correlation is given by:
$$ \eta = \eta_{ref} \cdot 10^{\left(-\frac{a \cdot (T - T_{ref})}{T + b}\right)} $$where $\eta$ is the dynamic viscosity, $T$ is the absolute temperature in Kelvin, $\eta_{ref}$ is the reference viscosity at reference temperature $T_{ref}$, and $a$ and $b$ are empirical parameters specific to the fluid.
The Swindells correlation was developed specifically for water and provides excellent accuracy over a wide temperature range. It is particularly useful in engineering applications where water viscosity needs to be calculated at various temperatures.
The plot above shows the Swindells correlation for water over a temperature range from 0°C to 100°C. Notice the characteristic exponential decrease in viscosity with increasing temperature.
The UliEngineering library provides pre-defined Swindells constants for water through CommonLiquids.Water.swindells. Custom constants can be defined using the SwindellsConstants dataclass for other fluids.
Related posts
- How to compute Andrade viscosity in Python using UliEngineering
- How to compute VFT viscosity in Python using UliEngineering
- How to compute Kestin viscosity in Python using UliEngineering
Plot generation script
#!/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,
)
# Temperature range in Celsius for plotting
T_C = np.linspace(0, 100, 200) # 0 to 100°C
T_K = T_C + 273.15 # Convert to Kelvin
# Create plot
plt.figure(figsize=(10, 6))
# Plot for water using Swindells correlation
eta = swindells_viscosity(T_K, CommonLiquids.Water.swindells) * 1000 # Convert to 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")