|
[Sponsors] |
December 14, 2010, 17:23 |
UDF for Velocity change at inlet
|
#1 |
New Member
Alex Hai
Join Date: Mar 2010
Posts: 27
Rep Power: 16 |
Hello Everyone,
I am trying to write a UDF for unsteady flow, in which the velocity at the intlet of 2d cylinder is increased by time (or by time step). I am using a VOF model, and it is pressure based. If it is easy, can anyone write me the code, if not, then point me to the right place. I am currently reading the UDF manual, so i know how to compile the c file and load it. Thanks Alex. |
|
December 14, 2010, 19:16 |
|
#2 |
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16 |
||
December 14, 2010, 20:55 |
|
#3 |
New Member
Alex Hai
Join Date: Mar 2010
Posts: 27
Rep Power: 16 |
Computerguy,
Thank you for your reply, that was helpful to read.. but that code is made for velocity change at a defined time, how can have that code to change the velocity at everytime step between 0 m/s till 1m/s, within lets say 30000 time steps. And make it only for the inlet boundary. Many thanks, Alex |
|
December 14, 2010, 21:27 |
|
#4 |
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16 |
Alex,
Are you asking how to perform a ramp of the velocity between 0 and 1 m/s over some defined period of time which takes 30000 time steps? If so, it's simply linear interpolation. I haven't checked the following code, but it should be clear enough to fix if it's broken: Code:
#include "udf.h" DEFINE_PROFILE(pressure_magnitude, t, i) { real default_velocity_mag,velocity_mag; real start_velocity,end_velocity; real ramp_start,ramp_end; real line_slope, line_intercept; face_t f; default_velocity_mag=0.0; start_velocity=0.0; end_velocity=1.0; ramp_start=0.0; ramp_end=3.0; velocity_mag=default_velocity_mag; the_current_time = CURRENT_TIME; line_slope=(end_velocity-start_velocity)/(ramp_end-ramp_start); line_intercept=start_velocity-line_slope*ramp_start; if ((the_current_time>=ramp_start) && (the_current_time<=ramp_end)) { velocity_mag=line_slope*the_current_time+line_intercept; } begin_f_loop(f,t) { F_PROFILE(f,t,i) = velocity_mag; } end_f_loop(f,t) }
Let me know if this is clear. ComputerGuy |
|
December 15, 2010, 16:01 |
|
#5 |
New Member
Alex Hai
Join Date: Mar 2010
Posts: 27
Rep Power: 16 |
Dear Computerguy,
Thank you so much. The code is very clear. However i have few questions, they may sound stupid but still i thought i should ask. for the DEFINE_PROFILE(pressure_magnitude, t, i) .. shouldn't be DEFINE_PROFILE(velocity_magnitude, t, i)? or it really doesn't make a difference? My other question is: after lets say 3 seconds of flow time, where the velocity becomes 1 m/s, will the code maintain that velocity at a later time (i.e t>3seconds)? Thanks again CG .. i will do the compiling using FLUENT today.. and i will then run it in the simulation.. i will let you know how it goes. Regards, Alex |
|
December 15, 2010, 19:58 |
|
#6 |
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16 |
haihek,
Good questions.
The updated code you're looking for is below: Code:
#include "udf.h" DEFINE_PROFILE(velocity_magnitude, t, i) { real default_early_velocity_mag,default_late_velocity_mag,velocity_mag; real start_velocity,end_velocity; real ramp_start,ramp_end; real line_slope, line_intercept; face_t f; default_early_velocity_mag=0.0; default_late_velocity_mag=3.0; start_velocity=0.0; end_velocity=1.0; ramp_start=0.0; ramp_end=3.0; velocity_mag=default_early_velocity_mag; the_current_time = CURRENT_TIME; line_slope=(end_velocity-start_velocity)/(ramp_end-ramp_start); line_intercept=start_velocity-line_slope*ramp_start; if ((the_current_time>=ramp_start) && (the_current_time<=ramp_end)) { velocity_mag=line_slope*the_current_time+line_intercept; } if ((the_current_time>ramp_end)) { velocity_mag=default_late_velocity_mag; } begin_f_loop(f,t) { F_PROFILE(f,t,i) = velocity_mag; } end_f_loop(f,t) } |
|
January 16, 2018, 23:25 |
|
#7 |
New Member
CFDGUY
Join Date: Jan 2018
Posts: 1
Rep Power: 0 |
Dear ComputerGuy,
I have a problem with the code. I have defined a negative velocity outlet (0.5 m/s) on a curved pipe and defined the flow inlet (let say 7 L/m) for the inlet. in my problem velocity will change slightly and decreases in 2 seconds, starts from 0s and begin to peak to the highest velocity then drops to 0m/s in the 2s. imagine it is a vacuum and works for 2 sec and stops. Should I use the exact same code for this problem if not can you please advise the proper code? I really appreciate that! cheers, Alex #include "udf.h" DEFINE_PROFILE(pressure_magnitude, t, i) { real default_velocity_mag,velocity_mag; real start_velocity,end_velocity; real ramp_start,ramp_end; real line_slope, line_intercept; face_t f; default_velocity_mag=0.55; start_velocity=0.0; end_velocity=0.0; ramp_start=0.0; ramp_end=3.0; velocity_mag=default_velocity_mag; the_current_time = CURRENT_TIME; line_slope=(end_velocity-start_velocity)/(ramp_end-ramp_start); line_intercept=start_velocity-line_slope*ramp_start; if ((the_current_time>=ramp_start) && (the_current_time<=ramp_end)) { velocity_mag=line_slope*the_current_time+line_inte rcept; } begin_f_loop(f,t) { F_PROFILE(f,t,i) = velocity_mag; } end_f_loop(f,t) } |
|
August 2, 2019, 08:45 |
My own ramped function
|
#8 |
New Member
Tom
Join Date: Jan 2019
Posts: 5
Rep Power: 7 |
Thanks for the code ComputerGuy,
I have used it to setup my own ramp code. It is quite complicated and I thought that for anyone else wanting to use multiple ramps i have posted it here and it may assist. If anyone could suggest a method of simplifying the code further that would be helpful. It involves: 1st, a ramp from v=0 to v=-0.1 m/s, for 0.005 s. 2nd, to maintain at -0.1 m/s, for 0.041 s 3rd, to ramp from v=-0.1 m/s to 0 m/s, in 0.005 s, 4th, to ramp from v=0 m/s to 0.06 m/s, in 0.002 s. 5th, to maintain at 0.06 m/s for 0.001 s, 6th, to ramp from v=0.06 m/s to 0 m/s, in 0.002 s. 7th, the code repeats itself looping back to the first stage. #include "udf.h" DEFINE_PROFILE(inlet_y_velocity, t, position) { real velocity_mag; real start_velocity1,end_velocity1; real start_velocity2, end_velocity2; real start_velocity3, end_velocity3; real start_velocity4, end_velocity4; real ramp_start1,ramp_end1; real ramp_start2, ramp_end2; real ramp_start3, ramp_end3; real ramp_start4, ramp_end4; real line_slope1, line_intercept1; real line_slope2, line_intercept2; real line_slope3, line_intercept3; real line_slope4, line_intercept4; real cycle_period = 0.056; real flow_time = RP_Get_Real("flow-time"); real cycle_number = flow_time / cycle_period; real time_in_cycle = cycle_period * (cycle_number - floor(cycle_number)); face_t f; start_velocity1=0.0; end_velocity1=-0.1; start_velocity2 = -0.1; end_velocity2 = 0; start_velocity3 = 0; end_velocity3 =0.06; start_velocity4 =0.06; end_velocity4 =0.0; ramp_start1=0.0; ramp_end1=0.005; ramp_start2=0.046; ramp_end2=0.051; ramp_start3=0.051; ramp_end3=0.053; ramp_start4=0.054; ramp_end4=0.056; line_slope1 = (end_velocity1 - start_velocity1) / (ramp_end1 - ramp_start1); line_slope2 = (end_velocity2 - start_velocity2) / (ramp_end2 - ramp_start2); line_slope3 = (end_velocity3 - start_velocity3) / (ramp_end3 - ramp_start3); line_slope4 = (end_velocity4 - start_velocity4) / (ramp_end4 - ramp_start4); line_intercept1 = start_velocity1 - line_slope1 * ramp_start1; line_intercept2 = start_velocity2 - line_slope2 * ramp_start2; line_intercept3 = start_velocity3 - line_slope3 * ramp_start3; line_intercept4 = start_velocity4 - line_slope4 * ramp_start4; if ((time_in_cycle >=ramp_start1) && (time_in_cycle <=ramp_end1)) { velocity_mag=line_slope1* time_in_cycle +line_intercept1; } else if ((time_in_cycle >ramp_end1) && (time_in_cycle <=ramp_start2)) { velocity_mag=-0.1; } else if ((time_in_cycle >= ramp_start2) && (time_in_cycle <= ramp_end2)) { velocity_mag=line_slope2* time_in_cycle + line_intercept2; } else if ((time_in_cycle >= ramp_start3) && (time_in_cycle <= ramp_end3)) { velocity_mag = line_slope3 * time_in_cycle + line_intercept3; } else if ((time_in_cycle >ramp_end3) && (time_in_cycle < ramp_start4)) { velocity_mag = 0.06; } else if ((time_in_cycle >= ramp_start4) && (time_in_cycle <= ramp_end4)) { velocity_mag = line_slope4 * time_in_cycle + line_intercept4; } begin_f_loop (f,t) { F_PROFILE(f,t,position) = velocity_mag; } end_f_loop(f,t) } |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF Cmu change | selçuk ataş | FLUENT | 2 | July 19, 2017 13:24 |
change particle properties using udf? | ljp | FLUENT | 0 | April 1, 2010 16:12 |
UDF for Inlet velocity | Mijin Kim | FLUENT | 0 | September 28, 2009 05:50 |
udf for varying inlet temperature | aravind | FLUENT | 0 | October 27, 2008 11:08 |
About UDF of Inlet and Periodic B.C. | JI Lucheng | FLUENT | 2 | December 28, 2001 20:18 |