SPH
Conductivity.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "quantities/Storage.h"
11 
13 
18 public:
19  class Derivative : public DerivativeTemplate<Derivative> {
20  private:
21  Float alpha, beta;
23  ArrayView<const Float> m, rho, u, p, cs;
25 
26  SignalSpeedEnum sig;
27 
28  public:
29  explicit Derivative(const RunSettings& settings)
30  : DerivativeTemplate<Derivative>(settings) {
31  alpha = settings.get<Float>(RunSettingsId::SPH_AC_ALPHA);
32  beta = settings.get<Float>(RunSettingsId::SPH_AC_BETA);
34  }
35 
38  }
39 
40  INLINE void additionalInitialize(const Storage& storage, Accumulated& results) {
41  tie(m, rho, u, p, cs) = storage.getValues<Float>(QuantityId::MASS,
46  r = storage.getValue<Vector>(QuantityId::POSITION);
47  v = storage.getDt<Vector>(QuantityId::POSITION);
49  }
50 
51  INLINE bool additionalEquals(const Derivative& other) const {
52  return alpha == other.alpha && beta == other.beta && sig == other.sig;
53  }
54 
55  template <bool Symmetrize>
56  INLINE void eval(const Size i, const Size j, const Vector& grad) {
57  const Float eps = 1.e-6_f;
58  const Vector e = (r[i] - r[j]) / (getLength(r[i] - r[j]) + eps);
59  const Float rho_bar = 0.5_f * (rho[i] + rho[j]);
60  Float vu_sig;
62  vu_sig = sgn((p[i] - p[j]) * (u[i] - u[j])) * sqrt(abs(p[i] - p[j]) / rho_bar);
63  } else {
65  vu_sig = abs(dot(v[i] - v[j], e));
66  }
67  const Float a = alpha * vu_sig * (u[i] - u[j]);
68  const Float heat = a * dot(e, grad) / rho_bar;
69  du[i] += m[j] * heat;
70 
71  if (Symmetrize) {
72  du[j] -= m[j] * heat;
73  }
74  }
75  };
76 
81  throw InvalidSetup(
82  "Artificial conductivity with pressure-based signal speed cannot be used with forces other "
83  "than pressure gradient. Consider using the velocity-based signal speed instead.");
84  }
85  }
86 
87  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override {
88  derivatives.require(makeAuto<Derivative>(settings));
89  }
90 
91  virtual void initialize(IScheduler& UNUSED(scheduler),
92  Storage& UNUSED(storage),
93  const Float UNUSED(t)) override {}
94 
95  virtual void finalize(IScheduler& UNUSED(scheduler),
96  Storage& UNUSED(storage),
97  const Float UNUSED(t)) override {}
98 
99  virtual void create(Storage& UNUSED(storage), IMaterial& UNUSED(material)) const override {}
100 };
101 
102 
@ SHARED
Multiple derivatives may accumulate into the buffer.
#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
INLINE T sqrt(const T f)
Return a squared root of a value.
Definition: MathUtils.h:78
INLINE int sgn(const T val)
Definition: MathUtils.h:336
INLINE auto abs(const T &f)
Definition: MathUtils.h:276
#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
@ PRESSURE
Pressure, affected by yielding and fragmentation model, always a scalar quantity.
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ ENERGY
Specific internal energy, always a scalar quantity.
@ DENSITY
Density, always a scalar quantity.
@ MASS
Paricles masses, always a scalar quantity.
@ SOUND_SPEED
Sound speed, always a scalar quantity.
@ FIRST
Quantity with 1st derivative.
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
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
Derivative(const RunSettings &settings)
Definition: Conductivity.h:29
INLINE void additionalCreate(Accumulated &results)
Definition: Conductivity.h:36
INLINE void additionalInitialize(const Storage &storage, Accumulated &results)
Definition: Conductivity.h:40
INLINE bool additionalEquals(const Derivative &other) const
Definition: Conductivity.h:51
INLINE void eval(const Size i, const Size j, const Vector &grad)
Definition: Conductivity.h:56
Artificial thermal conductivity.
Definition: Conductivity.h:17
virtual void create(Storage &UNUSED(storage), IMaterial &UNUSED(material)) const override
Definition: Conductivity.h:99
ArtificialConductivity(const RunSettings &settings)
Definition: Conductivity.h:77
virtual void initialize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: Conductivity.h:91
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
Definition: Conductivity.h:87
virtual void finalize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: Conductivity.h:95
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.
Wrapper of an integral value providing functions for reading and modifying individual bits.
Definition: Flags.h:20
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
Thrown when components of the run are mutually incompatible.
Definition: Exceptions.h:24
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
Flags< TValue > getFlags(const TEnum idx) const
Returns Flags from underlying value stored in settings.
Definition: Settings.h:348
Container storing all quantities used within the simulations.
Definition: Storage.h:230
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
ForceEnum
Definition: Settings.h:658
@ PRESSURE
Use force from pressure gradient in the solver.
SignalSpeedEnum
Definition: Settings.h:777
@ PRESSURE_DIFFERENCE
Signal speed given by the absolute value of pressure difference, as in Price (2008)
@ VELOCITY_DIFFERENCE
Signal speed given by relative velocity projected to the positive vector, as in Valdarnini (2018),...
@ SPH_SOLVER_FORCES
List of forces to compute by the solver.
@ SPH_AC_ALPHA
Artificial conductivity alpha coefficient.
@ SPH_AC_BETA
Artificial conductivity beta coefficient.
@ SPH_AC_SIGNAL_SPEED
Type of the signal speed used by artificial conductivity.