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/)
-   -   temperature at a point (https://www.cfd-online.com/Forums/fluent-udf/83785-temperature-point.html)

hariswch2 September 16, 2015 00:50

Quote:

Originally Posted by ghost82 (Post 564097)
Try to declare nt as real, not integer, maybe the division returns 0 if nt is defined as int.
can you also change name p to something else?maybe 'p' is reserved?

Below shown was modified program as suggested but still heater is not cutting off...it is still on position only
.................................................. .................................................. ....
#include "udf.h"
real thermosensor=300.0;

/* Obtain the mean temperature at the location of thermocouple */
/* Thermocouple located at coordinates (x,y,z) = (0.115,0.135,0.25) */

DEFINE_EXECUTE_AT_END(tsensor) /* exectued at the end of time step in trasient and iteration in steadddy state*/
{
real thermosensor_coordinate[ND_ND];
real thermosensor_temperature;
real xmin;
real xmax;
real ymin;
real ymax;
real zmin;
real zmax;
real x,y,z;
real nt;

cell_t c;
Domain *d;
Thread *t;
d = Get_Domain(1);


xmin=0.115;
xmax=0.135;
ymin=0.115;
ymax=0.135;
zmin=0.243;
zmax=0.250;

/* Begin loop to determine the temperature at the centroid of cells near the thermocouple */
nt=0;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_CENTROID(thermosensor_coordinate,c,t);

x=thermosensor_coordinate[0];
y=thermosensor_coordinate[1];
z=thermosensor_coordinate[2];

if ((x >= xmin) && (x <= xmax))
{
if ((y >= ymin) && (y <= ymax))
{
if ((z >= zmin) && (z <= zmax))
{
printf("X-cord = %f\n",x);
printf("y-cord = %f\n",y);
printf("Z-cord = %f\n",z);
thermosensor_temperature=thermosensor_temperature + C_T(c,t); /* get thermocouple temperature */
printf("thermosensor_temperature = %f\n",thermosensor_temperature);
nt=nt+1.0; /* count number */
printf("value_nt = %d\n",nt);
}
}
}
}
end_c_loop(c,t)
}
thermosensor_temperature=thermosensor_temperature/nt;
printf("final_temp = %f\n",thermosensor_temperature);
thermosensor = thermosensor_temperature;
}


DEFINE_SOURCE(heater,c,t,ds,eqn)
{
real cutoff_temperature;
real source;

cutoff_temperature = 301.0;

if (thermosensor <= cutoff_temperature)
{
source = 327680;
return source;
}

else
{
source = 0;
return source;
}

}
.................................................. .................................................. ......

I am interpreting the whole program using define>user-defined>functions>interpreted...it was successful without errors.

now it was showing two things,one is udf tsensor and second one is udf heater

I got confusion here regarding two things,

1. for function hook option..i selected both udf tensor and udf heater as execute at end

2. In cell zone conditions, selected udf heater for required domain

while doing above things, i got the below error..
chip-exec: heater: wrong return type: void udf function expected

Would like to know the above interpretation procedure was correct or any suggestions

Thanks in advance

hariswch2 September 16, 2015 01:23

now i modified interpretation procedure as follows

1. for function hook option..selected udf tensor only as execute at end

2. In cell zone conditions, selected udf heater for required component

Error "chip-exec: heater: wrong return type: void udf function expected" was not showing..it is working fine...but still. the temperature is keep on increasing mode only i.e., heater on only......it was not getting off after cutoff temp also...

Plz give suggestions....

Thanks in advance.....

Johnr May 26, 2016 11:52

UDMs
 
I have the same problem...How can I access the temp calculated in the first macro for using it in the second macro. Please tell....

I am new to udfs and need the solution URGENTLY!!

hariswch2 May 26, 2016 11:57

Hi johnr..

