diff --git a/src/meshTools/topoSet/topoSets/cellZoneSet.C b/src/meshTools/topoSet/topoSets/cellZoneSet.C index 4fca3baacc0db87d120475faa8adb940e42b1268..fd36af0d2faee1804201690711d43394dc005fc3 100644 --- a/src/meshTools/topoSet/topoSets/cellZoneSet.C +++ b/src/meshTools/topoSet/topoSets/cellZoneSet.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2022,2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -114,7 +114,12 @@ Foam::cellZoneSet::cellZoneSet : cellSet(mesh, name, set.size(), wOpt), mesh_(mesh), - addressing_(refCast<const cellZoneSet>(set).addressing()) + addressing_ + ( + isA<const cellZoneSet>(set) + ? refCast<const cellZoneSet>(set).addressing() + : set.sortedToc() + ) { updateSet(); } @@ -156,13 +161,27 @@ void Foam::cellZoneSet::subset(const topoSet& set) { DynamicList<label> newAddressing(addressing_.size()); - const cellZoneSet& zoneSet = refCast<const cellZoneSet>(set); + const auto* setPtr = dynamic_cast<const cellZoneSet*>(&set); - for (const label celli : zoneSet.addressing()) + if (setPtr) { - if (found(celli)) + for (const label celli : setPtr->addressing()) { - newAddressing.append(celli); + if (found(celli)) + { + newAddressing.append(celli); + } + } + } + else + { + // Assume a cellSet + for (const label celli : refCast<const cellSet>(set).sortedToc()) + { + if (found(celli)) + { + newAddressing.append(celli); + } } } @@ -192,13 +211,27 @@ void Foam::cellZoneSet::addSet(const topoSet& set) { DynamicList<label> newAddressing(addressing_); - const cellZoneSet& zoneSet = refCast<const cellZoneSet>(set); + const auto* setPtr = dynamic_cast<const cellZoneSet*>(&set); - for (const label celli : zoneSet.addressing()) + if (setPtr) { - if (!found(celli)) + for (const label celli : setPtr->addressing()) { - newAddressing.append(celli); + if (!found(celli)) + { + newAddressing.append(celli); + } + } + } + else + { + // Assume a cellSet + for (const label celli : refCast<const cellSet>(set).sortedToc()) + { + if (!found(celli)) + { + newAddressing.append(celli); + } } } @@ -228,11 +261,9 @@ void Foam::cellZoneSet::subtractSet(const topoSet& set) { DynamicList<label> newAddressing(addressing_.size()); - const cellZoneSet& zoneSet = refCast<const cellZoneSet>(set); - for (const label celli : addressing_) { - if (!zoneSet.found(celli)) + if (!set.found(celli)) { // Not found in zoneSet so add newAddressing.append(celli); diff --git a/src/meshTools/topoSet/topoSets/faceZoneSet.C b/src/meshTools/topoSet/topoSets/faceZoneSet.C index 6b230325ead262a2f44833b4b7e83a15acf65937..73431e3890c634e9fef12b903565f16773425635 100644 --- a/src/meshTools/topoSet/topoSets/faceZoneSet.C +++ b/src/meshTools/topoSet/topoSets/faceZoneSet.C @@ -220,8 +220,18 @@ void Foam::faceZoneSet::subset void Foam::faceZoneSet::subset(const topoSet& set) { - const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); - subset(zoneSet.name(), zoneSet.addressing(), zoneSet.flipMap()); + const auto* setPtr = dynamic_cast<const faceZoneSet*>(&set); + + if (setPtr) + { + subset(setPtr->name(), setPtr->addressing(), setPtr->flipMap()); + } + else + { + // Assume a faceSet. Ignore flipMap + const auto& fSet = refCast<const faceSet>(set); + subset(fSet.name(), fSet.sortedToc(), boolList::null()); + } } @@ -282,8 +292,18 @@ void Foam::faceZoneSet::addSet void Foam::faceZoneSet::addSet(const topoSet& set) { - const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); - addSet(zoneSet.name(), zoneSet.addressing(), zoneSet.flipMap()); + const auto* setPtr = dynamic_cast<const faceZoneSet*>(&set); + + if (setPtr) + { + addSet(setPtr->name(), setPtr->addressing(), setPtr->flipMap()); + } + else + { + // Assume a faceSet. Ignore flipMap + const auto& fSet = refCast<const faceSet>(set); + addSet(fSet.name(), fSet.sortedToc(), boolList::null()); + } } @@ -346,8 +366,18 @@ void Foam::faceZoneSet::subtractSet void Foam::faceZoneSet::subtractSet(const topoSet& set) { - const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); - subtractSet(zoneSet.name(), zoneSet.addressing(), zoneSet.flipMap()); + const auto* setPtr = dynamic_cast<const faceZoneSet*>(&set); + + if (setPtr) + { + subtractSet(setPtr->name(), setPtr->addressing(), setPtr->flipMap()); + } + else + { + // Assume a faceSet. Ignore flipMap + const auto& fSet = refCast<const faceSet>(set); + subtractSet(fSet.name(), fSet.sortedToc(), boolList::null()); + } } diff --git a/src/meshTools/topoSet/topoSets/pointZoneSet.C b/src/meshTools/topoSet/topoSets/pointZoneSet.C index 752ab2524bd1a30efbc7f2567e7986b6c2742631..1bcd5b503dacde5b3d4b79f505dfee9d62a3eb04 100644 --- a/src/meshTools/topoSet/topoSets/pointZoneSet.C +++ b/src/meshTools/topoSet/topoSets/pointZoneSet.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2022,2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -115,7 +115,12 @@ Foam::pointZoneSet::pointZoneSet : pointSet(mesh, name, set.size(), wOpt), mesh_(mesh), - addressing_(refCast<const pointZoneSet>(set).addressing()) + addressing_ + ( + isA<const pointZoneSet>(set) + ? refCast<const pointZoneSet>(set).addressing() + : set.sortedToc() + ) { updateSet(); } @@ -156,13 +161,27 @@ void Foam::pointZoneSet::subset(const topoSet& set) { DynamicList<label> newAddressing(addressing_.size()); - const pointZoneSet& zoneSet = refCast<const pointZoneSet>(set); + const auto* setPtr = dynamic_cast<const pointZoneSet*>(&set); - for (const label pointi : zoneSet.addressing()) + if (setPtr) { - if (found(pointi)) + for (const label pointi : setPtr->addressing()) { - newAddressing.append(pointi); + if (found(pointi)) + { + newAddressing.append(pointi); + } + } + } + else + { + // Assume a pointSet + for (const label pointi : refCast<const pointSet>(set).sortedToc()) + { + if (found(pointi)) + { + newAddressing.append(pointi); + } } } @@ -192,13 +211,27 @@ void Foam::pointZoneSet::addSet(const topoSet& set) { DynamicList<label> newAddressing(addressing_); - const pointZoneSet& zoneSet = refCast<const pointZoneSet>(set); + const auto* setPtr = dynamic_cast<const pointZoneSet*>(&set); - for (const label pointi : zoneSet.addressing()) + if (setPtr) { - if (!found(pointi)) + for (const label pointi : setPtr->addressing()) { - newAddressing.append(pointi); + if (!found(pointi)) + { + newAddressing.append(pointi); + } + } + } + else + { + // Assume a pointSet + for (const label pointi : refCast<const pointSet>(set).sortedToc()) + { + if (!found(pointi)) + { + newAddressing.append(pointi); + } } } @@ -228,11 +261,9 @@ void Foam::pointZoneSet::subtractSet(const topoSet& set) { DynamicList<label> newAddressing(addressing_.size()); - const pointZoneSet& zoneSet = refCast<const pointZoneSet>(set); - for (label pointi : addressing_) { - if (!zoneSet.found(pointi)) + if (!set.found(pointi)) { // Not found in zoneSet so add newAddressing.append(pointi);