CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Be careful when calling meshSearch::findNearestFace with a seed face (https://www.cfd-online.com/Forums/openfoam-programming-development/206426-careful-when-calling-meshsearch-findnearestface-seed-face.html)

t.oliveira September 6, 2018 08:38

Be careful when calling meshSearch::findNearestFace with a seed face
 
1 Attachment(s)
Hi,

I was using meshSearch::findNearestFace (OpenFOAM v5) to find a face label from its coordinates. The function declaration is
Code:

label findNearestFace
(
    const point& location,
    const label seedFacei = -1,
    const bool useTreeSearch = true
) const;

I was providing as seedFacei the label of a nearby face, in the hope of speeding up the search. However, in some specific cases, I was not getting the results I expected.

If seedFacei != -1 is provided, findNearestFace calls findNearestFaceWalk. From what I understood reading findNearestFaceWalk's implementation, it does not find the correct face in cases such as the one below.

Consider the attached figure. 'X' marks the location and 'f' is the seed face. findNearestFaceWalk does the following:
Code:

distanceSqr = distance between 'X' and the center of 'f';
for every face of cell A and cell B
{
    if ( (distance between 'X' and the center of face) < distanceSqr )
    {
        face is the new best candidate for nearest face;
        distanceSqr = (distance between 'X' and the center of face);
    }

}

As you can see in the figure, no other face center of A or B is closer to 'X' than the center of face f. As a result, the face over which 'X' lies is never found.

I decided not to use seedFacei when calling findNearestFace. It defaults to seedFacei=-1 and, if useTreeSearch is true (its default value), findNearestFace uses findNearestFaceTree instead of findNearestFaceWalk. I did not check if the performance got worse. The result of the search is now as expected.

Kind regards,
Thomas


All times are GMT -4. The time now is 22:01.