From 269d0ffd5c0caec33bf094e3d4f9f3d6ff5137f3 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Sat, 19 Jun 2021 13:02:42 +0200 Subject: [PATCH] ENH: improve flexibility of zoneTo{Cell,Face,Point} (#2130) - add setter/getter methods for the zone selection - construct for multiple zone selection - support explicit zone ids instead of name matcher --- .../faceZoneToCell/faceZoneToCell.C | 137 +++++++++++----- .../faceZoneToCell/faceZoneToCell.H | 36 ++++- .../sets/cellSources/zoneToCell/zoneToCell.C | 152 ++++++++++++++---- .../sets/cellSources/zoneToCell/zoneToCell.H | 45 +++++- .../sets/faceSources/zoneToFace/zoneToFace.C | 152 ++++++++++++++---- .../sets/faceSources/zoneToFace/zoneToFace.H | 46 +++++- .../pointSources/zoneToPoint/zoneToPoint.C | 152 ++++++++++++++---- .../pointSources/zoneToPoint/zoneToPoint.H | 45 +++++- 8 files changed, 615 insertions(+), 150 deletions(-) diff --git a/src/meshTools/sets/cellSources/faceZoneToCell/faceZoneToCell.C b/src/meshTools/sets/cellSources/faceZoneToCell/faceZoneToCell.C index ee6493d14c4..f0bba7bdcaa 100644 --- a/src/meshTools/sets/cellSources/faceZoneToCell/faceZoneToCell.C +++ b/src/meshTools/sets/cellSources/faceZoneToCell/faceZoneToCell.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -59,59 +59,103 @@ Foam::faceZoneToCell::faceActionNames_ ({ { faceAction::MASTER, "master" }, { faceAction::SLAVE, "slave" }, + //TBD: { faceAction::BOTH, "attached" }, }); // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const +void Foam::faceZoneToCell::combine +( + topoSet& set, + const labelUList& zoneIDs, + const bool add, + const bool verbosity +) const { - bool hasMatched = false; + const label nZones = mesh_.faceZones().size(); + + if (zoneIDs.empty() || !nZones) + { + return; // Nothing to do + } - for (const faceZone& zone : mesh_.faceZones()) + for (const label zonei : zoneIDs) { - if (selectedZones_.match(zone.name())) + if (zonei < 0 || zonei >= nZones) { - hasMatched = true; + continue; + } - const labelList& cellLabels = - ( - option_ == MASTER - ? zone.masterCells() - : zone.slaveCells() - ); + const auto& zone = mesh_.faceZones()[zonei]; - if (verbose_) - { - Info<< " Found matching zone " << zone.name() - << " with " << cellLabels.size() << " cells on " - << faceActionNames_[option_] << " side" << endl; - } + const labelList& cellLabels = + ( + option_ == MASTER + ? zone.masterCells() + : zone.slaveCells() + ); + + if (verbosity) + { + Info<< " Using matching zone " << zone.name() + << " with " << cellLabels.size() << " cells on " + << faceActionNames_[option_] << " side" << endl; + } - for (const label celli : cellLabels) + // NOTE could also handle both sides directly if required + + for (const label celli : cellLabels) + { + // Only do active cells + if (celli >= 0 && celli < mesh_.nCells()) { - // Only do active cells - if (celli >= 0 && celli < mesh_.nCells()) - { - addOrDelete(set, celli, add); - } + addOrDelete(set, celli, add); } } } +} + + +void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const +{ + if (zoneMatcher_.empty()) + { + return; // Nothing to do + } - if (!hasMatched) + const labelList matched(mesh_.faceZones().indices(zoneMatcher_)); + + if (matched.empty()) { WarningInFunction << "Cannot find any faceZone matching " - << flatOutput(selectedZones_) << nl - << "Valid names: " << flatOutput(mesh_.faceZones().names()) + << flatOutput(zoneMatcher_) << nl + << "Valid names are " << flatOutput(mesh_.faceZones().names()) << endl; + + return; // Nothing to do } + + combine(set, matched, add, verbose_); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam::faceZoneToCell::faceZoneToCell +( + const polyMesh& mesh, + const wordRes& zoneSelector, + const faceAction option +) +: + topoSetCellSource(mesh), + zoneMatcher_(zoneSelector), + option_(option) +{} + + Foam::faceZoneToCell::faceZoneToCell ( const polyMesh& mesh, @@ -120,7 +164,7 @@ Foam::faceZoneToCell::faceZoneToCell ) : topoSetCellSource(mesh), - selectedZones_(one{}, zoneName), + zoneMatcher_(one{}, zoneName), option_(option) {} @@ -132,14 +176,14 @@ Foam::faceZoneToCell::faceZoneToCell ) : topoSetCellSource(mesh), - selectedZones_(), + zoneMatcher_(), option_(faceActionNames_.get("option", dict)) { // Look for 'zones' and 'zone', but accept 'name' as well - if (!dict.readIfPresent("zones", selectedZones_)) + if (!dict.readIfPresent("zones", zoneMatcher_)) { - selectedZones_.resize(1); - selectedZones_.first() = + zoneMatcher_.resize(1); + zoneMatcher_.first() = dict.getCompat<wordRe>("zone", {{"name", 1806}}); } } @@ -152,13 +196,32 @@ Foam::faceZoneToCell::faceZoneToCell ) : topoSetCellSource(mesh), - selectedZones_(one{}, wordRe(checkIs(is))), + zoneMatcher_(one{}, wordRe(checkIs(is))), option_(faceActionNames_.read(checkIs(is))) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +const Foam::wordRes& Foam::faceZoneToCell::zones() const noexcept +{ + return zoneMatcher_; +} + + +void Foam::faceZoneToCell::zones(const wordRes& zonesSelector) +{ + zoneMatcher_ = zonesSelector; +} + + +void Foam::faceZoneToCell::zones(const wordRe& zoneName) +{ + zoneMatcher_.resize(1); + zoneMatcher_.first() = zoneName; +} + + void Foam::faceZoneToCell::applyToSet ( const topoSetSource::setAction action, @@ -167,22 +230,22 @@ void Foam::faceZoneToCell::applyToSet { if (action == topoSetSource::ADD || action == topoSetSource::NEW) { - if (verbose_) + if (verbose_ && !zoneMatcher_.empty()) { Info<< " Adding all " << faceActionNames_[option_] << " cells of face zones " - << flatOutput(selectedZones_) << " ..." << endl; + << flatOutput(zoneMatcher_) << " ..." << endl; } combine(set, true); } else if (action == topoSetSource::SUBTRACT) { - if (verbose_) + if (verbose_ && !zoneMatcher_.empty()) { Info<< " Removing all " << faceActionNames_[option_] << " cells of face zones " - << flatOutput(selectedZones_) << " ..." << endl; + << flatOutput(zoneMatcher_) << " ..." << endl; } combine(set, false); diff --git a/src/meshTools/sets/cellSources/faceZoneToCell/faceZoneToCell.H b/src/meshTools/sets/cellSources/faceZoneToCell/faceZoneToCell.H index c667a0b76a0..7bad0f2e198 100644 --- a/src/meshTools/sets/cellSources/faceZoneToCell/faceZoneToCell.H +++ b/src/meshTools/sets/cellSources/faceZoneToCell/faceZoneToCell.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -93,8 +93,8 @@ Usage Options for the conditional mandatory entries: \verbatim Entry | Description | Type | Req'd | Dflt - zones | Names of input faceZones | wordList | cond'l | - - zone | Name of input faceZone | word | cond'l | - + zones | Names of input faceZones | wordRes | cond'l | - + zone | Name of input faceZone | wordRe | cond'l | - \verbatim Note @@ -149,7 +149,7 @@ private: static addToUsageTable usage_; //- Matcher for face zones - wordRes selectedZones_; + wordRes zoneMatcher_; //- Selection type faceAction option_; @@ -157,6 +157,14 @@ private: // Private Member Functions + void combine + ( + topoSet& set, + const labelUList& zoneIDs, + const bool add, + const bool verbosity + ) const; + void combine(topoSet& set, const bool add) const; @@ -168,7 +176,15 @@ public: // Constructors - //- Construct from components + //- Construct from mesh, zones selector and selection option + faceZoneToCell + ( + const polyMesh& mesh, + const wordRes& zoneSelector, + const faceAction option + ); + + //- Construct from mesh, single zone selector and selection option faceZoneToCell ( const polyMesh& mesh, @@ -189,6 +205,16 @@ public: // Member Functions + //- Return the current zones selector + const wordRes& zones() const noexcept; + + //- Define the zones selector + void zones(const wordRes& zoneSelector); + + //- Define the zones selector with a single zone selector + void zones(const wordRe& zoneName); + + virtual void applyToSet ( const topoSetSource::setAction action, diff --git a/src/meshTools/sets/cellSources/zoneToCell/zoneToCell.C b/src/meshTools/sets/cellSources/zoneToCell/zoneToCell.C index c8ed9326813..64e6aafed40 100644 --- a/src/meshTools/sets/cellSources/zoneToCell/zoneToCell.C +++ b/src/meshTools/sets/cellSources/zoneToCell/zoneToCell.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -67,48 +67,91 @@ Foam::topoSetSource::addToUsageTable Foam::zoneToCell::usage_ // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::zoneToCell::combine(topoSet& set, const bool add) const +void Foam::zoneToCell::combine +( + topoSet& set, + const labelUList& zoneIDs, + const bool add, + const bool verbosity +) const { - bool hasMatched = false; + const label nZones = mesh_.cellZones().size(); + + if (zoneIDs.empty() || !nZones) + { + return; // Nothing to do + } - for (const cellZone& zone : mesh_.cellZones()) + for (const label zonei : zoneIDs) { - if (selectedZones_.match(zone.name())) + if (zonei < 0 || zonei >= nZones) { - hasMatched = true; + continue; + } - const labelList& cellLabels = zone; + const auto& zone = mesh_.cellZones()[zonei]; - if (verbose_) - { - Info<< " Found matching zone " << zone.name() - << " with " << cellLabels.size() << " cells." << endl; - } + if (verbosity) + { + Info<< " Using zone " << zone.name() + << " with " << zone.size() << " cells." << endl; + } - for (const label celli : cellLabels) + for (const label celli : zone) + { + // Only do active cells + if (celli >= 0 && celli < mesh_.nCells()) { - // Only do active cells - if (celli >= 0 && celli < mesh_.nCells()) - { - addOrDelete(set, celli, add); - } + addOrDelete(set, celli, add); } } } +} + + +void Foam::zoneToCell::combine(topoSet& set, const bool add) const +{ + if (!zoneIDs_.empty()) + { + combine(set, zoneIDs_, add, false); + return; + } + + if (zoneMatcher_.empty()) + { + return; // Nothing to do + } - if (!hasMatched) + const labelList matched(mesh_.cellZones().indices(zoneMatcher_)); + + if (matched.empty()) { WarningInFunction << "Cannot find any cellZone matching " - << flatOutput(selectedZones_) << nl + << flatOutput(zoneMatcher_) << nl << "Valid names: " << flatOutput(mesh_.cellZones().names()) << endl; + + return; // Nothing to do } + + combine(set, matched, add, verbose_); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam::zoneToCell::zoneToCell +( + const polyMesh& mesh, + const wordRes& zoneSelector +) +: + topoSetCellSource(mesh), + zoneMatcher_(zoneSelector) +{} + + Foam::zoneToCell::zoneToCell ( const polyMesh& mesh, @@ -116,7 +159,19 @@ Foam::zoneToCell::zoneToCell ) : topoSetCellSource(mesh), - selectedZones_(one{}, zoneName) + zoneMatcher_(one{}, zoneName) +{} + + +Foam::zoneToCell::zoneToCell +( + const polyMesh& mesh, + const labelUList& zoneIDs +) +: + topoSetCellSource(mesh), + zoneMatcher_(), + zoneIDs_(zoneIDs) {} @@ -127,13 +182,13 @@ Foam::zoneToCell::zoneToCell ) : topoSetCellSource(mesh), - selectedZones_() + zoneMatcher_() { // Look for 'zones' and 'zone', but accept 'name' as well - if (!dict.readIfPresent("zones", selectedZones_)) + if (!dict.readIfPresent("zones", zoneMatcher_)) { - selectedZones_.resize(1); - selectedZones_.first() = + zoneMatcher_.resize(1); + zoneMatcher_.first() = dict.getCompat<wordRe>("zone", {{"name", 1806}}); } } @@ -145,13 +200,48 @@ Foam::zoneToCell::zoneToCell Istream& is ) : - topoSetCellSource(mesh), - selectedZones_(one{}, wordRe(checkIs(is))) + zoneToCell(mesh, wordRe(checkIs(is))) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +const Foam::wordRes& Foam::zoneToCell::zones() const noexcept +{ + return zoneMatcher_; +} + + +void Foam::zoneToCell::zones(const wordRes& zonesSelector) +{ + zoneMatcher_ = zonesSelector; + zoneIDs_.clear(); +} + + +void Foam::zoneToCell::zones(const wordRe& zoneName) +{ + zoneMatcher_.resize(1); + zoneMatcher_.first() = zoneName; + zoneIDs_.clear(); +} + + +void Foam::zoneToCell::zones(const labelUList& zoneIDs) +{ + zoneMatcher_.clear(); + zoneIDs_ = zoneIDs; +} + + +void Foam::zoneToCell::zones(const label zoneID) +{ + zoneMatcher_.clear(); + zoneIDs_.resize(1); + zoneIDs_.first() = zoneID; +} + + void Foam::zoneToCell::applyToSet ( const topoSetSource::setAction action, @@ -160,20 +250,20 @@ void Foam::zoneToCell::applyToSet { if (action == topoSetSource::ADD || action == topoSetSource::NEW) { - if (verbose_) + if (verbose_ && !zoneMatcher_.empty()) { Info<< " Adding all cells of cell zones " - << flatOutput(selectedZones_) << " ..." << endl; + << flatOutput(zoneMatcher_) << " ..." << endl; } combine(set, true); } else if (action == topoSetSource::SUBTRACT) { - if (verbose_) + if (verbose_ && !zoneMatcher_.empty()) { Info<< " Removing all cells of cell zones " - << flatOutput(selectedZones_) << " ..." << endl; + << flatOutput(zoneMatcher_) << " ..." << endl; } combine(set, false); diff --git a/src/meshTools/sets/cellSources/zoneToCell/zoneToCell.H b/src/meshTools/sets/cellSources/zoneToCell/zoneToCell.H index 89901dfb2aa..11f63165485 100644 --- a/src/meshTools/sets/cellSources/zoneToCell/zoneToCell.H +++ b/src/meshTools/sets/cellSources/zoneToCell/zoneToCell.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -84,8 +84,8 @@ Usage Options for the conditional mandatory entries: \verbatim Entry | Description | Type | Req'd | Dflt - zones | Names of input cellZones | wordList | cond'l | - - zone | Name of input cellZone | word | cond'l | - + zones | Names of input cellZones | wordRes | cond'l | - + zone | Name of input cellZone | wordRe | cond'l | - \verbatim Note @@ -126,11 +126,22 @@ class zoneToCell static addToUsageTable usage_; //- Matcher for zones - wordRes selectedZones_; + wordRes zoneMatcher_; + + //- Explicitly specified zone ids + labelList zoneIDs_; // Private Member Functions + void combine + ( + topoSet& set, + const labelUList& zoneIDs, + const bool add, + const bool verbosity + ) const; + void combine(topoSet& set, const bool add) const; @@ -142,9 +153,15 @@ public: // Constructors - //- Construct from components + //- Construct from mesh and zones selector + zoneToCell(const polyMesh& mesh, const wordRes& zoneSelector); + + //- Construct from mesh and single zone selector zoneToCell(const polyMesh& mesh, const wordRe& zoneName); + //- Construct from mesh and specified zone IDs + zoneToCell(const polyMesh& mesh, const labelUList& zoneIDs); + //- Construct from dictionary zoneToCell(const polyMesh& mesh, const dictionary& dict); @@ -158,6 +175,24 @@ public: // Member Functions + //- Return the current zones selector + const wordRes& zones() const noexcept; + + //- Define the zones selector + void zones(const wordRes& zoneSelector); + + //- Define the zones selector with a single zone selector + void zones(const wordRe& zoneName); + + //- Define the cellZone IDs to use (must exist). + // Clears the zone name matcher + void zones(const labelUList& zoneIDs); + + //- Define the cellZone ID to use (must exist). + // Clears the zone name matcher + void zones(const label zoneID); + + virtual void applyToSet ( const topoSetSource::setAction action, diff --git a/src/meshTools/sets/faceSources/zoneToFace/zoneToFace.C b/src/meshTools/sets/faceSources/zoneToFace/zoneToFace.C index 36da6b79655..f0ca752b08b 100644 --- a/src/meshTools/sets/faceSources/zoneToFace/zoneToFace.C +++ b/src/meshTools/sets/faceSources/zoneToFace/zoneToFace.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -68,48 +68,91 @@ Foam::topoSetSource::addToUsageTable Foam::zoneToFace::usage_ // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::zoneToFace::combine(topoSet& set, const bool add) const +void Foam::zoneToFace::combine +( + topoSet& set, + const labelUList& zoneIDs, + const bool add, + const bool verbosity +) const { - bool hasMatched = false; + const label nZones = mesh_.faceZones().size(); + + if (zoneIDs.empty() || !nZones) + { + return; // Nothing to do + } - for (const faceZone& zone : mesh_.faceZones()) + for (const label zonei : zoneIDs) { - if (selectedZones_.match(zone.name())) + if (zonei < 0 || zonei >= nZones) { - hasMatched = true; + continue; + } - const labelList& faceLabels = zone; + const auto& zone = mesh_.faceZones()[zonei]; - if (verbose_) - { - Info<< " Found matching zone " << zone.name() - << " with " << faceLabels.size() << " faces." << endl; - } + if (verbosity) + { + Info<< " Using zone " << zone.name() + << " with " << zone.size() << " faces." << endl; + } - for (const label facei : faceLabels) + for (const label facei : zone) + { + // Only do active faces + if (facei >= 0 && facei < mesh_.nFaces()) { - // Only do active faces - if (facei >= 0 && facei < mesh_.nFaces()) - { - addOrDelete(set, facei, add); - } + addOrDelete(set, facei, add); } } } +} + + +void Foam::zoneToFace::combine(topoSet& set, const bool add) const +{ + if (!zoneIDs_.empty()) + { + combine(set, zoneIDs_, add, false); + return; + } + + if (zoneMatcher_.empty()) + { + return; // Nothing to do + } - if (!hasMatched) + const labelList matched(mesh_.faceZones().indices(zoneMatcher_)); + + if (matched.empty()) { WarningInFunction << "Cannot find any faceZone matching " - << flatOutput(selectedZones_) << nl + << flatOutput(zoneMatcher_) << nl << "Valid names are " << flatOutput(mesh_.faceZones().names()) << endl; + + return; // Nothing to do } + + combine(set, matched, add, verbose_); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam::zoneToFace::zoneToFace +( + const polyMesh& mesh, + const wordRes& zoneSelector +) +: + topoSetFaceSource(mesh), + zoneMatcher_(zoneSelector) +{} + + Foam::zoneToFace::zoneToFace ( const polyMesh& mesh, @@ -117,7 +160,19 @@ Foam::zoneToFace::zoneToFace ) : topoSetFaceSource(mesh), - selectedZones_(one{}, zoneName) + zoneMatcher_(one{}, zoneName) +{} + + +Foam::zoneToFace::zoneToFace +( + const polyMesh& mesh, + const labelUList& zoneIDs +) +: + topoSetFaceSource(mesh), + zoneMatcher_(), + zoneIDs_(zoneIDs) {} @@ -128,13 +183,13 @@ Foam::zoneToFace::zoneToFace ) : topoSetFaceSource(mesh), - selectedZones_() + zoneMatcher_() { // Look for 'zones' and 'zone', but accept 'name' as well - if (!dict.readIfPresent("zones", selectedZones_)) + if (!dict.readIfPresent("zones", zoneMatcher_)) { - selectedZones_.resize(1); - selectedZones_.first() = + zoneMatcher_.resize(1); + zoneMatcher_.first() = dict.getCompat<wordRe>("zone", {{"name", 1806}}); } } @@ -146,13 +201,48 @@ Foam::zoneToFace::zoneToFace Istream& is ) : - topoSetFaceSource(mesh), - selectedZones_(one{}, wordRe(checkIs(is))) + zoneToFace(mesh, wordRe(checkIs(is))) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +const Foam::wordRes& Foam::zoneToFace::zones() const noexcept +{ + return zoneMatcher_; +} + + +void Foam::zoneToFace::zones(const wordRes& zonesSelector) +{ + zoneMatcher_ = zonesSelector; + zoneIDs_.clear(); +} + + +void Foam::zoneToFace::zones(const wordRe& zoneName) +{ + zoneMatcher_.resize(1); + zoneMatcher_.first() = zoneName; + zoneIDs_.clear(); +} + + +void Foam::zoneToFace::zones(const labelUList& zoneIDs) +{ + zoneMatcher_.clear(); + zoneIDs_ = zoneIDs; +} + + +void Foam::zoneToFace::zones(const label zoneID) +{ + zoneMatcher_.clear(); + zoneIDs_.resize(1); + zoneIDs_.first() = zoneID; +} + + void Foam::zoneToFace::applyToSet ( const topoSetSource::setAction action, @@ -161,20 +251,20 @@ void Foam::zoneToFace::applyToSet { if (action == topoSetSource::ADD || action == topoSetSource::NEW) { - if (verbose_) + if (verbose_ && !zoneMatcher_.empty()) { Info<< " Adding all faces of face zones " - << flatOutput(selectedZones_) << " ..." << endl; + << flatOutput(zoneMatcher_) << " ..." << endl; } combine(set, true); } else if (action == topoSetSource::SUBTRACT) { - if (verbose_) + if (verbose_ && !zoneMatcher_.empty()) { Info<< " Removing all faces of face zones " - << flatOutput(selectedZones_) << " ..." << endl; + << flatOutput(zoneMatcher_) << " ..." << endl; } combine(set, false); diff --git a/src/meshTools/sets/faceSources/zoneToFace/zoneToFace.H b/src/meshTools/sets/faceSources/zoneToFace/zoneToFace.H index 7e30c342835..efad9bc4e7b 100644 --- a/src/meshTools/sets/faceSources/zoneToFace/zoneToFace.H +++ b/src/meshTools/sets/faceSources/zoneToFace/zoneToFace.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -84,8 +84,8 @@ Usage Options for the conditional mandatory entries: \verbatim Entry | Description | Type | Req'd | Dflt - zones | Names of input faceZones | wordList | cond'l | - - zone | Name of input faceZone | word | cond'l | - + zones | Names of input faceZones | wordRes | cond'l | - + zone | Name of input faceZone | wordRe | cond'l | - \verbatim Note @@ -126,11 +126,23 @@ class zoneToFace static addToUsageTable usage_; //- Matcher for zones - wordRes selectedZones_; + wordRes zoneMatcher_; + + //- Explicitly specified zone ids + labelList zoneIDs_; + // Private Member Functions + void combine + ( + topoSet& set, + const labelUList& zoneIDs, + const bool add, + const bool verbosity + ) const; + void combine(topoSet& set, const bool add) const; @@ -142,9 +154,15 @@ public: // Constructors - //- Construct from components + //- Construct from mesh and zones selector + zoneToFace(const polyMesh& mesh, const wordRes& zoneSelector); + + //- Construct from mesh and single zone selector zoneToFace(const polyMesh& mesh, const wordRe& zoneName); + //- Construct from mesh and specified zone IDs + zoneToFace(const polyMesh& mesh, const labelUList& zoneIDs); + //- Construct from dictionary zoneToFace(const polyMesh& mesh, const dictionary& dict); @@ -158,6 +176,24 @@ public: // Member Functions + //- Return the current zones selector + const wordRes& zones() const noexcept; + + //- Define the zones selector + void zones(const wordRes& zoneSelector); + + //- Define the zones selector with a single zone selector + void zones(const wordRe& zoneName); + + //- Define the faceZone IDs to use (must exist). + // Clears the zone name matcher + void zones(const labelUList& zoneIDs); + + //- Define the faceZone ID to use (must exist). + // Clears the zone name matcher + void zones(const label zoneID); + + virtual void applyToSet ( const topoSetSource::setAction action, diff --git a/src/meshTools/sets/pointSources/zoneToPoint/zoneToPoint.C b/src/meshTools/sets/pointSources/zoneToPoint/zoneToPoint.C index 604e4da83c7..b29bb88167c 100644 --- a/src/meshTools/sets/pointSources/zoneToPoint/zoneToPoint.C +++ b/src/meshTools/sets/pointSources/zoneToPoint/zoneToPoint.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -68,48 +68,91 @@ Foam::topoSetSource::addToUsageTable Foam::zoneToPoint::usage_ // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::zoneToPoint::combine(topoSet& set, const bool add) const +void Foam::zoneToPoint::combine +( + topoSet& set, + const labelUList& zoneIDs, + const bool add, + const bool verbosity +) const { - bool hasMatched = false; + const label nZones = mesh_.pointZones().size(); + + if (zoneIDs.empty() || !nZones) + { + return; // Nothing to do + } - for (const pointZone& zone : mesh_.pointZones()) + for (const label zonei : zoneIDs) { - if (selectedZones_.match(zone.name())) + if (zonei < 0 || zonei >= nZones) { - hasMatched = true; + continue; + } - const labelList& pointLabels = zone; + const auto& zone = mesh_.pointZones()[zonei]; - if (verbose_) - { - Info<< " Found matching zone " << zone.name() - << " with " << pointLabels.size() << " points." << endl; - } + if (verbosity) + { + Info<< " Using zone " << zone.name() + << " with " << zone.size() << " points." << endl; + } - for (const label pointi : pointLabels) + for (const label pointi : zone) + { + // Only do active points + if (pointi >= 0 && pointi < mesh_.nPoints()) { - // Only do active points - if (pointi >= 0 && pointi < mesh_.nPoints()) - { - addOrDelete(set, pointi, add); - } + addOrDelete(set, pointi, add); } } } +} + + +void Foam::zoneToPoint::combine(topoSet& set, const bool add) const +{ + if (!zoneIDs_.empty()) + { + combine(set, zoneIDs_, add, false); + return; + } + + if (zoneMatcher_.empty()) + { + return; // Nothing to do + } - if (!hasMatched) + const labelList matched(mesh_.pointZones().indices(zoneMatcher_)); + + if (matched.empty()) { WarningInFunction << "Cannot find any pointZone matching " - << flatOutput(selectedZones_) << nl + << flatOutput(zoneMatcher_) << nl << "Valid names: " << flatOutput(mesh_.pointZones().names()) << endl; + + return; // Nothing to do } + + combine(set, matched, add, verbose_); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam::zoneToPoint::zoneToPoint +( + const polyMesh& mesh, + const wordRes& zoneSelector +) +: + topoSetPointSource(mesh), + zoneMatcher_(zoneSelector) +{} + + Foam::zoneToPoint::zoneToPoint ( const polyMesh& mesh, @@ -117,7 +160,19 @@ Foam::zoneToPoint::zoneToPoint ) : topoSetPointSource(mesh), - selectedZones_(one{}, zoneName) + zoneMatcher_(one{}, zoneName) +{} + + +Foam::zoneToPoint::zoneToPoint +( + const polyMesh& mesh, + const labelUList& zoneIDs +) +: + topoSetPointSource(mesh), + zoneMatcher_(), + zoneIDs_(zoneIDs) {} @@ -128,13 +183,13 @@ Foam::zoneToPoint::zoneToPoint ) : topoSetPointSource(mesh), - selectedZones_() + zoneMatcher_() { // Look for 'zones' and 'zone', but accept 'name' as well - if (!dict.readIfPresent("zones", selectedZones_)) + if (!dict.readIfPresent("zones", zoneMatcher_)) { - selectedZones_.resize(1); - selectedZones_.first() = + zoneMatcher_.resize(1); + zoneMatcher_.first() = dict.getCompat<wordRe>("zone", {{"name", 1806}}); } } @@ -146,13 +201,48 @@ Foam::zoneToPoint::zoneToPoint Istream& is ) : - topoSetPointSource(mesh), - selectedZones_(one{}, wordRe(checkIs(is))) + zoneToPoint(mesh, wordRe(checkIs(is))) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +const Foam::wordRes& Foam::zoneToPoint::zones() const noexcept +{ + return zoneMatcher_; +} + + +void Foam::zoneToPoint::zones(const wordRes& zonesSelector) +{ + zoneMatcher_ = zonesSelector; + zoneIDs_.clear(); +} + + +void Foam::zoneToPoint::zones(const wordRe& zoneName) +{ + zoneMatcher_.resize(1); + zoneMatcher_.first() = zoneName; + zoneIDs_.clear(); +} + + +void Foam::zoneToPoint::zones(const labelUList& zoneIDs) +{ + zoneMatcher_.clear(); + zoneIDs_ = zoneIDs; +} + + +void Foam::zoneToPoint::zones(const label zoneID) +{ + zoneMatcher_.clear(); + zoneIDs_.resize(1); + zoneIDs_.first() = zoneID; +} + + void Foam::zoneToPoint::applyToSet ( const topoSetSource::setAction action, @@ -161,20 +251,20 @@ void Foam::zoneToPoint::applyToSet { if (action == topoSetSource::ADD || action == topoSetSource::NEW) { - if (verbose_) + if (verbose_ && !zoneMatcher_.empty()) { Info<< " Adding all points of point zones " - << flatOutput(selectedZones_) << " ..." << endl; + << flatOutput(zoneMatcher_) << " ..." << endl; } combine(set, true); } else if (action == topoSetSource::SUBTRACT) { - if (verbose_) + if (verbose_ && !zoneMatcher_.empty()) { Info<< " Removing all points of point zones " - << flatOutput(selectedZones_) << " ..." << endl; + << flatOutput(zoneMatcher_) << " ..." << endl; } combine(set, false); diff --git a/src/meshTools/sets/pointSources/zoneToPoint/zoneToPoint.H b/src/meshTools/sets/pointSources/zoneToPoint/zoneToPoint.H index 9cdec8297bd..2405fe42217 100644 --- a/src/meshTools/sets/pointSources/zoneToPoint/zoneToPoint.H +++ b/src/meshTools/sets/pointSources/zoneToPoint/zoneToPoint.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -84,8 +84,8 @@ Usage Options for the conditional mandatory entries: \verbatim Entry | Description | Type | Req'd | Dflt - zones | Names of input pointZones | wordList | cond'l | - - zone | Name of input pointZone | word | cond'l | - + zones | Names of input pointZones | wordRes | cond'l | - + zone | Name of input pointZone | wordRe | cond'l | - \verbatim Note @@ -126,11 +126,22 @@ class zoneToPoint static addToUsageTable usage_; //- Matcher for zones - wordRes selectedZones_; + wordRes zoneMatcher_; + + //- Explicitly specified zone ids + labelList zoneIDs_; // Private Member Functions + void combine + ( + topoSet& set, + const labelUList& zoneIDs, + const bool add, + const bool verbosity + ) const; + void combine(topoSet& set, const bool add) const; @@ -142,9 +153,15 @@ public: // Constructors - //- Construct from components + //- Construct from mesh and zones selector + zoneToPoint(const polyMesh& mesh, const wordRes& zoneSelector); + + //- Construct from mesh and single zone selector zoneToPoint(const polyMesh& mesh, const wordRe& zoneName); + //- Construct from mesh and specified zone IDs + zoneToPoint(const polyMesh& mesh, const labelUList& zoneIDs); + //- Construct from dictionary zoneToPoint(const polyMesh& mesh, const dictionary& dict); @@ -158,6 +175,24 @@ public: // Member Functions + //- Return the current zones selector + const wordRes& zones() const noexcept; + + //- Define the zones selector + void zones(const wordRes& zoneSelector); + + //- Define the zones selector with a single zone selector + void zones(const wordRe& zoneName); + + //- Define the pointZone IDs to use (must exist). + // Clears the zone name matcher + void zones(const labelUList& zoneIDs); + + //- Define the pointZone ID to use (must exist). + // Clears the zone name matcher + void zones(const label zoneID); + + virtual void applyToSet ( const topoSetSource::setAction action, -- GitLab