Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

get the temperature difference from different zones using UDF

    • Selawe97
      Subscriber

      Hello Dears,

      My problem is I am using a UDF code to collect temperature values at different cell zones (solid region and fluid region). I am saving temperature values in arrays (as shown in the code) by looping over them and using them later to get the temperature difference to use it in a formula for the fluid cell zone.

      in (c0_array[n]) and (c1_array[n]) the data was saved as I want in the first two loops

      Code:
      (begin_c_loop(c01,ft1)

      and

      Code:
      begin_c_loop(c02,ft2))

      , and they saved correctly, but when I loop them inside the third loop

      Code:
      (begin_c_loop(c, t))

      to receive the data saved in the first two loops the values of (c0_array[n]) in the third loop are saved correctly as I want, but for (c1_array[n]) the data became chaotic and disorganized! so why do I get something like that?

      knowing both zones are coincided and have the same number of cells. and I have to use the define profile macro.

      Code:
      #include "udf.h"
      #include "mem.h"
      
      DEFINE_PROFILE(Heat_Transfer_Coeff, t, position) 
      	{
          Domain* domain = Get_Domain(1);
          Thread* ft1 = Lookup_Thread(domain, 2);
          Thread* ft2 = Lookup_Thread(domain, 4);
          cell_t c, c01, c02;
          Thread* t01, t02;
          int n;
          real c0_array[10000], c1_array[10000];
      
          n = 0;
          begin_c_loop(c01, ft1) 
      	{
              C_UDMI(c01, ft1, 0) = C_T(c01, ft1);
              c0_array[n] = C_T(c01, ft1);
      		C_UDMI(c01, ft1, 1) = c0_array[n];
              n++;
          }
          end_c_loop(c01, ft1)
      
          n = 0;
          begin_c_loop(c02, ft2) 
      	{
              C_UDMI(c02, ft2, 2) = C_T(c02, ft2);
              c1_array[n] = C_T(c02, ft2);
      		C_UDMI(c02, ft2, 3) = c1_array[n];
              n++;
          }
          end_c_loop(c02, ft2)
      
          n = 0;
          begin_c_loop(c, t)
      	{
              C_UDMI(c, t, 4) = c0_array[n]; // or C_UDMI(c,t,2)= c0_array[n] - c1_array[n]; 
              C_UDMI(c, t, 5) = c1_array[n];
      
              C_PROFILE(c, t, position) = C_UDMI(c, t, 4)-C_UDMI(c, t, 5);
              C_UDMI(c, t, 6) = C_PROFILE(c, t, position);
              n++;
          }
          end_c_loop(c, t)
      }

      Your help is appreciated,
      Thanks

    • Rob
      Forum Moderator

      Why would the cell order be the same for both mesh blocks? Fluent stores and loops over the cell ID, not the location. 

    • Selawe97
      Subscriber

      Dear Thanks for your response, 

      so, can you please guide me on how to store the temperature values of both cell zones and subtract them to get the temperature difference between them?

    • Rob
      Forum Moderator

      Not without breaking the rules that staff must abide by. It's doable but not easy. Start with figuring out where the cells are, and go from there.  

      • Selawe97
        Subscriber

        Thanks

Viewing 3 reply threads
  • The topic ‘get the temperature difference from different zones using UDF’ is closed to new replies.