Copying the particle distribution function


I am wondering how to copy the particle distribution function from a simulation result. I used the “saveAsciiData(lattice.getDataAnalysis().getPopulations()” but some of the values I get are negative, which should not be the case. They are also small that I do not think they will add up to 1 (one), the density of the fluid.


This is the right way of getting the populations. If some of them are negative, I’d suspect that your simulation is likely to be numerically unstable, or close to.

Well, to verify that I was on the right track, I copied the populations for the cavity2d examples and I get very similar results…some negative values and most of them are of the order of e-6 and e-5 such that their addidtion will not be equal to 1. Thus I wonder how the output says average density =1,…while a peep at the populations does not show that the sum is equal to 1.

Aaah, right, sorry for the confusion. If I am not mistaken, the value which is stored in OpenLB is not f_i, but (f_i-t_i). The purpose of this is to gain numerical accuracy, as it is explained here. Therefore, the sum of these is approximately zero, and you need to add 1 to get the density. For the actual value of the f_i, you need to add the lattice constant t_i (4/9, 1/9, or 1/36 for D2Q9) to each direction.

Hope this helps.

Waow, now I need to digest this information very well. I understand it but will have to try it out because I have been stalled in my research as I could not understand why the values were outrageous.

Thanks as I wonder how I would have done with out your suggestion.
I will get back to you as soon as I try it out.


It worked add my analysis of the results showed that it was equal to 1 (one) when I accounted for the weights. However, my file is too big, close to 2.5G. I have therefore decided not to store the distribution functions in a file, but to use them directly for my analysis. There again, I faced another problem as the method of dynamic object I used, as explained in the manual and in the templates, would not work.

I have posted an inquiry in this forum and I hope I can get the solution.