ENH: code reduction in PackedList, PackedBoolList (issue #751)

- eliminate iterators from PackedList since they were unused, had
  lower performance than direct access and added unneeded complexity.

- eliminate auto-vivify for the PackedList '[] operator.
  The set() method provides any required auto-vivification and
  removing this ability from the '[]' operator allows for a lower
  when accessing the values. Replaced the previous cascade of iterators
  with simpler reference class.

PackedBoolList:

- (temporarily) eliminate logic and addition operators since
  these contained partially unclear semantics.

- 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.

- more consistent use of PackedBoolList test(), set(), unset() methods
  for fewer operation and clearer code. Eg,

      if (list.test(index)) ...    |  if (list[index]) ...
      if (!list.test(index)) ...   |  if (list[index] == 0u) ...
      list.set(index);             |  list[index] = 1u;
      list.unset(index);           |  list[index] = 0u;

- deleted the operator=(const labelUList&) and replaced with a setMany()
  method for more clarity about the intended operation and to avoid any
  potential inadvertent behaviour.
This commit is contained in:
Mark Olesen
2018-03-13 08:32:40 +01:00
parent 23b6ea4b85
commit 5d1fb23555
91 changed files with 622 additions and 1999 deletions

View File

@ -263,9 +263,9 @@ void Foam::meshRefinement::updateIntersections(const labelList& changedFaces)
label nMasterFaces = 0;
forAll(isMasterFace, facei)
{
if (isMasterFace.get(facei) == 1)
if (isMasterFace.test(facei))
{
nMasterFaces++;
++nMasterFaces;
}
}
reduce(nMasterFaces, sumOp<label>());
@ -273,9 +273,9 @@ void Foam::meshRefinement::updateIntersections(const labelList& changedFaces)
label nChangedFaces = 0;
forAll(changedFaces, i)
{
if (isMasterFace.get(changedFaces[i]) == 1)
if (isMasterFace.test(changedFaces[i]))
{
nChangedFaces++;
++nChangedFaces;
}
}
reduce(nChangedFaces, sumOp<label>());
@ -1260,9 +1260,9 @@ Foam::label Foam::meshRefinement::countHits() const
forAll(surfaceIndex_, facei)
{
if (surfaceIndex_[facei] >= 0 && isMasterFace.get(facei) == 1)
if (surfaceIndex_[facei] >= 0 && isMasterFace.test(facei))
{
nHits++;
++nHits;
}
}
return nHits;
@ -1562,7 +1562,7 @@ Foam::labelList Foam::meshRefinement::intersectedPoints() const
forAll(f, fp)
{
if (isBoundaryPoint.set(f[fp], 1u))
if (isBoundaryPoint.set(f[fp]))
{
nBoundaryPoints++;
}
@ -1588,7 +1588,7 @@ Foam::labelList Foam::meshRefinement::intersectedPoints() const
//
// forAll(f, fp)
// {
// if (isBoundaryPoint.set(f[fp], 1u))
// if (isBoundaryPoint.set(f[fp]))
// nBoundaryPoints++;
// }
// }
@ -1603,7 +1603,7 @@ Foam::labelList Foam::meshRefinement::intersectedPoints() const
nBoundaryPoints = 0;
forAll(isBoundaryPoint, pointi)
{
if (isBoundaryPoint.get(pointi) == 1u)
if (isBoundaryPoint.test(pointi))
{
boundaryPoints[nBoundaryPoints++] = pointi;
}
@ -2298,7 +2298,6 @@ void Foam::meshRefinement::findRegions
{
PackedBoolList insideCell(mesh.nCells());
// Mark all cells reachable from locationsInMesh
labelList insideRegions(locationsInMesh.size());
forAll(insideRegions, i)
@ -2319,7 +2318,7 @@ void Foam::meshRefinement::findRegions
{
if (cellRegion[celli] == regioni)
{
insideCell[celli] = true;
insideCell.set(celli);
}
}
}
@ -2736,7 +2735,7 @@ Foam::PackedBoolList Foam::meshRefinement::getMasterPoints
{
if (myPoints[pointi] == globalPoints.toGlobal(pointi))
{
isPatchMasterPoint[pointi] = true;
isPatchMasterPoint.set(pointi);
}
}
@ -2773,7 +2772,7 @@ Foam::PackedBoolList Foam::meshRefinement::getMasterEdges
{
if (myEdges[edgei] == globalEdges.toGlobal(edgei))
{
isMasterEdge[edgei] = true;
isMasterEdge.set(edgei);
}
}