#include "udf.h"
extern Domain* domain;
DEFINE_ON_DEMAND(demo_calc)
{
float tavg = 0.;
float tmax = 0.;
float tmin = 0.;
float temp,volume,vol_tot;
Thread *t;
cell_t c;
/* Loop over all cells in the domain */
thread_loop_c(t,domain)
{
/* Compute max, min, volume-averaged temperature */
begin_c_loop(c,t)
{
volume = C_VOLUME(c,t); /* get cell volume */
temp = C_T(c,t); /* get cell temperature */
if (temp < tmin || tmin == 0.) tmin = temp;
if (temp > tmax || tmax == 0.) tmax = temp;
vol_tot += volume;
tavg += temp*volume;
}
end_c_loop(c,t)
tavg /= vol_tot;
printf("\n Tmin = %g Tmax = %g Tavg = %g\n",tmin,tmax,tavg);
/* Compute temperature function and store in user-defined memory */
/* (location index 0) */
begin_c_loop(c,t)
{
temp = C_T(c,t);
C_UDMI(c,t,0) = (temp-tmin)/(tmax-tmin);
}
end_c_loop(c,t)
}
}
评论0