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

call temperature in Profile UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 21, 2021, 01:26
Default call temperature in Profile UDF
  #1
Member
 
sina
Join Date: Nov 2021
Posts: 41
Rep Power: 5
sina_sls is on a distinguished road
Hello,

In DEFINE_PROFILE , I want to call temperature of cell but when i run the file error "Node 0: Process 1404 : Received signal SIGSEGV" comes up .I'm sure problem because of C_T(c,t) .How can i call temperature in DEFINE_PROFILE?

here's my udf:

DEFINE_PROFILE(temperature_profile,t,i)

{

cell_t c;

float temparc;

float timeflow = CURRENT_TIME;

begin_c_loop(c,t)

{

if (timeflow>=0.021 || timeflow<=0.0346){

temparc=C_T(c,t);

F_PROFILE(c,t,i) =temparc;

}

else

F_PROFILE(c,t,i) =600;

}

end_c_loop(c,t)

}



Best Regards,
sina_sls is offline   Reply With Quote

Old   November 21, 2021, 23:47
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
instead of float use real

this UDF could work only in zones (not boundaries) apply it correctly.

put #include "udf.h" in the very first line
sina_sls likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   November 22, 2021, 10:05
Default
  #3
Member
 
sina
Join Date: Nov 2021
Posts: 41
Rep Power: 5
sina_sls is on a distinguished road
Thank you for your response, I used #include "udf.h" but I didn't copy here I forgot.
I have another problem I want to write profile (udf) which for specific time use tabular data and out of these time use the temperature that FLUENT is computed. but when i want to use temperature that FLUENT is computed it gets me the last temperature in tabular data how can I define that don't use these tabular data after specific time here is my part of code
/* Interpolate temperature from look-up table and assign to cell value */
DEFINE_PROFILE(temperature_profile,t,i)
{
cell_t c;
float time_flow = CURRENT_TIME;
float temparc;
float tempp=C_T(c,t);
begin_c_loop(c,t)
{
if (time_flow>=0.021 && time_flow<=0.0346){
temparc=get_tem_from_time(time_flow);
F_PROFILE(c,t,i) =temparc;
}else
F_PROFILE(c,t,i) =tempp;
}
end_c_loop(c,t)
}
sina_sls is offline   Reply With Quote

Old   November 22, 2021, 10:07
Default
  #4
Member
 
sina
Join Date: Nov 2021
Posts: 41
Rep Power: 5
sina_sls is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
instead of float use real

this UDF could work only in zones (not boundaries) apply it correctly.

put #include "udf.h" in the very first line
Thank you for your response, I used #include "udf.h" but I didn't copy here I forgot.
I have another problem I want to write profile (udf) which for specific time use tabular data and out of these time use the temperature that FLUENT is computed. but when i want to use temperature that FLUENT is computed it gets me the last temperature in tabular data how can I define that don't use these tabular data after specific time here is my part of code
/* Interpolate temperature from look-up table and assign to cell value */
DEFINE_PROFILE(temperature_profile,t,i)
{
cell_t c;
float time_flow = CURRENT_TIME;
float temparc;
float tempp=C_T(c,t);
begin_c_loop(c,t)
{
if (time_flow>=0.021 && time_flow<=0.0346){
temparc=get_tem_from_time(time_flow);
F_PROFILE(c,t,i) =temparc;
}else
F_PROFILE(c,t,i) =tempp;
}
end_c_loop(c,t)
}
sina_sls is offline   Reply With Quote

Old   November 22, 2021, 23:59
Default
  #5
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
show code for get_tem_from_time function
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   November 24, 2021, 14:53
Default
  #6
Member
 
sina
Join Date: Nov 2021
Posts: 41
Rep Power: 5
sina_sls is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
show code for get_tem_from_time function
#include "udf.h"

int NPts_tem = 111; /* number of entries in temperature table */

/* Locate the place in the interpolation vector using bisection algorithm*/

int locate(float xx[], int n, float x)
{
int j = 0;
int jm = 0;
int jl = 0;
int ju = n+1;
int ascnd = 0;

ascnd = (xx[n] >= xx[1]);
while (ju-jl > 1)
{
jm = (ju+jl) >> 1;
if (x >= xx[jm] == ascnd)
jl = jm;
else
ju = jm;
}

if (x == xx[1])
j = 1;
else if (x == xx[n])
j = n-1;
else
j = jl;

return j;
}

