SPH
Derivative.h
Go to the documentation of this file.
1 #pragma once
2 
7 
10 #include "quantities/Storage.h"
12 #include "system/Profiler.h"
13 #include "system/Settings.h"
14 #include <typeinfo>
15 
17 
18 
28 enum class DerivativePhase {
30  PRECOMPUTE,
31 
34  EVALUATION,
35 };
36 
43 class IDerivative : public Polymorphic {
44 public:
48  virtual void create(Accumulated& results) = 0;
49 
57  virtual void initialize(const Storage& input, Accumulated& results) = 0;
58 
67  virtual void evalNeighs(const Size idx, ArrayView<const Size> neighs, ArrayView<const Vector> grads) = 0;
68 
74  virtual DerivativePhase phase() const = 0;
75 
81  virtual bool equals(const IDerivative& other) const {
82  return typeid(*this) == typeid(other);
83  }
84 };
85 
91 public:
106  virtual void evalSymmetric(const Size idx,
107  ArrayView<const Size> neighs,
108  ArrayView<const Vector> grads) = 0;
109 
115  virtual DerivativePhase phase() const final {
117  }
118 };
119 
125 public:
142  virtual void evalAcceleration(const Size idx,
143  ArrayView<const Size> neighs,
145  ArrayView<Vector> dv) = 0;
146 };
147 
148 
149 class CorrectionTensor final : public IDerivative {
150 private:
153  ArrayView<const Float> reduce;
154  ArrayView<const Float> m, rho;
156 
157  bool sumOnlyUndamaged;
158 
159 public:
160  explicit CorrectionTensor(const RunSettings& settings);
161 
162  virtual void create(Accumulated& results) override;
163 
164  virtual void initialize(const Storage& input, Accumulated& results) override;
165 
166  virtual void evalNeighs(Size i, ArrayView<const Size> neighs, ArrayView<const Vector> grads) override;
167 
168  virtual DerivativePhase phase() const override;
169 };
170 
171 
174 private:
175  Accumulated accumulated;
176 
177  struct Less {
178  INLINE bool operator()(const AutoPtr<IDerivative>& d1, const AutoPtr<IDerivative>& d2) const {
179  if (d1->phase() != d2->phase()) {
180  // sort primarily by phases
181  return d1->phase() < d2->phase();
182  }
183  // used sorting of pointers for order within the same phase
184  return &*d1 < &*d2;
185  }
186  };
187 
194  FlatSet<AutoPtr<IDerivative>, Less> derivatives;
195 
197  bool needsCreate = true;
198 
199 public:
205  virtual void require(AutoPtr<IDerivative>&& derivative);
206 
208  virtual void initialize(const Storage& input);
209 
211  void eval(const Size idx, ArrayView<const Size> neighs, ArrayView<const Vector> grads);
212 
218  void evalSymmetric(const Size idx, ArrayView<const Size> neighs, ArrayView<const Vector> grads);
219 
224  bool isSymmetric() const;
225 
227  return accumulated;
228  }
229 
231  return derivatives.size();
232  }
233 };
234 
Buffer storing quantity values accumulated by summing over particle pairs.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
DerivativePhase
Defines the phases of derivative evaluation.
Definition: Derivative.h:28
@ PRECOMPUTE
Auxiliary quantities needed for evaluation of other derivatives (grad-h, correction tensor,...
Container storing sorted unique values.
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
#define INLINE
Macros for conditional compilation based on selected compiler.
Definition: Object.h:31
#define NAMESPACE_SPH_END
Definition: Object.h:12
Tool to measure time spent in functions and profile the code.
Container for storing particle quantities and materials.
Basic vector algebra. Computations are accelerated using SIMD.
Storage for accumulating derivatives.
Definition: Accumulated.h:30
Wrapper of pointer that deletes the resource from destructor.
Definition: AutoPtr.h:15
CorrectionTensor(const RunSettings &settings)
Definition: Derivative.cpp:8
virtual void create(Accumulated &results) override
Emplace all needed buffers into shared storage.
Definition: Derivative.cpp:17
virtual void initialize(const Storage &input, Accumulated &results) override
Initialize derivative before iterating over neighbours.
Definition: Derivative.cpp:22
virtual DerivativePhase phase() const override
Returns the phase of the derivative.
Definition: Derivative.cpp:12
virtual void evalNeighs(Size i, ArrayView< const Size > neighs, ArrayView< const Vector > grads) override
Compute derivatives of given particle.
Definition: Derivative.cpp:36
Container holding derivatives and the storage they accumulate to.
Definition: Derivative.h:173
virtual void require(AutoPtr< IDerivative > &&derivative)
Adds derivative if not already present.
Definition: Derivative.cpp:77
void evalSymmetric(const Size idx, ArrayView< const Size > neighs, ArrayView< const Vector > grads)
Evaluates all held derivatives symetrically for given particle pairs.
Definition: Derivative.cpp:120
void eval(const Size idx, ArrayView< const Size > neighs, ArrayView< const Vector > grads)
Evaluates all held derivatives for given particle.
Definition: Derivative.cpp:113
INLINE Accumulated & getAccumulated()
Definition: Derivative.h:226
bool isSymmetric() const
Returns true if all stored derivatives are symmetric.
Definition: Derivative.cpp:131
INLINE Size getDerivativeCnt() const
Definition: Derivative.h:230
virtual void initialize(const Storage &input)
Initialize derivatives before loop.
Definition: Derivative.cpp:96
INLINE Size size() const
Definition: FlatSet.h:28
Extension of derivative allowing to compute pair-wise acceleration for each neighbour.
Definition: Derivative.h:124
virtual void evalAcceleration(const Size idx, ArrayView< const Size > neighs, ArrayView< const Vector > grads, ArrayView< Vector > dv)=0
Computes the pair-wise accelerations of given particle and its neighbours.
Derivative accumulated by summing up neighbouring particles.
Definition: Derivative.h:43
virtual bool equals(const IDerivative &other) const
Returns true if this derivative is equal to the given derivative.
Definition: Derivative.h:81
virtual DerivativePhase phase() const =0
Returns the phase of the derivative.
virtual void create(Accumulated &results)=0
Emplace all needed buffers into shared storage.
virtual void evalNeighs(const Size idx, ArrayView< const Size > neighs, ArrayView< const Vector > grads)=0
Compute derivatives of given particle.
virtual void initialize(const Storage &input, Accumulated &results)=0
Initialize derivative before iterating over neighbours.
Extension of derivative, allowing a symmetrized evaluation.
Definition: Derivative.h:90
virtual DerivativePhase phase() const final
Symmetric derivatives are always in EVALUATION phase.
Definition: Derivative.h:115
virtual void evalSymmetric(const Size idx, ArrayView< const Size > neighs, ArrayView< const Vector > grads)=0
Compute a part of derivatives from interaction of particle pairs.
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Generic storage and input/output routines of settings.
Base class for all polymorphic objects.
Definition: Object.h:88