|
[Sponsors] |
UDF writes the outlet temperature assignment to the inlet temperature of another calc |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
May 22, 2020, 11:05 |
UDF writes the outlet temperature assignment to the inlet temperature of another calc
|
#1 |
New Member
Join Date: May 2020
Posts: 8
Rep Power: 6 |
For steady-state simulation, I want to assign the outlet temperature of one computing domain to the inlet temperature of another computing domain. I write the following code, but the simulation results show that the inlet temperature is always zero. I don’t know why. I hope you all Take a look at my UDF, thank you.
UDF: #include“udf.h" DEFINE_ADJUST(T_out_in, d) { real NV_VEC(A); real sum_T_A = 0.0; real sum_A = 0.0; real outlet_temp; int i; #if !RP_HOST Domain *domain; Thread *threadOutlet1; Thread *threadInlet2; domain = Get_Domain(1); threadOutlet1 = Lookup_Thread(domain, 44); threadInlet2 = Lookup_Thread(domain, 43); for(i = 0; i < THREAD_N_ELEMENTS_INT(threadOutlet1); i++) { F_AREA(A,i,threadOutlet1); sum_A+=NV_MAG(A); sum_T_A+=NV_MAG(A)*F_T(i,threadOutlet1); } #endif #if RP_NODE sum_A = PRF_GRSUM1(sum_A); sum_T_A = PRF_GRSUM1(sum_T_A); #endif node_to_host_real_2(sum_A, sum_T_A); #if !RP_NODE outlet_temp = sum_T_A/sum_A; Message("\n temp of outlet2 is %g\n", outlet_temp); #endif host_to_node_real_1(outlet_temp); #if !RP_HOST for(i = 0; i<THREAD_N_ELEMENTS_INT(threadInlet2); i++) F_UDMI(i, threadInlet2, 0) = outlet_temp; #endif } DEFINE_PROFILE(Inlet2_T, t, index) { #if !RP_HOST int i; for(i = 0; i < THREAD_N_ELEMENTS_INT(t); i++) F_PROFILE(i, t, index) = F_UDMI(i, t, 0); #endif } |
|
May 24, 2020, 23:50 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
instead of i which has type integer you should use type face_t
it influence F_UDMI and F_PROFILE macros example Code:
#include "udf.h" DEFINE_PROFILE(pressure_profile,t,i) { real x[ND_ND]; /* this will hold the position vector */ real y; face_t f; begin_f_loop(f,t) { F_CENTROID(x,f,t); y = x[1]; F_PROFILE(f,t,i) = 1.1e5 - y*y/(.0745*.0745)*0.1e5; } end_f_loop(f,t) }
__________________
best regards ****************************** press LIKE if this message was helpful |
|
May 25, 2020, 00:44 |
|
#3 |
New Member
Join Date: May 2020
Posts: 8
Rep Power: 6 |
Thanks for your reply, I feel the problem is not the use of int type, because I changed the udf to the following, the result is still that the inlet temperature is zero. I want to simulate a situation similar to a U-shaped tube flow, the middle connection part is not drawn, and the temperature is transmitted in some way.
#include"udf.h" DEFINE_ADJUST(T_out_in, d) { real NV_VEC(A); real sum_T_A = 0.0; real sum_A = 0.0; real outlet_temp; face_t f; Domain *domain; Thread *threadOutlet; Thread *threadInlet; domain = Get_Domain(1); threadOutlet = Lookup_Thread(domain, 44); threadInlet = Lookup_Thread(domain, 43); begin_f_loop(f,threadOutlet) { if(PRINCIPAL_FACE_P(f,threadOutlet)) { F_AREA(A,i,threadOutlet); F_UDMI(f,threadOutlet,0)=NV_MAG(A); sum_A+=NV_MAG(A); sum_T_A+=NV_MAG(A)*F_T(i,threadOutlet); } } end_f_loop(f,threadOutlet) #if RP_NODE sum_A = PRF_GRSUM1(sum_A); sum_T_A = PRF_GRSUM1(sum_T_A); #endif node_to_host_real_2(sum_A, sum_T_A); #if !RP_NODE outlet_temp = sum_T_A/sum_A; Message("\n temp of outlet2 is %g\n", outlet_temp); #endif host_to_node_real_1(outlet_temp); begin_f_loop(f,threadInlet) { F_UDMI(f,threadInlet,1) = outlet_temp; } end_f_loop(f,threadInlet) } DEFINE_PROFILE(Inlet2_T, t, i) { begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,1); } end_f_loop(f,t) } |
|
May 25, 2020, 13:12 |
Approach
|
#4 |
Senior Member
|
It's not the code, but the approach that has a problem. Since you want to apply a single value, area-weighted average, as boundary condition, there are no UDMs needed, none of those. You can sum all the values in the loop and calculate average and assign it to a real scalar. Then, access this scalar in DEFINE_PROFILE and assign it to F_PROFILE.
As far as the code is concerned, though face_t and cell_t are int types, they are associated to the grid structure. Hence, you can use standard-C for loop with integer counter but that won't guarantee the access of same UDMs as face IDs. UDMs are associated with particular faces and cells.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
May 25, 2020, 22:38 |
|
#5 | |
New Member
Join Date: May 2020
Posts: 8
Rep Power: 6 |
Quote:
new UDF: #include"udf.h" real avg_T_A_penal_W01_up=0.0; DEFINE_ADJUST(T_TRANSFER,d) { real total_A_penal_W01_up=0.0; real total_T_A_penal_W01_up=0.0; /* "Parallelized" Sections */ #if !RP_HOST /* Compile this section for computing processes only (serial and node) */ Thread *thread_penal_W01_up; Domain=*domain; face_t f; real A[ND_ND]; #endif /* RP_HOST*/ #if !RP_HOST domain=Get_Domain(1); thread_penal_W01_up=Lookup_Thread(domain,33); begin_f_loop(f,thread_penal_W01_up) {F_AREA(A,f,thread_penal_W01_up); total_A_penal_W01_up+=NV_MAG(A); total_T_A_penal_W01_up+=NV_MAG(A)*F_T(f,thread_pen al_W01_up); } end_f_loop(f,thread_penal_W01_up) /* global summation for nodes,Does nothing in Serial */ #if RP_NODE total_A_penal_W01_up=PRF_GRSUM1(total_A_penal_W01_ up); total_T_A_penal_W01_up=PRF_GRSUM1(total_T_A_penal_ W01_up); #endif /* RP_NODE*/ #endif /* RP_HOST*/ /* Pass the node's total area,total temp and total vilocity to the Host for averaging */ node_to_host_real_2(total_A_penal_W01_up,total_T_A _penal_W01_up); /* Does nothing in SERIAL */ #if RP_HOST Message("i am in host, %g, %g", total_A_penal_W01_up,total_T_A_penal_W01_up); #endif avg_T_A_penal_W01_up=total_T_A_penal_W01_up/total_A_penal_W01_up; } DEFINE_PROFILE(T_adjust_penal_W02_up,t,i) { #if !RP_HOST /* SERIAL or NODE */ face_t f; #endif /* RP_HOST*/ #if !RP_HOST begin_f_loop(f,t) { F_PROFILE(f,t,i)=avg_T_A_penal_W01_up; } end_f_loop(f,t) #endif /* !RP_HOST */ } |
||
May 26, 2020, 11:15 |
Code
|
#6 |
Senior Member
|
Yes, that's correct. You don't need a UDM and a global variable can be used. Do note that DEFINE_ADJUST needs to be hooked and it won't work until hooked at its right place. Furthermore, Domain is already provided by Fluent as second argument of DEFINE_ADJUST. Hence, you don't need commands like Get_Domain; just use d, if required. Before parallelizing, make it work in Serial. Once it works as expected, then parallelize it.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
May 26, 2020, 23:08 |
|
#7 | |
New Member
Join Date: May 2020
Posts: 8
Rep Power: 6 |
Quote:
|
||
May 27, 2020, 05:14 |
Serial
|
#8 |
Senior Member
|
Using it in Serial helps with debugging. However, if the code is already doing what you expect it to do, then you don't need to try it in serial. For these codes, serialization term does not apply, only parallelization is done; the codes are already in their serial form.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[openSmoke] libOpenSMOKE | Tobi | OpenFOAM Community Contributions | 562 | January 25, 2023 10:21 |
UDF for pressure outlet backflow total temperature | MrDaimon | FLUENT | 13 | June 23, 2017 01:45 |
map outlet boundary profile as an inlet condition using UDF | Daniel_Khazaei | Fluent UDF and Scheme Programming | 2 | June 20, 2016 12:53 |
make the inlet volume fraction equal to the outlet - udf syntax error | kongl1986 | Fluent UDF and Scheme Programming | 2 | October 27, 2014 14:02 |
please, would anyone help me with this UDF, inlet temperature change with time | Juun | Fluent UDF and Scheme Programming | 2 | March 18, 2014 11:03 |