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

View File

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

View File

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

View File

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