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

@ -94,7 +94,7 @@ Foam::PackedBoolList Foam::isoSurface::collocatedFaces
{
forAll(pp, i)
{
collocated[i] = 1u;
collocated.set(i);
}
}
}
@ -104,7 +104,7 @@ Foam::PackedBoolList Foam::isoSurface::collocatedFaces
{
forAll(pp, i)
{
collocated[i] = 1u;
collocated.set(i);
}
}
}
@ -691,7 +691,7 @@ void Foam::isoSurface::calcSnappedPoint
forAll(mesh_.pointFaces(), pointi)
{
if (isBoundaryPoint.get(pointi) == 1)
if (isBoundaryPoint.test(pointi))
{
continue;
}
@ -1527,10 +1527,7 @@ Foam::isoSurface::isoSurface
{
const face& f = mesh_.faces()[cpp.start()+i];
forAll(f, fp)
{
isBoundaryPoint.set(f[fp], 1);
}
isBoundaryPoint.setMany(f);
}
}
}
@ -1542,10 +1539,7 @@ Foam::isoSurface::isoSurface
{
const face& f = mesh_.faces()[pp.start()+i];
forAll(f, fp)
{
isBoundaryPoint.set(f[fp], 1);
}
isBoundaryPoint.setMany(f);
}
}
}

View File

@ -89,7 +89,7 @@ Foam::isoSurfaceCell::cellCutType Foam::isoSurfaceCell::calcCutType
{
const cell& cFaces = mesh_.cells()[celli];
if (isTet.get(celli) == 1)
if (isTet.test(celli))
{
forAll(cFaces, cFacei)
{
@ -381,7 +381,7 @@ void Foam::isoSurfaceCell::calcSnappedCc
forAll(mesh_.cells(), celli)
{
if (cellCutType_[celli] == CUT && isTet.get(celli) == 0)
if (cellCutType_[celli] == CUT && !isTet.test(celli))
{
scalar cVal = cVals[celli];
@ -771,7 +771,7 @@ void Foam::isoSurfaceCell::calcSnappedPoint
label facei = pFaces[pFacei];
label own = mesh_.faceOwner()[facei];
if (isTet.get(own) == 1)
if (isTet.test(own))
{
// Since tets have no cell centre to include make sure
// we only generate a triangle once per point.
@ -797,7 +797,7 @@ void Foam::isoSurfaceCell::calcSnappedPoint
{
label nei = mesh_.faceNeighbour()[facei];
if (isTet.get(nei) == 1)
if (isTet.test(nei))
{
if (localPointCells.insert(nei))
{
@ -1327,7 +1327,7 @@ Foam::isoSurfaceCell::isoSurfaceCell
{
if (tet.isA(mesh_, celli))
{
isTet.set(celli, 1);
isTet.set(celli);
}
}
}