Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Divergence using UDF for specific Heat (Fluent)

    • johnam29
      Subscriber

      Background: Running water in co-axial channels into a 2-D domain with temperatures varying from sub- to super-critical using Fluent

      Since water has a Cp spike for Super critical water ( as attached in the file).
      Divergence using UDF for specific Heat-cp_nist_data.jpg

      I was looking at trying to model the spike using a UDF with temperature range from 300K to 1000K .I Took data points from the NIST website and generated piece-wise functions for multiple temperature ranges ( as depicted in the code).
      Divergence using UDF for specific Heat-cp_temp_contour.jpg


      While I believe the UDF gets loaded properly into fluent( using interpreted , it loads without showing any error), the residuals of continuity tend to blow up ( --> 1e+10 etc) while the energy residual (1e+0) and i get all sorts of temperature spots in the domain(As depicted in the picture).

      CODE:

      #include "udf.h"

      DEFINE_SPECIFIC_HEAT(john_cp, T, Tref, h, yi)

      {

      real cp;



      if (T >= 523 && T <=600)

      cp = 6.84697E+04 + -2.41062E+02*T + 2.28273E-01*T*T;



      else if (T>600 && T <= 630)

      cp = 6.05982E+05 -2.00334E+03*T +1.67297E+00*T*T;



      else if (T>630 && T<= 650)

      cp =8.91902E+06 -2.81935E+04*T+ 2.23004E+01*T*T;



      else if (T>650 && T <= 658)

      cp = 3.34752E+08 -1.02965E+06*T+ 7.91808E+02*T*T;



      else if (T>658 && T <= 660)

      cp = -1.01330E+08+ 3.22934E+05*T-2.56559E+02*T*T;



      else if (T>660 && T <= 668)

      cp =2.60837E+08 + -7.81911E+05*T+ 5.86025E+02*T*T;



      else if (T>668 && T <= 700)

      cp = 4.94026E+06 -1.41350E+04*T+ 1.01250E+01*T*T;



      else if (T>700 && T <= 850)

      cp = 1.18004E+06 -4.36540E+03*T+ 5.40459E+00*T*T -2.23261E-03*T*T*T;

      else

      cp = 3000;



      *h = cp*(T-Tref);

      return cp;

      }


      I was wondering if anyone has faced such an issue.

      p.s: I tried to recreate the Cp plot using the functions in MATLab and it seems to recreate them pretty well.

      I have also tried with coarse and fine mesh and it still gives me such plots.

      Any help or suggestion would be greatly appreciated.



      John Misquith

       

    • Karthik Remella
      Administrator

      Couple of quick questions:

      • does your model run without any issues if you do not use a UDF (and prescribe a constant Cp)? 
      • what is your mesh quality (max skewness or min orthogonal quality)?
    • johnam29
      Subscriber

      Thank you for your reply!

       

      Currently Im using piece-wise polynomials to capture the peak and it works fine without generating any of those spots. Its just that Im not able to accurately capture the highest point and therefore, I want to switch to udfs. Therefore, to answer your qn to the point, Yes it does work well with constant Cp.

      i believe my max skewness was around 0.65-0.7 ish. I tried this out with an even finer mesh and it was still giving an issue. 

      Today i ran the simulation by compiling the code instead of using the interpreter and im still getting those temperature spots.

      Regards

      John

    • Karthik Remella
      Administrator

      This macro works best as a compiled UDF. So, going forward, please compile the code.

      It almost seems like the temperature spots are observed because of the jumps in your Cp value. Are you seeing the correct Cp value based on your temperature range?

      I have another idea. What if you were to use Fluent Expressions instead of the UDF? You should be able to write out conditional statements using expressions. Since all your Cps are analytical expressions, theoretically, you should be able to write out this expression?

      Looking forward to hearing what you find.

      Thanks.

      Karthik

    • johnam29
      Subscriber

      So with help from someone from CFDOnline, I was able to solve this problem

       

      1. Yes, i switched to using Complied method to get my code loaded into AnSYS fluent accurately.

      2. Resolved the 'nmake error' by loading ANSYS fluent from VS Studio v19 terminal prompt

      3.  replaced the enthalpy formula h = Cp(t - Tref) with the integral of the Cp over the interval T to Tref. ( This was the major change which resulted in the temperature spots to vanish).

       

      Regards 

      John Misquith

Viewing 4 reply threads
  • The topic ‘Divergence using UDF for specific Heat (Fluent)’ is closed to new replies.