Advection-diffusion veeery beginner

Hi All,

I’m writing my very first codes in palabos and I’m dealing with the advection diffusion problem. I wrote a simple code which aims to solve the pure diffusion in a box imposing two different temperature on the top and bottom wall. As first attempt, i’m pretty satisfiedbut still I dont get why the top wall value doesn’t preserve during the simulation. I think I’m messing with the boudary conditions, but I’m really new to the topic and some concepts are not so clear yet… Hope that somebody of you can help me and can corrects the code if there are mistakes.

#include “palabos2D.h”
#include “palabos2D.hh”

using namespace std;
using namespace plb;

typedef double T;
#define DES descriptors::AdvectionDiffusionD2Q5Descriptor

int main(int argc, char *argv[])
// Init simulation
plbInit(&argc, &argv);

const T omega = 1.;
Array <T,2> u0(0.0,0.0);

// Istantiate lattice
MultiBlockLattice2D <T, DES> lattice(100,100, new AdvectionDiffusionBGKdynamics<T, DES>(omega));

// Init lattice and assign boundary conditions
plint nx = lattice.getNx();
plint ny = lattice.getNy();

Box2D topwall(0, nx-1, ny-1, ny-1);
Box2D bottomwall(0, nx-1, 0,    0);

// Create boundary conditions
OnLatticeAdvectionDiffusionBoundaryCondition2D <T, DES> *BC = createLocalAdvectionDiffusionBoundaryCondition2D<T, DES>();

//Impose the boundary conditions
BC->addTemperatureBoundary0N(topwall, lattice);
BC->addTemperatureBoundary0N(bottomwall, lattice);

// Try to impose a different temperature
setBoundaryDensity(lattice, topwall, 1.0);
setBoundaryDensity(lattice, bottomwall, 2.0);

// Init lattice
initializeAtEquilibrium(lattice, lattice.getBoundingBox(), 0.0,u0);

// Command to init the lattice

ImageWriter <T> imagewrite("leeloo");
imagewrite.writeScaledGif(createFileName("temp", 1, 1), *computeDensity(lattice), 100,100);

//* Main cicle for LbM
for(plint iT=0; iT < 100000; ++iT) {

    if (iT % 1000 == 0) {
       pcout << "Writing GIF... \n";
       imagewrite.writeScaledGif(createFileName("temp", iT, 6), *computeDensity(lattice), 100,100);


return 0;



After quickly looking at your code, I would suggest to change 2 things:

First, use:

BC->addTemperatureBoundary1P(topwall, lattice);
BC->addTemperatureBoundary1N(bottomwall, lattice);

to indicate that the outward-pointing normals point to the “+y” and “-y” directions on the topWall and bottomWall respectively.

Second, define periodicity only at the “x-axis” direction.

I hope these help!


It seems to work now… thanks!!!

I also noticed that palabos implements the “AdvectionDiffudionWithSourceBGKDynamics”. Is it possible to solve also the advection diffusion equation with source terms? Is it possible to assign a source term to single cells inside the lattice?

Thank you very much for your help.



Hi sdea,

Did you figure out how to implement ‘AdvectionDiffudionWithSourceBGKDynamics’? Specifically the method to pass source value to specific cells in lattice.

Thanks in advance

Hi Saran,
I am trying to implement a reaction source. I also notices the dynamic “AdvectionDiffusionWithSourceBGKDynamic”,
Do you know to transfer it to the corresponding class or function ?
Thank you in advance !