
[Sponsors] 
August 17, 2015, 06:43 
Particle Volume Fraction UDF

#1 
New Member
NNM_BSP
Join Date: Aug 2015
Posts: 5
Rep Power: 2 
Dear all,
I'm working with the Dense discrete phase model. I'm trying to get the volume fraction of the particles in each cell to calculate the viscosity in the cell. I can find the mass fraction of each component in the cell but I can't convert it to volume fraction(?). Now I'm thinking about calculating the volume fraction by: #particles*VParticle/VolumeCell. Is there a way to find the number of particles of a certain species in each cell? Does anyone have a suggestion or tips? I found a UDF on this forum to calculate the total number of particles. Is this a good starting point? #include "udf.h" DEFINE_ON_DEMAND(particle_cells_count) { Injection *Ilist; Injection *I; Particle *p; cell_t c; Thread *c_t; int parcel_trapped = 0; real num_part = 0; Ilist = Get_dpm_injections(); loop(I, Ilist) { loop(p, I>p) { c = P_CELL(p); c_t = P_CELL_THREAD(p); parcel_trapped+=1; num_part=p>number_in_parcel; } } Message("num_part: %d\n",num_part); Message("parcel_trapped: %d\n",parcel_trapped); } 

August 17, 2015, 10:13 

#2 
New Member
NNM_BSP
Join Date: Aug 2015
Posts: 5
Rep Power: 2 
Could the Macro C_VOF be used in the DDPM? That would solve most of the problem...


August 18, 2015, 06:09 

#3 
Senior Member
Join Date: Mar 2015
Posts: 416
Rep Power: 5 
I'm not aware of a direct macro for the volume fraction of the discrete phase in DPM.
It's possible to determine the volume fraction of particles in each cell with the following steps:
Then you can access the particle volume fraction with the C_UDMI macro. Remember to reset the UDM at the start of the UDF to avoid counting the same particles over multiple time steps. 

August 25, 2015, 07:23 

#4 
New Member
NNM_BSP
Join Date: Aug 2015
Posts: 5
Rep Power: 2 
I tried the way you suggested and came up with this UDF. The file compiles without problems but when I run it, I get an segmentation error. I marked to where it stops. I think something is wrong with the pointers. I tried to define the t0 thread outside the loop but it didn't make a difference. I want to calculate the volume fraction by dividing the total volume of all particles in the cell by the volume of the same cell.
Any any idea to solve it? #include "udf.h" #define RhoPlasma 1035 // kg/m^3 #define RhoRBC 1100 // kg/m^3 #define Mu_Plasma 1.65e3 // Pa.s #define VolPart 92e6 //m #define n 0.75 // experimantal data #define b 5.0 // experimental data #define k 0.5 // experimental data #define alpha 1 // Not clear=> estimate /* Define user defined memory location index (i.e. first user defined memory location) */ #define P_TOTAL_VOLUME 0 /* Total particle volume in each cell (m^3) */ DEFINE_PROPERTY(cell_viscosity,c,t) { /*Variables*/ real H_Vol,strain, Beta, Mu_Blood; /* Domain and pointers*/ Domain *domain = Get_Domain(1); Injection *I, *Ilist = Get_dpm_injections(); Particle *p; Thread *tc; real cell_particle_volume = 0.0; /* Reset UDM to zero */ thread_loop_c(tc, domain) { begin_c_loop(c, tc) { C_UDMI(c, tc, P_TOTAL_VOLUME)= 0.0; } end_c_loop(c, tc); } /* Loop through all injections */ loop(I, Ilist) { /* Loop through all particles */ loop(p, I>p_init) { Thread *t0 = P_CELL_THREAD(p); c = P_CELL(p); cell_particle_volume = M_PI * (P_DIAM(p) * P_DIAM(p) * P_DIAM(p)) * p>number_in_parcel / 6.0; C_UDMI(c, t0, P_TOTAL_VOLUME) += cell_particle_volume; } } Message("It works till this point"); /* Calculating the solid volume fraction. It goes wrong with the pointers I think */ H_Vol = C_UDMI(c,t0,P_TOTAL_VOLUME)/C_VOLUME(c,tc); Message("H_Vol %f\n",H_Vol); /* Get the magnitude of the strain rate at each cell */ strain = C_STRAIN_RATE_MAG(c,t); Message("1"); /* calculate the Beta factor => see articles for viscosity */ Beta =1 + b/pow(strain,n); Message("2"); /* Depending on the hematocrit fraction, calculating the viscosity of the blood.*/ if(H_Vol == 0) {Mu_Blood =1.65e3; } else if (H_Vol < 0.70) {Mu_Blood = Mu_Plasma*Beta*(1H_Vol)*exp(4.1* H_Vol/(1.64 H_Vol)); } else {Mu_Blood = Mu_Plasma*Beta*(alpha* H_Vol)/pow(1 H_Vol,k);} return Mu_Blood; } 

August 26, 2015, 06:53 

#5 
Senior Member
Join Date: Mar 2015
Posts: 416
Rep Power: 5 
The DEFINE_PROPERTY macro has the two argument types cell_t c and Thread *t which are used to identify the particular cell that the Fluent solver has called said macro on.
Firstly, you've overwritten c on line 48 with: Code:
c = P_CELL(p); Secondly, the cell c belongs to thread t, which might be different to t0 and tc (both used in line 58): Code:
H_Vol = C_UDMI(c,t0,P_TOTAL_VOLUME)/C_VOLUME(c,tc); Thirdly, this particle volume fraction is calculated for each cell for every cell called by DEFINE_PROPERTY (probably number of cells^2 times). If this poses a high computational expense, perhaps run this volume calculation at the start of the time step (DEFINE_ADJUST) or with a DPM macro (double check when they're called by the solver). Your UDF might not work in parallel; so start with the serial solver and then parallelise the UDF if needed. Lastly, it's best practice to have trailing periods for real numbers for example "1." (lines 66, 73 and 76) to avoid data type confusion. 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
mpirun interFoam very stable > then blows up  ghadab  OpenFOAM Running, Solving & CFD  3  October 27, 2013 11:34 
injection problem  Mark New  FLUENT  0  August 4, 2013 01:30 
nonorthogonal faces and incorrect orientation?  nennbs  OpenFOAM Native Meshers: blockMesh  7  April 17, 2013 05:42 
Water subcooled boiling  Attesz  CFX  7  January 5, 2013 04:32 
help: define volume of fraction using UDF in VOF  gogo  FLUENT  0  January 17, 2006 16:58 