Hello all, I've compiled a udf which reads velocity data with corresponding time stamp from a .csv file using DEFINE_ON_DEMAND macro. Then, I use DEFINE_PROFILE to define an inlet velocity profile at flow-time corresponding to the time stamp. The udf works well on local machine but when I try to run it on a cluster, it crashes giving me the error "Node XX: Process XXXXX: Received signal SIGSEGV." I've tried to modify the udf by inserting "host_to_node_float" once the data is read using the DEFINE_ON_DEMAND udf. But, still the problem exists. Can anyone give me suggestions or ideas ? I'm posting the sample udf here.
"
#include "udf.h"
#define NPts 28 /* Number of data points */
/* Arrays for data */
float tDat[NPts], Uvel[NPts];
static int index = 0;
DEFINE_ON_DEMAND(VelRead)
{
FILE* fp;
char name[500] = "WeatherData.csv";
int i;
fp = fopen(name, "r");
if (fp == NULL)
{
#if RP_HOST
Message("\nError opening file: %s\n\n", name); // Dynamic file name in error message
#endif
return; // Exit if file is not opened
}
else
{
#if RP_HOST
Message("\nSuccessfully opened file: %s\n", name); // Confirm file opened successfully
#endif
}
// Skip the header
if (fscanf(fp, "%*[^\n]\n") == EOF) {
fclose(fp);
#if RP_HOST
Message("\nFailed to skip header in file: %s\n", name);
#endif
return;
}
for (i = 0; i < NPts; i++)
{
if (fscanf(fp, "%f %f \n", &tDat[i], &Uvel[i]) != 2)
{
#if RP_HOST
Message("\nError reading data at line %d in file: %s\n", i + 2, name); // +2 considering the header and 0-index
#endif
break; // Exit if data reading fails
}
#if RP_HOST
// Print each set of values read from the file
Message("Read values at line %d: Time = %f, Uvel = %f\n",
i + 2, tDat[i], Uvel[i]);
#endif
}
fclose(fp); // Always close the file
host_to_node_float(tDat, NPts);
host_to_node_float(Uvel, NPts);
Message("\nFinished reading data from file: %s\n", name);
}
DEFINE_PROFILE(vel_inlet_x, t, var)
{
real x[ND_ND];
real y;
real usX;
real time = CURRENT_TIME;
int newindex = -1;
face_t f;
for (int i = 0; i < NPts; i++) {
if (tDat[i] == time) {
newindex = i;
Message("\n index is %d\n", index);
}
}
if (newindex != -1) {
index = newindex;
}
Message("Uvel is %f ", Uvel[index]);
begin_f_loop(f, t)
{
F_CENTROID(x, f, t);
y = x[1]; // Assuming the y-coordinate is the second component
usX = Uvel[index];
F_PROFILE(f, t, var) = usX;
}
end_f_loop(f, t)
}
"