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)

ehooi January 11, 2011 08:10

temperature at a point
 
Hi,
Does anyone know how to write the UDF to calculate the temperature at a point? I know surface monitors allow me to check the temperature at a point. However, the temperature at the particular point is needed to change the boundary condition.

Thank you.


Sincerely,
EH

Sangeeta January 11, 2011 10:31

Quote:

Originally Posted by ehooi (Post 290002)
Hi,
Does anyone know how to write the UDF to calculate the temperature at a point? I know surface monitors allow me to check the temperature at a point. However, the temperature at the particular point is needed to change the boundary condition.

Thank you.


Sincerely,
EH

DO u want to keep cahnging the BC depending on temperature?

ehooi January 11, 2011 10:36

Quote:

Originally Posted by Sangeeta (Post 290019)
DO u want to keep cahnging the BC depending on temperature?

Yes and it is time-dependent. I am hoping to specify the BC to be something like (syntax no accounted):

if (Tpoint < 333)
F_PROFILE(f,t,i)=10000
else
F_PROFILE(f,t,i)=0
end

Kind of like a heater to ensure that the temperature of the domain is always greater than a specified level. I know the coordinates where Tpoint is to be determined but how do I calculate it in UDF.

ComputerGuy January 11, 2011 21:14

ehooi,

Try something like the following.
Code:

