From 3e0dfb6abdd664d7ffae334872519f9b698ea160 Mon Sep 17 00:00:00 2001 From: graham <graham.macpherson@strath.ac.uk> Date: Wed, 8 Apr 2009 14:53:50 +0100 Subject: [PATCH] Added a boundBox to searchableSurface and implemented in all derived types except searchablePlane, and only as an approximation in searchableCylinder. Added bounds() function to searchableSurfacesQueries for the overall bounds of a subset of surfaces. Added closedTriSurfaceMesh type, derived from triSurfaceMesh, except forcing hasVolumeType = true to allow geometrically but not topologically closed or almost closed surfaces to query volumeType. --- src/meshTools/Make/files | 1 + .../searchableSurface/closedTriSurfaceMesh.C | 71 +++++++++++ .../searchableSurface/closedTriSurfaceMesh.H | 112 ++++++++++++++++++ .../searchableSurface/searchableBox.C | 8 +- .../searchableSurface/searchableCylinder.C | 24 +++- .../searchableSurface/searchableCylinder.H | 2 + .../searchableSurface/searchablePlate.C | 4 + .../searchableSurface/searchablePlate.H | 1 - .../searchableSurface/searchableSphere.C | 16 ++- .../searchableSurface/searchableSurface.H | 14 +++ .../searchableSurfacesQueries.C | 21 ++++ .../searchableSurfacesQueries.H | 6 + .../searchableSurface/triSurfaceMesh.C | 10 +- 13 files changed, 281 insertions(+), 9 deletions(-) create mode 100644 src/meshTools/searchableSurface/closedTriSurfaceMesh.C create mode 100644 src/meshTools/searchableSurface/closedTriSurfaceMesh.H diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index 9f849c58945..743a34eeec0 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -65,6 +65,7 @@ $(searchableSurface)/searchableSurfaces.C $(searchableSurface)/searchableSurfacesQueries.C $(searchableSurface)/searchableSurfaceWithGaps.C $(searchableSurface)/triSurfaceMesh.C +$(searchableSurface)/closedTriSurfaceMesh.C topoSets = sets/topoSets $(topoSets)/cellSet.C diff --git a/src/meshTools/searchableSurface/closedTriSurfaceMesh.C b/src/meshTools/searchableSurface/closedTriSurfaceMesh.C new file mode 100644 index 00000000000..32064188a57 --- /dev/null +++ b/src/meshTools/searchableSurface/closedTriSurfaceMesh.C @@ -0,0 +1,71 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "closedTriSurfaceMesh.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + +defineTypeNameAndDebug(closedTriSurfaceMesh, 0); +addToRunTimeSelectionTable(searchableSurface, closedTriSurfaceMesh, dict); + +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::closedTriSurfaceMesh::closedTriSurfaceMesh(const IOobject& io, const triSurface& s) +: + triSurfaceMesh(io, s) +{} + + +Foam::closedTriSurfaceMesh::closedTriSurfaceMesh(const IOobject& io) +: + triSurfaceMesh(io) +{} + + +Foam::closedTriSurfaceMesh::closedTriSurfaceMesh +( + const IOobject& io, + const dictionary& dict +) +: + triSurfaceMesh(io, dict) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::closedTriSurfaceMesh::~closedTriSurfaceMesh() +{} + + +// ************************************************************************* // diff --git a/src/meshTools/searchableSurface/closedTriSurfaceMesh.H b/src/meshTools/searchableSurface/closedTriSurfaceMesh.H new file mode 100644 index 00000000000..4ae351d6620 --- /dev/null +++ b/src/meshTools/searchableSurface/closedTriSurfaceMesh.H @@ -0,0 +1,112 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::closedTriSurfaceMesh + +Description + A triSurfaceMesh where it is forced to check volumeTypes, used for surfaces + that are topologically non-manifold (small holes or multiple parts) but are + geometrically essentially closed + +SourceFiles + closedTriSurfaceMesh.C + +\*---------------------------------------------------------------------------*/ + +#ifndef closedTriSurfaceMesh_H +#define closedTriSurfaceMesh_H + +#include "triSurfaceMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class closedTriSurfaceMesh Declaration +\*---------------------------------------------------------------------------*/ + +class closedTriSurfaceMesh +: + public triSurfaceMesh +{ +private: + + //- Disallow default bitwise copy construct + closedTriSurfaceMesh(const closedTriSurfaceMesh&); + + //- Disallow default bitwise assignment + void operator=(const closedTriSurfaceMesh&); + + +public: + + //- Runtime type information + TypeName("closedTriSurfaceMesh"); + + + // Constructors + + //- Construct from triSurface + closedTriSurfaceMesh(const IOobject&, const triSurface&); + + //- Construct read. + closedTriSurfaceMesh(const IOobject& io); + + //- Construct from IO and dictionary (used by searchableSurface). + // Dictionary may contain a 'scale' entry (eg, 0.001: mm -> m) + closedTriSurfaceMesh + ( + const IOobject& io, + const dictionary& dict + ); + + + // Destructor + + virtual ~closedTriSurfaceMesh(); + + // Member Functions + + //- Whether supports volume type, forcing to true to force getVolumeType + // queries for this type + virtual bool hasVolumeType() const + { + return true; + } + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/meshTools/searchableSurface/searchableBox.C b/src/meshTools/searchableSurface/searchableBox.C index cb9ca7e4426..64e3273eb09 100644 --- a/src/meshTools/searchableSurface/searchableBox.C +++ b/src/meshTools/searchableSurface/searchableBox.C @@ -170,7 +170,9 @@ Foam::searchableBox::searchableBox : searchableSurface(io), treeBoundBox(bb) -{} +{ + bounds() = static_cast<boundBox>(*this); +} Foam::searchableBox::searchableBox @@ -181,7 +183,9 @@ Foam::searchableBox::searchableBox : searchableSurface(io), treeBoundBox(dict.lookup("min"), dict.lookup("max")) -{} +{ + bounds() = static_cast<boundBox>(*this); +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // diff --git a/src/meshTools/searchableSurface/searchableCylinder.C b/src/meshTools/searchableSurface/searchableCylinder.C index fcaa42194aa..2aafe100ee3 100644 --- a/src/meshTools/searchableSurface/searchableCylinder.C +++ b/src/meshTools/searchableSurface/searchableCylinder.C @@ -352,6 +352,22 @@ void Foam::searchableCylinder::findLineAll } +Foam::boundBox Foam::searchableCylinder::calcBounds() const +{ + // Approximating the boundBox by the extents of spheres, centred at the + // endpoints, of the same radius as the cylinder + + pointField bbPoints(4); + + bbPoints[0] = point1_ + radius_*vector::one; + bbPoints[1] = point1_ - radius_*vector::one; + bbPoints[2] = point2_ + radius_*vector::one; + bbPoints[3] = point2_ - radius_*vector::one; + + return boundBox(bbPoints); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::searchableCylinder::searchableCylinder @@ -368,7 +384,9 @@ Foam::searchableCylinder::searchableCylinder magDir_(mag(point2_-point1_)), unitDir_((point2_-point1_)/magDir_), radius_(radius) -{} +{ + bounds() = calcBounds(); +} Foam::searchableCylinder::searchableCylinder @@ -383,7 +401,9 @@ Foam::searchableCylinder::searchableCylinder magDir_(mag(point2_-point1_)), unitDir_((point2_-point1_)/magDir_), radius_(readScalar(dict.lookup("radius"))) -{} +{ + bounds() = calcBounds(); +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // diff --git a/src/meshTools/searchableSurface/searchableCylinder.H b/src/meshTools/searchableSurface/searchableCylinder.H index cae0f058db2..254267db3a2 100644 --- a/src/meshTools/searchableSurface/searchableCylinder.H +++ b/src/meshTools/searchableSurface/searchableCylinder.H @@ -97,6 +97,8 @@ private: pointIndexHit& far ) const; + //- Return the boundBox of the cylinder + boundBox calcBounds() const; //- Disallow default bitwise copy construct searchableCylinder(const searchableCylinder&); diff --git a/src/meshTools/searchableSurface/searchablePlate.C b/src/meshTools/searchableSurface/searchablePlate.C index c72e28a7de2..3babc3a4bc4 100644 --- a/src/meshTools/searchableSurface/searchablePlate.C +++ b/src/meshTools/searchableSurface/searchablePlate.C @@ -227,6 +227,8 @@ Foam::searchablePlate::searchablePlate << " normal:" << vector::componentNames[normalDir_] << endl; } + + bounds() = boundBox(origin_, origin_ + span_); } @@ -249,6 +251,8 @@ Foam::searchablePlate::searchablePlate << " normal:" << vector::componentNames[normalDir_] << endl; } + + bounds() = boundBox(origin_, origin_ + span_); } diff --git a/src/meshTools/searchableSurface/searchablePlate.H b/src/meshTools/searchableSurface/searchablePlate.H index 7bc900f554b..d839891c442 100644 --- a/src/meshTools/searchableSurface/searchablePlate.H +++ b/src/meshTools/searchableSurface/searchablePlate.H @@ -93,7 +93,6 @@ private: const point& end ) const; - //- Disallow default bitwise copy construct searchablePlate(const searchablePlate&); diff --git a/src/meshTools/searchableSurface/searchableSphere.C b/src/meshTools/searchableSurface/searchableSphere.C index 287ae6743c2..1de89fa019e 100644 --- a/src/meshTools/searchableSurface/searchableSphere.C +++ b/src/meshTools/searchableSurface/searchableSphere.C @@ -133,7 +133,13 @@ Foam::searchableSphere::searchableSphere searchableSurface(io), centre_(centre), radius_(radius) -{} +{ + bounds() = boundBox + ( + centre_ + radius_*vector::one, + centre_ - radius_*vector::one + ); +} Foam::searchableSphere::searchableSphere @@ -145,7 +151,13 @@ Foam::searchableSphere::searchableSphere searchableSurface(io), centre_(dict.lookup("centre")), radius_(readScalar(dict.lookup("radius"))) -{} +{ + bounds() = boundBox + ( + centre_ + radius_*vector::one, + centre_ - radius_*vector::one + ); +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // diff --git a/src/meshTools/searchableSurface/searchableSurface.H b/src/meshTools/searchableSurface/searchableSurface.H index 35b9dc9fb5a..0ee49f729a7 100644 --- a/src/meshTools/searchableSurface/searchableSurface.H +++ b/src/meshTools/searchableSurface/searchableSurface.H @@ -43,6 +43,7 @@ SourceFiles #define searchableSurface_H #include "pointField.H" +#include "boundBox.H" #include "typeInfo.H" #include "runTimeSelectionTables.H" #include "pointIndexHit.H" @@ -87,6 +88,8 @@ private: const word name_; + boundBox bounds_; + // Private Member Functions @@ -174,6 +177,17 @@ public: // Member Functions + //- Return const reference to boundBox + const boundBox& bounds() const + { + return bounds_; + } + + //- Return non-const access to the boundBox to allow it to be set. + boundBox& bounds() + { + return bounds_; + } //- Names of regions. virtual const wordList& regions() const = 0; diff --git a/src/meshTools/searchableSurface/searchableSurfacesQueries.C b/src/meshTools/searchableSurface/searchableSurfacesQueries.C index b0d6322a740..8ae7e0b1cc6 100644 --- a/src/meshTools/searchableSurface/searchableSurfacesQueries.C +++ b/src/meshTools/searchableSurface/searchableSurfacesQueries.C @@ -688,6 +688,27 @@ void Foam::searchableSurfacesQueries::findNearest } +Foam::boundBox Foam::searchableSurfacesQueries::bounds +( + const PtrList<searchableSurface>& allSurfaces, + const labelList& surfacesToTest +) +{ + pointField bbPoints(2*surfacesToTest.size()); + + forAll(surfacesToTest, testI) + { + const searchableSurface& surface(allSurfaces[surfacesToTest[testI]]); + + bbPoints[2*testI] = surface.bounds().min(); + + bbPoints[2*testI + 1] = surface.bounds().max(); + } + + return boundBox(bbPoints); +} + + //- Calculate point which is on a set of surfaces. Foam::pointIndexHit Foam::searchableSurfacesQueries::facesIntersection ( diff --git a/src/meshTools/searchableSurface/searchableSurfacesQueries.H b/src/meshTools/searchableSurface/searchableSurfacesQueries.H index e6c6ce3bb9f..7e336fc68fe 100644 --- a/src/meshTools/searchableSurface/searchableSurfacesQueries.H +++ b/src/meshTools/searchableSurface/searchableSurfacesQueries.H @@ -172,6 +172,12 @@ public: List<pointIndexHit>& ); + //- Find the boundBox of the selected surfaces + static boundBox bounds + ( + const PtrList<searchableSurface>& allSurfaces, + const labelList& surfacesToTest + ); // Single point queries diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.C b/src/meshTools/searchableSurface/triSurfaceMesh.C index 877f2643414..8a2ea1ae797 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.C +++ b/src/meshTools/searchableSurface/triSurfaceMesh.C @@ -238,7 +238,9 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const triSurface& s) ), triSurface(s), surfaceClosed_(-1) -{} +{ + bounds() = boundBox(points()); +} Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io) @@ -280,7 +282,9 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io) ) ), surfaceClosed_(-1) -{} +{ + bounds() = boundBox(points()); +} Foam::triSurfaceMesh::triSurfaceMesh @@ -334,6 +338,8 @@ Foam::triSurfaceMesh::triSurfaceMesh { triSurface::scalePoints(scaleFactor); } + + bounds() = boundBox(points()); } -- GitLab