CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

Accessing the species mass fraction for particles data in UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By siramirsaman

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 7, 2015, 10:50
Smile Accessing the species mass fraction for particles data in UDF
  #1
New Member
 
Luleå tekniska universitet
Join Date: May 2015
Location: LTU, Luleå, Sweden
Posts: 11
Rep Power: 11
mac_09 is on a distinguished road
Hello all,

I am doing the spray simulation using the DPM modelling with the composition PDF method.

I am trying to access the particles species mass fraction in the UDF.

I know there are MACROS for particles like:
P_MASS (p) = particles mass
P_T(p) = particles temperature

How to access the species mass fraction for the particles?

Thanks in advanced.

Regards:
Chishty
mac_09 is offline   Reply With Quote

Old   June 20, 2015, 12:47
Default
  #2
New Member
 
Join Date: Dec 2010
Posts: 15
Rep Power: 16
siramirsaman is on a distinguished road
TP_COMPONENT_I(p,is) is the macro that gives you mass fraction inside each particle.

I will add an example here on how to use it:

int is;
int nc = TP_N_COMPONENTS(p); /* number of particle components */
printf("\n######");
for (is = 0; is < nc; is++)
{
int gas_index = TP_COMPONENT_INDEX_I(p,is); /* index of vaporizing component in the gas phase */
printf(" gas_index=%d is=%d TP_COMPONENT_I=%e ",gas_index,is,TP_COMPONENT_I(p,is));
}
printf("#######$\n");

To look in closely,

TP_N_COMPONENTS(p) gives you the total number of components inside each particle.

TP_COMPONENT_INDEX_I(p,is) gives gas index. if the component is not meant to evaporate, this gives -1.

and TP_COMPONENT_I(p,is) actually gives you the mass fraction.

Last edited by siramirsaman; June 20, 2015 at 15:56.
siramirsaman is offline   Reply With Quote

Old   June 21, 2015, 02:47
Default
  #3
New Member
 
Luleå tekniska universitet
Join Date: May 2015
Location: LTU, Luleå, Sweden
Posts: 11
Rep Power: 11
mac_09 is on a distinguished road
Hello Amirsaman,

Thanks for your reply.
I got this error when I tired to compile my UDF

qrad_source.c:18: error: 'Particle' has no member named 'component'

Here is my UDF:

#include "udf.h"
#include "pdf_transport.h"
#include "dpm.h"
#include "mem.h"
#include "materials.h"
FILE *fp;
DEFINE_SOURCE(rad_source,c,t,dS,eqn)
{
Particle *p;
int id_o2=0;
/***************************************/
Material *mat = THREAD_MATERIAL(t); /* This segment determines the species index number */
id_o2 = mixture_specie_index(mat, "o2");
/**************************************/
begin_particle_cell_loop(p,c,t)
{
fp = fopen("check.dat", "a");
fprintf(fp,"%g\t%g\t%g\t%g\t\n",CURRENT_TIME,C_YI( c, t, id_o2),TP_COMPONENT_I(p,id_o2));
fclose(fp);
}
end_particle_cell_loop(p,c,t)

return 0;
}

Is this "TP_COMPONENT_I(p,is)" hidden in some libraries?
I am using FLUENT 14.5.

Thanks again for your time and help.

Regards:
Chishty
mac_09 is offline   Reply With Quote

Old   June 21, 2015, 11:54
Default
  #4
New Member
 
Join Date: Dec 2010
Posts: 15
Rep Power: 16
siramirsaman is on a distinguished road
you need to use this in one of DPM UDF codes where particle is inputted among function inputs, like this DPM code where "p" is inputted to the function:

DEFINE_DPM_PROPERTY(coal_cp,c,t,p,T)
{
real mp0= P_INIT_MASS(p);
real mp = P_MASS(p);
real cf = P_CF(p); /*char fraction */
real vf = P_VF(p); /* volatiles fraction */
real af = 1. - P_VF(p) - P_CF(p); /* ash fraction */
real Cp = 2000*af + 1100*vf + 1300*cf;
p->enthalpy = Cp*(T-T_REF);
return Cp;
}


