Posted by: william
« on: June 19, 2012, 08:38:40 AM »Here is an example of how you can implement begin_particle_cell_loop:
/***********************************************************
DPM Spray Collide Example UDF
************************************************************/
#include "udf.h"
#include "dpm.h"
#include "surf.h"
DEFINE_DPM_SPRAY_COLLIDE(man_spray_collide,tp,p)
{
/* non-physical collision UDF that relaxes the particle */
/* velocity and diameter in a cell to the mean over the */
/* specified time scale t_relax */
const real t_relax = 0.001; /* seconds */
/* get the cell and Thread that the particle is currently in */
cell_t c = RP_CELL(&(tp->cCell));
Thread *t = RP_THREAD(&(tp->cCell));
/* Particle index for looping over all particles in the cell */
Particle *pi;
/* loop over all particles in the cell to find their mass */
/* weighted mean velocity and diameter */
int i;
real u_mean[3]={0.}, mass_mean=0.;
real d_orig = tp->state.diam;
real decay = 1. - exp(-t_relax);
begin_particle_cell_loop(pi,c,t)
{
mass_mean += pi->state.mass;
for(i=0;i<3;i++)
u_mean += pi->state.V*pi->state.mass;
}
end_particle_cell_loop(pi,c,t)
/* relax particle velocity to the mean and diameter to the */
/* initial diameter over the relaxation time scale t_relax */
if( mass_mean > 0. )
{
for(i=0;i<3;i++)
u_mean /= mass_mean;
for(i=0;i<3;i++)
tp->state.V += decay*( u_mean - tp->state.V );
tp->state.diam += decay*( P_INIT_DIAM(tp) - tp->state.diam );
/* adjust the number in the droplet parcel to conserve mass */
tp->number_in_parcel *= CUB( d_orig/tp->state.diam );
}
}
/***********************************************************
DPM Spray Collide Example UDF
************************************************************/
#include "udf.h"
#include "dpm.h"
#include "surf.h"
DEFINE_DPM_SPRAY_COLLIDE(man_spray_collide,tp,p)
{
/* non-physical collision UDF that relaxes the particle */
/* velocity and diameter in a cell to the mean over the */
/* specified time scale t_relax */
const real t_relax = 0.001; /* seconds */
/* get the cell and Thread that the particle is currently in */
cell_t c = RP_CELL(&(tp->cCell));
Thread *t = RP_THREAD(&(tp->cCell));
/* Particle index for looping over all particles in the cell */
Particle *pi;
/* loop over all particles in the cell to find their mass */
/* weighted mean velocity and diameter */
int i;
real u_mean[3]={0.}, mass_mean=0.;
real d_orig = tp->state.diam;
real decay = 1. - exp(-t_relax);
begin_particle_cell_loop(pi,c,t)
{
mass_mean += pi->state.mass;
for(i=0;i<3;i++)
u_mean += pi->state.V*pi->state.mass;
}
end_particle_cell_loop(pi,c,t)
/* relax particle velocity to the mean and diameter to the */
/* initial diameter over the relaxation time scale t_relax */
if( mass_mean > 0. )
{
for(i=0;i<3;i++)
u_mean /= mass_mean;
for(i=0;i<3;i++)
tp->state.V += decay*( u_mean - tp->state.V );
tp->state.diam += decay*( P_INIT_DIAM(tp) - tp->state.diam );
/* adjust the number in the droplet parcel to conserve mass */
tp->number_in_parcel *= CUB( d_orig/tp->state.diam );
}
}