CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

How to use nearestPoint()?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By einstein_zee

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 28, 2019, 20:57
Default How to use nearestPoint()?
  #1
New Member
 
samuel
Join Date: Oct 2019
Posts: 15
Rep Power: 6
Samuel Twain is on a distinguished road
Dear all:
I am wondering how openfoam calculates y (not yPlus) which is (maybe) the shorstest distance from the cell center to the wall. And I find a function nearestPoint() which maybe is to calculate y as following:
Foam::scalar Foam::cellDistFuncs::smallestDist
(
...
) const
{
...
for (label wallFacei = 0; wallFacei < nWallFaces; wallFacei++)
{
label patchFacei = wallFaces[wallFacei];

pointHit curHit = patch[patchFacei].nearestPoint(p, points);

if (curHit.distance() < minDist)
{
minDist = curHit.distance();
minFacei = patch.start() + patchFacei;
}
}

return minDist;
}
But the source code of nearestPoint() is difficult for me to find out how nearestPoint() calculates. Could anyone please explain how nearstPoint() works or share the materials related to it?
Each reply will be appreciated.
Thanks
Samuel
Samuel Twain is offline   Reply With Quote

Old   October 29, 2019, 05:39
Default
  #2
Member
 
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 93
Rep Power: 14
einstein_zee is on a distinguished road
Quote:
Originally Posted by Samuel Twain View Post
Dear all:
I am wondering how openfoam calculates y (not yPlus) which is (maybe) the shorstest distance from the cell center to the wall. And I find a function nearestPoint() which maybe is to calculate y as following:
Foam::scalar Foam::cellDistFuncs::smallestDist
(
...
) const
{
...
for (label wallFacei = 0; wallFacei < nWallFaces; wallFacei++)
{
label patchFacei = wallFaces[wallFacei];

pointHit curHit = patch[patchFacei].nearestPoint(p, points);

if (curHit.distance() < minDist)
{
minDist = curHit.distance();
minFacei = patch.start() + patchFacei;
}
}

return minDist;
}
But the source code of nearestPoint() is difficult for me to find out how nearestPoint() calculates. Could anyone please explain how nearstPoint() works or share the materials related to it?
Each reply will be appreciated.
Thanks
Samuel
Hii there,

I just looked at the code and it seems to be messy to track stuff. However, I may give you at least what I understood at first glance . The version of function nearestPoint with 2 arguments of point and pointField can be found here (https://github.com/OpenFOAM/OpenFOAM...Intersection.C). You should follow the code from line 198. From what I understood, the aim here is to do the calculations with an arbitrary point and a triangulated face. So, if your face is already a triangle it will do the calculations immediately, and if not it will try to triangulate the face first and then do the calculations. Note that here face means each of single faces which constructs the whole wallFace.

And the piece of code I think you are interested to see is this one (https://github.com/OpenFOAM/OpenFOAM...le/triangleI.H). You may follow the code from line 516 to see how this calculation is done with an arbitrary point and a triangulated face. This ref. is also given there (Real-time collision detection, Christer Ericson, 2005, p136-142)
Hope this helps...
Samuel Twain likes this.
einstein_zee is offline   Reply With Quote

Old   October 29, 2019, 06:36
Default
  #3
New Member
 
samuel
Join Date: Oct 2019
Posts: 15
Rep Power: 6
Samuel Twain is on a distinguished road
Quote:
Originally Posted by einstein_zee View Post
Hii there,

I just looked at the code and it seems to be messy to track stuff. However, I may give you at least what I understood at first glance . The version of function nearestPoint with 2 arguments of point and pointField can be found here (https://github.com/OpenFOAM/OpenFOAM...Intersection.C). You should follow the code from line 198. From what I understood, the aim here is to do the calculations with an arbitrary point and a triangulated face. So, if your face is already a triangle it will do the calculations immediately, and if not it will try to triangulate the face first and then do the calculations. Note that here face means each of single faces which constructs the whole wallFace.

And the piece of code I think you are interested to see is this one (https://github.com/OpenFOAM/OpenFOAM...le/triangleI.H). You may follow the code from line 516 to see how this calculation is done with an arbitrary point and a triangulated face. This ref. is also given there (Real-time collision detection, Christer Ericson, 2005, p136-142)
Hope this helps...
Thanks a lot!!! Following your suggestion, I looked at the code and looked up to "Real-time collision detection". I think I have understood what nearestPoint() does. nearestPoint() return the point on the triangulated face which is nearest to a given point( that used to be the cell center). The nearest point might be the vertex, lie on the edge or lie in the face( this algorithm can be found in "Real-time collision detection" ). If this face isn't triangulated. It will be decomposed to some triangulated faces.
Thank you again!
Samuel Twain is offline   Reply With Quote

Reply

Tags
nearestpoint


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



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