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:
Mark Olesen
2018-03-07 11:21:48 +01:00
parent 2768500d57
commit bac943e6fc
191 changed files with 4995 additions and 3151 deletions

View File

@ -257,7 +257,7 @@ void Foam::meshRefinement::calcCellCellRays
void Foam::meshRefinement::updateIntersections(const labelList& changedFaces)
{
// Stats on edges to test. Count proc faces only once.
PackedBoolList isMasterFace(syncTools::getMasterFaces(mesh_));
bitSet isMasterFace(syncTools::getMasterFaces(mesh_));
{
label nMasterFaces = 0;
@ -1254,7 +1254,7 @@ Foam::meshRefinement::meshRefinement
Foam::label Foam::meshRefinement::countHits() const
{
// Stats on edges to test. Count proc faces only once.
PackedBoolList isMasterFace(syncTools::getMasterFaces(mesh_));
bitSet isMasterFace(syncTools::getMasterFaces(mesh_));
label nHits = 0;
@ -1551,7 +1551,7 @@ Foam::labelList Foam::meshRefinement::intersectedPoints() const
const faceList& faces = mesh_.faces();
// Mark all points on faces that will become baffles
PackedBoolList isBoundaryPoint(mesh_.nPoints());
bitSet isBoundaryPoint(mesh_.nPoints());
label nBoundaryPoints = 0;
forAll(surfaceIndex_, facei)
@ -1800,7 +1800,7 @@ void Foam::meshRefinement::checkCoupledFaceZones(const polyMesh& mesh)
void Foam::meshRefinement::calculateEdgeWeights
(
const polyMesh& mesh,
const PackedBoolList& isMasterEdge,
const bitSet& isMasterEdge,
const labelList& meshPoints,
const edgeList& edges,
scalarField& edgeWeights,
@ -2292,7 +2292,7 @@ void Foam::meshRefinement::findRegions
labelList& cellRegion
)
{
PackedBoolList insideCell(mesh.nCells());
bitSet insideCell(mesh.nCells());
// Mark all cells reachable from locationsInMesh
labelList insideRegions(locationsInMesh.size());
@ -2702,7 +2702,7 @@ bool Foam::meshRefinement::write() const
}
Foam::PackedBoolList Foam::meshRefinement::getMasterPoints
Foam::bitSet Foam::meshRefinement::getMasterPoints
(
const polyMesh& mesh,
const labelList& meshPoints
@ -2726,7 +2726,7 @@ Foam::PackedBoolList Foam::meshRefinement::getMasterPoints
);
PackedBoolList isPatchMasterPoint(meshPoints.size());
bitSet isPatchMasterPoint(meshPoints.size());
forAll(meshPoints, pointi)
{
if (myPoints[pointi] == globalPoints.toGlobal(pointi))
@ -2739,7 +2739,7 @@ Foam::PackedBoolList Foam::meshRefinement::getMasterPoints
}
Foam::PackedBoolList Foam::meshRefinement::getMasterEdges
Foam::bitSet Foam::meshRefinement::getMasterEdges
(
const polyMesh& mesh,
const labelList& meshEdges
@ -2763,7 +2763,7 @@ Foam::PackedBoolList Foam::meshRefinement::getMasterEdges
);
PackedBoolList isMasterEdge(meshEdges.size());
bitSet isMasterEdge(meshEdges.size());
forAll(meshEdges, edgei)
{
if (myEdges[edgei] == globalEdges.toGlobal(edgei))
@ -2791,7 +2791,7 @@ const
}
{
PackedBoolList isMasterFace(syncTools::getMasterFaces(mesh_));
bitSet isMasterFace(syncTools::getMasterFaces(mesh_));
label nMasterFaces = 0;
forAll(isMasterFace, i)
{
@ -2801,7 +2801,7 @@ const
}
}
PackedBoolList isMeshMasterPoint(syncTools::getMasterPoints(mesh_));
bitSet isMeshMasterPoint(syncTools::getMasterPoints(mesh_));
label nMasterPoints = 0;
forAll(isMeshMasterPoint, i)
{