SPH
XSph.h
Go to the documentation of this file.
1 #pragma once
2 
7 
10 #include "sph/kernel/Kernel.h"
11 #include "system/Factory.h"
12 
14 
22 
23 class XSph : public IEquationTerm {
24 private:
25  class Derivative : public DerivativeTemplate<Derivative> {
26  private:
29 
33  Float epsilon;
34 
35  public:
36  explicit Derivative(const RunSettings& settings)
38  , kernel(Factory::getKernel<DIMENSIONS>(settings)) {
39  epsilon = settings.get<Float>(RunSettingsId::SPH_XSPH_EPSILON);
40  }
41 
42  INLINE void additionalCreate(Accumulated& results) {
44  }
45 
46  INLINE void additionalInitialize(const Storage& input, Accumulated& results) {
50  tie(r, v, dummy) = input.getAll<Vector>(QuantityId::POSITION);
51  }
52 
53  INLINE bool additionalEquals(const Derivative& other) const {
54  return epsilon == other.epsilon;
55  }
56 
57  template <bool Symmetric>
58  INLINE void eval(const Size i, const Size j, const Vector& UNUSED(grad)) {
59  // this depends on v[i]-v[j], so it is zero for i==j
60  Vector f = epsilon * (v[j] - v[i]) / (0.5_f * (rho[i] + rho[j])) * kernel.value(r[i], r[j]);
61  f[H] = 0._f;
62  dr[i] += m[j] * f;
63  if (Symmetric) {
64  dr[j] -= m[i] * f;
65  }
66  }
67  };
68 
69 public:
70  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override {
71  derivatives.require(makeAuto<Derivative>(settings));
72  }
73 
74  virtual void initialize(IScheduler& UNUSED(scheduler), Storage& storage, const Float UNUSED(t)) override {
75  // fix previously modified velocities before computing derivatives
81  for (Size i = 0; i < v.size(); ++i) {
82  v[i] -= dr[i];
83  }
84  }
85 
86  virtual void finalize(IScheduler& UNUSED(scheduler), Storage& storage, const Float UNUSED(t)) override {
89  for (Size i = 0; i < v.size(); ++i) {
90  v[i] += dr[i];
91  }
92  }
93 
94  virtual void create(Storage& storage, IMaterial& UNUSED(material)) const override {
96  }
97 };
98 
@ UNIQUE
Only a single derivative accumulates to this buffer.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Right-hand side term of SPH equations.
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
SPH kernels.
#define INLINE
Macros for conditional compilation based on selected compiler.
Definition: Object.h:31
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ DENSITY
Density, always a scalar quantity.
@ MASS
Paricles masses, always a scalar quantity.
@ ZERO
Quantity without derivatives, or "zero order" of quantity.
StaticArray< T0 &, sizeof...(TArgs)+1 > tie(T0 &t0, TArgs &... rest)
Creates a static array from a list of l-value references.
Definition: StaticArray.h:281
BasicVector< Float > Vector
Definition: Vector.h:539
@ H
Definition: Vector.h:25
Storage for accumulating derivatives.
Definition: Accumulated.h:30
Array< TValue > & getBuffer(const QuantityId id, const OrderEnum order)
Returns the buffer of given quantity and given order.
Definition: Accumulated.cpp:53
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
INLINE TCounter size() const
Definition: ArrayView.h:101
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
Helper template for derivatives that define both the symmetrized and asymmetric variant.
Represents a term or terms appearing in evolutionary equations.
Definition: EquationTerm.h:22
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
TValue get(const TEnum idx, std::enable_if_t<!std::is_enum< std::decay_t< TValue >>::value, int >=0) const
Returns a value of given type from the settings.
Definition: Settings.h:326
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Quantity & insert(const QuantityId key, const OrderEnum order, const TValue &defaultValue)
Creates a quantity in the storage, given its key, value type and order.
Definition: Storage.cpp:270
StaticArray< Array< TValue > &, 3 > getAll(const QuantityId key)
Retrieves quantity buffers from the storage, given its key and value type.
Definition: Storage.cpp:163
Array< TValue > & getDt(const QuantityId key)
Retrieves a quantity derivative from the storage, given its key and value type.
Definition: Storage.cpp:217
auto getValues(const QuantityId first, const QuantityId second, const TArgs... others)
Retrieves an array of quantities from the key.
Definition: Storage.h:359
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Definition: Storage.cpp:191
INLINE Float value(const Vector &r1, const Vector &r2) const
Definition: Kernel.h:573
XSPH correction that (partially) averages the velocities over neighbouring particles.
Definition: XSph.h:23
virtual void finalize(IScheduler &UNUSED(scheduler), Storage &storage, const Float UNUSED(t)) override
Definition: XSph.h:86
virtual void create(Storage &storage, IMaterial &UNUSED(material)) const override
Definition: XSph.h:94
virtual void initialize(IScheduler &UNUSED(scheduler), Storage &storage, const Float UNUSED(t)) override
Definition: XSph.h:74
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
Definition: XSph.h:70
Creating code components based on values from settings.