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:
@ -32,7 +32,7 @@ Description
|
||||
|
||||
#include "domainDecomposition.H"
|
||||
#include "IOstreams.H"
|
||||
#include "boolList.H"
|
||||
#include "bitSet.H"
|
||||
#include "cyclicPolyPatch.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
@ -434,7 +434,6 @@ void Foam::domainDecomposition::decomposeMesh()
|
||||
// }
|
||||
|
||||
|
||||
|
||||
Info<< "\nDistributing points to processors" << endl;
|
||||
// For every processor, loop through the list of faces for the processor.
|
||||
// For every face, loop through the list of points and mark the point as
|
||||
@ -443,42 +442,19 @@ void Foam::domainDecomposition::decomposeMesh()
|
||||
|
||||
forAll(procPointAddressing_, proci)
|
||||
{
|
||||
boolList pointLabels(nPoints(), false);
|
||||
bitSet pointsInUse(nPoints(), false);
|
||||
|
||||
// Get reference to list of used faces
|
||||
const labelList& procFaceLabels = procFaceAddressing_[proci];
|
||||
|
||||
forAll(procFaceLabels, facei)
|
||||
// For each of the faces used
|
||||
for (const label facei : procFaceAddressing_[proci])
|
||||
{
|
||||
// Because of the turning index, some labels may be negative
|
||||
const labelList& facePoints = fcs[mag(procFaceLabels[facei]) - 1];
|
||||
// Because of the turning index, some face labels may be -ve
|
||||
const labelList& facePoints = fcs[mag(facei) - 1];
|
||||
|
||||
forAll(facePoints, pointi)
|
||||
{
|
||||
// Mark the point as used
|
||||
pointLabels[facePoints[pointi]] = true;
|
||||
}
|
||||
// Mark the face points as being used
|
||||
pointsInUse.setMany(facePoints);
|
||||
}
|
||||
|
||||
// Collect the used points
|
||||
labelList& procPointLabels = procPointAddressing_[proci];
|
||||
|
||||
procPointLabels.setSize(pointLabels.size());
|
||||
|
||||
label nUsedPoints = 0;
|
||||
|
||||
forAll(pointLabels, pointi)
|
||||
{
|
||||
if (pointLabels[pointi])
|
||||
{
|
||||
procPointLabels[nUsedPoints] = pointi;
|
||||
|
||||
nUsedPoints++;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the size of used points
|
||||
procPointLabels.setSize(nUsedPoints);
|
||||
procPointAddressing_[proci] = pointsInUse.sortedToc();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user