SPH
Integrals.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "common/ForwardDecl.h"
9 #include "math/Means.h"
13 #include "quantities/QuantityIds.h"
14 #include "system/Settings.h"
15 
17 
26 template <typename Type>
27 class IIntegral : public Polymorphic {
28 public:
33  virtual Type evaluate(const Storage& storage) const = 0;
34 
38  virtual std::string getName() const = 0;
39 };
40 
41 
49 class TotalMass : public IIntegral<Float> {
50 public:
51  virtual Float evaluate(const Storage& storage) const override;
52 
53  virtual std::string getName() const override {
54  return "Total mass";
55  }
56 };
57 
62 class TotalMomentum : public IIntegral<Vector> {
63 private:
64  Vector omega;
65 
66 public:
67  explicit TotalMomentum(const Float omega = 0._f);
68 
69  virtual Vector evaluate(const Storage& storage) const override;
70 
71  virtual std::string getName() const override {
72  return "Total momentum";
73  }
74 };
75 
81 class TotalAngularMomentum : public IIntegral<Vector> {
82 private:
83  Vector frameFrequency;
84 
85 public:
86  explicit TotalAngularMomentum(const Float frameFrequency = 0._f);
87 
88  virtual Vector evaluate(const Storage& storage) const override;
89 
90  virtual std::string getName() const override {
91  return "Total angular momentum";
92  }
93 };
94 
100 class TotalKineticEnergy : public IIntegral<Float> {
101 private:
102  Vector omega;
103 
104 public:
105  explicit TotalKineticEnergy(const Float omega = 0._f);
106 
107  virtual Float evaluate(const Storage& storage) const override;
108 
109  virtual std::string getName() const override {
110  return "Kinetic energy";
111  }
112 };
113 
119 class TotalInternalEnergy : public IIntegral<Float> {
120 public:
121  virtual Float evaluate(const Storage& storage) const override;
122 
123  virtual std::string getName() const override {
124  return "Internal energy";
125  }
126 };
127 
132 class TotalEnergy : public IIntegral<Float> {
133 private:
134  Vector omega;
135 
136 public:
137  explicit TotalEnergy(const Float omega = 0._f);
138 
139  virtual Float evaluate(const Storage& storage) const override;
140 
141  virtual std::string getName() const override {
142  return "Total energy";
143  }
144 };
145 
150 class CenterOfMass : public IIntegral<Vector> {
151 private:
152  Optional<Size> bodyId;
153 
154 public:
155  explicit CenterOfMass(const Optional<Size> bodyId = NOTHING);
156 
157  virtual Vector evaluate(const Storage& storage) const override;
158 
159  virtual std::string getName() const override {
160  return "Center of mass";
161  }
162 };
163 
168 class IUserQuantity : public Polymorphic {
169 public:
170  virtual void initialize(const Storage& storage) = 0;
171 
172  virtual Float evaluate(const Size i) const = 0;
173 
174  virtual std::string name() const = 0;
175 };
176 
181 class QuantityMeans : public IIntegral<MinMaxMean> {
182 private:
184  Optional<Size> bodyId;
185 
186 public:
190  explicit QuantityMeans(const QuantityId id, const Optional<Size> bodyId = NOTHING);
191 
193  explicit QuantityMeans(AutoPtr<IUserQuantity>&& func, const Optional<Size> bodyId = NOTHING);
194 
195  virtual MinMaxMean evaluate(const Storage& storage) const override;
196 
197  virtual std::string getName() const override {
198  if (auto id = quantity.tryGet<QuantityId>()) {
199  return getMetadata(id.value()).quantityName;
200  } else {
201  return quantity.get<AutoPtr<IUserQuantity>>()->name();
202  }
203  }
204 };
205 
209 class QuantityValue : public IIntegral<Float> {
210 private:
211  QuantityId id;
212  Size idx;
213 
214 public:
215  QuantityValue(const QuantityId id, const Size particleIdx);
216 
217  virtual Float evaluate(const Storage& storage) const override;
218 
219  virtual std::string getName() const override {
220  return getMetadata(id).quantityName + " " + std::to_string(idx);
221  }
222 };
223 
228 class IntegralWrapper : public IIntegral<Float> {
229 private:
231  Function<Dynamic(const Storage& storage)> closure;
232 
234  std::string name;
235 
236 public:
237  IntegralWrapper() = default;
238 
239  template <typename TIntegral>
241  name = integral->getName();
242  closure = [i = std::move(integral)](
243  const Storage& storage) -> Dynamic { return i->evaluate(storage); };
244  }
245 
246  virtual Float evaluate(const Storage& storage) const override {
247  return closure(storage).getScalar();
248  }
249 
250  virtual std::string getName() const override {
251  return name;
252  }
253 };
254 
Generic dynamically allocated resizable storage.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Object holding a single values of various types.
Generic wrappers of lambdas, functors and other callables.
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 NothingType NOTHING
Definition: Optional.h:16
QuantityMetadata getMetadata(const QuantityId key)
Returns the quantity information using quantity ID.
Definition: QuantityIds.cpp:27
Quantity identifiers.
QuantityId
Unique IDs of basic quantities of SPH particles.
Definition: QuantityIds.h:19
Wrapper of pointer that deletes the resource from destructor.
Definition: AutoPtr.h:15
Computes the center of mass of particles.
Definition: Integrals.h:150
virtual Vector evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Definition: Integrals.cpp:127
CenterOfMass(const Optional< Size > bodyId=NOTHING)
Definition: Integrals.cpp:124
virtual std::string getName() const override
Returns the name of the integral.
Definition: Integrals.h:159
Convenient object for storing a single value of different types.
Definition: Dynamic.h:35
Interface for classes computing integral quantities from storage.
Definition: Integrals.h:27
virtual Type evaluate(const Storage &storage) const =0
Computes the integral quantity using particles in the storage.
virtual std::string getName() const =0
Returns the name of the integral.
Interface for auxilirary user-defined scalar quantities.
Definition: Integrals.h:168
virtual Float evaluate(const Size i) const =0
virtual void initialize(const Storage &storage)=0
virtual std::string name() const =0
Helper integral wrapping another integral and converting the returned value to scalar.
Definition: Integrals.h:228
virtual Float evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Definition: Integrals.h:246
IntegralWrapper(AutoPtr< TIntegral > &&integral)
Definition: Integrals.h:240
IntegralWrapper()=default
virtual std::string getName() const override
Returns the name of the integral.
Definition: Integrals.h:250
Helper class for statistics, accumulating minimal, maximal and mean value of a set of numbers.
Definition: Means.h:172
Returns means of given scalar quantity.
Definition: Integrals.h:181
QuantityMeans(const QuantityId id, const Optional< Size > bodyId=NOTHING)
Computes mean of quantity values.
Definition: Integrals.cpp:152
virtual MinMaxMean evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Definition: Integrals.cpp:160
virtual std::string getName() const override
Returns the name of the integral.
Definition: Integrals.h:197
Returns the quantity value of given particle.
Definition: Integrals.h:209
QuantityValue(const QuantityId id, const Size particleIdx)
Definition: Integrals.cpp:191
virtual std::string getName() const override
Returns the name of the integral.
Definition: Integrals.h:219
virtual Float evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Definition: Integrals.cpp:195
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Computes total angular momentum of all SPH particles with a respect to the reference frame.
Definition: Integrals.h:81
virtual Vector evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Definition: Integrals.cpp:40
TotalAngularMomentum(const Float frameFrequency=0._f)
Definition: Integrals.cpp:37
virtual std::string getName() const override
Returns the name of the integral.
Definition: Integrals.h:90
Returns the total energy of all particles.
Definition: Integrals.h:132
virtual Float evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Definition: Integrals.cpp:69
virtual std::string getName() const override
Returns the name of the integral.
Definition: Integrals.h:141
TotalEnergy(const Float omega=0._f)
Definition: Integrals.cpp:66
Returns the total internal energy of all particles.
Definition: Integrals.h:119
virtual Float evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Definition: Integrals.cpp:109
virtual std::string getName() const override
Returns the name of the integral.
Definition: Integrals.h:123
Returns the total kinetic energy of all particles.
Definition: Integrals.h:100
virtual Float evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Definition: Integrals.cpp:96
TotalKineticEnergy(const Float omega=0._f)
Definition: Integrals.cpp:93
virtual std::string getName() const override
Returns the name of the integral.
Definition: Integrals.h:109
Computes the total mass of all SPH particles.
Definition: Integrals.h:49
virtual Float evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Definition: Integrals.cpp:9
virtual std::string getName() const override
Returns the name of the integral.
Definition: Integrals.h:53
Computes total momentum of all SPH particles with a respect to the reference frame.
Definition: Integrals.h:62
virtual std::string getName() const override
Returns the name of the integral.
Definition: Integrals.h:71
virtual Vector evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Definition: Integrals.cpp:24
TotalMomentum(const Float omega=0._f)
Definition: Integrals.cpp:20
Variant, an implementation of type-safe union, similar to std::variant or boost::variant.
Definition: Variant.h:171
Optional< T > tryGet() const
Returns the stored value in the variant.
Definition: Variant.h:371
INLINE T & get()
Returns the stored value.
Definition: Variant.h:335
Generic storage and input/output routines of settings.
Base class for all polymorphic objects.
Definition: Object.h:88
std::string quantityName
Full name of the quantity (i.e. 'Density', 'Deviatoric stress', ...)
Definition: QuantityIds.h:242