CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Give comment to a heater inside the model

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 1 Post By Sun
  • 2 Post By ghost82
  • 1 Post By ghost82
  • 1 Post By ghost82

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 16, 2014, 11:12
Default Give comment to a heater inside the model
  #1
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
The target of my code is to give command to a heat source. in fact, I gave the coordinate of a node from the model which provides limits of heater on and off modes according to the specific command (when the temperature at node is less than that). but I received error when I use this code:

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


#include "udf.h"
#include "cxndsearch.h"
#include "dpm.h"
#include "math.h"


DEFINE_EXECUTE_AT_END(tsensor)
{
 cell_t c;
 Thread *t;
 CX_Cell_Id *cx_cell;
 real NV_VEC(pt);
 real pos[3];
 real posd[3];
 real xmin=-0.195;
 real ymin=0.0966492; 
 real zmin=0.345; 
 real q=5000000;
 NV_D(pt,=,xmin,ymin,zmin);
 pos[0]=xmin;
 pos[1]=ymin;
 pos[2]=zmin;
SV_locate_point(pos,cx_cell);
 c=cx_cell->ct.c;
t=cx_cell->ct.t;
if (C_T(c,t)<=294.15)
 {
 q=5000000.0;
 }
 else
 {
 q=0.0;
 }
}
DEFINE_SOURCE(heater_generation,c,t,dS,eqn)
{
real source;
source=q;
dS[eqn]=0.0;
return source;
}


error

Error:
received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
4. Report error to your distributor.
Error Object: #f

any helps please?
ahvz is offline   Reply With Quote

Old   October 17, 2014, 03:01
Default
  #2
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 16
Sun is on a distinguished road
My guess is "q" should be defined as a global argument and with the current format DEFINE_SOURCE macro does not have access to the value of q.
ahvz likes this.
Sun is offline   Reply With Quote

Old   October 18, 2014, 08:56
Default
  #3
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
Thanks for your reply,

I just found the below code interesting and seems to be adequate for my purpose (not sure yet). it works! without any error.

however, I do not understand why the command of OFF mode does not work!

in fact, the heater is ON from the beginning of analysis (since the temperature at sensor is lower than that defined for command of the heater ). so it is OK. but, it is still ON when the trumpeter goes upper than cut OFF temperature! do not know why. can you assist me on this trouble please?

Code:
#include "udf.h"
/* Obtain the mean temperature at the location of thermocouple */
/* Thermocouple located at coordinates (x,y,z) = (-0.195,0.0966492,0.345) */
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.195;
 xmax=-0.197;
 ymin=0.0966492;
 ymax=0.0968492;
 zmin=0.345;
 zmax=0.347;
 /* 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=294.15;
 
 heater_off = 0.0;
 heater_on = 5000000.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(f,t)
 }
}
ahvz is offline   Reply With Quote

Old   October 18, 2014, 09:49
Default
  #4
Senior Member
 
ghost82's Avatar
 
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27
ghost82 will become famous soon enough
I would add a "Message" line in the DEFINE_PROFILE macro to print on the console the value of thermosensor_temperature, if its value is correct.
I would move real thermosensor_temperature; right after #include "udf.h" and delete the 2 other declarations inside DEFINE_PROFILE and DEFINE_EXECUTE_AT_END.
That variable needs to be global to be accessed both by DEFINE_PROFILE and DEFINE_EXECUTE_AT_END.
I think you also need to initialize somewhere the thermosensor_temperature, otherwise it could continue increasing.

Try this, I introduced a new global variable that can be accessed by both macros, so to be able to initialize thermosensor_temperature (I don't have tested it)

Code:
#include "udf.h"
real thermosensor_temperature1;
/* Obtain the mean temperature at the location of thermocouple */
/* Thermocouple located at coordinates (x,y,z) = (-0.195,0.0966492,0.345) */
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.195;
 xmax=-0.197;
 ymin=0.0966492;
 ymax=0.0968492;
 zmin=0.345;
 zmax=0.347;
 thermosensor_temperature=0.0;
 nt=0.0;
 /* Begin loop to determine the temperature at the centroid of cells near the thermocouple */
 
 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))
    {
     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;
}
DEFINE_PROFILE(heater_bc,t,i)
{
 real cutoff_temperature;
 real heater_on;
 real heater_off;
 
 face_t f;
 cutoff_temperature=294.15;
 
 heater_off = 0.0;
 heater_on = 5000000.0;
 if (thermosensor_temperature1<=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)
 }
}
Daniele
ahvz and hotin87 like this.
__________________
Google is your friend and the same for the search button!

Last edited by ghost82; October 18, 2014 at 18:53.
ghost82 is offline   Reply With Quote

Old   February 6, 2015, 05:53
Default
  #5
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
Hi,

