mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: new special purpose bitSet-based topoSet (#1060)
This commit is contained in:
@ -134,6 +134,7 @@ searchableSurfaces/subTriSurfaceMesh/subTriSurfaceMesh.C
|
||||
searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C
|
||||
|
||||
topoSets = sets/topoSets
|
||||
$(topoSets)/cellBitSet.C
|
||||
$(topoSets)/cellSet.C
|
||||
$(topoSets)/topoSet.C
|
||||
$(topoSets)/faceSet.C
|
||||
|
||||
179
src/meshTools/sets/topoSets/cellBitSet.C
Normal file
179
src/meshTools/sets/topoSets/cellBitSet.C
Normal file
@ -0,0 +1,179 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "cellBitSet.H"
|
||||
#include "polyMesh.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(cellBitSet, 0);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::cellBitSet::cellBitSet(const polyMesh& mesh)
|
||||
:
|
||||
cellBitSet(mesh, false)
|
||||
{}
|
||||
|
||||
|
||||
Foam::cellBitSet::cellBitSet(const polyMesh& mesh, const bool val)
|
||||
:
|
||||
topoSet
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"cellBitSet",
|
||||
mesh.time().constant(),
|
||||
mesh,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
),
|
||||
0 // zero-sized (unallocated) labelHashSet
|
||||
),
|
||||
selected_(mesh.nCells(), val)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::cellBitSet::found(const label id) const
|
||||
{
|
||||
return selected_.test(id);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::cellBitSet::set(const label id)
|
||||
{
|
||||
return selected_.set(id);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::cellBitSet::unset(const label id)
|
||||
{
|
||||
return selected_.unset(id);
|
||||
}
|
||||
|
||||
|
||||
void Foam::cellBitSet::set(const labelUList& labels)
|
||||
{
|
||||
selected_.set(labels);
|
||||
}
|
||||
|
||||
|
||||
void Foam::cellBitSet::unset(const labelUList& labels)
|
||||
{
|
||||
selected_.unset(labels);
|
||||
}
|
||||
|
||||
|
||||
void Foam::cellBitSet::invert(const label maxLen)
|
||||
{
|
||||
selected_.resize(maxLen);
|
||||
selected_.flip();
|
||||
}
|
||||
|
||||
|
||||
void Foam::cellBitSet::subset(const topoSet& set)
|
||||
{
|
||||
// Only retain entries found in both sets
|
||||
if (isA<cellBitSet>(set))
|
||||
{
|
||||
selected_ &= refCast<const cellBitSet>(set).selected_;
|
||||
}
|
||||
else if (set.empty())
|
||||
{
|
||||
selected_.reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const label id : selected_)
|
||||
{
|
||||
if (!set.found(id))
|
||||
{
|
||||
selected_.unset(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::cellBitSet::addSet(const topoSet& set)
|
||||
{
|
||||
// Add entries to the set
|
||||
if (isA<cellBitSet>(set))
|
||||
{
|
||||
selected_ |= refCast<const cellBitSet>(set).selected_;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const label id : set)
|
||||
{
|
||||
selected_.set(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::cellBitSet::subtractSet(const topoSet& set)
|
||||
{
|
||||
// Subtract entries from the set
|
||||
if (isA<cellBitSet>(set))
|
||||
{
|
||||
selected_ -= refCast<const cellBitSet>(set).selected_;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const label id : set)
|
||||
{
|
||||
selected_.unset(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::cellBitSet::maxSize(const polyMesh& mesh) const
|
||||
{
|
||||
return mesh.nCells();
|
||||
}
|
||||
|
||||
|
||||
void Foam::cellBitSet::writeDebug
|
||||
(
|
||||
Ostream& os,
|
||||
const primitiveMesh& mesh,
|
||||
const label maxLen
|
||||
) const
|
||||
{
|
||||
topoSet::writeDebug(os, mesh.cellCentres(), maxLen);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
160
src/meshTools/sets/topoSets/cellBitSet.H
Normal file
160
src/meshTools/sets/topoSets/cellBitSet.H
Normal file
@ -0,0 +1,160 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::cellBitSet
|
||||
|
||||
Description
|
||||
A special purpose topoSet with the cell labels stored as a bitSet.
|
||||
It does not correspond to a cellSet either (no associated IOobject).
|
||||
|
||||
SourceFiles
|
||||
cellBitSet.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef cellBitSet_H
|
||||
#define cellBitSet_H
|
||||
|
||||
#include "topoSet.H"
|
||||
#include "bitSet.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class cellBitSet Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class cellBitSet
|
||||
:
|
||||
public topoSet
|
||||
{
|
||||
// Private data
|
||||
|
||||
bitSet selected_;
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("cellBitSet");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct with nCells elements, all elements unset
|
||||
explicit cellBitSet(const polyMesh& mesh);
|
||||
|
||||
//- Construct with nCells elements, using initial val
|
||||
cellBitSet(const polyMesh& mesh, const bool val);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~cellBitSet() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return the bitSet
|
||||
const bitSet& addressing() const
|
||||
{
|
||||
return selected_;
|
||||
}
|
||||
|
||||
//- Access the bitSet
|
||||
bitSet& addressing()
|
||||
{
|
||||
return selected_;
|
||||
}
|
||||
|
||||
//- Set values to false, leaving the size untouched
|
||||
void reset()
|
||||
{
|
||||
selected_.reset();
|
||||
}
|
||||
|
||||
//- Has the given index?
|
||||
virtual bool found(const label id) const;
|
||||
|
||||
//- Set an index
|
||||
virtual bool set(const label id);
|
||||
|
||||
//- Unset an index
|
||||
virtual bool unset(const label id);
|
||||
|
||||
//- Set multiple indices
|
||||
virtual void set(const labelUList& labels);
|
||||
|
||||
//- Unset multiple indices
|
||||
virtual void unset(const labelUList& labels);
|
||||
|
||||
//- Invert contents.
|
||||
// Insert all members [0,maxLen) which were not in set.
|
||||
virtual void invert(const label maxLen);
|
||||
|
||||
//- Subset contents. Only elements present in both sets remain.
|
||||
virtual void subset(const topoSet& set);
|
||||
|
||||
//- Add elements present in set.
|
||||
virtual void addSet(const topoSet& set);
|
||||
|
||||
//- Subtract elements present in set.
|
||||
virtual void subtractSet(const topoSet& set);
|
||||
|
||||
//- Sync cellBitSet across coupled patches.
|
||||
virtual void sync(const polyMesh& mesh)
|
||||
{}
|
||||
|
||||
//- Return max index+1.
|
||||
virtual label maxSize(const polyMesh& mesh) const;
|
||||
|
||||
//- Update any stored data for new labels.
|
||||
virtual void updateMesh(const mapPolyMesh& morphMap)
|
||||
{}
|
||||
|
||||
//- Update any stored data for mesh redistribution.
|
||||
virtual void distribute(const mapDistributePolyMesh& map)
|
||||
{}
|
||||
|
||||
//- Write maxLen items with label and coordinates.
|
||||
virtual void writeDebug
|
||||
(
|
||||
Ostream& os,
|
||||
const primitiveMesh& mesh,
|
||||
const label maxLen
|
||||
) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -491,6 +491,12 @@ Foam::topoSet::topoSet(const IOobject& io, labelHashSet&& labels)
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::topoSet::found(const label id) const
|
||||
{
|
||||
return static_cast<const labelHashSet&>(*this).found(id);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::topoSet::set(const label id)
|
||||
{
|
||||
return static_cast<labelHashSet&>(*this).set(id);
|
||||
|
||||
@ -313,6 +313,9 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Has the given index?
|
||||
virtual bool found(const label id) const;
|
||||
|
||||
//- Set an index
|
||||
virtual bool set(const label id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user