CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   How to calculate area of particular surface through UDF? (https://www.cfd-online.com/Forums/fluent-udf/236213-how-calculate-area-particular-surface-through-udf.html)

Silence May 19, 2021 10:44

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

pakk May 19, 2021 17:57

The images don't show up for me....

I don't understand the thread_loop_f loop here.

AlexanderZ May 19, 2021 20:49

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

Silence May 24, 2021 09:54

Quote:

Originally Posted by pakk (Post 804211)
The images don't show up for me....

I don't understand the thread_loop_f loop here.

Hello, pakk, thanks for the reply:
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

pakk May 24, 2021 10:30

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 think you must have had some compilation error, because you used variable nc that was never declared.

I did not test my code, so look for warnings/errors.

UchihaMadara May 24, 2021 11:04

isn't NV_MAG(va) would give area of just one cell, and should be
+=NV_mag(va) instead?

pakk May 24, 2021 11:24

Yes, I missed that!

Silence May 24, 2021 23:17

Quote:

Originally Posted by UchihaMadara (Post 804539)
isn't NV_MAG(va) would give area of just one cell, and should be
+=NV_mag(va) instead?

Hi, UchihaMadara, you are right, '=' should be replaced by "+=", but I am confused about the UDF calculation result, shown in Figure 3, compared with report result(I think it is the right answer), for, UDF result:
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

Silence May 24, 2021 23:20

Quote:

Originally Posted by pakk (Post 804536)
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 think you must have had some compilation error, because you used variable nc that was never declared.

I did not test my code, so look for warnings/errors.

Thanks for your help, pakk, now, UDF can run correctly(here, 'Area = NV_MAG(va)' becomes 'Area += NV_MAG(va)'), but I am confused about the correctness of UDF result, compared with report result(I think it is the right answer), for, UDF result:
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

pakk May 25, 2021 00:34

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.

AlexanderZ May 25, 2021 03:18

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);
}



All times are GMT -4. The time now is 06:30.