Author Topic: UDF to count number of droplets in VOF simulation  (Read 6940 times)

Offline infocfd

  • Newbie
  • *
  • Posts: 45
  • Reputation: +0/-0
  • Searching for solution
    • View Profile
UDF to count number of droplets in VOF simulation
« on: May 13, 2012, 11:44:33 AM »
Advertisement
I want to count the number of droplets in the volume using UDF in VOF simulation. Please can any one help?

Thanks.

Offline william

  • Full Member
  • ***
  • Posts: 159
  • Reputation: +15/-0
  • Know it, share it.
    • View Profile
Re: UDF to count number of droplets in VOF simulation
« Reply #1 on: May 13, 2012, 11:45:50 AM »
This udf will allow you to count the number of droplets in a VOF simulation, you can also get droplets' statistics if you want.

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, thread_id1, n)
{
f = C_FACE(cell_id1, thread_id1, n);
tf = C_FACE_THREAD(cell_id1, thread_id1, n);

c0=F_C0(f,tf);
t0=THREAD_T0(tf);
if (c0==cell_id1 && 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=cell_id2;
thread_id1=thread_id2;
cell_id2=0;
thread_id2=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("\n\n-------------------------------------\n");
Message("Total number of droplets: %d\n",N_droplet );
Message("-------------------------------------\n\n");
if(N_droplet!=0)Message(" ID DIAMETER(m) \n");

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




/*

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, thread_id1, n)
{
f = C_FACE(cell_id1, thread_id1, n);
tf = C_FACE_THREAD(cell_id1, thread_id1, n);

c0=F_C0(f,tf);
t0=THREAD_T0(tf);
if (c0==cell_id1 && 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=cell_id2;
thread_id1=thread_id2;
cell_id2=0;
thread_id2=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("\n\n-------------------------------------\n");
Message("Total number of droplets: %d\n",N_droplet );
Message("-------------------------------------\n\n");
if(N_droplet!=0)Message(" ID DIAMETER(m) \n");

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