diff --git a/src/meshTools/topoSet/cellSources/boxToCell/boxToCell.H b/src/meshTools/topoSet/cellSources/boxToCell/boxToCell.H index 1da35b00b0b4f5ade5e49bba9f9a78f98abde56b..0775939338caedd7dda44d11be436d30b881e66e 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 e43ab9ee64072abc222800eb756dbf0de0b6b61e..667ccd02c3dc7394e32e22bb6938c7494fe574a0 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 1a42aa8b00d9d3912702b2e3307f613e2ad1dab0..fb595cb7872bc547cb664e86a098df6f0bc9e409 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 ec52df9e2d4cf286cf70c38e5d6cf1685625ba8c..a71a70760b9de39e37927f997113396f1f683c10 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 dbd6f18f8a341ae800b7902dc5630ad3b36230d1..36811cbe32c75a2e61fddba76af694a25aea4112 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 44da5e124dce5aec002df2762059faef8b9b57ef..c5fbd88148c3883cabd4b234bf6dcd161fbf0f6b 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 4f78764288403723e66d219dec21a341c862f6a5..7705e0b10ccfd05a219de33a57051bfe19e4863a 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 17b26421bb9984a99d08163600e2167db207b6cc..9c74f9e3e6d05f0bf2e77ca011919154e1cdb163 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 7d5432501d8846a91f2d6751781580b0c51cf512..5fd938e079d1577b6f3890ceb5e561e384b87dc4 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 c83ec7ec74e2b4124768d90976e7a44c5350014d..f192b4f37d66dea3532efbdf9fc457764f05902e 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 4d273ffa5b71bb751cc4105beeae50018d45e2dc..2dd718a81b7624264aee9f14fb62ddea70610694 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 a83ce416ecac4d6096059e3d6de99a5f89b6c5e5..e9c2e1285542f10a7a0328d02bc81219290635e1 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 d0e4d3f3025c5038bbf1690b416bfea868dd2f65..ca3d0c1d78e06aaf35c3bd28ae8df985e26f3425 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 ecd4b0b305b277527f4b5049db616559ffbbcb14..3df24f8b5edb56f9be10feae8eee8e389600c4db 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 7c4a4c4be33e848e32980be9ae3d9f11863e5342..d3b7508de72403c12fe74bee5fafdf5cb37c2291 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 d1c5638a597043c357a99e9bca83eb15fc339b48..5b197e15a278698eabf857d6735c00dc40ad2563 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 8fbcf20838c9ff05172d549ea7d61bc4b5d53136..9eaed67c4e64b262bf349c5a1d7b1c45223de23b 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 67642a41ea947864ba5adfeb4089e667c76bb46e..b02309df68ee6813790b17ee416e579d6588d7a9 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 3816a19a6dfa8e92fbfdaf9154bb40ae01334591..90781958d539e9f0338d092aa94192f198f7f785 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 844824483d78cb72b3c5918bb2c2c0e3c3e2c839..792fad47fc6e990f3fb6657ba8eb619e212d5199 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 9633b6b424846f8c06ee7bfe17cf4cfb2f2652a5..6a4a77b96e56f5d0a04f09a265a136bae6b9d719 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 ea632bc4819003531d8446acc42fb387e47830e6..ebf18e4d35b5bfcb1e2d5c915bed63927fe29b2e 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 8bb3e8815ff3864d4191e8eae22253b7fb44592d..683e5e68e0e95b8fcb042f4bfe563158ca58e80c 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 9fafcb87e970070c8153eb85231d66e0a60d054e..f0faf5dd79c44726d75cbba1a53c28e6f9d842f3 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 3369ea17db8919e2b2c161f4fa47a085bce8c82d..5f4f7ba13e88a9c0e01d59db0c29e91af4e9e6c7 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 ed0586fba1d90c4750c104f5fb1cafdc925ae861..40e5330c36826b29210414f18d8c02e3027fc608 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 338d8f19e320c788dfbfb265e2a55f3dcba60ac0..053769cf9179e23acfedfe3888660f7aafcbe161 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 462c29285c228598b1dcf638783d9daf7cfc5817..a7b0b701e3f628dc2d245d27c6a7cf054f464d3e 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 4cf1f0b7f003acee4827bac95d180b1a86202ec6..e2be28d26c2c83adc3b5f62c511d43321e939575 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 7ff71fb09f7c54298ccc3966867c2a391cf04323..9026c49486ec755079432e3b17cfcdf09e127f85 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 0de8f548ccd487ecbc86c975386dfb8899fb6c3c..aac6b621614f07f9c329ea3bb8de3bbd907e6b23 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 8e12ef2740e9c6ab09693dd3a5dc3586d3422a95..49c132cf981ab8d5a3479162f27a3fedfcfb2843 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 6b8abbbdbb4652ef6d72cde26045e38fce99a910..0f428972cc94ce06dffd6a4811354aa31c055d2e 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 55efeceb8d5f706e458fa9589ebbfb638662cd56..1a6d0b39c635d3479efb9cd5e80539fb685a562e 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 8f44db859eb4b8308d57ac8358a10e690cdca012..2e587d39bdca3b951dcbabc8fd8dbcbcd12ed942 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 1d03c80dc356fce6ea29942fc88b0c20f49af5f2..40e50aa54fa32c283bf7b7fb3e08b351829214b3 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 16a7cd1d2d8a9eed57f29812b9e33300a0909cc1..10331ffa575a4a9ab19e2911e38ccda95b4b5819 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 68b07a71083992aa7c5ae8a612449ec1d3485ffb..a77977364475214c3c67a1ae19acd232f413a5cc 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 28ab5ac500d2f9eaa066075803d7e8b1500d0055..4fca3baacc0db87d120475faa8adb940e42b1268 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 d2e34e416b4050074cc6986e7ab3ce960d7451fe..cb53106b804d6374a271c3aef2a7a42694ce84c1 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 ab86d89c636445564ba5647a2e84acc3dd6afb24..6b230325ead262a2f44833b4b7e83a15acf65937 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 4a621de44c261ecf3c901cd9f9d93c8279c7ebf0..1f81d5d5d4eea8c89923116059b565362f662af6 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 cd0e151d61dcde8298520261e964ba4388bccc84..752ab2524bd1a30efbc7f2567e7986b6c2742631 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 5ba34edc85859e8301a6a9a4fc5c0c4d38439093..e1419f51cf933e4df11755440524e139f11826d9 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 56676ee94357f365b8caadadde50d37a5b748cec..6bd7005d5e52dbe24eb98a0819dde93c0f070e0e 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 456b65e67a1a9a3eb1606fc29da19af107300a1a..ae702fb71f9d6fef585d2312803c7ea5b9d48902 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 35268ec9690ee3c0bc36f27d1c6b3c15cb073d95..0045c159f32d3d15cafac8bd1a7eb9ef97e9f520 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 6abaf921cf0956e5ba901c08218a134c00d3c524..273e3297f9efe243522048fe1def1c12a163deba 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 177fb22b468afb1b83adfc08184d9c12322e539f..29d2a8cb1ce4e40dc2517e798d5913e0f6cb5997 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 d8eef752992a89e85ec2905f692696cb66d499c2..d843714966989e251196919739bbef2bdaee8561 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); } };