CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

UDF for Velocity change at inlet

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By haihek
  • 1 Post By ComputerGuy
  • 2 Post By ComputerGuy

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 14, 2010, 17:23
Default UDF for Velocity change at inlet
  #1
New Member
 
Alex Hai
Join Date: Mar 2010
Posts: 27
Rep Power: 16
haihek is on a distinguished road
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.
Chong070940103 likes this.
haihek is offline   Reply With Quote

Old   December 14, 2010, 19:16
Default
  #2
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
Alex,

Please look here: http://www.cfd-online.com/Forums/flu...tml#post287097
ComputerGuy is offline   Reply With Quote

Old   December 14, 2010, 20:55
Default
  #3
New Member
 
Alex Hai
Join Date: Mar 2010
Posts: 27
Rep Power: 16
haihek is on a distinguished road
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
haihek is offline   Reply With Quote

Old   December 14, 2010, 21:27
Default
  #4
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
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
Chong070940103 likes this.
ComputerGuy is offline   Reply With Quote

Old   December 15, 2010, 16:01
Default
  #5
New Member
 
Alex Hai
Join Date: Mar 2010
Posts: 27
Rep Power: 16
haihek is on a distinguished road
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
haihek is offline   Reply With Quote

Old   December 15, 2010, 19:58
Default
  #6
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
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
Chong070940103 and Bisht like this.
ComputerGuy is offline   Reply With Quote

Old   January 16, 2018, 23:25
Default
  #7
New Member
 
CFDGUY
Join Date: Jan 2018
Posts: 1
Rep Power: 0
AstralD is on a distinguished road
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)
}
AstralD is offline   Reply With Quote

Old   August 2, 2019, 08:45
Default My own ramped function
  #8
New Member
 
Tom
Join Date: Jan 2019
Posts: 5
Rep Power: 7
Dr.TDAJones is on a distinguished road
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)
}
Dr.TDAJones is offline   Reply With Quote

Reply


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
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


All times are GMT -4. The time now is 12:16.