
[Sponsors] 
UDF program for calculating the mass flow outlet with a pulsed output flow 

LinkBack  Thread Tools  Search this Thread  Display Modes 
July 26, 2019, 04:26 
UDF program for calculating the mass flow outlet with a pulsed output flow

#1 
New Member
Benito
Join Date: Jul 2019
Posts: 5
Rep Power: 6 
Hi everyone, I need some help with writing a UDF. I need write a code for simulating a car airbox for my final tesis, where you have an velocity inlet costant of 53m / s and 4 output tubes that have a mass flow outlet of 0.0045kg / s each. This outflows should have a pulsed output flow. Furthermore the exit from the pipes should take place in this order like a normal engine ignition configuration.(pipe 1;pipe 3;pipe 4;pipe 2).
Can you help me with this issue. Thank you 

July 29, 2019, 00:51 

#2 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,345
Rep Power: 33 
you should describe functionality of your UDF in more details.
you should put here your code, so other members could fix it if you wanna time dependent outflow massflow rate > you can use DEFINE_PROFILE macro you can find good example in Ansys Fluent Customization manual (use google) best regards 

July 30, 2019, 06:54 

#3 
New Member
Benito
Join Date: Jul 2019
Posts: 5
Rep Power: 6 
Thanks to your instructions, I found the udf code (2.3.20.10. Example 8  Target Mass Flow Rate UDF as a Function of Physical Flow Time) and I adapted it to my needs.
#include "udf.h" DEFINE_PROFILE(tm_pout2, t, nv) { face_t f ; real flow_time = RP_Get_Real("flowtime"); if (flow_time < 0.2) { printf("Time = %f sec. \n",flow_time); printf("Targeted massflow rate set at 0.0 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 0.0 ; } end_f_loop(f,t) } else { printf("Time = %f sec. \n",flow_time); printf("Targeted massflow rate set at 0.045 kg/s \n") ; begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 0.045 ; } end_f_loop(f,t) } } Only it always gives me a solution as 0. How can I change it? 18 1.6981e01 4.1807e03 2.9109e03 2.6440e03 0:00:30 2 Time = 0.000000 sec. Targeted massflow rate set at 0.0 kg/s Time = 0.000000 sec. Targeted massflow rate set at 0.0 kg/s Time = 0.000000 sec. Targeted massflow rate set at 0.0 kg/s Time = 0.000000 sec. Targeted massflow rate set at 0.0 kg/s 19 1.7504e01 4.3283e03 3.0188e03 2.6914e03 0:00:16 1 Time = 0.000000 sec. Targeted massflow rate set at 0.0 kg/s Time = 0.000000 sec. Targeted massflow rate set at 0.0 kg/s Time = 0.000000 sec. Targeted massflow rate set at 0.0 kg/s Time = 0.000000 sec. Targeted massflow rate set at 0.0 kg/s 20 1.8807e01 5.0708e03 3.5272e03 3.1685e03 0:00:00 0 

July 31, 2019, 01:05 

#4 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,345
Rep Power: 33 
Code:
#include "udf.h" DEFINE_PROFILE(tm_pout2, t, nv) { face_t f ; real flow_time; flow_time = RP_Get_Real("flowtime"); if (flow_time < 0.2) { printf("Time = %f sec. \n",flow_time); printf("Targeted massflow rate set at 0.0 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 0.0 ; } end_f_loop(f,t) } else { printf("Time = %f sec. \n",flow_time); printf("Targeted massflow rate set at 0.045 kg/s \n") ; begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 0.045 ; } end_f_loop(f,t) } } 

July 31, 2019, 13:30 

#5 
New Member
Benito
Join Date: Jul 2019
Posts: 5
Rep Power: 6 
Thank you very much AlexanderZ, it works perfectly.
But now I have another request, sorry if I always ask but it's the first time I use FLUENT. If instead of imposing a constant input speed, I set a pulsating speed written like this: #include "udf.h" DEFINE_PROFILE (my_velocity, thread, position) { face_t f; real t = CURRENT_TIME; begin_f_loop (f, thread) { F_PROFILE (f, thread, position) =  26.76 * cos (t * 3.14159) + 26.76 ; } end_f_loop (f, thread) } I always associate this code with that of the always pulsating air outlet mass. Can you do this? and above all the program how do you understand that the t of the two codes must be the same at the same time?For example if t = 2 should return 0 from both codes 

August 1, 2019, 01:51 

