CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

How to calculate area of particular surface through UDF?

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By pakk
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 19, 2021, 11:44
Default How to calculate area of particular surface through UDF?
  #1
New Member
 
Join Date: Feb 2020
Posts: 28
Rep Power: 6
Silence is on a distinguished road
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)
}
}
Silence is offline   Reply With Quote

Old   May 19, 2021, 18:57
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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".
pakk is offline   Reply With Quote

Old   May 19, 2021, 21:49
Default
  #3
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
AlexanderZ is offline   Reply With Quote

Old   May 24, 2021, 10:54
Smile
  #4
New Member
 
Join Date: Feb 2020
Posts: 28
Rep Power: 6
Silence is on a distinguished road
Quote:
Originally Posted by pakk View Post
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!


Figure1


Figure2

Last edited by Silence; May 24, 2021 at 11:14. Reason: add some pictures
Silence is offline   Reply With Quote

Old   May 24, 2021, 11:30
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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.
__________________
"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".
pakk is offline   Reply With Quote

Old   May 24, 2021, 12:04
Default
  #6
Member
 
Join Date: Jan 2018
Posts: 34
Rep Power: 8
UchihaMadara is on a distinguished road
isn't NV_MAG(va) would give area of just one cell, and should be
+=NV_mag(va) instead?
UchihaMadara is offline   Reply With Quote

Old   May 24, 2021, 12:24
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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".
pakk is offline   Reply With Quote

Old   May 25, 2021, 00:17
Smile
  #8
New Member
 
Join Date: Feb 2020
Posts: 28
Rep Power: 6
Silence is on a distinguished road
Quote:
Originally Posted by UchihaMadara View Post
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


Figure 3
Silence is offline   Reply With Quote

Old   May 25, 2021, 00:20
Smile
  #9
New Member
 
Join Date: Feb 2020
Posts: 28
Rep Power: 6
Silence is on a distinguished road
Quote:
Originally Posted by pakk View Post
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

Figure 3
Silence is offline   Reply With Quote

Old   May 25, 2021, 01:34
Default
  #10
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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.
Silence likes this.
__________________
"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".
pakk is offline   Reply With Quote

Old   May 25, 2021, 04:18
Default
  #11
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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);
}
Silence likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Reply

Tags
loop over face, macros, udf code


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 13:38.