SPH
DeltaSph.h
Go to the documentation of this file.
1 #pragma once
2 
7 
10 
12 
13 namespace DeltaSph {
14 
15 class RenormalizedDensityGradient : public DerivativeTemplate<RenormalizedDensityGradient> {
16 private:
19  ArrayView<Vector> drho;
20 
21 public:
22  explicit RenormalizedDensityGradient(const RunSettings& settings)
25 
26  void additionalCreate(Accumulated& results) {
28  }
29 
30  INLINE void additionalInitialize(const Storage& input, Accumulated& results) {
33  }
34 
36  return true;
37  }
38 
39  template <bool Symmetrize>
40  INLINE void eval(const Size i, const Size j, const Vector& grad) {
41  SPH_ASSERT(Symmetrize == false);
42  const Vector f = (rho[j] - rho[i]) * grad;
43  drho[i] += m[j] / rho[j] * f;
44  if (Symmetrize) {
45  drho[j] += m[i] / rho[i] * f;
46  }
47  }
48 };
49 
54  class Derivative : public DerivativeTemplate<Derivative> {
55  private:
56  ArrayView<Float> drho;
57  ArrayView<const Vector> r, gradRho;
58  ArrayView<const Float> m, rho, cs;
59 
60  Float delta;
61 
62  public:
63  explicit Derivative(const RunSettings& settings)
66  }
67 
68  void additionalCreate(Accumulated& results) {
70  }
71 
72  bool additionalEquals(const Derivative& other) const {
73  return delta == other.delta;
74  }
75 
76  INLINE void additionalInitialize(const Storage& input, Accumulated& results) {
77  tie(r, gradRho) =
79  tie(m, rho, cs) =
82  }
83 
84  template <bool Symmetrize>
85  INLINE void eval(const Size i, const Size j, const Vector& grad) {
86  const Vector dr = r[j] - r[i];
87  const Vector psi = 2._f * (rho[j] - rho[i]) * dr / getSqrLength(dr) - (gradRho[i] + gradRho[j]);
88  const Float hbar = 0.5_f * (r[i][H] + r[j][H]);
89  const Float cbar = 0.5_f * (cs[i] + cs[j]);
90  const Float f = delta * hbar * cbar * dot(psi, grad);
91 
92  drho[i] += m[j] / rho[j] * f;
93  if (Symmetrize) {
94  TODO("check sign!");
95  drho[j] += m[i] / rho[i] * f;
96  }
97  }
98  };
99 
100 public:
101  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override {
102  derivatives.require(makeAuto<RenormalizedDensityGradient>(settings));
103  derivatives.require(makeAuto<Derivative>(settings));
104  }
105 
106  virtual void initialize(IScheduler& UNUSED(scheduler),
107  Storage& UNUSED(storage),
108  const Float UNUSED(t)) override {}
109 
110  virtual void finalize(IScheduler& UNUSED(scheduler),
111  Storage& UNUSED(storage),
112  const Float UNUSED(t)) override {}
113 
114  virtual void create(Storage& storage, IMaterial& UNUSED(material)) const override {
116  }
117 };
118 
121 private:
122  class Derivative : public DerivativeTemplate<Derivative> {
123  private:
126  ArrayView<const Float> m, rho, cs;
127 
128  Float alpha;
129 
130  public:
131  explicit Derivative(const RunSettings& settings)
134  }
135 
136  void additionalCreate(Accumulated& results) {
138  }
139 
140  bool additionalEquals(const Derivative& other) const {
141  return alpha == other.alpha;
142  }
143 
144  INLINE void additionalInitialize(const Storage& input, Accumulated& results) {
146  tie(r, v, dummy) = input.getAll<Vector>(QuantityId::POSITION);
148  tie(m, rho, cs) =
150  }
151 
152  template <bool Symmetrize>
153  INLINE void eval(const Size i, const Size j, const Vector& grad) {
154  const Vector dr = r[j] - r[i];
155  const Float pi = dot(v[j] - v[i], dr) / getSqrLength(dr);
156  const Float hbar = 0.5_f * (r[i][H] + r[j][H]);
158  const Float cbar = 0.5_f * (cs[i] + cs[j]);
159  const Vector f = alpha * hbar * cbar * pi * grad;
160  const Float dh = dv[i][H];
161  dv[i] += m[j] / rho[j] * f;
162  dv[i][H] = dh;
163 
164  if (Symmetrize) {
165  TODO("check sign!");
166  dv[j] -= m[i] / rho[i] * f;
167  }
168  }
169  };
170 
171 public:
172  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override {
173  derivatives.require(makeAuto<Derivative>(settings));
174  }
175 
176  virtual void initialize(IScheduler& UNUSED(scheduler),
177  Storage& UNUSED(storage),
178  const Float UNUSED(t)) override {}
179 
180  virtual void finalize(IScheduler& UNUSED(scheduler),
181  Storage& UNUSED(storage),
182  const Float UNUSED(t)) override {}
183 
184  virtual void create(Storage& storage, IMaterial& UNUSED(material)) const override {
186  }
187 };
188 
189 } // namespace DeltaSph
190 
@ SHARED
Multiple derivatives may accumulate into the buffer.
@ UNIQUE
Only a single derivative accumulates to this buffer.
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
#define TODO(x)
Definition: Assert.h:84
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
DerivativeFlag
@ SUM_ONLY_UNDAMAGED
Only undamaged particles (particles with damage > 0) from the same body (body with the same flag) wil...
@ CORRECTED
Use correction tensor on kernel gradient when evaluating the derivative.
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
#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.
@ DELTASPH_DENSITY_GRADIENT
@ MASS
Paricles masses, always a scalar quantity.
@ SOUND_SPEED
Sound speed, always a scalar quantity.
@ SECOND
Quantity with 1st and 2nd derivative.
@ FIRST
Quantity with 1st derivative.
@ 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
INLINE Float getSqrLength(const Vector &v)
Definition: Vector.h:574
BasicVector< Float > Vector
Definition: Vector.h:539
INLINE float dot(const BasicVector< float > &v1, const BasicVector< float > &v2)
Make sure the vector is trivially constructible and destructible, needed for fast initialization of a...
Definition: Vector.h:548
@ 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.
Numerical diffusion of density.
Definition: DeltaSph.h:53
virtual void initialize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: DeltaSph.h:106
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
Definition: DeltaSph.h:101
virtual void finalize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: DeltaSph.h:110
virtual void create(Storage &storage, IMaterial &UNUSED(material)) const override
Definition: DeltaSph.h:114
RenormalizedDensityGradient(const RunSettings &settings)
Definition: DeltaSph.h:22
INLINE bool additionalEquals(const RenormalizedDensityGradient &UNUSED(other)) const
Definition: DeltaSph.h:35
INLINE void eval(const Size i, const Size j, const Vector &grad)
Definition: DeltaSph.h:40
void additionalCreate(Accumulated &results)
Definition: DeltaSph.h:26
INLINE void additionalInitialize(const Storage &input, Accumulated &results)
Definition: DeltaSph.h:30
Numerical diffusion of velocity.
Definition: DeltaSph.h:120
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
Definition: DeltaSph.h:172
virtual void initialize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: DeltaSph.h:176
virtual void finalize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: DeltaSph.h:180
virtual void create(Storage &storage, IMaterial &UNUSED(material)) const override
Definition: DeltaSph.h:184
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
auto getValues(const QuantityId first, const QuantityId second, const TArgs... others)
Retrieves an array of quantities from the key.
Definition: Storage.h:359
@ SPH_VELOCITY_DIFFUSION_ALPHA
Alpha-coefficient of the delta-SPH modification.
@ SPH_DENSITY_DIFFUSION_DELTA
Delta-coefficient of the delta-SPH modification, see Marrone et al. 2011.