#include "udf.h"
#include "unsteady.h"
#include "profile.h"
#include <stdio.h>
#include <stdlib.h>
#define MAX_POINTS 4000
#define MAX_TIMESTEPS 997
#define FILENAME "velocity_data.csv"
typedef struct {
double x, y, z;
double u[MAX_TIMESTEPS];
} PointData;
void read_data(PointData* points) {
FILE* file = fopen(FILENAME, "r");
if (file == NULL) {
printf("Error: Could not open file.\n");
exit(1);
}
for (int i = 0; i < MAX_POINTS; i++) {
fscanf(file, "%lf,%lf,%lf", &points[i].x, &points[i].y, &points[i].z);
for (int j = 0; j < MAX_TIMESTEPS; j++) {
fscanf(file, ",%lf", &points[i].u[j]);
}
}
fclose(file);
}
DEFINE_PROFILE(unsteady_velocity, thread, position)
{
real x[ND_ND];
real t = CURRENT_TIME;
int time_step = N_TIME;
PointData points[MAX_POINTS];
face_t f;
read_data(points);
begin_f_loop(f, thread)
{
F_CENTROID(x, f, thread);
for (int i = 0; i < MAX_POINTS; i++) {
if (x[0] == points[i].x && x[1] == points[i].y && x[2] == points[i].z) {
F_PROFILE(f, thread, position) = points[i].u[time_step];
break;
}
}
}
end_f_loop(f, thread)
}