I am guessing in your code, the line where you define "Particle *p", just creates a pointer that is meant to point to a particle structure. However this pointer is never assigned to an actual particle and hence is never initialized. So you need to utilize it in DPM UDFs, where like the example above, the particle pointer is already initialized as an input to the function.

try the function like this:


DEFINE_DPM_PROPERTY(viscosity,c,t,p,T)
{

int is;
int nc = TP_N_COMPONENTS(p); /* number of particle components */
printf("\n######");
for (is = 0; is < nc; is++)
{
int gas_index = TP_COMPONENT_INDEX_I(p,is); /* index of vaporizing component in the gas phase */
printf(" gas_index=%d is=%d TP_COMPONENT_I=%e ",gas_index,is,TP_COMPONENT_I(p,is));
}
printf("#######$\n");

return (0.001);
}


Compile the function above and use it in Materials tab to assign the viscosity of the mixture component "Particle Mixture", or the viscosity of one the components that are inside each particle.
siramirsaman is offline   Reply With Quote

Old   June 21, 2015, 12:57
Default
  #5
New Member
 
Join Date: Dec 2010
Posts: 15
Rep Power: 16
siramirsaman is on a distinguished road
I also got the feeling that you are trying to adjust source terms inside domain due to particle existence. If that is the case, trying having a look at fluent examples for:

DEFINE_DPM_HEAT_MASS (name, p, C_p, hgas, hvap, cvap_surf, Z, dydt, dzdt)
or
DEFINE_DPM_SOURCE (name, c, t, S, strength, p)
siramirsaman is offline   Reply With Quote

Old   June 21, 2015, 22:27
Default
  #6
New Member
 
Luleå tekniska universitet
Join Date: May 2015
Location: LTU, Luleå, Sweden
Posts: 11
Rep Power: 11
mac_09 is on a distinguished road
Quote:
Originally Posted by siramirsaman View Post
I also got the feeling that you are trying to adjust source terms inside domain due to particle existence. If that is the case, trying having a look at fluent examples for:

DEFINE_DPM_HEAT_MASS (name, p, C_p, hgas, hvap, cvap_surf, Z, dydt, dzdt)
or
DEFINE_DPM_SOURCE (name, c, t, S, strength, p)
I am trying to couple the DOM radiation model with the TPDF model for my diesel spray soot simulation in FLUENT.
The DOM energy coupling with the TPDF is not available in FLUENT, as the DOM solves the radiation source term at the CFD resolution and the TPDF solves the energy equation on the particle side.

So, I am trying to give the negative of radiation source term in the energy equation.

For the complete TRI, I need to update the absorption co-efficient using the particle data. For this, I need the mass fraction of soot, CH4 & CO2, but the problem is I did not find any macro for the species mass fraction of the particles.

I tried to print TP_COMPONENT_I(p,8) where "8" is the location of oxygen in my chemical mechanism, but it does not work.
mac_09 is offline   Reply With Quote

Old   June 22, 2015, 17:23
Default
  #7
New Member
 
Join Date: Dec 2010
Posts: 15
Rep Power: 16
siramirsaman is on a distinguished road
Unfortunately I am not familiar with SOOT simulations. A couple of ideas, and perhaps maybe someone else could also help.

I do not think it will be possible to access particles inside fluid domain macros. You will be able to work with mass fractions released from particles into each cell, but I am not sure if the particles in each cell can be accessed from macros designed for fluid part.

I have a suggestion that might work for you, done it in the past, needs a little bit of caution.

So you need to access particle data inside a macro that is not designed for particles. I suggest you use two macros and a couple of global variables.

One macro for fluid part, one macro for particles and global variables to establish the connection between these two.

In the particle macro, you can access particle info's. Better than that, you can have a global variable for particles, let's say an array of pointers that are going to point to particles, like Particle * Array_p[1000]. I am not sure if this is possible.

If you could create a global pointer array like that, then you can use particle UDF macros to copy available particle pointers to the global array. These particles can then be accesses in the macro inside fluid domain.

