In this tutorial, we consider the classical \(\DdQq{2}{9}\) to simulate a Poiseuille flow modeling by the Navier-Stokes equations.
In the following, we build the dictionary of the simulation step by step.
The simulation is done on a rectangle of length \(L\) and width \(W\). We can use \(L=W=1\).
We propose a dictionary that build the geometry of the domain. The labels of the bounds can be specified to different values for the moment.
Geometry informations
spatial dimension: 2
bounds of the box:
[[ 0. 1. ]
[-0.5 0.5]]
The stencil of the \(\DdQq{2}{9}\) is composed by the nine following velocities in 2D:
Stencil informations
* spatial dimension: 2
* maximal velocity in each direction: [1 1]
* minimal velocity in each direction: [-1 -1]
* Informations for each elementary stencil:
stencil 0
- number of velocities: 9
- velocities: (0: 0, 0), (1: 1, 0), (2: 0, 1), (3: -1, 0), (4: 0, -1), (5: 1, 1), (6: -1, 1), (7: -1, -1), (8: 1, -1),
In order to build the domain of the simulation, the dictionary should contain the space step \(\dx\) and the stencils of the velocities (one for each scheme).
Domain informations
spatial dimension: 2
space step: dx= 1.000e-01
In pyLBM, a simulation can be performed by using several coupled schemes. In this example, a single scheme is used and defined through a list of one single dictionary. This dictionary should contain:
(see the documentation for more details)
In order to fix the bulk (\(\mu\)) and the shear (\(\eta\)) viscosities, we impose
The scheme velocity could be taken to \(1\) and the inital value of \(\rho\) to \(\rho_0=1\), \(q_x\) and \(q_y\) to \(0\).
In order to accelerate the simulation, we can use another generator. The default generator is Numpy (pure python). We can use for instance Cython that generates a more efficient code. This generator can be activated by using ‘generator’: pyLBM.generator.CythonGenerator in the dictionary.
Scheme informations
spatial dimension: dim=2
number of schemes: nscheme=1
number of velocities:
Stencil.nv[0]=9
velocities value:
v[0]=(0: 0, 0), (1: 1, 0), (2: 0, 1), (3: -1, 0), (4: 0, -1), (5: 1, 1), (6: -1, 1), (7: -1, -1), (8: 1, -1),
polynomials:
P[0]=Matrix([[1], [LA*X], [LA*Y], [3*X**2 + 3*Y**2 - 4], [-21*X**2/2 - 21*Y**2/2 + 9*(X**2 + Y**2)**2/2 + 4], [3*X*(X**2 + Y**2) - 5*X], [3*Y*(X**2 + Y**2) - 5*Y], [X**2 - Y**2], [X*Y]])
equilibria:
EQ[0]=Matrix([[rho], [qx], [qy], [-2*rho + 3.0*qx**2/LA**2 + 3.0*qy**2/LA**2], [rho - 3.0*qx**2/LA**2 - 3.0*qy**2/LA**2], [-qx/LA], [-qy/LA], [1.0*qx**2/LA**2 - 1.0*qy**2/LA**2], [1.0*qx*qy/LA**2]])
relaxation parameters:
s[0]=[0.0, 0.0, 0.0, 1.1312217194570136, 1.1312217194570136, 0.025706940874035987, 0.025706940874035987, 0.025706940874035987, 0.025706940874035987]
moments matrices
M = [Matrix([
[ 1, 1, 1, 1, 1, 1, 1, 1, 1],
[ 0, LA, 0, -LA, 0, LA, -LA, -LA, LA],
[ 0, 0, LA, 0, -LA, LA, LA, -LA, -LA],
[-4, -1, -1, -1, -1, 2, 2, 2, 2],
[ 4, -2, -2, -2, -2, 1, 1, 1, 1],
[ 0, -2, 0, 2, 0, 1, -1, -1, 1],
[ 0, 0, -2, 0, 2, 1, 1, -1, -1],
[ 0, 1, -1, 1, -1, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 1, -1, 1, -1]])]
invM = [Matrix([
[1/9, 0, 0, -1/9, 1/9, 0, 0, 0, 0],
[1/9, 1/(6*LA), 0, -1/36, -1/18, -1/6, 0, 1/4, 0],
[1/9, 0, 1/(6*LA), -1/36, -1/18, 0, -1/6, -1/4, 0],
[1/9, -1/(6*LA), 0, -1/36, -1/18, 1/6, 0, 1/4, 0],
[1/9, 0, -1/(6*LA), -1/36, -1/18, 0, 1/6, -1/4, 0],
[1/9, 1/(6*LA), 1/(6*LA), 1/18, 1/36, 1/12, 1/12, 0, 1/4],
[1/9, -1/(6*LA), 1/(6*LA), 1/18, 1/36, -1/12, 1/12, 0, -1/4],
[1/9, -1/(6*LA), -1/(6*LA), 1/18, 1/36, -1/12, -1/12, 0, 1/4],
[1/9, 1/(6*LA), -1/(6*LA), 1/18, 1/36, 1/12, -1/12, 0, -1/4]])]
For the simulation, we take
Concerning the boundary conditions, we impose the velocity on all the edges by a bounce-back condition with a source term that reads
We compute the solution for \(t\in(0,50)\) and we plot several slices of the solution during the simulation.
This problem has an exact solution given by
We compute the exact and the numerical gradients of the pressure.
Exact pressure gradient : -8.000e-03
Numerical pressure gradient: -7.074e-03