CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   how to set up and write a cosine UDF (https://www.cfd-online.com/Forums/fluent-udf/107169-how-set-up-write-cosine-udf.html)

chriskit September 19, 2012 10:16

how to set up and write a cosine UDF
 
Hello everybody,

i ve got a problem with my inlet boundary conditions. i want to implement a cosine (or sine) function because, i got a pulsative flow at the inlet. my flow changes every second from 0 to 20 m/s.
one possible function would be 10*cos(x*pi)+10 with 0<x<2.

Now, i just dont know how to setup this function in fluent and how and where to wirte it. I know that i have to define this function somewhere and upload it after in fluent. and how can i tell fluent that one period is like 4 seconds?

Would be really great if someone can help me with this.

regards, chris

NormalVector September 19, 2012 12:47

You should read the Fluent UDF manual here:
http://hpce.iitm.ac.in/website/Manua...f/main_pre.htm

Alternatively you can create a Profile file with discrete velocity vs. time data and use that. See here:
http://hpce.iitm.ac.in/website/Manua...ug/node301.htm

chriskit September 20, 2012 08:02

ok thanks i`ll try it!

ghost82 September 20, 2012 11:22

Quote:

Originally Posted by chriskit (Post 382563)
Hello everybody,

i ve got a problem with my inlet boundary conditions. i want to implement a cosine (or sine) function because, i got a pulsative flow at the inlet. my flow changes every second from 0 to 20 m/s.
one possible function would be 10*cos(x*pi)+10 with 0<x<2.

Now, i just dont know how to setup this function in fluent and how and where to wirte it. I know that i have to define this function somewhere and upload it after in fluent. and how can i tell fluent that one period is like 4 seconds?

Would be really great if someone can help me with this.

regards, chris

Hi,
I don't understand very well: your function should be time dependent but there isn't time in your function..what is x?time?
From what I understand I think you want to change velocity at inlet with a time dependent cos function.
If so, try this udf.

Code:

#include "udf.h"
#include "math.h"
#include "mem.h"

DEFINE_PROFILE(my_velocity, thread, position)
{
  face_t f;
  real t = CURRENT_TIME;

  begin_f_loop(f, thread)
    {
          F_PROFILE(f, thread, position) = 10.*cos(t*3.14159)+10.;
    }
  end_f_loop(f, thread)
}

Am I right?
If so copy this udf in a textedit file and save it as somename.c (not txt extension but c extension) and put it in the folder of your cas and dat files.
Open fluent and go to define->user-defined->functions->interpreted.
Choose the c file and interpret it.
Then in your velocity boundary condition choose your interpreted udf ("my_velocity").
Choose an appropriate time step for your unsteady simulation and stop it after some periods (you know 1 period is 2 seconds).

Also, I don't understand this:
..and how can i tell fluent that one period is like 4 seconds?

your period is 2 seconds not 4.
If I don't understand post a sketch of your domain and explain better.

Daniele

chriskit September 21, 2012 06:08

Hey Daniele,

thanks a lot! You understood it absolute right. And really thanks for the code, my knowledge at C and C++ isnīt that big...

So now, i made it like your proposal but the new problem is that "my_velocity" doesn`t appear at the boundary conditions. I think interpreting worked well but i can`t choose this condition.

Do you know what kind of problem could be the reason for that?

Thank you and regards,

chris

ghost82 September 21, 2012 06:28

Quote:

Originally Posted by chriskit (Post 382946)
Hey Daniele,

thanks a lot! You understood it absolute right. And really thanks for the code, my knowledge at C and C++ isnīt that big...

So now, i made it like your proposal but the new problem is that "my_velocity" doesn`t appear at the boundary conditions. I think interpreting worked well but i can`t choose this condition.

Do you know what kind of problem could be the reason for that?

Thank you and regards,

chris

Hi Chris,
after interpreting your udf, go to boundary condition panel, choose your inlet, then change from "constant" to udf my_velocity.

PS: if you start your simulation with your function velocity at time=0 s is 20 m/s; you should perform a steady state simulation first, with v=constant=20 m/s than switch to unsteady and apply your cosine udf.

Daniele

chriskit September 21, 2012 09:38

ok great, thank you, now it works!!!


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