CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Udf function average temp inlet - outlet (https://www.cfd-online.com/Forums/fluent/85807-udf-function-average-temp-inlet-outlet.html)

 erodv March 7, 2011 15:33

SOLVED:Udf function average temp inlet - outlet

Hello,

I would appreciate if somebody take a look in the UDF and give me some advices. I am trying to get the average temperature at the outlet of a pipe, and after some manipulations use it in the pressure inlet of the next time step. It compiles and the simulation runs up to the first time step. It starts with reversed flow then just after the first time step prints Temperature limited to 1 in the domain 1. Tavg prints -nan.

Thanks

DEFINE_EXECUTE_AT_END(Temp_inlet)
{
Domain *d;
real Temp_t;
real area;
real area_tot;
real tavg;
real A[ND_ND];
face_t f;
d=Get_Domain(1);

begin_f_loop(f,t)
{
area = F_AREA(A,f,t);
Temp_t += F_T(f,t);
area_tot += area;
tavg += Temp_t*area;
}
end_f_loop(f,t)
tavg /= area_tot;
tavg_tot1=tavg;
printf("\n Tavg = %f\n",tavg_tot1); /*output -nan*/
}

DEFINE_PROFILE(Temp_inlet,t,i)
{
face_t f;
real time;
real current_time;
time=CURRENT_TIMESTEP;
current_time=CURRENT_TIME;

if (current_time >=10.)
{
begin_f_loop(f,t)
{
F_PROFILE(f,t,i)=((fabs(flow_tot)*(tavg_tot-tavg_tot1)*time)/15.)+tavg_tot1;
}
end_f_loop(f,t)
}
else
{
begin_f_loop(f,t)
{
F_PROFILE(f,t,i)=288.16;
}
end_f_loop(f,t)
}
}

 Amir March 7, 2011 16:08

Hi,
I think the problem is in your face loop, substitute this and check. hope that help you:
Quote:
 tavg=0; area_tot=0; begin_f_loop(f,t) { F_AREA(A,f,t); AREA=NV_MAG(A); area_tot += AREA; tavg +=F_T(f,t)*AREA; } end_f_loop(f,t) tavg /= area_tot;

 erodv March 7, 2011 20:54

Solved

Thanks Amir, I did your proposed changes and it worked, this thread has been solved :).

 shzinwoyk November 14, 2016 10:29

Quote:
 Originally Posted by erodv (Post 298340) Thanks Amir, I did your proposed changes and it worked, this thread has been solved :).

Hi,

Could u share correct form of the UDF? I am working on similar problem.

Thx

inlet average temperature udf

hi
this is my code , when i put outlet id in it , it works .
but when i put inlet id in it , it doesn't work .
pls help what should i do .

#include "udf.h"

{
int ID = 9 ;
FILE *output;
real total_temp=0;
real ave_T, T;
int i=0;
face_t face;

{
total_temp = total_temp + T;
i = i+1;
}

ave_T = total_temp / i ;

printf("inlet average of temp : %f\n" , ave_T);

output = fopen("inlet average of temp.txt","a");
fprintf(output, "inlet average of temp: %f\n", ave_T);
fclose(output);
}

 All times are GMT -4. The time now is 06:43.