DEFINE_PROFILE(heat_flux_profile,t,i)
{
        real thermostat_coordinate[ND_ND];
        real set_point_temperature;
        real heat_flux;
        real lower_bound_x,upper_bound_x;
        real lower_bound_y,upper_bound_y;
        real lower_bound_z,upper_bound_z;
        cell_t c;
        real x,y,z;
        real cutoff_temperature;
       
        heat_flux=10000;
        cutoff_temperature=333.;
       
        lower_bound_x=1.;upper_bound_x=2.;
        lower_bound_y=1.;upper_bound_y=2.;
        lower_bound_z=1.;upper_bound_z=2.;
       
        begin_c_loop(c,t)
        {
                C_CENTROID(thermostat_coordinate,c,t);
               
                x=thermostat_coordinate[0];
                y=thermostat_coordinate[1];
                z=thermostat_coordinate[2];
               
                if(((x>=lower_bound_x)&&(x<=upper_bound_x))&&((y>=lower_bound_y)&&(y<=upper_bound_y))&&((z>=lower_bound_z)&&(z<=upper_bound_z))
                {
                        if(C_T(c,t)<=cutoff_temperature)
                        {
                                F_PROFILE(c,t,i)=heat_flux;
                        }
                }
               
        }
}

I haven't checked this code for syntax, but the logic is there.

See the following thread for time dependent flow:
Time-dependent flows

You can modify the code I've posted to account for transient heat flux, temperature cutoffs, etc. You'll also need to modify the lower and upper bounds on the x,y, and z coordinates.

ComputerGuy

ehooi January 12, 2011 03:26

Quote:

Originally Posted by ComputerGuy (Post 290059)
ehooi,

Try something like the following.
Code:

DEFINE_PROFILE(heat_flux_profile,t,i)
{
    real thermostat_coordinate[ND_ND];
    real set_point_temperature;
    real heat_flux;
    real lower_bound_x,upper_bound_x;
    real lower_bound_y,upper_bound_y;
    real lower_bound_z,upper_bound_z;
    cell_t c;
    real x,y,z;
    real cutoff_temperature;
 
    heat_flux=10000;
    cutoff_temperature=333.;
 
    lower_bound_x=1.;upper_bound_x=2.;
    lower_bound_y=1.;upper_bound_y=2.;
    lower_bound_z=1.;upper_bound_z=2.;
 
    begin_c_loop(c,t)
    {
        C_CENTROID(thermostat_coordinate,c,t);
 
        x=thermostat_coordinate[0];
        y=thermostat_coordinate[1];
        z=thermostat_coordinate[2];
 
        if(((x>=lower_bound_x)&&(x<=upper_bound_x))&&((y>=lower_bound_y)&&(y<=upper_bound_y))&&((z>=lower_bound_z)&&(z<=upper_bound_z))
        {
            if(C_T(c,t)<=cutoff_temperature)
            {
                F_PROFILE(c,t,i)=heat_flux;
            }
        }
 
    }
}

I haven't checked this code for syntax, but the logic is there.

See the following thread for time dependent flow:
Time-dependent flows

You can modify the code I've posted to account for transient heat flux, temperature cutoffs, etc. You'll also need to modify the lower and upper bounds on the x,y, and z coordinates.

ComputerGuy

Hello ComputerGuy,
Thank you very much. This is very helpful. Let me see if I interpret this correctly. The 'begin_c_loop' basically calculates the centroid of every cell in my domain.

The upper and lower bounds of x, y and z basically defines the limits or the region where the specific point which I want to calculate the temperature is located.

So when the x, y and z is within the bounds, and when the temperature is less than the cutoff temperature, F_PROFILE specifies the required heat flux.

In this case, I guess set_point_temperature is redundant?

Am I right?

Thank you again for your guidance.

ehooi January 12, 2011 06:05

Hi ComputerGuy,
I have tried ammending the codes that you have shown earlier and I came up with this:

Code:


#include "udf.h"
/* Obtain the mean temperature at the location of thermocouple */
/* Thermocouple located at coordinates (x,y,z) = (0.275,0.27,-.900) */
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,nt;
 
cell_t c;
Domain *d;
Thread *t;
d = Get_Domain(1);
 
 
xmin=0.273;
xmax=0.277;
ymin=0.268;
ymax=0.272;
zmin=-0.898;
zmax=-0.90;
/* Begin loop to determine the temperature at the centroid of cells near the thermocouple */
 
thread_loop_c(t,d)
{
nt=0.0;
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) and (x <= xmax)) /* line 49 */
{
if ((y >= ymin) and (y <= ymax))
{
if ((z >= zmin) and (z <= zmax))
{
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
}
DEFINE_PROFILE(heater_bc,t,i)
{
real cutoff_temperature;
real heater_on; /* line 71 */
real heater_off; /* line 74 */
 
face_t f; /* line 74 */
cutoff_temperature=333.0;
heater_on=15923.5;
heater_off=0.0;
if (thermosensor_temperature<=cutoff_temperature)
{
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = heater_on
}
end_f_loop(f,t)
}
else
{
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = heater_off
}
end_f_loop
}
}

Since I am intending to check the value at the end of each time step, I have used the DEFINE_EXECUTE_AT_END. Is that correct?

After interpreting this code, I obtain the following error:
cpp -I"C:\PROGRA~1\ANSYSI~1\v121\fluent\fluent12.1.4/src" -I"C:\PROGRA~1\ANSYSI~1\v121\fluent\fluent12.1.4/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v121\fluent\fluent12.1.4/client/src" -I"C:\PROGRA~1\ANSYSI~1\v121\fluent\fluent12.1.4/multiport/src" -I. -DUDF
ONFIG_H="<C:/Users/EHOOI/AppData/Local/Temp/udfconfig-node1.h>" "C:/Users/EHOOI/AppData/Local/Temp/udfex1.c.1.c"
Error: C:/Users/EHOOI/AppData/Local/Temp/udfex1.c.1.c: line 49: parse error.
Error: C:/Users/EHOOI/AppData/Local/Temp/udfex1.c.1.c: line 71: parse error.
Error: C:/Users/EHOOI/AppData/Local/Temp/udfex1.c.1.c: line 72: parse error.
Error: C:/Users/EHOOI/AppData/Local/Temp/udfex1.c.1.c: line 74: parse error.
Error: C:/Users/EHOOI/AppData/Local/Temp/udfex1.c.1.c: line 76: cutoff_temperature: undeclared variable

The lines where the error are located are pointed out as comments in the code. I cant detect the error that is mentioned.

Could you please help me with this?

Thank you.

ComputerGuy January 12, 2011 07:28

First, use && instead of "and" in your logic. Not sure if "and" actually works (I get my languages jumbled).

Next, in the following lines:
thermosensor_temperature=thermosensor_temperature + C_T(c,t) /* get thermocouple temperature */
nt=nt+1.0 /* count number */

You need semicolons after each line, before the comment. Additionally, why are you adding a thermosensor temperature to the cell temperature? Perhaps I'm confused about the logic, but wouldn't it just be
thermosensor_temp=C_T(c,t);?

Try and fix those things and see how it goes.

ComputerGuy

ehooi January 12, 2011 07:39

I add them up and divide it by the number of added values to obtain the average. My logic behind it is that there may be more than one cell within the lower and upper bounds specified (I may not be right in this assumption). Hence, I calculate the average of it.

Thanks for your pointers. I will try them out now. Can't believe I overlooked the semi-colons there :o

ehooi January 12, 2011 08:05

Hi ComputerGuy,
I have successfully interpreted the code. Couldn;t run it at the moment because my model still needs some tweaking but the successful interpretation of the code is a good sign.

In case anyone else is interested, the code is listed here:
Code:


#include "udf.h"
/* Obtain the mean temperature at the location of thermocouple */
/* Thermocouple located at coordinates (x,y,z) = (0.275,0.27,-.900) */
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,nt;
 
 cell_t c;
 Domain *d;
 Thread *t;
 d = Get_Domain(1);

 
 xmin=0.273;
 xmax=0.277;
 ymin=0.268;
 ymax=0.272;
 zmin=-0.898;
 zmax=-0.90;
 /* Begin loop to determine the temperature at the centroid of cells near the thermocouple */
 
 thread_loop_c(t,d)
 {
 nt=0.0;
 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))
    {
    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;
}
DEFINE_PROFILE(heater_bc,t,i)
{
 real cutoff_temperature;
 real thermosensor_temperature;
 real heater_on;
 real heater_off;
 
 face_t f;
 cutoff_temperature=333.0;
 
 heater_off = 0.0;
 heater_on = 15923.5;
 if (thermosensor_temperature<=cutoff_temperature)
 {
  begin_f_loop(f,t)
  {
  F_PROFILE(f,t,i) = heater_on;
  }
  end_f_loop(f,t)
 }
 else
 {
  begin_f_loop(f,t)
  {
  F_PROFILE(f,t,i) = heater_off;
  }
  end_f_loop(f,t)
 }
}

