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 data export? (https://www.cfd-online.com/Forums/fluent-udf/132566-udf-data-export.html)

Topspin April 2, 2014 17:35

UDF for data export?
 
I want to export heat flux from a panel in a flat plate flow where the temperature of the plate varies with time.

The ASCII automatic data export tool in Fluent is nice, but it creates a new file for every timestep.

Is there a way to write a UDF to export the data from every timestep into a single file in this manner?:

time1|temperature1|vector1 of heat flux from cell center
time2|temperature2|vector2 of heat flux from cell center
...
time100|temperature100|vector100 of heat flux from cell center

If there is could I be pointed to a similar example?

macfly April 4, 2014 14:59

Hi,

Try this udf, it works in serial, you will have to modify the code if you work in parallel:

Code:

#include "udf.h"
DEFINE_EXECUTE_AT_END(execute_at_end)
{
FILE *data;
real coord[ND_ND];
real temperature;
real time = CURRENT_TIME;
real timestep = N_TIME;
Domain *d;
Thread *t;
cell_t c;
d = Get_Domain(1);

if (timestep == 1)
    {
    data = fopen("data.txt", "w");
    fprintf(data, "time x y z temperature\n");
    }
else
    data = fopen("data.txt", "a");

//fprintf(data, "current time is %g s\n", time);

thread_loop_c(t,d)
    {
    begin_c_loop(c,t)
          {
          C_CENTROID(coord,c,t);
          temperature = C_T(c,t);
          fprintf(data, "%g %g %g %g %f\n", time, coord[0], coord[1], coord[2], temperature);
          }
    end_c_loop(c,t)
    }
fclose(data);
}



Topspin April 4, 2014 15:52

Thank you I will try it very soon! Right now I've been using Matlab to automate the process of pulling data from each timestep file, but this is a much more elegant solution.


All times are GMT -4. The time now is 08:59.