SPH
Accumulated.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "common/ForwardDecl.h"
12 #include "quantities/QuantityIds.h"
13 
15 
16 enum class OrderEnum;
17 
18 enum class BufferSource {
20  UNIQUE,
21 
23  SHARED,
24 };
25 
30 class Accumulated {
31 private:
32  template <typename... TArgs>
34 
36 
37  struct Element {
39  QuantityId id;
40 
42  OrderEnum order;
43 
45  Buffer buffer;
46  };
47  Array<Element> buffers;
48 
49  struct QuantityRecord {
50  QuantityId id;
51  bool unique;
52  };
53 
55  Array<QuantityRecord> records;
56 
57 public:
67  template <typename TValue>
68  void insert(const QuantityId id, const OrderEnum order, const BufferSource source);
69 
73  void initialize(const Size size);
74 
80  template <typename TValue>
81  Array<TValue>& getBuffer(const QuantityId id, const OrderEnum order);
82 
87  void sum(ArrayView<Accumulated*> others);
88 
90  void sum(IScheduler& scheduler, ArrayView<Accumulated*> others);
91 
97  void store(Storage& storage);
98 
99  Size getBufferCnt() const;
100 
101 private:
102  template <typename Type>
103  Array<Iterator<Type>> getBufferIterators(const QuantityId id, ArrayView<Accumulated*> others);
104 
105  template <typename Type>
106  void sumBuffer(Array<Type>& buffer1, const QuantityId id, ArrayView<Accumulated*> others);
107 
108  template <typename Type>
109  void sumBuffer(IScheduler& scheduler,
110  Array<Type>& buffer1,
111  const QuantityId id,
112  ArrayView<Accumulated*> others);
113 
114  bool hasBuffer(const QuantityId id, const OrderEnum order) const;
115 };
116 
117 
BufferSource
Definition: Accumulated.h:18
@ SHARED
Multiple derivatives may accumulate into the buffer.
@ UNIQUE
Only a single derivative accumulates to this buffer.
Generic dynamically allocated resizable storage.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
#define NAMESPACE_SPH_END
Definition: Object.h:12
Quantity identifiers.
QuantityId
Unique IDs of basic quantities of SPH particles.
Definition: QuantityIds.h:19
OrderEnum
Definition: Quantity.h:15
Symmetric traceless 2nd order tensor.
Object capable of storing values of different types.
Storage for accumulating derivatives.
Definition: Accumulated.h:30
void initialize(const Size size)
Initialize all storages.
Definition: Accumulated.cpp:37
void sum(ArrayView< Accumulated * > others)
Sums values of a list of storages.
Definition: Accumulated.cpp:71
Array< TValue > & getBuffer(const QuantityId id, const OrderEnum order)
Returns the buffer of given quantity and given order.
Definition: Accumulated.cpp:53
Size getBufferCnt() const
void store(Storage &storage)
Stores accumulated values to corresponding quantities.
Definition: Accumulated.cpp:86
void insert(const QuantityId id, const OrderEnum order, const BufferSource source)
Creates a new storage with given ID.
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Variant, an implementation of type-safe union, similar to std::variant or boost::variant.
Definition: Variant.h:171