SPH
HashMapFinder.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "math/Means.h"
10 #include "objects/geometry/Box.h"
11 #include "system/Settings.h"
12 #include <unordered_map>
13 
15 
16 class HashMapFinder : public FinderTemplate<HashMapFinder> {
17 public:
18  struct Cell {
21 
22  Cell();
23  ~Cell();
24  };
25 
26 private:
27  std::unordered_map<Indices, Cell, std::hash<Indices>, IndicesEqual> map;
28  Float cellSize;
29  Float kernelRadius;
30  Float cellMult;
31 
32 public:
33  HashMapFinder(const RunSettings& settings, const Float cellMult = 1._f);
34 
36 
37  template <bool FindAll>
38  Size find(const Vector& pos, const Size index, const Float radius, Array<NeighbourRecord>& neighs) const;
39 
40  template <typename TFunctor>
41  void iterate(const TFunctor& func) const {
42  for (auto& p : map) {
43  Vector lower = Vector(p.first) * cellSize;
44  // lower += (Vector(-1._f) - Vector(p.first < Indices(0))) * cellSize;
45  const Box box(lower, lower + Vector(Indices(1, 1, 1)) * cellSize);
46  func(p.second, box);
47  }
48  }
49 
50 
51  Outcome good() const {
52  for (Size i = 0; i < map.bucket_count(); ++i) {
53  if (map.bucket_size(i) > 15) {
54  return makeFailed(
55  "Inefficient hash map: Bucket ", i, " has ", map.bucket_size(i), " elements");
56  }
57  }
58  return SUCCESS;
59  }
60 
62  MinMaxMean stats;
63  for (Size i = 0; i < map.bucket_count(); ++i) {
64  stats.accumulate(map.bucket_size(i));
65  }
66  return stats;
67  }
68 
69 protected:
70  virtual void buildImpl(IScheduler& scheduler, ArrayView<const Vector> points) override;
71 };
72 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Object representing a three-dimensional axis-aligned box.
const float radius
Definition: CurveDialog.cpp:18
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
Computing minimum, maximum and mean value of floats.
#define NAMESPACE_SPH_END
Definition: Object.h:12
const SuccessTag SUCCESS
Global constant for successful outcome.
Definition: Outcome.h:141
INLINE Outcome makeFailed(TArgs &&... args)
Constructs failed object with error message.
Definition: Outcome.h:157
BasicVector< Float > Vector
Definition: Vector.h:539
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
Helper object defining three-dimensional interval (box).
Definition: Box.h:17
Helper template, allowing to define all three functions with a single function.
virtual void buildImpl(IScheduler &scheduler, ArrayView< const Vector > points) override
Builds finder from set of vectors.
MinMaxMean getBucketStats() const
Definition: HashMapFinder.h:61
HashMapFinder(const RunSettings &settings, const Float cellMult=1._f)
Outcome good() const
Definition: HashMapFinder.h:51
Size find(const Vector &pos, const Size index, const Float radius, Array< NeighbourRecord > &neighs) const
void iterate(const TFunctor &func) const
Definition: HashMapFinder.h:41
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Helper object for storing three (possibly four) int or bool values.
Definition: Indices.h:16
Helper class for statistics, accumulating minimal, maximal and mean value of a set of numbers.
Definition: Means.h:172
INLINE void accumulate(const Float value)
Definition: Means.h:180
Generic storage and input/output routines of settings.
Array< Size > points
Definition: HashMapFinder.h:19