CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   How to read from file? (https://www.cfd-online.com/Forums/fluent-udf/132132-how-read-file.html)

blowback March 26, 2014 07:53

How to read from file?
 
Hello,

I'd like to create UDF that assigns over 30 different values contained in one matrix to variable which appears in DEFINE_PROFILE function.

In this example I tried to do this only for 2 different q values. I don't want to do it by hand, because I'd like to have easy possibilites to change q values which are contained in .txt file

After compiling, assigning boundary conditions and performing simulation 0 heat flux values are shown on faces.

#include "udf.h"
#include <math.h>
#include <stdio.h>
float q[2];
FILE *file;
DEFINE_EXECUTE_ON_LOADING(udf, libname)
{
int i;
file = fopen("power.txt", "r");
for (i=0;i<2;i++)
{
fscanf(file, "%g", &q[i]);
}
fclose(file);
}
DEFINE_PROFILE(p11,ft, var)
{
real x[3];
real z;
face_t f;
real q0 = q[0];
begin_f_loop(f,ft)
{
F_CENTROID(x,f,ft);
z = x[2];
F_PROFILE(f,ft,var)= (2/M_PI)*q0*sin(((z-0.287)/0.01)*M_PI);
}
end_f_loop(f,ft)
}
DEFINE_PROFILE(p12,ft, var)
{
real x[3];
real z;
face_t f;
real q0 = q[1];
begin_f_loop(f,ft)
{
F_CENTROID(x,f,ft);
z = x[2];
F_PROFILE(f,ft,var)= (2/M_PI)*q0*sin(((z-0.287)/0.01)*M_PI);
}
end_f_loop(f,ft)
}


All times are GMT -4. The time now is 11:54.