
[Sponsors] 
January 11, 2011, 09:10 
temperature at a point

#1 
Member
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 8 
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 

January 11, 2011, 11:31 

#2  
New Member
Sangeeta
Join Date: Mar 2009
Posts: 3
Rep Power: 10 
Quote:


January 11, 2011, 11:36 

#3 
Member
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 8 
Yes and it is timedependent. 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. 

January 11, 2011, 22:14 

#4 
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 9 
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; } } } } See the following thread for time dependent flow: Timedependent 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 

January 12, 2011, 04:26 

#5  
Member
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 8 
Quote:
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. 

January 12, 2011, 07:05 

#6 
Member
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 8 
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 } } 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/udfconfignode1.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. 

January 12, 2011, 08:28 

#7 
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 9 
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 

January 12, 2011, 08:39 

#8 
Member
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 8 
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 semicolons there 

January 12, 2011, 09:05 

#9 
Member
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 8 
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) } } 

January 12, 2011, 22:02 

#10 
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 9 
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 

January 13, 2011, 11:57 

#11 
Member
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 8 
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 

January 14, 2011, 19:11 

#12 
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 9 
It won't be automatically stored as written. You can simply write the value to a userdefined memory location (look up: C_UDMI).
ComputerGuy 

October 28, 2013, 09:49 

#13 
Senior Member
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0 
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 generalpurpose 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 executeatend 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) } } 

January 22, 2015, 04:24 

#14  
Senior Member
Join Date: Nov 2013
Posts: 1,066
Rep Power: 14 
Quote:
Code:
real thermosensor_temperature = 0.0; 

September 15, 2015, 05:15 
how to assign temp from first part of program to second part

#15  
New Member
Surya
Join Date: Jan 2014
Posts: 20
Rep Power: 5 
Quote:
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 

September 15, 2015, 08:50 

#16 
Senior Member
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 996
Rep Power: 17 
Have a look at this post:
http://www.cfdonline.com/Forums/flu...idemodel.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.
__________________
Google is your friend and the same for the search button! 

September 15, 2015, 09:24 

#17  
New Member
Surya
Join Date: Jan 2014
Posts: 20
Rep Power: 5 
Quote:
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("Xcord = %f\n",x); printf("ycord = %f\n",y); printf("Zcord = %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 

September 15, 2015, 09:30 

#18 
Senior Member
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 996
Rep Power: 17 
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;
__________________
Google is your friend and the same for the search button! 

September 15, 2015, 10:02 

#19  
New Member
Surya
Join Date: Jan 2014
Posts: 20
Rep Power: 5 
Quote:
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.... 

September 15, 2015, 10:08 

#20 
Senior Member
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 996
Rep Power: 17 
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?
__________________
Google is your friend and the same for the search button! 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
free stream temperature  qzhu  FLUENT  5  June 10, 2015 03:55 
CFX Post: Problems with moving point cloud for changing time steps  spatialtime  CFX  0  December 7, 2009 05:56 
field function to point variable temperature  Trofrensis  STARCCM+  1  November 25, 2009 01:46 
Static temperature  David  FLUENT  2  April 1, 2005 10:57 
CFX4.3 build analysis form  Chie Min  CFX  5  July 12, 2001 23:19 