How to calculate area of particular surface through UDF?
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 https://i.loli.net/2021/05/19/U4eYWEP2rqc17f9.png Figure 1 https://i.loli.net/2021/05/19/PqpfEe5AzyOFTKG.png 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) } } |
The images don't show up for me....
I don't understand the thread_loop_f loop here. |
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 https://www.cfd-online.com/Forums/fl...using-udf.html |
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! https://i.loli.net/2021/05/24/qH7mWSc9GodCJpz.png Figure1 https://i.loli.net/2021/05/24/w2zMJjgpdUF7fcE.png Figure2 |
Code:
#include "udf.h" I did not test my code, so look for warnings/errors. |
isn't NV_MAG(va) would give area of just one cell, and should be
+=NV_mag(va) instead? |
Yes, I missed that!
|
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 https://i.loli.net/2021/05/25/8fZk2IU9lgrvBTN.png Figure 3 |
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 https://i.loli.net/2021/05/25/8fZk2IU9lgrvBTN.png Figure 3 |
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. |
Code:
#include "udf.h" |
All times are GMT -4. The time now is 06:30. |