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

UDF to measure Mass Flow Rate

Register Blogs Community New Posts Updated Threads Search

Like Tree20Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 10, 2010, 07:16
Default
  #1
New Member
 
adrian lynch
Join Date: Feb 2010
Posts: 9
Rep Power: 16
a.lynchy is on a distinguished road
Hi Kartn
The problem with the previous code that I posted was in getting the value for the variable “flow” from the DEFINE_EXECUTE_AT_END section and using it in the DEFINE_PROFILE. The way it was set as a global variable was okay but what was happening was it was been set to zero after the DEFINE_EXECTUE_AT_END loop so the DEFINE_PROFILE function was seeing a value of flow=0. Sorry if what I am saying is hard to follow, but I have attached the working code below and maybe from comparing the two you will be able to understand.
The only real different is in introducing the flow_tot variable as the global variable instead of using the flow variable.

#include"udf.h"
real flow_tot;
real p ;

DEFINE_EXECUTE_AT_END(funny)
{
Domain *d;

real flow;
cell_t c;
Thread *t;
face_t f;
d = Get_Domain(1);
t= Lookup_Thread(d, 12);

begin_f_loop(f,t)
{
flow+=F_FLUX(f,t);
}
end_f_loop(f,t)
p = C_P(c,t);
printf(
"static pressure = %g\n", p);
printf(
"MASS Flow Rate: %g\n",flow);
flow_tot =flow;
flow=0.;
}

DEFINE_PROFILE(pressure_out,t,i)
{
real set_point = 1;
real pressure;
face_t f;




printf(
"MASS Flow Rate: %g\n",flow_tot);
if (flow_tot < set_point)

pressure = p - 1;

elseif (flow_tot > set_point)

pressure = p + 1;

else
pressure = p;



begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = pressure;
}
end_f_loop(f,t)
printf(
"Adjusted pressure = %g\n", pressure);
}

Hope this helps!
a.lynchy is offline   Reply With Quote

Old   February 22, 2011, 02:48
Default Udf for applying transient mass flow rate
  #2
New Member
 
zubair
Join Date: Feb 2011
Posts: 2
Rep Power: 0
mdzubairmanipal@gmail.com is on a distinguished road
I am trying to figure out how to write a udf for applying a transient mass flow rate at the inlet. In my case study the mass flow rate varies with time from 0 to 40L/min and then comes down to zero in one cycle that ranges from 0 to 4 sec.

If anybody have a ready made udf, i wud be grateful if u could plz post it in this link or pass on through my email id.

I admit i am have a bad programming knowledge but since it is bit urgent, i have to seek ur opinion and help without having to take the pain to learn it myself.

Plz do help
mdzubairmanipal@gmail.com is offline   Reply With Quote

Old   June 21, 2011, 21:43
Default
  #3
Member
 
Join Date: Mar 2011
Posts: 38
Rep Power: 15
aleisia is on a distinguished road
Quote:
Originally Posted by a.lynchy View Post
Hi Kartn
The problem with the previous code that I posted was in getting the value for the variable “flow” from the DEFINE_EXECUTE_AT_END section and using it in the DEFINE_PROFILE. The way it was set as a global variable was okay but what was happening was it was been set to zero after the DEFINE_EXECTUE_AT_END loop so the DEFINE_PROFILE function was seeing a value of flow=0. Sorry if what I am saying is hard to follow, but I have attached the working code below and maybe from comparing the two you will be able to understand.
The only real different is in introducing the flow_tot variable as the global variable instead of using the flow variable.

#include"udf.h"
real flow_tot;
real p ;

DEFINE_EXECUTE_AT_END(funny)
{
Domain *d;

real flow;
cell_t c;
Thread *t;
face_t f;
d = Get_Domain(1);
t= Lookup_Thread(d, 12);

begin_f_loop(f,t)
{
flow+=F_FLUX(f,t);
}
end_f_loop(f,t)
p = C_P(c,t);
printf(
"static pressure = %g\n", p);
printf(
"MASS Flow Rate: %g\n",flow);
flow_tot =flow;
flow=0.;
}

