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] Relative coordinates in logarithmic velocity profile (https://www.cfd-online.com/Forums/fluent-udf/63769-udf-relative-coordinates-logarithmic-velocity-profile.html)

cfdworker April 19, 2009 12:31

[UDF] Relative coordinates in logarithmic velocity profile
 
Hello, I have a problem with the definition of a boundary condition with UDF to simulation of the wind in a terrain. I have to define a velocity inlet in a 3d domain; this condition is a logarithmic velocity profile. I can define the logarithmic velocity profile with UDF, like this:



#include "udf.h"

DEFINE_PROFILE(log_velocity,thread,index)
{
real x[ND_ND];
real z;
face_t f;

begin_f_loop(f,thread)
{
F_CENTROID(x,f,thread);
z = x[2];
F_PROFILE(f,thread,index) = 3*log(z/0.01)/log(10/0.01);
}
end_f_loop(f,thread)
}


My domain is this:

http://img151.imageshack.us/img151/6542/semttulog.png

I have to impose the logarithmic profile in the front face that is shown in figure.
My question is how I define in the UDF so that the velocity in bottom of the face is equal 0.
My problem is the coordinates that I use in UDF are absolute and I don’t know how to define relative coordinates, in order to the z in the equation that defines the velocity profile, is the height relatively to the bottom of the face and not the absolute height.

I would appreciate any suggestions.

lalula2 April 21, 2009 05:28

hi, i need help on creating UDF for logarithmic velocity profile for my final year project also. But i am not very familiar with c programming language...any good example for me to follow??
thanks

lalula2 April 23, 2009 11:53

Hi cfdworker....
since ur simulation problem is 3D, then how about the y vector??
and for the array part,shudnt it be 3D array??
Any pro or expert here mind to share their suggestion and opinion?
thanks.

Häwimeddel April 23, 2009 12:25

I guess your boundary condition for the landscape ist WALL. To estimate the distace from any cell to the nearest WALL, you could maybe use C_WALL_DIST(c,t).

cfdworker April 23, 2009 17:20

Hi, thanks for the reply. I tried to use the C_WALL_DIST(c,thread) macro like this:


#include "udf.h"

DEFINE_PROFILE(log_velocity,thread,index)
{
real z;
face_t f;
cell_t c;

begin_f_loop(f,thread)
{
z = C_WALL_DIST(c,thread);
F_PROFILE(f,thread,index) =3*log(z/0.01)/log((10)/0.01);
}
end_f_loop(f,thread)
}



But when i selected the udf in velocity inlet in boundary condition, fluent gave me this message:


Error:
FLUENT received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
4. Report error to your distributor.
Error Object: ()



I think the problem is that the boundary condition that I set is to a face and I use a macro for cells in the udf.

I don’t know how to use this macro for my situation. Can anyone help me with this issue ?

Thanks in advance

cfdworker April 27, 2009 10:25

Someone can help me. Please I need someone who is patient to help me with this problem.

Thanks.

cfdworker April 27, 2009 20:38

I tried to make another udf, as shown:


#include "udf.h"

DEFINE_PROFILE(inlet_x_velocity, thread, position)
{
cell_t c;

begin_c_loop(c, thread)
{
C_PROFILE(c, thread, position) = 3.*log(C_WALL_DIST(c,thread)/(0.01))/log(10./(0.01));
}
end_c_loop(c, thread)
}

But gave me the same error message.
I want to use the distance between the faces centroids that were determined by the F_CENTROID(f,thread) macro in the first udf and the terrain, in the face where I have to impose the velocity profile. But the only macro i know that give an distance is the C_WALL_DIST(c,thread), and this is applied to cells. I don't Know how to determine the distance for faces, for my problem.

Please, i beg for help. :(

coglione April 29, 2009 04:03

Hello,

try this one and let me know if it works. Having a look at the UDF-Manual section 3.2.5 might also help.

#include "udf.h"

DEFINE_PROFILE(log_velocity,thread,index)
{
real z;
face_t f;
cell_t c;
Thread *tc;

begin_f_loop(f,thread)
{
c = F_C0(f,thread);
tc = THREAD_T0(f,thread);
z = C_WALL_DIST(c,tc);
F_PROFILE(f,thread,index) =3*log(z/0.01)/log((10)/0.01);
}
end_f_loop(f,thread)
}

cheers

cfdworker April 29, 2009 09:14

hello, thanks for the reply. I used your udf, but still gives the same error message, when I do init to start iterate.



Error:
FLUENT received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
4. Report error to your distributor.
Error Object: ()

coglione April 29, 2009 09:34

Hm,
seems like Fluent does not recognize C_WALL_DIST() at all. Is your case laminar or turbulent? It might be that C_WALL_DIST() is only available if a turbulence model is activated.

cheers

cfdworker April 29, 2009 09:59

My case is turbulent. I think that the fluent recognizes the macro, i think that the problem is in using macro for cells in a boundary condition that is imposed in a face. I do not know if this is the problem. What do you think ?

Thanks

coglione April 29, 2009 10:38

No, F_C0 and THREAD_T0 give you cell index and cell thread of the adjacent cell to each face at your boundary which is o.k. You can try the following:

type solve/set/expert in the text user interface of Fluent and enter yes if asked to keep temporary memory from being freed. Maybe a DEFINE_PROFILE macro for velocity i.e. applied for momentum equation does not has default access to C_WALL_DIST which is relevant for turbulence.

Hope this helps

cfdworker April 29, 2009 11:12

I already did what you said, but even so it gives the same error message.

Thanks for the replys.

coglione April 30, 2009 09:41

Hi again,

it seems like you have to do some testing what the actual problem is.

If you replace C_WALL_DIST with for example C_CENTROID: does it work? This would indicate that C_WALL_DIST is to blame

If so, try to hook your DEFINE_PROFILE for one of the turbulence variables, e.g. k, and check whether it works then. If yes you could iterate one single iteration/timestep, store the cell wall distance in a UDM and proceed with your velocity-profile-udf using this values.

cheers

cfdworker April 30, 2009 15:54

Hello. I did what you said. I replace C_WALL_DIST for C_CENTROID, but still gives the same error.

coglione May 4, 2009 03:34

Well, then something more fundamental is wrong with your udf. If you compile your udf, what does the log-file say? Everything ok or some warnings?

cheers

cfdworker May 4, 2009 10:11

Hello.
I found a alternative way to define the velocity profile for my problem.
What I did was, first write out a profile file at the inlet boundary, then obtain a profile file, which contains vectores of x,y,z,cell wall distance and velocity magnitude, then I read the file with excel and replace the velocity magnitude by a function of cell wall distance (which is the logarithmic function for velocity profile). Then i save the altered data and read this back to fluent as profile. Finally, then I used these profiles as boundary conditions for the inlet.

Thanks for the replys.

lalula2 May 14, 2009 12:27

hi there, how to use fluent to read the altered data??
mind to share??
Thanks.

mrn August 6, 2010 13:11

dear cfdworker,
i have a problem same as your case and i have to define logarithmic velocity inlet at the beginning of cylindrical pipe.but unfortunately i have a error when i want to hook this udf and set as velocity inlet in boundary condition panel or it doesn't iterate( error is invalid number?!).please tell me how i can solve my problem.i have wrote the udf as below.velocity inlet is in y direction.

#include "udf.h"

DEFINE_PROFILE(inlet_y_velocity, thread, position)

{

real xc[ND_ND];

real ro,mu_t,visc_t,x,y,z,a,r,rw,utaw,rbi,yplus,b;

cell_t c;
face_t f;
ro = C_R(c,thread);
mu_t = C_MU_T(c,thread);
visc_t=mu_t/ro;

begin_f_loop(f, thread)

{

F_CENTROID(xc,f,thread);

x = xc[0];
y = xc[1];
z = xc[2];

rw=0.5;
utaw=0.0176;
r=sqrt(pow(x,2)+pow(z,2));
rbi=r/rw;
yplus=utaw*r/visc_t;

b=(1.5*yplus*(1+rbi))/(1+2*pow(rbi,2.));


F_PROFILE(f, thread, position) = utaw*(2.5*log(b)+5.5);

}

end_f_loop(f, thread)

}

metmet August 8, 2014 11:59

wind profile
 
Dear friends
Would you mind if I remind this thread after along time?
Actually I want to simulate a tower with 30 levels in a 3D domain created by ICEM CFD. My objective is to simulate airflow around the tower and also investigate about the flow inside apartments in several levels which their windows are open in windward direction so I concern about wind profile which gives different value of velocity in different levels (heights). I have found that Log law wind profile will be used in this study but I'm very beginner in UDF so would you please guide me how come I can write a correct UDF suitable in my case? I will use K-Epsilon RNG and K-Omega turbulence models in my study and inlet is velocity inlet and outlet will be pressure outlet. the dimensions of domain is 700m (X), 350m (Y) and 280m (Z) which Z is height direction in this case. and apartments will be in 1m, 6m, 10m, 25m and 50 m of height.
Would you please guide me how I can solve my problem?


All times are GMT -4. The time now is 17:28.