FLUENT 6 - UDF to count the number of droplets in a VOF simulation


The VOF model is often used in the spray atomization application. In such applications, a lot of droplets will be produced in the simulation. Users often want to know the number of droplets and their size distribution from the simulation. The attached udf will do the work.

Genong
/*

This udf will allow user to count the number of droplets in a VOF simulation,
you can also get droplets' statistics if you want.

This UDF is written by Genong Li @ FLUENT
please report any bug to gnl@fluent.com

Feb. 9, 2007

NOTE:
(1) It can be used in 2D or 3D.
(2) It is recommended to run in serial, but it can be run in parallel as well. However, any droplet straddling the
partition interface will be counted as two separate droplets.
(3) User provides "PHASE_INDEX" and "INTERFACE_VOF" as inputs.
(4) Set one UDM to use this udf, the droplet # is saved in the UDM0.
(5) Any continuous liquid region will be counted as a droplet. Users may want to filter out the liquid pool
either in the udf or remove from the output.
(6) Procedures to run the udf:
a: Read in your case and data file.
b: Define one udm.
c: Run the simulation for 1 time step. THAT WILL ALLOCATE THE NEEDED MEMORY FOR THE UDM.
d: Compile this udf, hook it up and execute it.

*/


#include "udf.h"

#define PHASE_INDEX 1 /* droplet phase index 0 if it is the primary phase */
#define INTERFACE_VOF 0.5 /* threashold of VOF of the droplet phase at the interface */
#define NMAX 10000 /* Maximum number of out-layer cells within a droplet. increase this # if needed */
#define MAX_DROPLET 1000000 /* Maximum number of droplets, increase this # if needed */

DEFINE_ON_DEMAND(on_demand_size_distribution_vof)
{
Domain *d;
Thread *t, *t0;
cell_t c, c0;
face_t f;
Thread *tf;
int i,n,n_child,N_search;
int N_droplet=0;

cell_t cell_id1[NMAX], cell_id2[NMAX];
Thread *thread_id1[NMAX], *thread_id2[NMAX];
real Vol_droplet[MAX_DROPLET], Dia_droplet[MAX_DROPLET];
Thread **pt,**pt2;

d = Get_Domain(1);

/* initialization */

thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0)=0;
}
end_c_loop(c,t)
}

/* droplet counting */

thread_loop_c(t,d)
{
pt = THREAD_SUB_THREADS(t);

begin_c_loop(c,t)
{
Vol_droplet[N_droplet]=0.0;
if(C_VOF(c,pt[PHASE_INDEX])>INTERFACE_VOF && C_UDMI(c,t,0)==0)
{

C_UDMI(c,t,0)=N_droplet+1;
Vol_droplet[N_droplet] += C_VOLUME(c,t)*C_VOF(c,pt[PHASE_INDEX]);

N_search=1;
cell_id1[0]=c;
thread_id1[0]=t;

do
{
n_child= 0;
for(i=0; i<N_search; i++)
{
c_face_loop(cell_id1[i], thread_id1[i], n)
{
f = C_FACE(cell_id1[i], thread_id1[i], n);
tf = C_FACE_THREAD(cell_id1[i], thread_id1[i], n);

c0=F_C0(f,tf);
t0=THREAD_T0(tf);
if (c0==cell_id1[i] && THREAD_T1(tf) != NULL)
{
c0=F_C1(f,tf);
t0=THREAD_T1(tf);
}

pt2 = THREAD_SUB_THREADS(t0);
if(C_VOF(c0,pt2[PHASE_INDEX])>INTERFACE_VOF && C_UDMI(c0,t0,0)==0)
{
C_UDMI(c0,t0,0)=N_droplet+1;
cell_id2[n_child]=c0;
thread_id2[n_child]=t0;
Vol_droplet[N_droplet] += C_VOLUME(c0,t0)*C_VOF(c0,pt2[PHASE_INDEX]);
n_child += 1;
if((n_child-1)==NMAX)
{
Message("Please increase NMAX!! n");
exit(0);
}
}
}
}

N_search=n_child;
for(i=0; i<NMAX; i++)
{
cell_id1[i]=cell_id2[i];
thread_id1[i]=thread_id2[i];
cell_id2[i]=0;
thread_id2[i]=NULL;
}
} while(N_search>0);


N_droplet += 1;
if((N_droplet-1)==MAX_DROPLET)
{
Message("Please increase MAX_DROPLET in the udf!! n");
exit(0);
}
}
}
end_c_loop(c,t)
}

Message("nn-------------------------------------n");
Message("Total number of droplets: %dn",N_droplet );
Message("-------------------------------------nn");
if(N_droplet!=0)Message(" ID DIAMETER(m) n");

for(i=0; i<N_droplet; i++)
{
if(ND_ND==3)Dia_droplet[i]=2.0*pow(0.75*Vol_droplet[i]/M_PI,0.333333333) ;
if(ND_ND==2)Dia_droplet[i]=2.0*pow(Vol_droplet[i]/M_PI,0.5) ;
Message(" %d %gn",i+1,Dia_droplet[i]);
}
}