Thank you

ComputerGuy January 12, 2011 21:02

Good job -- glad I could help. I understand the volume averaging scheme on temperature; I just didn't see the piece of code where you divided by the cell count.

Thanks for sharing your final code with us.

ComputerGuy

ehooi January 13, 2011 10:57

Hi ComputerGuy,
In the code that I have written, there are two define macros, DEFINE_ADJUST and DEFINE_PROFILE. In DEFINE_ADJUST, I calculated the value for the variable thermosensor_temperature and in DEFINE_PROFILE, I use the value of thermosensor_temperature.

Can I know if the value of thermosensor_temperature calculated in DEFINE_ADJUST will be automatically stored such that the macro DEFINE_PROFILE can access it or do I have to write some code to store it?

Thanks.


EH

ComputerGuy January 14, 2011 18:11

It won't be automatically stored as written. You can simply write the value to a user-defined memory location (look up: C_UDMI).

ComputerGuy

ahvz October 28, 2013 08:49

I tried to used the below code but I have faced with "warning"

warning C4700: uninitialized local variable 'thermosensor_temperature' used
warning C4700: uninitialized local variable 'thermosensor_temperature' used

how to solve this warning? any helps ?

what is the reason of this kind of warnings ?




Code:

/***********************************************************************
udfexample.c
UDF for specifying the heater
 ************************************************************************/


#include "udf.h"
/* Obtain the mean temperature at the location of thermocouple */
/* Thermocouple located at coordinates (x,y,z) = (-0.24,0.185,0.26) */
DEFINE_EXECUTE_AT_END(tsensor)  /* DEFINE_EXECUTE_AT_END is a general-purpose macro that is executed at the end of an iteration in a steady state run, or at the end of a time step in a transient run. You can use DEFINE_EXECUTE_AT_END when you want to calculate flow quantities at these particular times. Note that you do not have to specify whether your execute-at-end UDF gets executed at the end of a time step or the end of an iteration. This is done automatically when you select the steady or unsteady time method in your ANSYS FLUENT model*/
{
 real thermosensor_coordinate[ND_ND];
 real thermosensor_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.22;
 xmax=-0.26;
 ymin=0.183;
 ymax=0.188;
 zmin=0.25;
 zmax=0.27;
 /* Begin loop to determine the temperature at the centroid of cells near the thermocouple */
 thread_loop_c(t,d)
 {
 nt=0.0;
 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))
    {
    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;
}
DEFINE_PROFILE(heater_bc,t,i)
{
 real cutoff_temperature;
 real thermosensor_temperature;
 real heater_on;
 real heater_off;
 
 face_t f;
 cutoff_temperature=295.15;
 
 heater_off = 0.0;
 heater_on = 22500;
 if (thermosensor_temperature<=cutoff_temperature)
 {
  begin_f_loop(f,t)
  {
  F_PROFILE(f,t,i) = heater_on;
  }
  end_f_loop(f,t)
 }
 else
 {
  begin_f_loop(f,t)
  {
  F_PROFILE(f,t,i) = heater_off;
  }
  end_f_loop(f,t)
 }
}


pakk January 22, 2015 03:24

Quote:

Originally Posted by ahvz (Post 459425)
I tried to used the below code but I have faced with "warning"

warning C4700: uninitialized local variable 'thermosensor_temperature' used
warning C4700: uninitialized local variable 'thermosensor_temperature' used

how to solve this warning? any helps ?

what is the reason of this kind of warnings ?

