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

@ -41,7 +41,7 @@ Usage
#include "triSurfaceMesh.H"
#include "indexedOctree.H"
#include "treeBoundBox.H"
#include "PackedBoolList.H"
#include "bitSet.H"
#include "unitConversion.H"
#include "searchableSurfaces.H"
#include "IOdictionary.H"
@ -329,7 +329,7 @@ int main(int argc, char *argv[])
List<DynamicList<labelledTri>> newFaces(surfs.size());
List<DynamicList<point>> newPoints(surfs.size());
List<PackedBoolList> visitedFace(surfs.size());
List<bitSet> visitedFace(surfs.size());
PtrList<triSurfaceMesh> newSurfaces(surfs.size());
forAll(surfs, surfI)
@ -370,7 +370,7 @@ int main(int argc, char *argv[])
newFaces[surfI] = newSurf.localFaces();
newPoints[surfI] = newSurf.localPoints();
visitedFace[surfI] = PackedBoolList(newSurf.size(), false);
visitedFace[surfI] = bitSet(newSurf.size(), false);
}
forAll(newSurfaces, surfI)

View File

@ -54,7 +54,7 @@ Usage
#include "triSurfaceFields.H"
#include "triSurfaceMesh.H"
#include "triSurfaceGeoMesh.H"
#include "PackedBoolList.H"
#include "bitSet.H"
#include "OBJstream.H"
#include "surfaceFeatures.H"
@ -131,7 +131,7 @@ tmp<vectorField> calcVertexNormals(const triSurface& surf)
tmp<vectorField> calcPointNormals
(
const triSurface& s,
const PackedBoolList& isFeaturePoint,
const bitSet& isFeaturePoint,
const List<surfaceFeatures::edgeStatus>& edgeStat
)
{
@ -215,7 +215,7 @@ tmp<vectorField> calcPointNormals
void detectSelfIntersections
(
const triSurfaceMesh& s,
PackedBoolList& isEdgeIntersecting
bitSet& isEdgeIntersecting
)
{
const edgeList& edges = s.edges();
@ -258,9 +258,9 @@ label detectIntersectionPoints
const vectorField& displacement,
const bool checkSelfIntersect,
const PackedBoolList& initialIsEdgeIntersecting,
const bitSet& initialIsEdgeIntersecting,
PackedBoolList& isPointOnHitEdge,
bitSet& isPointOnHitEdge,
scalarField& scale
)
{
@ -307,7 +307,7 @@ label detectIntersectionPoints
// 2. (new) surface self intersections
if (checkSelfIntersect)
{
PackedBoolList isEdgeIntersecting;
bitSet isEdgeIntersecting;
detectSelfIntersections(s, isEdgeIntersecting);
const edgeList& edges = s.edges();
@ -400,7 +400,7 @@ tmp<scalarField> avg
void minSmooth
(
const triSurface& s,
const PackedBoolList& isAffectedPoint,
const bitSet& isAffectedPoint,
const scalarField& fld,
scalarField& newFld
)
@ -442,19 +442,19 @@ void lloydsSmoothing
(
const label nSmooth,
triSurface& s,
const PackedBoolList& isFeaturePoint,
const bitSet& isFeaturePoint,
const List<surfaceFeatures::edgeStatus>& edgeStat,
const PackedBoolList& isAffectedPoint
const bitSet& isAffectedPoint
)
{
const labelList& meshPoints = s.meshPoints();
const edgeList& edges = s.edges();
PackedBoolList isSmoothPoint(isAffectedPoint);
bitSet isSmoothPoint(isAffectedPoint);
// Extend isSmoothPoint
{
PackedBoolList newIsSmoothPoint(isSmoothPoint);
bitSet newIsSmoothPoint(isSmoothPoint);
forAll(edges, edgeI)
{
const edge& e = edges[edgeI];
@ -539,7 +539,7 @@ void lloydsSmoothing
// Extend isSmoothPoint
{
PackedBoolList newIsSmoothPoint(isSmoothPoint);
bitSet newIsSmoothPoint(isSmoothPoint);
forAll(edges, edgeI)
{
const edge& e = edges[edgeI];
@ -662,7 +662,7 @@ int main(int argc, char *argv[])
<< " out of " << s.nEdges() << nl
<< endl;
PackedBoolList isFeaturePoint(s.nPoints(), features.featurePoints());
bitSet isFeaturePoint(s.nPoints(), features.featurePoints());
const List<surfaceFeatures::edgeStatus> edgeStat(features.toStatus());
@ -723,11 +723,11 @@ int main(int argc, char *argv[])
// Any point on any intersected edge in any of the iterations
PackedBoolList isScaledPoint(s.nPoints());
bitSet isScaledPoint(s.nPoints());
// Detect any self intersections on initial mesh
PackedBoolList initialIsEdgeIntersecting;
bitSet initialIsEdgeIntersecting;
if (checkSelfIntersect)
{
detectSelfIntersections(s, initialIsEdgeIntersecting);
@ -775,7 +775,7 @@ int main(int argc, char *argv[])
// Detect any intersections and scale back
PackedBoolList isAffectedPoint;
bitSet isAffectedPoint;
label nIntersections = detectIntersectionPoints
(
1e-9, // intersection tolerance
@ -818,7 +818,7 @@ int main(int argc, char *argv[])
minSmooth
(
s,
PackedBoolList(s.nPoints(), true),
bitSet(s.nPoints(), true),
oldScale,
scale
);

View File

@ -54,7 +54,7 @@ using namespace Foam;
tmp<pointField> avg
(
const meshedSurface& s,
const PackedBoolList& fixedPoints
const bitSet& fixedPoints
)
{
const labelListList& pointEdges = s.pointEdges();
@ -95,7 +95,7 @@ void getFixedPoints
(
const edgeMesh& feMesh,
const pointField& points,
PackedBoolList& fixedPoints
bitSet& fixedPoints
)
{
scalarList matchDistance(feMesh.points().size(), 1e-1);
@ -177,7 +177,7 @@ int main(int argc, char *argv[])
<< "Vertices : " << surf1.nPoints() << nl
<< "Bounding Box: " << boundBox(surf1.localPoints()) << endl;
PackedBoolList fixedPoints(surf1.localPoints().size(), false);
bitSet fixedPoints(surf1.localPoints().size(), false);
if (args.found("featureFile"))
{