mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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
This commit is contained in:
@ -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,20 +59,35 @@ 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();
|
||||
|
||||
for (const faceZone& zone : mesh_.faceZones())
|
||||
if (zoneIDs.empty() || !nZones)
|
||||
{
|
||||
if (selectedZones_.match(zone.name()))
|
||||
return; // Nothing to do
|
||||
}
|
||||
|
||||
for (const label zonei : zoneIDs)
|
||||
{
|
||||
hasMatched = true;
|
||||
if (zonei < 0 || zonei >= nZones)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& zone = mesh_.faceZones()[zonei];
|
||||
|
||||
const labelList& cellLabels =
|
||||
(
|
||||
@ -81,13 +96,15 @@ void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
|
||||
: zone.slaveCells()
|
||||
);
|
||||
|
||||
if (verbose_)
|
||||
if (verbosity)
|
||||
{
|
||||
Info<< " Found matching zone " << zone.name()
|
||||
Info<< " Using matching zone " << zone.name()
|
||||
<< " with " << cellLabels.size() << " cells on "
|
||||
<< faceActionNames_[option_] << " side" << endl;
|
||||
}
|
||||
|
||||
// NOTE could also handle both sides directly if required
|
||||
|
||||
for (const label celli : cellLabels)
|
||||
{
|
||||
// Only do active cells
|
||||
@ -97,21 +114,48 @@ void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,25 +67,37 @@ 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();
|
||||
|
||||
for (const cellZone& zone : mesh_.cellZones())
|
||||
if (zoneIDs.empty() || !nZones)
|
||||
{
|
||||
if (selectedZones_.match(zone.name()))
|
||||
{
|
||||
hasMatched = true;
|
||||
|
||||
const labelList& cellLabels = zone;
|
||||
|
||||
if (verbose_)
|
||||
{
|
||||
Info<< " Found matching zone " << zone.name()
|
||||
<< " with " << cellLabels.size() << " cells." << endl;
|
||||
return; // Nothing to do
|
||||
}
|
||||
|
||||
for (const label celli : cellLabels)
|
||||
for (const label zonei : zoneIDs)
|
||||
{
|
||||
if (zonei < 0 || zonei >= nZones)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& zone = mesh_.cellZones()[zonei];
|
||||
|
||||
if (verbosity)
|
||||
{
|
||||
Info<< " Using zone " << zone.name()
|
||||
<< " with " << zone.size() << " cells." << endl;
|
||||
}
|
||||
|
||||
for (const label celli : zone)
|
||||
{
|
||||
// Only do active cells
|
||||
if (celli >= 0 && celli < mesh_.nCells())
|
||||
@ -94,21 +106,52 @@ void Foam::zoneToCell::combine(topoSet& set, const bool add) const
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::zoneToCell::combine(topoSet& set, const bool add) const
|
||||
{
|
||||
if (!zoneIDs_.empty())
|
||||
{
|
||||
combine(set, zoneIDs_, add, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasMatched)
|
||||
if (zoneMatcher_.empty())
|
||||
{
|
||||
return; // Nothing to do
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,25 +68,37 @@ 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();
|
||||
|
||||
for (const faceZone& zone : mesh_.faceZones())
|
||||
if (zoneIDs.empty() || !nZones)
|
||||
{
|
||||
if (selectedZones_.match(zone.name()))
|
||||
{
|
||||
hasMatched = true;
|
||||
|
||||
const labelList& faceLabels = zone;
|
||||
|
||||
if (verbose_)
|
||||
{
|
||||
Info<< " Found matching zone " << zone.name()
|
||||
<< " with " << faceLabels.size() << " faces." << endl;
|
||||
return; // Nothing to do
|
||||
}
|
||||
|
||||
for (const label facei : faceLabels)
|
||||
for (const label zonei : zoneIDs)
|
||||
{
|
||||
if (zonei < 0 || zonei >= nZones)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& zone = mesh_.faceZones()[zonei];
|
||||
|
||||
if (verbosity)
|
||||
{
|
||||
Info<< " Using zone " << zone.name()
|
||||
<< " with " << zone.size() << " faces." << endl;
|
||||
}
|
||||
|
||||
for (const label facei : zone)
|
||||
{
|
||||
// Only do active faces
|
||||
if (facei >= 0 && facei < mesh_.nFaces())
|
||||
@ -95,21 +107,52 @@ void Foam::zoneToFace::combine(topoSet& set, const bool add) const
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::zoneToFace::combine(topoSet& set, const bool add) const
|
||||
{
|
||||
if (!zoneIDs_.empty())
|
||||
{
|
||||
combine(set, zoneIDs_, add, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasMatched)
|
||||
if (zoneMatcher_.empty())
|
||||
{
|
||||
return; // Nothing to do
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,25 +68,37 @@ 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();
|
||||
|
||||
for (const pointZone& zone : mesh_.pointZones())
|
||||
if (zoneIDs.empty() || !nZones)
|
||||
{
|
||||
if (selectedZones_.match(zone.name()))
|
||||
{
|
||||
hasMatched = true;
|
||||
|
||||
const labelList& pointLabels = zone;
|
||||
|
||||
if (verbose_)
|
||||
{
|
||||
Info<< " Found matching zone " << zone.name()
|
||||
<< " with " << pointLabels.size() << " points." << endl;
|
||||
return; // Nothing to do
|
||||
}
|
||||
|
||||
for (const label pointi : pointLabels)
|
||||
for (const label zonei : zoneIDs)
|
||||
{
|
||||
if (zonei < 0 || zonei >= nZones)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& zone = mesh_.pointZones()[zonei];
|
||||
|
||||
if (verbosity)
|
||||
{
|
||||
Info<< " Using zone " << zone.name()
|
||||
<< " with " << zone.size() << " points." << endl;
|
||||
}
|
||||
|
||||
for (const label pointi : zone)
|
||||
{
|
||||
// Only do active points
|
||||
if (pointi >= 0 && pointi < mesh_.nPoints())
|
||||
@ -95,21 +107,52 @@ void Foam::zoneToPoint::combine(topoSet& set, const bool add) const
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::zoneToPoint::combine(topoSet& set, const bool add) const
|
||||
{
|
||||
if (!zoneIDs_.empty())
|
||||
{
|
||||
combine(set, zoneIDs_, add, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasMatched)
|
||||
if (zoneMatcher_.empty())
|
||||
{
|
||||
return; // Nothing to do
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user