CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   How to Reference an Adjacent Cell in a UDF ? (

jeff8541 March 8, 2011 10:33

How to Reference an Adjacent Cell in a UDF ?

I am trying to reference the temperature of an adjacent cell and assign the temperature of that cell to another cell.

Here is a basic overview of what I am doing:

A box is surrounded by another larger solid. A temp gradient in the solids are created by a fluid flowing past the larger solid. The flowing fluid temperature is based off a sine function. When the fluid temp is above a specific value the interior box walls should be a constant temp. When the fluid temp drops back below the specific value, the box walls should no longer be a constant temp, they should equalize to the surrounding solid temp.

1) assign a constant temperature to the faces of the box for a period of time when the fluid temp is above Tactivate.

2) when the surrounding fluid temp drops below Tactivate, I want the face temp of the box to no longer be at a constant temp. The box temp should essentually equalize to the surrounding solid temp.

I tried to set the temperature of the box equal to the temperature of the adjacent cells outside the box. The idea is that the cells adjacent to the face will be affected by the surrounding solid and the interior box will slowly re-establish equilibrium.

The UDF will interpret, but the setup closes when I try to calculate.

Here's some of the code:

DEFINE_PROFILE(box_temp_step, thread, position)
/** Apply to box edges **/
real t = CURRENT_TIME;
real r[3];
real A = 12.727;
real B = 6.346017;
real D = 15.7;
real E = -1.84;
real airtemp = A*sin(B*t/(365*24*60*60)+E)+D+273.15;
real pi = 3.1415926535897932384626433832795;
real e = 2.718281828182818;
real boxdepth = 1.524;
real Tp = 305.15;
real Tactivate = 284.82;

face_t f;

int adjacent_cell = F_C1(f,thread);
int adjacent_thread = THREAD_T1(thread);
real boxtemp = C_T(adjacent_cell,adjacent_thread);

begin_f_loop(f, thread)
F_CENTROID(r, f, thread);
if (airtemp <= Tactivate) {
F_PROFILE(f,thread,position) = boxtemp;
}else if(airtemp > Tactivate) {
F_PROFILE(f,thread,position) = Tp;

end_f_loop(f, thread)
/** Code should turn the tank on whenever the mean air temperature reaches above 284.82. When the tank is turned on it has a constant temperature of Tp. When the mean air temp drops below 284.82, the tank should turn off and equalize to the surrounding temperature **/

All times are GMT -4. The time now is 22:33.