DEFINE_PROFILE(pressure_out,t,i)
{
real set_point = 1;
real pressure;
face_t f;




printf(
"MASS Flow Rate: %g\n",flow_tot);
if (flow_tot < set_point)

pressure = p - 1;

elseif (flow_tot > set_point)

pressure = p + 1;

else
pressure = p;



begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = pressure;
}
end_f_loop(f,t)
printf(
"Adjusted pressure = %g\n", pressure);
}

Hope this helps!
I think about it again, and found this in your code:
begin_f_loop(f,t)
{
flow+=F_FLUX(f,t);
}
end_f_loop(f,t)

Here the F_FLUX(f,t) is a vector, I believe, so what if you want to get the mass flow rate, instead of the flux, can I write:
begin_f_loop(f,t)
{
flow+=F_YI(f,t,i)*F_FLUX(f,t)*F_AREA(A,f,t);
}
end_f_loop(f,t)


or

real A[ND_ND], flux(ND_ND)
begin_f_loop(f,t)
{
flux=
F_FLUX(f,t);
F_AREA(A,f,t);
mf=F_YI(f,t,i);
flow+=mf*NV_DOT(flux, A);
}
end_f_loop(f,t)


As I understand, F_YI(f,t,i), F_FLUX(f,t) and F_AREA(A,f,t) just get one patch of the surface 'f' corresponding to the thread 't', so the area 'A' is the area of that patch, that's why we need the begin_f_loop and end_f_loop, am I getting this right?

thanks!
aleisia is offline   Reply With Quote

Old   June 24, 2011, 16:30
Default
  #4
New Member
 
Join Date: Sep 2010
Posts: 3
Rep Power: 15
kartn is on a distinguished road
Quote:
Originally Posted by aleisia View Post
I think about it again, and found this in your code:
begin_f_loop(f,t)
{
flow+=F_FLUX(f,t);
}
end_f_loop(f,t)

Here the F_FLUX(f,t) is a vector, I believe, so what if you want to get the mass flow rate, instead of the flux, can I write:
begin_f_loop(f,t)
{
flow+=F_YI(f,t,i)*F_FLUX(f,t)*F_AREA(A,f,t);
}
end_f_loop(f,t)


or

real A[ND_ND], flux(ND_ND)
begin_f_loop(f,t)
{
flux=
F_FLUX(f,t);
F_AREA(A,f,t);
mf=F_YI(f,t,i);
flow+=mf*NV_DOT(flux, A);
}
end_f_loop(f,t)


As I understand, F_YI(f,t,i), F_FLUX(f,t) and F_AREA(A,f,t) just get one patch of the surface 'f' corresponding to the thread 't', so the area 'A' is the area of that patch, that's why we need the begin_f_loop and end_f_loop, am I getting this right?

thanks!
Hi Aleisia,

F_FLUX(f,t) by itself outputs the mass flow rate entering or leaving a face in a cell. It is a scalar quantity and it outputs the result of the dot product of the mass flux vector and area normal vector.
So all u have to do in order to calculate the mass flow rate of a particular species is find the product of total flux of the mass flux vector and the mass fraction.

begin_f_loop(f,t)
{
flow+=F_FLUX(f,t)*F_YI(f,t);
}
end_f_loop(f,t)
BlnPhoenix and shahjehan13 like this.
kartn is offline   Reply With Quote

Old   June 25, 2011, 01:04
Default
  #5
Member
 
Join Date: Mar 2011
Posts: 38
Rep Power: 15
aleisia is on a distinguished road
Thanks a million Kartn!

So, if I have some fluid entering into a surface, F_FLUX should be a negative scalar, right?

