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/)
-   -   UDF for reading velocity values and adding random perturbation (https://www.cfd-online.com/Forums/fluent-udf/178204-udf-reading-velocity-values-adding-random-perturbation.html)

Jomid October 2, 2016 00:46

UDF for reading velocity values and adding random perturbation
 
Hi,

I have a pipe whose inlet has 3312 elements. Inlet velocity at each cell is different than the others so that I have all those velocities. I would like to write a udf which reads all the velocity inlet data given in a text file, with 1 column and 3312 rows, and add them to random numbers generated by a wave equation, available in the same udf. Note that the random number generated by the wave equation varies as time elapses so at different time steps the code adds different numbers to the velocity inlet profile values. Then, the code takes the 3312 new velocities as new inlet velocities for the corresponding cells.
The code can be interpreted and works without any errors. However, I realised that, it is malfunctioning. I guess the problem is that it does not read the 3312 initial inlet profile values or does not add them with the value computed by the wave equation so that the velocity at the inlet is just a small value generated by the wave equation.
Here is my Code:

#include "udf.h"

double Velocity[3312];
FILE *fp;
DEFINE_INIT(read_data, d)
{
int i;
fp=fopen("velocit.txt","r");
for (i=1;i<3312;i++)
{
fscanf(fp,"%ld", &Velocity[i]);
}
fclose(fp);
}

DEFINE_PROFILE(temporal_wave, thread, position)
{
real coord[ND_ND];
real x;
face_t f;
real t = CURRENT_TIME;
int i = t;
begin_f_loop(f, thread)
{
F_CENTROID(coord,f,thread);
x=coord[1];
F_PROFILE(f, thread, position) = Velocity[i] + 0.003*sin(500.*t);
}
end_f_loop(f, thread)
}

Could you please have look at my code and let me know where the potential error(s) is coming from.
Regards
Joe


All times are GMT -4. The time now is 15:56.