|
[Sponsors] |
How to calculate area of particular surface through UDF? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
May 19, 2021, 11:44 |
How to calculate area of particular surface through UDF?
|
#1 |
New Member
Join Date: Feb 2020
Posts: 28
Rep Power: 6 |
Background
Hello, everyone: I want to calculate the area of top surface(ID=10) which is shown in Figure 1, but I encountered some problem and I cannot figure it out. For UDF code, I searched previous examples on the internet, but I cannot fully understand the meaning of some syntax. Problem (1) UDF problem. I know I should find the target surface and then use the macro called F_AREA and NV_MAG to obtain area, but I don’t know how to realize it? (2) Understanding of macro problem. The loop macro in UDF code, ‘thread_loop_f’ and ‘begin_f_loop-end_f_loop’, I know the function of these two macros, for example, to my understanding, ‘thread_loop_f(thread, domain) is to loop over thread which contains faces in domain(am I right?), but I do not know why they are here? (3) After built and loaded UDF file successfully, once I clicked the ‘execute on demand’, error pops out, which is shown in Figure 2, why this happened? Any help will be appreciated, thank you, I need your help. Regards, Silence Figure 1 Figure 2 UDF code: #include<iostream> #include "udf.h" using namespace std; DEFINE_ON_DEMAND(Face_area) { face_t face; Thread* thread; Domain* domain; domain = Get_Domain(1); int zone_id = 6; thread = Lookup_Thread(domain, zone_id); real NV_VEC(va); /* Array for storing area vector */ real Area = 0; thread_loop_f(thread, domain) { begin_f_loop(face, thread) { F_AREA(va, face, thread); /* Obtain the area vector */ Area = NV_MAG(nc); /* Obtain area magnitude */ cout << "Area of top surface is" << Area << endl; } end_f_loop(face, thread) } } |
|
May 19, 2021, 18:57 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
The images don't show up for me....
I don't understand the thread_loop_f loop here.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build". |
|
May 19, 2021, 21:49 |
|
#3 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
problem comes from the fact, that you've made few typos
compile code and check log, fix problems the logic of code is correct, from my point of view you may use this link as a hint if needed Obtaining fluid properties using UDF
__________________
best regards ****************************** press LIKE if this message was helpful |
|
May 24, 2021, 10:54 |
|
#4 | |
New Member
Join Date: Feb 2020
Posts: 28
Rep Power: 6 |
Quote:
1.Images have been re-uploaded, I hope it works; 2.For the thread_loop, I also can’t understand(actually, I think it is wrong here), but I cannot find a way to select the target wall to apply the calculation macro, can you give me a hint about that? Thx! Figure1 Figure2 Last edited by Silence; May 24, 2021 at 11:14. Reason: add some pictures |
||
May 24, 2021, 11:30 |
|
#5 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Code:
#include "udf.h" DEFINE_ON_DEMAND(Face_area) { face_t face; Thread* thread; Domain* domain; domain = Get_Domain(1); int zone_id = 10; thread = Lookup_Thread(domain, zone_id); real NV_VEC(va); /* Array for storing area vector */ real Area = 0; begin_f_loop(face, thread) { F_AREA(va, face, thread); /* Obtain the area vector */ Area = NV_MAG(va); /* Obtain area magnitude */ } Message("Area of top surface is %f", Area); } I did not test my code, so look for warnings/errors.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build". |
|
May 24, 2021, 12:04 |
|
#6 |
Member
Join Date: Jan 2018
Posts: 34
Rep Power: 8 |
isn't NV_MAG(va) would give area of just one cell, and should be
+=NV_mag(va) instead? |
|
May 24, 2021, 12:24 |
|
#7 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Yes, I missed that!
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build". |
|
May 25, 2021, 00:17 |
|
#8 | |
New Member
Join Date: Feb 2020
Posts: 28
Rep Power: 6 |
Quote:
1.First, I think it is wrong; 2.Second, why there exists 5 results? The ‘message’ syntax is actually out of the loop, I can’t understand this, can you give me your advice? Thanks! Regards, Silence Figure 3 |
||
May 25, 2021, 00:20 |
|
#9 | |
New Member
Join Date: Feb 2020
Posts: 28
Rep Power: 6 |
Quote:
1.First, I think it is wrong; 2.second, why there exists 5 result? The ‘message’ syntax is actually out of the loop, I can’t understand this, can you give me your advice? Thanks! Regards, Silence Figure 3 |
||
May 25, 2021, 01:34 |
|
#10 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
You are running in paralel mode. Your simulation is split over five nodes, each nodes calculate its own area. You have to let them communicate.
Check manual for the syntax, I don't remember.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build". |
|
May 25, 2021, 04:18 |
|
#11 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Code:
#include "udf.h" DEFINE_ON_DEMAND(Face_area) { face_t face; Thread* thread; Domain* domain; domain = Get_Domain(1); int zone_id = 10; thread = Lookup_Thread(domain, zone_id); real NV_VEC(va); /* Array for storing area vector */ real Area = 0; begin_f_loop(face, thread) { F_AREA(va, face, thread); /* Obtain the area vector */ Area += NV_MAG(va); /* Obtain area magnitude */ } #IF RP_NODE Area = PRF_GRSUM1(Area); #ENDIF Message0("Area of top surface is %f", Area); }
__________________
best regards ****************************** press LIKE if this message was helpful |
|
Tags |
loop over face, macros, udf code |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to calculate the area of a boundary in UDF? | peter | FLUENT | 2 | May 31, 2021 21:54 |
[ICEM] Problems with coedge curves and surfaces | tommymoose | ANSYS Meshing & Geometry | 6 | December 1, 2020 12:12 |
[OpenFOAM] Surface field value gives incorrect area | McReijen | ParaView | 0 | July 18, 2018 06:28 |
UDF Defining VOF Free Surface at Outlet | Alex | Fluent UDF and Scheme Programming | 13 | August 8, 2012 17:50 |
report surface area WITHOUT solit | Ralf Schmidt | FLUENT | 1 | June 1, 2007 11:23 |