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

@ -122,7 +122,7 @@ int main(int argc, char *argv[])
fvc::makeAbsolute(phi, rho, U);
// Test : disable refinement for some cells
PackedBoolList& protectedCell =
bitSet& protectedCell =
refCast<dynamicRefineFvMesh>(mesh).protectedCell();
if (protectedCell.empty())

View File

@ -2,8 +2,8 @@
interpolationCellPoint<vector> UInterpolator(HbyA);
// Determine faces on outside of interpolated cells
PackedBoolList isOwnerInterpolatedFace(mesh.nInternalFaces());
PackedBoolList isNeiInterpolatedFace(mesh.nInternalFaces());
bitSet isOwnerInterpolatedFace(mesh.nInternalFaces());
bitSet isNeiInterpolatedFace(mesh.nInternalFaces());
// Determine donor cells
labelListList donorCell(mesh.nInternalFaces());
@ -175,11 +175,11 @@ surfaceVectorField faceNormals(mesh.Sf()/mesh.magSf());
forAll(isNeiInterpolatedFace, faceI)
{
label cellId = -1;
if (isNeiInterpolatedFace[faceI])
if (isNeiInterpolatedFace.test(faceI))
{
cellId = mesh.faceNeighbour()[faceI];
}
else if (isOwnerInterpolatedFace[faceI])
else if (isOwnerInterpolatedFace.test(faceI))
{
cellId = mesh.faceOwner()[faceI];
}

View File

@ -474,7 +474,7 @@ int main(int argc, char *argv[])
}
{
PackedBoolList select = HashSetOps::bitset(locations);
bitSet select = HashSetOps::bitset(locations);
auto output = ListOps::createWithValue<label>
(
30,
@ -482,8 +482,8 @@ int main(int argc, char *argv[])
100,
-1 // default value
);
Info<< "with PackedBoolList: " << flatOutput(output)
<< " selector: " << flatOutput(select.used()) << nl;
Info<< "with bitSet: " << flatOutput(output)
<< " selector: " << flatOutput(select.toc()) << nl;
}
{
@ -516,7 +516,7 @@ int main(int argc, char *argv[])
}
{
PackedBoolList select = HashSetOps::bitset(locations);
bitSet select = HashSetOps::bitset(locations);
auto output = ListOps::createWithValue<label>
(
30,
@ -524,7 +524,7 @@ int main(int argc, char *argv[])
100,
-1 // default value
);
Info<< "with PackedBoolList: " << flatOutput(output)
Info<< "with bitSet: " << flatOutput(output)
<< " selector: " << flatOutput(HashSetOps::used(select))
<< nl;
}

View File

