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

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");
}