Author Topic: How can I get particles mean diameters at each cell?  (Read 2870 times)

Offline infocfd

  • Newbie
  • *
  • Posts: 37
  • Reputation: +0/-0
  • Searching for solution
    • View Profile
How can I get particles mean diameters at each cell?
« on: April 25, 2012, 10:08:30 AM »
Advertisement
I am running a Fluent CFD simulation with lagrangian discrete phase particles of varying sizes in a spray. I want to calculate mean particle size/diameter in each cell. Can it be done in Fluent?

Thanks.

Offline william

  • Full Member
  • ***
  • Posts: 151
  • Reputation: +14/-0
  • Know it, share it.
    • View Profile
Re: How can I get particles mean diameters at each cell?
« Reply #1 on: April 25, 2012, 10:11:10 AM »
The following udf code allows to get mean diameters (D10, D20, D30 and sauter mean D32) in a spray simulation for each cell. To use this udf, you need to follow the following procedures:

(1) copy this udf to your working directory where Fluent case/data files of a converged spay simulation are saved.

(2) compile that udf and create a udf library: launch Fluent and read in your case/data file; go to the Define/User-Defined/Functions/Compiled
panel, add "spray-sample.c" to the source list, and hit "Build" to generate a udf library. After the library is built, click "Load" button to load in the udf.

(3) Hook up the udf:
a) Go to the Define/User-Defined/Memory panel and set 10 UDMs.
b) Go to the Define/User-Defined/Function Hooks/Adjust and hook up "adjust_spray"
c) Go to the Define/Discrete Phase Model panel to hook up "body_force_spray" to Body Force under User-Defined Functions, and also set Number of Scalars to be "1" in that panel.

(4) Run more iterations. The more iterations you run, more particles will be used to get those statistics.

(5) Draw contour of those mean diameters.

The above procedures give you particles mean diameters at each cell. If you want to know particles mean diameters across a particle cut plane,
let's say D32, you can use the following procedures:

(1) Go to the Report/Surface Integrals to calculate Sum_(n_k*d_k**3): choose "Integral" under Report Type and "User Defined Memory" and
"udf-3" user Field variable, and pick up a cut-plane in the Surface list. Click "Compute" will give you Sum_(n_k*d_k**3).

(2) Calculate Sum_(n_k*d_k**2) in the same panel: choose "User Defined Memory" and "udf-2" user Field variable and click "Compute" to obtain
Sum_(n_k*d_k**2).

(3) D32=Sum_(n_k*d_k**3)/Sum_(n_k*d_k**2).
-----------------------------------------------------------------------------------------
/*

This udf will calculate mean diameter D10, D20, D30 and D32 for all particles
passing thorugh that cell. This udf should be hooked up only after the solution
has converged and you want to obtain particles' statistics. After it's hooked
up, you should run simulation for many iterations in order to get meaningful
statistics. More iterations you run, more sampling particles you will have,
and more accurate results you will get.

Ten User-Defined Memories were used to save the following inforamtion:

C_UDMI(c,t,0): sum (n_k)
C_UDMI(c,t,1): sum (n_k*d_k)
C_UDMI(c,t,2): sum (n_k*d_k*d_k)
C_UDMI(c,t,3): sum (n_k*d_k*d_k*d_k)
C_UDMI(c,t,4): sum (n_k*d_k*d_k*d_k*d_k)
C_UDMI(c,t,5): number of particle parcels passing through that cell
C_UDMI(c,t,6): = D10 = C_UDMI(c,t,1)/C_UDMI(c,t,0) =sum (n_k*d_k)/sum (n_k)
C_UDMI(c,t,7): = D20 = sqrt(C_UDMI(c,t,2)/C_UDMI(c,t,0)) =sqrt(sum (n_k*d_k*d_k)/sum (n_k))
C_UDMI(c,t,8): = D30 = pow(C_UDMI(c,t,3)/C_UDMI(c,t,0),1/3) = pow(sum (n_k*d_k*d_k*d_k)/sum (n_k), 1/3)
C_UDMI(c,t,9): = D32 = C_UDMI(c,t,3)/C_UDMI(c,t,2) =sum (n_k*d_k)/sum (n_k)

*/

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

static int counter=0;

DEFINE_ADJUST(adjust_spray, d)
{
Thread *t;
cell_t c;

if (counter==0)
{counter=1;
thread_loop_c (t,d)
{
begin_c_loop (c,t)
{
C_UDMI(c,t,0)=0.0;
C_UDMI(c,t,1)=0.0;
C_UDMI(c,t,2)=0.0;
C_UDMI(c,t,3)=0.0;
C_UDMI(c,t,4)=0.0;
C_UDMI(c,t,5)=0.0;
}
end_c_loop (c,t)
}
}

thread_loop_c (t,d)
{
begin_c_loop (c,t)
{
C_UDMI(c,t,6) = C_UDMI(c,t,1)/MAX(C_UDMI(c,t,0),DPM_SMALL);
C_UDMI(c,t,7) = sqrt(C_UDMI(c,t,2)/MAX(C_UDMI(c,t,0),DPM_SMALL));
C_UDMI(c,t,8) = pow(C_UDMI(c,t,3)/MAX(C_UDMI(c,t,0),DPM_SMALL),0.333333);
C_UDMI(c,t,9) = C_UDMI(c,t,3)/MAX(C_UDMI(c,t,2),DPM_SMALL);
}
end_c_loop (c,t)
}
}

