
[Sponsors] 
Resolved: Changing boundary condition with UDF according to pressure outlet boundary 

LinkBack  Thread Tools  Display Modes 
May 30, 2010, 07:43 
Resolved: Changing boundary condition with UDF according to pressure outlet boundary

#1 
New Member
alpemre
Join Date: May 2010
Posts: 3
Rep Power: 8 
Hello everybody, my problem was:
I was trying to set a temperature to a velocity inlet in my problem according to the average temperature of the air leaving the domain from a pressure outlet. I searched through the forum to find a solution to this but I could not find a clear answer. Now I managed to write a parallel UDF (for 8 cpus) as a remedy to this problem. Hope this helps if you have the same problem: Code:
#include "udf.h" /* Average temperature is calculated and share with other CPUs */ DEFINE_ADJUST(average_exit_temp, domain) { #if !RP_HOST /* either serial or compute node process is involved */ face_t f; real sum_temp=0.0; int nfaces = 0, i; int ID = 21; //on_hava_cikisi int ID0 = 31; //uflec_orta_sag int ID1 = 30; //uflec_orta_sol int ID2 = 28; //uflec_sag int ID3 = 29; //uflec_sag_cam int ID4 = 26; //uflec_sol int ID5 = 27; //uflec_sol_cam /* Determination of zone IDs */ Thread *thread = Lookup_Thread(domain, ID ); Thread *thread0 = Lookup_Thread(domain, ID0); Thread *thread1 = Lookup_Thread(domain, ID1); Thread *thread2 = Lookup_Thread(domain, ID2); Thread *thread3 = Lookup_Thread(domain, ID3); Thread *thread4 = Lookup_Thread(domain, ID4); Thread *thread5 = Lookup_Thread(domain, ID5); /* Calculation of average exit temperature and sending to other nodes. The thread on which the average temperature is calculated is on node zero*/ if(I_AM_NODE_ZERO_P) { begin_f_loop(f, thread) { nfaces = nfaces + 1; sum_temp = sum_temp + F_T(f,thread); } end_f_loop(f,thread) sum_temp = sum_temp/nfaces; Message("Node %d : Average exit temperature = %f\n", myid, sum_temp); compute_node_loop_not_zero(i) { PRF_CSEND_REAL(i, &sum_temp, 1, myid); } } /* Reception of average temperature from node zero */ if(! I_AM_NODE_ZERO_P) { PRF_CRECV_REAL(0, &sum_temp, 1, 0); Message("Node %d : Average exit temperature = %f\n", myid, sum_temp); } /* User defined memory of thread0 are filled with sum_temp */ begin_f_loop(f, thread0) { F_UDMI(f,thread0,0) = sum_temp; } end_f_loop(f,thread0) /* User defined memory of thread1 are filled with sum_temp */ begin_f_loop(f, thread1) { F_UDMI(f,thread1,1) = sum_temp; } end_f_loop(f,thread1) /* User defined memory of thread2 are filled with sum_temp */ begin_f_loop(f, thread2) { F_UDMI(f,thread2,2) = sum_temp; } end_f_loop(f,thread2) /* User defined memory of thread3 are filled with sum_temp */ begin_f_loop(f, thread3) { F_UDMI(f,thread3,3) = sum_temp; } end_f_loop(f,thread3) /* User defined memory of thread4 are filled with sum_temp */ begin_f_loop(f, thread4) { F_UDMI(f,thread4,4) = sum_temp; } end_f_loop(f,thread4) /* User defined memory of thread5 are filled with sum_temp */ begin_f_loop(f, thread5) { F_UDMI(f,thread5,5) = sum_temp; } end_f_loop(f,thread5) #endif } /* Boundary conditions are filled from user defined memory locations */ DEFINE_PROFILE(temp_uflec_orta_sag,t,i) { #if !RP_HOST face_t f; begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,0); } end_f_loop(f,t) #endif } DEFINE_PROFILE(temp_uflec_orta_sol,t,i) { #if !RP_HOST face_t f; begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,1); } end_f_loop(f,t) #endif } DEFINE_PROFILE(temp_uflec_sag,t,i) { #if !RP_HOST face_t f; begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,2); } end_f_loop(f,t) #endif } DEFINE_PROFILE(temp_uflec_sag_cam,t,i) { #if !RP_HOST face_t f; begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,3); } end_f_loop(f,t) #endif } DEFINE_PROFILE(temp_uflec_sol,t,i) { #if !RP_HOST face_t f; begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,4); } end_f_loop(f,t) #endif } DEFINE_PROFILE(temp_uflec_sol_cam,t,i) { #if !RP_HOST face_t f; begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,5); } end_f_loop(f,t) #endif } 

January 3, 2011, 04:58 
help

#2 
Member
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 8 
Hi there,
Thank you very much for this. Can I know some of the function of the lines you have written? 1) Message("Node %d : Average exit temperature = %f\n", myid, sum_temp); and 2)compute_node_loop_not_zero(i) I am very new in UDF in ANSYS Fluent and will appreciate all the help I can get. Thank you. EH 

December 17, 2012, 16:46 
How can I do the same job as you did but not for parallel nodes?