The main challenge will be tracking particles that are dead and also to make sure you do not overwrtie particle addresses in your global array.

All this said, perhaps there might be a much easier way out there!
siramirsaman is offline   Reply With Quote

Old   June 22, 2015, 23:24
Default
  #8
New Member
 
Luleå tekniska universitet
Join Date: May 2015
Location: LTU, Luleå, Sweden
Posts: 11
Rep Power: 11
mac_09 is on a distinguished road
Thanks for your time and suggestions.

I will look into it.

But just one quick question, is there any MACRO assigned to access the species mass fraction of particles whether in DEFINE_SOURCE or DPM MACRO's?

If it is, than in which MACRO?

I will access that and safe into the UDM, so I can access it anywhere.

mac_09 is offline   Reply With Quote

Old   June 23, 2015, 00:44
Default
  #9
New Member
 
Join Date: Dec 2010
Posts: 15
Rep Power: 16
siramirsaman is on a distinguished road
In the header file, dpm_types.h, the function has been defined as

#define TP_COMPONENT_I(tp,i) (tp->component.state[i])

which is accessing the component.state member in the "tp" particle. component.state[i] is the mass fraction of each component that you are looking for.

I think even by modifying macros, you will still miss the link to access pointer to particles that have already been injected inside the domain.

All DPM macros like the one below are inputted particle pointer as an input:

#define DEFINE_DPM_SOURCE(name, c, t, S, strength, p) \
void name(cell_t c, Thread *t, dpms_t *S, real strength, Tracked_Particle *p)
siramirsaman is offline   Reply With Quote

Old   July 10, 2016, 06:38
Default
  #10
New Member
 
Yin Xu
Join Date: Aug 2015
Posts: 1
Rep Power: 0
seu_007 is on a distinguished road
Quote:
Originally Posted by siramirsaman View Post
TP_COMPONENT_I(p,is) is the macro that gives you mass fraction inside each particle.

I will add an example here on how to use it:

int is;
int nc = TP_N_COMPONENTS(p); /* number of particle components */
printf("\n######");
for (is = 0; is < nc; is++)
{
int gas_index = TP_COMPONENT_INDEX_I(p,is); /* index of vaporizing component in the gas phase */
printf(" gas_index=%d is=%d TP_COMPONENT_I=%e ",gas_index,is,TP_COMPONENT_I(p,is));
}
printf("#######$\n");

To look in closely,

TP_N_COMPONENTS(p) gives you the total number of components inside each particle.

TP_COMPONENT_INDEX_I(p,is) gives gas index. if the component is not meant to evaporate, this gives -1.

and TP_COMPONENT_I(p,is) actually gives you the mass fraction.
Thank you, siramirsaman. Your answers really fix my problem. It works and gives the mass fraction of components in particles when I use the DPM Macros (DEFINE_DPM_HEAT_MASS). Again, Thanks for your kindness!
seu_007 is offline   Reply With Quote

Old   January 10, 2017, 01:31
Default
  #11
Senior Member
 
Join Date: Jun 2014
Location: Taiwan
Posts: 100
Rep Power: 12
SJSW is on a distinguished road
Hi~
I found this in the example of DEFINE_DPM_HEAT_MASS :

real molwt[MAX_SPE_EQNS]; /* molecular weight of gas species */
real molwt_bulk = 0.; /* average molecular weight in bulk gas */
molwt[ns] = MATERIAL_PROP(sp,PROP_mwi); /* molecular weight of gas species */
molwt_bulk += c->yi[ns] / molwt[ns]; /* average molecular weight */
/* bulk gas concentration (ideal gas) */
real cvap_bulk = c->pressure / UNIVERSAL_GAS_CONSTANT / c->temp * c->yi[gas_index] / molwt_bulk / solver_par.molWeight[gas_index];

and this in DEFINE_DPM_VP_EQUILIB :

real molwt_cond = 0.; /* reciprocal molecular weight of the particle */
/* the molecular weight of particle material */
molwt[gas_index] = MATERIAL_PROP(MIXTURE_COMPONENT(gas_mix,gas_index) ,PROP_mwi);
molwt_cond += TP_COMPONENT_I(p,is) / molwt[gas_index];
/* condensed component molefraction */
real xi_cond = TP_COMPONENT_I(p,is)/(molwt[gas_index]*molwt_cond);

