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

UDF writes the outlet temperature assignment to the inlet temperature of another calc

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 22, 2020, 11:05
Default 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
ZengJiChuan is on a distinguished road
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
}
ZengJiChuan is offline   Reply With Quote

Old   May 24, 2020, 23:50
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 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
AlexanderZ is offline   Reply With Quote

Old   May 25, 2020, 00:44
Default
  #3
New Member
 
Join Date: May 2020
Posts: 8
Rep Power: 6
ZengJiChuan is on a distinguished road
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)
}
ZengJiChuan is offline   Reply With Quote

Old   May 25, 2020, 13:12
Default Approach
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   May 25, 2020, 22:38
Default
  #5
New Member
 
Join Date: May 2020
Posts: 8
Rep Power: 6
ZengJiChuan is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
Thank you for your reply. You mean that I don't need to use UDM, so I use global variables to pass the temperature instead, and begin_f_loop function to loop. However, the calculation result is still that the inlet temperature is zero. I feel that the ADJUST function does not work, and the message function displays no information. So it's my UDF's fault, or ADJUST can't achieve the function I want. The simulation I want to do is similar to the flow of a U-shaped tube, the middle connection part is not drawn, and I want to pass the temperature through udf.
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 */
}
ZengJiChuan is offline   Reply With Quote

Old   May 26, 2020, 11:15
Default Code
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   May 26, 2020, 23:08
Thumbs up
  #7
New Member
 
Join Date: May 2020
Posts: 8
Rep Power: 6
ZengJiChuan is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
Thank you for your reply. I hooked the ADJUST function according to your ideas, and the result of the operation is in line with my expectations. But I did the parallel operation directly without serializing it first. So how to achieve serial then parallel?
ZengJiChuan is offline   Reply With Quote

Old   May 27, 2020, 05:14
Default Serial
  #8
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Reply


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
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


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