Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

code won’t print all the temperature values

    • csolanov
      Subscriber

      this code prints me the temperature values on the face boundary of my 2d geometry. I have 17 face id but when it prints it only gives me 8 face id values.

      What can I do to make the code print all the faces temperature values? I'm running fluent in parallel. 

      #include "udf.h"
       
      DEFINE_EXECUTE_AT_END(get_left_boundary_temperatures)
      {
          Domain* d = Get_Domain(1);  // Get the domain
          Thread* t;
          face_t f;
          FILE* fp;
          int i, ID;
          int zone[3] = { 5, 6,7 };
       
          // Open file to write temperatures
          fp = fopen("left_boundary_temperatures2.txt", "w");
          if (fp == NULL)
          {
              Message("Error opening file for writing temperatures.\n");
              return;
          }
       
          for (i = 0; i < 3; i++) {  // Loop over relevant zones (left side)
              ID = zone[i];
              t = Lookup_Thread(d, ID);
       
              // Loop through all threads
              thread_loop_f(t, d)
              {
                  // Check if the thread is a boundary thread
                  if (BOUNDARY_FACE_THREAD_P(t))
                  {
                      // Check if this is the left boundary thread
                      if (THREAD_ID(t) == zone[i])  // Use actual ID of left boundary
                      {
                          // Loop through faces in the thread
                          begin_f_loop(f, t)
                          {
                              // Get the temperature at the face
                              real temperature = F_T(f, t);
       
       
                              // Write the temperature to the file
                              fprintf(fp, "Face ID: %d, Temperature: %f\n", f, temperature);
                          }
                          end_f_loop(f, t);
                      
                      }
                  }
              }
       
              
              // Close the file
              fclose(fp);
          }
      }
    • Federico
      Ansys Employee

      Hello, 

       When running Fluent in parallel, each compute node will handle a subset of the domain's mesh. Hence, try your UDF on a single CPU (serial) and see if it works. If it does, you will need to parallelize your UDFs. 7.3. Parallelizing Your Serial UDF (ansys.com)

    • csolanov
      Subscriber

      Hi,

       

      Thank you for your reply. Yes I have this code and it runs well in serial. I've tried to paralellize the code and it prints me only values for two boundary faces ID's. This is the code using macros for parallel and debug messages.

      #include "udf.h"
       
      DEFINE_EXECUTE_AT_END(get_left_boundary_temperatures)
      {
      #if !RP_HOST 
          Domain* d = Get_Domain(1);  // Get the domain
          Thread* t;
          face_t f;
      #endif
          FILE* fp;
          int i, ID;
          int zone[3] = { 5, 6, 7 };
       
          // Open file to write temperatures
          fp = fopen("left_boundary_temperatures2.txt", "w");
          if (fp == NULL)
          {
              Message("Error opening file for writing temperatures.\n");
              return;
          }
          Message("File opened successfully.\n");
       
       
          for (i = 0; i < 3; i++) 
          {  // Loop over relevant zones (left side)
              ID = zone[i];
      #if !RP_HOST
              t = Lookup_Thread(d, ID);
       
              // Debug message for thread ID
              Message("Processing Thread ID: %d\n", ID);
       
              // Check if the thread is a boundary thread
              if (BOUNDARY_FACE_THREAD_P(t))
              {
                  Message("Thread ID %d is a boundary thread.\n", ID);  // Debug message
                  // Loop through faces in the thread
                  begin_f_loop(f, t)
                  {
                      // Get the temperature at the face
                      real temperature = F_T(f, t);
       
                      // Write the temperature to the file
                      fprintf(fp, "Thread ID: %d, Face ID: %d, Temperature: %f\n", ID, f, temperature);
       
                      // Debug message for face ID and temperature
                      Message("Thread ID: %d, Face ID: %d, Temperature: %f\n", ID, f, temperature);
                  }
                  end_f_loop(f, t);
              }
       
              else
              {
                  Message("Thread ID %d is NOT a boundary thread.\n", ID);  // Debug message
              }
      #endif   
              PRF_GSYNC();
       
          }
       
         
          // Close the file
          fclose(fp);
          Message("File closed successfully.\n");
      }
Viewing 2 reply threads
  • You must be logged in to reply to this topic.