Ansys Assistant will be unavailable on the Learning Forum starting January 30. An upgraded version is coming soon. We apologize for any inconvenience and appreciate your patience. Stay tuned for updates.
Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

UDF for Carreau-Yasuda Viscosity model

    • BeginerModel
      Subscriber

      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);


      }


       

    • DrAmine
      Ansys Employee

      Wrong sytanx: Look into the Ffuent Customization.


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

    • Rob
      Forum Moderator

      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
      Subscriber

      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;


      }


       


       

Viewing 3 reply threads
  • The topic ‘UDF for Carreau-Yasuda Viscosity model’ is closed to new replies.
[bingo_chatbox]