CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   UDF Mass flux computing (https://www.cfd-online.com/Forums/fluent/67211-udf-mass-flux-computing.html)

Carlo August 7, 2009 04:41

UDF Mass flux computing
 
Hi everybody: I'm trying to write an UDF which calculates the mass flux of an outlet. I need it to calculate a pollutant concentration: for this reason the DEFINE in which my computing is inserted is the DEFINE_ADJUST. my problem is that this udf doesn't return the total mass flux value I get from the REPORT tool.

The problem is 2D axisymmetric, so my outlet is seen like a circular area.

#include "udf.h"

DEFINE_ADJUST(massflux, domain)
{
int zone_ID = 4;
Thread *t = Lookup_Thread(domain,zone_ID);
face_t f;
float r, x[2];
real summ=0.;
real m;
real NV_VEC (A);
begin_f_loop(f,t)
{
F_CENTROID(x,f,t);
r=x[1];
F_AREA(A,f,t);
m=F_U(f,t)*F_R(f,t)*NV_MAG(A)*6.28*r;
summ += m;
}
end_f_loop(f,t)
printf("massf: %g\n", summ);
}

The 6.28 is from 2*pi. It derives because of the area computing in polar coordinates. If you have any idea to carry on the computing in a simpler way, please tell me it.

Last thing: I don't get any error while fluent compiles it. It's just that I obtain different values.

THANKS

PawnPace August 11, 2009 22:41

Please check your formulation
 
I believe that your formulation is incorrect for flux. You just add the mass flow rate for each face and then finally divide by pi*Rmax^2.

I'm not sure why you are using 2*pi*r*area in the evaluation of m.

Instead you need to replace area by dr (i.e cell length in r direction). You will have m_dot = rho*U*2*pi*r*dr.

I am assuming that the actual flow velocity is in the U direction i.e flow parallel to the area vector.

The other way is to use the F_FLUX(f,t) macro and if needed you can play with it. I'm not sure if this macro accounts for axisymmetric calculations!


Good Luck and have fun!

Carlo August 12, 2009 04:03

Annulus
 
Dear PawnPace,
let's imagine an outlet of a 2d grid: it is formed by several segments. Now, when you ask to fluent to consider the case as axisymmetric, you obtain a cylinder as you can see in this link:

http://jullio.pe.kr/fluent6.1/help/html/ug/node347.htm

Now, doing this in the outlet, for each segment you have an Annulus. The area of an Annulus is:
(R^2 - r^2)*pi

Considering it as infinitesimal you get:
((r+dr)^2-r^2)*pi=(r^2+2rdr+dr^2-r^2)*pi

Neglecting the dr^2 you have that the infinitesimal area of the considered Annulus is 2pi*r*dr. Applying all this to our case, you have that r and dr are respectively the y coordinate and the height of the generic segment of the outlet. You have to sum the area of each Annulus multiplied for the density and for the velocity axial component. By this the 2*pi derives.

Anyway, I'm going to try your hints and I'll let you know about :)

PawnPace August 12, 2009 13:49

I think there was some misunderstanding. Anyway I just wanted to tell you that your formulation of mass flow rate does not match units on right side of your equation.

Since, you are using 2d formulation and the area for the face (i think it) is the edge length multiplied by unit depth (not sure). Numerically your equation may be correct but dimensionally it is not.

Well I hope my posts were helpful!

Regards,

PawnPace

Carlo August 17, 2009 11:19

I did it!
 
Well, I did it!

#include "udf.h"

DEFINE_ADJUST(massflux, domain)
{
int zone_ID = 4;
Thread *t = Lookup_Thread(domain,zone_ID);
face_t f;
real summ=0.;
real m;
real sumarea=0.;
real area;
real NV_VEC (A);
begin_f_loop(f,t)
{
F_AREA(A,f,t);
m=F_U(f,t)*F_R(f,t)*NV_MAG(A)*6.28;
summ += m;
area=NV_MAG(A)*6.28;
sumarea += area;
}
end_f_loop(f,t)
printf("massf: ,%g,%g\n", summ,sumarea);
}

Well, this works fine! It makes me get exactly what I wanted both in terms of area and mass flux. Thanks to your suggestion, I thought that multiply an area by a length (in our case r) could be dimensionally wrong.
So I decided to multiply only by the area deleting 2*pi*r. After having done it, results were still wrong. Fortunately I've thought to look at what was the ratio between my (wrong) results and the ones I would have wanted to get. Well, that ratio was exactly 6.28! This is the reason the 6.28 lasts. In order to prove if It was right, I've tried it also in others domains and It computes the right area and mass flux in all of them!
So I think that the NV_MAG(A) in axisymmetric cases is just the r*dr we spoke above, which is the difference between R^2 and r^2.
Thanks you!

PawnPace August 17, 2009 12:22

I'm glad that it's resolved! Good Luck and have fun with Fluent! Regards, PawnPace

sam_paris November 23, 2014 21:59

thanks a lot! but I use your code but i didn't got the cooperate massflow.
 
Quote:

Originally Posted by Carlo (Post 226591)
Well, I did it!

#include "udf.h"

DEFINE_ADJUST(massflux, domain)
{
int zone_ID = 4;
Thread *t = Lookup_Thread(domain,zone_ID);
face_t f;
real summ=0.;
real m;
real sumarea=0.;
real area;
real NV_VEC (A);
begin_f_loop(f,t)
{
F_AREA(A,f,t);
m=F_U(f,t)*F_R(f,t)*NV_MAG(A)*6.28;
summ += m;
area=NV_MAG(A)*6.28;
sumarea += area;
}
end_f_loop(f,t)
printf("massf: ,%g,%g\n", summ,sumarea);
}

Well, this works fine! It makes me get exactly what I wanted both in terms of area and mass flux. Thanks to your suggestion, I thought that multiply an area by a length (in our case r) could be dimensionally wrong.
So I decided to multiply only by the area deleting 2*pi*r. After having done it, results were still wrong. Fortunately I've thought to look at what was the ratio between my (wrong) results and the ones I would have wanted to get. Well, that ratio was exactly 6.28! This is the reason the 6.28 lasts. In order to prove if It was right, I've tried it also in others domains and It computes the right area and mass flux in all of them!
So I think that the NV_MAG(A) in axisymmetric cases is just the r*dr we spoke above, which is the difference between R^2 and r^2.
Thanks you!


I think the original F_FLUX function could bring a similar flux result, but not accurate, hope for your reply!

11-24 11:06
I work it out! I think maybe the unaccuracy was cuased by an unsteady flow.


All times are GMT -4. The time now is 03:12.