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

@ -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;