From bfd30ea00613398858072dbce5fbe42c0050e77a Mon Sep 17 00:00:00 2001 From: laurence Date: Fri, 5 Apr 2013 15:28:00 +0100 Subject: [PATCH] ENH: Expand triSurfaceSearch and add triSurfaceRegionSearch + Move most of the octree searching functionality from triSurfaceMesh into triSurfaceSearch. Much of it was duplicated anyway. + Add triSurfaceRegionSearch, which constructs an octree for each region in a surface and performs searches on specified regions only. --- .../primitiveMesh/PatchTools/PatchTools.H | 17 +- .../PatchTools/PatchToolsSearch.C | 45 +- .../meshes/primitiveShapes/plane/plane.H | 16 +- src/meshTools/Make/files | 1 + .../searchableSurface/triSurfaceMesh.C | 423 ++---------------- .../searchableSurface/triSurfaceMesh.H | 54 +-- .../orientedSurface/orientedSurface.C | 29 +- .../triSurfaceSearch/triSurfaceRegionSearch.C | 246 ++++++++++ .../triSurfaceSearch/triSurfaceRegionSearch.H | 144 ++++++ .../triSurfaceSearch/triSurfaceSearch.C | 363 ++++++++------- .../triSurfaceSearch/triSurfaceSearch.H | 92 ++-- .../twoDPointCorrector/twoDPointCorrector.H | 4 +- .../distributedTriSurfaceMesh.C | 5 +- 13 files changed, 791 insertions(+), 648 deletions(-) create mode 100644 src/meshTools/triSurface/triSurfaceSearch/triSurfaceRegionSearch.C create mode 100644 src/meshTools/triSurface/triSurfaceSearch/triSurfaceRegionSearch.H diff --git a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.H b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.H index 36e792326d..e0800452a1 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.H +++ b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.H @@ -54,6 +54,7 @@ namespace Foam class polyMesh; class PackedBoolList; +class boundBox; /*---------------------------------------------------------------------------*\ Class PatchTools Declaration @@ -140,6 +141,21 @@ public: labelList& faceMap ); + //- + template + < + class Face, + template class FaceList, + class PointField, + class PointType + > + static void calcBounds + ( + const PrimitivePatch& p, + boundBox& bb, + label& nPoints + ); + //- Return edge-face addressing sorted by angle around the edge. // Orientation is anticlockwise looking from edge.vec(localPoints()) template @@ -271,7 +287,6 @@ public: List& mergedFaces, labelList& pointMergeMap ); - }; diff --git a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSearch.C b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSearch.C index 4fc6ca13c7..8ecd790b1e 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSearch.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSearch.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,6 +27,8 @@ Description \*---------------------------------------------------------------------------*/ #include "PatchTools.H" +#include "PackedBoolList.H" +#include "boundBox.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -222,4 +224,45 @@ Foam::PatchTools::subsetMap } +template +< + class Face, + template class FaceList, + class PointField, + class PointType +> +void Foam::PatchTools::calcBounds +( + const PrimitivePatch& p, + boundBox& bb, + label& nPoints +) +{ + // Unfortunately nPoints constructs meshPoints() so do compact version + // ourselves + const PointField& points = p.points(); + + PackedBoolList pointIsUsed(points.size()); + + nPoints = 0; + bb = boundBox::invertedBox; + + forAll(p, faceI) + { + const Face& f = p[faceI]; + + forAll(f, fp) + { + label pointI = f[fp]; + if (pointIsUsed.set(pointI, 1u)) + { + bb.min() = ::Foam::min(bb.min(), points[pointI]); + bb.max() = ::Foam::max(bb.max(), points[pointI]); + nPoints++; + } + } + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H index 3d4e25211c..3a47e6bf2e 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,7 +26,7 @@ Class Description Geometric class that creates a 2D plane and can return the intersection - point between a line and the plane. + point between a line and the plane. SourceFiles plane.C @@ -62,6 +62,14 @@ class plane { public: + //- Side of the plane + enum side + { + NORMAL, + FLIP + }; + + //- A direction and a reference point class ray { @@ -182,6 +190,10 @@ public: //- Return the cutting point between this plane and two other planes point planePlaneIntersect(const plane&, const plane&) const; + //- Return the side of the plane that the point is on. + // If the point is on the plane, then returns NORMAL. + side sideOfPlane(const point& p) const; + //- Write to dictionary void writeDict(Ostream&) const; diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index f11e6fc471..91bbbc11fd 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -160,6 +160,7 @@ $(intersectedSurface)/intersectedSurface.C $(intersectedSurface)/edgeSurface.C triSurface/triSurfaceSearch/triSurfaceSearch.C +triSurface/triSurfaceSearch/triSurfaceRegionSearch.C triSurface/triangleFuncs/triangleFuncs.C triSurface/surfaceFeatures/surfaceFeatures.C triSurface/triSurfaceTools/triSurfaceTools.C diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.C b/src/meshTools/searchableSurface/triSurfaceMesh.C index e2e974fd09..f95f84c3f4 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.C +++ b/src/meshTools/searchableSurface/triSurfaceMesh.C @@ -29,7 +29,7 @@ License #include "EdgeMap.H" #include "triSurfaceFields.H" #include "Time.H" -#include "PackedBoolList.H" +#include "PatchTools.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -218,48 +218,6 @@ bool Foam::triSurfaceMesh::isSurfaceClosed() const } -void Foam::triSurfaceMesh::calcBounds(boundBox& bb, label& nPoints) const -{ - const triSurface& s = static_cast(*this); - - calcBounds(s, bb, nPoints); -} - - -template -void Foam::triSurfaceMesh::calcBounds -( - const PatchType& patch, - boundBox& bb, - label& nPoints -) const -{ - // Unfortunately nPoints constructs meshPoints() so do compact version - // ourselves - - PackedBoolList pointIsUsed(points()().size()); - - nPoints = 0; - bb = boundBox::invertedBox; - - forAll(patch, faceI) - { - const typename PatchType::FaceType& f = patch[faceI]; - - forAll(f, fp) - { - label pointI = f[fp]; - if (pointIsUsed.set(pointI, 1u)) - { - bb.min() = ::Foam::min(bb.min(), points()()[pointI]); - bb.max() = ::Foam::max(bb.max(), points()()[pointI]); - nPoints++; - } - } - } -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const triSurface& s) @@ -279,9 +237,8 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const triSurface& s) ) ), triSurface(s), - tolerance_(indexedOctree::perturbTol()), + triSurfaceRegionSearch(s), minQuality_(-1), - maxTreeDepth_(10), surfaceClosed_(-1) { bounds() = boundBox(points()); @@ -326,9 +283,8 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io) searchableSurface::objectPath() ) ), - tolerance_(indexedOctree::perturbTol()), + triSurfaceRegionSearch(static_cast(*this)), minQuality_(-1), - maxTreeDepth_(10), surfaceClosed_(-1) { bounds() = boundBox(points()); @@ -376,9 +332,8 @@ Foam::triSurfaceMesh::triSurfaceMesh searchableSurface::objectPath() ) ), - tolerance_(indexedOctree::perturbTol()), + triSurfaceRegionSearch(static_cast(*this), dict), minQuality_(-1), - maxTreeDepth_(10), surfaceClosed_(-1) { scalar scaleFactor = 0; @@ -394,13 +349,6 @@ Foam::triSurfaceMesh::triSurfaceMesh bounds() = boundBox(points()); - // Have optional non-standard search tolerance for gappy surfaces. - if (dict.readIfPresent("tolerance", tolerance_) && tolerance_ > 0) - { - Info<< searchableSurface::name() << " : using intersection tolerance " - << tolerance_ << endl; - } - // Have optional minimum quality for normal calculation if (dict.readIfPresent("minQuality", minQuality_) && minQuality_ > 0) { @@ -408,13 +356,6 @@ Foam::triSurfaceMesh::triSurfaceMesh << " : ignoring triangles with quality < " << minQuality_ << " for normals calculation." << endl; } - - // Have optional non-standard tree-depth to limit storage. - if (dict.readIfPresent("maxTreeDepth", maxTreeDepth_) && maxTreeDepth_ > 0) - { - Info<< searchableSurface::name() << " : using maximum tree depth " - << maxTreeDepth_ << endl; - } } @@ -428,7 +369,7 @@ Foam::triSurfaceMesh::~triSurfaceMesh() void Foam::triSurfaceMesh::clearOut() { - tree_.clear(); + triSurfaceRegionSearch::clearOut(); edgeTree_.clear(); triSurface::clearOut(); } @@ -470,176 +411,12 @@ bool Foam::triSurfaceMesh::overlaps(const boundBox& bb) const void Foam::triSurfaceMesh::movePoints(const pointField& newPoints) { - tree_.clear(); + triSurfaceRegionSearch::clearOut(); edgeTree_.clear(); triSurface::movePoints(newPoints); } -const Foam::indexedOctree& -Foam::triSurfaceMesh::tree() const -{ - if (tree_.empty()) - { - // Calculate bb without constructing local point numbering. - treeBoundBox bb; - label nPoints; - calcBounds(bb, nPoints); - - if (nPoints != points()().size()) - { - WarningIn("triSurfaceMesh::tree() const") - << "Surface " << searchableSurface::name() - << " does not have compact point numbering." - << " Of " << points()().size() << " only " << nPoints - << " are used. This might give problems in some routines." - << endl; - } - - - // Random number generator. Bit dodgy since not exactly random ;-) - Random rndGen(65431); - - // 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); - - scalar oldTol = indexedOctree::perturbTol(); - indexedOctree::perturbTol() = tolerance_; - - tree_.reset - ( - new indexedOctree - ( - treeDataTriSurface(true, *this, tolerance_), - bb, - maxTreeDepth_, // maxLevel - 10, // leafsize - 3.0 // duplicity - ) - ); - - indexedOctree::perturbTol() = oldTol; - } - - return tree_(); -} - - -const Foam::PtrList -< - Foam::indexedOctree - < - Foam::triSurfaceMesh::treeDataTriSurfacePrimitivePatch - > ->& -Foam::triSurfaceMesh::treeByRegion() const -{ - if (treeByRegion_.empty()) - { - Map