CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

Particle Volume Fraction UDF

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By `e`

Reply
 
LinkBack Thread Tools Display Modes
Old   August 17, 2015, 06:43
Default Particle Volume Fraction UDF
  #1
New Member
 
NNM_BSP
Join Date: Aug 2015
Posts: 5
Rep Power: 2
AP3181 is on a distinguished road
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);

}
AP3181 is offline   Reply With Quote

Old   August 17, 2015, 10:13
Default
  #2
New Member
 
NNM_BSP
Join Date: Aug 2015
Posts: 5
Rep Power: 2
AP3181 is on a distinguished road
Could the Macro C_VOF be used in the DDPM? That would solve most of the problem...
AP3181 is offline   Reply With Quote

Old   August 18, 2015, 06:09
Default
  #3
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 416
Rep Power: 5
`e` is on a distinguished road
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:
  1. Loop through all of the particles (start with the UDF you have posted)
  2. Sum the number of particles in each cell with User-Defined Memory (UDM)
  3. Divide the particle volume by the cell volume

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.
`e` is offline   Reply With Quote

Old   August 25, 2015, 07:23
Default
  #4
New Member
 
NNM_BSP
Join Date: Aug 2015
Posts: 5
Rep Power: 2
AP3181 is on a distinguished road
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.65e-3 // Pa.s
#define VolPart 92e-6 //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.65e-3; }

else if (H_Vol < 0.70)
{Mu_Blood = Mu_Plasma*Beta*(1-H_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;
}
AP3181 is offline   Reply With Quote

Old   August 26, 2015, 06:53
Default
  #5
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 416
Rep Power: 5
`e` is on a distinguished road
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);
Change this variable to something else.

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);
Change the thread pointer to t.

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.
AP3181 likes this.
`e` is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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
non-orthogonal 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


All times are GMT -4. The time now is 19:14.