The variable is not initialized when you use it. It does not have a value yet, but at a certain line in your code you say it should increase its value. The solution: initialize the variable:
Code:

real thermosensor_temperature = 0.0;

hariswch2 September 15, 2015 05:15

how to assign temp from first part of program to second part
 
Quote:

Originally Posted by ehooi (Post 290141)
Hi ComputerGuy,
I have successfully interpreted the code. Couldn;t run it at the moment because my model still needs some tweaking but the successful interpretation of the code is a good sign.

In case anyone else is interested, the code is listed here:
Code:


#include "udf.h"
/* Obtain the mean temperature at the location of thermocouple */
/* Thermocouple located at coordinates (x,y,z) = (0.275,0.27,-.900) */
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,nt;
 
 cell_t c;
 Domain *d;
 Thread *t;
 d = Get_Domain(1);

 
 xmin=0.273;
 xmax=0.277;
 ymin=0.268;
 ymax=0.272;
 zmin=-0.898;
 zmax=-0.90;
 /* Begin loop to determine the temperature at the centroid of cells near the thermocouple */
 
 thread_loop_c(t,d)
 {
 nt=0.0;
 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))
    {
    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;
}
DEFINE_PROFILE(heater_bc,t,i)
{
 real cutoff_temperature;
 real thermosensor_temperature;
 real heater_on;
 real heater_off;
 
 face_t f;
 cutoff_temperature=333.0;
 
 heater_off = 0.0;
 heater_on = 15923.5;
 if (thermosensor_temperature<=cutoff_temperature)
 {
  begin_f_loop(f,t)
  {
  F_PROFILE(f,t,i) = heater_on;
  }
  end_f_loop(f,t)
 }
 else
 {
  begin_f_loop(f,t)
  {
  F_PROFILE(f,t,i) = heater_off;
  }
  end_f_loop(f,t)
 }
}

Thank you

.................................................. .................................................. .
Hi ehooi,

Thank you very much for sharing the program with us.

I interpreted your program with some modifications but it was showing udf tsensor and udf heater, both are running fine individually.

while combining both as single program, the thermocouple sensor temperature obtained in the first part of program i.e.,udf tsensor is not assigning as input to second part of program i.e., udf heater.

I would like to know how to assign thermocouple temperate form first part of program (output) to second part of program as a input

Thanks in advance

ghost82 September 15, 2015 08:50

Have a look at this post:
http://www.cfd-online.com/Forums/flu...ide-model.html

If I remember well it is an update of this post.

The problem you have is that the variable that is passed to the second block must be defined as global variable.

hariswch2 September 15, 2015 09:24

Quote:

Originally Posted by ghost82 (Post 564080)
Have a look at this post:
http://www.cfd-online.com/Forums/flu...ide-model.html

If I remember well it is an update of this post.

The problem you have is that the variable that is passed to the second block must be defined as global variable.

.................................................. .................................................. .
Thank u very much for reply ghost82

I defined as you told but still heater is in on position only after crossing higher limit also.

below is my code....

#include "udf.h"
real p;
/* 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;
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.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);
p = thermosensor_temperature;
}


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

cutoff_temperature = 301.0;

if (p <= cutoff_temperature)
{
source = 327680;
}

else
{
source = 0;
}
return source;
}



I dont know what might be the problem

can u plz help me

Thanks in advance

ghost82 September 15, 2015 09:30

Look at udf in message #4 of the other post.
I think you have to reinizialize also "p" in the first block (just after of before initializing nt, for example), what I'm calling thermosensor_temperature
Code:

thermosensor_temperature=0.0;
If it doesn't work, adapt your udf to that of message #4, because another difference is that thermosensor_temperature is initialized in first block, but I was passing its value to thermosensor_temperature1 before going to the second block.

hariswch2 September 15, 2015 10:02

Quote:

Originally Posted by ghost82 (Post 564087)
Look at udf in message #4 of the other post.
I think you have to reinizialize also "p" in the first block (just after of before initializing nt, for example), what I'm calling thermosensor_temperature
Code:

thermosensor_temperature=0.0;
If it doesn't work, adapt your udf to that of message #4, because another difference is that thermosensor_temperature is initialized in first block, but I was passing its value to thermosensor_temperature1 before going to the second block.

.................................................. ...............................................

As you told, "p" i defined as global variable and reinitialized as p=0 before the command nt=0 but still the temperature is increasing mode only( heater on only)

i tried to print "p" values in second block but it was showing zero and same "p" value i printed in first block, it was showing correct value.

the problem what i thought was '"p" value is not assigning from first block to second block, even though it is global variable.

Can u plz identify the problem....

ghost82 September 15, 2015 10:08

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?

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 03:37.