@ -145,7 +145,7 @@ int main(int argc, char *argv[])
Info<<"Test reorder - oldToNew:" << nl
<< flatOutput(oldToNew) << nl << nl;
PackedBoolList bitset
bitSet bitset
(
ListOps::createWithValue<bool>
(

View File

@ -32,7 +32,7 @@ Description
#include "IOobject.H"
#include "IOstreams.H"
#include "IFstream.H"
#include "PackedBoolList.H"
#include "bitSet.H"
#include <climits>
@ -131,7 +131,7 @@ int main(int argc, char *argv[])
IFstream ifs(srcFile);
List<label> rawLst(ifs);
PackedBoolList packLst(rawLst);
bitSet packLst(rawLst);
Info<< "size: " << packLst.size() << nl;

View File

@ -28,61 +28,100 @@ Description
\*---------------------------------------------------------------------------*/
#include "uLabel.H"
#include "labelRange.H"
#include "bitSet.H"
#include "FlatOutput.H"
#include "IOstreams.H"
#include "PackedBoolList.H"
using namespace Foam;
template<unsigned Width>
inline Ostream& report
(
const PackedList<Width>& list,
bool showBits = false,
bool debugOutput = false
)
{
Info<< list.info();
if (showBits)
{
list.printBits(Info, debugOutput) << nl;
}
return Info;
}
inline Ostream& report
(
const bitSet& bitset,
bool showBits = false,
bool debugOutput = false
)
{
Info<< bitset.info();
Info<< "all:" << bitset.all()
<< " any:" << bitset.any()
<< " none:" << bitset.none() << nl;
if (showBits)
{
bitset.printBits(Info, debugOutput) << nl;
}
return Info;
}
// BitOps::printBits((Info<< list1.info()), true) << nl;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
Info<< "PackedList max_bits() = " << PackedList<>::max_bits() << nl;
Info<< "\ntest allocation with value\n";
PackedList<3> list1(5,1);
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest assign uniform value\n";
list1 = 3;
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest assign uniform value (with overflow)\n";
list1 = -1;
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest zero\n";
list1 = 0;
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest set() with default argument (max_value)\n";
list1.set(1);
list1.set(3);
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest unset() with in-range and out-of-range\n";
list1.unset(3);
list1.unset(100000);
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest assign between references\n";
list1[2] = 3;
list1[4] = list1[2];
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest assign between references, with chaining\n";
list1[0] = 1;
list1[4] = 1;
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest assign between references, with chaining and auto-vivify\n";
list1[1] = 2;
list1[8] = 2;
list1[10] = 2;
list1[14] = 2;
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest operator== between references\n";
if (list1[1] == list1[8])
@ -106,7 +145,9 @@ int main(int argc, char *argv[])
{
const PackedList<3>& constLst = list1;
Info<< "\ntest operator[] const with out-of-range index\n";
constLst.printInfo(Info, true);
report(constLst);
if (constLst[20])
{
Info<< "[20] is true (unexpected)\n";
@ -116,7 +157,7 @@ int main(int argc, char *argv[])
Info<< "[20] is false (expected) list size should be unchanged "
<< "(const)\n";
}
constLst.printInfo(Info, true);
report(constLst);
Info<< "\ntest operator[] non-const with out-of-range index\n";
if (list1[20])
@ -128,7 +169,8 @@ int main(int argc, char *argv[])
Info<< "[20] is false (expected) but list was resized?? "
<< "(non-const)\n";
}
list1.printInfo(Info, true);
report(list1);
}
@ -137,94 +179,94 @@ int main(int argc, char *argv[])
{
Info<< "[20] is false, as expected\n";
}
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest resize with value (without reallocation)\n";
list1.resize(8, list1.max_value());
list1.printInfo(Info, true);
list1.resize(8, list1.max_value);
report(list1);
Info<< "\ntest flip() function\n";
list1.flip();
list1.printInfo(Info, true);
report(list1);
Info<< "\nre-flip()\n";
list1.flip();
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest set() function\n";
list1.set(1, 5);
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest assign bool\n";
list1 = false;
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest assign bool\n";
list1 = true;
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest resize without value (with reallocation)\n";
list1.resize(12);
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest resize with value (with reallocation)\n";
list1.resize(25, list1.max_value());
list1.printInfo(Info, true);
list1.resize(25, list1.max_value);
report(list1);
Info<< "\ntest resize smaller (should not touch allocation)\n";
list1.resize(8);
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest append() operation\n";
list1.append(2);
list1.append(3);
list1.append(4);
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest reserve() operation\n";
list1.reserve(32);
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest shrink() operation\n";
list1.shrink();
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest setCapacity() operation\n";
list1.setCapacity(15);
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest setCapacity() operation\n";
list1.setCapacity(100);
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest operator[] assignment\n";
list1[16] = 5;
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest operator[] assignment with auto-vivify\n";
list1[36] = list1.max_value();
list1.printInfo(Info, true);
list1[36] = list1.max_value;
report(list1);
Info<< "\ntest setCapacity smaller\n";
list1.setCapacity(24);
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest resize much smaller\n";
list1.resize(150);
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest trim\n";
list1.trim();
list1.printInfo(Info, true);
report(list1);
// add in some misc values
// Add in some misc values
list1[31] = 1;
list1[32] = 2;
list1[33] = 3;
Info<< "\ntest get() method\n";
Info<< "get(10):" << list1.get(10) << " and list[10]:" << list1[10] << "\n";
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest operator[] auto-vivify\n";
Info<< "size:" << list1.size() << "\n";
@ -234,33 +276,34 @@ int main(int argc, char *argv[])
Info<< "list[45]:" << val << "\n";
Info<< "size after read:" << list1.size() << "\n";
list1[45] = list1.max_value();
list1[45] = list1.max_value;
Info<< "size after write:" << list1.size() << "\n";
Info<< "list[45]:" << list1[45] << "\n";
list1[49] = list1[100];
list1.printInfo(Info, true);
report(list1);
Info<< "\ntest copy constructor + append\n";
PackedList<3> list2(list1);
list2.append(4);
Info<< "source list:\n";
list1.printInfo(Info, true);
report(list1);
Info<< "destination list:\n";
list2.printInfo(Info, true);
report(list2);
Info<< "\ntest pattern that fills all bits\n";
PackedList<4> list3(8, 8);
label pos = list3.size() - 1;
list3[pos--] = list3.max_value();
list3[pos--] = list3.max_value;
list3[pos--] = 0;
list3[pos--] = list3.max_value();
list3.printInfo(Info, true);
list3[pos--] = list3.max_value;
report(list3);
Info<< "removed final value: " << list3.remove() << endl;
list3.printInfo(Info, true);
report(list3);
Info<<"list: " << list3 << endl;
@ -289,18 +332,117 @@ int main(int argc, char *argv[])
}
PackedBoolList listb(list4);
bitSet listb(list4);
Info<< "copied from bool list " << endl;
listb.printInfo(Info, true);
// report(listb);
{
labelList indices = listb.used();
labelList indices = listb.toc();
Info<< "indices: " << indices << endl;
}
Info<< nl
<< "resizing: " << nl;
{
PackedList<1> list1(81, 1);
PackedList<3> list3(27, 5); // ie, 101
Info<< "initial" << nl; report(list1, true);
Info<< "initial" << nl; report(list3, true);
list1.resize(118, 1);
list3.resize(37, 3);
Info<< "extend with val" << nl; report(list1, true);
Info<< "extend with val" << nl; report(list3, true);
list1.resize(90, 0);
list3.resize(30, 4);
Info<< "contract with val" << nl; report(list1, true);
Info<< "contract with val" << nl; report(list3, true);
}
{
bitSet bits(45);
Info<< "bits" << nl; report(bits, true);
bits = true;
Info<< "bits" << nl; report(bits, true);
bits.unset(35);
Info<< "bits" << nl; report(bits, true);
bits.resize(39);
Info<< "bits" << nl; report(bits, true);
Info<< "values:" << flatOutput(bits.values()) << nl;
Info<< "used:" << flatOutput(bits.toc()) << nl;
bits.unset(labelRange(-15, 8));
Info<< "bits" << nl; report(bits, true);
bits.set(labelRange(-15, 100));
Info<< "bits" << nl; report(bits, true);
bits.set(labelRange(-15, 100));
Info<< "bits" << nl; report(bits, true);
bits.set(labelRange(150, 15));
Info<< "bits" << nl; report(bits, true);
bits.set(labelRange(0, 5));
Info<< "bits" << nl; report(bits, true);
bits.reset();
bits.resize(50);
Info<< "bits" << nl; report(bits, true);
bits.set(labelRange(4, 8));
Info<< "bits" << nl; report(bits, true);
bits.set(labelRange(30, 35));
Info<< "bits" << nl; report(bits, true);
bits.set(labelRange(80, 12));
Info<< "bits" << nl; report(bits, true);
bits.unset(labelRange(35, 16));
Info<< "bits" << nl; report(bits, true);
bits.unset(labelRange(0, 50));
bits.resize(100000);
bits.set(labelRange(30, 6));
bits[33] = false;
Info<<"used: " << flatOutput(bits.toc()) << endl;
Info<<"first: " << bits.find_first() << endl;
Info<<"next: " << bits.find_next(29) << endl;
Info<<"next: " << bits.find_next(30) << endl;
Info<<"next: " << bits.find_next(31) << endl;
Info<<"next: " << bits.find_next(31) << endl;
bits.set(labelRange(80, 10));
bits.resize(100);
Info<< "bits" << nl; report(bits, true);
bits.set(labelRange(125, 10));
Info<<"next: " << bits.find_next(64) << endl;
Info<<"used: " << flatOutput(bits.toc()) << endl;
for (const auto pos : bits)
{
Info<<"have: " << pos << nl;
}
}
Info<< "\n\nDone.\n";
return 0;

View File

@ -29,7 +29,7 @@ Description
#include "argList.H"
#include "boolList.H"
#include "PackedBoolList.H"
#include "bitSet.H"
#include "HashSet.H"
#include "cpuTime.H"
#include <vector>
@ -63,7 +63,7 @@ int main(int argc, char *argv[])
unsigned long sum = 0;
PackedBoolList packed(n, 1);
bitSet packed(n, true);
boolList unpacked(n, true);
#ifdef TEST_STD_BOOLLIST

View File

@ -1,3 +0,0 @@
Test-PackedList3.C
EXE = $(FOAM_USER_APPBIN)/Test-PackedList3

View File

@ -1,3 +0,0 @@
Test-PackedList4.C
EXE = $(FOAM_USER_APPBIN)/Test-PackedList4

View File