/*

This udf will allow user to count the number of droplets in a VOF simulation,
you can also get droplets' statistics if you want.

This UDF is written by Genong Li @ FLUENT
please report any bug to gnl@fluent.com

Feb. 9, 2007

NOTE:
(1) it can be used in 2D or 3D.
(2) it is recommended to run in serial, but it can be run in parallel as well. Any droplet straddles the
partition interface will be counted as two separate droplets though.
(3) user provide "PHASE_INDEX" and "INTERFACE_VOF" as inputs.
(4) set one UDM to use this udf, the droplet # is saved in the UDM0.
(5) Any continuous liquid region will be counted as a droplet. User may want to filter out the liquid pool
either in the udf or remove from the output.
(6) procedures to run the udf.
a: read in your case and data file.
b: define one udm.
c: run the simulation for 1 time step. THAT WILL ALLOCTE THE NEEDED MEMORY FOR THE UDM.
d: comiple this udf, hook it up and execute it.

*/


#include "udf.h"

#define PHASE_INDEX 1 /* droplet phase index 0 if it is the primary phase */
#define INTERFACE_VOF 0.5 /* threashold of VOF of the droplet phase at the interface */
#define NMAX 10000 /* Maximum number of out-layer cells within a droplet. increase this # if needed */
#define MAX_DROPLET 1000000 /* Maximum number of droplets, increase this # if needed */

DEFINE_ON_DEMAND(on_demand_size_distribution_vof)
{
Domain *d;
Thread *t, *t0;
cell_t c, c0;
face_t f;
Thread *tf;
int i,n,n_child,N_search;
int N_droplet=0;

cell_t cell_id1[NMAX], cell_id2[NMAX];
Thread *thread_id1[NMAX], *thread_id2[NMAX];
real Vol_droplet[MAX_DROPLET], Dia_droplet[MAX_DROPLET];
Thread **pt,**pt2;

d = Get_Domain(1);

/* initialization */

thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0)=0;
}
end_c_loop(c,t)
}

/* droplet counting */

thread_loop_c(t,d)
{
pt = THREAD_SUB_THREADS(t);

begin_c_loop(c,t)
{
Vol_droplet[N_droplet]=0.0;
if(C_VOF(c,pt[PHASE_INDEX])>INTERFACE_VOF && C_UDMI(c,t,0)==0)
{

C_UDMI(c,t,0)=N_droplet+1;
Vol_droplet[N_droplet] += C_VOLUME(c,t)*C_VOF(c,pt[PHASE_INDEX]);

N_search=1;
cell_id1[0]=c;
thread_id1[0]=t;

do
{
n_child= 0;
for(i=0; i<N_search; i++)
{
c_face_loop(cell_id1[i], thread_id1[i], n)
{
f = C_FACE(cell_id1[i], thread_id1[i], n);
tf = C_FACE_THREAD(cell_id1[i], thread_id1[i], n);

c0=F_C0(f,tf);
t0=THREAD_T0(tf);
if (c0==cell_id1[i] && THREAD_T1(tf) != NULL)
{
c0=F_C1(f,tf);
t0=THREAD_T1(tf);
}

pt2 = THREAD_SUB_THREADS(t0);
if(C_VOF(c0,pt2[PHASE_INDEX])>INTERFACE_VOF && C_UDMI(c0,t0,0)==0)
{
C_UDMI(c0,t0,0)=N_droplet+1;
cell_id2[n_child]=c0;
thread_id2[n_child]=t0;
Vol_droplet[N_droplet] += C_VOLUME(c0,t0)*C_VOF(c0,pt2[PHASE_INDEX]);
n_child += 1;
if((n_child-1)==NMAX)
{
Message("Please increase NMAX!! n");
exit(0);
}
}
}
}

N_search=n_child;
for(i=0; i<NMAX; i++)
{
cell_id1[i]=cell_id2[i];
thread_id1[i]=thread_id2[i];
cell_id2[i]=0;
thread_id2[i]=NULL;
}
} while(N_search>0);


N_droplet += 1;
if((N_droplet-1)==MAX_DROPLET)
{
Message("Please increase MAX_DROPLET in the udf!! n");
exit(0);
}
}
}
end_c_loop(c,t)
}

Message("nn-------------------------------------n");
Message("Total number of droplets: %dn",N_droplet );
Message("-------------------------------------nn");
if(N_droplet!=0)Message(" ID DIAMETER(m) n");

for(i=0; i<N_droplet; i++)
{
if(ND_ND==3)Dia_droplet[i]=2.0*pow(0.75*Vol_droplet[i]/M_PI,0.333333333) ;
if(ND_ND==2)Dia_droplet[i]=2.0*pow(Vol_droplet[i]/M_PI,0.5) ;
Message(" %d %gn",i+1,Dia_droplet[i]);
}
}





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