SPH
EquationTerm.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "common/ForwardDecl.h"
11 #include "physics/Constants.h"
12 #include "quantities/Storage.h"
13 #include <typeinfo>
14 
16 
22 class IEquationTerm : public Polymorphic {
23 public:
29  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) = 0;
30 
36  virtual void initialize(IScheduler& scheduler, Storage& storage, const Float t) = 0;
37 
41  virtual void finalize(IScheduler& scheduler, Storage& storage, const Float t) = 0;
42 
46  virtual void create(Storage& storage, IMaterial& material) const = 0;
47 };
48 
66 protected:
69 
72 
73  struct {
77 
78 public:
79  explicit AdaptiveSmoothingLength(const RunSettings& settings, const Size dimensions = DIMENSIONS);
80 
81  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override;
82 
83  virtual void initialize(IScheduler& scheduler, Storage& storage, const Float t) override;
84 
85  virtual void finalize(IScheduler& scheduler, Storage& storage, const Float t) override;
86 
87  virtual void create(Storage& storage, IMaterial& material) const override;
88 
89 private:
99  void enforce(const Size i,
102  ArrayView<const Size> neighCnt);
103 };
104 
105 
113 class PressureForce : public IEquationTerm {
114 public:
115  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override;
116 
117  virtual void initialize(IScheduler& scheduler, Storage& storage, const Float t) override;
118 
119  virtual void finalize(IScheduler& scheduler, Storage& storage, const Float t) override;
120 
121  virtual void create(Storage& storage, IMaterial& material) const override;
122 };
123 
150 private:
151  bool useCorrectionTensor;
152 
153 public:
154  explicit SolidStressForce(const RunSettings& settings);
155 
156  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override;
157 
158  virtual void initialize(IScheduler& scheduler, Storage& storage, const Float t) override;
159 
160  virtual void finalize(IScheduler& scheduler, Storage& storage, const Float t) override;
161 
162  virtual void create(Storage& storage, IMaterial& material) const override;
163 };
164 
169 public:
170  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override;
171 
172  virtual void initialize(IScheduler& scheduler, Storage& storage, const Float t) override;
173 
174  virtual void finalize(IScheduler& scheduler, Storage& storage, const Float t) override;
175 
176  virtual void create(Storage& storage, IMaterial& material) const override;
177 };
178 
193 private:
194  ContinuityEnum mode;
195  Float w0;
196 
197 public:
198  explicit ContinuityEquation(const RunSettings& settings);
199 
200  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override;
201 
202  virtual void initialize(IScheduler& scheduler, Storage& storage, const Float t) override;
203 
204  virtual void finalize(IScheduler& scheduler, Storage& storage, const Float t) override;
205 
206  virtual void create(Storage& storage, IMaterial& material) const override;
207 };
208 
220 public:
221  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override;
222 
223  virtual void initialize(IScheduler& scheduler, Storage& storage, const Float t) override;
224 
225  virtual void finalize(IScheduler& scheduler, Storage& storage, const Float t) override;
226 
227  virtual void create(Storage& storage, IMaterial& material) const override;
228 };
229 
230 
239 private:
241 
242 public:
243  EquationHolder() = default;
244 
245  explicit EquationHolder(const SharedPtr<IEquationTerm>& term) {
246  if (term != nullptr) {
247  terms.push(term);
248  }
249  }
250 
252  terms.pushAll(other.terms);
253  return *this;
254  }
255 
257  EquationHolder holder;
258  holder += *this;
259  holder += other;
260  return holder;
261  }
262 
264  template <typename Term>
265  bool contains() const {
266  static_assert(std::is_base_of<IEquationTerm, Term>::value, "Can be used only for terms");
267  for (const auto& ptr : terms) {
268  IEquationTerm& term = *ptr;
269  if (typeid(term) == typeid(Term)) {
270  return true;
271  }
272  }
273  return false;
274  }
275 
277  void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) const {
278  for (const auto& term : terms) {
279  term->setDerivatives(derivatives, settings);
280  }
281  }
282 
284  void initialize(IScheduler& scheduler, Storage& storage, const Float t) {
285  for (const auto& term : terms) {
286  term->initialize(scheduler, storage, t);
287  }
288  }
289 
293  void finalize(IScheduler& scheduler, Storage& storage, const Float t) {
294  for (const auto& term : reverse(terms)) {
295  term->finalize(scheduler, storage, t);
296  }
297  }
298 
300  void create(Storage& storage, IMaterial& material) const {
301  for (const auto& term : terms) {
302  term->create(storage, material);
303  }
304  }
305 
306  Size getTermCnt() const {
307  return terms.size();
308  }
309 };
310 
311 template <typename Term, typename... TArgs>
312 INLINE EquationHolder makeTerm(TArgs&&... args) {
313  return EquationHolder(makeShared<Term>(std::forward<TArgs>(args)...));
314 }
315 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Definitions of physical constaints (in SI units).
INLINE EquationHolder makeTerm(TArgs &&... args)
Definition: EquationTerm.h:312
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
constexpr int DIMENSIONS
Number of spatial dimensions in the code.
Definition: Globals.h:22
Helper objects allowing to iterate in reverse, iterate over multiple containeres, etc.
ReverseAdapter< TContainer > reverse(TContainer &&container)
#define INLINE
Macros for conditional compilation based on selected compiler.
Definition: Object.h:31
#define NAMESPACE_SPH_END
Definition: Object.h:12
Container for storing particle quantities and materials.
Evolutionary equation for the (scalar) smoothing length.
Definition: EquationTerm.h:65
AdaptiveSmoothingLength(const RunSettings &settings, const Size dimensions=DIMENSIONS)
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
Float minimal
Minimal allowed value of the smoothing length.
Definition: EquationTerm.h:71
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t) override
Computes all the derivatives and/or quantity values based on accumulated derivatives.
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t) override
Initialize all the derivatives and/or quantity values before derivatives are computed.
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
Size dimensions
Number of spatial dimensions of the simulation. This should match the dimensions of the SPH kernel.
Definition: EquationTerm.h:68
struct AdaptiveSmoothingLength::@17 enforcing
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
Generic dynamically allocated resizable storage.
Definition: Array.h:43
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
Definition: Array.h:306
INLINE TCounter size() const noexcept
Definition: Array.h:193
void pushAll(const TIter first, const TIter last)
Definition: Array.h:312
Helper term to keep smoothing length constant during the simulation.
Definition: EquationTerm.h:219
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t) override
Computes all the derivatives and/or quantity values based on accumulated derivatives.
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t) override
Initialize all the derivatives and/or quantity values before derivatives are computed.
Equation for evolution of density.
Definition: EquationTerm.h:192
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t) override
Initialize all the derivatives and/or quantity values before derivatives are computed.
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
ContinuityEquation(const RunSettings &settings)
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t) override
Computes all the derivatives and/or quantity values based on accumulated derivatives.
Container holding derivatives and the storage they accumulate to.
Definition: Derivative.h:173
Container holding equation terms.
Definition: EquationTerm.h:238
EquationHolder(const SharedPtr< IEquationTerm > &term)
Definition: EquationTerm.h:245
EquationHolder & operator+=(const EquationHolder &other)
Definition: EquationTerm.h:251
void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) const
Calls EquationTerm::setDerivatives for all stored equation terms.
Definition: EquationTerm.h:277
bool contains() const
Checks if the holder contains term of given type.
Definition: EquationTerm.h:265
void create(Storage &storage, IMaterial &material) const
Calls EquationTerm::create for all stored equation terms.
Definition: EquationTerm.h:300
EquationHolder()=default
EquationHolder operator+(const EquationHolder &other) const
Definition: EquationTerm.h:256
void initialize(IScheduler &scheduler, Storage &storage, const Float t)
Calls EquationTerm::initialize for all stored equation terms.
Definition: EquationTerm.h:284
void finalize(IScheduler &scheduler, Storage &storage, const Float t)
Calls EquationTerm::finalize for all stored equation terms.
Definition: EquationTerm.h:293
Size getTermCnt() const
Definition: EquationTerm.h:306
Represents a term or terms appearing in evolutionary equations.
Definition: EquationTerm.h:22
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t)=0
Computes all the derivatives and/or quantity values based on accumulated derivatives.
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings)=0
Sets derivatives required by this term.
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t)=0
Initialize all the derivatives and/or quantity values before derivatives are computed.
virtual void create(Storage &storage, IMaterial &material) const =0
Creates all quantities needed by the term using given material.
Material settings and functions specific for one material.
Definition: IMaterial.h:110
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
Navier-Stokes equation of motion.
Definition: EquationTerm.h:168
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t) override
Initialize all the derivatives and/or quantity values before derivatives are computed.
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t) override
Computes all the derivatives and/or quantity values based on accumulated derivatives.
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
Equation of motion due to pressure gradient.
Definition: EquationTerm.h:113
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t) override
Initialize all the derivatives and/or quantity values before derivatives are computed.
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t) override
Computes all the derivatives and/or quantity values based on accumulated derivatives.
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
Equation of motion for solid body and constitutive equation for the stress tensor (Hooke's law)
Definition: EquationTerm.h:149
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t) override
Initialize all the derivatives and/or quantity values before derivatives are computed.
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
SolidStressForce(const RunSettings &settings)
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t) override
Computes all the derivatives and/or quantity values based on accumulated derivatives.
Container storing all quantities used within the simulations.
Definition: Storage.h:230
ContinuityEnum
Definition: Settings.h:721
Base class for all polymorphic objects.
Definition: Object.h:88