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

UDF-Using facet average temperature to change thermal conducitivity

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 1 Post By AlexanderZ
  • 1 Post By pakk
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ
  • 1 Post By StefanR

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 30, 2021, 07:19
Default UDF-Using facet average temperature to change thermal conducitivity
  #1
New Member
 
Join Date: Feb 2021
Posts: 7
Rep Power: 5
StefanR is on a distinguished road
Hello everyone!

I am solving this steady state 2D problem: I have one solid, which has constant thermal conductivity. But this constant conducitivty changes in dependence of average temperature of this solid. So i wanted to write UDF, which takes average temperature of solid and set constant thermal conductivity after every iteration.

I have read forums and one was close to mine, but it doesn't work - thermal conducitivity is 0 W/mK.

Can someone help me please? I am not very good at programming in C and this is first time I am using UDF.

This is my code:

#include "udf.h"
real tavg;
DEFINE_ADJUST(average_temp)
{
Domain *d;
face_t f;
real temper = 0.0;
real A[ND_ND];
real area = 0.0;
real area_tot = 0.0;
int ID = 2; /*this is the ID of the boundary wall that I want to get the temperature from*/
Thread *t;
int zone_ID;
d = Get_Domain(1);
t = Lookup_Thread(d,ID);
tavg = 0.0;
begin_f_loop(f,t)
{
F_AREA(A,f,t);
area = NV_MAG(A);
area_tot += area;
temper = F_T(f,t); tavg += temper*area;
}
end_f_loop(f,t)
tavg /= area_tot;
printf("Tavg = %g area_tot = %g\n",tavg,area_tot);
}

DEFINE_PROPERTY(thermal_conductivity,f,t)
{
real keff;
keff=0.001*tavg;
return keff;
}
StefanR is offline   Reply With Quote

Old   October 30, 2021, 07:32
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
On my phone, so this is not complete, but you need just one UDF. Define a new face thread and rename some things. I hope to fix this code later.

Code:
#include "udf.h"

DEFINE_PROPERTY(thermal_conductivity,f,t)
{
real keff;
real tavg = 0.0;
real temper = 0.0;
real A[ND_ND];
real area = 0.0;
real area_tot = 0.0;
begin_f_loop(f,t)
{
F_AREA(A,f,t);
area = NV_MAG(A);
area_tot += area;
temper = F_T(f,t); tavg += temper*area;
}
end_f_loop(f,t)
tavg /= area_tot;
keff=0.001*tavg;
return keff;
}
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   October 30, 2021, 09:18
Default
  #3
New Member
 
Join Date: Feb 2021
Posts: 7
Rep Power: 5
StefanR is on a distinguished road
Thank you for quick reply.

I tried to complete the code. I added it to Fluent and it was without warrning or error. But when I try to initialize the case, the Fluent crashes with "recieved signal code SIGSEGV".

I know that there is problem with my code, but I am not sure where.

My code:

#include "udf.h"

DEFINE_PROPERTY(thermal_conductivity,f,t)
{
Domain *d;
face_t face;
real tavg = 0.0;
real temper = 0.0;
real A[ND_ND];
real area = 0.0;
real area_tot = 0.0;
real k_eff;
int ID = 2;
Thread *thread;
int zone_ID;
d = Get_Domain(1);
thread = Lookup_Thread(d,zone_ID);
begin_f_loop(face,thread)
{
F_AREA(A,face,thread);
area = NV_MAG(A);
area_tot += area;
temper = F_T(face,thread); tavg += temper*area;
}
end_f_loop(face,thread)
tavg /= area_tot;
k_eff=0.001*tavg;
return k_eff;
}
StefanR is offline   Reply With Quote

Old   October 31, 2021, 18:55
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Code:
#include "udf.h"

real tavg;

DEFINE_PROPERTY(thermal_conductivity,f,t)
{
real k_eff;
k_eff=0.001*tavg;
return k_eff;
}

DEFINE_ADJUST(get_avg_temp,d)
{
face_t face;
real temper,A[ND_ND],area,area_tot;

Thread *thread;
int zone_ID = 2;
area = 0;
area_tot = 0;
tavg = 0;
temper = 0;
thread = Lookup_Thread(d,zone_ID);
begin_f_loop(face,thread)
{
	F_AREA(A,face,thread);
	area = NV_MAG(A);
	area_tot += area;
	temper = F_T(face,thread);
	tavg += temper*area;
}
end_f_loop(face,thread)
# if RP_NODE /* Perform node synchronized actions here. Does nothing in Serial */
	area_tot = PRF_GRSUM1(area_tot);
	tavg = PRF_GRSUM1(tavg);
# endif /* RP_NODE */
tavg /= area_tot;
Message0("************* tavg = %f *************\n",tavg);
}
StefanR likes this.
__________________
best regards


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

Old   November 1, 2021, 14:19
Default
  #5
New Member
 
Join Date: Feb 2021
Posts: 7
Rep Power: 5
StefanR is on a distinguished road
Thank you AlexanderZ.

