Ansys Learning Forum › Forums › Discuss Simulation › Fluids › code won’t print all the temperature values › Reply To: code won’t print all the temperature values
September 9, 2024 at 1:42 pm
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");
}