diff --git a/src/meshTools/searchableSurface/searchableCone.C b/src/meshTools/searchableSurface/searchableCone.C index 2d6cabd8c4..b4c212a92b 100644 --- a/src/meshTools/searchableSurface/searchableCone.C +++ b/src/meshTools/searchableSurface/searchableCone.C @@ -83,7 +83,7 @@ Foam::tmp Foam::searchableCone::points() const } -void Foam::searchableCone::findNearest +void Foam::searchableCone::findNearestAndNormal ( const point& sample, const scalar nearestDistSqr, @@ -780,7 +780,7 @@ void Foam::searchableCone::findNearest forAll(samples, i) { vector normal; - findNearest(samples[i], nearestDistSqr[i], info[i], normal); + findNearestAndNormal(samples[i], nearestDistSqr[i], info[i], normal); } } @@ -1054,7 +1054,7 @@ void Foam::searchableCone::getNormal if (info[i].hit()) { pointIndexHit nearInfo; - findNearest + findNearestAndNormal ( info[i].hitPoint(), Foam::sqr(GREAT), diff --git a/src/meshTools/searchableSurface/searchableCone.H b/src/meshTools/searchableSurface/searchableCone.H index 6e477bc405..3b4d7c3d1f 100644 --- a/src/meshTools/searchableSurface/searchableCone.H +++ b/src/meshTools/searchableSurface/searchableCone.H @@ -100,7 +100,7 @@ class searchableCone // Private Member Functions //- Find nearest point on cylinder. - void findNearest + void findNearestAndNormal ( const point& sample, const scalar nearestDistSqr, @@ -236,14 +236,6 @@ public: List& ) const; - //- Find any intersection on line from start to end - virtual void findLineAny - ( - const pointField& start, - const pointField& end, - List& - ) const; - //- Find all intersections in order from start to end virtual void findLineAll ( @@ -252,6 +244,14 @@ public: List >& ) const; + //- Find any intersection on line from start to end + virtual void findLineAny + ( + const pointField& start, + const pointField& end, + List& + ) const; + //- From a set of points and indices get the region virtual void getRegion ( @@ -277,7 +277,7 @@ public: // regIOobject implementation - bool writeData(Ostream&) const + virtual bool writeData(Ostream&) const { notImplemented("searchableCone::writeData(Ostream&) const"); return false; diff --git a/src/meshTools/searchableSurface/searchableCylinder.H b/src/meshTools/searchableSurface/searchableCylinder.H index fe00bc4258..60880aa0cf 100644 --- a/src/meshTools/searchableSurface/searchableCylinder.H +++ b/src/meshTools/searchableSurface/searchableCylinder.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -43,8 +43,6 @@ SourceFiles namespace Foam { -// Forward declaration of classes - /*---------------------------------------------------------------------------*\ Class searchableCylinder Declaration \*---------------------------------------------------------------------------*/ diff --git a/src/meshTools/searchableSurface/searchableRotatedBox.C b/src/meshTools/searchableSurface/searchableRotatedBox.C index cbedeeeeed..3e9660ca80 100644 --- a/src/meshTools/searchableSurface/searchableRotatedBox.C +++ b/src/meshTools/searchableSurface/searchableRotatedBox.C @@ -55,8 +55,7 @@ Foam::searchableRotatedBox::searchableRotatedBox io.db(), io.readOpt(), io.writeOpt(), - false, //io.registerObject(), - io.globalObject() + false //io.registerObject(), ), treeBoundBox(point::zero, dict.lookup("span")) ), diff --git a/src/meshTools/searchableSurface/searchableRotatedBox.H b/src/meshTools/searchableSurface/searchableRotatedBox.H index 1d1b9c452c..5c5c9206ad 100644 --- a/src/meshTools/searchableSurface/searchableRotatedBox.H +++ b/src/meshTools/searchableSurface/searchableRotatedBox.H @@ -56,10 +56,8 @@ SourceFiles namespace Foam { -// Forward declaration of classes - /*---------------------------------------------------------------------------*\ - Class searchableRotatedBox Declaration + Class searchableRotatedBox Declaration \*---------------------------------------------------------------------------*/ class searchableRotatedBox @@ -145,6 +143,9 @@ public: // Single point queries. + //- Inherit findNearest from searchableSurface + using searchableSurface::findNearest; + //- Calculate nearest point on surface. // Returns // - bool : any point found nearer than nearestDistSqr diff --git a/src/meshTools/searchableSurface/subTriSurfaceMesh.C b/src/meshTools/searchableSurface/subTriSurfaceMesh.C new file mode 100644 index 0000000000..dfffbd793e --- /dev/null +++ b/src/meshTools/searchableSurface/subTriSurfaceMesh.C @@ -0,0 +1,153 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 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 3 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, see . + +\*---------------------------------------------------------------------------*/ + +#include "subTriSurfaceMesh.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + +defineTypeNameAndDebug(subTriSurfaceMesh, 0); +addToRunTimeSelectionTable(searchableSurface, subTriSurfaceMesh, dict); + +} + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::wordList Foam::subTriSurfaceMesh::patchNames(const triSurface& s) +{ + const geometricSurfacePatchList& patches = s.patches(); + + wordList names(patches.size()); + forAll(patches, patchI) + { + names[patchI] = patches[patchI].name(); + } + return names; +} + + +Foam::labelList Foam::subTriSurfaceMesh::selectedRegions +( + const triSurface& s, + const wordReList& regionNames +) +{ + const wordList names(patchNames(s)); + + labelList regions(names.size()); + + label compactI = 0; + + forAll(names, regionI) + { + const word& name = names[regionI]; + + forAll(regionNames, i) + { + if (regionNames[i].match(name)) + { + regions[compactI++] = regionI; + } + } + } + regions.setSize(compactI); + + return regions; +} + + +Foam::triSurface Foam::subTriSurfaceMesh::subset +( + const IOobject& io, + const dictionary& dict +) +{ + const word subGeomName(dict.lookup("surface")); + + const triSurfaceMesh& s = + io.db().lookupObject(subGeomName); + + const wordReList regionNames(dict.lookup("patches")); + + labelList regionMap(selectedRegions(s, regionNames)); + + if (regionMap.size() == 0) + { + FatalIOErrorIn + ( + "subTriSurfaceMesh::subset" + "(\n" + " const IOobject&,\n" + " const dictionary&\n" + ")", + dict + ) << "Found no regions in triSurface matching " << regionNames + << ". Valid regions are " << patchNames(s) + << exit(FatalIOError); + } + + labelList reverseRegionMap(s.patches().size(), -1); + forAll(regionMap, i) + { + reverseRegionMap[regionMap[i]] = i; + } + + boolList isSelected(s.size(), false); + forAll(s, triI) + { + if (reverseRegionMap[s.triSurface::operator[](triI).region()] != -1) + { + isSelected[triI] = true; + } + } + + labelList pointMap; + labelList faceMap; + return s.subsetMesh(isSelected, pointMap, faceMap); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::subTriSurfaceMesh::subTriSurfaceMesh +( + const IOobject& io, + const dictionary& dict +) +: + triSurfaceMesh(io, subset(io, dict)) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::subTriSurfaceMesh::~subTriSurfaceMesh() +{} + + +// ************************************************************************* // diff --git a/src/meshTools/searchableSurface/subTriSurfaceMesh.H b/src/meshTools/searchableSurface/subTriSurfaceMesh.H new file mode 100644 index 0000000000..9d0f508e14 --- /dev/null +++ b/src/meshTools/searchableSurface/subTriSurfaceMesh.H @@ -0,0 +1,115 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 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 3 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, see . + +Class + Foam::subTriSurfaceMesh + +Description + On-the-fly subset of triSurfaceMesh (based on selected patches) + +Note + + Example usage: + \verbatim + spheres.stl + { + type subTriSurfaceMesh; + + // Surface to operate on. Avoid duplicate loading + surface spheres.stl; + + // Regions to operate on (regular expressions allowed) + patches (solid1); + } + \endverbatim + + +SourceFiles + subTriSurfaceMesh.C + +\*---------------------------------------------------------------------------*/ + +#ifndef subTriSurfaceMesh_H +#define subTriSurfaceMesh_H + +#include "triSurfaceMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class subTriSurfaceMesh Declaration +\*---------------------------------------------------------------------------*/ + +class subTriSurfaceMesh +: + public triSurfaceMesh +{ + // Private member functions + + //- Extract patch names of triSurface + static wordList patchNames(const triSurface& s); + + //- Select regions by name + static labelList selectedRegions + ( + const triSurface& s, + const wordReList& regionNames + ); + + //- Subset triSurface based on regions + static triSurface subset(const IOobject&, const dictionary&); + + +public: + + //- Runtime type information + TypeName("subTriSurfaceMesh"); + + + // Constructors + + //- Construct from IO and dictionary. + subTriSurfaceMesh + ( + const IOobject& io, + const dictionary& dict + ); + + + //- Destructor + virtual ~subTriSurfaceMesh(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //