Matlab OpenLB Boundary Condition Geometry


After studying the Matlab script for OpenLB implementation “cylinder.m”, I can not tell how to alter the boundary conditions on the top and bottom walls. I wish to know how I can specify an alternate geometry (other than the flat walls that are currently present).

I have checked this forum as well as the PDF documentation for a similar query, but the answer is not apparent.

Thank you.

I’m not sure I understood your question. Do you ask for curved boundary conditions? Am I right?

For the moment in OpenLB you can only have flat walls boundary conditions. For curved geometry the best you can do is to use the “staircase” approximation, using the fullway bounce back boundary condition. It is planned to add a curved boundary condition, but it is still in the middle of the to-do list of things that are going to be added in OpenLB.


Admittedly, the boundary condition implementation in this Matlab script is not obvious. This sample is actually obsolete and should be removed soon. I suggest that you have a look at the Matlab implementation of the lid-driven cavity instead:

Here, Adriano implemented Zou/He boundary conditions which are easier to understand. For background information on the Zou/He boundary condition, check

the Wiki on boundary conditions


the paper by Zou and He.

This should help you understand how the boundary condition is implemented in this Matlab script. This is for straight boundaries of course. Curved boundaries are a different story which needs much more efforts.

I don’t want a curved geometry, I actually want to specify grooves on the channel wall (top or bottom). I am unclear about how to specify in the matlab script grooved walls.

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| (top wall)

(inlet) … outlet

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| (bottom wall)

For the bottom wall
you could define obstacles (solid) where you impose a bounce-back conditions and reproduce the shape of your grooves…

You should code something like
If (we are looking at a lattice node belonging to the Obstacle) then (bounce_back)

How to define the obstacles?
as Jonas did for the cylinder in his matlab code for flow past a cylinder in 2D. He defines the bbregion where he only has bounce-back …

Here how he does for the cylinder:

obst_x = lx/5+1; % position of the cylinder; (exact
obst_y = ly/2+1; % y-symmetry is avoided)
obst_r = ly/10+1; % radius of the cylinder

[y,x] = meshgrid(1:ly,1:lx);
obst = (x-obst_x).^2 + (y-obst_y).^2 <= obst_r.^2;
obst(:,[1,ly]) = 1;
bbRegion = find(obst);

for i=1:9
% Left boundary
fOut(i,1,col) = fEq(i,1,col) + …
18*t(i)cx(i)cy(i) ( fIn(8,1,col) - …
fIn(7,1,col)-fEq(8,1,col)+fEq(7,1,col) );
% Right boundary
fOut(i,lx,col) = fEq(i,lx,col) + …
t(i)*cx(i)cy(i) ( fIn(6,lx,col) - …
fIn(9,lx,col)-fEq(6,lx,col)+fEq(9,lx,col) );
% Bounce back region
fOut(i,bbRegion) = fIn(opp(i),bbRegion);

… you could define a new bbregion.
I hope I was clear … if not sorry.