I tried to use this code but I think the "loop" does not work properly.

at the first time step the heater is ON mode regardless initial temperature. and in the remain steps the heater is OFF. help please.




Code:
#include "udf.h"
/* Obtain the mean temperature at the location of thermocouple */
/* Thermocouple located at coordinates (x,y,z) = (-0.195,0.0966492,0.345) */
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.195;
 xmax=-0.2;
 ymin=0.090;
 ymax=0.091;
 zmin=0.33;
 zmax=0.39;
 /* 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=294.15;
 
 heater_off = 0.0;
 heater_on = 1000.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(f,t)
 }
}
ahvz is offline   Reply With Quote

Old   February 6, 2015, 05:56
Default
  #6
Senior Member
 
ghost82's Avatar
 
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27
ghost82 will become famous soon enough
Quote:
Originally Posted by ahvz View Post
Hi,

I tried to use this code but I think the "loop" does not work properly.

at the first time step the heater is ON mode regardless initial temperature. and in the remain steps the heater is OFF. help please.
Hi,
I saw that you quoted an udf different from the last udf I posted, in which I introduced a global variable.
Can you test udf in message #4?
http://www.cfd-online.com/Forums/flu...tml#post514940

PS: This code must be used in serial
__________________
Google is your friend and the same for the search button!
ghost82 is offline   Reply With Quote

Old   February 6, 2015, 06:07
Default
  #7
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
Thanks for your attentions,

Now I am running the message#4...
ahvz is offline   Reply With Quote

Old   February 6, 2015, 06:19
Default
  #8
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
Still have same problem with UDF message#4 (but I changed the coordinates of sensor placement only) as below:

Code:
#include "udf.h"
real thermosensor_temperature1;
/* Obtain the mean temperature at the location of thermocouple */
/* Thermocouple located at coordinates (x,y,z) = (-0.195,0.0966492,0.345) */
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.195;
 xmax=-0.2;
 ymin=0.090;
 ymax=0.091;
 zmin=0.33;
 zmax=0.39;
 thermosensor_temperature=0.0;
 nt=0.0;
 /* Begin loop to determine the temperature at the centroid of cells near the thermocouple */
 
 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))
    {
     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;
}
DEFINE_PROFILE(heater_bc,t,i)
{
 real cutoff_temperature;
 real heater_on;
 real heater_off;
 
 face_t f;
 cutoff_temperature=294.15;
 
 heater_off = 0.0;
 heater_on = 1000.0;
 if (thermosensor_temperature1<=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)
 }
}

What I expected from this code is to control the heater when the temperature at sensor placement is lower than cut off temeprature the heater treats as ON and when the temperature at sensor placement is above cut off temperature the heater treats as OFF.

I used a graph to monitor the temperature variations of the heater and it shown that the heater is ON at first time step and then OFF till end of analysis...
what is your opinion?

Regards,
ahvz is offline   Reply With Quote

Old   February 6, 2015, 06:21
Default
  #9
Senior Member
 
ghost82's Avatar
 
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27
ghost82 will become famous soon enough
Can you share the cas file?
It will be simpler to me to analyze where are the errors.
If you want you can upload it somewhere and send me a pm to download it.
__________________
Google is your friend and the same for the search button!
ghost82 is offline   Reply With Quote

Old   February 6, 2015, 08:49
Default
  #10
Senior Member
 
ghost82's Avatar
 
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27
ghost82 will become famous soon enough
Hi,
I opened your cas file and I received a warning, and I'm not sure if it's ok or not.
The warning is:
Warning: zone of type interior found between different solids!
Material of cell zone 11 is refm, while material of cell zone 13 is xps.
This will adversely affect the solution.
It is recommended that you fix this issue via the TUI command
/mesh/modify-zones/slit-interior-between-diff-solids

So, I decided to test the udf of message #4 with a simple test case: a cube with an inlet, an outlet and 4 walls (one of them is the heater), and I put the T sensor in the center of the cube.

By initializing the domain with different temperatures I can see if the heater is switching on or off.

Some insights:
DEFINE_EXECUTE_AT_END executes at the end of each time step (not iteration): if you have the cut off temperature (in udf) > initialization temperature (fluent gui) the heater will be however on at first time step (whilst it should be off); this is because thermosensor_temperature1 is not initialized and it has a not determined value for the first time step (it should be a value of zero). To avoid this you can add a line after real thermosensor_temperature1, such as:

if you want the heater off for the first time step:
Code:
#include "udf.h"
real thermosensor_temperature1;
thermosensor_temperature1=296.0;
the 296.0 value is an arbitrary value > cut off temperature, to initialize for the first time step the heater to be off.
In the next time steps this value will be overwritten by looping the cells.
If you want the heater on for the first time step the macro is ok as it is or (better) you can initialize thermosensor_temperature1 with a value < cut off temperature, such as:
Code:
#include "udf.h"
real thermosensor_temperature1;
thermosensor_temperature1=290.0;
Apart this small issue, the udf works correctly.

