SPH
Riemann.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "quantities/Storage.h"
11 
13 
17 class RiemannAV : public IEquationTerm {
18 public:
19  class Derivative : public AccelerationTemplate<Derivative> {
20  private:
21  Float alpha;
23  ArrayView<const Float> cs, rho;
24 
25  public:
26  explicit Derivative(const RunSettings& settings)
27  : AccelerationTemplate<Derivative>(settings) {
28  alpha = settings.get<Float>(RunSettingsId::SPH_AV_ALPHA);
29  }
30 
32 
33  INLINE void additionalInitialize(const Storage& storage, Accumulated& UNUSED(results)) {
35  tie(r, v, dummy) = storage.getAll<Vector>(QuantityId::POSITION);
36  cs = storage.getValue<Float>(QuantityId::SOUND_SPEED);
37  rho = storage.getValue<Float>(QuantityId::DENSITY);
38  }
39 
40  INLINE bool additionalEquals(const Derivative& other) const {
41  return alpha == other.alpha;
42  }
43 
44  template <bool Symmetrize>
45  INLINE Tuple<Vector, Float> eval(const Size i, const Size j, const Vector& grad) {
46  const Float av = evalAv(i, j);
47  SPH_ASSERT(isReal(av) && av >= 0._f);
48  const Vector Pi = av * grad;
49  const Float heating = 0.5_f * av * dot(v[i] - v[j], grad);
50  SPH_ASSERT(isReal(heating) && heating >= 0._f);
51  return { -Pi, heating };
52  }
53 
54  INLINE Float evalAv(const int i, const int j) {
55  const Float dvdr = dot(v[i] - v[j], r[i] - r[j]);
56  if (dvdr >= 0._f) {
57  return 0._f;
58  }
59  const Float w = dvdr / getLength(r[i] - r[j]);
60  const Float vsig = cs[i] + cs[j] - 3._f * w;
61  const Float rhobar = 0.5_f * (rho[i] + rho[j]);
62  return -0.5_f * alpha * vsig * w / rhobar;
63  }
64  };
65 
66  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override {
67  derivatives.require(makeAuto<Derivative>(settings));
68  }
69 
70  virtual void initialize(IScheduler& UNUSED(scheduler),
71  Storage& UNUSED(storage),
72  const Float UNUSED(t)) override {}
73 
74  virtual void finalize(IScheduler& UNUSED(scheduler),
75  Storage& UNUSED(storage),
76  const Float UNUSED(t)) override {}
77 
78  virtual void create(Storage& UNUSED(storage), IMaterial& UNUSED(material)) const override {}
79 };
80 
81 
INLINE bool isReal(const AntisymmetricTensor &t)
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
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
#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.
@ SOUND_SPEED
Sound speed, always a scalar 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
Container for storing particle quantities and materials.
INLINE Float getLength(const Vector &v)
Returns the length of the vector. Enabled only for vectors of floating-point precision.
Definition: Vector.h:579
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
Helper template specifically used to implement forces.
Storage for accumulating derivatives.
Definition: Accumulated.h:30
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
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
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
INLINE Tuple< Vector, Float > eval(const Size i, const Size j, const Vector &grad)
Definition: Riemann.h:45
INLINE void additionalCreate(Accumulated &UNUSED(results))
Definition: Riemann.h:31
INLINE bool additionalEquals(const Derivative &other) const
Definition: Riemann.h:40
Derivative(const RunSettings &settings)
Definition: Riemann.h:26
INLINE void additionalInitialize(const Storage &storage, Accumulated &UNUSED(results))
Definition: Riemann.h:33
INLINE Float evalAv(const int i, const int j)
Definition: Riemann.h:54
Artificial viscosity based on Riemann solver.
Definition: Riemann.h:17
virtual void finalize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: Riemann.h:74
virtual void initialize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: Riemann.h:70
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
Definition: Riemann.h:66
virtual void create(Storage &UNUSED(storage), IMaterial &UNUSED(material)) const override
Definition: Riemann.h:78
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
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 > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Definition: Storage.cpp:191
Heterogeneous container capable of storing a fixed number of values.
Definition: Tuple.h:146
@ SPH_AV_ALPHA
Artificial viscosity alpha coefficient.