#3  
New Member
Join Date: Oct 2012
Posts: 8
Rep Power: 6 
Hi,
I am trying to do the same with my code, but since it's not parallel, I am omitting every line in your code that relates to parallel CPUs. Here is my code: #include "udf.h" DEFINE_ADJUST(average_exit_temp, domain) { face_t f; real tempa=0.0; real totalarea=0.0; real avetempa=0.0; real A[ND_ND]; int ID1 = 4; /* Zone ID for Outflow zone from Boundary Conditions panel */ Thread *outlet_thread = Lookup_Thread(domain, ID1); int ID2 = 7; /* Zone ID for Inlet zone from Boundary Conditions panel */ Thread *inlet_thread = Lookup_Thread(domain, ID2); /* Loop over faces in a face thread to get the information stored on faces.*/ begin_f_loop(f,outlet_thread) { /* F_T gets face temperature. += causes all face areas/temperatures to be added together. */ totalarea += F_AREA(A,f,outlet_thread); tempa += F_AREA(A,f,outlet_thread)*F_T(f,outlet_thread); } end_f_loop(f,outlet_thread) avetempa = tempa/totalarea + 30*200/(0.561*4182); printf("average temperature= %e\n",avetempa); begin_f_loop(f, inlet_thread) { F_UDMI(f,inlet_thread,1) = avetempa; } } DEFINE_PROFILE(Inlettemp,t,i) { real flow_time; flow_time = RP_Get_Real("flowtime"); face_t face; if(flow_time<=5.0) { printf("t= %e\n",flow_time); begin_f_loop(face, t) { F_PROFILE(face, t, i)=283.0; } end_f_loop(face, t) } else { begin_f_loop(face, t) { F_PROFILE(face, t, i) = F_UDMI(f,t,1); } end_f_loop(face, t) printf("t= %e\n",flow_time); } } and I get a parse error on the Define_Profile line. Note that my case file and my c file are in the same directory. Do you have any idea what might be wrong here? Thank you in advance for your help. CMA Quote:


January 11, 2013, 09:13 

#4 
New Member
Join Date: Jan 2011
Posts: 3
Rep Power: 8 
Hi CMA,
Not sure if you have solved this ourself but as I am 'borrowing' your code I thought I better reply with the fix. I think the error you have is that you don't have an end_f_loop(f,inlet_thread) at the end of the DEFINE_ADJUST() The parse error kicks in once you leave the function so it looks like it is relatign to the next function, but it isn't as I am only using our first function and also got the parse error. Taff 

January 11, 2013, 11:44 

#5  
New Member
Join Date: Oct 2012
Posts: 8
Rep Power: 6 
Hi Taff,
There are a couple of errors in the above code including the one you mentioned. For example where I calculate the area of a face, my code gets the vector area which creates another error. However, if you are only using the general structure of the code, you will be fine. I will be happy to hear your suggestions, if there's any. Quote:


January 11, 2013, 11:53 

#6  
New Member
Join Date: Jan 2011
Posts: 3
Rep Power: 8 
I'm struggling a bit to be honest, first attempt at UDFs and not quite sure I have it worked out.
For some reason my system isn't processing the begin_f_loop loop, I think because I am running multiprocessor i have included the if(I_AM_ NODE_ZERO_P) and for some reason this is stopping the loop occuring, maybe the thread isn't in the node_zero processors area? I'm sure I have something stupid going on. If you have a working version would wouldn't mind sharing i'd like to have a look at it. Thanks Taff Quote:


April 11, 2013, 23:16 

#7 
New Member
massoud
Join Date: Nov 2011
Posts: 17
Rep Power: 7 
Thank you so much. It was really helpful


April 18, 2013, 02:39 

#8 
New Member
massoud
Join Date: Nov 2011
Posts: 17
Rep Power: 7 
Hi. Sorry just one question. How can I find that my outlet thread is on which node? because in this code you said that "The thread on which the average temperature is calculated is on node zero"
thank you so much. 

April 23, 2013, 11:43 
answer to ehooi

#9  
New Member
alpemre
Join Date: May 2010
Posts: 3
Rep Power: 8 
Quote:
This is to send a real variable from node 0 to all other nodes. 

April 24, 2013, 05:35 
answer to massoud

#10  
New Member
alpemre
Join Date: May 2010
Posts: 3
Rep Power: 8 
Quote:
Maybe you can try printing messages from different processors to determine it. Let me know if you learn how to do it. 

April 25, 2013, 00:04 

#11 
New Member
massoud
Join Date: Nov 2011
Posts: 17
Rep Power: 7 
thank you so much dear alpemre, I found it by printing message.
Last edited by massoudepsilon; April 25, 2013 at 04:11. 

September 9, 2013, 05:01 
pressure inlet boundary vs to value of mass flow rate

#12 
New Member
mohammad azizi
Join Date: Sep 2013
Location: Iran, Tehran, TMU
Posts: 2
Rep Power: 0 
Hi all
I want to write a udf defining the value of the pressure in a pressure inlet boundary vs to value of mass flow rate passing that bouandary. can anyone help me or write this udf for me? thanks. M.Azizi 

February 24, 2014, 11:18 
additionnal question...

#13 
New Member
Join Date: May 2009
Posts: 9
Rep Power: 9 
Hi all,
This post is quite old, but maybe someone will be able to answer this little question. In the code above, alpemre use user defined memory for each thread, and then assign sum_temp to each one, to finally reread it in separate DEFINE_PROFILE loops.. This seems quite long, and I'm wondering (since my C skills are quite low..) if we couldn't just declare some global variable "sum_temp", assign to it the computed average temp, and then just use something like F_PROFILE(f,t,i) = sum_temp; . So no more UDM needed. Would that work ? Thank you, 

Tags 
change boundary condition, udf 
Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Neumann Pressure Boundary Condition with UDF  Balder  Fluent UDF and Scheme Programming  8  July 6, 2012 11:21 
pressure outlet boundary condition  Sastry  FLUENT  4  February 19, 2011 02:33 
ATTENTION! Reliability problems in CFX 5.7  Joseph  CFX  14  April 20, 2010 15:45 
UDF for tractionfree boundary condition at outlet  psb  Fluent UDF and Scheme Programming  0  November 10, 2009 03:40 
Convective Heat Transfer  Heat Exchanger  Mark  CFX  6  November 15, 2004 16:55 