Poiseuille flow in ESPResSo¶
Poiseuille flow is the flow through a pipe or (in our case) a slit under a homogeneous force density, e.g. gravity. In the limit of small Reynolds numbers, the flow can be described with the Stokes equation. We assume the slit being infinitely extended in $y$ and $z$ direction and a force density $f_y$ on the fluid in $y$ direction. No slip-boundary conditions (i.e. $\vec{u}=0$) are located at $x = \pm h/2$. Assuming invariance in $y$ and $z$ direction and a steady state, the Stokes equation is simplified to:
\begin{equation} \mu \partial_x^2 u_y = f_y \end{equation}
where $f_y$ denotes the force density and $\mu$ the dynamic viscosity. This can be integrated twice and the integration constants are chosen so that $u_y=0$ at $x = \pm h/2$ to obtain the solution to the planar Poiseuille flow [8]:
\begin{equation} u_y(x) = \frac{f_y}{2\mu} \left(h^2/4-x^2\right) \end{equation}
We will simulate a planar Poiseuille flow using a square box, two walls with normal vectors $\left(\pm 1, 0, 0 \right)$, and an external force density applied to every node.
1. Setting up the system¶
import logging
import sys
%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams.update({'font.size': 14})
import numpy as np
import tqdm.auto as tqdm
import espressomd
import espressomd.lb
import espressomd.shapes
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
espressomd.assert_features(['WALBERLA'])
# System constants
BOX_L = 16.0
TIME_STEP = 0.01
system = espressomd.System(box_l=[BOX_L] * 3)
system.time_step = TIME_STEP
system.cell_system.skin = 0.4
/usr/lib/python3/dist-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from .autonotebook import tqdm as notebook_tqdm
1.1 Setting up the lattice-Boltzmann fluid¶
We will now create a lattice-Boltzmann fluid confined between two walls.
# LB parameters
AGRID = 0.5
VISCOSITY = 2.0
FORCE_DENSITY = [0.0, 0.001, 0.0]
DENSITY = 1.5
# LB boundary parameters
WALL_OFFSET = AGRID
Create a lattice-Boltzmann actor and attach it to the system. Use the GPU implementation of LB.
You can refer to section setting up a LB fluid in the user guide.
# SOLUTION CELL
logging.info("Setup LB fluid.")
lbf = espressomd.lb.LBFluid(agrid=AGRID, density=DENSITY,
kinematic_viscosity=VISCOSITY,
tau=TIME_STEP,
ext_force_density=FORCE_DENSITY)
system.lb = lbf
INFO:root:Setup LB fluid.
Use the convenience function add_boundary_from_shape of the LB actor to mark nodes within a shape as boundaries.
# SOLUTION CELL
logging.info("Setup LB boundaries.")
top_wall = espressomd.shapes.Wall(normal=[1, 0, 0], dist=WALL_OFFSET)
bottom_wall = espressomd.shapes.Wall(normal=[-1, 0, 0], dist=-(BOX_L - WALL_OFFSET))
lbf.add_boundary_from_shape(top_wall)
lbf.add_boundary_from_shape(bottom_wall)
INFO:root:Setup LB boundaries.
2. Simulation¶
We will now simulate the fluid flow until we reach the steady state.
logging.info("Iterate until the flow profile converges (5000 LB updates).")
for _ in tqdm.trange(20):
system.integrator.run(5000 // 20)
INFO:root:Iterate until the flow profile converges (5000 LB updates).
0%| | 0/20 [00:00<?, ?it/s]
5%|▌ | 1/20 [00:01<00:33, 1.78s/it]
10%|â–ˆ | 2/20 [00:03<00:33, 1.85s/it]
15%|█▌ | 3/20 [00:06<00:37, 2.23s/it]
20%|██ | 4/20 [00:08<00:34, 2.15s/it]
25%|██▌ | 5/20 [00:10<00:31, 2.11s/it]
30%|███ | 6/20 [00:12<00:29, 2.09s/it]
35%|███▌ | 7/20 [00:14<00:27, 2.08s/it]
40%|████ | 8/20 [00:16<00:25, 2.11s/it]
45%|████▌ | 9/20 [00:18<00:23, 2.14s/it]
50%|█████ | 10/20 [00:21<00:21, 2.13s/it]
55%|█████▌ | 11/20 [00:23<00:18, 2.08s/it]
60%|██████ | 12/20 [00:24<00:16, 2.03s/it]
65%|██████▌ | 13/20 [00:26<00:13, 1.97s/it]
70%|███████ | 14/20 [00:28<00:11, 1.94s/it]
75%|███████▌ | 15/20 [00:30<00:09, 1.90s/it]
80%|████████ | 16/20 [00:32<00:07, 1.90s/it]
85%|████████▌ | 17/20 [00:34<00:05, 1.94s/it]
90%|█████████ | 18/20 [00:36<00:03, 1.89s/it]
95%|█████████▌| 19/20 [00:38<00:01, 1.90s/it]
100%|██████████| 20/20 [00:39<00:00, 1.89s/it]
100%|██████████| 20/20 [00:39<00:00, 2.00s/it]
3. Data analysis¶
We can now extract the flow profile and compare it to the analytical solution for the planar Poiseuille flow.
logging.info("Extract fluid velocities along the x-axis")
fluid_positions = (np.arange(lbf.shape[0]) + 0.5) * AGRID
# get all velocities as Numpy array and extract y components only
fluid_velocities = (lbf[:,:,:].velocity)[:,:,:,1]
# average velocities in y and z directions (perpendicular to the walls)
fluid_velocities = np.average(fluid_velocities, axis=(1,2))
def poiseuille_flow(x, force_density, dynamic_viscosity, height):
return force_density / (2 * dynamic_viscosity) * (height**2 / 4 - x**2)
# Note that the LB viscosity is not the dynamic viscosity but the
# kinematic viscosity (mu=LB_viscosity * density)
x_values = np.linspace(0.0, BOX_L, lbf.shape[0])
HEIGHT = BOX_L - 2.0 * AGRID
# analytical curve
y_values = poiseuille_flow(x_values - (HEIGHT / 2 + AGRID), FORCE_DENSITY[1],
VISCOSITY * DENSITY, HEIGHT)
# velocity is zero inside the walls
y_values[np.nonzero(x_values < WALL_OFFSET)] = 0.0
y_values[np.nonzero(x_values > BOX_L - WALL_OFFSET)] = 0.0
fig1 = plt.figure(figsize=(10, 6))
plt.plot(x_values, y_values, '-', linewidth=2, label='analytical')
plt.plot(fluid_positions, fluid_velocities, 'o', label='simulation')
plt.xlabel('Position on the $x$-axis')
plt.ylabel('Fluid velocity in $y$-direction')
plt.legend()
plt.show()
INFO:root:Extract fluid velocities along the x-axis