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

@ -170,7 +170,7 @@ bool Foam::sampledPlane::update()
<< nl << endl;
}
labelList selectedCells = mesh().cellZones().findMatching(zoneKey_).used();
labelList selectedCells(mesh().cellZones().findMatching(zoneKey_).toc());
bool fullMesh = returnReduce(selectedCells.empty(), andOp<bool>());

View File

@ -184,8 +184,10 @@ bool Foam::surfMeshPlaneSampler::update()
<< nl << endl;
}
labelList selectedCells = mesh().cellZones().findMatching(zoneKey_).used();
labelList selectedCells
(
mesh().cellZones().findMatching(zoneKey_).sortedToc()
);
bool fullMesh = returnReduce(selectedCells.empty(), andOp<bool>());
if (!bounds_.empty())

View File

@ -80,13 +80,13 @@ bool Foam::isoSurface::collocatedPatch(const polyPatch& pp)
}
Foam::PackedBoolList Foam::isoSurface::collocatedFaces
Foam::bitSet Foam::isoSurface::collocatedFaces
(
const coupledPolyPatch& pp
) const
{
// Initialise to false
PackedBoolList collocated(pp.size());
bitSet collocated(pp.size());
if (isA<processorPolyPatch>(pp))
{
@ -671,7 +671,7 @@ void Foam::isoSurface::calcSnappedCc
void Foam::isoSurface::calcSnappedPoint
(
const PackedBoolList& isBoundaryPoint,
const bitSet& isBoundaryPoint,
const labelList& boundaryRegion,
const volVectorField& meshC,
const volScalarField& cVals,
@ -1403,7 +1403,7 @@ Foam::isoSurface::isoSurface
meshC.boundaryField()[patchi]
);
PackedBoolList isCollocated
bitSet isCollocated
(
collocatedFaces(refCast<const coupledPolyPatch>(pp))
);
@ -1504,7 +1504,7 @@ Foam::isoSurface::isoSurface
if (regularise_)
{
// Determine if point is on boundary.
PackedBoolList isBoundaryPoint(mesh_.nPoints());
bitSet isBoundaryPoint(mesh_.nPoints());
forAll(patches, patchi)
{
@ -1519,7 +1519,7 @@ Foam::isoSurface::isoSurface
patches[patchi]
);
PackedBoolList isCollocated(collocatedFaces(cpp));
bitSet isCollocated(collocatedFaces(cpp));
forAll(isCollocated, i)
{

View File

@ -64,7 +64,7 @@ SourceFiles
#ifndef isoSurface_H
#define isoSurface_H
#include "PackedBoolList.H"
#include "bitSet.H"
#include "volFields.H"
#include "slicedVolFields.H"
#include "MeshedSurface.H"
@ -165,7 +165,7 @@ class isoSurface
static bool collocatedPatch(const polyPatch&);
//- Per face whether is collocated
PackedBoolList collocatedFaces(const coupledPolyPatch&) const;
bitSet collocatedFaces(const coupledPolyPatch&) const;
//- Synchonise points on all non-separated coupled patches
void syncUnseparatedPoints
@ -231,7 +231,7 @@ class isoSurface
// point.
void calcSnappedPoint
(
const PackedBoolList& isBoundaryPoint,
const bitSet& isBoundaryPoint,
const labelList& boundaryRegion,
const volVectorField& meshC,
const volScalarField& cVals,

View File

@ -81,7 +81,7 @@ bool Foam::isoSurfaceCell::isTriCut
Foam::isoSurfaceCell::cellCutType Foam::isoSurfaceCell::calcCutType
(
const PackedBoolList& isTet,
const bitSet& isTet,
const scalarField& cellValues,
const scalarField& pointValues,
const label celli
@ -192,7 +192,7 @@ Foam::isoSurfaceCell::cellCutType Foam::isoSurfaceCell::calcCutType
void Foam::isoSurfaceCell::calcCutTypes
(
const PackedBoolList& isTet,
const bitSet& isTet,
const scalarField& cVals,
const scalarField& pVals
)
@ -360,7 +360,7 @@ Foam::pointIndexHit Foam::isoSurfaceCell::collapseSurface
void Foam::isoSurfaceCell::calcSnappedCc
(
const PackedBoolList& isTet,
const bitSet& isTet,
const scalarField& cVals,
const scalarField& pVals,
@ -685,7 +685,7 @@ void Foam::isoSurfaceCell::genPointTris
void Foam::isoSurfaceCell::calcSnappedPoint
(
const PackedBoolList& isTet,
const bitSet& isTet,
const scalarField& cVals,
const scalarField& pVals,
@ -695,7 +695,7 @@ void Foam::isoSurfaceCell::calcSnappedPoint
{
// Determine if point is on boundary. Points on boundaries are never
// snapped. Coupled boundaries are handled explicitly so not marked here.
PackedBoolList isBoundaryPoint(mesh_.nPoints());
bitSet isBoundaryPoint(mesh_.nPoints());
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
forAll(patches, patchi)
{
@ -1319,7 +1319,7 @@ Foam::isoSurfaceCell::isoSurfaceCell
}
// Determine if cell is tet
PackedBoolList isTet(mesh_.nCells());
bitSet isTet(mesh_.nCells());
{
tetMatcher tet;

View File

@ -47,7 +47,7 @@ SourceFiles
#include "labelPair.H"
#include "pointIndexHit.H"
#include "PackedBoolList.H"
#include "bitSet.H"
#include "boundBox.H"
#include "MeshedSurface.H"
#include "MeshedSurfacesFwd.H"
@ -146,7 +146,7 @@ class isoSurfaceCell
//- Determine whether cell is cut
cellCutType calcCutType
(
const PackedBoolList&,
const bitSet&,
const scalarField& cellValues,
const scalarField& pointValues,
const label
@ -154,7 +154,7 @@ class isoSurfaceCell
void calcCutTypes
(
const PackedBoolList&,
const bitSet&,
const scalarField& cellValues,
const scalarField& pointValues
);
@ -182,7 +182,7 @@ class isoSurfaceCell
// point.
void calcSnappedCc
(
const PackedBoolList& isTet,
const bitSet& isTet,
const scalarField& cVals,
const scalarField& pVals,
DynamicList<point>& triPoints,
@ -214,7 +214,7 @@ class isoSurfaceCell
// point.
void calcSnappedPoint
(
const PackedBoolList& isTet,
const bitSet& isTet,
const scalarField& cVals,
const scalarField& pVals,
DynamicList<point>& triPoints,

View File

@ -132,7 +132,7 @@ Foam::isoSurface::adaptPatchFields
w*pfld.patchInternalField()
+ (1.0-w)*pfld.patchNeighbourField();
PackedBoolList isCollocated
bitSet isCollocated
(
collocatedFaces(refCast<const processorPolyPatch>(pp))
);
@ -636,7 +636,7 @@ void Foam::isoSurface::generateTriPoints
const processorPolyPatch& cpp =
refCast<const processorPolyPatch>(pp);
PackedBoolList isCollocated(collocatedFaces(cpp));
bitSet isCollocated(collocatedFaces(cpp));
forAll(isCollocated, i)
{