ENH: fvMeshSubsetProxy resetZones, noexcept on some methods

This commit is contained in:
Mark Olesen
2021-06-22 12:38:53 +02:00
parent 98aa92a07f
commit f5e0f69bae
4 changed files with 67 additions and 45 deletions

View File

@ -73,7 +73,7 @@ namespace Foam
class fvMeshSubset class fvMeshSubset
{ {
// Private data // Private Data
//- Mesh to subset from //- Mesh to subset from
const fvMesh& baseMesh_; const fvMesh& baseMesh_;
@ -214,13 +214,13 @@ public:
// Access // Access
//- Original mesh //- Original mesh
inline const fvMesh& baseMesh() const; inline const fvMesh& baseMesh() const noexcept;
//- Return baseMesh or subMesh, depending on the current state. //- Return baseMesh or subMesh, depending on the current state.
inline const fvMesh& mesh() const; inline const fvMesh& mesh() const noexcept;
//- Have subMesh? //- Have subMesh?
inline bool hasSubMesh() const; inline bool hasSubMesh() const noexcept;
//- Return reference to subset mesh //- Return reference to subset mesh
inline const fvMesh& subMesh() const; inline const fvMesh& subMesh() const;
@ -491,7 +491,6 @@ public:
syncCouples syncCouples
); );
} }
}; };

View File

