BUG: topoSet: allow use of 'set' as input for zones. Fixes #3126

This commit is contained in:
mattijs
2024-03-27 10:28:56 +00:00
parent 6bd1486a38
commit 5091c79e96
3 changed files with 124 additions and 32 deletions

View File

@ -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);

View File

@ -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());
}
}

View File

@ -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);