@ -1,168 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
Description
\*---------------------------------------------------------------------------*/
#include "uLabel.H"
#include "boolList.H"
#include "DynamicList.H"
#include "IOstreams.H"
#include "PackedBoolList.H"
#include "ITstream.H"
#include "StringStream.H"
#include "FlatOutput.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
PackedBoolList list1(20);
// set every third one on
forAll(list1, i)
{
list1[i] = !(i % 3);
}
Info<< "\nalternating bit pattern\n";
list1.printInfo(Info, true);
PackedBoolList list2(list1);
list2.flip();
Info<< "\nflipped bit pattern\n";
list2.printBits(Info);
// set every other on
forAll(list2, i)
{
list2[i] = !(i % 2);
}
Info<< "\nalternating bit pattern\n";
list2.printBits(Info);
list2.resize(28, false);
list2.resize(34, true);
list2.resize(40, false);
for (label i=0; i < 4; ++i)
{
list2[i] = true;
}
Info<< "\nresized with false, 6 true + 6 false, bottom 4 bits true\n";
list2.printInfo(Info, true);
labelList list2Labels = list2.used();
PackedBoolList list4
(
ITstream
(
"input",
"(1 n 1 n 1 n 1 1 off 0 0 f f 0 y yes y true y false on t)"
)()
);
Info<< "\ntest Istream constructor\n";
list4.printInfo(Info, true);
Info<< list4 << " indices: " << list4.used() << nl;
Info<< "\nassign from labelList\n";
list4.clear();
list4.setMany(labelList{0, 1, 2, 3, 12, 13, 14, 19, 20, 21});
list4.printInfo(Info, true);
Info<< list4 << " indices: " << list4.used() << nl;
// Not yet:
// PackedBoolList list5{0, 1, 2, 3, 12, 13, 14, 19, 20, 21};
// list5.printInfo(Info, true);
// Info<< list5 << " indices: " << list5.used() << nl;
Info<< "\nassign from indices\n";
list4.read
(
IStringStream
(
"{0 1 2 3 12 13 14 19 20 21}"
)()
);
list4.printInfo(Info, true);
Info<< list4 << " indices: " << list4.used() << nl;
boolList bools(list4.size());
forAll(list4, i)
{
bools[i] = list4[i];
}
Info<< "boolList: " << bools << nl;
// check roundabout assignments
PackedList<2> pl2
(
IStringStream
(
"{(0 3)(1 3)(2 3)(3 3)(12 3)(13 3)(14 3)(19 3)(20 3)(21 3)}"
)()
);
Info<< "roundabout assignment: " << pl2 << nl;
list4.clear();
forAll(pl2, i)
{
list4[i] = pl2[i];
}
list4.writeList(Info, -1) << nl; // indexed output
list4.writeEntry("PackedBoolList", Info);
// Construct from labelUList, labelUIndList
{
DynamicList<label> indices({10, 50, 300});
Info<< "set: " << flatOutput(indices) << endl;
PackedBoolList bools1(indices);
Info<< "used: " << bools1.size() << " "
<< flatOutput(bools1.used()) << endl;
}
return 0;
}
// ************************************************************************* //

View File