I think your problem could be the min/max coordinates, expecially the y values: you set:
ymin=0.090
ymax=0.091

EDIT: it seems you have 4 values inside the range you specified, so this is not a problem.
Problem is in the next message: just switch the xmin/xmax values.

-------------------------------
Are you sure that in this range there are cell centered values? if your mesh is coarser in that region than 1 mm you have not cell centered values, you will never enter the loop, and the thermosensor_temperature1 will remain at a not determined value: 0.0/0.0.

Printing on the console the temperature of the sensor for your cas will give you:
-1.#IND00
-------------------------------
ahvz likes this.
__________________
Google is your friend and the same for the search button!

Last edited by ghost82; February 6, 2015 at 10:40.
ghost82 is offline   Reply With Quote

Old   February 6, 2015, 09:11
Default
  #11
Senior Member
 
ghost82's Avatar
 
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27
ghost82 will become famous soon enough
...And here the issue:

Code:
 xmin=-0.195;
 xmax=-0.2;
 ymin=0.090;
 ymax=0.091;
 zmin=0.33;
 zmax=0.39;
your xmax is < xmin!!!!!
Just switch xmin/xmax
ahvz likes this.
__________________
Google is your friend and the same for the search button!
ghost82 is offline   Reply With Quote

Old   February 6, 2015, 11:17
Default
  #12
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
Many many thanks for your excellent assistant on my problem. you right! my problem was the coordinate's values. I double checked them all and now they are correct and also the heater is getting command from the UDF.

Without your help I could not solve this problem. and you understood it very well.

Kind regards,
ahvz is offline   Reply With Quote

Old   September 22, 2015, 07:04
Default heatflux on and off
  #13
New Member
 
kams
Join Date: Sep 2015
Posts: 2
Rep Power: 0
kams is on a distinguished road
Quote:
Originally Posted by ghost82 View Post
Hi,
I opened your cas file and I received a warning, and I'm not sure if it's ok or not.

thermosensor_temperature1, such as:

if you want the heater off for the first time step:
Code:
#include "udf.h"
real thermosensor_temperature1;
thermosensor_temperature1=296.0;
the 296.0 value is an arbitrary value > cut off temperature, to initialize for the first time step the heater to be off.
In the next time steps this value will be overwritten by looping the cells.
If you want the heater on for the first time step the macro is ok as it is or (better) you can initialize thermosensor_temperature1 with a value < cut off temperature, such as:
Code:
#include "udf.h"
real thermosensor_temperature1;
thermosensor_temperature1=290.0;
Apart this small issue, the udf works correctly.



-------------------------------
Hi Ghost82,

you have explained clearly regarding UDF on heater.

even i tried the same as above example. As i compile the above program it is showing error.
..\..\src\print_27.c(3) : error C2371: 'thermosensor_temperature1' : redefinition; different basic types
..\..\src\print_27.c(2) : see declaration of 'thermosensor_temperature1'

i think this error is due to defining thermosensor_temperature1=296;
if we don't define the above line it wont get initialize by the above temperature and the program gets compiled without any error .

but the program runs as heater on condition without cutting off the temperature and heat flux.

please let me know what could be the issue on same

Best regards
Kams
kams is offline   Reply With Quote

Old   September 22, 2015, 11:02
Default
  #14
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
The problem could be that you did not copy the text literally.

Did you by chance type this:

Code:
#include "udf.h"
real thermosensor_temperature1;
real thermosensor_temperature1=296.0;
pakk is offline   Reply With Quote

Old   September 23, 2015, 03:00
Default
  #15
New Member
 
kams
Join Date: Sep 2015
Posts: 2
Rep Power: 0
kams is on a distinguished road
Quote:
Originally Posted by pakk View Post
The problem could be that you did not copy the text literally.

Did you by chance type this:

Code:
#include "udf.h"
real thermosensor_temperature1;
real thermosensor_temperature1=296.0;
Thanks for replying Mr.pakk
dint consider real in third line.

Please let me know what could be the issues.

Best regards
Kams
kams is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to model natural convection in a 2D horizontal model in fluent caitoc FLUENT 1 May 5, 2014 14:32
about Subgrid-scale model impecca OpenFOAM Running, Solving & CFD 4 December 20, 2013 11:36
Double surface inside model Andrew Siemens 1 March 16, 2005 00:04
How to model a flow inside centrifugal compressor? starPlatinum Main CFD Forum 0 October 26, 2003 10:03
does anyone answer or give some comment about my questions??? Z. Chang Main CFD Forum 7 May 9, 2000 11:15


All times are GMT -4. The time now is 18:26.