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:
Mark Olesen
2021-06-19 13:02:42 +02:00
parent b2fdc67273
commit 269d0ffd5c
8 changed files with 628 additions and 163 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -59,20 +59,35 @@ Foam::faceZoneToCell::faceActionNames_
({ ({
{ faceAction::MASTER, "master" }, { faceAction::MASTER, "master" },
{ faceAction::SLAVE, "slave" }, { faceAction::SLAVE, "slave" },
//TBD: { faceAction::BOTH, "attached" },
}); });
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * 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 = const labelList& cellLabels =
( (
@ -81,13 +96,15 @@ void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
: zone.slaveCells() : zone.slaveCells()
); );
if (verbose_) if (verbosity)
{ {
Info<< " Found matching zone " << zone.name() Info<< " Using matching zone " << zone.name()
<< " with " << cellLabels.size() << " cells on " << " with " << cellLabels.size() << " cells on "
<< faceActionNames_[option_] << " side" << endl; << faceActionNames_[option_] << " side" << endl;
} }
// NOTE could also handle both sides directly if required
for (const label celli : cellLabels) for (const label celli : cellLabels)
{ {
// Only do active cells // 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 WarningInFunction
<< "Cannot find any faceZone matching " << "Cannot find any faceZone matching "
<< flatOutput(selectedZones_) << nl << flatOutput(zoneMatcher_) << nl
<< "Valid names: " << flatOutput(mesh_.faceZones().names()) << "Valid names are " << flatOutput(mesh_.faceZones().names())
<< endl; << endl;
return; // Nothing to do
} }
combine(set, matched, add, verbose_);
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::faceZoneToCell::faceZoneToCell
(
const polyMesh& mesh,
const wordRes& zoneSelector,
const faceAction option
)
:
topoSetCellSource(mesh),
zoneMatcher_(zoneSelector),
option_(option)
{}
Foam::faceZoneToCell::faceZoneToCell Foam::faceZoneToCell::faceZoneToCell
( (
const polyMesh& mesh, const polyMesh& mesh,
@ -120,7 +164,7 @@ Foam::faceZoneToCell::faceZoneToCell
) )
: :
topoSetCellSource(mesh), topoSetCellSource(mesh),
selectedZones_(one{}, zoneName), zoneMatcher_(one{}, zoneName),
option_(option) option_(option)
{} {}
@ -132,14 +176,14 @@ Foam::faceZoneToCell::faceZoneToCell
) )
: :
topoSetCellSource(mesh), topoSetCellSource(mesh),
selectedZones_(), zoneMatcher_(),
option_(faceActionNames_.get("option", dict)) option_(faceActionNames_.get("option", dict))
{ {
// Look for 'zones' and 'zone', but accept 'name' as well // Look for 'zones' and 'zone', but accept 'name' as well
if (!dict.readIfPresent("zones", selectedZones_)) if (!dict.readIfPresent("zones", zoneMatcher_))
{ {
selectedZones_.resize(1); zoneMatcher_.resize(1);
selectedZones_.first() = zoneMatcher_.first() =
dict.getCompat<wordRe>("zone", {{"name", 1806}}); dict.getCompat<wordRe>("zone", {{"name", 1806}});
} }
} }
@ -152,13 +196,32 @@ Foam::faceZoneToCell::faceZoneToCell
) )
: :
topoSetCellSource(mesh), topoSetCellSource(mesh),
selectedZones_(one{}, wordRe(checkIs(is))), zoneMatcher_(one{}, wordRe(checkIs(is))),
option_(faceActionNames_.read(checkIs(is))) option_(faceActionNames_.read(checkIs(is)))
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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 void Foam::faceZoneToCell::applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,
@ -167,22 +230,22 @@ void Foam::faceZoneToCell::applyToSet
{ {
if (action == topoSetSource::ADD || action == topoSetSource::NEW) if (action == topoSetSource::ADD || action == topoSetSource::NEW)
{ {
if (verbose_) if (verbose_ && !zoneMatcher_.empty())
{ {
Info<< " Adding all " << faceActionNames_[option_] Info<< " Adding all " << faceActionNames_[option_]
<< " cells of face zones " << " cells of face zones "
<< flatOutput(selectedZones_) << " ..." << endl; << flatOutput(zoneMatcher_) << " ..." << endl;
} }
combine(set, true); combine(set, true);
} }
else if (action == topoSetSource::SUBTRACT) else if (action == topoSetSource::SUBTRACT)
{ {
if (verbose_) if (verbose_ && !zoneMatcher_.empty())
{ {
Info<< " Removing all " << faceActionNames_[option_] Info<< " Removing all " << faceActionNames_[option_]
<< " cells of face zones " << " cells of face zones "
<< flatOutput(selectedZones_) << " ..." << endl; << flatOutput(zoneMatcher_) << " ..." << endl;
} }
combine(set, false); combine(set, false);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -93,8 +93,8 @@ Usage
Options for the conditional mandatory entries: Options for the conditional mandatory entries:
\verbatim \verbatim
Entry | Description | Type | Req'd | Dflt Entry | Description | Type | Req'd | Dflt
zones | Names of input faceZones | wordList | cond'l | - zones | Names of input faceZones | wordRes | cond'l | -
zone | Name of input faceZone | word | cond'l | - zone | Name of input faceZone | wordRe | cond'l | -
\verbatim \verbatim
Note Note
@ -149,7 +149,7 @@ private:
static addToUsageTable usage_; static addToUsageTable usage_;
//- Matcher for face zones //- Matcher for face zones
wordRes selectedZones_; wordRes zoneMatcher_;
//- Selection type //- Selection type
faceAction option_; faceAction option_;
@ -157,6 +157,14 @@ private:
// Private Member Functions // 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; void combine(topoSet& set, const bool add) const;
@ -168,7 +176,15 @@ public:
// Constructors // 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 faceZoneToCell
( (
const polyMesh& mesh, const polyMesh& mesh,
@ -189,6 +205,16 @@ public:
// Member Functions // 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 virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

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-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -67,25 +67,37 @@ Foam::topoSetSource::addToUsageTable Foam::zoneToCell::usage_
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * 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())) return; // Nothing to do
{
hasMatched = true;
const labelList& cellLabels = zone;
if (verbose_)
{
Info<< " Found matching zone " << zone.name()
<< " with " << cellLabels.size() << " cells." << endl;
} }
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 // Only do active cells
if (celli >= 0 && celli < mesh_.nCells()) 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 WarningInFunction
<< "Cannot find any cellZone matching " << "Cannot find any cellZone matching "
<< flatOutput(selectedZones_) << nl << flatOutput(zoneMatcher_) << nl
<< "Valid names: " << flatOutput(mesh_.cellZones().names()) << "Valid names: " << flatOutput(mesh_.cellZones().names())
<< endl; << endl;
return; // Nothing to do
} }
combine(set, matched, add, verbose_);
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::zoneToCell::zoneToCell
(
const polyMesh& mesh,
const wordRes& zoneSelector
)
:
topoSetCellSource(mesh),
zoneMatcher_(zoneSelector)
{}
Foam::zoneToCell::zoneToCell Foam::zoneToCell::zoneToCell
( (
const polyMesh& mesh, const polyMesh& mesh,
@ -116,7 +159,19 @@ Foam::zoneToCell::zoneToCell
) )
: :
topoSetCellSource(mesh), 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), topoSetCellSource(mesh),
selectedZones_() zoneMatcher_()
{ {
// Look for 'zones' and 'zone', but accept 'name' as well // Look for 'zones' and 'zone', but accept 'name' as well
if (!dict.readIfPresent("zones", selectedZones_)) if (!dict.readIfPresent("zones", zoneMatcher_))
{ {
selectedZones_.resize(1); zoneMatcher_.resize(1);
selectedZones_.first() = zoneMatcher_.first() =
dict.getCompat<wordRe>("zone", {{"name", 1806}}); dict.getCompat<wordRe>("zone", {{"name", 1806}});
} }
} }
@ -145,13 +200,48 @@ Foam::zoneToCell::zoneToCell
Istream& is Istream& is
) )
: :
topoSetCellSource(mesh), zoneToCell(mesh, wordRe(checkIs(is)))
selectedZones_(one{}, wordRe(checkIs(is)))
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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 void Foam::zoneToCell::applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,
@ -160,20 +250,20 @@ void Foam::zoneToCell::applyToSet
{ {
if (action == topoSetSource::ADD || action == topoSetSource::NEW) if (action == topoSetSource::ADD || action == topoSetSource::NEW)
{ {
if (verbose_) if (verbose_ && !zoneMatcher_.empty())
{ {
Info<< " Adding all cells of cell zones " Info<< " Adding all cells of cell zones "
<< flatOutput(selectedZones_) << " ..." << endl; << flatOutput(zoneMatcher_) << " ..." << endl;
} }
combine(set, true); combine(set, true);
} }
else if (action == topoSetSource::SUBTRACT) else if (action == topoSetSource::SUBTRACT)
{ {
if (verbose_) if (verbose_ && !zoneMatcher_.empty())
{ {
Info<< " Removing all cells of cell zones " Info<< " Removing all cells of cell zones "
<< flatOutput(selectedZones_) << " ..." << endl; << flatOutput(zoneMatcher_) << " ..." << endl;
} }
combine(set, false); combine(set, false);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -84,8 +84,8 @@ Usage
Options for the conditional mandatory entries: Options for the conditional mandatory entries:
\verbatim \verbatim
Entry | Description | Type | Req'd | Dflt Entry | Description | Type | Req'd | Dflt
zones | Names of input cellZones | wordList | cond'l | - zones | Names of input cellZones | wordRes | cond'l | -
zone | Name of input cellZone | word | cond'l | - zone | Name of input cellZone | wordRe | cond'l | -
\verbatim \verbatim
Note Note
@ -126,11 +126,22 @@ class zoneToCell
static addToUsageTable usage_; static addToUsageTable usage_;
//- Matcher for zones //- Matcher for zones
wordRes selectedZones_; wordRes zoneMatcher_;
//- Explicitly specified zone ids
labelList zoneIDs_;
// Private Member Functions // 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; void combine(topoSet& set, const bool add) const;
@ -142,9 +153,15 @@ public:
// Constructors // 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); zoneToCell(const polyMesh& mesh, const wordRe& zoneName);
//- Construct from mesh and specified zone IDs
zoneToCell(const polyMesh& mesh, const labelUList& zoneIDs);
//- Construct from dictionary //- Construct from dictionary
zoneToCell(const polyMesh& mesh, const dictionary& dict); zoneToCell(const polyMesh& mesh, const dictionary& dict);
@ -158,6 +175,24 @@ public:
// Member Functions // 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 virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

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-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -68,25 +68,37 @@ Foam::topoSetSource::addToUsageTable Foam::zoneToFace::usage_
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * 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())) return; // Nothing to do
{
hasMatched = true;
const labelList& faceLabels = zone;
if (verbose_)
{
Info<< " Found matching zone " << zone.name()
<< " with " << faceLabels.size() << " faces." << endl;
} }
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 // Only do active faces
if (facei >= 0 && facei < mesh_.nFaces()) 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 WarningInFunction
<< "Cannot find any faceZone matching " << "Cannot find any faceZone matching "
<< flatOutput(selectedZones_) << nl << flatOutput(zoneMatcher_) << nl
<< "Valid names are " << flatOutput(mesh_.faceZones().names()) << "Valid names are " << flatOutput(mesh_.faceZones().names())
<< endl; << endl;
return; // Nothing to do
} }
combine(set, matched, add, verbose_);
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::zoneToFace::zoneToFace
(
const polyMesh& mesh,
const wordRes& zoneSelector
)
:
topoSetFaceSource(mesh),
zoneMatcher_(zoneSelector)
{}
Foam::zoneToFace::zoneToFace Foam::zoneToFace::zoneToFace
( (
const polyMesh& mesh, const polyMesh& mesh,
@ -117,7 +160,19 @@ Foam::zoneToFace::zoneToFace
) )
: :
topoSetFaceSource(mesh), 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), topoSetFaceSource(mesh),
selectedZones_() zoneMatcher_()
{ {
// Look for 'zones' and 'zone', but accept 'name' as well // Look for 'zones' and 'zone', but accept 'name' as well
if (!dict.readIfPresent("zones", selectedZones_)) if (!dict.readIfPresent("zones", zoneMatcher_))
{ {
selectedZones_.resize(1); zoneMatcher_.resize(1);
selectedZones_.first() = zoneMatcher_.first() =
dict.getCompat<wordRe>("zone", {{"name", 1806}}); dict.getCompat<wordRe>("zone", {{"name", 1806}});
} }
} }
@ -146,13 +201,48 @@ Foam::zoneToFace::zoneToFace
Istream& is Istream& is
) )
: :
topoSetFaceSource(mesh), zoneToFace(mesh, wordRe(checkIs(is)))
selectedZones_(one{}, wordRe(checkIs(is)))
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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 void Foam::zoneToFace::applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,
@ -161,20 +251,20 @@ void Foam::zoneToFace::applyToSet
{ {
if (action == topoSetSource::ADD || action == topoSetSource::NEW) if (action == topoSetSource::ADD || action == topoSetSource::NEW)
{ {
if (verbose_) if (verbose_ && !zoneMatcher_.empty())
{ {
Info<< " Adding all faces of face zones " Info<< " Adding all faces of face zones "
<< flatOutput(selectedZones_) << " ..." << endl; << flatOutput(zoneMatcher_) << " ..." << endl;
} }
combine(set, true); combine(set, true);
} }
else if (action == topoSetSource::SUBTRACT) else if (action == topoSetSource::SUBTRACT)
{ {
if (verbose_) if (verbose_ && !zoneMatcher_.empty())
{ {
Info<< " Removing all faces of face zones " Info<< " Removing all faces of face zones "
<< flatOutput(selectedZones_) << " ..." << endl; << flatOutput(zoneMatcher_) << " ..." << endl;
} }
combine(set, false); combine(set, false);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -84,8 +84,8 @@ Usage
Options for the conditional mandatory entries: Options for the conditional mandatory entries:
\verbatim \verbatim
Entry | Description | Type | Req'd | Dflt Entry | Description | Type | Req'd | Dflt
zones | Names of input faceZones | wordList | cond'l | - zones | Names of input faceZones | wordRes | cond'l | -
zone | Name of input faceZone | word | cond'l | - zone | Name of input faceZone | wordRe | cond'l | -
\verbatim \verbatim
Note Note
@ -126,11 +126,23 @@ class zoneToFace
static addToUsageTable usage_; static addToUsageTable usage_;
//- Matcher for zones //- Matcher for zones
wordRes selectedZones_; wordRes zoneMatcher_;
//- Explicitly specified zone ids
labelList zoneIDs_;
// Private Member Functions // 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; void combine(topoSet& set, const bool add) const;
@ -142,9 +154,15 @@ public:
// Constructors // 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); zoneToFace(const polyMesh& mesh, const wordRe& zoneName);
//- Construct from mesh and specified zone IDs
zoneToFace(const polyMesh& mesh, const labelUList& zoneIDs);
//- Construct from dictionary //- Construct from dictionary
zoneToFace(const polyMesh& mesh, const dictionary& dict); zoneToFace(const polyMesh& mesh, const dictionary& dict);
@ -158,6 +176,24 @@ public:
// Member Functions // 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 virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,

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-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -68,25 +68,37 @@ Foam::topoSetSource::addToUsageTable Foam::zoneToPoint::usage_
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * 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())) return; // Nothing to do
{
hasMatched = true;
const labelList& pointLabels = zone;
if (verbose_)
{
Info<< " Found matching zone " << zone.name()
<< " with " << pointLabels.size() << " points." << endl;
} }
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 // Only do active points
if (pointi >= 0 && pointi < mesh_.nPoints()) 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 WarningInFunction
<< "Cannot find any pointZone matching " << "Cannot find any pointZone matching "
<< flatOutput(selectedZones_) << nl << flatOutput(zoneMatcher_) << nl
<< "Valid names: " << flatOutput(mesh_.pointZones().names()) << "Valid names: " << flatOutput(mesh_.pointZones().names())
<< endl; << endl;
return; // Nothing to do
} }
combine(set, matched, add, verbose_);
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::zoneToPoint::zoneToPoint
(
const polyMesh& mesh,
const wordRes& zoneSelector
)
:
topoSetPointSource(mesh),
zoneMatcher_(zoneSelector)
{}
Foam::zoneToPoint::zoneToPoint Foam::zoneToPoint::zoneToPoint
( (
const polyMesh& mesh, const polyMesh& mesh,
@ -117,7 +160,19 @@ Foam::zoneToPoint::zoneToPoint
) )
: :
topoSetPointSource(mesh), 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), topoSetPointSource(mesh),
selectedZones_() zoneMatcher_()
{ {
// Look for 'zones' and 'zone', but accept 'name' as well // Look for 'zones' and 'zone', but accept 'name' as well
if (!dict.readIfPresent("zones", selectedZones_)) if (!dict.readIfPresent("zones", zoneMatcher_))
{ {
selectedZones_.resize(1); zoneMatcher_.resize(1);
selectedZones_.first() = zoneMatcher_.first() =
dict.getCompat<wordRe>("zone", {{"name", 1806}}); dict.getCompat<wordRe>("zone", {{"name", 1806}});
} }
} }
@ -146,13 +201,48 @@ Foam::zoneToPoint::zoneToPoint
Istream& is Istream& is
) )
: :
topoSetPointSource(mesh), zoneToPoint(mesh, wordRe(checkIs(is)))
selectedZones_(one{}, wordRe(checkIs(is)))
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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 void Foam::zoneToPoint::applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,
@ -161,20 +251,20 @@ void Foam::zoneToPoint::applyToSet
{ {
if (action == topoSetSource::ADD || action == topoSetSource::NEW) if (action == topoSetSource::ADD || action == topoSetSource::NEW)
{ {
if (verbose_) if (verbose_ && !zoneMatcher_.empty())
{ {
Info<< " Adding all points of point zones " Info<< " Adding all points of point zones "
<< flatOutput(selectedZones_) << " ..." << endl; << flatOutput(zoneMatcher_) << " ..." << endl;
} }
combine(set, true); combine(set, true);
} }
else if (action == topoSetSource::SUBTRACT) else if (action == topoSetSource::SUBTRACT)
{ {
if (verbose_) if (verbose_ && !zoneMatcher_.empty())
{ {
Info<< " Removing all points of point zones " Info<< " Removing all points of point zones "
<< flatOutput(selectedZones_) << " ..." << endl; << flatOutput(zoneMatcher_) << " ..." << endl;
} }
combine(set, false); combine(set, false);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -84,8 +84,8 @@ Usage
Options for the conditional mandatory entries: Options for the conditional mandatory entries:
\verbatim \verbatim
Entry | Description | Type | Req'd | Dflt Entry | Description | Type | Req'd | Dflt
zones | Names of input pointZones | wordList | cond'l | - zones | Names of input pointZones | wordRes | cond'l | -
zone | Name of input pointZone | word | cond'l | - zone | Name of input pointZone | wordRe | cond'l | -
\verbatim \verbatim
Note Note
@ -126,11 +126,22 @@ class zoneToPoint
static addToUsageTable usage_; static addToUsageTable usage_;
//- Matcher for zones //- Matcher for zones
wordRes selectedZones_; wordRes zoneMatcher_;
//- Explicitly specified zone ids
labelList zoneIDs_;
// Private Member Functions // 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; void combine(topoSet& set, const bool add) const;
@ -142,9 +153,15 @@ public:
// Constructors // 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); zoneToPoint(const polyMesh& mesh, const wordRe& zoneName);
//- Construct from mesh and specified zone IDs
zoneToPoint(const polyMesh& mesh, const labelUList& zoneIDs);
//- Construct from dictionary //- Construct from dictionary
zoneToPoint(const polyMesh& mesh, const dictionary& dict); zoneToPoint(const polyMesh& mesh, const dictionary& dict);
@ -158,6 +175,24 @@ public:
// Member Functions // 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 virtual void applyToSet
( (
const topoSetSource::setAction action, const topoSetSource::setAction action,