From 6692ecfbbc813664b357cac5c7411204ee864e07 Mon Sep 17 00:00:00 2001 From: Mattijs Janssens <ext-mjanssens@esi-group.com> Date: Mon, 18 Mar 2024 19:58:06 +0000 Subject: [PATCH] topoSet: allow use of 'zone' instead 'set', 'zones' instead of 'sets' in all set sources --- .../topoSet/cellSources/boxToCell/boxToCell.H | 2 +- .../cellSources/cellToCell/cellToCell.C | 50 ++++++---- .../cellSources/cellToCell/cellToCell.H | 37 +++++--- .../cellSources/faceToCell/faceToCell.C | 65 ++++++++----- .../cellSources/faceToCell/faceToCell.H | 41 ++++++-- .../faceZoneToCell/faceZoneToCell.H | 4 +- .../cellSources/patchToCell/patchToCell.H | 2 +- .../cellSources/pointToCell/pointToCell.C | 59 ++++++++---- .../cellSources/pointToCell/pointToCell.H | 45 ++++++--- .../cellSources/regionToCell/regionToCell.C | 52 +++++++--- .../cellSources/regionToCell/regionToCell.H | 14 ++- .../cellSources/zoneToCell/zoneToCell.H | 2 +- .../setToCellZone/setToCellZone.C | 10 +- .../topoSet/faceSources/boxToFace/boxToFace.H | 2 +- .../faceSources/cellToFace/cellToFace.C | 69 +++++++++----- .../faceSources/cellToFace/cellToFace.H | 37 ++++++-- .../faceSources/faceToFace/faceToFace.C | 52 ++++++---- .../faceSources/faceToFace/faceToFace.H | 28 ++++-- .../faceSources/holeToFace/holeToFace.C | 6 +- .../faceSources/patchToFace/patchToFace.H | 2 +- .../faceSources/pointToFace/pointToFace.C | 59 ++++++++---- .../faceSources/pointToFace/pointToFace.H | 43 ++++++--- .../faceSources/regionToFace/regionToFace.C | 58 +++++++++--- .../faceSources/regionToFace/regionToFace.H | 14 ++- .../faceSources/zoneToFace/zoneToFace.H | 2 +- .../cellToFaceZone/cellToFaceZone.C | 66 ++++++++----- .../cellToFaceZone/cellToFaceZone.H | 33 ++++++- .../pointSources/boxToPoint/boxToPoint.H | 2 +- .../pointSources/cellToPoint/cellToPoint.C | 56 +++++++---- .../pointSources/cellToPoint/cellToPoint.H | 45 ++++++--- .../pointSources/faceToPoint/faceToPoint.C | 53 +++++++---- .../pointSources/faceToPoint/faceToPoint.H | 17 ++-- .../pointSources/pointToPoint/pointToPoint.C | 50 ++++++---- .../pointSources/pointToPoint/pointToPoint.H | 30 ++++-- .../pointSources/zoneToPoint/zoneToPoint.H | 2 +- .../setToPointZone/setToPointZone.C | 10 +- .../topoSet/topoSetSource/topoSetSource.C | 48 ++++++++++ .../topoSet/topoSetSource/topoSetSource.H | 5 + src/meshTools/topoSet/topoSets/cellZoneSet.C | 54 +++++++++++ src/meshTools/topoSet/topoSets/cellZoneSet.H | 11 +++ src/meshTools/topoSet/topoSets/faceZoneSet.C | 94 ++++++++++++++----- src/meshTools/topoSet/topoSets/faceZoneSet.H | 36 +++++++ src/meshTools/topoSet/topoSets/pointZoneSet.C | 54 +++++++++++ src/meshTools/topoSet/topoSets/pointZoneSet.H | 12 +++ src/meshTools/topoSet/topoSets/topoBitSet.C | 28 ++++++ src/meshTools/topoSet/topoSets/topoBitSet.H | 11 +++ src/meshTools/topoSet/topoSets/topoBoolSet.C | 39 ++++++++ src/meshTools/topoSet/topoSets/topoBoolSet.H | 11 +++ src/meshTools/topoSet/topoSets/topoSet.C | 34 ++++++- src/meshTools/topoSet/topoSets/topoSet.H | 19 +++- 50 files changed, 1189 insertions(+), 386 deletions(-) diff --git a/src/meshTools/topoSet/cellSources/boxToCell/boxToCell.H b/src/meshTools/topoSet/cellSources/boxToCell/boxToCell.H index 1da35b00b0b..0775939338c 100644 --- a/src/meshTools/topoSet/cellSources/boxToCell/boxToCell.H +++ b/src/meshTools/topoSet/cellSources/boxToCell/boxToCell.H @@ -50,7 +50,7 @@ Usage source boxToCell; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 boxes diff --git a/src/meshTools/topoSet/cellSources/cellToCell/cellToCell.C b/src/meshTools/topoSet/cellSources/cellToCell/cellToCell.C index e43ab9ee640..667ccd02c3d 100644 --- a/src/meshTools/topoSet/cellSources/cellToCell/cellToCell.C +++ b/src/meshTools/topoSet/cellSources/cellToCell/cellToCell.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -60,7 +60,8 @@ Foam::cellToCell::cellToCell ) : topoSetCellSource(mesh), - names_(one{}, setName) + names_(Foam::one{}, setName), + isZone_(false) {} @@ -71,15 +72,9 @@ Foam::cellToCell::cellToCell ) : topoSetCellSource(mesh, dict), - names_() -{ - // Look for 'sets' or 'set' - if (!dict.readIfPresent("sets", names_)) - { - names_.resize(1); - dict.readEntry("set", names_.front()); - } -} + names_(), + isZone_(topoSetSource::readNames(dict, names_)) +{} Foam::cellToCell::cellToCell @@ -89,7 +84,8 @@ Foam::cellToCell::cellToCell ) : topoSetCellSource(mesh), - names_(one{}, word(checkIs(is))) + names_(Foam::one{}, word(checkIs(is))), + isZone_(false) {} @@ -105,30 +101,44 @@ void Foam::cellToCell::applyToSet { if (verbose_) { - Info<< " Adding all elements of cell sets: " + Info<< " Adding all elements of cell " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } for (const word& setName : names_) { - cellSet loadedSet(mesh_, setName); - - set.addSet(loadedSet); + if (isZone_) + { + set.addSet(mesh_.cellZones()[setName]); + } + else + { + cellSet loadedSet(mesh_, setName); + set.addSet(loadedSet); + } } } else if (action == topoSetSource::SUBTRACT) { if (verbose_) { - Info<< " Removing all elements of cell sets: " + Info<< " Removing all elements of cell " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } for (const word& setName : names_) { - cellSet loadedSet(mesh_, setName); - - set.subtractSet(loadedSet); + if (isZone_) + { + set.subtractSet(mesh_.cellZones()[setName]); + } + else + { + cellSet loadedSet(mesh_, setName); + set.subtractSet(loadedSet); + } } } } diff --git a/src/meshTools/topoSet/cellSources/cellToCell/cellToCell.H b/src/meshTools/topoSet/cellSources/cellToCell/cellToCell.H index 1a42aa8b00d..fb595cb7872 100644 --- a/src/meshTools/topoSet/cellSources/cellToCell/cellToCell.H +++ b/src/meshTools/topoSet/cellSources/cellToCell/cellToCell.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,8 @@ Class Foam::cellToCell Description - A \c topoSetCellSource to select all the cells from given \c cellSet(s). + A \c topoSetCellSource to select all the cells from given \c cellSet(s) + or \c cellZone(s). Operands: \table @@ -50,7 +51,7 @@ Usage source cellToCell; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 sets @@ -61,7 +62,18 @@ Usage ); // Option-2 - set <cellSetName>; + zones + ( + <cellZoneName0> + <cellZoneName1> + ... + ); + + // Option-3 + set <cellSetName>; + + // Option-4 + zone <cellZoneName>; } \endverbatim @@ -81,17 +93,15 @@ Usage subtract | Remove selected cells from this cellSet \endverbatim - Options for the conditional mandatory entries: + Options for the conditional mandatory entries (in order of precedence): \verbatim Entry | Description | Type | Req'd | Dflt sets | Names of input cellSets | wordList | cond'l | - + zones | Names of input cellZones | wordList | cond'l | - set | Name of input cellSet | word | cond'l | - + zone | Name of input cellZone | word | cond'l | - \endverbatim -Note - The order of precedence among the conditional mandatory entries from the - highest to the lowest is \c sets, and \c set. - See also - Foam::topoSetSource - Foam::topoSetCellSource @@ -101,8 +111,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef cellToCell_H -#define cellToCell_H +#ifndef Foam_cellToCell_H +#define Foam_cellToCell_H #include "topoSetCellSource.H" @@ -124,9 +134,12 @@ class cellToCell //- Add usage string static addToUsageTable usage_; - //- Names of sets to use + //- Names of sets or zones to use wordList names_; + //- Is name a set or a zone + const bool isZone_; + public: diff --git a/src/meshTools/topoSet/cellSources/faceToCell/faceToCell.C b/src/meshTools/topoSet/cellSources/faceToCell/faceToCell.C index ec52df9e2d4..a71a70760b9 100644 --- a/src/meshTools/topoSet/cellSources/faceToCell/faceToCell.C +++ b/src/meshTools/topoSet/cellSources/faceToCell/faceToCell.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -66,18 +66,14 @@ Foam::faceToCell::faceActionNames_ // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::faceToCell::combine +template<class Selector> +void Foam::faceToCell::combineImpl ( topoSet& set, const bool add, - const word& setName + const Selector& faceLabels ) const { - // Load the set - faceSet loadedSet(mesh_, setName); - - const labelHashSet& faceLabels = loadedSet; - // Handle owner/neighbour/any selection for (const label facei : faceLabels) { @@ -104,7 +100,7 @@ void Foam::faceToCell::combine { // Count number of selected faces per cell. - Map<label> facesPerCell(loadedSet.size()); + Map<label> facesPerCell(faceLabels.size()); for (const label facei : faceLabels) { @@ -134,6 +130,31 @@ void Foam::faceToCell::combine } +void Foam::faceToCell::combine +( + topoSet& set, + const bool add, + const word& setName +) const +{ + if (isZone_) + { + const labelList& faceLabels = mesh_.faceZones()[setName]; + + combineImpl(set, add, faceLabels); + } + else + { + // Load the set + faceSet loadedSet(mesh_, setName); + + const labelHashSet& faceLabels = loadedSet; + + combineImpl(set, add, faceLabels); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::faceToCell::faceToCell @@ -144,7 +165,8 @@ Foam::faceToCell::faceToCell ) : topoSetCellSource(mesh), - names_(one{}, setName), + names_(Foam::one{}, setName), + isZone_(false), option_(option) {} @@ -157,15 +179,9 @@ Foam::faceToCell::faceToCell : topoSetCellSource(mesh, dict), names_(), + isZone_(topoSetSource::readNames(dict, names_)), option_(faceActionNames_.get("option", dict)) -{ - // Look for 'sets' or 'set' - if (!dict.readIfPresent("sets", names_)) - { - names_.resize(1); - dict.readEntry("set", names_.front()); - } -} +{} Foam::faceToCell::faceToCell @@ -175,7 +191,8 @@ Foam::faceToCell::faceToCell ) : topoSetCellSource(mesh), - names_(one{}, word(checkIs(is))), + names_(Foam::one{}, word(checkIs(is))), + isZone_(false), option_(faceActionNames_.read(checkIs(is))) {} @@ -192,8 +209,9 @@ void Foam::faceToCell::applyToSet { if (verbose_) { - Info<< " Adding cells according to face sets: " - << flatOutput(names_) << endl; + Info<< " Adding cells according to face " + << (isZone_ ? "zones: " : "sets: ") + << flatOutput(names_) << nl; } for (const word& setName : names_) @@ -205,8 +223,9 @@ void Foam::faceToCell::applyToSet { if (verbose_) { - Info<< " Removing cells according to face sets: " - << flatOutput(names_) << endl; + Info<< " Removing cells according to face " + << (isZone_ ? "zones: " : "sets: ") + << flatOutput(names_) << nl; } for (const word& setName : names_) diff --git a/src/meshTools/topoSet/cellSources/faceToCell/faceToCell.H b/src/meshTools/topoSet/cellSources/faceToCell/faceToCell.H index dbd6f18f8a3..36811cbe32c 100644 --- a/src/meshTools/topoSet/cellSources/faceToCell/faceToCell.H +++ b/src/meshTools/topoSet/cellSources/faceToCell/faceToCell.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -53,7 +53,7 @@ Usage option <option>; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 sets @@ -64,7 +64,18 @@ Usage ); // Option-2 + zones + ( + <faceZoneName0> + <faceZoneName1> + ... + ); + + // Option-3 set <faceSetName>; + + // Option-4 + zone <faceZoneName>; } \endverbatim @@ -93,17 +104,15 @@ Usage neighbour | Cells that are neighbour of given faces \endverbatim - Options for the conditional mandatory entries: + Options for the conditional mandatory entries (in order of precedence): \verbatim Entry | Description | Type | Req'd | Dflt sets | Names of input faceSets | wordList | cond'l | - + zones | Names of input faceZones | wordList | cond'l | - set | Name of input faceSet | word | cond'l | - + zone | Name of input faceZone | word | cond'l | - \endverbatim -Note - The order of precedence among the conditional mandatory entries from the - highest to the lowest is \c sets, and \c set. - See also - Foam::topoSetSource - Foam::topoSetCellSource @@ -114,8 +123,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef faceToCell_H -#define faceToCell_H +#ifndef Foam_faceToCell_H +#define Foam_faceToCell_H #include "topoSetCellSource.H" #include "Enum.H" @@ -153,15 +162,27 @@ private: //- Add usage string static addToUsageTable usage_; - //- Names of sets to use + //- Names of sets or zones to use wordList names_; + //- Is name a set or a zone + const bool isZone_; + //- Option faceAction option_; // Private Member Functions + //- Depending on face to cell option add to or delete from cellSet. + template<class Selector> + void combineImpl + ( + topoSet& set, + const bool add, + const Selector& faceLabels + ) const; + //- Depending on face to cell option add to or delete from cellSet. void combine(topoSet& set, const bool add, const word& setName) const; diff --git a/src/meshTools/topoSet/cellSources/faceZoneToCell/faceZoneToCell.H b/src/meshTools/topoSet/cellSources/faceZoneToCell/faceZoneToCell.H index 44da5e124dc..c5fbd88148c 100644 --- a/src/meshTools/topoSet/cellSources/faceZoneToCell/faceZoneToCell.H +++ b/src/meshTools/topoSet/cellSources/faceZoneToCell/faceZoneToCell.H @@ -52,7 +52,7 @@ Usage option <option>; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 zones @@ -63,7 +63,7 @@ Usage ); // Option-2 - set <faceZoneName>; + zone <faceZoneName>; } \endverbatim diff --git a/src/meshTools/topoSet/cellSources/patchToCell/patchToCell.H b/src/meshTools/topoSet/cellSources/patchToCell/patchToCell.H index 4f787642884..7705e0b10cc 100644 --- a/src/meshTools/topoSet/cellSources/patchToCell/patchToCell.H +++ b/src/meshTools/topoSet/cellSources/patchToCell/patchToCell.H @@ -48,7 +48,7 @@ Usage source patchToCell; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 patches diff --git a/src/meshTools/topoSet/cellSources/pointToCell/pointToCell.C b/src/meshTools/topoSet/cellSources/pointToCell/pointToCell.C index 17b26421bb9..9c74f9e3e6d 100644 --- a/src/meshTools/topoSet/cellSources/pointToCell/pointToCell.C +++ b/src/meshTools/topoSet/cellSources/pointToCell/pointToCell.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -64,18 +64,14 @@ Foam::pointToCell::pointActionNames_ // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::pointToCell::combine +template<class Selector> +void Foam::pointToCell::combineImpl ( topoSet& set, const bool add, - const word& setName + const Selector& pointLabels ) const { - // Load the set - pointSet loadedSet(mesh_, setName); - - const labelHashSet& pointLabels = loadedSet; - // Handle any selection if (option_ == ANY) { @@ -114,6 +110,31 @@ void Foam::pointToCell::combine } +void Foam::pointToCell::combine +( + topoSet& set, + const bool add, + const word& setName +) const +{ + if (isZone_) + { + const labelList& pointLabels = mesh_.pointZones()[setName]; + + combineImpl(set, add, pointLabels); + } + else + { + // Load the set + pointSet loadedSet(mesh_, setName); + + const labelHashSet& pointLabels = loadedSet; + + combineImpl(set, add, pointLabels); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::pointToCell::pointToCell @@ -124,7 +145,8 @@ Foam::pointToCell::pointToCell ) : topoSetCellSource(mesh), - names_(one{}, setName), + names_(Foam::one{}, setName), + isZone_(false), option_(option) {} @@ -137,15 +159,9 @@ Foam::pointToCell::pointToCell : topoSetCellSource(mesh, dict), names_(), + isZone_(topoSetSource::readNames(dict, names_)), option_(pointActionNames_.get("option", dict)) -{ - // Look for 'sets' or 'set' - if (!dict.readIfPresent("sets", names_)) - { - names_.resize(1); - dict.readEntry("set", names_.front()); - } -} +{} Foam::pointToCell::pointToCell @@ -155,7 +171,8 @@ Foam::pointToCell::pointToCell ) : topoSetCellSource(mesh), - names_(one{}, word(checkIs(is))), + names_(Foam::one{}, word(checkIs(is))), + isZone_(false), option_(pointActionNames_.read(checkIs(is))) {} @@ -172,7 +189,8 @@ void Foam::pointToCell::applyToSet { if (verbose_) { - Info<< " Adding cells according to point sets: " + Info<< " Adding cells according to point " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } @@ -185,7 +203,8 @@ void Foam::pointToCell::applyToSet { if (verbose_) { - Info<< " Removing cells according to point sets: " + Info<< " Removing cells according to point " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } diff --git a/src/meshTools/topoSet/cellSources/pointToCell/pointToCell.H b/src/meshTools/topoSet/cellSources/pointToCell/pointToCell.H index 7d5432501d8..5fd938e079d 100644 --- a/src/meshTools/topoSet/cellSources/pointToCell/pointToCell.H +++ b/src/meshTools/topoSet/cellSources/pointToCell/pointToCell.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2012 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,7 +52,7 @@ Usage option <option>; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 sets @@ -62,8 +62,19 @@ Usage ... ); - // Option-2 - set <pointSetName>; + // Option-3 + zones + ( + <pointZoneName0> + <pointZoneName1> + ... + ); + + // Option-3 + set <pointSetName>; + + // Option-4 + zone <pointZoneName>; } \endverbatim @@ -90,17 +101,15 @@ Usage edge | Cells using an edge with both points in pointSet \endverbatim - Options for the conditional mandatory entries: + Options for the conditional mandatory entries (in order of precedence): \verbatim Entry | Description | Type | Req'd | Dflt sets | Names of input pointSets | wordList | cond'l | - + zones | Names of input pointZones | wordList | cond'l | - set | Name of input pointSet | word | cond'l | - + zone | Name of input pointZone | word | cond'l | - \endverbatim -Note - The order of precedence among the conditional mandatory entries from the - highest to the lowest is \c sets, and \c set. - See also - Foam::topoSetSource - Foam::topoSetCellSource @@ -110,8 +119,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef pointToCell_H -#define pointToCell_H +#ifndef Foam_pointToCell_H +#define Foam_pointToCell_H #include "topoSetCellSource.H" #include "Enum.H" @@ -148,15 +157,27 @@ private: static const Enum<pointAction> pointActionNames_; - //- Names of sets to use + //- Names of sets or zones to use wordList names_; + //- Is name a set or a zone + const bool isZone_; + //- Selection type pointAction option_; // Private Member Functions + //- Depending on point to cell option add to or delete from cellSet. + template<class Selector> + void combineImpl + ( + topoSet& set, + const bool add, + const Selector& pointLabels + ) const; + //- Depending on point-to-cell option add to or delete from cellSet. void combine(topoSet& set, const bool add, const word& setName) const; diff --git a/src/meshTools/topoSet/cellSources/regionToCell/regionToCell.C b/src/meshTools/topoSet/cellSources/regionToCell/regionToCell.C index c83ec7ec74e..f192b4f37d6 100644 --- a/src/meshTools/topoSet/cellSources/regionToCell/regionToCell.C +++ b/src/meshTools/topoSet/cellSources/regionToCell/regionToCell.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -346,18 +346,33 @@ void Foam::regionToCell::combine(topoSet& set, const bool add) const // Note: wip. Select cells first boolList selectedCell(mesh_.nCells(), true); - if (setName_.size() && setName_ != "none") + if (!setName_.empty() && setName_ != "none") { - Info<< " Loading subset " << setName_ - << " to delimit search region." - << endl; - - cellSet subSet(mesh_, setName_); + if (isZone_) + { + Info<< " Using cellZone " << setName_ + << " to delimit search region." + << endl; - selectedCell = false; - for (const label celli : subSet) + selectedCell = false; + for (const label celli : mesh_.cellZones()[setName_]) + { + selectedCell[celli] = true; + } + } + else { - selectedCell[celli] = true; + Info<< " Loading cellSet " << setName_ + << " to delimit search region." + << endl; + + cellSet subSet(mesh_, setName_); + + selectedCell = false; + for (const label celli : subSet) + { + selectedCell[celli] = true; + } } } @@ -392,6 +407,7 @@ Foam::regionToCell::regionToCell : topoSetCellSource(mesh), setName_(setName), + isZone_(false), insidePoints_(insidePoints), nErode_(nErode) {} @@ -404,13 +420,24 @@ Foam::regionToCell::regionToCell ) : topoSetCellSource(mesh, dict), - setName_(dict.getOrDefault<word>("set", "none")), + setName_(), + isZone_(false), insidePoints_ ( dict.getCompat<pointField>("insidePoints", {{ "insidePoint", 0 }}) ), nErode_(dict.getCheckOrDefault<label>("nErode", 0, labelMinMax::ge(0))) -{} +{ + // A single set or zone only! + if (dict.readIfPresent("set", setName_)) + { + isZone_ = false; + } + else if (dict.readIfPresent("zone", setName_)) + { + isZone_ = true; + } +} Foam::regionToCell::regionToCell @@ -421,6 +448,7 @@ Foam::regionToCell::regionToCell : topoSetCellSource(mesh), setName_(checkIs(is)), + isZone_(false), insidePoints_(checkIs(is)), nErode_(readLabel(checkIs(is))) {} diff --git a/src/meshTools/topoSet/cellSources/regionToCell/regionToCell.H b/src/meshTools/topoSet/cellSources/regionToCell/regionToCell.H index 4d273ffa5b7..2dd718a81b7 100644 --- a/src/meshTools/topoSet/cellSources/regionToCell/regionToCell.H +++ b/src/meshTools/topoSet/cellSources/regionToCell/regionToCell.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2012 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -59,6 +59,7 @@ Usage // Optional entries set <cellSetName>; + zone <cellZoneName>; nErode <label>; } \endverbatim @@ -93,8 +94,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef regionToCell_H -#define regionToCell_H +#ifndef Foam_regionToCell_H +#define Foam_regionToCell_H #include "topoSetCellSource.H" #include "boolList.H" @@ -119,8 +120,11 @@ class regionToCell //- Add usage string static addToUsageTable usage_; - //- Name of cellSet to keep to - const word setName_; + //- Name of cellSet or cellZone to keep to + word setName_; + + //- Is name a set or a zone + bool isZone_; //- Coordinate(s) that is inside connected region const pointField insidePoints_; diff --git a/src/meshTools/topoSet/cellSources/zoneToCell/zoneToCell.H b/src/meshTools/topoSet/cellSources/zoneToCell/zoneToCell.H index a83ce416eca..e9c2e128554 100644 --- a/src/meshTools/topoSet/cellSources/zoneToCell/zoneToCell.H +++ b/src/meshTools/topoSet/cellSources/zoneToCell/zoneToCell.H @@ -50,7 +50,7 @@ Usage source zoneToCell; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 zones diff --git a/src/meshTools/topoSet/cellZoneSources/setToCellZone/setToCellZone.C b/src/meshTools/topoSet/cellZoneSources/setToCellZone/setToCellZone.C index d0e4d3f3025..ca3d0c1d78e 100644 --- a/src/meshTools/topoSet/cellZoneSources/setToCellZone/setToCellZone.C +++ b/src/meshTools/topoSet/cellZoneSources/setToCellZone/setToCellZone.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -123,7 +123,7 @@ void Foam::setToCellZone::applyToSet { if (!zoneSet.found(celli)) { - newAddressing.append(celli); + newAddressing.push_back(celli); } } @@ -144,11 +144,11 @@ void Foam::setToCellZone::applyToSet // Start off empty DynamicList<label> newAddressing(zoneSet.addressing().size()); - forAll(zoneSet.addressing(), i) + for (const label celli : zoneSet.addressing()) { - if (!loadedSet.found(zoneSet.addressing()[i])) + if (!loadedSet.found(celli)) { - newAddressing.append(zoneSet.addressing()[i]); + newAddressing.push_back(celli); } } zoneSet.addressing().transfer(newAddressing); diff --git a/src/meshTools/topoSet/faceSources/boxToFace/boxToFace.H b/src/meshTools/topoSet/faceSources/boxToFace/boxToFace.H index ecd4b0b305b..3df24f8b5ed 100644 --- a/src/meshTools/topoSet/faceSources/boxToFace/boxToFace.H +++ b/src/meshTools/topoSet/faceSources/boxToFace/boxToFace.H @@ -50,7 +50,7 @@ Usage source boxToFace; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 boxes diff --git a/src/meshTools/topoSet/faceSources/cellToFace/cellToFace.C b/src/meshTools/topoSet/faceSources/cellToFace/cellToFace.C index 7c4a4c4be33..d3b7508de72 100644 --- a/src/meshTools/topoSet/faceSources/cellToFace/cellToFace.C +++ b/src/meshTools/topoSet/faceSources/cellToFace/cellToFace.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -68,23 +68,14 @@ Foam::cellToFace::cellActionNames_ // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::cellToFace::combine +template<class Selector> +void Foam::cellToFace::combineImpl ( topoSet& set, const bool add, - const word& setName + const Selector& cellLabels ) const { - // Load the set - if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName))) - { - SeriousError<< "Cannot load set " - << setName << endl; - } - - cellSet loadedSet(mesh_, setName); - const labelHashSet& cellLabels = loadedSet; - if (option_ == ALL) { // Add all faces from cell @@ -212,6 +203,36 @@ void Foam::cellToFace::combine } +void Foam::cellToFace::combine +( + topoSet& set, + const bool add, + const word& setName +) const +{ + if (isZone_) + { + const labelList& cellLabels = mesh_.cellZones()[setName]; + + combineImpl(set, add, cellLabels); + } + else + { + // Load the set + if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName))) + { + SeriousError<< "Cannot load set " + << setName << endl; + } + + cellSet loadedSet(mesh_, setName); + const labelHashSet& cellLabels = loadedSet; + + combineImpl(set, add, cellLabels); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::cellToFace::cellToFace @@ -222,7 +243,8 @@ Foam::cellToFace::cellToFace ) : topoSetFaceSource(mesh), - names_(one{}, setName), + names_(Foam::one{}, setName), + isZone_(false), option_(option) {} @@ -235,15 +257,9 @@ Foam::cellToFace::cellToFace : topoSetFaceSource(mesh, dict), names_(), + isZone_(topoSetSource::readNames(dict, names_)), option_(cellActionNames_.get("option", dict)) -{ - // Look for 'sets' or 'set' - if (!dict.readIfPresent("sets", names_)) - { - names_.resize(1); - dict.readEntry("set", names_.front()); - } -} +{} Foam::cellToFace::cellToFace @@ -253,7 +269,8 @@ Foam::cellToFace::cellToFace ) : topoSetFaceSource(mesh), - names_(one{}, word(checkIs(is))), + names_(Foam::one{}, word(checkIs(is))), + isZone_(false), option_(cellActionNames_.read(checkIs(is))) {} @@ -270,7 +287,8 @@ void Foam::cellToFace::applyToSet { if (verbose_) { - Info<< " Adding faces according to cell sets: " + Info<< " Adding faces according to cell " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } @@ -283,7 +301,8 @@ void Foam::cellToFace::applyToSet { if (verbose_) { - Info<< " Removing faces according to cell sets: " + Info<< " Removing faces according to cell " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } diff --git a/src/meshTools/topoSet/faceSources/cellToFace/cellToFace.H b/src/meshTools/topoSet/faceSources/cellToFace/cellToFace.H index d1c5638a597..5b197e15a27 100644 --- a/src/meshTools/topoSet/faceSources/cellToFace/cellToFace.H +++ b/src/meshTools/topoSet/faceSources/cellToFace/cellToFace.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,7 +51,7 @@ Usage option <option>; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 sets @@ -62,7 +62,18 @@ Usage ); // Option-2 - set <cellSetName>; + zones + ( + <cellZoneName0> + <cellZoneName1> + ... + ); + + // Option-3 + set <cellSetName>; + + // Option-4 + zone <cellZoneName>; } \endverbatim @@ -90,16 +101,16 @@ Usage outside | Faces with only one neighbour in the cellSet \endverbatim - Options for the conditional mandatory entries: + Options for the conditional mandatory entries (in order of precedence): \verbatim Entry | Description | Type | Reqd | Deflt sets | Names of input cellSets | wordList | choice | - + zones | Names of input cellZones | wordList | cond'l | - set | Name of input cellSet | word | choice | - + zone | Name of input cellZone | word | cond'l | - \endverbatim Note - - The order of precedence among the conditional mandatory entries from the - highest to the lowest is \c sets, and \c set. - The \c outside option applies to the cellSets individually. See also @@ -149,9 +160,12 @@ private: static const Enum<cellAction> cellActionNames_; - //- Names of cellSets to use + //- Names of sets or zones to use wordList names_; + //- Is name a set or a zone + const bool isZone_; + //- Selection type cellAction option_; @@ -159,6 +173,15 @@ private: // Private Member Functions //- Depending on face to cell option add to or delete from cellSet. + template<class Selector> + void combineImpl + ( + topoSet& set, + const bool add, + const Selector& cellLabels + ) const; + + //- Depending on face to cell option add to or delete from set. void combine(topoSet& set, const bool add, const word& setName) const; diff --git a/src/meshTools/topoSet/faceSources/faceToFace/faceToFace.C b/src/meshTools/topoSet/faceSources/faceToFace/faceToFace.C index 8fbcf20838c..9eaed67c4e6 100644 --- a/src/meshTools/topoSet/faceSources/faceToFace/faceToFace.C +++ b/src/meshTools/topoSet/faceSources/faceToFace/faceToFace.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -60,7 +60,8 @@ Foam::faceToFace::faceToFace ) : topoSetFaceSource(mesh), - names_(one{}, setName) + names_(Foam::one{}, setName), + isZone_(false) {} @@ -71,15 +72,9 @@ Foam::faceToFace::faceToFace ) : topoSetFaceSource(mesh, dict), - names_() -{ - // Look for 'sets' or 'set' - if (!dict.readIfPresent("sets", names_)) - { - names_.resize(1); - dict.readEntry("set", names_.front()); - } -} + names_(), + isZone_(topoSetSource::readNames(dict, names_)) +{} Foam::faceToFace::faceToFace @@ -89,7 +84,8 @@ Foam::faceToFace::faceToFace ) : topoSetFaceSource(mesh), - names_(one{}, word(checkIs(is))) + names_(Foam::one{}, word(checkIs(is))), + isZone_(false) {} @@ -105,30 +101,46 @@ void Foam::faceToFace::applyToSet { if (verbose_) { - Info<< " Adding all elements of face sets: " + Info<< " Adding all elements of face " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } for (const word& setName : names_) { - faceSet loadedSet(mesh_, setName); - - set.addSet(loadedSet); + if (isZone_) + { + set.addSet(mesh_.faceZones()[setName]); + } + else + { + faceSet loadedSet(mesh_, setName); + + set.addSet(loadedSet); + } } } else if (action == topoSetSource::SUBTRACT) { if (verbose_) { - Info<< " Removing all elements of face sets: " + Info<< " Removing all elements of face " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } for (const word& setName : names_) { - faceSet loadedSet(mesh_, setName); - - set.subtractSet(loadedSet); + if (isZone_) + { + set.subtractSet(mesh_.faceZones()[setName]); + } + else + { + faceSet loadedSet(mesh_, setName); + + set.subtractSet(loadedSet); + } } } } diff --git a/src/meshTools/topoSet/faceSources/faceToFace/faceToFace.H b/src/meshTools/topoSet/faceSources/faceToFace/faceToFace.H index 67642a41ea9..b02309df68e 100644 --- a/src/meshTools/topoSet/faceSources/faceToFace/faceToFace.H +++ b/src/meshTools/topoSet/faceSources/faceToFace/faceToFace.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -50,7 +50,7 @@ Usage source faceToFace; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 sets @@ -61,7 +61,18 @@ Usage ); // Option-2 + zones + ( + <faceZoneName0> + <faceZoneName1> + ... + ); + + // Option-3 set <faceSetName>; + + // Option-4 + zone <faceZoneName>; } \endverbatim @@ -81,11 +92,13 @@ Usage subtract | Remove selected faces from this faceSet \endverbatim - Options for the conditional mandatory entries: + Options for the conditional mandatory entries (in order of precedence): \verbatim Entry | Description | Type | Req'd | Dflt sets | Names of input faceSets | wordList | cond'l | - + zones | Names of input faceZones | wordList | cond'l | - set | Name of input faceSet | word | cond'l | - + zone | Name of input faceZone | word | cond'l | - \endverbatim Note @@ -101,8 +114,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef faceToFace_H -#define faceToFace_H +#ifndef Foam_faceToFace_H +#define Foam_faceToFace_H #include "topoSetFaceSource.H" @@ -124,9 +137,12 @@ class faceToFace //- Add usage string static addToUsageTable usage_; - //- Names of faceSets to use + //- Names of sets or zones to use wordList names_; + //- Is name a set or a zone + const bool isZone_; + public: diff --git a/src/meshTools/topoSet/faceSources/holeToFace/holeToFace.C b/src/meshTools/topoSet/faceSources/holeToFace/holeToFace.C index 3816a19a6df..90781958d53 100644 --- a/src/meshTools/topoSet/faceSources/holeToFace/holeToFace.C +++ b/src/meshTools/topoSet/faceSources/holeToFace/holeToFace.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2020-2022 OpenCFD Ltd. + Copyright (C) 2020-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1149,7 +1149,7 @@ void Foam::holeToFace::applyToSet for (const word& setName : blockedFaceNames_) { const faceSet loadedSet(mesh_, setName); - isBlockedFace.set(loadedSet.toc()); + isBlockedFace.setMany(loadedSet.begin(), loadedSet.end()); } // Optional initial blocked cells @@ -1159,7 +1159,7 @@ void Foam::holeToFace::applyToSet for (const word& setName : blockedCellNames_) { const cellSet loadedSet(mesh_, setName); - isCandidateCell.set(loadedSet.toc()); + isCandidateCell.setMany(loadedSet.begin(), loadedSet.end()); } } else diff --git a/src/meshTools/topoSet/faceSources/patchToFace/patchToFace.H b/src/meshTools/topoSet/faceSources/patchToFace/patchToFace.H index 844824483d7..792fad47fc6 100644 --- a/src/meshTools/topoSet/faceSources/patchToFace/patchToFace.H +++ b/src/meshTools/topoSet/faceSources/patchToFace/patchToFace.H @@ -49,7 +49,7 @@ Usage source patchToFace; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 patches diff --git a/src/meshTools/topoSet/faceSources/pointToFace/pointToFace.C b/src/meshTools/topoSet/faceSources/pointToFace/pointToFace.C index 9633b6b4248..6a4a77b96e5 100644 --- a/src/meshTools/topoSet/faceSources/pointToFace/pointToFace.C +++ b/src/meshTools/topoSet/faceSources/pointToFace/pointToFace.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -82,18 +82,14 @@ Foam::pointToFace::pointActionNames_ // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::pointToFace::combine +template<class Selector> +void Foam::pointToFace::combineImpl ( topoSet& set, const bool add, - const word& setName + const Selector& pointLabels ) const { - // Load the set - pointSet loadedSet(mesh_, setName); - - const labelHashSet& pointLabels = loadedSet; - if (option_ == ANY) { // Add faces with any point in loadedSet @@ -160,6 +156,31 @@ void Foam::pointToFace::combine } +void Foam::pointToFace::combine +( + topoSet& set, + const bool add, + const word& setName +) const +{ + if (isZone_) + { + const labelList& pointLabels = mesh_.pointZones()[setName]; + + combineImpl(set, add, pointLabels); + } + else + { + // Load the set + pointSet loadedSet(mesh_, setName); + + const labelHashSet& pointLabels = loadedSet; + + combineImpl(set, add, pointLabels); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::pointToFace::pointToFace @@ -170,7 +191,8 @@ Foam::pointToFace::pointToFace ) : topoSetFaceSource(mesh), - names_(one{}, setName), + names_(Foam::one{}, setName), + isZone_(false), option_(option) {} @@ -183,15 +205,9 @@ Foam::pointToFace::pointToFace : topoSetFaceSource(mesh, dict), names_(), + isZone_(topoSetSource::readNames(dict, names_)), option_(pointActionNames_.get("option", dict)) -{ - // Look for 'sets' or 'set' - if (!dict.readIfPresent("sets", names_)) - { - names_.resize(1); - dict.readEntry("set", names_.front()); - } -} +{} Foam::pointToFace::pointToFace @@ -201,7 +217,8 @@ Foam::pointToFace::pointToFace ) : topoSetFaceSource(mesh), - names_(one{}, word(checkIs(is))), + names_(Foam::one{}, word(checkIs(is))), + isZone_(false), option_(pointActionNames_.read(checkIs(is))) {} @@ -218,7 +235,8 @@ void Foam::pointToFace::applyToSet { if (verbose_) { - Info<< " Adding faces according to point sets: " + Info<< " Adding faces according to point " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } @@ -231,7 +249,8 @@ void Foam::pointToFace::applyToSet { if (verbose_) { - Info<< " Removing faces according to point sets: " + Info<< " Removing faces according to point " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } diff --git a/src/meshTools/topoSet/faceSources/pointToFace/pointToFace.H b/src/meshTools/topoSet/faceSources/pointToFace/pointToFace.H index ea632bc4819..ebf18e4d35b 100644 --- a/src/meshTools/topoSet/faceSources/pointToFace/pointToFace.H +++ b/src/meshTools/topoSet/faceSources/pointToFace/pointToFace.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2012 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,7 +52,7 @@ Usage option <option>; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 sets @@ -63,7 +63,18 @@ Usage ); // Option-2 - set <pointSetName>; + zones + ( + <pointZoneName0> + <pointZoneName1> + ... + ); + + // Option-3 + set <pointSetName>; + + // Option-4 + zone <pointZoneName>; } \endverbatim @@ -91,17 +102,15 @@ Usage all | All points in the pointSet \endverbatim - Options for the conditional mandatory entries: + Options for the conditional mandatory entries (in order of precedence): \verbatim Entry | Description | Type | Req'd | Dflt sets | Names of input pointSets | wordList | cond'l | - + zones | Names of input pointZones | wordList | cond'l | - set | Name of input pointSet | word | cond'l | - + zone | Name of input pointZone | word | cond'l | - \endverbatim -Note - The order of precedence among the conditional mandatory entries from the - highest to the lowest is \c sets, and \c set. - See also - Foam::topoSetSource - Foam::topoSetFaceSource @@ -111,8 +120,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef pointToFace_H -#define pointToFace_H +#ifndef Foam_pointToFace_H +#define Foam_pointToFace_H #include "topoSetFaceSource.H" #include "Enum.H" @@ -149,15 +158,27 @@ private: static const Enum<pointAction> pointActionNames_; - //- Names of sets to use + //- Names of sets or zones to use wordList names_; + //- Is name a set or a zone + const bool isZone_; + //- Option pointAction option_; // Private Member Functions + //- Depending on option add to or delete from set. + template<class Selector> + void combineImpl + ( + topoSet& set, + const bool add, + const Selector& pointLabels + ) const; + //- Depending on face to cell option add to or delete from faceSet. void combine(topoSet& set, const bool add, const word& setName) const; diff --git a/src/meshTools/topoSet/faceSources/regionToFace/regionToFace.C b/src/meshTools/topoSet/faceSources/regionToFace/regionToFace.C index 8bb3e8815ff..683e5e68e0e 100644 --- a/src/meshTools/topoSet/faceSources/regionToFace/regionToFace.C +++ b/src/meshTools/topoSet/faceSources/regionToFace/regionToFace.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2017 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -136,7 +136,12 @@ void Foam::regionToFace::markZone } -void Foam::regionToFace::combine(topoSet& set, const bool add) const +void Foam::regionToFace::combine +( + topoSet& set, + const bool add, + const labelUList& ids +) const { if (verbose_) { @@ -144,11 +149,9 @@ void Foam::regionToFace::combine(topoSet& set, const bool add) const << " to delimit search region." << endl; } - faceSet subSet(mesh_, setName_); - indirectPrimitivePatch patch ( - IndirectList<face>(mesh_.faces(), subSet.toc()), + IndirectList<face>(mesh_.faces(), ids), mesh_.points() ); @@ -158,7 +161,7 @@ void Foam::regionToFace::combine(topoSet& set, const bool add) const Tuple2<scalar, label> ( sqr(GREAT), - Pstream::myProcNo() + UPstream::myProcNo() ) ); @@ -217,6 +220,7 @@ Foam::regionToFace::regionToFace : topoSetFaceSource(mesh), setName_(setName), + isZone_(false), nearPoint_(nearPoint) {} @@ -228,9 +232,20 @@ Foam::regionToFace::regionToFace ) : topoSetFaceSource(mesh, dict), - setName_(dict.get<word>("set")), + setName_(), + isZone_(false), nearPoint_(dict.get<point>("nearPoint")) -{} +{ + if (dict.readIfPresent("set", setName_)) + { + isZone_ = false; + } + else + { + dict.readEntry("zone", setName_); + isZone_ = true; + } +} Foam::regionToFace::regionToFace @@ -241,6 +256,7 @@ Foam::regionToFace::regionToFace : topoSetFaceSource(mesh), setName_(checkIs(is)), + isZone_(false), nearPoint_(checkIs(is)) {} @@ -257,23 +273,41 @@ void Foam::regionToFace::applyToSet { if (verbose_) { - Info<< " Adding all faces of connected region of set " + Info<< " Adding all faces of connected region of " + << (isZone_ ? "zone " : "set ") << setName_ << " starting from point " << nearPoint_ << " ..." << endl; } - combine(set, true); + if (isZone_) + { + combine(set, true, mesh_.faceZones()[setName_].addressing()); + } + else + { + faceSet subSet(mesh_, setName_); + combine(set, true, subSet.sortedToc()); + } } else if (action == topoSetSource::SUBTRACT) { if (verbose_) { - Info<< " Removing all cells of connected region of set " + Info<< " Removing all cells of connected region of " + << (isZone_ ? "zone " : "set ") << setName_ << " starting from point " << nearPoint_ << " ..." << endl; } - combine(set, false); + if (isZone_) + { + combine(set, false, mesh_.faceZones()[setName_].addressing()); + } + else + { + faceSet subSet(mesh_, setName_); + combine(set, false, subSet.sortedToc()); + } } } diff --git a/src/meshTools/topoSet/faceSources/regionToFace/regionToFace.H b/src/meshTools/topoSet/faceSources/regionToFace/regionToFace.H index 9fafcb87e97..f0faf5dd79c 100644 --- a/src/meshTools/topoSet/faceSources/regionToFace/regionToFace.H +++ b/src/meshTools/topoSet/faceSources/regionToFace/regionToFace.H @@ -105,11 +105,14 @@ class regionToFace //- Add usage string static addToUsageTable usage_; - //- Name of set to use + //- Name of set or zone to use word setName_; + //- Is name a set or a zone + bool isZone_; + //- Coordinate that is nearest/on connected region - point nearPoint_; + const point nearPoint_; // Private Member Functions @@ -124,7 +127,12 @@ class regionToFace labelList& faceZone ) const; - void combine(topoSet& set, const bool add) const; + void combine + ( + topoSet& set, + const bool add, + const labelUList& ids + ) const; public: diff --git a/src/meshTools/topoSet/faceSources/zoneToFace/zoneToFace.H b/src/meshTools/topoSet/faceSources/zoneToFace/zoneToFace.H index 3369ea17db8..5f4f7ba13e8 100644 --- a/src/meshTools/topoSet/faceSources/zoneToFace/zoneToFace.H +++ b/src/meshTools/topoSet/faceSources/zoneToFace/zoneToFace.H @@ -50,7 +50,7 @@ Usage source zoneToFace; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 zones diff --git a/src/meshTools/topoSet/faceZoneSources/cellToFaceZone/cellToFaceZone.C b/src/meshTools/topoSet/faceZoneSources/cellToFaceZone/cellToFaceZone.C index ed0586fba1d..40e5330c368 100644 --- a/src/meshTools/topoSet/faceZoneSources/cellToFaceZone/cellToFaceZone.C +++ b/src/meshTools/topoSet/faceZoneSources/cellToFaceZone/cellToFaceZone.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022 OpenCFD Ltd. + Copyright (C) 2022-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -58,7 +58,7 @@ Foam::topoSetSource::addToUsageTable Foam::cellToFaceZone::usage_ void Foam::cellToFaceZone::selectFaces ( - const cellSet& cSet, + const bitSet& whichCells, bitSet& selectedFace, bitSet& doFlip ) const @@ -81,8 +81,8 @@ void Foam::cellToFaceZone::selectFaces // Check all internal faces for (label facei = 0; facei < nInt; ++facei) { - const bool ownFound = cSet.found(own[facei]); - const bool neiFound = cSet.found(nei[facei]); + const bool ownFound = whichCells.test(own[facei]); + const bool neiFound = whichCells.test(nei[facei]); if (ownFound && !neiFound) { @@ -106,7 +106,7 @@ void Foam::cellToFaceZone::selectFaces label facei = pp.start(); forAll(pp, i) { - neiInSet[facei-nInt] = cSet.found(own[facei]); + neiInSet[facei-nInt] = whichCells.test(own[facei]); ++facei; } } @@ -120,7 +120,7 @@ void Foam::cellToFaceZone::selectFaces label facei = pp.start(); forAll(pp, i) { - const bool ownFound = cSet.found(own[facei]); + const bool ownFound = whichCells.test(own[facei]); const bool neiFound = neiInSet[facei-nInt]; if (ownFound && !neiFound) @@ -149,7 +149,8 @@ Foam::cellToFaceZone::cellToFaceZone ) : topoSetFaceZoneSource(mesh), - names_(one{}, setName), + names_(Foam::one{}, setName), + isZone_(false), flip_(flip) {} @@ -162,15 +163,9 @@ Foam::cellToFaceZone::cellToFaceZone : topoSetFaceZoneSource(mesh, dict), names_(), + isZone_(topoSetSource::readNames(dict, names_)), flip_(dict.getOrDefault("flip", false)) -{ - // Look for 'sets' or 'set' - if (!dict.readIfPresent("sets", names_)) - { - names_.resize(1); - dict.readEntry("set", names_.front()); - } -} +{} Foam::cellToFaceZone::cellToFaceZone @@ -180,7 +175,8 @@ Foam::cellToFaceZone::cellToFaceZone ) : topoSetFaceZoneSource(mesh), - names_(one{}, word(checkIs(is))), + names_(Foam::one{}, word(checkIs(is))), + isZone_(false), flip_(false) {} @@ -207,7 +203,8 @@ void Foam::cellToFaceZone::applyToSet { if (verbose_) { - Info<< " Adding all faces on outside of cell sets: " + Info<< " Adding all faces on outside of cell " + << (isZone_ ? "zones:" : "sets: ") << flatOutput(names_) << "; orientation pointing "; if (flip_) @@ -222,12 +219,23 @@ void Foam::cellToFaceZone::applyToSet bitSet selectedFace(mesh_.nFaces()); bitSet doFlip(mesh_.nFaces()); + for (const word& setName : names_) { - // Load the sets - cellSet cSet(mesh_, setName); + bitSet whichCells(mesh_.nCells()); + if (isZone_) + { + whichCells.set(mesh_.cellZones()[setName]); + } + else + { + // Load the sets + const cellSet loadedSet(mesh_, setName); + whichCells.setMany(loadedSet.begin(), loadedSet.end()); + } + // Select outside faces - selectFaces(cSet, selectedFace, doFlip); + selectFaces(whichCells, selectedFace, doFlip); } // Start off from copy @@ -251,7 +259,8 @@ void Foam::cellToFaceZone::applyToSet { if (verbose_) { - Info<< " Removing all faces on outside of cell sets: " + Info<< " Removing all faces on outside of cell " + << (isZone_ ? "zones:" : "sets: ") << flatOutput(names_) << " ..." << endl; } @@ -259,10 +268,19 @@ void Foam::cellToFaceZone::applyToSet bitSet doFlip(mesh_.nFaces()); for (const word& setName : names_) { - // Load the sets - cellSet cSet(mesh_, setName); + bitSet whichCells(mesh_.nCells()); + if (isZone_) + { + whichCells.set(mesh_.cellZones()[setName]); + } + else + { + // Load the sets + const cellSet loadedSet(mesh_, setName); + whichCells.setMany(loadedSet.begin(), loadedSet.end()); + } // Select outside faces - selectFaces(cSet, selectedFace, doFlip); + selectFaces(whichCells, selectedFace, doFlip); } // Start off empty diff --git a/src/meshTools/topoSet/faceZoneSources/cellToFaceZone/cellToFaceZone.H b/src/meshTools/topoSet/faceZoneSources/cellToFaceZone/cellToFaceZone.H index 338d8f19e32..053769cf917 100644 --- a/src/meshTools/topoSet/faceZoneSources/cellToFaceZone/cellToFaceZone.H +++ b/src/meshTools/topoSet/faceZoneSources/cellToFaceZone/cellToFaceZone.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022 OpenCFD Ltd. + Copyright (C) 2022-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,7 +52,7 @@ Usage action <action>; source cellToFaceZone; - // Select either of the below + // Select one of the below // Option-1 sets @@ -63,7 +63,18 @@ Usage ); // Option-2 - set <word>; + zones + ( + <cellZoneName0> + <cellZoneName1> + ... + ); + + // Option-3 + set <cellSetName>; + + // Option-4 + zone <cellZoneName>; // Optional entries flip <bool>; @@ -89,6 +100,15 @@ Usage subtract | Remove selected faces of a faceZoneSet from this faceZone \endverbatim + Options for the conditional mandatory entries (in order of precedence): + \verbatim + Entry | Description | Type | Reqd | Deflt + sets | Names of input cellSets | wordList | choice | - + zones | Names of input cellZones | wordList | cond'l | - + set | Name of input cellSet | word | choice | - + zone | Name of input cellZone | word | cond'l | - + \endverbatim + Notes - \c flip=true sets the orientation of faces pointing into the \c cellSet, and vice versa. @@ -124,9 +144,12 @@ class cellToFaceZone //- Add usage string static addToUsageTable usage_; - //- Names of cellSets to use + //- Names of sets or zones to use wordList names_; + //- Is name a set or a zone + const bool isZone_; + //- Whether cellSet is slave cells or master cells const bool flip_; @@ -136,7 +159,7 @@ class cellToFaceZone //- Select outside faces of cellSet void selectFaces ( - const cellSet& cSet, + const bitSet& cSet, bitSet& selectedFace, bitSet& doFlip ) const; diff --git a/src/meshTools/topoSet/pointSources/boxToPoint/boxToPoint.H b/src/meshTools/topoSet/pointSources/boxToPoint/boxToPoint.H index 462c29285c2..a7b0b701e3f 100644 --- a/src/meshTools/topoSet/pointSources/boxToPoint/boxToPoint.H +++ b/src/meshTools/topoSet/pointSources/boxToPoint/boxToPoint.H @@ -50,7 +50,7 @@ Usage source boxToPoint; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 boxes diff --git a/src/meshTools/topoSet/pointSources/cellToPoint/cellToPoint.C b/src/meshTools/topoSet/pointSources/cellToPoint/cellToPoint.C index 4cf1f0b7f00..e2be28d26c2 100644 --- a/src/meshTools/topoSet/pointSources/cellToPoint/cellToPoint.C +++ b/src/meshTools/topoSet/pointSources/cellToPoint/cellToPoint.C @@ -62,17 +62,14 @@ Foam::cellToPoint::cellActionNames_ // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::cellToPoint::combine +template<class Selector> +void Foam::cellToPoint::combineImpl ( topoSet& set, const bool add, - const word& setName + const Selector& cellLabels ) const { - // Load the set - cellSet loadedSet(mesh_, setName); - const labelHashSet& cellLabels = loadedSet; - // Add all point from cells in loadedSet for (const label celli : cellLabels) { @@ -88,6 +85,31 @@ void Foam::cellToPoint::combine } +void Foam::cellToPoint::combine +( + topoSet& set, + const bool add, + const word& setName +) const +{ + if (isZone_) + { + const labelList& cellLabels = mesh_.cellZones()[setName]; + + combineImpl(set, add, cellLabels); + } + else + { + // Load the set + cellSet loadedSet(mesh_, setName); + + const labelHashSet& cellLabels = loadedSet; + + combineImpl(set, add, cellLabels); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::cellToPoint::cellToPoint @@ -98,7 +120,8 @@ Foam::cellToPoint::cellToPoint ) : topoSetPointSource(mesh), - names_(one{}, setName), + names_(Foam::one{}, setName), + isZone_(false), option_(option) {} @@ -111,15 +134,9 @@ Foam::cellToPoint::cellToPoint : topoSetPointSource(mesh, dict), names_(), + isZone_(topoSetSource::readNames(dict, names_)), option_(cellActionNames_.get("option", dict)) -{ - // Look for 'sets' or 'set' - if (!dict.readIfPresent("sets", names_)) - { - names_.resize(1); - dict.readEntry("set", names_.front()); - } -} +{} Foam::cellToPoint::cellToPoint @@ -129,7 +146,8 @@ Foam::cellToPoint::cellToPoint ) : topoSetPointSource(mesh), - names_(one{}, word(checkIs(is))), + names_(Foam::one{}, word(checkIs(is))), + isZone_(false), option_(cellActionNames_.read(checkIs(is))) {} @@ -146,7 +164,8 @@ void Foam::cellToPoint::applyToSet { if (verbose_) { - Info<< " Adding points in cell sets: " + Info<< " Adding points in cell " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } @@ -159,7 +178,8 @@ void Foam::cellToPoint::applyToSet { if (verbose_) { - Info<< " Removing points in cell sets: " + Info<< " Removing points in cell " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } diff --git a/src/meshTools/topoSet/pointSources/cellToPoint/cellToPoint.H b/src/meshTools/topoSet/pointSources/cellToPoint/cellToPoint.H index 7ff71fb09f7..9026c49486e 100644 --- a/src/meshTools/topoSet/pointSources/cellToPoint/cellToPoint.H +++ b/src/meshTools/topoSet/pointSources/cellToPoint/cellToPoint.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2020,2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,7 +51,7 @@ Usage option <option>; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 sets @@ -62,7 +62,18 @@ Usage ); // Option-2 - set <pointSetName>; + zones + ( + <pointZoneName0> + <pointZoneName1> + ... + ); + + // Option-3 + set <pointSetName>; + + // Option-4 + zone <pointZoneName>; } \endverbatim @@ -88,17 +99,15 @@ Usage all | Select all points of cells in the cellSet \endverbatim - Options for the conditional mandatory entries: + Options for the conditional mandatory entries (in order of precedence): \verbatim - Entry | Description | Type | Req'd | Dflt - sets | Names of input cellSets | wordList | cond'l | - - set | Name of input cellSet | word | cond'l | - + Entry | Description | Type | Reqd | Deflt + sets | Names of input cellSets | wordList | choice | - + zones | Names of input cellZones | wordList | cond'l | - + set | Name of input cellSet | word | choice | - + zone | Name of input cellZone | word | cond'l | - \endverbatim -Note - The order of precedence among the conditional mandatory entries from the - highest to the lowest is \c sets, and \c set. - See also - Foam::topoSetSource - Foam::topoSetPointSource @@ -145,15 +154,27 @@ private: static const Enum<cellAction> cellActionNames_; - //- Names of sets to use + //- Names of sets or zones to use wordList names_; + //- Is name a set or a zone + const bool isZone_; + //- Option cellAction option_; // Private Member Functions + //- Depending on cell to point option add to or delete from pointSet. + template<class Selector> + void combineImpl + ( + topoSet& set, + const bool add, + const Selector& cellLabels + ) const; + void combine(topoSet& set, const bool add, const word& setName) const; diff --git a/src/meshTools/topoSet/pointSources/faceToPoint/faceToPoint.C b/src/meshTools/topoSet/pointSources/faceToPoint/faceToPoint.C index 0de8f548ccd..aac6b621614 100644 --- a/src/meshTools/topoSet/pointSources/faceToPoint/faceToPoint.C +++ b/src/meshTools/topoSet/pointSources/faceToPoint/faceToPoint.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -68,16 +68,31 @@ void Foam::faceToPoint::combine const word& setName ) const { - // Load the set - faceSet loadedSet(mesh_, setName); - const labelHashSet& faceLabels = loadedSet; + if (isZone_) + { + const auto& faceLabels = mesh_.faceZones()[setName].addressing(); + + // Add all points from faces in loadedSet + for (const label facei : faceLabels) + { + const face& f = mesh_.faces()[facei]; - // Add all points from faces in loadedSet - for (const label facei : faceLabels) + addOrDelete(set, f, add); + } + } + else { - const face& f = mesh_.faces()[facei]; + // Load the set + faceSet loadedSet(mesh_, setName); + const labelHashSet& faceLabels = loadedSet; + + // Add all points from faces in loadedSet + for (const label facei : faceLabels) + { + const face& f = mesh_.faces()[facei]; - addOrDelete(set, f, add); + addOrDelete(set, f, add); + } } } @@ -92,7 +107,8 @@ Foam::faceToPoint::faceToPoint ) : topoSetPointSource(mesh), - names_(one{}, setName), + names_(Foam::one{}, setName), + isZone_(false), option_(option) {} @@ -105,15 +121,9 @@ Foam::faceToPoint::faceToPoint : topoSetPointSource(mesh, dict), names_(), + isZone_(topoSetSource::readNames(dict, names_)), option_(faceActionNames_.get("option", dict)) -{ - // Look for 'sets' or 'set' - if (!dict.readIfPresent("sets", names_)) - { - names_.resize(1); - dict.readEntry("set", names_.front()); - } -} +{} Foam::faceToPoint::faceToPoint @@ -123,7 +133,8 @@ Foam::faceToPoint::faceToPoint ) : topoSetPointSource(mesh), - names_(one{}, word(checkIs(is))), + names_(Foam::one{}, word(checkIs(is))), + isZone_(false), option_(faceActionNames_.read(checkIs(is))) {} @@ -140,7 +151,8 @@ void Foam::faceToPoint::applyToSet { if (verbose_) { - Info<< " Adding points from face in face sets: " + Info<< " Adding face points in face " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } @@ -153,7 +165,8 @@ void Foam::faceToPoint::applyToSet { if (verbose_) { - Info<< " Removing points from face in face sets: " + Info<< " Removing face points in face " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } diff --git a/src/meshTools/topoSet/pointSources/faceToPoint/faceToPoint.H b/src/meshTools/topoSet/pointSources/faceToPoint/faceToPoint.H index 8e12ef2740e..49c132cf981 100644 --- a/src/meshTools/topoSet/pointSources/faceToPoint/faceToPoint.H +++ b/src/meshTools/topoSet/pointSources/faceToPoint/faceToPoint.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,7 +52,7 @@ Usage option <option>; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 sets @@ -89,17 +89,15 @@ Usage all | Select all points of faces in the faceSet \endverbatim - Options for the conditional mandatory entries: + Options for the conditional mandatory entries (in order of precedence): \verbatim Entry | Description | Type | Req'd | Dflt sets | Names of input faceSets | wordList | cond'l | - + zones | Names of input faceZones | wordList | cond'l | - set | Name of input faceSet | word | cond'l | - + zone | Name of input faceZone | word | cond'l | - \endverbatim -Note - The order of precedence among the conditional mandatory entries from the - highest to the lowest is \c sets, and \c set. - See also - Foam::topoSetSource - Foam::topoSetPointSource @@ -146,9 +144,12 @@ private: static const Enum<faceAction> faceActionNames_; - //- Names of sets to use + //- Names of sets or zones to use wordList names_; + //- Is name a set or a zone + const bool isZone_; + //- Option faceAction option_; diff --git a/src/meshTools/topoSet/pointSources/pointToPoint/pointToPoint.C b/src/meshTools/topoSet/pointSources/pointToPoint/pointToPoint.C index 6b8abbbdbb4..0f428972cc9 100644 --- a/src/meshTools/topoSet/pointSources/pointToPoint/pointToPoint.C +++ b/src/meshTools/topoSet/pointSources/pointToPoint/pointToPoint.C @@ -60,7 +60,8 @@ Foam::pointToPoint::pointToPoint ) : topoSetPointSource(mesh), - names_(one{}, setName) + names_(Foam::one{}, setName), + isZone_(false) {} @@ -71,15 +72,9 @@ Foam::pointToPoint::pointToPoint ) : topoSetPointSource(mesh, dict), - names_() -{ - // Look for 'sets' or 'set' - if (!dict.readIfPresent("sets", names_)) - { - names_.resize(1); - dict.readEntry("set", names_.front()); - } -} + names_(), + isZone_(topoSetSource::readNames(dict, names_)) +{} Foam::pointToPoint::pointToPoint @@ -89,7 +84,8 @@ Foam::pointToPoint::pointToPoint ) : topoSetPointSource(mesh), - names_(one{}, word(checkIs(is))) + names_(Foam::one{}, word(checkIs(is))), + isZone_(false) {} @@ -105,30 +101,46 @@ void Foam::pointToPoint::applyToSet { if (verbose_) { - Info<< " Adding all elements of point sets: " + Info<< " Adding all elements of point " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } for (const word& setName : names_) { - pointSet loadedSet(mesh_, setName); - - set.addSet(loadedSet); + if (isZone_) + { + set.addSet(mesh_.pointZones()[setName]); + } + else + { + pointSet loadedSet(mesh_, setName); + + set.addSet(loadedSet); + } } } else if (action == topoSetSource::SUBTRACT) { if (verbose_) { - Info<< " Removing all elements of point sets: " + Info<< " Removing all elements of point " + << (isZone_ ? "zones: " : "sets: ") << flatOutput(names_) << nl; } for (const word& setName : names_) { - pointSet loadedSet(mesh_, setName); - - set.subtractSet(loadedSet); + if (isZone_) + { + set.subtractSet(mesh_.pointZones()[setName]); + } + else + { + pointSet loadedSet(mesh_, setName); + + set.subtractSet(loadedSet); + } } } } diff --git a/src/meshTools/topoSet/pointSources/pointToPoint/pointToPoint.H b/src/meshTools/topoSet/pointSources/pointToPoint/pointToPoint.H index 55efeceb8d5..1a6d0b39c63 100644 --- a/src/meshTools/topoSet/pointSources/pointToPoint/pointToPoint.H +++ b/src/meshTools/topoSet/pointSources/pointToPoint/pointToPoint.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2020,2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -50,7 +50,7 @@ Usage source pointToPoint; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 sets @@ -61,7 +61,18 @@ Usage ); // Option-2 - set <pointSetName>; + zones + ( + <pointZoneName0> + <pointZoneName1> + ... + ); + + // Option-3 + set <pointSetName>; + + // Option-4 + zone <pointZoneName>; } \endverbatim @@ -81,17 +92,15 @@ Usage subtract | Remove selected points from this pointSet \endverbatim - Options for the conditional mandatory entries: + Options for the conditional mandatory entries (in order of precedence): \verbatim Entry | Description | Type | Req'd | Dflt sets | Names of input pointSets | wordList | cond'l | - + zones | Names of input pointZones | wordList | cond'l | - set | Name of input pointSet | word | cond'l | - + zone | Name of input pointZone | word | cond'l | - \endverbatim -Note - The order of precedence among the conditional mandatory entries from the - highest to the lowest is \c sets, and \c set. - See also - Foam::topoSetSource - Foam::topoSetPointSource @@ -124,9 +133,12 @@ class pointToPoint //- Add usage string static addToUsageTable usage_; - //- Names of sets to use + //- Names of sets or zones to use wordList names_; + //- Is name a set or a zone + const bool isZone_; + public: diff --git a/src/meshTools/topoSet/pointSources/zoneToPoint/zoneToPoint.H b/src/meshTools/topoSet/pointSources/zoneToPoint/zoneToPoint.H index 8f44db859eb..2e587d39bdc 100644 --- a/src/meshTools/topoSet/pointSources/zoneToPoint/zoneToPoint.H +++ b/src/meshTools/topoSet/pointSources/zoneToPoint/zoneToPoint.H @@ -50,7 +50,7 @@ Usage source zoneToPoint; // Conditional mandatory entries - // Select either of the below + // Select one of the below // Option-1 zones diff --git a/src/meshTools/topoSet/pointZoneSources/setToPointZone/setToPointZone.C b/src/meshTools/topoSet/pointZoneSources/setToPointZone/setToPointZone.C index 1d03c80dc35..40e50aa54fa 100644 --- a/src/meshTools/topoSet/pointZoneSources/setToPointZone/setToPointZone.C +++ b/src/meshTools/topoSet/pointZoneSources/setToPointZone/setToPointZone.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -124,7 +124,7 @@ void Foam::setToPointZone::applyToSet { if (!zoneSet.found(pointi)) { - newAddressing.append(pointi); + newAddressing.push_back(pointi); } } @@ -145,11 +145,11 @@ void Foam::setToPointZone::applyToSet // Start off empty DynamicList<label> newAddressing(zoneSet.addressing().size()); - forAll(zoneSet.addressing(), i) + for (const label pointi : zoneSet.addressing()) { - if (!loadedSet.found(zoneSet.addressing()[i])) + if (!loadedSet.found(pointi)) { - newAddressing.append(zoneSet.addressing()[i]); + newAddressing.push_back(pointi); } } zoneSet.addressing().transfer(newAddressing); diff --git a/src/meshTools/topoSet/topoSetSource/topoSetSource.C b/src/meshTools/topoSet/topoSetSource/topoSetSource.C index 16a7cd1d2d8..10331ffa575 100644 --- a/src/meshTools/topoSet/topoSetSource/topoSetSource.C +++ b/src/meshTools/topoSet/topoSetSource/topoSetSource.C @@ -304,4 +304,52 @@ Foam::tmp<Foam::pointField> Foam::topoSetSource::transform } +bool Foam::topoSetSource::readNames +( + const dictionary& dict, + wordList& names +) +{ + bool isZone = false; + + // priority + // 1. 'sets' + // 2. 'zones' + // 3. 'set' + // 4. 'zone' + + if (dict.readIfPresent("sets", names, keyType::LITERAL)) + { + // -> isZone = false; + } + else if (dict.readIfPresent("zones", names, keyType::LITERAL)) + { + isZone = true; + } + else + { + // Ensure error messsages make sense if nothing was provided + names.resize(1); + + if (dict.readIfPresent("zone", names.front(), keyType::LITERAL)) + { + // Had 'zone', so 'set' is optional... + isZone = true; + if (dict.readIfPresent("set", names.front(), keyType::LITERAL)) + { + isZone = false; + } + } + else + { + // No 'zone', so 'set' is mandatory... + dict.readEntry("set", names.front(), keyType::LITERAL); + // -> isZone = false; + } + } + + return isZone; +} + + // ************************************************************************* // diff --git a/src/meshTools/topoSet/topoSetSource/topoSetSource.H b/src/meshTools/topoSet/topoSetSource/topoSetSource.H index 68b07a71083..a7797736447 100644 --- a/src/meshTools/topoSet/topoSetSource/topoSetSource.H +++ b/src/meshTools/topoSet/topoSetSource/topoSetSource.H @@ -405,6 +405,11 @@ public: { return actionNames[actionName]; } + + //- Helper: extract wordList of patches/zones from dictionary. Returns + // true if zone(s). Order of parsing is + // sets, zones, set, zone + static bool readNames(const dictionary& dict, wordList& names); }; diff --git a/src/meshTools/topoSet/topoSets/cellZoneSet.C b/src/meshTools/topoSet/topoSets/cellZoneSet.C index 28ab5ac500d..4fca3baacc0 100644 --- a/src/meshTools/topoSet/topoSets/cellZoneSet.C +++ b/src/meshTools/topoSet/topoSets/cellZoneSet.C @@ -171,6 +171,23 @@ void Foam::cellZoneSet::subset(const topoSet& set) } +void Foam::cellZoneSet::subset(const labelUList& set) +{ + DynamicList<label> newAddressing(addressing_.size()); + + for (const label celli : set) + { + if (found(celli)) + { + newAddressing.append(celli); + } + } + + addressing_.transfer(newAddressing); + updateSet(); +} + + void Foam::cellZoneSet::addSet(const topoSet& set) { DynamicList<label> newAddressing(addressing_); @@ -190,6 +207,23 @@ void Foam::cellZoneSet::addSet(const topoSet& set) } +void Foam::cellZoneSet::addSet(const labelUList& set) +{ + DynamicList<label> newAddressing(addressing_); + + for (const label celli : set) + { + if (!found(celli)) + { + newAddressing.append(celli); + } + } + + addressing_.transfer(newAddressing); + updateSet(); +} + + void Foam::cellZoneSet::subtractSet(const topoSet& set) { DynamicList<label> newAddressing(addressing_.size()); @@ -210,6 +244,26 @@ void Foam::cellZoneSet::subtractSet(const topoSet& set) } +void Foam::cellZoneSet::subtractSet(const labelUList& elems) +{ + DynamicList<label> newAddressing(addressing_.size()); + + const labelHashSet zoneSet(elems); + + for (const label celli : addressing_) + { + if (!zoneSet.found(celli)) + { + // Not found in zoneSet so add + newAddressing.append(celli); + } + } + + addressing_.transfer(newAddressing); + updateSet(); +} + + void Foam::cellZoneSet::sync(const polyMesh& mesh) { cellSet::sync(mesh); diff --git a/src/meshTools/topoSet/topoSets/cellZoneSet.H b/src/meshTools/topoSet/topoSets/cellZoneSet.H index d2e34e416b4..cb53106b804 100644 --- a/src/meshTools/topoSet/topoSets/cellZoneSet.H +++ b/src/meshTools/topoSet/topoSets/cellZoneSet.H @@ -128,6 +128,17 @@ public: //- Subtract elements present in set. virtual void subtractSet(const topoSet& set); + // Variants taking labelUList& + + //- Subset contents. Only elements present in both sets remain. + virtual void subset(const labelUList& set); + + //- Add elements present in set. + virtual void addSet(const labelUList& set); + + //- Subtract elements present in set. + virtual void subtractSet(const labelUList& set); + //- Sync cellSet across coupled patches; update cellZone from cellSet virtual void sync(const polyMesh& mesh); diff --git a/src/meshTools/topoSet/topoSets/faceZoneSet.C b/src/meshTools/topoSet/topoSets/faceZoneSet.C index ab86d89c636..6b230325ead 100644 --- a/src/meshTools/topoSet/topoSets/faceZoneSet.C +++ b/src/meshTools/topoSet/topoSets/faceZoneSet.C @@ -171,7 +171,12 @@ void Foam::faceZoneSet::invert(const label maxLen) } -void Foam::faceZoneSet::subset(const topoSet& set) +void Foam::faceZoneSet::subset +( + const word& setName, + const labelUList& setAddressing, + const UList<bool>& setFlipMap +) { label nConflict = 0; @@ -180,11 +185,9 @@ void Foam::faceZoneSet::subset(const topoSet& set) Map<label> faceToIndex(invertToMap(addressing_)); - const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); - - forAll(zoneSet.addressing(), i) + forAll(setAddressing, i) { - const label facei = zoneSet.addressing()[i]; + const label facei = setAddressing[i]; const auto iter = faceToIndex.cfind(facei); @@ -192,7 +195,7 @@ void Foam::faceZoneSet::subset(const topoSet& set) { const label index = iter.val(); - if (zoneSet.flipMap()[i] != flipMap_[index]) + if (setFlipMap.size() && (setFlipMap[i] != flipMap_[index])) { ++nConflict; } @@ -205,8 +208,8 @@ void Foam::faceZoneSet::subset(const topoSet& set) { WarningInFunction << "subset : there are " << nConflict - << " faces with different orientation in faceZonesSets " - << name() << " and " << set.name() << endl; + << " faces with different orientation in faceZoneSets " + << name() << " and " << setName << endl; } addressing_.transfer(newAddressing); @@ -215,7 +218,25 @@ void Foam::faceZoneSet::subset(const topoSet& set) } -void Foam::faceZoneSet::addSet(const topoSet& set) +void Foam::faceZoneSet::subset(const topoSet& set) +{ + const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); + subset(zoneSet.name(), zoneSet.addressing(), zoneSet.flipMap()); +} + + +void Foam::faceZoneSet::subset(const labelUList& set) +{ + subset(word::null, set, boolList::null()); +} + + +void Foam::faceZoneSet::addSet +( + const word& setName, + const labelUList& setAddressing, + const UList<bool>& setFlipMap +) { label nConflict = 0; @@ -224,18 +245,16 @@ void Foam::faceZoneSet::addSet(const topoSet& set) Map<label> faceToIndex(invertToMap(addressing_)); - const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); - - forAll(zoneSet.addressing(), i) + forAll(setAddressing, i) { - const label facei = zoneSet.addressing()[i]; + const label facei = setAddressing[i]; const auto iter = faceToIndex.cfind(facei); if (iter.good()) { const label index = iter.val(); - if (zoneSet.flipMap()[i] != flipMap_[index]) + if (setFlipMap.size() && (setFlipMap[i] != flipMap_[index])) { ++nConflict; } @@ -243,7 +262,7 @@ void Foam::faceZoneSet::addSet(const topoSet& set) else { newAddressing.append(facei); - newFlipMap.append(zoneSet.flipMap()[i]); + newFlipMap.append(setFlipMap.size() ? setFlipMap[i] : false); } } @@ -252,7 +271,7 @@ void Foam::faceZoneSet::addSet(const topoSet& set) WarningInFunction << "addSet : there are " << nConflict << " faces with different orientation in faceZonesSets " - << name() << " and " << set.name() << endl; + << name() << " and " << setName << endl; } addressing_.transfer(newAddressing); @@ -261,16 +280,32 @@ void Foam::faceZoneSet::addSet(const topoSet& set) } -void Foam::faceZoneSet::subtractSet(const topoSet& set) +void Foam::faceZoneSet::addSet(const topoSet& set) +{ + const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); + addSet(zoneSet.name(), zoneSet.addressing(), zoneSet.flipMap()); +} + + +void Foam::faceZoneSet::addSet(const labelUList& set) +{ + addSet(word::null, set, boolList::null()); +} + + +void Foam::faceZoneSet::subtractSet +( + const word& setName, + const labelUList& setAddressing, + const UList<bool>& setFlipMap +) { label nConflict = 0; DynamicList<label> newAddressing(addressing_.size()); DynamicList<bool> newFlipMap(flipMap_.size()); - const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); - - Map<label> faceToIndex(invertToMap(zoneSet.addressing())); + Map<label> faceToIndex(invertToMap(setAddressing)); forAll(addressing_, i) { @@ -282,7 +317,7 @@ void Foam::faceZoneSet::subtractSet(const topoSet& set) { const label index = iter.val(); - if (zoneSet.flipMap()[index] != flipMap_[i]) + if (setFlipMap.size() && (setFlipMap[index] != flipMap_[i])) { ++nConflict; } @@ -291,7 +326,7 @@ void Foam::faceZoneSet::subtractSet(const topoSet& set) { // Not found in zoneSet so add newAddressing.append(facei); - newFlipMap.append(zoneSet.flipMap()[i]); + newFlipMap.append(setFlipMap.size() ? setFlipMap[i] : false); } } @@ -300,7 +335,7 @@ void Foam::faceZoneSet::subtractSet(const topoSet& set) WarningInFunction << "subtractSet : there are " << nConflict << " faces with different orientation in faceZonesSets " - << name() << " and " << set.name() << endl; + << name() << " and " << setName << endl; } addressing_.transfer(newAddressing); @@ -309,6 +344,19 @@ void Foam::faceZoneSet::subtractSet(const topoSet& set) } +void Foam::faceZoneSet::subtractSet(const topoSet& set) +{ + const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); + subtractSet(zoneSet.name(), zoneSet.addressing(), zoneSet.flipMap()); +} + + +void Foam::faceZoneSet::subtractSet(const labelUList& set) +{ + subtractSet(word::null, set, boolList::null()); +} + + void Foam::faceZoneSet::sync(const polyMesh& mesh) { // This routine serves two purposes diff --git a/src/meshTools/topoSet/topoSets/faceZoneSet.H b/src/meshTools/topoSet/topoSets/faceZoneSet.H index 4a621de44c2..1f81d5d5d4e 100644 --- a/src/meshTools/topoSet/topoSets/faceZoneSet.H +++ b/src/meshTools/topoSet/topoSets/faceZoneSet.H @@ -62,6 +62,30 @@ class faceZoneSet boolList flipMap_; + // Private Member Functions + + void subset + ( + const word& setName, + const labelUList& setAddressing, + const UList<bool>& setFlipMap + ); + + void addSet + ( + const word& setName, + const labelUList& setAddressing, + const UList<bool>& setFlipMap + ); + + void subtractSet + ( + const word& setName, + const labelUList& setAddressing, + const UList<bool>& setFlipMap + ); + + public: //- Runtime type information @@ -142,6 +166,18 @@ public: //- Subtract elements present in set. virtual void subtractSet(const topoSet& set); + // Variants taking labelUList& + + //- Subset contents. Only elements present in both sets remain. + virtual void subset(const labelUList& set); + + //- Add elements present in set. + virtual void addSet(const labelUList& set); + + //- Subtract elements present in set. + virtual void subtractSet(const labelUList& set); + + //- Sync faceZoneSet across coupled patches. virtual void sync(const polyMesh& mesh); diff --git a/src/meshTools/topoSet/topoSets/pointZoneSet.C b/src/meshTools/topoSet/topoSets/pointZoneSet.C index cd0e151d61d..752ab2524bd 100644 --- a/src/meshTools/topoSet/topoSets/pointZoneSet.C +++ b/src/meshTools/topoSet/topoSets/pointZoneSet.C @@ -171,6 +171,23 @@ void Foam::pointZoneSet::subset(const topoSet& set) } +void Foam::pointZoneSet::subset(const labelUList& set) +{ + DynamicList<label> newAddressing(addressing_.size()); + + for (const label pointi : set) + { + if (found(pointi)) + { + newAddressing.append(pointi); + } + } + + addressing_.transfer(newAddressing); + updateSet(); +} + + void Foam::pointZoneSet::addSet(const topoSet& set) { DynamicList<label> newAddressing(addressing_); @@ -190,6 +207,23 @@ void Foam::pointZoneSet::addSet(const topoSet& set) } +void Foam::pointZoneSet::addSet(const labelUList& set) +{ + DynamicList<label> newAddressing(addressing_); + + for (const label pointi : set) + { + if (!found(pointi)) + { + newAddressing.append(pointi); + } + } + + addressing_.transfer(newAddressing); + updateSet(); +} + + void Foam::pointZoneSet::subtractSet(const topoSet& set) { DynamicList<label> newAddressing(addressing_.size()); @@ -210,6 +244,26 @@ void Foam::pointZoneSet::subtractSet(const topoSet& set) } +void Foam::pointZoneSet::subtractSet(const labelUList& elems) +{ + DynamicList<label> newAddressing(addressing_.size()); + + const labelHashSet zoneSet(elems); + + for (const label pointi : addressing_) + { + if (!zoneSet.found(pointi)) + { + // Not found in zoneSet so add + newAddressing.append(pointi); + } + } + + addressing_.transfer(newAddressing); + updateSet(); +} + + void Foam::pointZoneSet::sync(const polyMesh& mesh) { pointSet::sync(mesh); diff --git a/src/meshTools/topoSet/topoSets/pointZoneSet.H b/src/meshTools/topoSet/topoSets/pointZoneSet.H index 5ba34edc858..e1419f51cf9 100644 --- a/src/meshTools/topoSet/topoSets/pointZoneSet.H +++ b/src/meshTools/topoSet/topoSets/pointZoneSet.H @@ -129,6 +129,18 @@ public: //- Subtract elements present in set. virtual void subtractSet(const topoSet& set); + // Variants taking labelUList& + + //- Subset contents. Only elements present in both sets remain. + virtual void subset(const labelUList& set); + + //- Add elements present in set. + virtual void addSet(const labelUList& set); + + //- Subtract elements present in set. + virtual void subtractSet(const labelUList& set); + + //- Sync pointZoneSet across coupled patches. virtual void sync(const polyMesh& mesh); diff --git a/src/meshTools/topoSet/topoSets/topoBitSet.C b/src/meshTools/topoSet/topoSets/topoBitSet.C index 56676ee9435..6bd7005d5e5 100644 --- a/src/meshTools/topoSet/topoSets/topoBitSet.C +++ b/src/meshTools/topoSet/topoSets/topoBitSet.C @@ -239,6 +239,22 @@ void Foam::topoBitSet::subset(const topoSet& set) } +void Foam::topoBitSet::subset(const labelUList& elems) +{ + // Only retain entries found in both sets + bitSet newSelected(selected_.size()); + + for (const label id : elems) + { + if (selected_[id]) + { + newSelected.set(id); + } + } + selected_ = newSelected; +} + + void Foam::topoBitSet::addSet(const topoSet& set) { // Add entries to the set @@ -256,6 +272,12 @@ void Foam::topoBitSet::addSet(const topoSet& set) } +void Foam::topoBitSet::addSet(const labelUList& elems) +{ + selected_.set(elems); +} + + void Foam::topoBitSet::subtractSet(const topoSet& set) { // Subtract entries from the set @@ -273,4 +295,10 @@ void Foam::topoBitSet::subtractSet(const topoSet& set) } +void Foam::topoBitSet::subtractSet(const labelUList& elems) +{ + selected_.unset(elems); +} + + // ************************************************************************* // diff --git a/src/meshTools/topoSet/topoSets/topoBitSet.H b/src/meshTools/topoSet/topoSets/topoBitSet.H index 456b65e67a1..ae702fb71f9 100644 --- a/src/meshTools/topoSet/topoSets/topoBitSet.H +++ b/src/meshTools/topoSet/topoSets/topoBitSet.H @@ -154,6 +154,17 @@ public: //- Subtract elements present in set. virtual void subtractSet(const topoSet& set); + + // Variants taking labelUList& + + //- Subset contents. Only elements present in both sets remain. + virtual void subset(const labelUList& set); + + //- Add elements present in set. + virtual void addSet(const labelUList& set); + + //- Subtract elements present in set. + virtual void subtractSet(const labelUList& set); }; diff --git a/src/meshTools/topoSet/topoSets/topoBoolSet.C b/src/meshTools/topoSet/topoSets/topoBoolSet.C index 35268ec9690..0045c159f32 100644 --- a/src/meshTools/topoSet/topoSets/topoBoolSet.C +++ b/src/meshTools/topoSet/topoSets/topoBoolSet.C @@ -250,6 +250,25 @@ void Foam::topoBoolSet::subset(const topoSet& set) } +void Foam::topoBoolSet::subset(const labelUList& set) +{ + // Only retain entries found in both sets + if (set.empty()) + { + selected_ = false; + } + else + { + const boolList oldSelected(selected_); + selected_ = false; + for (const label id : set) + { + selected_[id] = oldSelected[id]; + } + } +} + + void Foam::topoBoolSet::addSet(const topoSet& set) { // Add entries to the set @@ -260,6 +279,16 @@ void Foam::topoBoolSet::addSet(const topoSet& set) } +void Foam::topoBoolSet::addSet(const labelUList& set) +{ + // Add entries to the set + for (const label id : set) + { + selected_[id] = true; + } +} + + void Foam::topoBoolSet::subtractSet(const topoSet& set) { // Subtract entries from the set @@ -270,4 +299,14 @@ void Foam::topoBoolSet::subtractSet(const topoSet& set) } +void Foam::topoBoolSet::subtractSet(const labelUList& set) +{ + // Subtract entries from the set + for (const label id : set) + { + selected_.unset(id); + } +} + + // ************************************************************************* // diff --git a/src/meshTools/topoSet/topoSets/topoBoolSet.H b/src/meshTools/topoSet/topoSets/topoBoolSet.H index 6abaf921cf0..273e3297f9e 100644 --- a/src/meshTools/topoSet/topoSets/topoBoolSet.H +++ b/src/meshTools/topoSet/topoSets/topoBoolSet.H @@ -154,6 +154,17 @@ public: //- Subtract elements present in set. virtual void subtractSet(const topoSet& set); + + // Variants taking labelUList& + + //- Subset contents. Only elements present in both sets remain. + virtual void subset(const labelUList& set); + + //- Add elements present in set. + virtual void addSet(const labelUList& set); + + //- Subtract elements present in set. + virtual void subtractSet(const labelUList& set); }; diff --git a/src/meshTools/topoSet/topoSets/topoSet.C b/src/meshTools/topoSet/topoSets/topoSet.C index 177fb22b468..29d2a8cb1ce 100644 --- a/src/meshTools/topoSet/topoSets/topoSet.C +++ b/src/meshTools/topoSet/topoSets/topoSet.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -553,6 +553,26 @@ void Foam::topoSet::subset(const topoSet& set) } +void Foam::topoSet::subset(const labelUList& elems) +{ + // Only retain entries found in both sets + auto& currentSet = static_cast<labelHashSet&>(*this); + + DynamicList<label> newElems(elems.size()+currentSet.size()); + for (const label elem : elems) + { + if (currentSet.found(elem)) + { + newElems.push_back(elem); + } + } + if (newElems.size() < currentSet.size()) + { + currentSet = newElems; + } +} + + void Foam::topoSet::addSet(const topoSet& set) { // Add entries to the set @@ -560,6 +580,13 @@ void Foam::topoSet::addSet(const topoSet& set) } +void Foam::topoSet::addSet(const labelUList& elems) +{ + // Add entries to the set + static_cast<labelHashSet&>(*this).set(elems); +} + + void Foam::topoSet::subtractSet(const topoSet& set) { // Subtract entries from the set @@ -567,9 +594,10 @@ void Foam::topoSet::subtractSet(const topoSet& set) } -void Foam::topoSet::deleteSet(const topoSet& set) +void Foam::topoSet::subtractSet(const labelUList& elems) { - this->subtractSet(set); + // Subtract entries from the set + static_cast<labelHashSet&>(*this).unset(elems); } diff --git a/src/meshTools/topoSet/topoSets/topoSet.H b/src/meshTools/topoSet/topoSets/topoSet.H index d8eef752992..d8437149669 100644 --- a/src/meshTools/topoSet/topoSets/topoSet.H +++ b/src/meshTools/topoSet/topoSets/topoSet.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -331,12 +331,22 @@ public: //- Subset contents. Only elements present in both sets remain. virtual void subset(const topoSet& set); - //- Add elements present in set. + //- Subset contents. Only elements present in both sets remain. + virtual void subset(const labelUList& set); + + //- Add elements virtual void addSet(const topoSet& set); - //- Subtract elements present in set. + //- Add elements + virtual void addSet(const labelUList& set); + + //- Subtract elements virtual void subtractSet(const topoSet& set); + //- Subtract elements + virtual void subtractSet(const labelUList& set); + + //- Sync set across coupled patches. virtual void sync(const polyMesh& mesh); @@ -392,7 +402,8 @@ public: //- Deprecated(2018-10) subtract elements present in set. // \deprecated(2018-10) - use subtractSet instead - virtual void deleteSet(const topoSet& set); + FOAM_DEPRECATED_FOR(2018-10, "subtractSet()") + virtual void deleteSet(const topoSet& set) { this->subtractSet(set); } }; -- GitLab