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   August 14, 2013, 11:42
Default UDF for keep water height constant at inlet for a VOF model
  #21
Senior Member
 
Tanjina Afrin
Join Date: May 2013
Location: South Carolina
Posts: 169
Rep Power: 12
Tanjina is on a distinguished road
Hi, does anybody have UDF for keeping the water height constant at inlet for VOF ( 2 phase) model? Or can anyone can give an idea from where I can learn how to write UDF ?


I badly need of it. It will be very great if anyone can help me . Thanks a ton in advance.
Tanjina is offline   Reply With Quote

Old   February 15, 2014, 02:18
Default
  #22
New Member
 
Dustin
Join Date: Sep 2011
Location: Earth
Posts: 23
Rep Power: 14
DungPham is on a distinguished road
Quote:
Originally Posted by Tanjina View Post
Hi, does anybody have UDF for keeping the water height constant at inlet for VOF ( 2 phase) model? Or can anyone can give an idea from where I can learn how to write UDF ?


I badly need of it. It will be very great if anyone can help me . Thanks a ton in advance.
If you show a specific picture, Maybe I can help you
DungPham is offline   Reply With Quote

Old   September 26, 2017, 12:50
Default
  #23
Senior Member
 
Astio Lamar
Join Date: May 2012
Location: Pipe
Posts: 186
Rep Power: 13
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

Old   January 6, 2018, 13:50
Default
  #24
New Member
 
wasim
Join Date: Aug 2015
Posts: 9
Rep Power: 10
wasim_03 is on a distinguished road
Hello everyone i am using the similar UDF to alter the inlet boundary condition of my simulation. Basically i am also calculating the mass flow rate at the outlet of my valve and using this flow rate to calculate the pressure drop in feed line. Can someone help to find out what is problem wit this UDF..


Following UDF i am using to modify the inlet pressure......
#include "udf.h"
FILE *fp;
real flow_tot;

DEFINE_EXECUTE_AT_END(pressure)
{
Domain *d;
float 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)

flow_tot =flow;
flow=0.;
}
DEFINE_PROFILE(inlet_pressure, thread, position)
{
face_t f;
float P_i=903063;/* 199625Pa steady state pressure drop in feed circuit*/
real t= CURRENT_TIME;/* steady state inlet pressure 703438Pa*/
/*float flow_t=0;*/
float Del_P=0;
fp = fopen("output.txt","a");
fprintf(fp,"MASS Flow Rate: %f kg/s \n",flow_tot);
fclose(fp);
Del_P=(0.79215*flow_tot*flow_tot);
begin_f_loop(f, thread)
{

F_PROFILE(f, thread, position)=P_i-Del_P;
}
end_f_loop(f, thread)
}
wasim_03 is offline   Reply With Quote

Old   January 6, 2018, 13:53
Default
  #25
New Member
 
wasim
Join Date: Aug 2015
Posts: 9
Rep Power: 10
wasim_03 is on a distinguished road
can someone tells why i am getting Pi=9 bar at t=0 when mass flow is max. this should be 7.0 bar (Pi-Delta_p) but at t=0 i am getting initial pressure as 9.0 bar........where is the problem????can anyone tell....

Delta_P in steady state is given by Del_P=(0.79215*flow_tot*flow_tot); hence in steady state flow rate is maximum hence Pi should be minimum but surface monitor will start reading from 9.0 bar
wasim_03 is offline   Reply With Quote

Old   January 8, 2018, 12:13
Default UDF for mass flow rate at a pressure outlet
  #26
New Member
 
wasim
Join Date: Aug 2015
Posts: 9
Rep Power: 10
wasim_03 is on a distinguished road
Can someone find where is the mistake in following udf. It is always printing zero flow rate at all time steps while mass flow rate from surface monitor is coming total different....???


#include "udf.h"
FILE *fp;
real flow_tot=0.;
DEFINE_EXECUTE_AT_END(fun)
{
Domain *d;
real flow=0.;
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)
printf("MASS Flow Rate is: %g kg/s \n",flow_tot);
flow_tot =flow;
flow=0.;
}
wasim_03 is offline   Reply With Quote

Old   January 11, 2018, 09:14
Default
  #27
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 11
obscureed is on a distinguished road
Hi Wasim_03,

Your latest question is easy: you are printing the value of "flow_tot" *before* you copy the value of "flow" into it -- it should be after.

I haven't looked in detail at your previous questions. I do know that commands involving writing to file (fopen(fp...) fprintf(fp...)) are dangerous in parallel. Much better to print to the Fluent window using Message(...), which has a similar syntax to printf(...).

You are presumably trying to print out the value of "flow_tot" because you are not sure whether the value calculated by one UDF will survive when the next UDF is called. This is a valid concern -- you probably want to declare "static real flow_tot=0.;".

I worry whether your intended linkage between flowrate and pressure will be stable -- you might want to apply some home-made under-relaxation. (If you do this, you should be aware that DEFINE_PROFILE is sometimes called many times per iteration, for reasons that are not clear to me.)

