CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   UDF for Velocity change at inlet (http://www.cfd-online.com/Forums/fluent/83106-udf-velocity-change-inlet.html)

 haihek December 14, 2010 17:23

UDF for Velocity change at inlet

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.

 ComputerGuy December 14, 2010 19:16

Alex,

 haihek December 14, 2010 20:55

Computerguy,

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

 ComputerGuy December 14, 2010 21:27

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) }```
• default velocity is the value that the code will use outside the ramp time
• start velocity is the value of the velocity at the beginning of the ramp (in your case, 0 m/s)
• end velocity is the value of the velocity at the beginning of the ramp (in your case, 1 m/s)
• ramp start and ramp end are the times, in seconds, you want to start and end the velocity ramp, respectively. This is easier to do (and slightly more robust) than selecting the number of time steps you'd like to subdivide the ramp into, as it gives you the option to take variable time steps.

Let me know if this is clear.

ComputerGuy

 haihek December 15, 2010 16:01

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

 ComputerGuy December 15, 2010 19:58

haihek,

Good questions.
1. It doesn't matter what name you use on a UDF, I just forgot to change the name
2. The code will not use the last value from the previous timestep. It will always default to "default_velocity_mag"

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) }```
ComputerGuy

 All times are GMT -4. The time now is 19:44.