Fully Periodic boundary conditions

Can any body provide me the fortran code for fully periodic boundary conditions? Mine is not working. have some ambiguities regarding it. Best regards and Thanks in advance…

you can use the following streaming function. It is already include periodic boundary


for (int q=0; q<9 ; q++)
for (int i=0; i<nx ; i++)
int ii=(i+cx[q]+nx)%nx;
for (int j=0; j<ny ; j++)
int jj=(j+cy[q]+ny)%ny;

you can convert this streaming function to fortran by taking care of the indecies and using the mod function instead of %. the mod function is used to to the get the rest of the division. 


But how to define c?
And should i redistribute the flow both in x and y direction when it reenters?


for d2q9

I am not sure what you mean by “should i redistribute the flow both in x and y direction when it reenters?”

but if you mean distribute each distribution function in its direction even in the the end of the domain to reenter fron the other side then the previous streaming function will do that.
assume q=7 which has cx=-1, cy=-1 at i=0, j=0;


this value will leave form the buttom left corner and reenter at the upper right corner

also try to read alrady written codes it will help you.

I hope this help you


If you are using C or Fortran you can use the cshift function.

Exactly, it will reenter by streaming step, but some initial acceleration is provided in the flow direction when it reenters to give some initial push to the fluid . Because it is not gravity driven flow.

Will see cshift function

I think may be you can try to add some froce term on the node you want to accelerat. maybe this will work.

could you give me a general Idea how you did this in c in 2d array. Actually I tried to do it once but I did not succeed


Hello SaS,

I want to ask two questions regarding LBM (I am using a D2Q9 model).

  1. In the absence of any obstacle, distribution functions leaving the domain re-enter (from enterance) the boundaries as a result of streaming process. So, in addition to streaming, whether we should define periodic boundary conditions separately or streaming itself is enough?

  2. If in addition to streaming process, we have to apply fully periodic boundary conditions separately, then what to do with the distribution functions present at the corner nodes. the distribution function # 5 at the bottom left corner node will be coming from the distribution function # 5 at the top left corner and the distribution function # 5 at the bottom right corner node.
    Same will happen with some other the distribution functions present at the edges of domain.
    Can you please post your email address for further discussion on this topic? or if can you please provide a fortran version of it? I cannot understand C.

I am actually much confused about the corner points of the domain.

Best Regards