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

Time dependent sinus velocity inlet UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By obscureed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 6, 2018, 14:07
Question Time dependent sinus velocity inlet UDF
  #1
New Member
 
Join Date: Dec 2018
Posts: 2
Rep Power: 0
LinW is on a distinguished road
Hey,

I've spent a few hours trying to set up a UDF for a 2D velocity inlet.
Nothing special but as im relatively new to fluent and completely new to C im facing some errors.

I wan't to do a transient simulation of water flow where the u (x-velocity) inlet profile is a time and space dependent sinus.

The formula it should solve looks like this: u(y,t)=2*sin(5*t+0.1*y). Im not sure whether the following code is suitable to solve this equation for every node (centroid?) and adds a node-specific phase angle phi(y) where y is the number of the node. (Position in the Array)
I shloud propably mention, that the specific u-profile is supposed to only be "active" in a specified time.

Starting with zero C knowledge a few hours ago, but with the help of this forum and the manual, i've put together the following code.

I hope there arent too many mistakes left. I tried to let fluent interpret the UDF but it keeps failing at line 25 saying: parse error.

The encoding can't be the cause as i chose ANSI.

P.S.: Is there a way to read out the amount of entrys in the x[ND_ND] array?

Thanks a lot already.

My UDF:

#include "udf.h"
#define PI 3.141592654
#define N 600 //Amount of nodes
#define Y_max 0.3 //Max. amplitude
#define U_inf 1.2 //Base velocity
#define W 0.502654825 //Angular velocity

DEFINE_PROFILE(inlet_u_velocity,thread,position)
{
float x[ND_ND];
float y; //?

face_t f;

double t = CURRENT_TIME; //Time

begin_f_loop(f,thread) //here the "parse-error" occurs
{

F_CENTROID(x, f, thread);

y=x[1]; //gives y-coordinate

if(t >= 0 && t <= 1) //Base velocity at beginning
F_PROFILE(f,thread,position) = 1,2);

if(t > 1 && t <= 13.5) //Varying velocity
F_PROFILE(f,thread,position) = Y_max*sin(W*t+(2*PI*y/N)); //For every timestep this equation has to be solved for every centroid y

else if(t > 13.5) //Base velocity for the rest of the time
F_PROFILE(f,thread,position) = 1,2;

}
end_f_loop(f,thread)
}
LinW is offline   Reply With Quote

Old   December 6, 2018, 20:34
Default
  #2
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi LinW

Are you sure you're counting lines correctly? Because one line that looks bad to me is
F_PROFILE(f,thread,position) = 1,2);
which could easily be line 25. Lines are counted from the top of the text file. Line 31 is also bad. You cannot supply a vector here -- you can only supply one component.

Your "if" statements hang together fairly well, but the neatest structure (without repeating values, for example) is
Code:
if(t < 1.0) {
   //...
} else if (t < 13.5) {
   //...
} else {
   // ...
}
I would always recommend compiling UDFs rather than interpreting. M_PI is built-in and needs no definition; if you run in double precision, it will be more accurate than your value (not that this matters much).

Good luck!
Ed
LinW likes this.
obscureed is offline   Reply With Quote

Old   December 7, 2018, 12:22
Default
  #3
New Member
 
Join Date: Dec 2018
Posts: 2
Rep Power: 0
LinW is on a distinguished road
Thanks a lot!

You're right... i added the comment in the wrong line.

The Solution for the Problem was the brace in line 25 and the commas in Line 25 and 31. Additionally i changed the y in Line 25 against x[1] and deleted Line 11.

Now it seems to work.
LinW 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
bash script for pseudo-parallel usage of reconstructPar kwardle OpenFOAM Post-Processing 42 May 8, 2024 00:17
AMI speed performance danny123 OpenFOAM 21 October 24, 2020 05:13
UDF problem- time dependent temperature at inlet kaeran FLUENT 1 June 16, 2015 22:48
mixerVesselAMI2D's mass is not balancing sharonyue OpenFOAM Running, Solving & CFD 6 June 10, 2013 10:34
can i set the velocity and pressure at the inlet at the same time by UDF minyang.cau FLUENT 0 July 15, 2009 00:14


All times are GMT -4. The time now is 03:11.