@ -27,19 +27,19 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::fvMesh& Foam::fvMeshSubset::baseMesh() const inline const Foam::fvMesh& Foam::fvMeshSubset::baseMesh() const noexcept
{ {
return baseMesh_; return baseMesh_;
} }
inline const Foam::fvMesh& Foam::fvMeshSubset::mesh() const inline const Foam::fvMesh& Foam::fvMeshSubset::mesh() const noexcept
{ {
return fvMeshSubsetPtr_ ? *fvMeshSubsetPtr_ : baseMesh_; return fvMeshSubsetPtr_ ? *fvMeshSubsetPtr_ : baseMesh_;
} }
inline bool Foam::fvMeshSubset::hasSubMesh() const inline bool Foam::fvMeshSubset::hasSubMesh() const noexcept
{ {
return bool(fvMeshSubsetPtr_); return bool(fvMeshSubsetPtr_);
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2019 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,6 +30,18 @@ License
#include "cellZone.H" #include "cellZone.H"
#include "Time.H" #include "Time.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fvMeshSubsetProxy::clearOut()
{
subsetter_.clear();
type_ = subsetType::NONE;
name_.clear();
names_.clear();
selectedCells_.clearStorage();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fvMeshSubsetProxy::fvMeshSubsetProxy(fvMesh& baseMesh) Foam::fvMeshSubsetProxy::fvMeshSubsetProxy(fvMesh& baseMesh)
@ -37,16 +49,11 @@ Foam::fvMeshSubsetProxy::fvMeshSubsetProxy(fvMesh& baseMesh)
baseMesh_(baseMesh), baseMesh_(baseMesh),
subsetter_(baseMesh), subsetter_(baseMesh),
exposedPatchId_(-1), exposedPatchId_(-1),
type_(NONE), type_(subsetType::NONE),
name_(), name_(),
names_(), names_(),
selectedCells_() selectedCells_()
{ {}
if (useSubMesh())
{
correct();
}
}
Foam::fvMeshSubsetProxy::fvMeshSubsetProxy Foam::fvMeshSubsetProxy::fvMeshSubsetProxy
@ -60,26 +67,23 @@ Foam::fvMeshSubsetProxy::fvMeshSubsetProxy
baseMesh_(baseMesh), baseMesh_(baseMesh),
subsetter_(baseMesh), subsetter_(baseMesh),
exposedPatchId_(exposedPatchId), exposedPatchId_(exposedPatchId),
type_(selectionName.empty() ? NONE : type), type_(selectionName.empty() ? subsetType::NONE : type),
name_(), name_(),
names_(), names_(),
selectedCells_() selectedCells_()
{ {
if (type_ == ZONES) if (type_ == subsetType::ZONES)
{ {
// Populate wordRes for ZONES // Populate wordRes for ZONES
names_.resize(1); names_.resize(1);
names_.first() = selectionName; names_.first() = selectionName;
} }
else if (type_ != NONE) else if (type_ == subsetType::SET || type_ == subsetType::ZONE)
{ {
name_ = selectionName; name_ = selectionName;
} }
if (useSubMesh())
{
correct(); correct();
}
} }
@ -93,15 +97,12 @@ Foam::fvMeshSubsetProxy::fvMeshSubsetProxy
baseMesh_(baseMesh), baseMesh_(baseMesh),
subsetter_(baseMesh), subsetter_(baseMesh),
exposedPatchId_(exposedPatchId), exposedPatchId_(exposedPatchId),
type_(ZONES), type_(subsetType::ZONES),
name_(), name_(),
names_(zoneNames), names_(zoneNames),
selectedCells_() selectedCells_()
{ {
if (useSubMesh())
{
correct(); correct();
}
} }
@ -115,23 +116,33 @@ Foam::fvMeshSubsetProxy::fvMeshSubsetProxy
baseMesh_(baseMesh), baseMesh_(baseMesh),
subsetter_(baseMesh), subsetter_(baseMesh),
exposedPatchId_(exposedPatchId), exposedPatchId_(exposedPatchId),
type_(ZONES), type_(subsetType::ZONES),
name_(), name_(),
names_(std::move(zoneNames)), names_(std::move(zoneNames)),
selectedCells_() selectedCells_()
{ {
if (useSubMesh())
{
correct(); correct();
}
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fvMeshSubsetProxy::resetZones(const wordRes& zoneNames)
{
fvMeshSubsetProxy::clearOut();
if (!zoneNames.empty())
{
type_ = subsetType::ZONES;
names_ = zoneNames;
correct();
}
}
bool Foam::fvMeshSubsetProxy::correct(bool verbose) bool Foam::fvMeshSubsetProxy::correct(bool verbose)
{ {
if (type_ == NONE) if (type_ == subsetType::NONE)
{ {
subsetter_.clear(); subsetter_.clear();
selectedCells_.clearStorage(); selectedCells_.clearStorage();
@ -142,7 +153,7 @@ bool Foam::fvMeshSubsetProxy::correct(bool verbose)
bitSet selectedCells; bitSet selectedCells;
if (type_ == SET) if (type_ == subsetType::SET)
{ {
if (verbose) if (verbose)
{ {
@ -157,7 +168,7 @@ bool Foam::fvMeshSubsetProxy::correct(bool verbose)
selectedCells.set(idx); selectedCells.set(idx);
} }
} }
else if (type_ == ZONE) else if (type_ == subsetType::ZONE)
{ {
if (verbose) if (verbose)
{ {
@ -167,7 +178,7 @@ bool Foam::fvMeshSubsetProxy::correct(bool verbose)
selectedCells.resize(nCells); selectedCells.resize(nCells);
selectedCells.set(baseMesh_.cellZones()[name_]); selectedCells.set(baseMesh_.cellZones()[name_]);
} }
else if (type_ == ZONES) else if (type_ == subsetType::ZONES)
{ {
if (verbose) if (verbose)
{ {

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.
@ -97,6 +97,9 @@ private:
// Private Member Functions // Private Member Functions
//- Clear, set to NONE
void clearOut();
//- No copy construct //- No copy construct
fvMeshSubsetProxy(const fvMeshSubsetProxy&) = delete; fvMeshSubsetProxy(const fvMeshSubsetProxy&) = delete;
@ -142,21 +145,27 @@ public:
// Access // Access
//- The entire base mesh //- The entire base mesh
inline const fvMesh& baseMesh() const const fvMesh& baseMesh() const noexcept
{ {
return baseMesh_; return baseMesh_;
} }
//- The mesh subsetter //- The mesh subsetter
inline const fvMeshSubset& subsetter() const const fvMeshSubset& subsetter() const noexcept
{ {
return subsetter_; return subsetter_;
} }
//- Check if a sub-mesh is being used //- The mesh subsetter
inline bool useSubMesh() const fvMeshSubset& subsetter() noexcept
{ {
return type_ != NONE; return subsetter_;
}
//- True if sub-mesh should be used
bool useSubMesh() const noexcept
{
return type_ != subsetType::NONE;
} }
//- Access either base-mesh or sub-mesh //- Access either base-mesh or sub-mesh
@ -171,13 +180,13 @@ public:
} }
//- The associated (set or zone) name if any. //- The associated (set or zone) name if any.
inline const word& name() const const word& name() const noexcept
{ {
return name_; return name_;
} }
//- The current cell selection, when subsetting is active //- The current cell selection, when subsetting is active
inline const bitSet& selectedCells() const const bitSet& selectedCells() const noexcept
{ {
return selectedCells_; return selectedCells_;
} }
@ -185,6 +194,9 @@ public:
// Edit // Edit
//- Define the zones selection, subset the mesh accordingly
void resetZones(const wordRes& zoneNames);
//- Update of mesh subset. //- Update of mesh subset.
// Return true if the subset changed from previous call. // Return true if the subset changed from previous call.
bool correct(bool verbose = false); bool correct(bool verbose = false);