Below was the working program for 3 cycles of heater on and off using IF condition
.....................
#include "udf.h"
real thermosensor_temperature1;
real x;
/* Obtain the mean temperature at the location of thermocouple */
/* Thermocouple located at coordinates (x,y,z) = (0.115,0.135,0.25) */
DEFINE_EXECUTE_AT_END(tsensor)
{
real thermosensor_coordinate[ND_ND];
real thermosensor_temperature;

real xmin;
real xmax;
real ymin;
real ymax;
real zmin;
real zmax;
real x,y,z;
int nt;

cell_t c;
Domain *d;
Thread *t;
d = Get_Domain(1);


xmin=0.115;
xmax=0.135;
ymin=0.115;
ymax=0.135;
zmin=0.246;
zmax=0.250;

thermosensor_temperature=0.0;
/*thermosensor_temperature1=300.0;*/

/* Begin loop to determine the temperature at the centroid of cells near the thermocouple */
nt=0;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_CENTROID(thermosensor_coordinate,c,t);

x=thermosensor_coordinate[0];
y=thermosensor_coordinate[1];
z=thermosensor_coordinate[2];

if ((x >= xmin) && (x <= xmax))
{
if ((y >= ymin) && (y <= ymax))
{
if ((z >= zmin) && (z <= zmax))
{
/*printf("X-cord = %f\n",x);*/
/*printf("y-cord = %f\n",y);*/
/*printf("Z-cord = %f\n",z);*/
thermosensor_temperature=thermosensor_temperature + C_T(c,t); /* get thermocouple temperature */
nt=nt+1.0; /* count number */
}
}
}
}
end_c_loop(c,t)
}
thermosensor_temperature=thermosensor_temperature/nt;
thermosensor_temperature1=thermosensor_temperature ;
printf("final_temp = %f\n",thermosensor_temperature1);
}

DEFINE_SOURCE(heater,c,t,ds,eqn)
{
real source;

if(thermosensor_temperature1 == 300.0)
{
x=1.0;
if (x == 1.0)
{
if(thermosensor_temperature1>=300.0)
{
x=2.0;
source = 327680;
}
}
}
else if (x == 2.0)
{
if(thermosensor_temperature1>=300.0 && thermosensor_temperature1<=305.0)
{
source = 327680;
}
else
{
x=3.0;
source = 0;
}
}
else if (x == 3.0)
{
if(thermosensor_temperature1>=305.0 && thermosensor_temperature1<=306.0)
{
source = 0;
}
else if(thermosensor_temperature1>=302.0 && thermosensor_temperature1<=305.0)
{
source = 0;
}
else
{
x=4.0;
source = 327680;
}
}
else if (x == 4.0)
{
if(thermosensor_temperature1>=300.0 && thermosensor_temperature1<=305.0)
{
source = 327680;
}
else
{
x=5.0;
source = 0;
}
}
else if (x == 5.0)
{
if(thermosensor_temperature1>=305.0 && thermosensor_temperature1<=306.0)
{
source = 0;
}
else if(thermosensor_temperature1>=302.0 && thermosensor_temperature1<=305.0)
{
source = 0;
}
else
{
x=6.0;
source = 327680;
}
}
else if(x == 6.0)
{
if(thermosensor_temperature1>=300.0 && thermosensor_temperature1<=305.0)
{
source = 327680;
}
else
{
x=7.0;
source = 0;
}
}
else if(x == 7.0)
{
if(thermosensor_temperature1>=305.0 && thermosensor_temperature1<=306.0)
{
source = 0;
}
else if(thermosensor_temperature1>=302.0 && thermosensor_temperature1<=305.0)
{
source = 0;
}
else
{
x=8.0;
source = 327680;
}
}
else
{
if(thermosensor_temperature1>=300.0 && thermosensor_temperature1<=305.0)
{
source = 327680;
}
else
{
x=9.0;
source = 0;
}
}
return source;
}
.................................................. .................
Hope it will be useful to you...

Any queries let me know..............

Johnr May 26, 2016 12:12

UDMs
 
Thanks hariswch2,

But the variable thermosensor_temperature1 is not accessible in DEFINE_SOURCE. i.e. whatever change has happened in the value of thermosensor_temperature1, is not carried in the DEFINE_SOURCE macro.

`e` May 26, 2016 19:14

Quote:

Originally Posted by Johnr (Post 601968)
But the variable thermosensor_temperature1 is not accessible in DEFINE_SOURCE. i.e. whatever change has happened in the value of thermosensor_temperature1, is not carried in the DEFINE_SOURCE macro.

If you define thermosensor_temperature1 outside of the DEFINE_SOURCE and other macros then this variable is global and accessible throughout the compiled UDF. hariswch2's code includes this declaration. Ensure you are not re-declaring or re-initialising the variable within other macros.

hariswch2 May 27, 2016 00:18

I support Mr "e" reply..thermosensor_temperature1 is declared as global variable, so it carries all over the program

Johnr May 27, 2016 01:07

