Commit a456e9ae authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: relocate nonCoupledBoundaryTree into meshSearcher

- use point::uniform in more places
parent 3835734f
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -68,8 +69,8 @@ int main(int argc, char *argv[])
efem.points()
);
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
labelList allEdges(identity(efem.edges().size()));
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -1983,8 +1984,8 @@ void Foam::conformalVoronoiMesh::buildEdgeLocationTree
geometryToConformTo_.globalBounds().extend(rndGen_, 1e-4)
);
overallBb.min() -= Foam::point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
overallBb.max() += Foam::point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
overallBb.min() -= Foam::point::uniform(ROOTVSMALL);
overallBb.max() += Foam::point::uniform(ROOTVSMALL);
edgeLocationTreePtr_.reset
(
......@@ -2010,8 +2011,8 @@ void Foam::conformalVoronoiMesh::buildSurfacePtLocationTree
geometryToConformTo_.globalBounds().extend(rndGen_, 1e-4)
);
overallBb.min() -= Foam::point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
overallBb.max() += Foam::point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
overallBb.min() -= Foam::point::uniform(ROOTVSMALL);
overallBb.max() += Foam::point::uniform(ROOTVSMALL);
surfacePtLocationTreePtr_.reset
(
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2014-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -180,8 +181,8 @@ void createBoundaryEdgeTrees
treeBoundBox(UList<point>(surf.localPoints())).extend(rndGen, 1e-4)
);
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
bEdgeTrees.set
(
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -48,12 +49,17 @@ bool Foam::matchPoints
point compareOrigin = origin;
if (origin == point(VGREAT, VGREAT, VGREAT))
if (origin == point::max)
{
if (pts1.size())
{
compareOrigin = sum(pts1)/pts1.size();
}
else
{
// Unusable, but avoid comparison with VGREAT!
compareOrigin = point::zero;
}
}
SortableList<scalar> pts0MagSqr(magSqr(pts0 - compareOrigin));
......@@ -160,12 +166,17 @@ bool Foam::matchPoints
point compareOrigin = origin;
if (origin == point(VGREAT, VGREAT, VGREAT))
if (origin == point::max)
{
if (pts1.size())
{
compareOrigin = sum(pts1)/pts1.size();
}
else
{
// Unusable, but avoid comparison with VGREAT!
compareOrigin = point::zero;
}
}
SortableList<scalar> pts0MagSqr(magSqr(pts0 - compareOrigin));
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2012 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -58,7 +59,7 @@ bool matchPoints
const UList<scalar>& matchDistance,
const bool verbose,
labelList& from0To1,
const point& origin = point::zero
const point& origin = point::zero //!< point::max = use average origin
);
......@@ -75,7 +76,7 @@ bool matchPoints
const UList<scalar>& matchDistance,
const bool verbose,
labelList& from0To1,
const point& origin = point::zero
const point& origin = point::zero //!< point::max = use average origin
);
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -901,8 +901,8 @@ Foam::polyMesh::cellTree() const
Random rndGen(261782);
overallBb = overallBb.extend(rndGen, 1e-4);
overallBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
overallBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
overallBb.min() -= point::uniform(ROOTVSMALL);
overallBb.max() += point::uniform(ROOTVSMALL);
cellTreePtr_.reset
(
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -297,8 +298,8 @@ void Foam::refinementFeatures::buildTrees(const label featI)
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4);
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
edgeTrees_.set
(
......@@ -438,8 +439,8 @@ Foam::refinementFeatures::regionEdgeTrees() const
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4);
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
trees.set
(
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -3174,8 +3174,8 @@ void Foam::snappySnapDriver::reverseAttractMeshPoints
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4);
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
}
// Collect candidate points for attraction
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -848,8 +848,8 @@ Foam::extendedEdgeMesh::pointTree() const
treeBoundBox(points()).extend(rndGen, 1e-4)
);
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
const labelList featurePointLabels = identity(nonFeatureStart_);
......@@ -888,8 +888,8 @@ Foam::extendedEdgeMesh::edgeTree() const
treeBoundBox(points()).extend(rndGen, 1e-4)
);
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
labelList allEdges(identity(edges().size()));
......@@ -932,8 +932,8 @@ Foam::extendedEdgeMesh::edgeTreesByType() const
treeBoundBox(points()).extend(rndGen, 1e-4)
);
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
labelListList sliceEdges(nEdgeTypes);
......
......@@ -294,8 +294,8 @@ void Foam::mappedPatchBase::findSamples
1e-4
)
);
patchBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
patchBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
patchBb.min() -= point::uniform(ROOTVSMALL);
patchBb.max() += point::uniform(ROOTVSMALL);
indexedOctree<treeDataFace> boundaryTree
(
......@@ -366,8 +366,8 @@ void Foam::mappedPatchBase::findSamples
1e-4
)
);
patchBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
patchBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
patchBb.min() -= point::uniform(ROOTVSMALL);
patchBb.max() += point::uniform(ROOTVSMALL);
indexedOctree<treeDataPoint> boundaryTree
(
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2018 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -603,30 +603,33 @@ Foam::meshSearch::~meshSearch()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::indexedOctree<Foam::treeDataFace>&
Foam::meshSearch::boundaryTree() const
const Foam::treeBoundBox& Foam::meshSearch::dataBoundBox() const
{
if (!boundaryTreePtr_.valid())
if (!overallBbPtr_.valid())
{
//
// Construct tree
//
Random rndGen(261782);
overallBbPtr_.reset
(
new treeBoundBox(mesh_.points())
);
if (!overallBbPtr_.valid())
{
Random rndGen(261782);
overallBbPtr_.reset
(
new treeBoundBox(mesh_.points())
);
treeBoundBox& overallBb = overallBbPtr_();
treeBoundBox& overallBb = overallBbPtr_();
// Extend slightly and make 3D
overallBb = overallBb.extend(rndGen, 1e-4);
overallBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
overallBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
}
// Extend slightly and make 3D
overallBb = overallBb.extend(rndGen, 1e-4);
overallBb.min() -= point::uniform(ROOTVSMALL);
overallBb.max() += point::uniform(ROOTVSMALL);
}
return *overallBbPtr_;
}
const Foam::indexedOctree<Foam::treeDataFace>&
Foam::meshSearch::boundaryTree() const
{
if (!boundaryTreePtr_.valid())
{
// All boundary faces (not just walls)
labelList bndFaces
(
......@@ -643,7 +646,7 @@ Foam::meshSearch::boundaryTree() const
mesh_,
bndFaces // boundary faces only
),
overallBbPtr_(), // overall search domain
dataBoundBox(), // overall search domain
8, // maxLevel
10, // leafsize
3.0 // duplicity
......@@ -655,30 +658,57 @@ Foam::meshSearch::boundaryTree() const
}
const Foam::indexedOctree<Foam::treeDataCell>&
Foam::meshSearch::cellTree() const
const Foam::indexedOctree<Foam::treeDataFace>&
Foam::meshSearch::nonCoupledBoundaryTree() const
{
if (!cellTreePtr_.valid())
if (!nonCoupledBoundaryTreePtr_.valid())
{
//
// Construct tree
//
// All non-coupled boundary faces (not just walls)
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
labelList bndFaces(mesh_.nBoundaryFaces());
if (!overallBbPtr_.valid())
label bndi = 0;
for (const polyPatch& pp : patches)
{
Random rndGen(261782);
overallBbPtr_.reset
if (!pp.coupled())
{
forAll(pp, i)
{
bndFaces[bndi++] = pp.start()+i;
}
}
}
bndFaces.setSize(bndi);
nonCoupledBoundaryTreePtr_.reset
(
new indexedOctree<treeDataFace>
(
new treeBoundBox(mesh_.points())
);
treeDataFace // all information needed to search faces
(
false, // do not cache bb
mesh_,
bndFaces // boundary faces only
),
dataBoundBox(), // overall search domain
8, // maxLevel
10, // leafsize
3.0 // duplicity
)
);
}
treeBoundBox& overallBb = overallBbPtr_();
// Extend slightly and make 3D
overallBb = overallBb.extend(rndGen, 1e-4);
overallBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
overallBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
}
return *nonCoupledBoundaryTreePtr_;
}
const Foam::indexedOctree<Foam::treeDataCell>&
Foam::meshSearch::cellTree() const
{
if (!cellTreePtr_.valid())
{
cellTreePtr_.reset
(
new indexedOctree<treeDataCell>
......@@ -689,7 +719,7 @@ Foam::meshSearch::cellTree() const
mesh_,
cellDecompMode_ // cell decomposition mode for inside tests
),
overallBbPtr_(),
dataBoundBox(), // overall search domain
8, // maxLevel
10, // leafsize
6.0 // duplicity
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2018 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -48,7 +48,7 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward Declarations
class treeDataCell;
class treeDataFace;
template<class Type> class indexedOctree;
......@@ -60,7 +60,7 @@ class treeBoundBox;
class meshSearch
{
// Private data
// Private Data
//- Reference to mesh
const polyMesh& mesh_;
......@@ -73,6 +73,7 @@ class meshSearch
//- Demand driven octrees
mutable autoPtr<indexedOctree<treeDataFace>> boundaryTreePtr_;
mutable autoPtr<indexedOctree<treeDataFace>> nonCoupledBoundaryTreePtr_;
mutable autoPtr<indexedOctree<treeDataCell>> cellTreePtr_;
......@@ -98,6 +99,12 @@ class meshSearch
);
// Points
//- Demand-driven bounding box for mesh points
const treeBoundBox& dataBoundBox() const;
// Cells
//- Nearest cell centre using octree
......@@ -127,7 +134,6 @@ class meshSearch
label findNearestFaceWalk(const point&, const label) const;
// Boundary faces
//- Walk from seed to find nearest boundary face. Gets stuck in
......@@ -148,11 +154,11 @@ class meshSearch
public:
// Declare name of the class and its debug switch
//- Declare type-name (with debug switch)
ClassName("meshSearch");
// Static data members
// Static Data
//- Tolerance on linear dimensions
static scalar tol_;
......@@ -160,17 +166,17 @@ public:
// Constructors
//- Construct from components. Constructs bb slightly bigger than
// mesh points bb.
meshSearch
//- Construct from components.
// Constructs bb slightly bigger than mesh points bb.
explicit meshSearch
(
const polyMesh& mesh,
const polyMesh::cellDecomposition = polyMesh::CELL_TETS
);
//- Construct with a custom bounding box. Any mesh element outside
// bb will not be found. Up to user to make sure bb
// extends slightly beyond wanted elements.
//- Construct with a custom bounding box.
// Any mesh element outside bb will not be found.
// Up to user to ensure bb extends slightly beyond wanted elements.
meshSearch
(
const polyMesh& mesh,
......@@ -178,6 +184,7 @@ public:
const polyMesh::cellDecomposition = polyMesh::CELL_TETS
);
//- Destructor
~meshSearch();
......@@ -196,11 +203,14 @@ public:
return cellDecompMode_;
}
//- Get (demand driven) reference to octree holding all
// boundary faces
//- Demand-driven reference to octree holding all boundary faces
const indexedOctree<treeDataFace>& boundaryTree() const;
//- Get (demand driven) reference to octree holding all cells
//- Demand-driven reference to octree holding all
//- non-coupled boundary faces
const indexedOctree<treeDataFace>& nonCoupledBoundaryTree() const;
//- Demand-driven reference to octree holding all cells
const indexedOctree<treeDataCell>& cellTree() const;
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -100,8 +100,8 @@ Foam::searchableExtrudedCircle::searchableExtrudedCircle
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
edgeTree_.reset
(
......
......@@ -759,8 +759,8 @@ Foam::triSurfaceMesh::edgeTree() const
// geometry there are less face/edge aligned items.
bb = bb.extend(rndGen, 1e-4);
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015,2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -157,8 +157,8 @@ Foam::triSurfaceRegionSearch::treeByRegion() const
// on symmetric geometry there are fewer face/edge
// aligned items.
bb = bb.extend(rndGen, 1e-4);
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
}
treeByRegion_.set
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation