Commit Graph

19320 Commits

Author SHA1 Message Date
4b0d1632b6 BUG: hashtable key_iterator ++ operator returning incorrect type
ENH: ensure std::distance works with hashtable iterators
2017-05-14 16:58:47 +02:00
0c53a815ed ENH: avoid std::distance for std::initializer_list
- std::initializer_list has its own size() method, so no need to use
  std::distance.

STYLE/BUG: use separate iterator de-reference and increment in List

- avoids unnecessary copying of iterators, and avoids any potentially
  odd behaviour with the combination with incrementing.

ENH: support construct from iterator pair for DynamicList, SortableList
2017-05-14 16:28:21 +02:00
83669e284f ENH: improvements to labelRange const_iterator
- inherit from std::iterator to obtain the full STL typedefs, meaning
  that std::distance works and the following is now possible:

      labelRange range(100, 1500);
      scalarList list(range.begin(), range.end());

  --
  Note that this does not work (mismatched data-types):

      scalarList list = identity(12345);

  But this does, since the *iter promotes label to scalar:

      labelList ident = identity(12345);
      scalarList list(ident.begin(), ident.end());

  It is however more than slightly wasteful to create a labelList
  just for initializing a scalarList. An alternative could be a
  a labelRange for the same purpose.

      labelRange ident = labelRange::identity(12345);
      scalarList list(ident.begin(), ident.end());

  Or this
      scalarList list
      (
          labelRange::null.begin(),
          labelRange::identity(12345).end()
      );
2017-05-14 14:39:17 +02:00
0e7b135181 STYLE: adjust const access for linked-list iterators 'operator*'
- provides const/non-const access to the underlying list, but the
  iterator access itself is const.

- provide linked-list iterator 'found()' method for symmetry with
  hash-table iterators. Use nullptr for more clarity.
2017-05-12 12:26:28 +02:00
f73b5b629f ENH: added HashTable 'lookup' and 'retain' methods
- lookup(): with a default value (const access)
  For example,
      Map<label> something;
      value = something.lookup(key, -1);

    being equivalent to the following:

      Map<label> something;
      value = -1;  // bad value
      if (something.found(key))
      {
          value = something[key];
      }

    except that lookup also makes it convenient to handle const references.
    Eg,

      const labelList& ids = someHash.lookup(key, labelList());

- For consistency, provide a two parameter HashTable '()' operator.
  The lookup() method is, however, normally preferable when
  const-only access is to be ensured.

- retain(): the counterpart to erase(), it only retains entries
  corresponding to the listed keys.

  For example,
      HashTable<someType> largeCache;
      wordHashSet preserve = ...;

      largeCache.retain(preserve);

    being roughly equivalent to the following two-stage process,
    but with reduced overhead and typing, and fewer potential mistakes.

      HashTable<someType> largeCache;
      wordHashSet preserve = ...;

      {
          wordHashSet cull(largeCache.toc()); // all keys
          cull.erase(preserve);               // except those to preserve
          largeCache.erase(cull);             //
      }

  The HashSet &= operator and retain() are functionally equivalent,
  but retain() also works with dissimilar value types.
2017-05-11 12:25:35 +02:00
8728e8353f STYLE: avoid explicit use of 'word' as HashTable template parameter
- less clutter and typing to use the default template parameter when
  the key is 'word' anyhow.

- use EdgeMap instead of the longhand HashTable version where
  appropriate
2017-05-10 13:44:27 +02:00
4d126bfe2d ENH: add dictionary optionalSubDict() method as per .org change (20-Apr) 2017-05-10 12:51:21 +02:00
cd8083eb95 Merge branch 'feature-consistency-face-access' into 'develop'
Feature consistency face access

See merge request !109
2017-05-08 10:58:42 +01:00
46a1fed97b Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop 2017-05-08 10:51:24 +01:00
134f7abd57 ENH: checkMesh: output vol fields of mesh quality. Fixes #466. 2017-05-08 10:50:59 +01:00
708c1b5c41 ENH: simplify ensightCells/ensightFaces with labelRange
- can avoid allocating/reallocating SubList

STYLE: don't need NamedEnum for ensightCells, ensightFaces lookup
2017-05-08 11:21:44 +02:00
b4f6484ddf ENH: use faceTraits for managing differences between face representations 2017-05-07 16:58:44 +02:00
0c4d2bcd76 ENH: improve consistency in access for face, triFace, edge.
- ensure that each have found() and which() methods

- add faceTraits for handling compile-time differences between
  'normal' and tri-faces

