Coupling Liggghts with a LBM code written in Fortran.

Submitted by paulbrumby on Tue, 10/04/2011 - 10:03

In case anyone finds it useful here is some information about a method I use to couple Liggghts with a separate Lattice Boltzmann code written in Fortran.

The Fortran code is the driver, so it starts first calculates the fluid flow, writes the particle information to a file and then calls an external subroutine to run Liggghts automatically from the command line for one time step. See the following link.c file:

#include
#include
int dem_(int i)
{
printf ("Checking if processor is available...");
if (system(NULL)) puts ("Ok");
else exit (1);
printf ("Run DEM...\n");
i=system ("./lmp_myFedora11 < input_dem.txt");
printf ("The value returned was: %d.\n",i);
return 0;
}

this subroutine is called as "dem" from within the Fortran code (note the underscore in "dem_" the code above).

The codes are complied and run by doing something like this (depending upon which compliers are available):

gcc -c link.c -m64
ifort -c lbm.f90 -m64
ifort -o dem_lbm.exe lbm.o link.o -m64
./dem_lbm.exe

The trick is making sure that the input file describes the system you have in the linked code perfectly and that the particle positions are written and read in the correct format, along with any geometry particular to your system. Liggghts seems to mix around the order of the particles so if you rely on labelling them them in Fortran then they won't usually be read back in, in the same order, so you'll need to take that into account.

After Liggghts has finished running the Fortran code automatically resumes and then reads the new particle positions from the dump files produced from Liggghts. Obviously the time steps used in each of the two codes should be equal.

Taxonomy upgrade extras:

ckloss's picture

ckloss | Tue, 10/04/2011 - 13:18

Thanks for posting this!

>>Liggghts seems to mix around the order of the particles so if you rely on labelling them them in Fortran
>>then they won't usually be read back in, in the same order, so you'll need to take that into account
this is mainly for speed reasons and also necessary for parallel computing.
If you are running in serial only, you could check out "atom_modify sort 0 0"
Or you can identify particles via their tag, as it's done in the coupling interface, see library*.h/cpp
You can also have a look at our cfd coupling, fix cfd_coupling*

Christoph