CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Accessing the species mass fraction for particles data in UDF (https://www.cfd-online.com/Forums/fluent/153945-accessing-species-mass-fraction-particles-data-udf.html)

mac_09 June 7, 2015 09:50

Accessing the species mass fraction for particles data in UDF
 
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

siramirsaman June 20, 2015 11:47

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.

mac_09 June 21, 2015 01:47

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

siramirsaman June 21, 2015 10:54

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 June 21, 2015 11:57

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)

mac_09 June 21, 2015 21:27

Quote:

Originally Posted by siramirsaman (Post 551408)
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.

siramirsaman June 22, 2015 16:23

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! ;)

mac_09 June 22, 2015 22:24

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.

:)

siramirsaman June 22, 2015 23:44

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)

seu_007 July 10, 2016 05:38

Quote:

Originally Posted by siramirsaman (Post 551325)
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!

SJSW January 10, 2017 00:31

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] ?

siramirsaman January 10, 2017 00:39

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 January 10, 2017 03:00

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? @@

siramirsaman January 10, 2017 23:25

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.

SJSW January 11, 2017 06:28

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".

2phase August 9, 2017 13:33

Quote:

Originally Posted by siramirsaman (Post 632778)
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 August 9, 2017 13:36

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]

SJSW August 9, 2017 20:15

It seems MATERIAL_PROP(sp,PROP_mwi) is for gas species, and solver_par.molWeight[gas_index] is for species in a particle ?


All times are GMT -4. The time now is 02:29.