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

temperature at a point

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 16, 2015, 00:50
Default
  #21
New Member
 
Surya
Join Date: Jan 2014
Posts: 20
Rep Power: 12
hariswch2 is on a distinguished road
Quote:
Originally Posted by ghost82 View Post
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 is offline   Reply With Quote

Old   September 16, 2015, 01:23
Default
  #22
New Member
 
Surya
Join Date: Jan 2014
Posts: 20
Rep Power: 12
hariswch2 is on a distinguished road
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.....
hariswch2 is offline   Reply With Quote

Old   May 26, 2016, 11:52
Default UDMs
  #23
New Member
 
johnr
Join Date: May 2016
Posts: 10
Rep Power: 10
Johnr is on a distinguished road
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!!
Johnr is offline   Reply With Quote

Old   May 26, 2016, 11:57
Default
  #24
New Member
 
Surya
Join Date: Jan 2014
Posts: 20
Rep Power: 12
hariswch2 is on a distinguished road
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..............
hariswch2 is offline   Reply With Quote

Old   May 26, 2016, 12:12
Default UDMs
  #25
New Member
 
johnr
Join Date: May 2016
Posts: 10
Rep Power: 10
Johnr is on a distinguished road
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.
Johnr is offline   Reply With Quote

Old   May 26, 2016, 19:14
Default
  #26
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Quote:
Originally Posted by Johnr View Post
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 likes this.
`e` is offline   Reply With Quote

Old   May 27, 2016, 00:18
Default
  #27
New Member
 
Surya
Join Date: Jan 2014
Posts: 20
Rep Power: 12
hariswch2 is on a distinguished road
I support Mr "e" reply..thermosensor_temperature1 is declared as global variable, so it carries all over the program
hariswch2 is offline   Reply With Quote

Old   May 27, 2016, 01:07
Default UDFs
  #28
New Member
 
johnr
Join Date: May 2016
Posts: 10
Rep Power: 10
Johnr is on a distinguished road
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....
Johnr is offline   Reply With Quote

Old   May 27, 2016, 04:28
Default
  #29
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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.)
`e` is offline   Reply With Quote

Old   May 27, 2016, 11:20
Default UDfs
  #30
New Member
 
johnr
Join Date: May 2016
Posts: 10
Rep Power: 10
Johnr is on a distinguished road
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 is offline   Reply With Quote

Old   May 27, 2016, 12:26
Default UDFs
  #31
New Member
 
johnr
Join Date: May 2016
Posts: 10
Rep Power: 10
Johnr is on a distinguished road
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!
Johnr is offline   Reply With Quote

Old   May 27, 2016, 17:47
Default
  #32
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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)
`e` is offline   Reply With Quote

Old   June 5, 2016, 15:35
Default Fixed Velocity in cell zone
  #33
New Member
 
johnr
Join Date: May 2016
Posts: 10
Rep Power: 10
Johnr is on a distinguished road
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!
Johnr 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
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 04:56
field function to point variable temperature Trofrensis STAR-CCM+ 1 November 25, 2009 00: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


All times are GMT -4. The time now is 14:30.