/* -----Understood------ */


float *time_vec_tem,*tem_vec;
#define FAST_LOOKUP TRUE /* use bisection algorithm for interpolation */

#define TABLE_MESSAGES TRUE
#define DISPLAY_TABLES TRUE

/* Obtaine mu given temperature */

float get_tem_from_time(float xdata)
{
int i = 0;
int j = 0;
float xL,xU,ydata;

#if FAST_LOOKUP
j = locate(time_vec_tem,NPts_tem,xdata);
xL = time_vec_tem[j];
xU = time_vec_tem[j+1];
ydata = tem_vec[j] + (xdata-xL)/(xU-xL)*( tem_vec[j+1] - tem_vec[j] );
#else
for ( i=1; i<NPts_tem ;i++ )
{
xL = time_vec_tem[i];
xU = time_vec_tem[i+1];
if ( (xdata>=xL)&&(xdata<=xU) )
{
ydata = tem_vec[i] + (xdata-xL)/(xU-xL)*( tem_vec[i+1] - tem_vec[i] );
break;
}
}
#endif

if ( xdata>time_vec_tem[NPts_tem] )
{
#if TABLE_MESSAGES
Message("n temperature is above the bound of visc-array n");
#endif
ydata = tem_vec[NPts_tem];
}
if ( xdata<time_vec_tem[1] )
{
#if TABLE_MESSAGES
Message("n temperature is below the bound of visc-array n");
#endif
ydata = tem_vec[1];
}

return ydata;
}

/* -----Understood------*/

/* Read in the data file containing temperature as a function of time */

DEFINE_ON_DEMAND(read_arctemperature)
{
int i = 0;
float xdata,ydata;
FILE* fp;

fp = fopen("arctemperature.dat","r");
if ( fp!=NULL )
{
#if !RP_NODE
Message(" \n");
Message("Reading file arctemperature.dat \n");
Message(" \n");
#endif
}
else
{
#if !RP_NODE
Message(" \n");
Message("Error opening file \n");
Message(" \n");
#endif
}

time_vec_tem = (float *) malloc(NPts_tem*sizeof(float)); /*Dynamic Memory Allocation*/

tem_vec = (float *) malloc(NPts_tem*sizeof(float)); /*Dynamic Memory Allocation*/

if ( (time_vec_tem==NULL)||(tem_vec==NULL) )
{
#if !RP_NODE
Message("Memory allocation error \n");
#endif
}

for ( i=1;i<=NPts_tem;i++ )
{
fscanf(fp,"%e %e \n",&xdata,&ydata);
time_vec_tem[i] = xdata;
tem_vec[i] = ydata;
#if DISPLAY_TABLES
#if !RP_NODE
Message("%e %e \n",time_vec_tem[i],tem_vec[i]);
#endif
}
#else
}
#if !RP_NODE
Message(" \n");
#endif
#endif

fclose(fp);
}


/* Interpolate temperature from look-up table and assign to cell value */
DEFINE_PROFILE(temperature_profile,t,i)
{
cell_t c;
float time_flow = CURRENT_TIME;
float temparc;
float tempp=C_T(c,t);
begin_c_loop(c,t)
{
if (time_flow>=0.021 && time_flow<=0.0346){
temparc=get_tem_from_time(time_flow);
F_PROFILE(c,t,i) =temparc;
}else
F_PROFILE(c,t,i) =tempp;
}
end_c_loop(c,t)
}
sina_sls is offline   Reply With Quote

Reply

Tags
profile, udf


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
Temperature Profile UDF AC1993 Fluent UDF and Scheme Programming 1 November 1, 2016 03:15
Temperature profile UDF for 3D cylinder surface Himel Fluent UDF and Scheme Programming 1 June 16, 2015 11:59
defining temperature profile with UDF mohammadkm Fluent UDF and Scheme Programming 11 July 3, 2013 01:15
is internalField(U) equivalent to zeroGradient? immortality OpenFOAM Running, Solving & CFD 7 March 29, 2013 02:27
UDF for linear temperature profile on horizontal parallel surfaces. Chirag2302 Fluent UDF and Scheme Programming 0 February 4, 2012 01:44


All times are GMT -4. The time now is 15:59.