- provide line::unitVec method (complimentary to edge::unitVec)
2017-05-07 15:49:52 +02:00
c872b0f13f Merge remote-tracking branch '1612/master' into develop 2017-05-05 10:20:02 +02:00
f895c934e7 COMP: skip compilation of plugins if include files are missing (fixes #464) 2017-05-05 10:14:48 +02:00
8006d64d74 COMP: skip compilation of plugins if include files are missing (fixes #464) 2017-05-05 10:02:34 +02:00
cd6221664f Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop 2017-05-04 17:50:33 +01:00
4b7c74f8eb BUG: sampledPlane: fix parallel running on subset. Fixes #463. 2017-05-04 17:50:07 +01:00
97b6475877 Merge branch 'feature-improved-container-classes' into 'develop'
improved container classes

See merge request !108
2017-05-04 16:48:57 +01:00
6747d14dfa BUG: odd table size after shrink (issue #460)
- remove this unused method
2017-05-04 13:11:46 +02:00
7edd801c72 BUG: wall/patch distance and inverseDistanceDiffusivity - updated dimensions and use meshWave as a default method for backwards compatibility. Fixes #462 2017-05-04 11:33:00 +01:00
8dae01913c ENH: regex matching on std::string, not Foam::string
- avoids unneeded promotion of types.
  Easier to switch regex engines in the future.
2017-05-04 12:31:49 +02:00
03d180724b ENH: improve HashTable iterator access and management
- provide key_iterator/const_key_iterator for all hashes,
  reuse directly for HashSet as iterator/const_iterator, respectively.

- additional keys() method for HashTable that returns a wrapped to
  a pair of begin/end const_iterators with additional size/empty
  information that allows these to be used directly by anything else
  expecting things with begin/end/size. Unfortunately does not yet
  work with std::distance().

  Example,
     for (auto& k : labelHashTable.keys())
     {
        ...
     }
2017-05-04 10:17:18 +02:00
759306a3e2 STYLE: more consistent typedefs in Map, PtrMap, HashPtrTable 2017-05-04 02:47:32 +02:00
e105e30bfb STYLE: add edge(labelPair) constructor, debug info etc. 2017-05-04 02:42:50 +02:00
f7e502d459 STYLE: relocate some friend operations to be global ones 2017-05-04 02:39:57 +02:00
5d541defe6 ENH: simplify and extend labelRange
- add increment/decrement, repositioning. Simplify const_iterator.

- this makes is much easier to use labelRange for constructing ranges of
  sub-lists. For symmetry with setSize() it has a setStart() instead of
  simply assigning to start() directly. This would also provide the
  future possibility to imbue the labelRange with a particular policy
  (eg, no negative starts, max size etc) and ensure that they are
  enforced.

  A simple use case:

    // initialize each to zero...
    List<labelRange> subListRanges = ...;

    // scan and categorize
    if (condition)
       subListRanges[categoryI]++;  // increment size for that category

    // finally, set the starting points
    start = 0;
    for (labelRange& range : subListRanges)
    {
        range.setStart(start);
        start += range.size();
    }
2017-05-04 02:19:01 +02:00
c9df5f9249 Merge branch 'dict-lookup' into 'develop'
Dict lookup

See merge request !105
2017-05-02 16:37:57 +01:00
a8e3482591 Merge branch 'edge-labelPair-containers' into 'develop'
Use updated edge and labelPair containers

See merge request !106
2017-05-02 16:35:54 +01:00
45c29be341 COMP: avoid clang compiler warnings 2017-05-02 13:33:40 +02:00
1dc3236825 BUG: fixed odd sizing for hash tables (fixes #460) 2017-05-02 12:31:52 +02:00
f8c58bdd5c ENH: HashSet iterators operator* now return Key.
- much more useful than returning nil. Can now use with a for range:

    for (auto i : myLabelHashSet)
    {
        ...
    }
2017-05-02 01:58:38 +02:00
8f75bfbed5 ENH: add HashTable::writeKeys and HashSet::writeList
- can use the hash-set writeList in combination with FlatOutput:

  Eg, flatOutput(myHashSet);
2017-05-02 00:51:04 +02:00
c0a50dc621 ENH: improve overall consistency of the HashTable and its iterators
- previously had a mismash of const/non-const attributes on iterators
  that were confused with the attributes of the object being accessed.

- use the iterator keys() and object() methods consistently for all
  internal access of the HashTable iterators. This makes the intention
  clearer, the code easier to maintain, and protects against any
  possible changes in the definition of the operators.

- 'operator*': The standard form expected by STL libraries.
  However, for the std::map, this dereferences to a <key,value> pair,
  whereas OpenFOAM dereferences simply to <value>.

- 'operator()': OpenFOAM treats this like the 'operator*'

- adjusted the values of end() and cend() to reinterpret from nullObject
  instead of returning a static iteratorEnd() object.
  This means that C++ templates can now correctly deduce and match
  the return types from begin() and end() consistently.
  So that range-based now works.

  Eg,
      HashTable<label> table1 = ...;
      for (auto i : table1)
      {
          Info<< i << endl;
      }

  Since the 'operator*' returns hash table values, this prints all the
  values in the table.
2017-05-02 00:15:12 +02:00
0298c02b2d ENH: ensure nullObject is large enough for reinterpret
- previously occupied 1 byte. Now occupies enough to hold a pointer,
  which helps if using reinterpret_cast to something that has some
  member content.
2017-05-01 22:39:36 +02:00
7cceda620d BUG: comparison to static end() for hashtable lookup.
- just use the iterator method found() as an alternative and
  convenient way to avoid the issue with less typing.
2017-05-01 21:28:41 +02:00
dc57c016ae BUG: comparison with incorrect construction tables
- previously hidden when hashtable used a static method and a
  different class for end()
2017-05-01 21:27:42 +02:00
805b76d4b9 ENH: support UList[labelRange] and SubList construction with labelRange
This uses a concept similar to what std::valarray and std::slice do.
A labelRange provides a convenient container for holding start/size
and lends itself to addressing 'sliced' views of lists.
For safety, the operations and constructors restricts the given input range
to a valid addressible region of the underlying list, while the labelRange
itself precludes negative sizes.

The SubList version is useful for patches or other things that have a
SubList as its parameter. Otherwise the UList [] operator will be the
more natural solution. The slices can be done with a labelRange, or
a {start,size} pair.

Examples,
     labelList list1 = identity(20);

     list1[labelRange(18,10)]  = -1;
     list1[{-20,25}] = -2;
     list1[{1000,5}] = -3;

     const labelList list2 = identity(20);
     list2[{5,10}] = -3;  // ERROR: cannot assign to const!
2017-05-01 14:01:09 +02:00
75ef6f4e50 ENH: add labelRange comparison operators and subset methods
- improve interface consistency.
2017-04-30 21:29:24 +02:00
7b427c382e ENH: add Tuple2 comparison operators, typedefs 2017-04-30 13:05:49 +02:00
5d6bf3e43d ENH: HashTable improvements
- optimize erasure using different HashTable based on its size.
  Eg, hashtable.erase(other);

  If 'other' is smaller than the hashtable, it is more efficient to
  use the keys from other to remove from the hashtable.

  Otherwise simply iterate over the hashtable and remove it if
  that key was found in other.
2017-04-30 10:21:10 +02:00
c65e2e580d ENH: add some standard templates and macros into stdFoam.H
- some functionality similar to what the standary library <iterator>
  provides.

  * stdFoam::begin() and stdFoam::end() do type deduction,
    which means that many cases it is possible to manage these types
    of changes.

    For example, when managing a number of indices:
       Map<labelHashSet> lookup;

    1) Longhand:

        for
        (
            Map<labelHashSet>::const_iterator iter = lookup.begin();
            iter != lookup.end();
            ++iter
        )
        { .... }

    1b) The same, but wrapped via a macro:

        forAllConstIter(Map<labelHashSet>, lookup, iter)
        { .... }

    2) Using stdFoam begin/end templates directly

        for
        (
            auto iter = stdFoam::begin(lookup);
            iter != stdFoam::end(lookup);
            ++iter
        )
        { .... }

    2b) The same, but wrapped via a macro:

        forAllConstIters(lookup, iter)
        { .... }

