mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: new bitSet class and improved PackedList class (closes #751)
- The bitSet class replaces the old PackedBoolList class.
The redesign provides better block-wise access and reduced method
calls. This helps both in cases where the bitSet may be relatively
sparse, and in cases where advantage of contiguous operations can be
made. This makes it easier to work with a bitSet as top-level object.
In addition to the previously available count() method to determine
if a bitSet is being used, now have simpler queries:
- all() - true if all bits in the addressable range are empty
- any() - true if any bits are set at all.
- none() - true if no bits are set.
These are faster than count() and allow early termination.
The new test() method tests the value of a single bit position and
returns a bool without any ambiguity caused by the return type
(like the get() method), nor the const/non-const access (like
operator[] has). The name corresponds to what std::bitset uses.
The new find_first(), find_last(), find_next() methods provide a faster
means of searching for bits that are set.
This can be especially useful when using a bitSet to control an
conditional:
OLD (with macro):
forAll(selected, celli)
{
if (selected[celli])
{
sumVol += mesh_.cellVolumes()[celli];
}
}
NEW (with const_iterator):
for (const label celli : selected)
{
sumVol += mesh_.cellVolumes()[celli];
}
or manually
for
(
label celli = selected.find_first();
celli != -1;
celli = selected.find_next()
)
{
sumVol += mesh_.cellVolumes()[celli];
}
- When marking up contiguous parts of a bitset, an interval can be
represented more efficiently as a labelRange of start/size.
For example,
OLD:
if (isA<processorPolyPatch>(pp))
{
forAll(pp, i)
{
ignoreFaces.set(i);
}
}
NEW:
if (isA<processorPolyPatch>(pp))
{
ignoreFaces.set(pp.range());
}
This commit is contained in:
@ -306,7 +306,7 @@ void Foam::mergeAndWrite
|
||||
|
||||
|
||||
// Determine faces on outside of cellSet
|
||||
PackedBoolList isInSet(mesh.nCells());
|
||||
bitSet isInSet(mesh.nCells());
|
||||
forAllConstIter(cellSet, set, iter)
|
||||
{
|
||||
isInSet.set(iter.key());
|
||||
|
||||
@ -660,7 +660,7 @@ Foam::label Foam::checkTopology
|
||||
|
||||
const cellList& cells = mesh.cells();
|
||||
const faceList& faces = mesh.faces();
|
||||
PackedBoolList isZonePoint(mesh.nPoints());
|
||||
bitSet isZonePoint(mesh.nPoints());
|
||||
|
||||
for (const cellZone& cZone : cellZones)
|
||||
{
|
||||
|
||||
@ -192,7 +192,7 @@ void modifyOrAddFace
|
||||
const label zoneID,
|
||||
const bool zoneFlip,
|
||||
|
||||
PackedBoolList& modifiedFace
|
||||
bitSet& modifiedFace
|
||||
)
|
||||
{
|
||||
if (modifiedFace.set(facei))
|
||||
@ -247,7 +247,7 @@ void createFaces
|
||||
const labelList& newMasterPatches,
|
||||
const labelList& newSlavePatches,
|
||||
polyTopoChange& meshMod,
|
||||
PackedBoolList& modifiedFace,
|
||||
bitSet& modifiedFace,
|
||||
label& nModified
|
||||
)
|
||||
{
|
||||
@ -538,15 +538,13 @@ int main(int argc, char *argv[])
|
||||
if (mesh.faceZones().findZoneID(name) == -1)
|
||||
{
|
||||
mesh.faceZones().clearAddressing();
|
||||
label sz = mesh.faceZones().size();
|
||||
const label zoneID = mesh.faceZones().size();
|
||||
|
||||
labelList addr(0);
|
||||
boolList flip(0);
|
||||
mesh.faceZones().setSize(sz+1);
|
||||
mesh.faceZones().setSize(zoneID+1);
|
||||
mesh.faceZones().set
|
||||
(
|
||||
sz,
|
||||
new faceZone(name, addr, flip, sz, mesh.faceZones())
|
||||
zoneID,
|
||||
new faceZone(name, labelList(), false, zoneID, mesh.faceZones())
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -604,7 +602,14 @@ int main(int argc, char *argv[])
|
||||
mesh.faceZones().set
|
||||
(
|
||||
zoneID,
|
||||
new faceZone(name, addr, flip, zoneID, mesh.faceZones())
|
||||
new faceZone
|
||||
(
|
||||
name,
|
||||
std::move(addr),
|
||||
std::move(flip),
|
||||
zoneID,
|
||||
mesh.faceZones()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -751,7 +756,7 @@ int main(int argc, char *argv[])
|
||||
// side come first and faces from the other side next.
|
||||
|
||||
// Whether first use of face (modify) or consecutive (add)
|
||||
PackedBoolList modifiedFace(mesh.nFaces());
|
||||
bitSet modifiedFace(mesh.nFaces());
|
||||
label nModified = 0;
|
||||
|
||||
forAll(selectors, selectorI)
|
||||
|
||||
@ -483,7 +483,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
candidates.setCapacity(sz);
|
||||
|
||||
PackedBoolList isCandidate(mesh.nPoints());
|
||||
bitSet isCandidate(mesh.nPoints());
|
||||
forAll(splitPatchIDs, i)
|
||||
{
|
||||
const labelList& mp = patches[splitPatchIDs[i]].meshPoints();
|
||||
|
||||
@ -87,7 +87,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
|
||||
|
||||
const PackedBoolList isMasterFace(syncTools::getMasterFaces(mesh));
|
||||
const bitSet isMasterFace(syncTools::getMasterFaces(mesh));
|
||||
|
||||
|
||||
// Data on all edges and faces
|
||||
|
||||
@ -146,7 +146,7 @@ Foam::label Foam::meshDualiser::findDualCell
|
||||
|
||||
void Foam::meshDualiser::generateDualBoundaryEdges
|
||||
(
|
||||
const PackedBoolList& isBoundaryEdge,
|
||||
const bitSet& isBoundaryEdge,
|
||||
const label pointi,
|
||||
polyTopoChange& meshMod
|
||||
)
|
||||
@ -374,7 +374,7 @@ Foam::label Foam::meshDualiser::addBoundaryFace
|
||||
void Foam::meshDualiser::createFacesAroundEdge
|
||||
(
|
||||
const bool splitFace,
|
||||
const PackedBoolList& isBoundaryEdge,
|
||||
const bitSet& isBoundaryEdge,
|
||||
const label edgeI,
|
||||
const label startFacei,
|
||||
polyTopoChange& meshMod,
|
||||
@ -886,7 +886,7 @@ void Foam::meshDualiser::setRefinement
|
||||
// Mark boundary edges and points.
|
||||
// (Note: in 1.4.2 we can use the built-in mesh point ordering
|
||||
// facility instead)
|
||||
PackedBoolList isBoundaryEdge(mesh_.nEdges());
|
||||
bitSet isBoundaryEdge(mesh_.nEdges());
|
||||
for (label facei = mesh_.nInternalFaces(); facei < mesh_.nFaces(); facei++)
|
||||
{
|
||||
const labelList& fEdges = mesh_.faceEdges()[facei];
|
||||
|
||||
@ -48,7 +48,7 @@ SourceFiles
|
||||
#define meshDualiser_H
|
||||
|
||||
#include "DynamicList.H"
|
||||
#include "PackedBoolList.H"
|
||||
#include "bitSet.H"
|
||||
#include "boolList.H"
|
||||
#include "typeInfo.H"
|
||||
|
||||
@ -100,7 +100,7 @@ class meshDualiser
|
||||
// emanating from (boundary & feature) point
|
||||
void generateDualBoundaryEdges
|
||||
(
|
||||
const PackedBoolList& isBoundaryEdge,
|
||||
const bitSet& isBoundaryEdge,
|
||||
const label pointi,
|
||||
polyTopoChange& meshMod
|
||||
);
|
||||
@ -143,7 +143,7 @@ class meshDualiser
|
||||
void createFacesAroundEdge
|
||||
(
|
||||
const bool splitFace,
|
||||
const PackedBoolList& isBoundaryEdge,
|
||||
const bitSet& isBoundaryEdge,
|
||||
const label edgeI,
|
||||
const label startFacei,
|
||||
polyTopoChange& meshMod,
|
||||
|
||||
@ -67,7 +67,7 @@ Note
|
||||
#include "unitConversion.H"
|
||||
#include "polyTopoChange.H"
|
||||
#include "mapPolyMesh.H"
|
||||
#include "PackedBoolList.H"
|
||||
#include "bitSet.H"
|
||||
#include "meshTools.H"
|
||||
#include "OFstream.H"
|
||||
#include "meshDualiser.H"
|
||||
@ -87,7 +87,7 @@ using namespace Foam;
|
||||
void simpleMarkFeatures
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const PackedBoolList& isBoundaryEdge,
|
||||
const bitSet& isBoundaryEdge,
|
||||
const scalar featureAngle,
|
||||
const bool concaveMultiCells,
|
||||
const bool doNotPreserveFaceZones,
|
||||
@ -390,7 +390,7 @@ int main(int argc, char *argv[])
|
||||
// Mark boundary edges and points.
|
||||
// (Note: in 1.4.2 we can use the built-in mesh point ordering
|
||||
// facility instead)
|
||||
PackedBoolList isBoundaryEdge(mesh.nEdges());
|
||||
bitSet isBoundaryEdge(mesh.nEdges());
|
||||
for (label facei = mesh.nInternalFaces(); facei < mesh.nFaces(); facei++)
|
||||
{
|
||||
const labelList& fEdges = mesh.faceEdges()[facei];
|
||||
|
||||
@ -79,7 +79,7 @@ void printEdgeStats(const polyMesh& mesh)
|
||||
scalar minOther = GREAT;
|
||||
scalar maxOther = -GREAT;
|
||||
|
||||
PackedBoolList isMasterEdge(syncTools::getMasterEdges(mesh));
|
||||
bitSet isMasterEdge(syncTools::getMasterEdges(mesh));
|
||||
|
||||
const edgeList& edges = mesh.edges();
|
||||
|
||||
|
||||
@ -303,7 +303,7 @@ void subsetTopoSets
|
||||
Info<< "Subsetting " << set.type() << " " << set.name() << endl;
|
||||
|
||||
// Map the data
|
||||
PackedBoolList isSet(set.maxSize(mesh));
|
||||
bitSet isSet(set.maxSize(mesh));
|
||||
forAllConstIters(set, iter)
|
||||
{
|
||||
isSet.set(iter.key());
|
||||
|
||||
Reference in New Issue
Block a user