I remembered I've seen it somewhere, the result we see from the GUI values are actually the opposite of the F_FLUX , because they have different definitions of the 'normal' direction.
What I mean, from GUI, the value should be positive, because the fluid is entering into the surface, so it should be positive, but according to the definition of F_FLUX, it should be negative. Am I getting this right?

Thanks!

Quote:
Originally Posted by kartn View Post
Hi Aleisia,

F_FLUX(f,t) by itself outputs the mass flow rate entering or leaving a face in a cell. It is a scalar quantity and it outputs the result of the dot product of the mass flux vector and area normal vector.
So all u have to do in order to calculate the mass flow rate of a particular species is find the product of total flux of the mass flux vector and the mass fraction.

begin_f_loop(f,t)
{
flow+=F_FLUX(f,t)*F_YI(f,t);
}
end_f_loop(f,t)
aleisia is offline   Reply With Quote

Old   May 4, 2012, 06:58
Default
  #6
New Member
 
Luca Gorasso
Join Date: Oct 2011
Location: Harbin, China
Posts: 24
Rep Power: 14
elcino is on a distinguished road
Send a message via Skype™ to elcino
Good morning everybody,

I was reading your post and I think I've the same problem as all of you. I'm analyzing journal bearings. The problems seams easy but i can't have the convergence if the "pressure-inlet" vs "pressure-outlet" are imposed. If I try to impose "mass flow inlet" vs "pressure-outlet" i can reach a good convergence. The problem is: I don't know the mass flow!!!! My idea is: impose a mass flow, calculate the total pressure (known data) and then recompute the mass flow at any iteration.

I've to write an UDF like yours:

1. Calculate the total average total pressure on the inlet and with an algorithm calculate the next mass flow (this is easy like a bisection algorithm will work sure, remember i had an aimed total pressure).

2. Input the new mass flow.

So the first UDF must be an DEFINE_EXECUTE_AT_END, to calculate for example "mass_flow", and the next will be an DEFINE_PROFILE.

My question is: how to calculate the average total pressure on a face (of course Ptot=Pstat+0.5*rho*v^2) but i don't know how to implement it as an average on the boundary.

when u do this:

begin_f_loop(f,t)
{
flow+=F_FLUX(f,t);
}
end_f_loop(f,t)


means that fluent is going to give u "flow" as the summatory of all the face fluxes of the boundary with the same ID?

thanks for your help!
elcino is offline   Reply With Quote

Old   June 20, 2012, 12:53
Default
  #7
Senior Member
 
mahdi abdollahzadeh
Join Date: Mar 2011
Location: Covilha,Portugal
Posts: 153
Rep Power: 15
mm.abdollahzadeh is on a distinguished road
Quote:
Originally Posted by a.lynchy View Post
Hi Kartn
The problem with the previous code that I posted was in getting the value for the variable “flow” from the DEFINE_EXECUTE_AT_END section and using it in the DEFINE_PROFILE. The way it was set as a global variable was okay but what was happening was it was been set to zero after the DEFINE_EXECTUE_AT_END loop so the DEFINE_PROFILE function was seeing a value of flow=0. Sorry if what I am saying is hard to follow, but I have attached the working code below and maybe from comparing the two you will be able to understand.
The only real different is in introducing the flow_tot variable as the global variable instead of using the flow variable.

#include"udf.h"
real flow_tot;
real p ;

DEFINE_EXECUTE_AT_END(funny)
{
Domain *d;

real flow;
cell_t c;
Thread *t;
face_t f;
d = Get_Domain(1);
t= Lookup_Thread(d, 12);

begin_f_loop(f,t)
{
flow+=F_FLUX(f,t);
}
end_f_loop(f,t)
p = C_P(c,t);
printf(
"static pressure = %g\n", p);
printf(
"MASS Flow Rate: %g\n",flow);
flow_tot =flow;
flow=0.;
}

