We have an exciting announcement about badges coming in May 2025. Until then, we will temporarily stop issuing new badges for course completions and certifications. However, all completions will be recorded and fulfilled after May 2025.
Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Problem with the UDF and the default turbulent viscosity of Realizable k-e

    • Max
      Subscriber

      Hi Fluent experts,

      I am trying to make the UDF for the Realizable k-epsilon turbulent viscosity based on the paper of Shih et al. and that expressed in the Fluent theory guide.

      The UDF code is for 2D simulation as follows:

      #include "udf.h"
      #include "math.h"

      DEFINE_TURBULENT_VISCOSITY(tur_vis,c,t)
      {
        real mu_tur;
        real S11, S12, S22, W12, W12r, S;
        real SMU, WAS, PHI, USTAR;
        real AS;
        real CMU, a1, a2, a3, a4, a5, a6;
        real PHI2, F2;

      /***/
        real betas=0.09;
        real A0=4.04;
        real rho=C_R(c,t);
        real k=C_K(c,t);
        real w=C_D(c,t);
        real CMUL=C_MU_L(c,t);
        real y=C_WALL_DIST(c,t);

      /***/
        real wr=-1.485446130;       /***rotation speed unit: 1/s***/

      /***/
        S11=0.5*(C_DUDX(c,t)+C_DUDX(c,t));
        S12=0.5*(C_DUDY(c,t)+C_DVDX(c,t));
        S22=0.5*(C_DVDY(c,t)+C_DVDY(c,t));
       
        W12=0.5*(C_DVDX(c,t)-C_DUDY(c,t));

      /*** Cal vorticity with angular velocity wr ***/
       
        W12r=W12-wr;

      /*** Cal U*  ***/

        USTAR=sqrt(S11*S11+2.0*S12*S12+S22*S22+2.0*W12r*W12r);

      /*** Cal Phi ***/

        SMU=sqrt(S11*S11+2.0*S12*S12+S22*S22);
        WAS=(pow(S11,3)+pow(S22,3)+3.0*pow(S12,2)*(S11+S22))/pow(SMU,3);
        PHI=1.0/3.0*acos(max(-1.0,min(sqrt(6.0)*WAS,1.0)));

      /*** Cal As ***/
       
        AS = sqrt(6.0)*cos(PHI);

      /*** Cal CMU ***/
       
        CMU=1.0/(A0+AS*USTAR*k/w);

      /*** Cal Viscosity ***/

        mu_tur=CMU*rho*k*k/w;
        
        return mu_tur;
      }

      The simulations were performed for both the UDF and the default viscous model. However, there is a large deviation between these simulations' averaged results. I do not know why and why this difference is because the UDF code was based on the expression in the Fluent theory guide. I also compared the simulation between the UDF code and the default turbulent viscosity of the SST k-omega model and got a good agreement between the results.

      Could anyone please help?

      Thank you very much.

    • Rob
      Forum Moderator

      I'm assuming PHI is in radians? Otherwise the code doesn't look to have any obvious problems. I'd favour more intenting and comments for future reference and I'd tend to avoid 2-3 character variables where possible in case anything overlaps with a Fluent value. 

      I've not had a detailed look, and won't be doing any debugging. If you plot contours, lines  etc are the results off by an offset, factor or just random differences?

      • Max
        Subscriber

         

         

        Thank Rob,

        I think PHI is in radian.

        I compare the torque on the object versus the simulation time which shows the difference in the case of Realizable k-e (see the figure – series 1 is UDF and series 2 is the defaul model) but not for SST k-w.

         

         

    • Rob
      Forum Moderator

      That looks like an offset, how constant is that value?

Viewing 2 reply threads
  • You must be logged in to reply to this topic.