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.

how to write conditional source UDF?

    • suraj9735
      Subscriber

      #include "udf.h"


      DEFINE_SOURCE(my_heat_source, c, t, dS, eqn)


      {


      real t = CURRENT_TIME; 


      real temp;


      real source; 


      temp = C_T(cell, thread);


      dS[eqn] = 0;       


      if (temp <= 453.)     /* If the temperature is low, Cartridge heater ON */


      source = 750000;


      else


      source = 0;     /* Otherwise, Cartridge Heater OFF */


      return source;


      }



      I get error with this UDF. Could you please check it!


       
    • Amine Ben Hadj Ali
      Ansys Employee
      As ANSYS stuff debugging UDF is not our task even for commercial customers. But your UDF is wrong: wrong thread assigned (t is the thread of cells passed by the udf) and the cell index is wrong. Refer to the manual which contains several working examples.
    • suraj9735
      Subscriber

      Thanks a lot!


      Your little hint made my day!


      I have changed little in UDF and it's working now....

    • suraj9735
      Subscriber

      /**************************************************************/


      /* User-Defined Functions for temperature-dependent source */


      /* FLUENT 19.0 */


      /**************************************************************/


      #include "udf.h"


      DEFINE_SOURCE(my_heat_source, c, t, dS, eqn)


      {


      real temp;


      real source;


      temp = C_T(c, t);


      if (temp <= 453.)     /* If the temperature is low, Cartridge heater ON */


      source = 31830988.62;


      else source = 0;   /* Otherwise, Cartridge Heater OFF */


      dS[eqn] = 0;


      return source;


      }


       


       

    • suraj9735
      Subscriber

      Now I have another issue with this UDF.


      With current UDF, The problem is some of cells of heater cell zones are giving power and some of them are not. But I want all cells of heater must be ON or OFF simultaneously according to the data of maximum temperature of Cavity surface (It's a interested area of my model).


      I want to put a sensor on cavity surface of my heating plate. For that I need to access the data of maximum surface temperature of cavity surface and use that output in UDF to decide my heater (All cells of heater on or off simultaneously) should ON or OFF.


       


      How can I do that? Do I need to use user defined memory/scalar to store the maximum surface temperature data and use in UDF?

    • Amine Ben Hadj Ali
      Ansys Employee

      In a Adjust you check for the max. temperature store it and use it (directly or via setting a flag to TRUE: condition fulfilled) in a DEFINE_SOURCE to turn on/off. For the DEFINE_ADJUST you need to be careful with initialization and global reduction.

    • suraj9735
      Subscriber

      I am new to the UDF.


      I want to store the maximum temperature of a point in DEFINE_ADJUST and directly use in DEFINE_SOURCE. But unable to write the code to store the maximum temperature of a point. Could you please edit my code and send it back as a sample. I also confused about how to hook multiple UDF.


      I tried to store the maximum temperature in ADJUST but it loops all over my domain but I want to check at a particular point.


       



      #include "udf.h"


       


      real T_M=0.;


      DEFINE_ADJUST(my_adjust,d)


      {


      Thread *t;


      /* Maximum Temperature. */


      cell_t c;


      thread_loop_c(t,d)


      {


      begin_c_loop(c,t)


      if(T_M

      T_M=C_T(c,t);


      else


      T_M=T_M;


      end_c_loop(c,t)


      }


      printf("T_M: %gn", T_M);


      }


       


      DEFINE_SOURCE(my_heat_source, c, t, dS, eqn)


       


       


      {


       


      real source; 


       


      if (T_M <= 453.)


           /* If the temperature is low, Cartridge heater ON */


       


      source = 31830988.62;


       


      else


      source = 0;


      /* Otherwise, Cartridge Heater OFF */


       


      dS[eqn] = 0;


      printf("source: %gn", source);


      return source;


       


      }


       



      First, How to create a point in Fluent and find out thread pointer of the particular point and calculate its temperature?


      Please edit my code as a sample, If you can!


      Thanks!

    • Amine Ben Hadj Ali
      Ansys Employee

      It would require a lot of parallelization to get the the Adjust working. Check the manual to have ideas about global reductions. Start with the on demand from help and make it parallel. ANSYS Staff do not even debug or write UDF's for non academic  customers 

    • suraj9735
      Subscriber

      In a Adjust you check for the max. temperature store it and use it (directly or via setting a flag to TRUE: condition fulfilled) in a DEFINE_SOURCE to turn on/off. For the DEFINE_ADJUST you need to be careful with initialization and global reduction.



      In this post as you said to store the current temp. of a vertex and use it in If Else statement. So what's wrong with this concept. In my new UDF, I just loop over all the domain because I don't know how to get a temp. of a particular vertex. This is completely new bugs for me...


      1) Parallelization in UDF.


      2) Global Reduction.


      Could you please explain more why I need these kinds of stuff!, While I just want to find the temp. of a point.

    • Amine Ben Hadj Ali
      Ansys Employee
      Global reduction are required to reduce values if every more to a single value which might be communicated to the other nodes and just process. It is required for cases like looking into average values or looking into extreme values across the partitions.
Viewing 9 reply threads
  • The topic ‘how to write conditional source UDF?’ is closed to new replies.