# UDF program for calculating the mass flow outlet with a pulsed output flow

 Register Blogs Members List Search Today's Posts Mark Forums Read

 July 26, 2019, 03: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: 7 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 28, 2019, 23:51 #2 Senior Member   Alexander Join Date: Apr 2013 Posts: 2,363 Rep Power: 34 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 mass-flow rate -> you can use DEFINE_PROFILE macro you can find good example in Ansys Fluent Customization manual (use google) best regards Benito89 likes this.

 July 30, 2019, 05:54 #3 New Member   Benito Join Date: Jul 2019 Posts: 5 Rep Power: 7 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("flow-time"); if (flow_time < 0.2) { printf("Time = %f sec. \n",flow_time); printf("Targeted mass-flow 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 mass-flow 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.6981e-01 4.1807e-03 2.9109e-03 2.6440e-03 0:00:30 2 Time = 0.000000 sec. Targeted mass-flow rate set at 0.0 kg/s Time = 0.000000 sec. Targeted mass-flow rate set at 0.0 kg/s Time = 0.000000 sec. Targeted mass-flow rate set at 0.0 kg/s Time = 0.000000 sec. Targeted mass-flow rate set at 0.0 kg/s 19 1.7504e-01 4.3283e-03 3.0188e-03 2.6914e-03 0:00:16 1 Time = 0.000000 sec. Targeted mass-flow rate set at 0.0 kg/s Time = 0.000000 sec. Targeted mass-flow rate set at 0.0 kg/s Time = 0.000000 sec. Targeted mass-flow rate set at 0.0 kg/s Time = 0.000000 sec. Targeted mass-flow rate set at 0.0 kg/s 20 1.8807e-01 5.0708e-03 3.5272e-03 3.1685e-03 0:00:00 0

 July 31, 2019, 00:05 #4 Senior Member   Alexander Join Date: Apr 2013 Posts: 2,363 Rep Power: 34 Code: ```#include "udf.h" DEFINE_PROFILE(tm_pout2, t, nv) { face_t f ; real flow_time; flow_time = RP_Get_Real("flow-time"); if (flow_time < 0.2) { printf("Time = %f sec. \n",flow_time); printf("Targeted mass-flow 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 mass-flow 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) } }``` best regards

 July 31, 2019, 12:30 #5 New Member   Benito Join Date: Jul 2019 Posts: 5 Rep Power: 7 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, 00:51 #6 Senior Member   Alexander Join Date: Apr 2013 Posts: 2,363 Rep Power: 34 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) { ... }``` your second UDF is correct also. 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("flow-time");` I recommend you to use this macro Dont do this: Code: `real flow_time = CURRENT_TIME;` but use Code: ```real flow_time ; flow_time = CURRENT_TIME; or flow_time = RP_Get_Real("flow-time");``` best regards Benito89 likes this.

 August 20, 2019, 06:48 #7 New Member   Benito Join Date: Jul 2019 Posts: 5 Rep Power: 7 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("flow-time"); if (flow_time < 0.2) { printf("Time = %f sec. \n",flow_time); printf("Targeted mass-flow 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 mass-flow 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("flow-time"); if (flow_time < 0.3) { printf("Time = %f sec. \n",flow_time); printf("Targeted mass-flow 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 mass-flow 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("flow-time"); if (flow_time < 0.4) { printf("Time = %f sec. \n",flow_time); printf("Targeted mass-flow 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 mass-flow 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("flow-time"); if (flow_time < 0.5) { printf("Time = %f sec. \n",flow_time); printf("Targeted mass-flow 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 mass-flow 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("flow-time"); 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, 00:12 #8 Senior Member   Alexander Join Date: Apr 2013 Posts: 2,363 Rep Power: 34 use sin with period 0.6s - 0.2 s = 0.4 s best regards Benito89 likes this.

 August 21, 2019, 05:06 #9 New Member   Benito Join Date: Jul 2019 Posts: 5 Rep Power: 7 Excuse ignorance but where do I put this function?

 August 21, 2019, 23:57 #10 Senior Member   Alexander Join Date: Apr 2013 Posts: 2,363 Rep Power: 34 in my vision, you should put it in if statement: Code: `if (flow_time*sin(your_function) > 0)` best regards Benito89 likes this.