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 | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2022 OpenCFD Ltd. Copyright (C) 2018-2022,2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -114,7 +114,12 @@ Foam::cellZoneSet::cellZoneSet
: :
cellSet(mesh, name, set.size(), wOpt), cellSet(mesh, name, set.size(), wOpt),
mesh_(mesh), mesh_(mesh),
addressing_(refCast<const cellZoneSet>(set).addressing()) addressing_
(
isA<const cellZoneSet>(set)
? refCast<const cellZoneSet>(set).addressing()
: set.sortedToc()
)
{ {
updateSet(); updateSet();
} }
@ -156,15 +161,29 @@ void Foam::cellZoneSet::subset(const topoSet& set)
{ {
DynamicList<label> newAddressing(addressing_.size()); 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)
{
for (const label celli : setPtr->addressing())
{ {
if (found(celli)) if (found(celli))
{ {
newAddressing.append(celli); newAddressing.append(celli);
} }
} }
}
else
{
// Assume a cellSet
for (const label celli : refCast<const cellSet>(set).sortedToc())
{
if (found(celli))
{
newAddressing.append(celli);
}
}
}
addressing_.transfer(newAddressing); addressing_.transfer(newAddressing);
updateSet(); updateSet();
@ -192,15 +211,29 @@ void Foam::cellZoneSet::addSet(const topoSet& set)
{ {
DynamicList<label> newAddressing(addressing_); 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)
{
for (const label celli : setPtr->addressing())
{ {
if (!found(celli)) if (!found(celli))
{ {
newAddressing.append(celli); newAddressing.append(celli);
} }
} }
}
else
{
// Assume a cellSet
for (const label celli : refCast<const cellSet>(set).sortedToc())
{
if (!found(celli))
{
newAddressing.append(celli);
}
}
}
addressing_.transfer(newAddressing); addressing_.transfer(newAddressing);
updateSet(); updateSet();
@ -228,11 +261,9 @@ void Foam::cellZoneSet::subtractSet(const topoSet& set)
{ {
DynamicList<label> newAddressing(addressing_.size()); DynamicList<label> newAddressing(addressing_.size());
const cellZoneSet& zoneSet = refCast<const cellZoneSet>(set);
for (const label celli : addressing_) for (const label celli : addressing_)
{ {
if (!zoneSet.found(celli)) if (!set.found(celli))
{ {
// Not found in zoneSet so add // Not found in zoneSet so add
newAddressing.append(celli); newAddressing.append(celli);

View File

@ -220,8 +220,18 @@ void Foam::faceZoneSet::subset
void Foam::faceZoneSet::subset(const topoSet& set) void Foam::faceZoneSet::subset(const topoSet& set)
{ {
const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); const auto* setPtr = dynamic_cast<const faceZoneSet*>(&set);
subset(zoneSet.name(), zoneSet.addressing(), zoneSet.flipMap());
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) void Foam::faceZoneSet::addSet(const topoSet& set)
{ {
const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); const auto* setPtr = dynamic_cast<const faceZoneSet*>(&set);
addSet(zoneSet.name(), zoneSet.addressing(), zoneSet.flipMap());
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) void Foam::faceZoneSet::subtractSet(const topoSet& set)
{ {
const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); const auto* setPtr = dynamic_cast<const faceZoneSet*>(&set);
subtractSet(zoneSet.name(), zoneSet.addressing(), zoneSet.flipMap());
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 | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2022 OpenCFD Ltd. Copyright (C) 2018-2022,2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -115,7 +115,12 @@ Foam::pointZoneSet::pointZoneSet
: :
pointSet(mesh, name, set.size(), wOpt), pointSet(mesh, name, set.size(), wOpt),
mesh_(mesh), mesh_(mesh),
addressing_(refCast<const pointZoneSet>(set).addressing()) addressing_
(
isA<const pointZoneSet>(set)
? refCast<const pointZoneSet>(set).addressing()
: set.sortedToc()
)
{ {
updateSet(); updateSet();
} }
@ -156,15 +161,29 @@ void Foam::pointZoneSet::subset(const topoSet& set)
{ {
DynamicList<label> newAddressing(addressing_.size()); 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)
{
for (const label pointi : setPtr->addressing())
{ {
if (found(pointi)) if (found(pointi))
{ {
newAddressing.append(pointi); newAddressing.append(pointi);
} }
} }
}
else
{
// Assume a pointSet
for (const label pointi : refCast<const pointSet>(set).sortedToc())
{
if (found(pointi))
{
newAddressing.append(pointi);
}
}
}
addressing_.transfer(newAddressing); addressing_.transfer(newAddressing);
updateSet(); updateSet();
@ -192,15 +211,29 @@ void Foam::pointZoneSet::addSet(const topoSet& set)
{ {
DynamicList<label> newAddressing(addressing_); 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)
{
for (const label pointi : setPtr->addressing())
{ {
if (!found(pointi)) if (!found(pointi))
{ {
newAddressing.append(pointi); newAddressing.append(pointi);
} }
} }
}
else
{
// Assume a pointSet
for (const label pointi : refCast<const pointSet>(set).sortedToc())
{
if (!found(pointi))
{
newAddressing.append(pointi);
}
}
}
addressing_.transfer(newAddressing); addressing_.transfer(newAddressing);
updateSet(); updateSet();
@ -228,11 +261,9 @@ void Foam::pointZoneSet::subtractSet(const topoSet& set)
{ {
DynamicList<label> newAddressing(addressing_.size()); DynamicList<label> newAddressing(addressing_.size());
const pointZoneSet& zoneSet = refCast<const pointZoneSet>(set);
for (label pointi : addressing_) for (label pointi : addressing_)
{ {
if (!zoneSet.found(pointi)) if (!set.found(pointi))
{ {
// Not found in zoneSet so add // Not found in zoneSet so add
newAddressing.append(pointi); newAddressing.append(pointi);