From d1d6421b49974dc94b07951c8bc2e883a51bc12f Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Fri, 30 Nov 2012 15:52:36 +0000 Subject: [PATCH] ENH: searchableSurfaceToFaceZone: selection of faces and normals --- .../mesh/manipulation/topoSet/topoSetDict | 21 ++ src/meshTools/Make/files | 1 + .../searchableSurfaceToFaceZone.C | 211 ++++++++++++++++++ .../searchableSurfaceToFaceZone.H | 107 +++++++++ 4 files changed, 340 insertions(+) create mode 100644 src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.C create mode 100644 src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.H diff --git a/applications/utilities/mesh/manipulation/topoSet/topoSetDict b/applications/utilities/mesh/manipulation/topoSet/topoSetDict index 31fa348e979..00720d23825 100644 --- a/applications/utilities/mesh/manipulation/topoSet/topoSetDict +++ b/applications/utilities/mesh/manipulation/topoSet/topoSetDict @@ -226,6 +226,12 @@ FoamFile // // (regular expressions allowed) // } // +// // All boundary faces +// source boundaryToFace; +// sourceInfo +// { +// } +// // // All faces of faceZone // source zoneToFace; // sourceInfo @@ -359,6 +365,21 @@ FoamFile // cellSet c0; // name of cellSet of slave side // } // +// // Select based on surface. Orientation from normals on surface +// { +// name fz0; +// type faceZoneSet; +// action new; +// source searchableSurfaceToFaceZone; +// sourceInfo +// { +// surface searchableSphere; +// centre (0.05 0.05 0.005); +// radius 0.025; +// } +// } +// +// // // pointZoneSet // ~~~~~~~~~~~~ diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index 2621adbc235..b35aff1ab4a 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -128,6 +128,7 @@ faceZoneSources = sets/faceZoneSources $(faceZoneSources)/faceZoneToFaceZone/faceZoneToFaceZone.C $(faceZoneSources)/setsToFaceZone/setsToFaceZone.C $(faceZoneSources)/setToFaceZone/setToFaceZone.C +$(faceZoneSources)/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.C cellZoneSources = sets/cellZoneSources $(cellZoneSources)/setToCellZone/setToCellZone.C diff --git a/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.C b/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.C new file mode 100644 index 00000000000..b91ec33b828 --- /dev/null +++ b/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.C @@ -0,0 +1,211 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "searchableSurfaceToFaceZone.H" +#include "polyMesh.H" +#include "faceZoneSet.H" +#include "searchableSurface.H" +#include "syncTools.H" + +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(searchableSurfaceToFaceZone, 0); + addToRunTimeSelectionTable + ( + topoSetSource, + searchableSurfaceToFaceZone, + word + ); +} + + +Foam::topoSetSource::addToUsageTable Foam::searchableSurfaceToFaceZone::usage_ +( + searchableSurfaceToFaceZone::typeName, + "\n Usage: searchableSurfaceToFaceZone surface\n\n" + " Select all faces whose cell-cell centre vector intersects the surface " + "\n" +); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +// Construct from dictionary +Foam::searchableSurfaceToFaceZone::searchableSurfaceToFaceZone +( + const polyMesh& mesh, + const dictionary& dict +) +: + topoSetSource(mesh), + surfacePtr_ + ( + searchableSurface::New + ( + word(dict.lookup("surface")), + mesh.objectRegistry::db(), + dict + ) + ) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::searchableSurfaceToFaceZone::~searchableSurfaceToFaceZone() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::searchableSurfaceToFaceZone::applyToSet +( + const topoSetSource::setAction action, + topoSet& set +) const +{ + if (!isA<faceZoneSet>(set)) + { + WarningIn + ( + "searchableSurfaceToFaceZone::applyToSet" + "(const topoSetSource::setAction" + ", topoSet" + ) << "Operation only allowed on a faceZoneSet." << endl; + } + else + { + faceZoneSet& fzSet = refCast<faceZoneSet>(set); + + // Get cell-cell centre vectors + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + pointField start(mesh_.nFaces()); + pointField end(mesh_.nFaces()); + + const pointField& cc = mesh_.cellCentres(); + + // Internal faces + for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++) + { + start[faceI] = cc[mesh_.faceOwner()[faceI]]; + end[faceI] = cc[mesh_.faceNeighbour()[faceI]]; + } + + // Boundary faces + vectorField nbrCellCentres; + syncTools::swapBoundaryCellList(mesh_, cc, nbrCellCentres); + + const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); + + forAll(pbm, patchI) + { + const polyPatch& pp = pbm[patchI]; + + if (pp.coupled()) + { + forAll(pp, i) + { + label faceI = pp.start()+i; + start[faceI] = cc[mesh_.faceOwner()[faceI]]; + end[faceI] = nbrCellCentres[faceI-mesh_.nInternalFaces()]; + } + } + else + { + forAll(pp, i) + { + label faceI = pp.start()+i; + start[faceI] = cc[mesh_.faceOwner()[faceI]]; + end[faceI] = mesh_.faceCentres()[faceI]; + } + } + } + + + // Do all intersection tests + // ~~~~~~~~~~~~~~~~~~~~~~~~~ + + List<pointIndexHit> hits; + surfacePtr_().findLine(start, end, hits); + pointField normals; + surfacePtr_().getNormal(hits, normals); + + + // Select intersected faces + // ~~~~~~~~~~~~~~~~~~~~~~~~ + + if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD)) + { + Info<< " Adding all faces from surface " + << surfacePtr_().name() << " ..." << endl; + + DynamicList<label> newAddressing(fzSet.addressing()); + DynamicList<bool> newFlipMap(fzSet.flipMap()); + + forAll(hits, faceI) + { + if (hits[faceI].hit() && !fzSet.found(faceI)) + { + newAddressing.append(faceI); + vector d = end[faceI]-start[faceI]; + newFlipMap.append((normals[faceI] & d) < 0); + } + } + + fzSet.addressing().transfer(newAddressing); + fzSet.flipMap().transfer(newFlipMap); + fzSet.updateSet(); + } + else if (action == topoSetSource::DELETE) + { + Info<< " Removing all faces from surface " + << surfacePtr_().name() << " ..." << endl; + + // Start off empty + DynamicList<label> newAddressing(fzSet.addressing().size()); + DynamicList<bool> newFlipMap(fzSet.flipMap().size()); + + forAll(fzSet.addressing(), i) + { + if (!hits[fzSet.addressing()[i]].hit()) + { + newAddressing.append(fzSet.addressing()[i]); + newFlipMap.append(fzSet.flipMap()[i]); + } + } + fzSet.addressing().transfer(newAddressing); + fzSet.flipMap().transfer(newFlipMap); + fzSet.updateSet(); + } + } +} + + +// ************************************************************************* // diff --git a/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.H b/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.H new file mode 100644 index 00000000000..7269a3d38ee --- /dev/null +++ b/src/meshTools/sets/faceZoneSources/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.H @@ -0,0 +1,107 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ 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 <http://www.gnu.org/licenses/>. + +Class + Foam::searchableSurfaceToFaceZone + +Description + A topoSetSource to select faces based on intersection (of cell-cell + vector) with a surface. + +SourceFiles + searchableSurfaceToFaceZone.C + +\*---------------------------------------------------------------------------*/ + +#ifndef searchableSurfaceToFaceZone_H +#define searchableSurfaceToFaceZone_H + +#include "topoSetSource.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class searchableSurface; + +/*---------------------------------------------------------------------------*\ + Class searchableSurfaceToFaceZone Declaration +\*---------------------------------------------------------------------------*/ + +class searchableSurfaceToFaceZone +: + public topoSetSource +{ + // Private data + + //- Add usage string + static addToUsageTable usage_; + + //- Surface + autoPtr<searchableSurface> surfacePtr_; + +public: + + //- Runtime type information + TypeName("searchableSurfaceToFaceZone"); + + // Constructors + + //- Construct from dictionary + searchableSurfaceToFaceZone + ( + const polyMesh& mesh, + const dictionary& dict + ); + + + //- Destructor + virtual ~searchableSurfaceToFaceZone(); + + + // Member Functions + + virtual sourceType setType() const + { + return FACEZONESOURCE; + } + + virtual void applyToSet + ( + const topoSetSource::setAction action, + topoSet& + ) const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // -- GitLab