 ## Fluids

#### How to remove “Undeclared Variable” Error in Ansys Fluent UDF for Density?

• Azim07
Subscriber

Here i have a UDF which Shows the undeclared variable error in line 6. How can i remove this?

#include "udf.h"
DEFINE_PROPERTY(cell_density,c,t)
{
real rho;
real T = C_T(c,t);
rho = 885/(0.0008(temp-321.35)+1);
C_UDMI(c,t,0) = rho;
return rho;
}

• Rob
Ansys Employee

I find deleting the line to solve many problems. Read the error carefully, and tell me which variable is undefined.

• rachels1001
Subscriber

I may be wrong, but is the "temp" variable defined anywhere?

• Azim07
Subscriber

I just need to define the density in the way of following Equation

rho = 885/(0.0008*(t-321.35)+1)

How can i easily enter it ?

• rachels1001
Subscriber

by using the macro C_T, you are finding the temperature for the cell that you are passing into the UDF, and you are defining this temperature as T. If this is the temperature that you want to evaluate density by, the line should read

"rho = 885/(0.008*(T-321.35)+1)"

not "rho = 885/(0.008*(Temp-321.35)+1)"

• Rob
Ansys Employee

cvelikonja: correct. T is defined, temp is not so will cause an error when used in the code.

Note, UDFs may be case sensitive so always consider this too.  T is also a slightly dangerous letter to use when you're using t for thread in Line 2.

• Azim07
Subscriber

Thank you very much Gentleman......

I am getting Floating Error in the following UDF of viscosity......

#include "udf.h"

DEFINE_PROPERTY(cell_viscosity,c,t)

{

real mu;

real temp=C_T(c,t);

mu =(0.00727)+((((-8.6022)+(1871.3/temp)+(0.0152*temp)-(0.000012043*temp*temp))-(0.00727))/1+(exp((10/343-temp)*(temp-321.35))));

return mu;

}

How can i remove this?

• Rob
Ansys Employee

I doubt the floating point is in the UDF: it'll be the value produced by the UDF. Plot the value of your function against temperature and see what it produces. 