UDFs
 
Hi,
yes i know, that being a global variable it should be accessible in every macro.
below is my code-

#include "udf.h"
real outlet_temperature1;


/* Obtain the mean temperature at the outlet location */
/* outlet point located at coordinates (x,y,z) = (0.254085,0.130187,0.00226474) */
DEFINE_EXECUTE_AT_END(toutlet)
{
real outlet_coordinate[ND_ND];
real outlet_temperature;
real xmin;
real xmax;
real ymin;
real ymax;
real zmin;
real zmax;
real x,y,z,nt;

cell_t c;
Domain *d;
Thread *t;
d = Get_Domain(1);


xmin=0.253;
xmax=0.255;
ymin=0.130;
ymax=0.132;
zmin=0.0022;
zmax=0.0023;
outlet_temperature=0.0;
nt=0.0;
/* Begin loop to determine the temperature at the centroid of cells near the outlet location */

thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_CENTROID(outlet_coordinate,c,t);

x=outlet_coordinate[0];
y=outlet_coordinate[1];
z=outlet_coordinate[2];


if ((x >= xmin) && (x <= xmax))
{
if ((y >= ymin) && (y <= ymax))
{
if ((z >= zmin) && (z <= zmax))
{
outlet_temperature=outlet_temperature + C_T(c,t); /* get outlet temperature */
nt=nt+1.0; /* count number */
}
}
}
}
end_c_loop(c,t)
}
outlet_temperature=outlet_temperature/nt;
outlet_temperature1=outlet_temperature;


}


DEFINE_SOURCE(xmom_source,c,t,dS,eqn)
{
real source;

if (outlet_temperature1<=296)
{
source=-113013699.0;

}
else
{
source=0.0;
}

dS[eqn]=0.0;
return source;
}
__________________________________________________ _____




Now I have taken a 2D case in with the x momentum source term is regulated by the temperature at a particular location in the domain.


But the code is not working as desired. The source is having 0.0 value throughout the time, even if the temperature of the location went below 296.

The initial patched temperature is 298.

Please help....

`e` May 27, 2016 04:28

First, check if you're getting the correct average temperature at outlet and if this value is being passed through to the source macro. Use the Message() function, for example:

Code:

...
outlet_temperature1 = outlet_temperature;
Message("outlet_temperature1 = %e\n",outlet_temperature1);
}

Code:

DEFINE_SOURCE(xmom_source,c,t,dS,eqn)
{
        real source;

        Message("outlet_temperature1 from DEFINE_SOURCE = %e\n",outlet_temperature1);

        if (outlet_temperature1<=296)
        {
                source=-113013699.0;
        }
        else
        {
                source=0.0;
        }

        Message("source from DEFINE_SOURCE = %e\n",source);

        dS[eqn]=0.0;
        return source;
}

Note: use a trailing dot on real values to avoid erroneous type casting. You were comparing a real value with an integer:

Code:

if (outlet_temperature1<=296.)

Johnr May 27, 2016 11:20

UDfs
 
Hi 'e',

Thanks for your reply...

I am getting this message for every iteration,

outlet_temperature1 =-1.#IND00e+00
outlet_temperature1 from DEFINE_SOURCE = -1.#IND00e+00
source from DEFINE_SOURCE = 0.000000e+00

I think the Execute_at_end macro is not calculating the outlet temperature correctly....and i am not getting a hint to what should i do??

Johnr May 27, 2016 12:26

UDFs
 
I have increased the dimension ranges i.e. xmin, xmax...etc and now it is calculating the temperatures correctly....
And also the source is working properly...

Thank you so much...without all the help it would not be easy!

`e` May 27, 2016 17:47

You could loop over the boundary faces on the outlet surface to find the average outlet temperature (example code). Then, you only need to specify the outlet boundary, rather than the tedious cell coordinates:

Code:

t=Lookup_Thread(d,11); // 11 is the outlet boundary ID (from GUI under boundary conditions)

Johnr June 5, 2016 15:35

Fixed Velocity in cell zone
 
Hi,
I am trying to fix the axial velocity in a cell zone but getting error of pressure divergence. I have tried everything but can't solve the problem.

I am doing a 3D analysis of flow in two tanks connected by two pipes. One pipe has this small cylindrical cell zone(made by slicing operation) in which i am trying to fix the velocity. Putting a x momentum source term is working perfectly fine though.

Please help!


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