|
[Sponsors] |
UDF-Using facet average temperature to change thermal conducitivity |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 30, 2021, 07:19 |
UDF-Using facet average temperature to change thermal conducitivity
|
#1 |
New Member
Join Date: Feb 2021
Posts: 7
Rep Power: 5 |
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; } |
|
October 30, 2021, 07:32 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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". |
|
October 30, 2021, 09:18 |
|
#3 |
New Member
Join Date: Feb 2021
Posts: 7
Rep Power: 5 |
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; } |
|
October 31, 2021, 18:55 |
|
#4 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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); }
__________________
best regards ****************************** press LIKE if this message was helpful |
|
November 1, 2021, 14:19 |
|
#5 |
New Member
Join Date: Feb 2021
Posts: 7
Rep Power: 5 |
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. |
|
November 3, 2021, 00:22 |
|
#6 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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; Code:
real tavg = 300;
__________________
best regards ****************************** press LIKE if this message was helpful |
|
November 3, 2021, 04:56 |
|
#7 |
New Member
Join Date: Feb 2021
Posts: 7
Rep Power: 5 |
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. |
|
November 3, 2021, 13:44 |
|
#8 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Did you hook average_temp?
__________________
"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". |
|
November 3, 2021, 23:37 |
|
#9 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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"
__________________
best regards ****************************** press LIKE if this message was helpful |
|
November 5, 2021, 07:31 |
|
#10 |
New Member
Join Date: Feb 2021
Posts: 7
Rep Power: 5 |
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); } |
|
November 8, 2021, 00:08 |
|
#11 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
you are using cell loop if the zone which you've defined through macro
Code:
int zone_ID = 1 if it is boundary you are using face loop check ID number in fluent gui
__________________
best regards ****************************** press LIKE if this message was helpful |
|
November 8, 2021, 09:10 |
|
#12 |
New Member
Join Date: Feb 2021
Posts: 7
Rep Power: 5 |
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); } |
|
Tags |
average temperature, udf |
|
|
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 |