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 : velocity, k and epsilon (radial profile) (https://www.cfd-online.com/Forums/fluent-udf/121010-udf-velocity-k-epsilon-radial-profile.html)

cdiako July 19, 2013 05:03

UDF : velocity, k and epsilon (radial profile)
 
Hello,

I am an user of FINE/Open. I would like to make a comparison with Fluent. Therefore, I need a little help in Fluent:

I have a radial profile (in inlet) for speed, k and epsilon. And I'd like to define an UDF. Is it possible to give a profile of a distance and say that the problem is cylindrical in an UDF? (To simplify the problem).

To complicate matters, my inlet surface is divided into two inlet in Fluent (I imported the Hexpress mesh to Gambit and I could not merge the surfaces).


Thanks a lot !

blackmask July 19, 2013 05:28

You can use the
Code:

DEFINE_PROFILE
macro.

cdiako July 19, 2013 05:35

Can you give me a little example?
For example, if I have a velocity profile:

for r = 0, v = 25 m / s
r= 0.02m = r v = 10 m / s
r = 0.03 m, v = 0.5 m / s
r = 0.2 m, v = 0 m/s

blackmask July 19, 2013 06:11

For simplicity, I assume that the velocity profile is piece-wise constant.

Code:

#include "udf.h"
DEFINE_PROFILE(inlet_axial_velocity, thread, position)
{
real orig[ND_ND] = {1.0, 2.0, 3.0};
real x[ND_ND];
face_t f;
real r;
real v;

begin_f_loop(f,thread)
{
F_CENTROID(x, f, thread);
NV_VV(x,=,x,-,orig);
r = NV_MAG(x);
if ( r < 0.02) {
v = 25.0;
} else if ( r < 0.03) {
 v = 10.0;
} else if ( r < 0.2) {
 v = 0.5;
} else {
 v = 0.0;
}
F_PROFILE(f, thread, position) = v;
}
end_f_loop(f, thread)
}


cdiako July 19, 2013 08:23

Ok, thank you very much ! I must just read a little about commands that you used in the code.

I may come back with some questions in a few days ;)

cdiako July 19, 2013 10:10

I have a small question about the line

real orig [ND_ND] = ...

if the inlet face has a distance on 0.06m (on the z axis) above the origin. I can replace our line by :

static const real origin [3]= {0.0; 0.0; 0.06}

it's correct?

Thank you again for the help !

blackmask July 19, 2013 10:16

Yes, and
r = NV_MAG(x);
should be replaced by
r = sqrt(x[0]*x[0]+x[1]*x[1]);
I made a mistake in my previous post.

cdiako July 19, 2013 10:22

Ok, thank you! I didn't see the fault.

blackmask July 19, 2013 10:27

I took r as the distance between x and the origin in my #4 post, i.e., r=|X-O|. But in fact r should be the length of projection of the vector <X-O> onto the (r, theta) plane, that's why x[2] vanishes in #7.

cdiako July 19, 2013 10:33

Yes yes, I understood. I meant that I hadn't seen the fault before you say it.

cdiako July 19, 2013 11:21

And just a last thing : you have simplify the case, but if we want to interpolate the velocity, we must use a loop or there is another possibility (a function) ?

blackmask July 19, 2013 21:02

Yes, you simply change
F_PROFILE(f, thread, position) = v;to
F_PROFILE(f, thread, position) = some_func(r);where
Code:

real some_func(real r) {
real vel;
real r0[] = {0.0, 0.02, 0.03, 0.20};
real v0[] = {25.0, 20.0, 10.0, 0.00};
// interpolation the value of vel at r
return vel;
}


str6073 July 20, 2013 11:15

hi guys
i need a udf for a work. i'll explain what i need . I want to provide a linear varying temperature boundary condition on the circular side of a cylinder . can you help me?? My idea about udf is very small. diameter of cylinder is 41.3 mm . temperature may vary from 25 to 50 degrees

cdiako July 22, 2013 05:37

@blackmask : Thank you ! can you tell me if the code is correct?

#include "udf.h"

real some_func(real r)
{
real vel;
real r0[] = {0.0, 0.02, 0.03, 0.20};
real v0[] = {25.0, 20.0, 10.0, 0.00};
int j=0;
int i=0;

while(i<=ND_ND)
{

if(r==0)
{
vel[i]=v0[0];
}

if(r<0.2)
{
while (r<r0[j])
{
j++;
}
vel[i]=((v0[j+1]-v0[j])/(r0[j+1]-r0[j]))*(r-r0[j])+v0[j];
}

else
{
vel[i]=0;
}

i++;

}

return vel;
}


DEFINE_PROFILE(inlet_axial_velocity, thread, position)
{
static const real orig[3]={0.0, 0.0, 0.06};
real x[ND_ND];
face_t f;
real r;
real v;
int i=0;

begin_f_loop(f,thread)
{
F_CENTROID(x, f, thread);
NV_VV(x,=,x,-,orig);
r = sqrt(x[0]*x[0]+x[1]*x[1]);
F_PROFILE(f, thread, position) = some_func(r);
}
end_f_loop(f, thread)
}

