## Fluids

#### HOW TO WRITE UDF FOR DENSITY OF WATER

• Devank12
Subscriber

I want to define Density of  water that varies with temperature  I have  written a UDF based on the following polynomial equation. I donot know it is right . If anycorrection plz inform me. Thanks

#include "udf.h"

{

real rho;

real T = C_T(c,t);

rho = 765.33+1.8142*T – 0.0035*pow(T,2.)

C_UDMI(c,t,0) = rho;

return rho;

}

• DrAmine
Ansys Employee

Help your self by using debugging messages. You have started with writing into UDMI's that if fine. You need to use the cell pointer and cell thread pointer passed by Fluent. Actually you don't need an UDF as you can use the polynomial option there.

• RagnorakMan
Subscriber

Hi Devank,

While this post is a year old but I've recently tried out your udf but for a solid. Just remember to change the cell and thread to c & t eitherwise FLUENT wouldn't recognize the other variables.

#include "udf.h"

DEFINE_PROPERTY(cell_density, c, t)

{

real rho;

real T = C_T(c,t);

rho = 765.33+1.8142*T – 0.0035*pow(T,2.)

C_UDMI(c,t,0) = rho;

return rho;

}

• DrAmine
Ansys Employee

Why using an UDF to do just a temperature dependent density. Just use polynomial law in Fluent.

• RagnorakMan
Subscriber

Because I'm trying to model a phase change material but as a solid. The drop down menu does not provide me with a polynomial function. Only the specific heat capacity and the thermal conductivity

• DrAmine
Ansys Employee

You need to define that solid as a fluid in order to use phase change models or any phase-change related UDF.