I compiled it and ran calculation but there is some problem. The thermal conductivity is zero and doesn't change. So the temperature hits the limit 5000 K.
StefanR is offline   Reply With Quote

Old   November 3, 2021, 00:22
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
on each time step you should see in in console message with calculated tavg

************* tavg = SOME VALUE HERE *************

which in your case is linear with conductivity with factor 0.001

you may make small modification of line 3
was
Code:
real tavg;
to be
Code:
real tavg = 300;
which could help to avoid problems for the very first time step if there is one.
__________________
best regards


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

Old   November 3, 2021, 04:56
Default
  #7
New Member
 
Join Date: Feb 2021
Posts: 7
Rep Power: 5
StefanR is on a distinguished road
I tried it, but it looks like the UDF doesn't change tavg. There is no *****tavg=something****** and thermal conductivity stays constant and doesn't depend on the average temperature of the face.

I tried to use this UDF also for transient calculation, but it is the same as I described above.
StefanR is offline   Reply With Quote

Old   November 3, 2021, 13:44
Default
  #8
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Did you hook average_temp?
StefanR likes this.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   November 3, 2021, 23:37
Default
  #9
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
if you don't have messages in console it means adjust function is not executed

as Pakk said, look for: "how to hook DEFINE_ADJUST in fluent"
StefanR likes this.
__________________
best regards


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

Old   November 5, 2021, 07:31
Default
  #10
New Member
 
Join Date: Feb 2021
Posts: 7
Rep Power: 5
StefanR is on a distinguished road
Thank you.

But after this, I found another problem.

1.png

I have a 2D problem, so am I right that I need cell temperature instead of face?

I tried to edit the code but Fluent crashes in the first iteration, so there is a problem with the code.

Code:
#include "udf.h"

real tavg=100;

DEFINE_PROPERTY(thermal_conductivity,c,t)
{
real k_eff;
k_eff=0.001*tavg;
return k_eff;
}

DEFINE_ADJUST(get_avg_temp,d)
{
cell_t cell;
real temper,A[ND_ND],area,area_tot;

Thread *thread;


int zone_ID = 1;
area = 0;
area_tot = 0;
tavg = 0;
temper = 0;

thread = Lookup_Thread(d,zone_ID);
begin_c_loop(cell,thread)
{
	F_AREA(A,cell,thread);
	area = NV_MAG(A);
	area_tot += area;
	temper = C_T(cell,thread);
	tavg += temper*area;
}
end_c_loop(cell,thread)
# if RP_NODE /* Perform node synchronized actions here. Does nothing in Serial */
	area_tot = PRF_GRSUM1(area_tot);
	tavg = PRF_GRSUM1(tavg);
# endif /* RP_NODE */
tavg /= area_tot;
Message0("************* tavg = %f *************\n",tavg);
}
StefanR is offline   Reply With Quote

Old   November 8, 2021, 00:08
Default
  #11
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you are using cell loop if the zone which you've defined through macro
Code:
int zone_ID = 1
is not the boundary
if it is boundary you are using face loop
check ID number in fluent gui
StefanR likes this.
__________________
best regards


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

Old   November 8, 2021, 09:10
Default
  #12
New Member
 
Join Date: Feb 2021
Posts: 7
Rep Power: 5
StefanR is on a distinguished road
Thank you both!

My problem is now solved, so here is the final code that I am using.

Code:
#include "udf.h"

real tavg=200;

DEFINE_PROPERTY(thermal_conductivity,c,t)
{
real k_eff;
k_eff=0.001*tavg;
return k_eff;
}

DEFINE_ADJUST(get_avg_temp,d)
{
cell_t cell;
real temper;
real volume = 0;
real total_volume = 0;

Thread *thread;
int zone_ID = 7;
tavg = 0;
temper = 0;
thread = Lookup_Thread(d,zone_ID);
begin_c_loop_int(cell,thread)
{
	volume = C_VOLUME(cell,thread);
	total_volume += C_VOLUME(cell,thread);
	temper = C_T(cell,thread);
	tavg += temper*volume;
}
end_c_loop_int(cell,thread)
# if RP_NODE /* Perform node synchronized actions here. Does nothing in Serial */
	total_volume = PRF_GRSUM1(total_volume);
	tavg = PRF_GRSUM1(tavg);
# endif /* RP_NODE */
tavg /= total_volume;
Message0("************* tavg = %f *************\n",tavg);



}
FelixS likes this.
StefanR is offline   Reply With Quote

Reply

Tags
average temperature, 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
[openSmoke] libOpenSMOKE Tobi OpenFOAM Community Contributions 562 January 25, 2023 10:21
temperature store and monitoring UDF indsujin Fluent UDF and Scheme Programming 1 July 9, 2021 05:08
Simple piston movement in cylinder- fluid models arun1994 CFX 4 July 8, 2016 03:54
Ansys CFX problem: unexpected very high temperatures in premix laminar combustion faizan_habib7 CFX 4 February 1, 2016 18:00
is internalField(U) equivalent to zeroGradient? immortality OpenFOAM Running, Solving & CFD 7 March 29, 2013 02:27


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