@ str6063 : I started too. So, I do not know how to help you.

blackmask July 22, 2013 20:55

A linear interpolation could be implemented as follows:
Code:

#include "udf.h"

real some_func(real r)
{
        real vel;
        real r0[] = {0.0, 0.02, 0.03, 0.20};
        real v0[] = {25.0, 20.0, 10.0, 0.00};
        int i=0;

        if ( r >= r0[3] ) return 0.0;
        while( r >= r0[++i]) ;

        return v0[i-1]+(v0[i] - v0[i-1])/(r0[i] - r0[i-1]);

}


DEFINE_PROFILE(inlet_axial_velocity, thread, position)
{
        static const real orig[3]={0.0, 0.0, 0.06};
        real x[ND_ND];
        face_t f;
        real r;
        real v;

        begin_f_loop(f,thread)
        {
                F_CENTROID(x, f, thread);
                NV_VV(x,=,x,-,orig);
                r = sqrt(x[0]*x[0]+x[1]*x[1]);
                F_PROFILE(f, thread, position) = some_func(r);
        }
        end_f_loop(f, thread)
}


cdiako July 23, 2013 04:10

Thank you again !

Juste to be sure, I think that there is two mistake :

1) the 4 int the two vector : real r0[4]={...};
2) the second return : I think, it must be :

return return v0[i-1]+((v0[i] - v0[i-1])/(r0[i] - r0[i-1]))*(r-r0[i-1]);

and for k and epsilon, I suppose that is exactly the same ?

And now, I have an other question : In my domain, I have a fluid part and a solid part. In the solid, I'd like inserting a localized heat source in terms of x, y and z. Is this possible? (and in the definition of the coordinates, it slightly exceeds? eg, due to an imprecise geometry, my x-coordinate exceeds of 1 mm, how Fluent work? ) Can you help me ?

Thank you again for your help !

cdiako July 23, 2013 04:16

(I forgot to say that I want to insert the heat source in the solid)

blackmask July 23, 2013 04:30

#16
1) c array is zero-based so that the last index in the array is length of array minus one
2) you are right, I forget the (r - r0[i-1]) term

You can use
Code:

FLUID_THREAD_P

cdiako July 23, 2013 04:43

You can help me to construct the udf ? if I have this coordonates for the heat source :

- x : x=0 to 0.001
- y : y=0 to 0.0015
- z : z=0.001 to 0.00012

vol=0.001*0.0015*0.0002;
HT=10/vol;

thanks a lot !

str6073 July 23, 2013 05:03

hi
i need a udf for a work. i'll explain what i need . I want to provide a linear varying temperature boundary condition on the circular side of a cylinder . can you help me?? My idea about udf is very small. diameter of cylinder is 470mm. temperature may vary from 25 to 50 degrees from botom to top

cdiako July 23, 2013 06:02

It's really strange, I have compiled the udf and the compiler tells me this :

udf_final_velocity_check.c: In function ‘some_func’: udf_final_velocity_check.c:6: warning: excess elements in array initializer udf_final_velocity_check.c:6: warning: (near initialization for ‘r0’) udf_final_velocity_check.c:7: warning: excess elements in array initializer udf_final_velocity_check.c:7: warning: (near initialization for ‘v0’) udf_final_velocity_check.c:5: warning: unused variable ‘vel’ udf_final_velocity_check.c: In function ‘inlet_axial_velocity’: udf_final_velocity_check.c:23: warning: unused variable ‘v’ # Linking libudf.so because of makefile user.udf udf_names.c udf_names.o udf_final_velocity_check.o ld -shared -lm udf_names.o udf_final_velocity_check.o -o libudf.so make[3]: warning: Clock skew detected. Your build may be incomplete. make[3]: Leaving directory `/home/cdiakodi/Desktop/Fluent_fran_fran/maillage_pr_fluent/new_2/lnamd64/3d' make[2]: warning: Clock skew detected. Your build may be incomplete. make[2]: Leaving directory `/home/cdiakodi/Desktop/Fluent_fran_fran/maillage_pr_fluent/new_2/lnamd64/3d' make[1]: warning: Clock skew detected. Your build may be incomplete. make[1]: Leaving directory `/home/cdiakodi/Desktop/Fluent_fran_fran/maillage_pr_fluent/new_2/lnamd64/3d'

an idea ?

blackmask July 26, 2013 20:42

It happens if you the array initializer has more elements than the array declared
Code:

int r0[3] = {0, 1, 2, 3};
In the above example "r0" is an integer array of length three while the initializer has four elements. In my post I wrote it as
Code:

int r0[] = {0, 1, 2, 3};
There should be no warning.

cdiako July 29, 2013 04:44

You were right, the UDF works now.

Thank you!

cdiako July 30, 2013 08:29

Just one last question: how can I change the UDF that we have created to add a velocity profile of particles (using DPM)?


All times are GMT -4. The time now is 00:15.