Note that in many cases it is possible to simply use a range-based for.
Eg,
     labelList myList;

     for (auto val : myList)
     { ... }

     for (const auto& val : myList)
     { ... }

These however will not work with any of the OpenFOAM hash-tables,
since the standard C++ concept of an iterator would return a key,value
pair when deferencing the *iter.

The deduction methods also exhibits some slightly odd behaviour with
some PtrLists (needs some more investigation).
2017-04-29 22:28:16 +02:00
6a5ea9a2bf ENH: improve HashSet construction and assignment
- make construct from UList explicit and provide corresponding
  assignment operator.

- add construct,insert,set,assignment from FixedList.
  This is convenient when dealing with things like edges or triFaces.
2017-04-29 15:19:47 +02:00
a2ddf7dd48 ENH: support HashTable erasure via a FixedList
- propagate common erasure methods as HashSet::unset() method,
  for symmetry with HashSet::set()
2017-04-29 14:50:46 +02:00
ded105c539 STYLE: HashTable documentation
- explicitly mention the value-initialized status for the operator().
  This means that the following code will properly use an initialized
  zero.

      HashTable<label> regionCount;

      if (...)
         regionCount("region1")++;

      ... and also this;

      if (regionCount("something") > 0)
      {
          ...
      }

  Note that the OpenFOAM HashTable uses operator[] to provide read and
  write access to *existing* entries and will provoke a FatalError if
  the entry does not exist.

  The operator() provides write access to *existing* entries or will
  create the new entry as required.
  The STL hashes use operator[] for this purpose.
2017-04-29 12:27:11 +02:00
1d9b311b82 ENH: further refinement to edge methods
- more hash-like methods.
  Eg, insert/erase via lists, clear(), empty(),...

- minVertex(), maxVertex() to return the smallest/largest label used

- improved documentation, more clarification about where/how negative
  point labels are treated.
2017-04-29 12:14:46 +02:00
1a24be6e54 Merge branch 'feature-random-numbers' into 'develop'
Updated random numbers

See merge request !107
2017-04-28 10:11:18 +01:00
0b42024c98 ENH: turbulentDFSEMInlet - ensure different procs initialise the random number generator with a different seed 2017-04-28 10:01:43 +01:00
7f0cc0045d ENH: Random numbers - updated dependent code from change cachedRandom->Random class 2017-04-28 09:15:52 +01:00
b07bc1f0b8 ENH: Random numbers - consolidated Random classes
- old Random class deprecated
- cachedRandom renamed Random
2017-04-28 09:07:42 +01:00