The other stability issue is that DEFINE_PROFILE will be called before DEFINE_EXECUTE_AT_END, so the first iteration might go mad.
obscureed is offline   Reply With Quote

Old   January 16, 2018, 08:58
Default Udf
  #28
New Member
 
wasim
Join Date: Aug 2015
Posts: 9
Rep Power: 10
wasim_03 is on a distinguished road
Hi OBSCUREED....Thanks for your reply...

i am able to compiled and run this UDF, your concerned regarding initial time step i have well taken care when Define_profile is called and Execute_at_end is still on hold and to be called subsequently, at this time i have implemented if else logic to define the initial value flow rate to avoid the function go made and both function are working perfectly.......


Thanks and regards
Wasim
wasim_03 is offline   Reply With Quote

Old   August 9, 2018, 10:04
Default
  #29
New Member
 
沈建琦
Join Date: May 2017
Posts: 1
Rep Power: 0
Jianqi Shen is on a distinguished road
Quote:
Originally Posted by Kanarya View Post
Hi ALL,

I want to calculate solid phase mass flow rate at outlet and I wrote following code to it but it only read primary phase even though I pointed secondary phase. is there any one to help me why?
thanks a lot!!
#include "udf.h"
DEFINE_EXECUTE_AT_END(measure_mass_flow)
{
real mass_flow;
real abs_v;
Domain *d=Get_Domain(2);
face_t f;
Thread *mixture_thread = Lookup_Thread(d,2);
Thread **pt = THREAD_SUB_THREADS(mixture_thread);
Thread *tp = pt[0];
Thread *ts = pt[1];

mass_flow=0.;
mp_thread_loop_f(tp,d,pt)
{
if( THREAD_ID(tp) == 4 )

{
begin_f_loop(f,tp)
{

mass_flow+=F_FLUX(f,tp);

}
end_f_loop(f,tp)
}



}
Message("mass_flow:%g/n",mass_flow);
}
thanks again..
Hi, Kanarya,
i'm trying to build a circulating fluidized bed, and encourtered a problems like yours. can you plz give some suggestions?
thanks a million in advance
Jianqi Shen is offline   Reply With Quote

Old   October 4, 2018, 13:56
Default
  #30
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 10
Oula is on a distinguished road
Quote:
Originally Posted by a.lynchy View Post
Hi everyone,
I am trying to measure the mass flow rate through a pressure outlet using a UDF. I realise there are easier way to get the mass flow rate at the outlet, rather than using the UDF but this is to be incorperated into a larger UDF later (hopefully ). I have attached the code below that i have writen. The UDF interpetes okay and runs, however the problem is this code is giving me the mass flow rate throughout the whole volume and not at the pressure outlet ID 12 as required. I believe the problem is to do with the line: Lookup_Thread(d, 12);

#include "udf.h"
DEFINE_EXECUTE_AT_END(measure_mass_flow)
{
Domain *d;
real flow=0.;
face_t f;
Thread *t;
t= Lookup_Thread(d, 12);
d = Get_Domain(1);

thread_loop_f(t,d)
{
begin_f_loop(f,t)
{
flow+=F_FLUX(f,t);
}
end_f_loop(f,t)
}
printf("MASS Flow Rate: %g\n",flow);
flow=0.;
}

Please can anyone point me in the right direction?
Hi
Is the mass flow rate that you tried to measure is an output of the simulation?
Oula is offline   Reply With Quote

Old   October 4, 2018, 14:01
Default
  #31
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 10
Oula is on a distinguished road
Quote:
Originally Posted by a.lynchy View Post
Hi everyone,
I am trying to measure the mass flow rate through a pressure outlet using a UDF. I realise there are easier way to get the mass flow rate at the outlet, rather than using the UDF but this is to be incorperated into a larger UDF later (hopefully ). I have attached the code below that i have writen. The UDF interpetes okay and runs, however the problem is this code is giving me the mass flow rate throughout the whole volume and not at the pressure outlet ID 12 as required. I believe the problem is to do with the line: Lookup_Thread(d, 12);

#include "udf.h"
DEFINE_EXECUTE_AT_END(measure_mass_flow)
{
Domain *d;
real flow=0.;
face_t f;
Thread *t;
t= Lookup_Thread(d, 12);
d = Get_Domain(1);

thread_loop_f(t,d)
{
begin_f_loop(f,t)
{
flow+=F_FLUX(f,t);
}
end_f_loop(f,t)
}
printf("MASS Flow Rate: %g\n",flow);
flow=0.;
}

Please can anyone point me in the right direction?
Hi a.lynchy
Is the mass flow rate that you tried to measure is an output of the simulation?
Oula is offline   Reply With Quote

Old   October 4, 2018, 14:10
Default
  #32
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 11
obscureed is on a distinguished road
Hi Oula,

You seem to be replying to the original post -- this is confusing, because that post was answered completely by coglione in 2010. If you have your own question, it is probably better to start a new thread. (The content of a.lynchy's question was good, by the way, and worth emulating -- it included descriptions of the goal, the current progress, the problem and a possible route towards a solution.)

Good luck!
Ed
Oula likes this.
obscureed 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 12:20.