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

UDF for Velocity change at inlet

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

Reply
 
LinkBack Thread Tools 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: 7
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.
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: 180
Rep Power: 7
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: 7
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: 180
Rep Power: 7
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
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: 7
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: 180
Rep Power: 7
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
ComputerGuy is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
change particle properties using udf? ljp FLUENT 0 April 1, 2010 15:12
UDF for Inlet velocity Mijin Kim FLUENT 0 September 28, 2009 04:50
udf for varying inlet temperature aravind FLUENT 0 October 27, 2008 11:08
UDF Cmu change selçuk ataş FLUENT 1 September 29, 2008 14:16
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 13:15.