# UDF for Carreau-Yasuda Viscosity model

• 382 Views
• Last Post 27 September 2019
• Topic Is Solved
BeginerModel posted this 19 March 2019

Hi All,

I am trying to write a UDF for the Carreau-Yasuda viscosity model according to the following equation.

Everything in the equation is a parameter which I can define apart from the shear rate term. I believe in fluent I can call this value using;

C_STRAIN_RATE_MAG(c,t), but when I try and raise this to a power as in the equation, I get an error saying "invalid binary expression, double ^ float), implying that the magnitude isn't an integer? Any help is appreciated, and my UDF is below.

/* Carreau-Yasuda Viscosity Model */

#include "udf.h"

float mu_inf=0.00345;

float mu_zero=0.16;

float lambda=8.2;

float p=0.64;

float n=0.2128;

DEFINE_PROPERTY(cell_viscosity,c,t)

{

real mu_lam;

real rate;

rate=(C_STRAIN_RATE_MAG(c,t));

mu_lam=mu_inf+((mu_zero-mu_inf)*(1+(lambda*rate)^(p)))^((n-1)/p);

}

abenhadj posted this 19 March 2019

Wrong sytanx: Look into the Ffuent Customization.

Use pow function for power and use real as variable type.

Best regards,

Amine

rwoolhou posted this 20 March 2019

You need to make rate a real too: I just put the macro into the equation when I wrote the code a few years back for blood flow modelling.

Eirene2015 posted this 27 September 2019

After one day of digging in UDFs, i wrote and validated the following function.

No need to compile it and go through the whole miserable process of compiling UDFs in Ansys Fluent, just interpret it and use it,

Note that if you are initialising with zero velocity in the whole domain, then the shear rate at t=0 is equal to zero, which makes the formulation pow( 0 , p) diverge the simulation. Simply use a small value for a component of velocity to overcome this issue

/* Carreau-Yasuda Viscosity Model */

#include "udf.h"

DEFINE_PROPERTY(cell_viscosity,c,t)

{

real mu_inf=0.00345;

real mu_zero=0.16;

real lambda=8.2;

real p=0.64;

real n=0.2128;

real mu_lam;

real rate=(C_STRAIN_RATE_MAG(c,t));

mu_lam=mu_inf + (mu_zero-mu_inf) * pow(1.0 + pow( lambda*rate , p ) , (n-1)/p );

return mu_lam;

}