DEFINE_DPM_BODY_FORCE(body_force_spray, p, i)
{
Thread *t;
cell_t c;
real num_p, dia;

c = P_CELL(p);
t = P_CELL_THREAD(p);
if(P_USER_REAL(p,0) != (float) c)
{num_p = p->number_in_parcel;
dia = p->state.diam;
C_UDMI(c,t,0) += num_p;
C_UDMI(c,t,1) += num_p * dia;
C_UDMI(c,t,2) += num_p * dia * dia;
C_UDMI(c,t,3) += num_p * dia * dia * dia;
C_UDMI(c,t,4) += num_p * dia * dia * dia * dia;
C_UDMI(c,t,5) += 1;
P_USER_REAL(p,0)=(float) c;}

return 0.0;
}

Offline tue1984

  • Newbie
  • *
  • Posts: 4
  • Reputation: +0/-0
  • Searching for solution
    • View Profile
Re: How can I get particles mean diameters at each cell?
« Reply #2 on: August 28, 2012, 04:18:09 PM »
Hi William,

Your UDF is really useful. Could you please extend it so that one can compute the following variables at every cell:

1. All particle velocity components u, v and w.

2. Volume flux (m3/s/m2) which is defined as: particle volume/time interval/cell area

Thank you, Tue.

Offline william

  • Full Member
  • ***
  • Posts: 151
  • Reputation: +14/-0
  • Know it, share it.
    • View Profile
Re: How can I get particles mean diameters at each cell?
« Reply #3 on: August 28, 2012, 06:23:17 PM »
You will need to define additional UDMs for this purpose.

The particle velocities at cells can be stored using:

P_VEL(p)[0] ---> x component of particle velocity
P_VEL(p)[1] ---> y component of particle velocity
P_VEL(p)[2] ---> z component of particle velocity


Offline tue1984

  • Newbie
  • *
  • Posts: 4
  • Reputation: +0/-0
  • Searching for solution
    • View Profile
Re: How can I get particles mean diameters at each cell?
« Reply #4 on: August 28, 2012, 07:48:08 PM »
Thank you! I realize how the particle velocities can be computed now.

Is there any way that we can compute the particle volume flux or particle mass flux per area for every cell face on a given surface and then write that down as a 2D contour plot? This would be very useful because particle volume flux per area is the variable that is normally measured in the experiments with Phase Doppler Particle Analyzer.

Tue

Offline tue1984

  • Newbie
  • *
  • Posts: 4
  • Reputation: +0/-0
  • Searching for solution
    • View Profile
Re: How can I get particles mean diameters at each cell?
« Reply #5 on: August 29, 2012, 06:17:21 AM »
I figured out an easier way to compute the volume flux which is multiplying the volume fraction with the particle velocity.

William: since I have some problems with compiling udf on my computer at work, I have tried to interpret it but Fluent gave me several errors, e.g., "parse error" for the static variable, "undeclared variables P_CELL", etc. Is there any way to modify your udf so that it can be interpreted? If yes, please let me know how. Thanks.

Offline william

  • Full Member
  • ***
  • Posts: 151
  • Reputation: +14/-0
  • Know it, share it.
    • View Profile
Re: How can I get particles mean diameters at each cell?
« Reply #6 on: August 29, 2012, 09:00:03 AM »
You will have to compile the UDF you can not run it as interpreted because it uses variables.
You will need to sort out the issues with compiling.

Offline tue1984

  • Newbie
  • *
  • Posts: 4
  • Reputation: +0/-0
  • Searching for solution
    • View Profile
Re: How can I get particles mean diameters at each cell?
« Reply #7 on: August 29, 2012, 10:35:04 AM »
William: Thanks. Fortunately, I have fixed the compiling issue and it works for me now. One more question though: how do you get the particle volume or volume fraction in every cell? Is it C_VOF(c,t)?

Tue
« Last Edit: August 29, 2012, 10:38:02 AM by tue1984 »

Offline william

  • Full Member
  • ***
  • Posts: 151
  • Reputation: +14/-0
  • Know it, share it.
    • View Profile
Re: How can I get particles mean diameters at each cell?
« Reply #8 on: August 29, 2012, 11:21:03 AM »
You can get an estimated solid volume fraction in a cell by diving discrete phase concentration with particle density (assuming that all particles have the same density).

This will be:

C_DPMS_CONCENTRATION(c,t)/P_RHO(p)

You may get a value greater than 1 in certain regions if your case involves dense discrete phase flow.