SPH
Standard.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "physics/Eos.h"
9 #include "quantities/Storage.h"
12 #include "system/Settings.h"
13 
15 
34 class StandardAV : public IEquationTerm {
35 public:
36  class Derivative : public AccelerationTemplate<Derivative> {
37  private:
39  ArrayView<const Float> rho, cs;
40  const Float eps = 1.e-2_f;
41  Float alpha, beta;
42 
43  public:
44  explicit Derivative(const RunSettings& settings)
45  : AccelerationTemplate<Derivative>(settings)
46  , alpha(settings.get<Float>(RunSettingsId::SPH_AV_ALPHA))
47  , beta(settings.get<Float>(RunSettingsId::SPH_AV_BETA)) {}
48 
50 
51  INLINE void additionalInitialize(const Storage& input, Accumulated& UNUSED(results)) {
53  tie(r, v, dummy) = input.getAll<Vector>(QuantityId::POSITION);
54  // sound speed must be computed by the solver using AV
56  }
57 
58  INLINE bool additionalEquals(const Derivative& other) const {
59  return alpha == other.alpha && beta == other.beta;
60  }
61 
62  template <bool Symmetrize>
63  INLINE Tuple<Vector, Float> eval(const Size i, const Size j, const Vector& grad) {
64  const Float av = evalAv(i, j);
65  SPH_ASSERT(isReal(av) && av >= 0._f);
66  const Vector Pi = av * grad;
67  const Float heating = 0.5_f * av * dot(v[i] - v[j], grad);
68  SPH_ASSERT(isReal(heating) && heating >= 0._f);
69  return { -Pi, heating };
70  }
71 
73  INLINE Float evalAv(const Size i, const Size j) const {
74  const Float dvdr = dot(v[i] - v[j], r[i] - r[j]);
75  if (dvdr >= 0._f) {
76  return 0._f;
77  }
78  const Float hbar = 0.5_f * (r[i][H] + r[j][H]);
79  const Float rhobar = 0.5_f * (rho[i] + rho[j]);
80  const Float csbar = 0.5_f * (cs[i] + cs[j]);
81  const Float mu = hbar * dvdr / (getSqrLength(r[i] - r[j]) + eps * sqr(hbar));
82  return 1._f / rhobar * (-alpha * csbar * mu + beta * sqr(mu));
83  }
84  };
85 
86  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override {
87  derivatives.require(makeAuto<Derivative>(settings));
88  }
89 
90  virtual void initialize(IScheduler& UNUSED(scheduler),
91  Storage& UNUSED(storage),
92  const Float UNUSED(t)) override {}
93 
94  virtual void finalize(IScheduler& UNUSED(scheduler),
95  Storage& UNUSED(storage),
96  const Float UNUSED(t)) override {}
97 
98  virtual void create(Storage& UNUSED(storage), IMaterial& UNUSED(material)) const override {}
99 };
100 
101 
INLINE bool isReal(const AntisymmetricTensor &t)
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Equations of state.
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
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
Definition: MathUtils.h:67
#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 getSqrLength(const Vector &v)
Definition: Vector.h:574
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
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 Float evalAv(const Size i, const Size j) const
Term used for Balsara switch.
Definition: Standard.h:73
INLINE void additionalCreate(Accumulated &UNUSED(results))
Definition: Standard.h:49
INLINE bool additionalEquals(const Derivative &other) const
Definition: Standard.h:58
INLINE Tuple< Vector, Float > eval(const Size i, const Size j, const Vector &grad)
Definition: Standard.h:63
INLINE void additionalInitialize(const Storage &input, Accumulated &UNUSED(results))
Definition: Standard.h:51
Derivative(const RunSettings &settings)
Definition: Standard.h:44
Standard artificial viscosity Monaghan & Gingold .
Definition: Standard.h:34
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
Definition: Standard.h:86
virtual void create(Storage &UNUSED(storage), IMaterial &UNUSED(material)) const override
Definition: Standard.h:98
virtual void finalize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: Standard.h:94
virtual void initialize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: Standard.h:90
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
auto getValues(const QuantityId first, const QuantityId second, const TArgs... others)
Retrieves an array of quantities from the key.
Definition: Storage.h:359
Heterogeneous container capable of storing a fixed number of values.
Definition: Tuple.h:146
Generic storage and input/output routines of settings.
RunSettingsId
Settings relevant for whole run of the simulation.
Definition: Settings.h:949
@ SPH_AV_BETA
Artificial viscosity beta coefficient.
@ SPH_AV_ALPHA
Artificial viscosity alpha coefficient.