DEFINE_PROFILE(pressure_out,t,i)
{
real set_point = 1;
real pressure;
face_t f;




printf(
"MASS Flow Rate: %g\n",flow_tot);
if (flow_tot < set_point)

pressure = p - 1;

elseif (flow_tot > set_point)

pressure = p + 1;

else
pressure = p;



begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = pressure;
}
end_f_loop(f,t)
printf(
"Adjusted pressure = %g\n", pressure);
}

Hope this helps!
Dear Adrian

Thanks For sharing your work. Could you please help me.
I want to calaculate the mass flow rate on a surface diffrent that the outlet boundary and then i want to modify the pressure at outlet according to that mass flow.
I dont have that surface as a boundary seprately. I just creat that surface as an isosurface in Fluent and I was calculataing the mass flow in GUI.

I appriciate your help.

Best
Mehdi
mm.abdollahzadeh is offline   Reply With Quote

Old   September 26, 2017, 12:50
Default
  #8
Senior Member
 
Astio Lamar
Join Date: May 2012
Location: Pipe
Posts: 186
Rep Power: 14
asal is on a distinguished road
Quote:
Originally Posted by a.lynchy View Post
Hi Kartn
The problem with the previous code that I posted was in getting the value for the variable “flow” from the DEFINE_EXECUTE_AT_END section and using it in the DEFINE_PROFILE. The way it was set as a global variable was okay but what was happening was it was been set to zero after the DEFINE_EXECTUE_AT_END loop so the DEFINE_PROFILE function was seeing a value of flow=0. Sorry if what I am saying is hard to follow, but I have attached the working code below and maybe from comparing the two you will be able to understand.
The only real different is in introducing the flow_tot variable as the global variable instead of using the flow variable.

#include"udf.h"
real flow_tot;
real p ;

DEFINE_EXECUTE_AT_END(funny)
{
Domain *d;

real flow;
cell_t c;
Thread *t;
face_t f;
d = Get_Domain(1);
t= Lookup_Thread(d, 12);

begin_f_loop(f,t)
{
flow+=F_FLUX(f,t);
}
end_f_loop(f,t)
p = C_P(c,t);
printf(
"static pressure = %g\n", p);
printf(
"MASS Flow Rate: %g\n",flow);
flow_tot =flow;
flow=0.;
}

DEFINE_PROFILE(pressure_out,t,i)
{
real set_point = 1;
real pressure;
face_t f;




printf(
"MASS Flow Rate: %g\n",flow_tot);
if (flow_tot < set_point)

pressure = p - 1;

elseif (flow_tot > set_point)

pressure = p + 1;

else
pressure = p;



begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = pressure;
}
end_f_loop(f,t)
printf(
"Adjusted pressure = %g\n", pressure);
}

Hope this helps!
I tried to use this UDF initially and modify according to my case. Prior to any modification, I got the following error after the first iteration on "DEFINE_EXECUTE_AT_END".

Code:
==============================================================================

Node 0: Process 13808: Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 1: Process 17288: Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 3: Process 17844: Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 999999: Process 16332: Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 5: Process 12176: Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 6: Process 17444: Received signal SIGSEGV.

==============================================================================
MPI Application rank 0 exited before MPI_Finalize() with status 2
 The fl process could not be started.
How can I fix this error?!!
Thanks.
PS: I interpret the UDF.
asal is offline   Reply With Quote

Reply

Tags
lookup_thread, mass flow rate, udf


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
mass flow rate not conserved in turbomachine, interface defined wrong? wildli FLUENT 3 September 15, 2022 12:19
mass flow rate (CFX post) sanchezz CFX 2 January 14, 2010 06:54
Mass Flow Rate student87 CFX 4 January 2, 2010 04:45
mass flow rate entering and exiting a cell samir bensaid FLUENT 0 July 4, 2007 05:37
User defined function of mass flow rate Eric FLUENT 1 April 22, 2005 18:15


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