@ -218,7 +218,7 @@ int main(int argc, char *argv[])
labelList patchEdges;
labelList coupledEdges;
PackedBoolList sameEdgeOrientation;
bitSet sameEdgeOrientation;
PatchTools::matchEdges
(
pp,

View File

@ -0,0 +1,3 @@
Test-bitSet1.C
EXE = $(FOAM_USER_APPBIN)/Test-bitSet1

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -22,50 +22,60 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
Test-bitSet1
Description
Test bitSet functionality
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "boolList.H"
#include "bitSet.H"
#include "HashSet.H"
#include "cpuTime.H"
#include "PackedBoolList.H"
#include <vector>
#include <unordered_set>
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline Ostream& report
(
const bitSet& bitset,
bool showBits = false,
bool debugOutput = false
)
{
Info<< "size=" << bitset.size() << "/" << bitset.capacity()
<< " count=" << bitset.count()
<< " all:" << bitset.all()
<< " any:" << bitset.any()
<< " none:" << bitset.none() << nl;
Info<< "values: " << flatOutput(bitset) << nl;
if (showBits)
{
bitset.printBits(Info, debugOutput) << nl;
}
return Info;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
const label nLoop = 5;
const label n = 100000000;
// const label nReport = 1000000;
bitSet set1(100);
cpuTime timer;
Info<<"bitSet(label): "; report(set1, true);
// test inserts
PackedBoolList packed;
for (label iloop = 0; iloop < nLoop; ++iloop)
{
for (label i = 0; i < n; ++i)
{
// if ((i % nReport) == 0 && i)
// {
// Info<< "." << flush;
// }
packed[i] = 1;
// Make compiler do something else too
packed[i/2] = 0;
}
}
Info<< nl
<< "insert test: " << nLoop << "*" << n << " elements in "
<< timer.cpuTimeIncrement() << " s\n\n";
bitSet set2(100, { -1, 10, 25, 45});
Info<<"bitSet(label, labels): "; report(set2, true);
Info << "\nEnd\n" << endl;
Info<< "End\n" << endl;
return 0;
}

View File

@ -0,0 +1,3 @@
Test-bitSet2.C
EXE = $(FOAM_USER_APPBIN)/Test-bitSet2

View File

@ -0,0 +1,311 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
Test-bitSet2
Description
Test bitSet functionality
\*---------------------------------------------------------------------------*/
#include "uLabel.H"
#include "boolList.H"
#include "DynamicList.H"
#include "IOstreams.H"
#include "ITstream.H"
#include "StringStream.H"
#include "bitSet.H"
#include "FlatOutput.H"
using namespace Foam;
inline Ostream& report
(
const bitSet& bitset,
bool showBits = false,
bool debugOutput = false
)
{
Info<< "size=" << bitset.size() << "/" << bitset.capacity()
<< " count=" << bitset.count()
<< " all:" << bitset.all()
<< " any:" << bitset.any()
<< " none:" << bitset.none() << nl;
Info<< "values: " << flatOutput(bitset) << nl;
if (showBits)
{
bitset.printBits(Info, debugOutput) << nl;
}
return Info;
}
template<class UIntType>
std::string toString(UIntType value, char off='.', char on='1')
{
std::string str(std::numeric_limits<UIntType>::digits, off);
unsigned n = 0;
// Starting from most significant bit - makes for easy reading.
for
(
unsigned test = (1u << (std::numeric_limits<UIntType>::digits-1));
test;
test >>= 1u
)
{
str[n++] = ((value & test) ? on : off);
}
return str;
}
inline bool compare
(
const bitSet& bitset,
const std::string& expected
)
{
const List<unsigned int>& store = bitset.storage();
std::string has;
for (label blocki=0; blocki < bitset.nBlocks(); ++blocki)
{
has += toString(store[blocki]);
}
if (has == expected)
{
Info<< "pass: " << has << nl;
return true;
}
Info<< "fail: " << has << nl;
Info<< "expect: " << expected << nl;
return false;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
bitSet list1(22);
// Set every third one on
forAll(list1, i)
{
list1[i] = !(i % 3);
}
Info<< "\nalternating bit pattern\n";
compare(list1, "..........1..1..1..1..1..1..1..1");
list1.unset(labelRange(13, 20)); // In range
Info<< "\nafter clear [13,..]\n";
compare(list1, "...................1..1..1..1..1");
report(list1, true);
list1.unset(labelRange(40, 20)); // out of range
Info<< "\nafter clear [40,..]\n";
compare(list1, "...................1..1..1..1..1");
report(list1, true);
Info<< "first: " << list1.find_first()
<< " last: " << list1.find_last() << endl;
Info<< "iterate through:";
for (const label idx : list1)
{
Info<<" " << idx;
}
Info<< nl;
Info<< "\nalternating bit pattern\n";
report(list1, true);
bitSet list2 = ~list1;
Info<< "\nflipped bit pattern\n";
report(list2, true);
// set every other on
forAll(list2, i)
{
list2[i] = !(i % 2);
}
Info<< "\nstarting pattern\n";
report(list2, true);
list2.resize(28, false);
list2.resize(34, true);
list2.resize(40, false);
for (label i=0; i < 4; ++i)
{
list2[i] = true;
}
Info<< "\nresized with false, [28,34) true + 6 false, bottom 4 bits true\n";
compare
(
list2,
"1111.......1.1.1.1.1.1.1.1.11111"
"..............................11"
);
report(list2, true);
labelList list2Labels = list2.toc();
Info<< "\noperator|\n";
list1.printBits(Info);
list2.printBits(Info);
Info<< "==\n";
(list1 | list2).printBits(Info);
Info<< "\noperator& : does trim\n";
report((list1 & list2), true);
Info<< "\noperator^\n";
report((list1 ^ list2), true);
Info<< "\noperator|=\n";
{
bitSet list3 = list1;
report((list3 |= list2), true);
}
Info<< "\noperator&=\n";
{
bitSet list3 = list1;
report((list3 &= list2), true);
}
Info<< "\noperator^=\n";
{
bitSet list3 = list1;
report((list3 ^= list2), true);
}
Info<< "\noperator-=\n";
{
bitSet list3 = list1;
report((list3 -= list2), true);
}
bitSet list4
(
ITstream
(
"input",
"(1 n 1 n 1 n 1 1 off 0 0 f f 0 y yes y true y false on t)"
)()
);
Info<< "\ntest Istream constructor\n";
report(list4, true);
Info<< "\nclear/assign from labelList\n";
list4.clear();
list4.setMany(labelList{0, 1, 2, 3, 12, 13, 14, 19, 20, 21});
report(list4, true);
// Not yet:
// bitSet list5{0, 1, 2, 3, 12, 13, 14, 19, 20, 21};
// list5.printInfo(Info, true);
// Info<< list5 << " indices: " << list5.toc() << nl;
Info<< "\nassign from indices\n";
list4.read
(
IStringStream
(
"{0 1 2 3 12 13 14 19 20 21}"
)()
);
report(list4, true);
compare(list4, "..........111....111........1111");
list4.set(labelRange(28, 6)); // extends size
Info<<"extended\n";
compare
(
list4,
"1111......111....111........1111"
"..............................11"
);
list4.set(labelRange(40, 6)); // extends size
Info<<"extended\n";
compare
(
list4,
"1111......111....111........1111"
"..................111111......11"
);
list4.unset(labelRange(14, 19));
Info<<"cleared [14,33)\n";
compare
(
list4,
"..................11........1111"
"..................111111......1."
);
// Construct from labelUList, labelUIndList
{
DynamicList<label> indices({10, 50, 300});
Info<< "set: " << flatOutput(indices) << endl;
bitSet bools1(indices);
Info<< "used: " << bools1.size() << " "
<< flatOutput(bools1.toc()) << endl;
}
return 0;
}
// ************************************************************************* //

View File

@ -27,6 +27,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "bool.H"
#include "BitOps.H"
#include "IOstreams.H"
#include "stdFoam.H"
@ -177,6 +178,15 @@ int main(int argc, char *argv[])
printOffset<double>();
Info<<nl << "Test repeat_value" << nl << nl;
Info<< BitOps::bitInfo<unsigned>(BitOps::repeat_value<unsigned, 3>(1u))
<< nl;
Info<< BitOps::bitInfo<unsigned>(BitOps::repeat_value<unsigned>(1u))
<< nl;
Info << "---\nEnd\n" << endl;
return 0;

View File

@ -0,0 +1,3 @@
Test-limits.C
EXE = $(FOAM_USER_APPBIN)/Test-limits

View File

@ -0,0 +1,2 @@
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -22,44 +22,24 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Test the sizeof for basic types. Can be compiled and run without
any OpenFOAM libraries.
Test the sizeof for basic types.
Can be compiled and run without any OpenFOAM libraries.
g++ -std=c++11 -oTest-machine-sizes Test-machine-sizes.cpp
\*---------------------------------------------------------------------------*/
#include <cstdint>
#include <climits>
#include <cstdlib>
#include <limits>
#include <iostream>
// Can also compile without OpenFOAM
#ifdef WM_LABEL_SIZE
#include "IOstreams.H"
#endif
template<class T>
void print(const char* msg)
{
std::cout<< msg << ' ' << sizeof(T) << '\n';
}
#ifdef WM_LABEL_SIZE
template<class T>
void printMax(const char* msg)
{
std::cout<< msg << ' ' << sizeof(T)
<< " max "
<< std::numeric_limits<T>::max() << '\n';
Foam::Info<< msg << ' ' << sizeof(T)
<< " max "
<< long(std::numeric_limits<T>::max()) << '\n';
}
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
@ -67,42 +47,16 @@ int main(int argc, char *argv[])
{
std::cout<<"machine sizes\n---\n\n";
print<mode_t>("mode_t");
print<short>("short");
print<int>("int");
print<long>("long");
print<long long>("long long");
print<unsigned short>("ushort");
print<unsigned int>("uint");
print<unsigned long>("ulong");
print<unsigned long long>("ulong-long");
print<int16_t>("int16");
print<int32_t>("int32");
print<int64_t>("int64");
print<uint16_t>("uint16");
print<uint32_t>("uint32");
print<uint64_t>("uint64");
print<float>("float");
print<double>("double");
print<long double>("long double");
print<std::string>("std::string");
print<std::string::size_type>("std::string::size_type");
#ifdef WM_LABEL_SIZE
std::cout<<"\nmax values\n---\n\n";
printMax<mode_t>("mode_t");
Foam::Info<< "mode_t 0777: " << mode_t(0777) << '\n';
printMax<short>("short");
printMax<int>("int");
printMax<long>("long");
printMax<unsigned short>("ushort");
printMax<unsigned int>("uint");
printMax<unsigned long>("ulong");
printMax<float>("float");
printMax<double>("double");
#endif
std::cout << "\n---\nEnd\n\n";
return 0;

View File

@ -48,10 +48,6 @@ Usage
- \par -triSurface
Use triSurface library for input/output
- \par -keyed
Use keyedSurface for input/output
Note
The filename extensions are used to determine the file format type.
@ -64,7 +60,6 @@ Note
#include "surfMesh.H"
#include "surfFields.H"
#include "surfPointFields.H"
#include "PackedBoolList.H"
#include "MeshedSurfaces.H"
#include "ModifiableMeshedSurface.H"

View File

@ -406,13 +406,13 @@ void testPointSync(const polyMesh& mesh, Random& rndGen)
{
labelList nMasters(mesh.nPoints(), 0);
PackedBoolList isMasterPoint(syncTools::getMasterPoints(mesh));
bitSet isMasterPoint(syncTools::getMasterPoints(mesh));
forAll(isMasterPoint, pointi)
{
if (isMasterPoint[pointi])
if (isMasterPoint.test(pointi))
{
nMasters[pointi] = 1;
nMasters.set(pointi);
}
}
@ -482,13 +482,13 @@ void testEdgeSync(const polyMesh& mesh, Random& rndGen)
{
labelList nMasters(edges.size(), 0);
PackedBoolList isMasterEdge(syncTools::getMasterEdges(mesh));
bitSet isMasterEdge(syncTools::getMasterEdges(mesh));
forAll(isMasterEdge, edgeI)
{
if (isMasterEdge[edgeI])
if (isMasterEdge.test(edgeI))
{
nMasters[edgeI] = 1;
nMasters.set(edgeI);
}
}
@ -551,13 +551,13 @@ void testFaceSync(const polyMesh& mesh, Random& rndGen)
{
labelList nMasters(mesh.nFaces(), 0);
PackedBoolList isMasterFace(syncTools::getMasterFaces(mesh));
Bitset isMasterFace(syncTools::getMasterFaces(mesh));
forAll(isMasterFace, facei)
{
if (isMasterFace[facei])
if (isMasterFace.test(facei))
{
nMasters[facei] = 1;
nMasters.set(facei);
}
}

View File

@ -81,7 +81,7 @@ void modifyOrAddFace
const label zoneID,
const bool zoneFlip,
PackedBoolList& modifiedFace
bitSet& modifiedFace
)
{
if (modifiedFace.set(facei))
@ -338,7 +338,7 @@ void subsetTopoSets
Info<< "Subsetting " << set.type() << " " << set.name() << endl;
// Map the data
PackedBoolList isSet(set.maxSize(mesh));
bitSet isSet(set.maxSize(mesh));
forAllConstIter(labelHashSet, set, iter)
{
isSet.set(iter.key());
@ -374,7 +374,7 @@ void createCoupledBaffles
fvMesh& mesh,
const labelList& coupledWantedPatch,
polyTopoChange& meshMod,
PackedBoolList& modifiedFace
bitSet& modifiedFace
)
{
const faceZoneMesh& faceZones = mesh.faceZones();
@ -442,7 +442,7 @@ void createCyclicCoupledBaffles
const labelList& cyclicMasterPatch,
const labelList& cyclicSlavePatch,
polyTopoChange& meshMod,
PackedBoolList& modifiedFace
bitSet& modifiedFace
)
{
const faceZoneMesh& faceZones = mesh.faceZones();
@ -1119,7 +1119,7 @@ int main(int argc, char *argv[])
// Whether first use of face (modify) or consecutive (add)
PackedBoolList modifiedFace(mesh.nFaces());
bitSet modifiedFace(mesh.nFaces());
// Create coupled wall-side baffles
createCoupledBaffles

View File

@ -366,7 +366,7 @@ void Foam::cellSplitter::setRefinement
// Mark off affected face.
boolList faceUpToDate(mesh_.nFaces(), true);
bitSet faceUpToDate(mesh_.nFaces(), true);
forAllConstIter(Map<point>, cellToMidPoint, iter)
{
@ -374,18 +374,15 @@ void Foam::cellSplitter::setRefinement
const cell& cFaces = mesh_.cells()[celli];
forAll(cFaces, i)
{
label facei = cFaces[i];
faceUpToDate[facei] = false;
}
faceUpToDate.unsetMany(cFaces);
}
forAll(faceUpToDate, facei)
{
if (!faceUpToDate[facei])
if (!faceUpToDate.test(facei))
{
faceUpToDate.set(facei);
const face& f = mesh_.faces()[facei];
if (mesh_.isInternalFace(facei))
@ -454,8 +451,6 @@ void Foam::cellSplitter::setRefinement
)
);
}
faceUpToDate[facei] = true;
}
}
}

View File

@ -579,7 +579,7 @@ int main(int argc, char *argv[])
pointField newPoints(points);
PackedBoolList collapseEdge(mesh.nEdges());
bitSet collapseEdge(mesh.nEdges());
Map<point> collapsePointToLocation(mesh.nPoints());
// Get new positions and construct collapse network

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -97,10 +97,10 @@ int main(int argc, char *argv[])
label nPatchFaces = 0;
label nPatchEdges = 0;
forAllConstIter(labelHashSet, patchSet, iter)
for (const label patchi : patchSet)
{
nPatchFaces += mesh.boundaryMesh()[iter.key()].size();
nPatchEdges += mesh.boundaryMesh()[iter.key()].nEdges();
nPatchFaces += mesh.boundaryMesh()[patchi].size();
nPatchEdges += mesh.boundaryMesh()[patchi].nEdges();
}
// Construct from estimate for the number of cells to refine
@ -111,15 +111,13 @@ int main(int argc, char *argv[])
DynamicList<scalar> allCutEdgeWeights(nPatchEdges);
// Find cells to refine
forAllConstIter(labelHashSet, patchSet, iter)
for (const label patchi : patchSet)
{
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
const polyPatch& pp = mesh.boundaryMesh()[patchi];
const labelList& meshPoints = pp.meshPoints();
forAll(meshPoints, pointi)
for (const label meshPointi : meshPoints)
{
label meshPointi = meshPoints[pointi];
const labelList& pCells = mesh.pointCells()[meshPointi];
cutCells.insertMany(pCells);
@ -139,49 +137,43 @@ int main(int argc, char *argv[])
<< cells.instance()/cells.local()/cells.name()
<< nl << endl;
forAllConstIter(cellSet, cells, iter)
for (const label celli : cells)
{
cutCells.erase(iter.key());
cutCells.erase(celli);
}
Info<< "Removed from cells to cut all the ones not in set "
<< setName << nl << endl;
}
// Mark all mesh points on patch
boolList vertOnPatch(mesh.nPoints(), false);
bitSet vertOnPatch(mesh.nPoints());
forAllConstIter(labelHashSet, patchSet, iter)
for (const label patchi : patchSet)
{
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
const polyPatch& pp = mesh.boundaryMesh()[patchi];
const labelList& meshPoints = pp.meshPoints();
forAll(meshPoints, pointi)
{
vertOnPatch[meshPoints[pointi]] = true;
}
vertOnPatch.setMany(meshPoints);
}
forAllConstIter(labelHashSet, patchSet, iter)
for (const label patchi : patchSet)
{
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
const polyPatch& pp = mesh.boundaryMesh()[patchi];
const labelList& meshPoints = pp.meshPoints();
forAll(meshPoints, pointi)
for (const label meshPointi : meshPoints)
{
label meshPointi = meshPoints[pointi];
const labelList& pEdges = mesh.pointEdges()[meshPointi];
forAll(pEdges, pEdgeI)
for (const label edgei : pEdges)
{
const label edgeI = pEdges[pEdgeI];
const edge& e = mesh.edges()[edgeI];
const edge& e = mesh.edges()[edgei];
label otherPointi = e.otherVertex(meshPointi);
if (!vertOnPatch[otherPointi])
if (!vertOnPatch.test(otherPointi))
{
allCutEdges.append(edgeI);
allCutEdges.append(edgei);
if (e.start() == meshPointi)
{
@ -214,7 +206,7 @@ int main(int argc, char *argv[])
(
mesh,
cutCells.toc(), // cells candidate for cutting
labelList(0), // cut vertices
labelList(), // cut vertices
allCutEdges, // cut edges
cutEdgeWeights // weight on cut edges
);

View File

@ -869,7 +869,7 @@ int main(int argc, char *argv[])
// Pre-filtering: flip "owner" boundary or wrong oriented internal
// faces and move to neighbour
boolList fm(faces.size(), false);
bitSet fm(faces.size(), false);
forAll(faces, facei)
{
if
@ -878,7 +878,7 @@ int main(int argc, char *argv[])
|| (neighbour[facei] != -1 && owner[facei] > neighbour[facei])
)
{
fm[facei] = true;
fm.set(facei);
if (!cubitFile)
{
faces[facei].flip();
@ -1279,7 +1279,7 @@ int main(int argc, char *argv[])
false, // flipFaceFlux
-1, // patchID
faceZonei, // zoneID
fm[facei] // zoneFlip
fm.test(facei) // zoneFlip
);
}

View File

@ -1620,14 +1620,14 @@ int main(int argc, char *argv[])
labelList cls(end() - start() + 1);
// Mark zone cells, used for finding faces
boolList zoneCell(pShapeMesh.nCells(), false);
bitSet zoneCell(pShapeMesh.nCells(), false);
// shift cell indizes by 1
label nr=0;
for (label celli = (start() - 1); celli < end(); celli++)
{
cls[nr]=celli;
zoneCell[celli] = true;
zoneCell.set(celli);
nr++;
}
@ -1646,7 +1646,7 @@ int main(int argc, char *argv[])
label own = pShapeMesh.faceOwner()[facei];
if (nei != -1)
{
if (zoneCell[nei] && zoneCell[own])
if (zoneCell.test(nei) && zoneCell.test(own))
{
zoneFaces.append(facei);
}
@ -1669,7 +1669,7 @@ int main(int argc, char *argv[])
const labelList& faceCells = bPatches[pI].faceCells();
forAll(faceCells, fcI)
{
if (zoneCell[faceCells[fcI] ])
if (zoneCell.test(faceCells[fcI]))
{
boundaryZones[pI].append(name);
break;

View File

@ -890,7 +890,7 @@ int main(int argc, char *argv[])
const edgeList& edges = mesh.edges();
const pointField& points = mesh.points();
PackedBoolList collapseEdge(mesh.nEdges());
bitSet collapseEdge(mesh.nEdges());
Map<point> collapsePointToLocation(mesh.nPoints());
forAll(edges, edgeI)

View File

@ -1268,7 +1268,7 @@ void extrudeGeometricProperties
// Determine edge normals on original patch
labelList patchEdges;
labelList coupledEdges;
PackedBoolList sameEdgeOrientation;
bitSet sameEdgeOrientation;
PatchTools::matchEdges
(
extrudePatch,
@ -2160,7 +2160,7 @@ int main(int argc, char *argv[])
labelListList extrudeEdgePatches(extrudePatch.nEdges());
// Is edge a non-manifold edge
PackedBoolList nonManifoldEdge(extrudePatch.nEdges());
bitSet nonManifoldEdge(extrudePatch.nEdges());
// Note: logic has to be same as in countExtrudePatches.
forAll(edgeFaces, edgeI)

View File

@ -256,7 +256,7 @@ int main(int argc, char *argv[])
const boundBox& bb = mesh().bounds();
const scalar mergeDim = 1e-4 * bb.minDim();
PackedBoolList collapseEdge(mesh().nEdges());
bitSet collapseEdge(mesh().nEdges());
Map<point> collapsePointToLocation(mesh().nPoints());
forAll(edges, edgeI)

View File

@ -321,7 +321,7 @@ void Foam::controlMeshRefinement::initialMeshPopulation
sizes.clear();
alignments.clear();
PackedBoolList keepVertex(vertices.size(), true);
bitSet keepVertex(vertices.size(), true);
forAll(vertices, vI)
{
@ -496,7 +496,7 @@ void Foam::controlMeshRefinement::initialMeshPopulation
}
}
PackedBoolList keepVertex(vertices.size(), true);
bitSet keepVertex(vertices.size(), true);
forAll(vertices, vI)
{

View File

@ -1081,7 +1081,7 @@ void Foam::conformalVoronoiMesh::move()
Zero
);
PackedBoolList pointToBeRetained(number_of_vertices(), true);
bitSet pointToBeRetained(number_of_vertices(), true);
DynamicList<Point> pointsToInsert(number_of_vertices());

View File

@ -47,7 +47,7 @@ SourceFiles
#include "cellShapeControl.H"
#include "cvControls.H"
#include "DynamicList.H"
#include "PackedBoolList.H"
#include "bitSet.H"
#include "Time.H"
#include "polyMesh.H"
#include "plane.H"
@ -606,7 +606,7 @@ private:
pointField& cellCentres,
labelList& cellToDelaunayVertex,
labelListList& patchToDelaunayVertex,
PackedBoolList& boundaryFacesToRemove
bitSet& boundaryFacesToRemove
);
void calcNeighbourCellCentres
@ -760,7 +760,7 @@ private:
wordList& patchNames,
PtrList<dictionary>& patchDicts,
labelListList& patchPointPairSlaves,
PackedBoolList& boundaryFacesToRemove,
bitSet& boundaryFacesToRemove,
bool includeEmptyPatches = false
) const;
@ -791,7 +791,7 @@ private:
faceList& faces,
labelList& owner,
PtrList<dictionary>& patchDicts,
PackedBoolList& boundaryFacesToRemove,
bitSet& boundaryFacesToRemove,
const List<DynamicList<face>>& patchFaces,
const List<DynamicList<label>>& patchOwners,
const List<DynamicList<bool>>& indirectPatchFace
@ -997,7 +997,7 @@ public:
const wordList& patchNames,
const PtrList<dictionary>& patchDicts,
const pointField& cellCentres,
PackedBoolList& boundaryFacesToRemove
bitSet& boundaryFacesToRemove
) const;
//- Calculate and write a field of the target cell size,

View File

@ -47,7 +47,7 @@ void Foam::conformalVoronoiMesh::calcDualMesh
pointField& cellCentres,
labelList& cellToDelaunayVertex,
labelListList& patchToDelaunayVertex,
PackedBoolList& boundaryFacesToRemove
bitSet& boundaryFacesToRemove
)
{
timeCheck("Start calcDualMesh");
@ -277,7 +277,7 @@ void Foam::conformalVoronoiMesh::calcTetMesh
sortFaces(faces, owner, neighbour);
// PackedBoolList boundaryFacesToRemove;
// bitSet boundaryFacesToRemove;
// List<DynamicList<bool>> indirectPatchFace;
//
// addPatches
@ -703,7 +703,7 @@ Foam::conformalVoronoiMesh::createPolyMeshFromPoints
PtrList<dictionary> patchDicts;
pointField cellCentres;
labelListList patchToDelaunayVertex;
PackedBoolList boundaryFacesToRemove;
bitSet boundaryFacesToRemove;
timeCheck("Start of checkPolyMeshQuality");
@ -1103,7 +1103,7 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality
}
PackedBoolList ptToBeLimited(pts.size(), false);
bitSet ptToBeLimited(pts.size(), false);
forAllConstIter(labelHashSet, wrongFaces, iter)
{
@ -1704,7 +1704,7 @@ void Foam::conformalVoronoiMesh::createFacesOwnerNeighbourAndPatches
wordList& patchNames,
PtrList<dictionary>& patchDicts,
labelListList& patchPointPairSlaves,
PackedBoolList& boundaryFacesToRemove,
bitSet& boundaryFacesToRemove,
bool includeEmptyPatches
) const
{
@ -2486,7 +2486,7 @@ void Foam::conformalVoronoiMesh::addPatches
faceList& faces,
labelList& owner,
PtrList<dictionary>& patchDicts,
PackedBoolList& boundaryFacesToRemove,
bitSet& boundaryFacesToRemove,
const List<DynamicList<face>>& patchFaces,
const List<DynamicList<label>>& patchOwners,
const List<DynamicList<bool>>& indirectPatchFace
@ -2531,7 +2531,7 @@ void Foam::conformalVoronoiMesh::removeUnusedPoints
{
Info<< nl << "Removing unused points" << endl;
PackedBoolList ptUsed(pts.size(), false);
bitSet ptUsed(pts.size(), false);
// Scan all faces to find all of the points that are used
@ -2585,7 +2585,7 @@ Foam::labelList Foam::conformalVoronoiMesh::removeUnusedCells
{
Info<< nl << "Removing unused cells" << endl;
PackedBoolList cellUsed(vertexCount(), false);
bitSet cellUsed(vertexCount(), false);
// Scan all faces to find all of the cells that are used

View File

@ -2271,7 +2271,7 @@ void Foam::conformalVoronoiMesh::reinsertSurfaceConformation()
ptPairs_.reIndex(oldToNewIndices);
PackedBoolList selectedElems(surfaceConformationVertices_.size(), true);
bitSet selectedElems(surfaceConformationVertices_.size(), true);
forAll(surfaceConformationVertices_, vI)
{
@ -2295,7 +2295,7 @@ void Foam::conformalVoronoiMesh::reinsertSurfaceConformation()
}
}
inplaceSubset<PackedBoolList, List<Vb>>
inplaceSubset<bitSet, List<Vb>>
(
selectedElems,
surfaceConformationVertices_

View File

@ -115,7 +115,7 @@ void Foam::conformalVoronoiMesh::writeMesh(const fileName& instance)
wordList patchNames;
PtrList<dictionary> patchDicts;
pointField cellCentres;
PackedBoolList boundaryFacesToRemove;
bitSet boundaryFacesToRemove;
calcDualMesh
(
@ -377,7 +377,7 @@ void Foam::conformalVoronoiMesh::writeMesh(const fileName& instance)
//
// Info<< nl << "Writing tetDualMesh to " << instance << endl;
//
// PackedBoolList boundaryFacesToRemove;
// bitSet boundaryFacesToRemove;
// writeMesh
// (
// "tetDualMesh",
@ -773,7 +773,7 @@ void Foam::conformalVoronoiMesh::writeMesh
const wordList& patchNames,
const PtrList<dictionary>& patchDicts,
const pointField& cellCentres,
PackedBoolList& boundaryFacesToRemove
bitSet& boundaryFacesToRemove
) const
{
if (foamyHexMeshControls().objOutput())
@ -949,7 +949,7 @@ void Foam::conformalVoronoiMesh::writeMesh
orEqOp<unsigned int>()
);
labelList addr(boundaryFacesToRemove.used());
labelList addr(boundaryFacesToRemove.toc());
faceSet indirectPatchFaces
(

View File

@ -496,7 +496,7 @@ void Foam::CV2D::newPoints()
scalar u = 1.0;
scalar l = 0.7;
PackedBoolList pointToBeRetained(startOfSurfacePointPairs_, true);
bitSet pointToBeRetained(startOfSurfacePointPairs_, true);
std::list<Point> pointsToInsert;

View File

@ -122,7 +122,7 @@ SourceFiles
#include "point2DFieldFwd.H"
#include "dictionary.H"
#include "Switch.H"
#include "PackedBoolList.H"
#include "bitSet.H"
#include "EdgeMap.H"
#include "cv2DControls.H"
#include "tolerances.H"

View File

@ -306,7 +306,7 @@ void Foam::mergeAndWrite
// Determine faces on outside of cellSet
PackedBoolList isInSet(mesh.nCells());
bitSet isInSet(mesh.nCells());
forAllConstIter(cellSet, set, iter)
{
isInSet.set(iter.key());

View File

@ -660,7 +660,7 @@ Foam::label Foam::checkTopology
const cellList& cells = mesh.cells();
const faceList& faces = mesh.faces();
PackedBoolList isZonePoint(mesh.nPoints());
bitSet isZonePoint(mesh.nPoints());
for (const cellZone& cZone : cellZones)
{

View File

@ -192,7 +192,7 @@ void modifyOrAddFace
const label zoneID,
const bool zoneFlip,
PackedBoolList& modifiedFace
bitSet& modifiedFace
)
{
if (modifiedFace.set(facei))
@ -247,7 +247,7 @@ void createFaces
const labelList& newMasterPatches,
const labelList& newSlavePatches,
polyTopoChange& meshMod,
PackedBoolList& modifiedFace,
bitSet& modifiedFace,
label& nModified
)
{
@ -538,15 +538,13 @@ int main(int argc, char *argv[])
if (mesh.faceZones().findZoneID(name) == -1)
{
mesh.faceZones().clearAddressing();
label sz = mesh.faceZones().size();
const label zoneID = mesh.faceZones().size();
labelList addr(0);
boolList flip(0);
mesh.faceZones().setSize(sz+1);
mesh.faceZones().setSize(zoneID+1);
mesh.faceZones().set
(
sz,
new faceZone(name, addr, flip, sz, mesh.faceZones())
zoneID,
new faceZone(name, labelList(), false, zoneID, mesh.faceZones())
);
}
}
@ -604,7 +602,14 @@ int main(int argc, char *argv[])
mesh.faceZones().set
(
zoneID,
new faceZone(name, addr, flip, zoneID, mesh.faceZones())
new faceZone
(
name,
std::move(addr),
std::move(flip),
zoneID,
mesh.faceZones()
)
);
}
@ -751,7 +756,7 @@ int main(int argc, char *argv[])
// side come first and faces from the other side next.
// Whether first use of face (modify) or consecutive (add)
PackedBoolList modifiedFace(mesh.nFaces());
bitSet modifiedFace(mesh.nFaces());
label nModified = 0;
forAll(selectors, selectorI)

View File

@ -483,7 +483,7 @@ int main(int argc, char *argv[])
}
candidates.setCapacity(sz);
PackedBoolList isCandidate(mesh.nPoints());
bitSet isCandidate(mesh.nPoints());
forAll(splitPatchIDs, i)
{
const labelList& mp = patches[splitPatchIDs[i]].meshPoints();

View File

@ -87,7 +87,7 @@ int main(int argc, char *argv[])
const PackedBoolList isMasterFace(syncTools::getMasterFaces(mesh));
const bitSet isMasterFace(syncTools::getMasterFaces(mesh));
// Data on all edges and faces

View File

@ -146,7 +146,7 @@ Foam::label Foam::meshDualiser::findDualCell
void Foam::meshDualiser::generateDualBoundaryEdges
(
const PackedBoolList& isBoundaryEdge,
const bitSet& isBoundaryEdge,
const label pointi,
polyTopoChange& meshMod
)
@ -374,7 +374,7 @@ Foam::label Foam::meshDualiser::addBoundaryFace
void Foam::meshDualiser::createFacesAroundEdge
(
const bool splitFace,
const PackedBoolList& isBoundaryEdge,
const bitSet& isBoundaryEdge,
const label edgeI,
const label startFacei,
polyTopoChange& meshMod,
@ -886,7 +886,7 @@ void Foam::meshDualiser::setRefinement
// Mark boundary edges and points.
// (Note: in 1.4.2 we can use the built-in mesh point ordering
// facility instead)
PackedBoolList isBoundaryEdge(mesh_.nEdges());
bitSet isBoundaryEdge(mesh_.nEdges());
for (label facei = mesh_.nInternalFaces(); facei < mesh_.nFaces(); facei++)
{
const labelList& fEdges = mesh_.faceEdges()[facei];

View File

@ -48,7 +48,7 @@ SourceFiles
#define meshDualiser_H
#include "DynamicList.H"
#include "PackedBoolList.H"
#include "bitSet.H"
#include "boolList.H"
#include "typeInfo.H"
@ -100,7 +100,7 @@ class meshDualiser
// emanating from (boundary & feature) point
void generateDualBoundaryEdges
(
const PackedBoolList& isBoundaryEdge,
const bitSet& isBoundaryEdge,
const label pointi,
polyTopoChange& meshMod
);
@ -143,7 +143,7 @@ class meshDualiser
void createFacesAroundEdge
(
const bool splitFace,
const PackedBoolList& isBoundaryEdge,
const bitSet& isBoundaryEdge,
const label edgeI,
const label startFacei,
polyTopoChange& meshMod,

View File

@ -67,7 +67,7 @@ Note
#include "unitConversion.H"
#include "polyTopoChange.H"
#include "mapPolyMesh.H"
#include "PackedBoolList.H"
#include "bitSet.H"
#include "meshTools.H"
#include "OFstream.H"
#include "meshDualiser.H"
@ -87,7 +87,7 @@ using namespace Foam;
void simpleMarkFeatures
(
const polyMesh& mesh,
const PackedBoolList& isBoundaryEdge,
const bitSet& isBoundaryEdge,
const scalar featureAngle,
const bool concaveMultiCells,
const bool doNotPreserveFaceZones,
@ -390,7 +390,7 @@ int main(int argc, char *argv[])
// Mark boundary edges and points.
// (Note: in 1.4.2 we can use the built-in mesh point ordering
// facility instead)
PackedBoolList isBoundaryEdge(mesh.nEdges());
bitSet isBoundaryEdge(mesh.nEdges());
for (label facei = mesh.nInternalFaces(); facei < mesh.nFaces(); facei++)
{
const labelList& fEdges = mesh.faceEdges()[facei];

View File

@ -79,7 +79,7 @@ void printEdgeStats(const polyMesh& mesh)
scalar minOther = GREAT;
scalar maxOther = -GREAT;
PackedBoolList isMasterEdge(syncTools::getMasterEdges(mesh));
bitSet isMasterEdge(syncTools::getMasterEdges(mesh));
const edgeList& edges = mesh.edges();

View File

@ -303,7 +303,7 @@ void subsetTopoSets
Info<< "Subsetting " << set.type() << " " << set.name() << endl;
// Map the data
PackedBoolList isSet(set.maxSize(mesh));
bitSet isSet(set.maxSize(mesh));
forAllConstIters(set, iter)
{
isSet.set(iter.key());

View File

@ -32,7 +32,7 @@ Description
#include "domainDecomposition.H"
#include "IOstreams.H"
#include "boolList.H"
#include "bitSet.H"
#include "cyclicPolyPatch.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -434,7 +434,6 @@ void Foam::domainDecomposition::decomposeMesh()
// }
Info<< "\nDistributing points to processors" << endl;
// For every processor, loop through the list of faces for the processor.
// For every face, loop through the list of points and mark the point as
@ -443,42 +442,19 @@ void Foam::domainDecomposition::decomposeMesh()
forAll(procPointAddressing_, proci)
{
boolList pointLabels(nPoints(), false);
bitSet pointsInUse(nPoints(), false);
// Get reference to list of used faces
const labelList& procFaceLabels = procFaceAddressing_[proci];
forAll(procFaceLabels, facei)
// For each of the faces used
for (const label facei : procFaceAddressing_[proci])
{
// Because of the turning index, some labels may be negative
const labelList& facePoints = fcs[mag(procFaceLabels[facei]) - 1];
// Because of the turning index, some face labels may be -ve
const labelList& facePoints = fcs[mag(facei) - 1];
forAll(facePoints, pointi)
{
// Mark the point as used
pointLabels[facePoints[pointi]] = true;
}
// Mark the face points as being used
pointsInUse.setMany(facePoints);
}
// Collect the used points
labelList& procPointLabels = procPointAddressing_[proci];
procPointLabels.setSize(pointLabels.size());
label nUsedPoints = 0;
forAll(pointLabels, pointi)
{
if (pointLabels[pointi])
{
procPointLabels[nUsedPoints] = pointi;
nUsedPoints++;
}
}
// Reset the size of used points
procPointLabels.setSize(nUsedPoints);
procPointAddressing_[proci] = pointsInUse.sortedToc();
}
}

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"))
{