How to compute Andrade viscosity in Python using UliEngineering
You can easily compute the Andrade viscosity of liquids using the UliEngineering Python library. The Andrade equation is an Arrhenius-type model that describes the temperature dependence of viscosity:
from UliEngineering.Physics.Viscosity import andrade_viscosity, CommonLiquids
from UliEngineering.EngineerIO import *
# Compute Andrade viscosity of water at 20°C
T = 20 + 273.15 # Convert to Kelvin
eta = andrade_viscosity(T, CommonLiquids.Water.andrade)
print(f"Water viscosity at 20°C: {format_value(eta, 'Pa·s')}")
# Compute Andrade viscosity of ethanol at 50°C
T = 50 + 273.15
eta = andrade_viscosity(T, CommonLiquids.Ethanol.andrade)
print(f"Ethanol viscosity at 50°C: {format_value(eta, 'Pa·s')}")
# Using custom Andrade constants
from UliEngineering.Physics.Viscosity import AndradeConstants
custom = AndradeConstants(name="Custom liquid", A=1.0e-6, B=2000.0)
eta = andrade_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
Ethanol viscosity at 50°C: 1.05 µPa·s
Custom liquid viscosity at 300K: 2.35 mPa·sThe Andrade equation is given by:
$$ \eta = A \cdot \exp\left(\frac{B}{T}\right) $$where $\eta$ is the dynamic viscosity, $T$ is the absolute temperature in Kelvin, and $A$ and $B$ are material-specific constants. The parameter $B$ is related to the activation energy of viscous flow.
The plot above shows the Andrade viscosity model for several common liquids over a temperature range from 0°C to 100°C. Notice that viscosity decreases exponentially with temperature, which is characteristic of most liquids.
The UliEngineering library provides pre-defined Andrade constants for common liquids like Water, Ethanol, Methanol, Glycerol, Olive Oil, Mercury, Acetone, and Benzene through the CommonLiquids class.
Related posts
- How to compute VFT viscosity in Python using UliEngineering
- How to compute Sutherland gas viscosity in Python using UliEngineering
- How to compute Swindells 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 (
andrade_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 different common liquids
liquids_to_plot = [
('Water', CommonLiquids.Water.andrade, 'blue'),
('Ethanol', CommonLiquids.Ethanol.andrade, 'green'),
('Methanol', CommonLiquids.Methanol.andrade, 'red'),
('Glycerol', CommonLiquids.Glycerol.andrade, 'purple'),
('Mercury', CommonLiquids.Mercury.andrade, 'orange'),
]
for name, constants, color in liquids_to_plot:
eta = andrade_viscosity(T_K, constants) * 1000 # Convert to mPa·s
plt.plot(T_C, eta, label=name, color=color, linewidth=2)
plt.xlabel('Temperature (°C)', fontsize=12)
plt.ylabel('Dynamic Viscosity (mPa·s)', fontsize=12)
plt.title('Andrade Viscosity Model for Common Liquids', fontsize=14, fontweight='bold')
plt.legend(loc='upper right', fontsize=10)
plt.grid(True, alpha=0.3)
plt.yscale('log') # Log scale because viscosities span orders of magnitude
plt.tight_layout()
plt.savefig('andrade_viscosity_plot.svg', format='svg', dpi=300)
print("Plot saved to andrade_viscosity_plot.svg")