diff --git a/applications/utilities/mesh/manipulation/topoSet/topoSetDict b/applications/utilities/mesh/manipulation/topoSet/topoSetDict index cc78c310905aee5b334c95391a5d8122591a2fb6..f5af469be01a9a4a64929b496b74aa69bbdc8706 100644 --- a/applications/utilities/mesh/manipulation/topoSet/topoSetDict +++ b/applications/utilities/mesh/manipulation/topoSet/topoSetDict @@ -81,6 +81,14 @@ FoamFile // //option all; // cell with all faces in faceSet // } // +// // All cells on boundaries +// source boundaryToCell; +// +// // Select cells associated with patch +// source patchToCell; +// patches ("patch.*") +// patch somePatch; +// // // Select based on pointSet // source pointToCell; // sourceInfo @@ -144,7 +152,7 @@ FoamFile // source surfaceToCell; // sourceInfo // { -// file "www.avl.com-geometry.stl"; +// file "geometry.stl"; // useSurfaceOrientation false; // use closed surface inside/outside // // test (ignores includeCut, // // outsidePoints) @@ -235,9 +243,6 @@ FoamFile // // // All boundary faces // source boundaryToFace; -// sourceInfo -// { -// } // // // All faces of faceZone // source zoneToFace; diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index 4c1116e0b603b4e9ef137f5054ed5b17857a4cd1..ae698d00ca7a205f121e73a3fa3667325f1b8bdf 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -152,6 +152,7 @@ sets/topoSetSource/topoSetSource.C cellSources = sets/cellSources $(cellSources)/topoSetCellSource/topoSetCellSource.C +$(cellSources)/boundaryToCell/boundaryToCell.C $(cellSources)/boxToCell/boxToCell.C $(cellSources)/cellToCell/cellToCell.C $(cellSources)/cylinderAnnulusToCell/cylinderAnnulusToCell.C @@ -162,6 +163,7 @@ $(cellSources)/fieldToCell/fieldToCell.C $(cellSources)/labelToCell/labelToCell.C $(cellSources)/nbrToCell/nbrToCell.C $(cellSources)/nearestToCell/nearestToCell.C +$(cellSources)/patchToCell/patchToCell.C $(cellSources)/pointToCell/pointToCell.C $(cellSources)/regionToCell/regionToCell.C $(cellSources)/rotatedBoxToCell/rotatedBoxToCell.C diff --git a/src/meshTools/sets/cellSources/boundaryToCell/boundaryToCell.C b/src/meshTools/sets/cellSources/boundaryToCell/boundaryToCell.C new file mode 100644 index 0000000000000000000000000000000000000000..98f450a5f45d29be9cab86c2075565576783fb1f --- /dev/null +++ b/src/meshTools/sets/cellSources/boundaryToCell/boundaryToCell.C @@ -0,0 +1,137 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "boundaryToCell.H" +#include "polyMesh.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(boundaryToCell, 0); + addToRunTimeSelectionTable(topoSetSource, boundaryToCell, word); + addToRunTimeSelectionTable(topoSetSource, boundaryToCell, istream); + addToRunTimeSelectionTable(topoSetCellSource, boundaryToCell, word); + addToRunTimeSelectionTable(topoSetCellSource, boundaryToCell, istream); + addNamedToRunTimeSelectionTable + ( + topoSetCellSource, + boundaryToCell, + word, + boundary + ); + addNamedToRunTimeSelectionTable + ( + topoSetCellSource, + boundaryToCell, + istream, + boundary + ); +} + + +Foam::topoSetSource::addToUsageTable Foam::boundaryToCell::usage_ +( + boundaryToCell::typeName, + "\n Usage: boundaryToCell\n\n" + " Select all boundary cells\n\n" +); + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::boundaryToCell::combine(topoSet& set, const bool add) const +{ + for + ( + label facei = mesh().nInternalFaces(); + facei < mesh().nFaces(); + ++facei + ) + { + addOrDelete(set, mesh().faceOwner()[facei], add); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::boundaryToCell::boundaryToCell(const polyMesh& mesh) +: + topoSetCellSource(mesh) +{} + + +Foam::boundaryToCell::boundaryToCell +( + const polyMesh& mesh, + const dictionary& +) +: + topoSetCellSource(mesh) +{} + + +Foam::boundaryToCell::boundaryToCell +( + const polyMesh& mesh, + Istream& +) +: + topoSetCellSource(mesh) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::boundaryToCell::applyToSet +( + const topoSetSource::setAction action, + topoSet& set +) const +{ + if (action == topoSetSource::ADD || action == topoSetSource::NEW) + { + if (verbose_) + { + Info<< " Adding all boundary cells ..." << endl; + } + + combine(set, true); + } + else if (action == topoSetSource::SUBTRACT) + { + if (verbose_) + { + Info<< " Removing all boundary cells ..." << endl; + } + + combine(set, false); + } +} + + +// ************************************************************************* // diff --git a/src/meshTools/sets/cellSources/boundaryToCell/boundaryToCell.H b/src/meshTools/sets/cellSources/boundaryToCell/boundaryToCell.H new file mode 100644 index 0000000000000000000000000000000000000000..706b737c0562b3424270f13aaf5786b79454c7fe --- /dev/null +++ b/src/meshTools/sets/cellSources/boundaryToCell/boundaryToCell.H @@ -0,0 +1,107 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 <http://www.gnu.org/licenses/>. + +Class + Foam::boundaryToCell + +Description + A topoSetCellSource to select all external (boundary) faces. + + \heading Dictionary parameters + None + +SourceFiles + boundaryToCell.C + +\*---------------------------------------------------------------------------*/ + +#ifndef boundaryToCell_H +#define boundaryToCell_H + +#include "topoSetCellSource.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class boundaryToCell Declaration +\*---------------------------------------------------------------------------*/ + +class boundaryToCell +: + public topoSetCellSource +{ + // Private data + + //- Add usage string + static addToUsageTable usage_; + + + // Private Member Functions + + void combine(topoSet& set, const bool add) const; + + +public: + + //- Runtime type information + TypeName("boundaryToCell"); + + // Constructors + + //- Construct from components + boundaryToCell(const polyMesh& mesh); + + //- Construct from dictionary + boundaryToCell(const polyMesh& mesh, const dictionary& unused); + + //- Construct from Istream + boundaryToCell(const polyMesh& mesh, Istream& unused); + + + //- Destructor + virtual ~boundaryToCell() = default; + + + // Member Functions + + virtual void applyToSet + ( + const topoSetSource::setAction action, + topoSet& set + ) const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/meshTools/sets/cellSources/patchToCell/patchToCell.C b/src/meshTools/sets/cellSources/patchToCell/patchToCell.C new file mode 100644 index 0000000000000000000000000000000000000000..0d183423870558f8f0f7db646e8f83f0a13db6e0 --- /dev/null +++ b/src/meshTools/sets/cellSources/patchToCell/patchToCell.C @@ -0,0 +1,181 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "patchToCell.H" +#include "polyMesh.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(patchToCell, 0); + addToRunTimeSelectionTable(topoSetSource, patchToCell, word); + addToRunTimeSelectionTable(topoSetSource, patchToCell, istream); + addToRunTimeSelectionTable(topoSetCellSource, patchToCell, word); + addToRunTimeSelectionTable(topoSetCellSource, patchToCell, istream); + addNamedToRunTimeSelectionTable + ( + topoSetCellSource, + patchToCell, + word, + patch + ); + addNamedToRunTimeSelectionTable + ( + topoSetCellSource, + patchToCell, + istream, + patch + ); +} + + +Foam::topoSetSource::addToUsageTable Foam::patchToCell::usage_ +( + patchToCell::typeName, + "\n Usage: patchToCell patch\n\n" + " Select cells attached to patch. Note:accepts wildcards for patch.\n\n" +); + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::patchToCell::combine(topoSet& set, const bool add) const +{ + labelHashSet patchIDs = mesh_.boundaryMesh().patchSet + ( + selectedPatches_, + true, // warn if not found + true // use patch groups if available + ); + + for (const label patchi : patchIDs) + { + const polyPatch& pp = mesh_.boundaryMesh()[patchi]; + + if (verbose_) + { + Info<< " Found matching patch " << pp.name() + << " with " << pp.size() << " faces." << endl; + } + + for + ( + label facei = pp.start(); + facei < pp.start() + pp.size(); + ++facei + ) + { + addOrDelete(set, mesh_.faceOwner()[facei], add); + } + } + + if (patchIDs.empty()) + { + WarningInFunction + << "Cannot find any patches matching " + << flatOutput(selectedPatches_) << nl + << "Valid names are " << flatOutput(mesh_.boundaryMesh().names()) + << endl; + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::patchToCell::patchToCell +( + const polyMesh& mesh, + const wordRe& patchName +) +: + topoSetCellSource(mesh), + selectedPatches_(one(), patchName) +{} + + +Foam::patchToCell::patchToCell +( + const polyMesh& mesh, + const dictionary& dict +) +: + topoSetCellSource(mesh), + selectedPatches_() +{ + // Look for 'patches' and 'patch', but accept 'name' as well + if (!dict.readIfPresent("patches", selectedPatches_)) + { + selectedPatches_.resize(1); + selectedPatches_.first() = + dict.getCompat<wordRe>("patch", {{"name", 1806}}); + } +} + + +Foam::patchToCell::patchToCell +( + const polyMesh& mesh, + Istream& is +) +: + topoSetCellSource(mesh), + selectedPatches_(one(), wordRe(checkIs(is))) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::patchToCell::applyToSet +( + const topoSetSource::setAction action, + topoSet& set +) const +{ + if (action == topoSetSource::ADD || action == topoSetSource::NEW) + { + if (verbose_) + { + Info<< " Adding cells associated with patches " + << flatOutput(selectedPatches_) << " ..." << endl; + } + + combine(set, true); + } + else if (action == topoSetSource::SUBTRACT) + { + if (verbose_) + { + Info<< " Removing cells associated with patches " + << flatOutput(selectedPatches_) << " ..." << endl; + } + + combine(set, false); + } +} + + +// ************************************************************************* // diff --git a/src/meshTools/sets/cellSources/patchToCell/patchToCell.H b/src/meshTools/sets/cellSources/patchToCell/patchToCell.H new file mode 100644 index 0000000000000000000000000000000000000000..3916cec5d155fc848cd8aca732b13727e2e6d55a --- /dev/null +++ b/src/meshTools/sets/cellSources/patchToCell/patchToCell.H @@ -0,0 +1,118 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 <http://www.gnu.org/licenses/>. + +Class + Foam::patchToCell + +Description + A topoSetCellSource to select cells associated with patches. + + \heading Dictionary parameters + \table + Property | Description | Required | Default + patches | The face zone names or regexs | possibly | + patch | The face zone name or regex | possibly | + \endtable + +Note + Must specify "patches" or "patch" (highest to lowest precedence). + +SourceFiles + patchToCell.C + +\*---------------------------------------------------------------------------*/ + +#ifndef patchToCell_H +#define patchToCell_H + +#include "topoSetCellSource.H" +#include "wordRes.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class patchToCell Declaration +\*---------------------------------------------------------------------------*/ + +class patchToCell +: + public topoSetCellSource +{ + // Private Data + + //- Add usage string + static addToUsageTable usage_; + + //- Matcher for patches + wordRes selectedPatches_; + + + // Private Member Functions + + void combine(topoSet& set, const bool add) const; + + +public: + + //- Runtime type information + TypeName("patchToCell"); + + // Constructors + + //- Construct from components + patchToCell(const polyMesh& mesh, const wordRe& patchName); + + //- Construct from dictionary + patchToCell(const polyMesh& mesh, const dictionary& dict); + + //- Construct from Istream + patchToCell(const polyMesh& mesh, Istream& is); + + + //- Destructor + virtual ~patchToCell() = default; + + + // Member Functions + + virtual void applyToSet + ( + const topoSetSource::setAction action, + topoSet& set + ) const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //