SPH
Statistics.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "common/ForwardDecl.h"
9 #include "math/Means.h"
14 #include "quantities/QuantityIds.h"
15 
17 
22 class Statistics {
23 private:
24  enum Types { BOOL, INT, FLOAT, MEANS, VALUE, INTERVAL };
25 
27 
29 
30 public:
31  Statistics() = default;
32 
33  Statistics(const Statistics& other)
34  : entries(other.entries.clone()) {}
35 
36  Statistics& operator=(const Statistics& other) {
37  entries = other.entries.clone();
38  return *this;
39  }
40 
44  bool has(const StatisticsId idx) const {
45  return entries.contains(idx);
46  }
47 
51  template <typename TValue>
52  Statistics& set(const StatisticsId idx, TValue&& value) {
53  using StoreType = ConvertToSize<TValue>;
54  entries.insert(idx, StoreType(std::forward<TValue>(value)));
55  return *this;
56  }
57 
61  void increment(const StatisticsId idx, const Size amount) {
62  if (entries.contains(idx)) {
63  entries[idx].template get<int>() += amount;
64  } else {
65  entries.insert(idx, int(amount));
66  }
67  }
68 
73  void accumulate(const StatisticsId idx, const Float value) {
74  Optional<ValueType&> entry = entries.tryGet(idx);
75  if (entry) {
76  entry->template get<MinMaxMean>().accumulate(value);
77  } else {
78  MinMaxMean means;
79  means.accumulate(value);
80  entries.insert(idx, means);
81  }
82  }
83 
85 
87  template <typename TValue>
88  TValue get(const StatisticsId idx) const {
89  Optional<const ValueType&> entry = entries.tryGet(idx);
90  SPH_ASSERT(entry, int(idx));
91  using StoreType = ConvertToSize<TValue>;
92  const StoreType& value = entry->template get<StoreType>();
93  return TValue(value);
94  }
95 
97  template <typename TValue>
98  TValue getOr(const StatisticsId idx, const TValue& other) const {
99  if (this->has(idx)) {
100  return this->get<TValue>(idx);
101  } else {
102  return other;
103  }
104  }
105 };
106 
108 enum class StatisticsId {
110  INDEX,
111 
113  RUN_TIME,
114 
117 
121 
123  ETA,
124 
127 
130 
133 
136 
139 
142 
145 
148 
151 
154 
157 
160 
163 
165  MERGER_COUNT,
166 
168  BOUNCE_COUNT,
169 
172 
175 
178 
180  FRAME_ANGLE,
181 
184 
187 
190 
193 
196 
199 };
200 
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Object holding a single values of various types.
Key-value associative container implemented as a sorted array.
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
Object representing interval of real values.
Computing minimum, maximum and mean value of floats.
#define NAMESPACE_SPH_END
Definition: Object.h:12
@ INDEX
Index of particle.
Quantity identifiers.
StatisticsId
List of values that are computed and displayed every timestep.
Definition: Statistics.h:108
@ NEIGHBOUR_COUNT
Number of neighbours (min, max, mean)
@ LIMITING_PARTICLE_IDX
Index of particle that currently limits the timestep.
@ COLLISION_EVAL_TIME
Wallclock duration of collision evaluation.
@ WALLCLOCK_TIME
Current wallclock duration of the simulation.
@ SPH_EVAL_TIME
Wallclock duration of evaluation of SPH derivatives.
@ BREAKUP_COUNT
Number of fragmentation collisions.
@ GRAVITY_NODES_APPROX
Number of tree nodes evaluated using multipole approximation.
@ LIMITING_VALUE
Quantity value of particle that currently limits the timestep.
@ LIMITING_QUANTITY
Quantity that currently limits the timestep.
@ POSTPROCESS_EVAL_TIME
Wallclock spent on data dump, particle visualization, etc.
@ ETA
Estimated wallclock time to the end of the simulation.
@ GRAVITY_NODE_COUNT
Number of nodes in used gravity tree.
@ LIMITING_DERIVATIVE
Derivative value of particle that currently limits the timestep.
@ GRAVITY_NODES_EXACT
Number of tree nodes evaluated by pair-wise interacting.
@ FRAME_ANGLE
Current angular position of the non-inertial frame.
@ RUN_TIME
Current time of the simulation in code units. Does not necessarily have to be 0 when run starts.
@ TIMESTEP_VALUE
Current value of timestep.
@ AGGREGATE_COUNT
Number of aggregates in the simulation (single particles are not counted as aggregates).
@ SOLVER_SUMMATION_ITERATIONS
Number of iterations used to compute density and smoothing length in summation solver.
@ TIMESTEP_CRITERION
Criterion that currently limits the timestep.
@ TOTAL_COLLISION_COUNT
Number of collisions in the timestep.
@ OVERLAP_COUNT
Number of particle overlaps detected during collision evaluation.
@ TIMESTEP_ELAPSED
Wallclock time spend on computing last timestep.
@ GRAVITY_BUILD_TIME
Wallclock duration of gravity tree building.
@ MERGER_COUNT
Number of mergers in the timestep.
@ GRAVITY_EVAL_TIME
Wallclock duration of gravity evaluation.
@ BOUNCE_COUNT
Number of bounce collisions.
typename ConvertToSizeType< T >::Type ConvertToSize
Definition: Traits.h:197
Object capable of storing values of different types.
Container of key-value pairs.
Definition: FlatMap.h:19
INLINE bool contains(const TKey &key) const
Returns true if the map contains element of given key.
Definition: FlatMap.h:140
INLINE TValue & insert(const TKey &key, const TValue &value)
Adds a new element into the map or sets new value of element with the same key.
Definition: FlatMap.h:65
INLINE Optional< TValue & > tryGet(const TKey &key)
Returns a reference to the value matching the given key, or NOTHING if no such value exists.
Definition: FlatMap.h:118
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
Wrapper of type value of which may or may not be present.
Definition: Optional.h:23
Object holding various statistics about current run.
Definition: Statistics.h:22
TValue get(const StatisticsId idx) const
Returns value of a statistic.
Definition: Statistics.h:88
void increment(const StatisticsId idx, const Size amount)
Increments an integer statistic by given amount.
Definition: Statistics.h:61
void accumulate(const StatisticsId idx, const Float value)
Accumulate a value into means of given idx.
Definition: Statistics.h:73
Statistics & operator=(const Statistics &other)
Definition: Statistics.h:36
Statistics()=default
Statistics & set(const StatisticsId idx, TValue &&value)
Sets new values of a statistic.
Definition: Statistics.h:52
Statistics(const Statistics &other)
Definition: Statistics.h:33
TValue getOr(const StatisticsId idx, const TValue &other) const
Returns value of a statistic, or a given value if the statistic is not stored.
Definition: Statistics.h:98
bool has(const StatisticsId idx) const
Checks if the object contains a statistic with given ID.
Definition: Statistics.h:44
Variant, an implementation of type-safe union, similar to std::variant or boost::variant.
Definition: Variant.h:171