|
[Sponsors] |
Error when parallelizing serial UDF in fluent |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 19, 2022, 14:47 |
Error when parallelizing serial UDF in fluent
|
#1 |
New Member
John Zhao
Join Date: May 2020
Posts: 2
Rep Power: 0 |
Hey guys,
I have been struggled in this one for long. And this is my first time posting question. I am currently modeling two straight pipes (say A and B) with working fluid inside. I want to make sure the bottom inlet of B has the same temperature as the bottom outlet of A. So my UDF is to assign A's outlet's temperature to B's inlet in real time (transient). My original code is below and it is running well in serial process. #include "udf.h" DEFINE_PROFILE(inlet_temperatureDD01,t,i) { int ID1=11; int ID2=10; real temperature; face_t f; Domain *domain; domain=Get_Domain(1); t=Lookup_Thread(domain,ID1); begin_f_loop(f,t) { temperature=F_T(f,t); } end_f_loop(f,t); domain=Get_Domain(1); t=Lookup_Thread(domain,ID2); begin_f_loop(f,t) { real time=RP_Get_Real("flow-time"); F_PROFILE(f,t,i)=temperature; } end_f_loop(f,t) } Then I made some modifications to it to run it in parallel. I tried several times but it did not work. The last version of my code is here: #include "udf.h" #define ID1 11 #define ID2 10 DEFINE_PROFILE(inlet_temperatureDD01,t,i) { real temperature, time; #if !RP_HOST face_t f; Domain *domain; domain=Get_Domain(1); t=Lookup_Thread(domain,ID1); begin_f_loop(f,t) { temperature=F_T(f,t); } end_f_loop(f,t); domain=Get_Domain(1); t=Lookup_Thread(domain,ID2); begin_f_loop(f,t) { time=RP_Get_Real("flow-time"); F_PROFILE(f,t,i)=temperature; } end_f_loop(f,t) #endif } When I interpreted the code, the temperature of B's inlet became 0 K. Could anyone help me on this? Appreciated. John |
|
January 19, 2022, 17:55 |
|
#2 |
Senior Member
|
There are, really, a lot of issues in your UDF, even the serial one.
First of all, outlet temperature of A is not a single number, it's a number for each cell face on the outlet of A. You need a norm, that you haven't defined, to convert this set of numbers in a single value. Second, as a consequence of this lack, your loop just picks up the last cell face value in the boundary loop. It is unclear how you can judge it working. Third, even if it was working, it is coded weirdly, in a way that makes impossible to make it work in parallel. What you actually need is: 1) A define adjust udf, that will loop on the outlet boundary of your choice, compute some mean temperature on it and store it in a global variable (i.e., defined outside the define adjust) 2) a define profile using that global variable Parallel stuff only belongs to the adjust udf. You have to consider that each process will compute its part of the mean (some will just have no faces on that boundary), so you need all the processes to eventually reduce their value in a single mean |
|
January 19, 2022, 18:05 |
|
#3 | |
New Member
John Zhao
Join Date: May 2020
Posts: 2
Rep Power: 0 |
Quote:
Thanks for your reply! I will try the Define_adjust macro, see if it works or not. By the way, if it works with the define adjust, for parallel processing, should I just add a #if !RP_HOST and #endif to the loop and that's all? John |
||
January 19, 2022, 18:35 |
|
#4 |
Senior Member
|
Unfortunately not, it is more complex than this. I haven't coded udfs in a while, so I can only give you some pseudo code.
Let us assume you will use an area average as actual norm for the temperature. This would actually require an additional, dedicated, define on demand udf for efficiency, but it is not mandatory. First, somewhere on top of the file, after the includes, you need to define two global variables, say, area and tavg. Then, in the define adjust, you first set them to 0 and then, in the loop on the boundary faces (the outlet ones only), you update them with: area = area + area_F tavg = tavg + area_F*T_F where area_F and T_F are the values for the given boundary cell face in the loop. I'm not actually sure that T_F is available on a boundary. In that case, you can use T in cell c0 of that face. Then you need the only parallel command to reduce the values of area and tavg. Just insert: area = PRF_GRSUM1(area); tavg = PRF_GRSUM1(tavg); Then, the last command: tavg = tavg/area; And that's it, you can then use tavg in your define profile |
|
January 20, 2022, 04:42 |
|
#5 |
Senior Member
|
You can have a look at my udf here for an example of something working in parallel that also does a thing very close to what you need:
https://www.cfd-online.com/Forums/bl...nt-part-4.html This udf can actually copy the outlet face by face to your inlet (but for velocity). So it is more complex and you need to simplify it a lot. Just use it as example for the pieces I mentioned (the global variables, the multiple udfs, the parallel parts) |
|
Tags |
ansys, fluent, parallelized udf, temperature bc, udf |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Passing udf value to fluent | durg | Fluent UDF and Scheme Programming | 2 | February 11, 2019 13:55 |
Fluent do not use my velocity field(by UDF) to solve energy equation | tangleiplus | Fluent UDF and Scheme Programming | 6 | January 21, 2019 22:28 |
My UDF works well with Fluent 16 but not with Fluent 19 | Ahmed A. Serageldin | Fluent UDF and Scheme Programming | 3 | October 19, 2018 12:38 |
A Problem of Fluent Interpreted UDF: parse error | knight | Fluent UDF and Scheme Programming | 25 | August 16, 2018 11:26 |
fluent UDF external library lapack problem | Rick | FLUENT | 0 | May 7, 2008 11:16 |