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/)
-   -   UDF for unsteady velocity inlet (https://www.cfd-online.com/Forums/fluent-udf/151460-udf-unsteady-velocity-inlet.html)

chem engineer April 11, 2015 03:16

UDF for unsteady velocity inlet
 
Hello everyone,
I'm new and amateur in the world of CFD and fluent and I should use a udf for a velocity inlet in a cylindrical pipe.the velocity inlet follow a step function as is described:
for (t=time) t<10 v=6.5*(1-r/3.5)^(1/7)
t>10 v=0
I don't know how to write a step function.

does anyone can help me?
Thank you in advance

`e` April 11, 2015 03:54

Here's a start with the structure of the code, add in your velocity profile equation and you're set.

Code:

#include "udf.h"

DEFINE_PROFILE(unsteady_velocity_profile, t, i)
{
    real current_time;
    face_t f;
    current_time = CURRENT_TIME;

    begin_f_loop(f, t)
    {
        if (current_time < 10.)
        {
            // first period of time
        }
        else
        {
            // second period of time
        }
    }
    end_f_loop(f, t)
}


chem engineer April 12, 2015 04:17

1 Attachment(s)
Quote:

Originally Posted by `e` (Post 541125)
Here's a start with the structure of the code, add in your velocity profile equation and you're set.

Code:

#include "udf.h"

DEFINE_PROFILE(unsteady_velocity_profile, t, i)
{
    real current_time;
    face_t f;
    current_time = CURRENT_TIME;

    begin_f_loop(f, t)
    {
        if (current_time < 10.)
        {
            // first period of time
        }
        else
        {
            // second period of time
        }
    }
    end_f_loop(f, t)
}


thank you so much for your answer.
should I use this macro in a main steady state program? and do I need to use two loops for time and location? is the macro i have written and attached here correct?

chem engineer April 12, 2015 04:20

thank you so much for your answer.
should I use this code in a main steady state code? and do I need to use two loops for time and location? is the code i have written correct?


#include "udf.h"

DEFINE_PROFILE(unsteady_velocity_profile, t, i)
{
real current_time;
real x[ND_ND];
real y,u;
face_t f;
current_time = CURRENT_TIME;
begin_f_loop(f, t)
{
begin_f_loop(f, thread)
{
F_CENTROID(x,f,thread);
y = x[1];
if (current_time < 10.)
{
u=6.5*(1-y/3.5)^(1/7);
}
else
{
u=0;
}
}
end_f_loop(f, thread)
}
end_f_loop(f, t)
}

`e` April 12, 2015 04:53

Don't use two for loops. Set your boundary value with F_PROFILE(f,t,i); setting u=.. has nothing to do with the boundary condition value. Have a read of the UDF Manual for details.

chem engineer April 12, 2015 06:28

Quote:

Originally Posted by `e` (Post 541226)
Don't use two for loops. Set your boundary value with F_PROFILE(f,t,i); setting u=.. has nothing to do with the boundary condition value. Have a read of the UDF Manual for details.

according to what I read in UDF manuals, because this pipe is 2D I should define real x[ND_ND] that stand for a 2D array: x[1]=x & x[2]=y. x is the horizontal direction of flow and y is the vertical. I understood my mistake about defining "u" and I used F_PROFILE. so is this new code correct. if it is not would you please write the correct form?

DEFINE_PROFILE(unsteady_velocity_profile, t, i)
{
real current_time;
real x[ND_ND];
real y;
face_t f;
current_time = CURRENT_TIME;
begin_f_loop(f, t)
{
F_CENTROID(x,f,t);
y = x[1];
if (current_time < 10.)
{
F_PROFILE(f,t,i)=6.5*(1-y/3.5)^(1/7);
}
else
{
F_PROFILE(f,t,i)=0;
}
}
end_f_loop(f, t)
}

`e` April 12, 2015 06:34

This code is looking good, have you tried compiling and running this boundary condition profile?

chem engineer April 12, 2015 07:25

Quote:

Originally Posted by `e` (Post 541239)
This code is looking good, have you tried compiling and running this boundary condition profile?

I tried to compile it but I faced this error:

1 file(s) copied.
The system cannot find the file specified.
(system "copy C:\Fluent.Inc\fluent6.3.26\src\makefile_nt.udf libudf\ntx86\2ddp\makefile")
1 file(s) copied.
(chdir "libudf")()
(chdir "ntx86\2ddp")()
'nmake' is not recognized as an internal or external command,
operable program or batch file.
'nmake' is not recognized as an internal or external command,
operable program or batch file.

Done.
"C:/Users/LIDA/Desktop"

Opening library "libudf"...
Error: open_udf_library: The system cannot find the file specified.

Error Object: ()

as far as I searched and found, I should use Microsoft visual Studio program to compile it.but I haven't install it yet.

`e` April 12, 2015 08:09

Yea, you require a compiler such as Microsoft Visual Studio contains for compiling UDFs. Otherwise try interpreting this UDF (it may not require compiling).

chem engineer April 12, 2015 08:55

Quote:

Originally Posted by `e` (Post 541259)
Yea, you require a compiler such as Microsoft Visual Studio contains for compiling UDFs. Otherwise try interpreting this UDF (it may not require compiling).

I faced this error while interpreting it:

cpp -I"C:\Fluent.Inc\fluent6.3.26/src" -I"C:\Fluent.Inc\fluent6.3.26/cortex/src" -I"C:\Fluent.Inc\fluent6.3.26/client/src" -I"C:\Fluent.Inc\fluent6.3.26/multiport/src" -I. -DUDFCONFIG_H="<udfconfig.h>" "C:\Users\LIDA\Desktop\inlet.c"
Error: C:\Users\LIDA\Desktop\inlet.c: line 12: thread: undeclared variable

I don't know what does it mean and also if it can be solved or not.

`e` April 12, 2015 19:25

Quote:

Originally Posted by chem engineer (Post 541264)
Error: C:\Users\LIDA\Desktop\inlet.c: line 12: thread: undeclared variable

I don't know what does it mean and also if it can be solved or not.

Your error has provided the error type (undeclared variable, you should declare variables before using them) and where it has occurred (line 12 of inlet.c: your UDF?).

upeksa April 13, 2015 03:37

the line:

F_PROFILE(f,t,i)=6.5*(1-y/3.5)^(1/7);

is wrong.

Use:
F_PROFILE(f,t,i)=6.5*pow((1-y/3.5),(1/7)) ;

tooraj August 9, 2015 12:52

hello every one
i have two formolas and i want to write them in c+


the inlet velocity in the z direction from 0 to the prabolic profile
V(r)= 4.5 ( (r+0.1mm)/0.2mm)(1-(r+0.1mm)/0.2mm)
during the 2µs. the velocity is then v(r) for 10µs and finally decreases to 0 another 2µs the time dependent velocity profile in the z direction can then be defined as:
v(r,t)=(step(t-1.〖10〗^(-6))-step(t-13.〖10〗^(-6))).v(r)
where t is given in seconds and step(t) is a smooth step function

PLEASE help me


i wrote this but fluent cant run it:

#include "udf.h"

DEFINE_PROFILE( unsteady_velocity_profile, t, i,r,t,v,a,b,total,)
{
real current_time;
real x[ND_ND];
real y;
face_t f;
current_time = CURRENT_TIME;
begin_f_loop(f, t)
{
F_CENTROID(x,f,t);
y = x[1];
if (current_time < 10.)
{
F_PROFILE(f,t,i)=4.5*pow[(y+(0.1*0.001))/(0.2*0.001)]*[1-((y+(0.1*0.001))/0.2*0.001))];
}
"a event folat from 0 through 200*0.001
for(i=0;i<=200*0.001;i+=0.000001)
{
a+=i;
}
cout<<"sum in step one is"<<a;
"b even float from 0 through 200*0.001
for(i=0;i<=200*0.001;i+=13*0.000001)
{
b+=i;
}
cout<<"sum in step two is"<<b;
v total=(a-b)*v;
cout<<"total is:"<<total<<end l;
}


All times are GMT -4. The time now is 20:32.