#6 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,345
Rep Power: 33 
I didn't understand, what you want
if you want to define 2 boundary conditions in your UDF you can use 2 DEFINE_PROFILE macros (same way as you did before): Code:
#include "udf.h" DEFINE_PROFILE(tm_pout2, t, nv) { ... } DEFINE_PROFILE (my_velocity, thread, position) { ... } t (which is time probably) is the same for the whole your simulation as it is controlled by solver, but you only check its value using macro Code:
flow_time = RP_Get_Real("flowtime"); Dont do this: Code:
real flow_time = CURRENT_TIME; Code:
real flow_time ; flow_time = CURRENT_TIME; or flow_time = RP_Get_Real("flowtime"); 

August 20, 2019, 07:48 

#7 
New Member
Benito
Join Date: Jul 2019
Posts: 5
Rep Power: 6 
Thanks AlexanderZ, you are of great help.
I tried to channel the air sequentially like this: tube1, tube3, tube4, tube2. I did it through this code: #include "udf.h" DEFINE_PROFILE(tm_pout, t, nv) { face_t f ; real flow_time; flow_time = RP_Get_Real("flowtime"); if (flow_time < 0.2) { printf("Time = %f sec. \n",flow_time); printf("Targeted massflow rate set at 0.0 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 0.0 ; } end_f_loop(f,t) } else { printf("Time = %f sec. \n",flow_time); printf("Targeted massflow rate set at 0.045 kg/s \n") ; begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 0.045 ; } end_f_loop(f,t) } } DEFINE_PROFILE(tm_pout3, t, nv) { face_t f ; real flow_time; flow_time = RP_Get_Real("flowtime"); if (flow_time < 0.3) { printf("Time = %f sec. \n",flow_time); printf("Targeted massflow rate set at 0.0 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 0.0 ; } end_f_loop(f,t) } else { printf("Time = %f sec. \n",flow_time); printf("Targeted massflow rate set at 0.045 kg/s \n") ; begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 0.045 ; } end_f_loop(f,t) } } DEFINE_PROFILE(tm_pout4, t, nv) { face_t f ; real flow_time; flow_time = RP_Get_Real("flowtime"); if (flow_time < 0.4) { printf("Time = %f sec. \n",flow_time); printf("Targeted massflow rate set at 0.0 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 0.0 ; } end_f_loop(f,t) } else { printf("Time = %f sec. \n",flow_time); printf("Targeted massflow rate set at 0.045 kg/s \n") ; begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 0.045 ; } end_f_loop(f,t) } } DEFINE_PROFILE(tm_pout2, t, nv) { face_t f ; real flow_time; flow_time = RP_Get_Real("flowtime"); if (flow_time < 0.5) { printf("Time = %f sec. \n",flow_time); printf("Targeted massflow rate set at 0.0 kg/s \n"); begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 0.0 ; } end_f_loop(f,t) } else { printf("Time = %f sec. \n",flow_time); printf("Targeted massflow rate set at 0.045 kg/s \n") ; begin_f_loop(f,t) { F_PROFILE(f,t,nv) = 0.045 ; } end_f_loop(f,t) } } DEFINE_PROFILE (my_velocity, t, position) { face_t f; real flow_time; flow_time = RP_Get_Real("flowtime"); begin_f_loop (f, t) { F_PROFILE (f, t, position) =  26.76 * cos (flow_time * 3.14159) + 26.76 ; } end_f_loop (f, t) } but now I would like to impose a new condition: the tube1 opens at 0.2s and closes at 0.3s; the tube3 opens at 0.3s and closes at 0.4s; the tube4 opens at 0.4s and closes at 0.5s; the tube2 opens at 0.5s and closes at 0.6s. When the tube2 closes, the tube1 must be opened again and then start again with the cycle, how can I do? 

August 21, 2019, 01:12 

#8 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,345
Rep Power: 33 
use sin with period 0.6s  0.2 s = 0.4 s
best regards 

August 21, 2019, 06:06 

#9 
New Member
Benito
Join Date: Jul 2019
Posts: 5
Rep Power: 6 
Excuse ignorance but where do I put this function?


August 22, 2019, 00:57 

#10 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,345
Rep Power: 33 
in my vision, you should put it in if statement:
Code:
if (flow_time*sin(your_function) > 0) 

Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Match Pressure Inlet/Outlet Boundary Condition Mass Flow Rate  MSchneid  Fluent UDF and Scheme Programming  3  February 23, 2019 07:00 
Mass flow rate at inlet and outlet are not equal  jiaen961997  FLUENT  1  January 9, 2019 04:18 
Please help (an UDF for regulating the mass flow rate)  swidi  Fluent UDF and Scheme Programming  2  July 30, 2015 13:32 
UDF for Mass Flow at the Outlet: ERROR ACCESS VIOLATION  Imech  Fluent UDF and Scheme Programming  1  May 23, 2014 13:37 
UDF in Fluent to Match Mass Flow at Pressure Outlet  Jonas Larsson  Main CFD Forum  1  April 29, 1999 11:44 