Q1. Do "c->yi[ns]" and "TP_COMPONENT_I(p,is)" both mean mass fraction ?
Q2. If the answer of Q1 is Yes, why molwt_bulk += c->yi[ns] / molwt[ns] ?
SJSW is offline   Reply With Quote

Old   January 10, 2017, 01:39
Default
  #12
New Member
 
Join Date: Dec 2010
Posts: 15
Rep Power: 16
siramirsaman is on a distinguished road
Both are, but in different places. The first one is the mass fraction inside each cell ("c"), so lets say you have gas mixtures like water vapour, air etc that shows the fraction of each gs species. Hence it had to be divided by the average molecular weight of the mixture. This one so goes for the finite volume solver.

The second is the mass fraction inside each injected drop. So if you have water and other compounds, gives you the mass fraction there. This one is for the discrete phase model.

[QUOTE=SJSW;632653]
Q1. Do "c->yi[ns]" and "TP_COMPONENT_I(p,is)" both mean mass fraction ?
Q2. If the answer of Q1 is Yes, why molwt_bulk += c->yi[ns][COLOR="Red"] /
SJSW likes this.
siramirsaman is offline   Reply With Quote

Old   January 10, 2017, 04:00
Default
  #13
Senior Member
 
Join Date: Jun 2014
Location: Taiwan
Posts: 100
Rep Power: 12
SJSW is on a distinguished road
The unit of "molwt_cond" could be mole/kg, according to the description "reciprocal molecular weight of the particle".
Then molwt_cond += TP_COMPONENT_I(p,is) / molwt[gas_index].

However, The unit of "molwt_bulk" could be kg/mole, according to the description "average molecular weight in bulk gas".
Then why molwt_bulk += c->yi[ns] / molwt[ns] ?

Does "molwt[gas_index] = MATERIAL_PROP(MIXTURE_COMPONENT(gas_mix,gas_index) ,PROP_mwi)" mean kg/mole, mole/kg or something else? @@
SJSW is offline   Reply With Quote

Old   January 11, 2017, 00:25
Default
  #14
New Member
 
Join Date: Dec 2010
Posts: 15
Rep Power: 16
siramirsaman is on a distinguished road
I am not sure if I follow this correctly, perhaps this might help. In your gas mixture (gas surrounding your particles) the average molecular weight can be calculated using the following loop over all species:

Code:
int ns;
Material *sp;
Material *gas_mix = THREAD_MATERIAL(DPM_THREAD(t0, p)); 
mixture_species_loop(gas_mix, sp, ns)
{
     molwt_bulk += c->yi[ns] / MATERIAL_PROP(sp, PROP_mwi); /* average molecular weight */
}

and as you mentioned, for the vaporizing components inside the particles, the following loop is used:

Code:
for (is = 0; is < nc; is++)
{
int gas_index = TP_COMPONENT_INDEX_I(p,is); /* index of vaporizing component in the gas phase */
     if (gas_index >= 0)
     {
          /* the molecular weight of particle material */
          molwt[gas_index] = MATERIAL_PROP(MIXTURE_COMPONENT(gas_mix,gas_index),PROP_mwi);
          molwt_cond += TP_COMPONENT_I(p,is) / molwt[gas_index];
     }
}


Now the averaging I think is done as follows and it is called harmonic mean:

Code:
\frac{1}{\bar{M}}= \sum_i\frac{w_i}{M_i}
So the variable that is confusing I think should be \frac{1}{\bar{M}}. Here, \bar{M} is the average molar mass and w_i is the mass fractions.
siramirsaman is offline   Reply With Quote

Old   January 11, 2017, 07:28
Default
  #15
Senior Member
 
Join Date: Jun 2014
Location: Taiwan
Posts: 100
Rep Power: 12
SJSW is on a distinguished road
If there is a mixture composing of A and B,

for mass balance, unit :kg
m_total=ma+mb

