|
[Sponsors] |
November 9, 2023, 14:36 |
UDF cannot update cell temperature
|
#1 |
New Member
Zhongqi Zuo
Join Date: May 2018
Location: China
Posts: 8
Rep Power: 8 |
Dear all,
I am using UDF to update the temperature in a solid zone from the temperature in another solid zone (attachement1). The UDF can be successfully compiled. A strange thing happens that although the temperature could be updated when the UDF is compiled as "Execute on demand" or "Execute at end" (attachement2). However, when I simulated 1 more time step, the temperature recovered to the origin value (before update, (attachement3). Can anyone help me with this problem? Thanks in advance. Following is my UDF code. Code:
#include "udf.h" /* Mapping temperature profiles between solid zones of slabs */ DEFINE_ON_DEMAND(map_T_between_slabs) { Domain* d; cell_t c1; cell_t c2; Thread* t1; Thread* t2; real local_cor[ND_ND],target_cor[ND_ND]; real local_t,tar_t; real half_range; real z1, z2, nt, z_tar; real delta_x; delta_x = 0.02; half_range = 0.0002; d = Get_Domain(1); t1 = Lookup_Thread(d, 10); // Solid Zone 1 t2 = Lookup_Thread(d, 9); // Solid Zone 2 nt = 0.0; begin_c_loop(c1, t1) { tar_t = 0.0; nt = 0.0; C_CENTROID(local_cor, c1, t1); z1 = local_cor[2]; z_tar = z1 - delta_x; begin_c_loop(c2, t2) { C_CENTROID(target_cor, c2, t2); z2 = target_cor[2]; if ((z2 >= z_tar - half_range) && (z2 <= z_tar + half_range)) { tar_t = tar_t + C_T(c2, t2); nt = nt + 1.0; /* count number */ } } end_c_loop(c2, t2) local_t = tar_t / nt; C_T(c1, t1) = local_t; } end_c_loop(c1, t1) } Zuo |
|
November 10, 2023, 00:25 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
could be problem in the logic of model
you may freeze temperature using fixed values at cell zone conditions and apply profile (define_profile macro) to specify temperature values
__________________
best regards ****************************** press LIKE if this message was helpful |
|
November 10, 2023, 07:24 |
|
#3 |
New Member
Zhongqi Zuo
Join Date: May 2018
Location: China
Posts: 8
Rep Power: 8 |
Hi Alexander,
Thanks for your reply. The simulation is a solid at position 1 moving to position 2 periodically. The temperature of solids changes so I cannot use fixed values. Do you suggest that the setting of my case is wrong or that Fluent cannot handle this problem? I also tried a case that just set the fluid temperature in a region, but the same problem occurred. I wonder if there is a very tiny mistake in my code because I think UDF surely can do these things. DEFINE_ON_DEMAND(map_T_between_slabs) { Domain* d; cell_t c1; cell_t c2; Thread* t1; Thread* t2; real local_cor[ND_ND],target_cor[ND_ND]; real local_t,tar_t; real half_cell_size; real z1, z2, nt, z_tar; real delta_x; delta_x = 0.02; half_cell_size = 0.0002; d = Get_Domain(1); nt = 0.0; /* loop over all cell threads in the domain */ thread_loop_c(t1, d) { begin_c_loop(c1, t1) { C_CENTROID(local_cor, c1, t1); z1 = local_cor[2]; if ((z1 >= 0.0105) && (z1 <= 0.0195)) { C_T(c1, t1) = 310; } } end_c_loop(c1, t1) } } Thank you! Update: This code works in prue fluid simulations, so the problem may related to the solid-fluid coupling, e.g. the wall and shadow-wall. Will post the solution if solved. Last edited by MrZZQi; November 10, 2023 at 08:30. |
|
November 20, 2023, 13:50 |
|
#4 |
New Member
Zhongqi Zuo
Join Date: May 2018
Location: China
Posts: 8
Rep Power: 8 |
The problem arises because the assigning of temperature will quickly diverge after 5 iterations (in my case). The solution for me is quite hacky, which is executing the DEFINE_ADJUST macro every 2 iterations by adding a sentence like "if (N_ITER % 2 ==0){code}".
Hopes this can help. Zuo |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how can use the cell temperature of each cell from zone 1 in zone 2 with UDF? | bhwcs | Fluent UDF and Scheme Programming | 9 | November 17, 2021 03:20 |
[Other] refineWallLayer Error | Yuby | OpenFOAM Meshing & Mesh Conversion | 2 | November 11, 2021 12:04 |
Inlet won't apply UDF and has temperature at 0K! | tccruise | Fluent UDF and Scheme Programming | 2 | September 14, 2012 07:08 |
Pressure and Temperature UDF for Cell Zone | elixer2104 | FLUENT | 0 | February 24, 2011 12:54 |
[Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues | michele | OpenFOAM Meshing & Mesh Conversion | 2 | July 15, 2005 05:15 |