CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)

 gina September 29, 2009 13:35

Hello everybody. I would be really grateful if any of you could address me on how to create an UDF to change the turbulent viscosity (hence k+ formula), only on a portion of my domain. I have been trying the following:

-----------------------------------------

/************************************************** ********************

UDF pour la vitesse et la viscosité turbulente
************************************************** ********************/

#include "udf.h"

//udf de viscosité turbulente//

DEFINE_TURBULENT_VISCOSITY(user_mu_t,c,t)
{

real x[ND_ND];

real y;

real mu_t,yp,utau,nu,…..;

utau=;

nu=;
…..
y=x[1];

yp=(y*utau)/nu;
if (yp <= 20) {

mu_t =……….

return mu_t;

}

-----------------------------------------------------------

which I have interpreted and my program converged, by my result of k+=f(y+) is not correct.

I do not know if fluent takes into consideration that k also changes with the change of mu_turbulent or not?

 dmoroian October 20, 2009 02:52

Random value mu_t

Hello Gina,
Your code must specify a value for mu_t all the time, not only when yp <= 20! Otherwise the value will be undefined (random).
Code:

```... if(yp <= 20)   mu_t = ... else   mu_t = ... ...```
Dragos

 gina October 23, 2009 14:29

how to write in udf: take the default value?

ok, if I mean: for the other values of mu_t fluent must take the default one that exists already in fluent

how to write that in my udf

 gina October 23, 2009 14:34

how to write in udf: take the default value?

thank you very much to have reply for my request

ok, if I mean:

if(yp <= 20)
mu_t = ...
else
mu_t = takes the default value in fluent

how to write this in my udf?

 dmoroian October 23, 2009 15:37

I'm afraid that if you use a udf for the turbulent viscosity, you have to provide it for all the cells.
But I think you may check the manuals for the default implementation and add it to your own.
For example:
Code:

```  real mu_t;   real rho = C_R(c,t);   real k  = C_K(c,t);   real d  = C_D(c,t);   mu_t = M_keCmu*rho*SQR(k)/d;   return mu_t; ```
or try the default macro and see if it works:
Code:

`mu_t  = C_MU_T(c,t);`
Dragos

 gina October 23, 2009 16:35

it run but!!!

the calcul run but the results is not good! can i send you my udf to see it?

 dmoroian October 23, 2009 17:14

Send me your code, but I will not be able to look at it until Tuesday.

 gina October 23, 2009 17:32

my udf

if you need the values of constant and for mu_t expression i will
send them for you
-------------------------------------------------------------------------
#include "udf.h"

DEFINE_TURBULENT_VISCOSITY(user_mu_t,c,t)
{
real mu_t;
real rho = C_R(c,t);
real k = C_K(c,t);
real d = C_D(c,t);

real x[ND_ND];
real y,yplus,utau,vkr,Cv,Alplus,Akplus,B,nu;

Cv=..;
vkr=..;
B=..;
Akplus=..;
Alplus=..;
nu=..;
utau=..;

y=x[1];
yplus= (rho*utau*y)/nu;

if (yplus <= 20)
{
mu_t =(...)*nu;
}
else
{
mu_t = M_keCmu*rho*SQR(k)/d;
}

return mu_t;
}

 dmoroian October 25, 2009 13:35

Hi Gina,
If this is your complete udf, then I don't see where you initialize the vector x. If you don't put an explicit value inside it, then
Code:

`y = x[1];`
will set a random value to variable "y", and consequently it will produce an erroneous value for "yplus"?

Dragos

 gina October 26, 2009 17:26

i am new in udf and it is my first udf wich i write:

can you tell me please if it is correct to write
---------------------------------------------------------------------
#include "udf.h"

DEFINE_TURBULENT_VISCOSITY(user_mu_t,c,t)
{
real mu_t;
real rho = C_R(c,t);
real k = C_K(c,t);
real d = C_D(c,t);

real y,yplus,utau,vkr,Cv,Alplus,Akplus,B,nu;

Cv=..;
vkr=..;
B=..;
Akplus=..;
Alplus=..;
nu=..;
utau=..;

y=C_WALL_DIST(c,t);
yplus= (rho*utau*y)/nu;

if (yplus <= 20)
{
mu_t =(...)*nu;
}
else
{
mu_t = M_keCmu*rho*SQR(k)/d;
}

return mu_t;
}

 t.krishnamohan October 26, 2009 21:22

Hi,
I really cannot understand why you want to calculate eddy viscosity in the near wall regions. In near wall regions, properties are calculated using wall functions. If you want to define your own wall fuction, it is possible by using DEFINE_WALL_FUNCTIONS UDF. Numerical simulation is carried out only in the core turbulent flow region(Defect region). Please also be advised that the mean componet of minor velocities are zero in the near wall region and only the fluctuating component of velocty will exist and is equal in all the directions(isotropic). The mean component of major velocity is determined using wall function. Then why do you need eddy viscosity in the near wall region.

Hope I can be of any use to you if you can explain what exactly you need?
Regards,
Krishna Mohan

 gina October 27, 2009 15:15

yes i want to define my own wall function,
I want to implement a new eddy viscosity formulation for turbulent boundary layers near smooth walls.
For this reason that I thought to change the eddy viscosity which already exists in fluent but just near the wall,
i have write my new eddy viscosity formulation! , i have interpreted it and then i add it in the panal:
define_model_ viscous model_user define function_turbulent viscosity

it is not correct what i do!?

thanks to guide me

 t.krishnamohan October 27, 2009 20:50

Hi,
You are getting confused with wall functions and eddy viscosity. If you need to define your own wall functions, then why you need eddy viscosity in the near wall region? You can find the properties with wall functions near the wall region so, where is the question of eddy viscosity coming into picture. Please read "Near Wall Treatment for Wall Bounded Flows" chapter in fluent documentation. I am sure your approach to define eddy viscosity in the near wall region is wrong.
Regards,
Krishna Mohan

 t.krishnamohan October 27, 2009 20:53

If you want to run the UDF, change the term SQR(k) to pow(k,2.0), SQR() is not a valid function.
Rgds,

 dmoroian October 28, 2009 10:00

There is a macro defined by Fluent in global.h:
Code:

`#define SQR(a) ((a)*(a))`
which makes the call valid and much faster than pow(x,2).

Dragos

 gina October 28, 2009 16:16

hello Krishna Mohan, Perhaps I am not well express:(
I am trying to add a new eddy viscosity formulation (nu_t_plus) for turbulent boundary layers near smooth walls in near wall region and specially in the region when y+<=20

nu_t_plus= n_t/nu
in fluent we cant modiffy directly nu_t_plus for that i can write also:
nu_t=nu_t_plus*nu
and since I have airflow ro=1 --> mu_t=nu_t
than i can write
mu_t=nu_t_plus*nu
because in fluent we have acces for the value of mu_t and not nu_t

I have write my udf for mu_t and interpreted it than i have add it in viscosity turbulent udf panal to modify the nu_t_plus for y+<=20

have you understand what i want to do I

am new in udfs,and please I need your orientation if you want.
I thank you

 vsampath October 28, 2009 17:27

Gina i have a similar problem i am interested in getting the y co-ordinate

this is my udf

#include "udf.h"
{
cell_t c;
real x[ND_ND];
real mu_lam;
real y;
Domain *domain = Get_Domain(1);
y=C_WALL_DIST(c,t);
printf("y= %f \n",y);
mu_lam= 0.001002*(2-(y/0.01));
printf("MU= %f \n",mu_lam);
return mu_lam;

}

y=C_WALL_DIST(c,t); does not seem to work for me...... is their an alternative way???

thanks

 dmoroian October 29, 2009 03:24

Quote:
 Originally Posted by t.krishnamohan (Post 234264) Hi, ... You can find the properties with wall functions near the wall region so, where is the question of eddy viscosity coming into picture. ...
What about low Re turbulence models? Do they use wall functions, too?
I suspect that Gina tries to compute the flow using a low Re turbulence model. The only issue that I see is the macro C_WALL_DIST(c,t) which is not documented and I don't know when is available.
Gina, is your udf still not working? Maybe you can write your own function for the value of wall distance.

Dragos

 dmoroian October 29, 2009 03:33

Quote:
 Originally Posted by vsampath (Post 234415) ... real y; ... printf("y= %f \n",y); ...
Hi Vivek,
Besides the fact that you are using an undocumented macro, your udf should work only for single precision. To get it to work for double precision too, use "%g" or "%e" instead of "%f" (in both places). Then you will be sure that what you see on the screen is the actual value of the variable.

Dragos

 vsampath October 29, 2009 12:58

thank you dmorian,

Is there a way i can get y coordinate. My geometry is a circular pipe where my viscosity varies with radius of the pipe.... for that purpose i need the y cordinate in each cell to be able to specify the visocity.... can you help me find a way....

thank you

All times are GMT -4. The time now is 04:05.