Looping over all the particles in a domain


There is a loop available for looping over all the particles in a cell. But it does not work if used directly. Actually the array to bin the particles in the cell is not allocated by default. It has to be done before using this loop and then it will run ok.

So, at the top of the routine, please put,

Alloc_Storage_Vars(domain, SV_DPM_PARTICLE_BIN, SV_NULL);
bin_particles_in_cells(domain);

and at the botton, free up the memory with,

Free_Storage_Vars(domain, SV_DPM_PARTICLE_BIN, SV_NULL);
I am attaching my test UDF. It worked nicely for a simple 2d case in Linux.

#include "udf.h"
#include "surf.h"

DEFINE_ON_DEMAND(cell)
{

Domain *d=Get_Domain(1);
cell_t c;
int id;
Particle *p;

Thread *c_thread=Lookup_Thread(d,2); /*In my case 2 was the id of the fluid thread. Please change this number accordingly */

Alloc_Storage_Vars(d, SV_DPM_PARTICLE_BIN, SV_NULL);
bin_particles_in_cells(d);

begin_c_loop(c, c_thread)

{
/* Message("Cell_index=%dn",c);*/
begin_particle_cell_loop(p,c,c_thread)
{
id=p->part_id;
Message(" cell index=%d part_id=%d ",c,id);
}
end_particle_cell_loop(p,c,c_thread)
}

end_c_loop(c, c_thread)

Free_Storage_Vars(d, SV_DPM_PARTICLE_BIN, SV_NULL);

}





Show Form
No comments yet. Be the first to add a comment!