Skip to content
Snippets Groups Projects
Commit 8b5840d0 authored by mattijs's avatar mattijs
Browse files

ENH: mergePoints.C : enforce correct use of merge tolerance

parent 83a2a831
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -61,11 +61,26 @@ bool Foam::mergePoints ...@@ -61,11 +61,26 @@ bool Foam::mergePoints
return false; return false;
} }
// We're comparing distance squared to origin first.
// Say if starting from two close points:
// x, y, z
// x+mergeTol, y+mergeTol, z+mergeTol
// Then the magSqr of both will be
// x^2+y^2+z^2
// x^2+y^2+z^2 + 2*mergeTol*(x+z+y) + mergeTol^2*...
// so the difference will be 2*mergeTol*(x+y+z)
const scalar mergeTolSqr = sqr(mergeTol); const scalar mergeTolSqr = sqr(mergeTol);
// Sort points by magSqr // Sort points by magSqr
SortableList<scalar> sortedMagSqr(magSqr(points - compareOrigin)); const pointField d(points - compareOrigin);
SortableList<scalar> sortedMagSqr(magSqr(d));
scalarField sortedTol(points.size());
forAll(sortedMagSqr.indices(), sortI)
{
const point& pt = d[sortedMagSqr.indices()[sortI]];
sortedTol[sortI] = 2*mergeTol*(mag(pt.x())+mag(pt.y())+mag(pt.z()));
}
bool hasMerged = false; bool hasMerged = false;
...@@ -94,7 +109,7 @@ bool Foam::mergePoints ...@@ -94,7 +109,7 @@ bool Foam::mergePoints
( (
sortedMagSqr[prevSortI] sortedMagSqr[prevSortI]
- sortedMagSqr[sortI] - sortedMagSqr[sortI]
) <= mergeTolSqr; ) <= sortedTol[sortI];
prevSortI-- prevSortI--
) )
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment