CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Mass flow rate defined by velocity function and inlet area (https://www.cfd-online.com/Forums/fluent-udf/156977-mass-flow-rate-defined-velocity-function-inlet-area.html)

 saml July 16, 2015 11:26

Mass flow rate defined by velocity function and inlet area

Hi,

Apologies if this questions has been asked, I can't find the solution I'm looking for. I'm new to using Fluent. I am trying to figure out how to get a UDF working where a defined velocity and density is given and then mass flow rate is calculated dependent on the inlet surface area. As an example, the velocity profile is given here https://confluence.cornell.edu/pages...geId=268895958

If I change the variable, totalarea to a value that I have calculated manually, the resultant measured velocity is as expected.
It appears that the problem is in the totalarea += NV_MAG(area), it does not output the correct inlet surface area. Not sure what I'm missing. Any help would be greatly appreciated.

#include "udf.h"
#define PI 3.141592654

#define bloodrho 1060

real area[ND_ND];
real totalarea=0.0;

DEFINE_PROFILE(inlet_massflowrate,th,i)
{
{
face_t f;
double t = (CURRENT_TIME*2-floor(CURRENT_TIME*2))/2;
begin_f_loop(f,th)
{
F_AREA(area,f,th);
totalarea += NV_MAG(area);
printf("Area= %d\n",totalarea);
if(t <= 0.218)
F_PROFILE(f,th,i) = bloodrho*(0.5*sin(4*PI*(t+0.0160236)))*totalarea;
else
F_PROFILE(f,th,i) = bloodrho*0.1*totalarea;
}
end_f_loop(f,th);
}
}

Thanks!

 Kokemoor July 16, 2015 13:17

You'll need to have two loops to do this: one to calculate the total area, then a second to set the profile. Doing it in one loop means that the profile is being set the with the area computed so far, not the actual total area.

I think you'll also want to reinitialize totalarea=0 inside the DEFINE_PROFILE macro, before the loop. Otherwise, your totalarea will continue to grow every iteration.

 saml July 16, 2015 22:58

Quote:
 Originally Posted by Kokemoor (Post 555763) You'll need to have two loops to do this: one to calculate the total area, then a second to set the profile. Doing it in one loop means that the profile is being set the with the area computed so far, not the actual total area. I think you'll also want to reinitialize totalarea=0 inside the DEFINE_PROFILE macro, before the loop. Otherwise, your totalarea will continue to grow every iteration.
Great, thanks for the help. I've done the changes and with using printf, I can see the output of "total area". I'm using a cylinder to test the code out. I know the surface area is around 0.049 m^2.
The output of the printf is a list? Not sure if it's meant to be a list but if I summed the listed values,
6.642245e-03
4.322405e-03
2.799194e-03
0.000000e+00
1.558870e-02
5.616377e-03
9.217984e-03
4.651606e-03

It's about 0.049 or is this a coincidence? How do I sum these values in the UDF?

Code:

```#include "udf.h" #define PI 3.141592654 #define bloodrho 1060 DEFINE_PROFILE(inlet_massflowrate,th,i) {         real totalarea=0.0;         real area[ND_ND];         face_t f;         begin_f_loop(f,th)         {         F_AREA(area,f,th);         totalarea+=NV_MAG(area);         }         end_f_loop(f,th)         printf("%e\n",totalarea);                 begin_f_loop(f,th)                 {                 double t = (CURRENT_TIME*2-floor(CURRENT_TIME*2))/2;                 if(t <= 0.218)                         F_PROFILE(f,th,i) = bloodrho*0.5*sin(4*PI*t+0.0160236)))*0.049;0160236)))*totalarea;                 else                         F_PROFILE(f,th,i) = bloodrho*0.1*totalarea;                 }                 end_f_loop(f,th); }```
Thanks!

 pakk July 17, 2015 06:43

You get eight numbers... Are you doing a parallel calculation with 8 processes? If so, you will have to add some code to let the processes talk to each other, since they should communicate what the total area is. I don't know from my head how, but the manual helps here.

But in any case, I would start to get it working in serial mode, and only when that works go towards parallel.

 Kokemoor July 17, 2015 12:08

pakk is exactly right. Make sure it works in serial first, then look up global reduction macros, Section 7.5.4 in the UDF Manual.

 All times are GMT -4. The time now is 20:39.