SPH
Heat.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "quantities/IMaterial.h"
11 #include "sph/kernel/Kernel.h"
12 
14 
15 class EnergyLaplacian : public DerivativeTemplate<EnergyLaplacian> {
16 private:
17  ArrayView<Float> deltaU;
18  ArrayView<const Float> u, m, rho;
20 
21 public:
22  explicit EnergyLaplacian(const RunSettings& settings)
23  : DerivativeTemplate<EnergyLaplacian>(settings) {}
24 
27  }
28 
29  INLINE void additionalInitialize(const Storage& input, Accumulated& results) {
33  }
34 
35  INLINE bool additionalEquals(const EnergyLaplacian& UNUSED(other)) const {
36  return true;
37  }
38 
39  template <bool Symmetric>
40  INLINE void eval(const Size i, const Size j, const Vector& grad) {
41  const Float f = laplacian(u[j] - u[i], grad, r[j] - r[i]);
42  deltaU[i] += m[j] / rho[j] * f;
43  if (Symmetric) {
44  deltaU[j] -= m[i] / rho[i] * f;
45  }
46  }
47 };
48 
51 public:
52  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override {
53  // add laplacian of energy to the list of derivatives
54  derivatives.require(makeAuto<EnergyLaplacian>(settings));
55  }
56 
57  virtual void initialize(IScheduler& UNUSED(scheduler),
58  Storage& UNUSED(storage),
59  const Float UNUSED(t)) override {}
60 
61  virtual void finalize(IScheduler& UNUSED(scheduler), Storage& storage, const Float UNUSED(t)) override {
64  for (Size matIdx = 0; matIdx < storage.getMaterialCnt(); ++matIdx) {
65  MaterialView mat = storage.getMaterial(matIdx);
66  const Float alpha = mat->getParam<Float>(BodySettingsId::DIFFUSIVITY);
67  for (Size i : mat.sequence()) {
68  du[i] = alpha * deltaU[i];
69  }
70  }
71  }
72 
73  virtual void create(Storage& storage, IMaterial& material) const override {
75 
76  const Float u0 = material.getParam<Float>(BodySettingsId::ENERGY);
79  }
80 };
81 
82 class RadiativeCooling : public IEquationTerm {};
83 
@ 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
Base class for all particle materials.
SPH kernels.
INLINE T laplacian(const T &value, const Vector &grad, const Vector &dr)
SPH approximation of laplacian, computed from a kernel gradient.
Definition: Kernel.h:519
#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
@ ENERGY_LAPLACIAN
Laplacian of internal energy, used in heat diffusion equation.
@ 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.
@ 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
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.
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.
INLINE void additionalInitialize(const Storage &input, Accumulated &results)
Definition: Heat.h:29
INLINE bool additionalEquals(const EnergyLaplacian &UNUSED(other)) const
Definition: Heat.h:35
INLINE void additionalCreate(Accumulated &results)
Definition: Heat.h:25
INLINE void eval(const Size i, const Size j, const Vector &grad)
Definition: Heat.h:40
EnergyLaplacian(const RunSettings &settings)
Definition: Heat.h:22
virtual void initialize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: Heat.h:57
virtual void finalize(IScheduler &UNUSED(scheduler), Storage &storage, const Float UNUSED(t)) override
Definition: Heat.h:61
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
Definition: Heat.h:73
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
Definition: Heat.h:52
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
INLINE TValue getParam(const BodySettingsId paramIdx) const
Returns a parameter associated with given particle.
Definition: IMaterial.h:137
void setRange(const QuantityId id, const Interval &range, const Float minimal)
Sets the timestepping parameters of given quantity.
Definition: IMaterial.cpp:17
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Non-owning wrapper of a material and particles with this material.
Definition: IMaterial.h:30
INLINE IndexSequence sequence()
Returns iterable index sequence.
Definition: IMaterial.h:75
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Size getMaterialCnt() const
Return the number of materials in the storage.
Definition: Storage.cpp:437
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
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
MaterialView getMaterial(const Size matIdx) const
Returns an object containing a reference to given material.
Definition: Storage.cpp:366
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Definition: Storage.cpp:191
@ ENERGY_MIN
Estimated minimal value of energy used to determine timestepping error.
@ ENERGY
Initial specific internal energy.
@ ENERGY_RANGE
Allowed range of specific internal energy.