SPH
Interpolation.h
Go to the documentation of this file.
1 #pragma once
2 
7 
10 #include "quantities/Storage.h"
11 #include "sph/kernel/Kernel.h"
12 #include "system/Factory.h"
13 #include "system/Settings.h"
14 #include "thread/Scheduler.h"
15 
17 
20 template <typename Type>
21 class IInterpolant : public Noncopyable {
22 public:
26  virtual Type interpolate(const Vector& pos) const = 0;
27 };
28 
34 template <typename Type>
35 class SphInterpolant : public IInterpolant<Type> {
36 protected:
40 
44 
45 public:
47  SphInterpolant(const Storage& storage,
48  const QuantityId id,
49  const OrderEnum deriv,
50  const RunSettings& settings = RunSettings::getDefaults())
51  : SphInterpolant(storage, id, deriv, Factory::getFinder(settings), Factory::getKernel<3>(settings)) {}
52 
61  SphInterpolant(const Storage& storage,
62  const QuantityId id,
63  const OrderEnum deriv,
66  : finder(std::move(finder))
67  , kernel(std::move(kernel)) {
68  SPH_ASSERT(this->finder);
71  quantity = storage.getAll<Type>(id)[int(deriv)];
72  this->build(storage);
73  }
74 
75  virtual Type interpolate(const Vector& pos) const override {
76  Type interpol(0._f);
78  finder->findAll(pos, searchRadius, neighs);
79  for (Size k = 0; k < neighs.size(); ++k) {
80  const Size j = neighs[k].index;
81  if (neighs[k].distanceSqr < sqr(kernel.radius() * r[j][H])) {
82  interpol += m[j] / rho[j] * quantity[j] * kernel.value(pos - r[j], r[j][H]);
83  }
84  }
85  return interpol;
86  }
87 
88 private:
89  void build(const Storage& storage) {
92  searchRadius = 0._f;
93  for (Size i = 0; i < r.size(); ++i) {
95  }
96  }
97 };
98 
103 template <typename Type>
105 public:
107 
108  virtual Type interpolate(const Vector& pos) const override {
109  Type interpol(0._f);
110  Float weight = 0._f;
111  Array<NeighbourRecord> neighs;
112  this->finder->findAll(pos, this->searchRadius, neighs);
113  for (Size k = 0; k < neighs.size(); ++k) {
114  const Size j = neighs[k].index;
115  if (neighs[k].distanceSqr < sqr(this->kernel.radius() * this->r[j][H])) {
116  const Float w =
117  this->m[j] / this->rho[j] * this->kernel.value(pos - this->r[j], this->r[j][H]);
118  interpol += this->quantity[j] * w;
119  weight += w;
120  }
121  }
122  if (weight > 0._f) {
123  return interpol / weight;
124  } else {
125  return Type(0._f);
126  }
127  }
128 };
129 
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
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
SPH kernels.
INLINE Float weight(const Vector &r1, const Vector &r2)
constexpr INLINE T max(const T &f1, const T &f2)
Definition: MathBasic.h:20
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
Definition: MathUtils.h:67
#define NAMESPACE_SPH_END
Definition: Object.h:12
QuantityId
Unique IDs of basic quantities of SPH particles.
Definition: QuantityIds.h:19
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ DENSITY
Density, always a scalar quantity.
@ MASS
Paricles masses, always a scalar quantity.
OrderEnum
Definition: Quantity.h:15
SequentialScheduler SEQUENTIAL
Global instance of the sequential scheduler.
Definition: Scheduler.cpp:43
Interface for executing tasks (potentially) asynchronously.
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.
@ H
Definition: Vector.h:25
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
INLINE TCounter size() const noexcept
Definition: Array.h:193
Computes corrected interpolated value.
virtual Type interpolate(const Vector &pos) const override
Compute quantity value at given position.
void build(IScheduler &scheduler, ArrayView< const Vector > points)
Constructs the struct with an array of vectors.
virtual Size findAll(const Size index, const Float radius, Array< NeighbourRecord > &neighbours) const =0
Finds all neighbours within given radius from the point given by index.
Interface for computing quantity at any point in space.
Definition: Interpolation.h:21
virtual Type interpolate(const Vector &pos) const =0
Compute quantity value at given position.
INLINE Float value(const Vector &r, const Float h) const noexcept
Definition: Kernel.h:26
INLINE Float radius() const noexcept
Definition: Kernel.h:107
static const Settings & getDefaults()
\brief Returns a reference to object containing default values of all settings.
Object for computing interpolated values of quantities.
Definition: Interpolation.h:35
ArrayView< const Type > quantity
Definition: Interpolation.h:39
SphInterpolant(const Storage &storage, const QuantityId id, const OrderEnum deriv, AutoPtr< IBasicFinder > &&finder, LutKernel< 3 > &&kernel)
Constructs the interpolation object given a neighbour finding object and a SPH kernel.
Definition: Interpolation.h:61
ArrayView< const Vector > r
Definition: Interpolation.h:37
virtual Type interpolate(const Vector &pos) const override
Compute quantity value at given position.
Definition: Interpolation.h:75
LutKernel< 3 > kernel
Definition: Interpolation.h:42
ArrayView< const Float > rho
Definition: Interpolation.h:38
AutoPtr< IBasicFinder > finder
Definition: Interpolation.h:41
SphInterpolant(const Storage &storage, const QuantityId id, const OrderEnum deriv, const RunSettings &settings=RunSettings::getDefaults())
Constructs the interpolation object from settings.
Definition: Interpolation.h:47
ArrayView< const Float > m
Definition: Interpolation.h:38
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
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Definition: Storage.cpp:191
Creating code components based on values from settings.
Generic storage and input/output routines of settings.
Provides a convenient way to construct objects from settings.
Definition: Factory.h:46
AutoPtr< ISymmetricFinder > getFinder(const RunSettings &settings)
Definition: Factory.cpp:156
LutKernel< D > getKernel(const RunSettings &settings)
Definition: Factory.cpp:637
Overload of std::swap for Sph::Array.
Definition: Array.h:578
Object with deleted copy constructor and copy operator.
Definition: Object.h:54