for mole balance,
m_total/W_total=ma/wa+mb/wb
=>1/W_total=ma/m_total*1/wa+mb/m_total*1/wb

W_total is average molecular weight.
1/W_total is reciprocal molecular weight of the particle.

Then,
The unit of "molwt_cond" could be mole/kg, according to the description "reciprocal molecular weight of the particle".
I can see why "molwt_cond += TP_COMPONENT_I(p,is) / molwt[gas_index]".

However, The unit of "molwt_bulk" could be kg/mole, according to the description "average molecular weight in bulk gas".
Then why
"molwt_bulk += c->yi[ns] / molwt[ns]",
but not
"molwt_bulk += c->yi[ns] / molwt[ns];"
"molwt_bulk=1.0/molwt_bulk" ?

and in the example of DEFINE_DPM_HEAT_MASS:

/* bulk gas concentration (ideal gas) */
real cvap_bulk = c->pressure / UNIVERSAL_GAS_CONSTANT / c->temp * c->yi[gas_index] / molwt_bulk / solver_par.molWeight[gas_index];

this "molwt_bulk" seems --------

Wait, OK...I see what the answer is:
molwt_bulk is not "average molecular weight in bulk gas", it is "total amount of moles".
SJSW is offline   Reply With Quote

Old   August 9, 2017, 14:33
Default
  #16
New Member
 
Martin
Join Date: Apr 2017
Location: Germany
Posts: 26
Rep Power: 9
2phase is on a distinguished road
Quote:
Originally Posted by siramirsaman View Post
I am not sure if I follow this correctly,

[...]

Code:
\frac{1}{\bar{M}}= \sum_i\frac{w_i}{M_i}
So the variable that is confusing I think should be \frac{1}{\bar{M}}. Here, \bar{M} is the average molar mass and w_i is the mass fractions.
To add something to SJSW's conclusion, because I stumbled upon the same "problem":
ANSYS just did not molwt_{bulk}^{-1} = \bar{M} and reverse. They just left out that step and it resolves in the end - just try it...

The line for cvap_bulk = ...
uses ideal gas law to calculate the concentration, where cvap_{bulk} =  \frac{n_i}{V} = \frac{p_i}{R T}

with p_i =  p_{cell} \cdot x_i with x_i as the mole fraction.

And the mole fraction can be calculated via x_i =  \frac{w_i / M_i}{\sum{w_z / M_z}}

which is \sum{w_z / M_z} =  molwt_{bulk} = \bar{M}^{-1}

(For Germans) even the name molecular weight is irritating as it possibly should be called molar weight.

#fluent #dpm #heat mass transfer #UDF #molecular weight #molwt_bulk
2phase is offline   Reply With Quote

Old   August 9, 2017, 14:36
Default
  #17
New Member
 
Martin
Join Date: Apr 2017
Location: Germany
Posts: 26
Rep Power: 9
2phase is on a distinguished road
An additional question: does anyone have an idea, why the once use

MATERIAL_PROP(sp,PROP_mwi)
and the other time
solver_par.molWeight[gas_index]
2phase is offline   Reply With Quote

Old   August 9, 2017, 21:15
Default
  #18
Senior Member
 
Join Date: Jun 2014
Location: Taiwan
Posts: 100
Rep Power: 12
SJSW is on a distinguished road
It seems MATERIAL_PROP(sp,PROP_mwi) is for gas species, and solver_par.molWeight[gas_index] is for species in a particle ?
SJSW is offline   Reply With Quote

Reply

Tags
composition pdf method, dpm, macros, udf and programming


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Species Mole and Mass Fraction Macro combustion FLUENT 18 February 5, 2024 13:23
Gradient of species mass fraction zhou FLUENT 1 March 14, 2020 07:28
Problem of simulating of small droplet with radius of 2mm liguifan OpenFOAM Running, Solving & CFD 5 June 3, 2014 03:53
Low Mixing time Problem Mavier CFX 5 April 29, 2013 01:00
UDF for species mass fractions MRR FLUENT 0 December 29, 2005 08:14


All times are GMT -4. The time now is 16:40.