SPH
SphericalGravity.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "gravity/IGravity.h"
9 #include "physics/Functions.h"
10 #include "sph/Materials.h"
12 #include "thread/Scheduler.h"
13 
15 
23 class SphericalGravity : public IGravity {
24 private:
25  Vector center;
26  Float rho0;
28 
29 public:
30  SphericalGravity(const Vector& center = Vector(0._f))
31  : center(center) {}
32 
33  virtual void build(IScheduler& UNUSED(scheduler), const Storage& storage) override {
34  r = storage.getValue<Vector>(QuantityId::POSITION);
35  rho0 = storage.getMaterial(0)->getParam<Float>(BodySettingsId::DENSITY);
36  }
37 
38  virtual void evalAll(IScheduler& scheduler,
40  Statistics& UNUSED(stats)) const override {
41  Analytic::StaticSphere sphere(INFTY, rho0); // here radius does not matter
42  parallelFor(scheduler, 0, dv.size(), [this, sphere, &dv](const Size i) {
43  dv[i] += sphere.getAcceleration(r[i] - center);
44  });
45  }
46 
47  virtual Vector eval(const Vector& r0) const override {
48  Analytic::StaticSphere sphere(INFTY, rho0);
49  return sphere.getAcceleration(r0 - center);
50  }
51 
52  virtual Float evalEnergy(IScheduler& UNUSED(scheduler), Statistics& UNUSED(stats)) const override {
53  Analytic::StaticSphere sphere(INFTY, rho0);
54  return sphere.getEnergy();
55  }
56 
57  virtual RawPtr<const IBasicFinder> getFinder() const override {
58  return nullptr;
59  }
60 };
61 
66 public:
67  virtual void setDerivatives(DerivativeHolder& UNUSED(derivatives),
68  const RunSettings& UNUSED(settings)) override {}
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), Storage& storage, const Float UNUSED(t)) override {
77  const Float rho0 = storage.getMaterial(0)->getParam<Float>(BodySettingsId::DENSITY);
78  Analytic::StaticSphere sphere(INFTY, rho0);
79  for (Size i = 0; i < dv.size(); ++i) {
80  dv[i] += sphere.getAcceleration(r[i]);
81  }
82  }
83 
84  virtual void create(Storage& UNUSED(storage), IMaterial& UNUSED(material)) const override {}
85 };
86 
87 
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 solvers of gravity.
SPH-specific implementation of particle materials.
constexpr Float INFTY
Definition: MathUtils.h:38
#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,.
Interface for executing tasks (potentially) asynchronously.
INLINE void parallelFor(IScheduler &scheduler, const Size from, const Size to, TFunctor &&functor)
Executes a functor concurrently from all available threads.
Definition: Scheduler.h:98
BasicVector< Float > Vector
Definition: Vector.h:539
Properties of a homogeneous sphere in rest (no temporal derivatives)
Definition: Functions.h:19
INLINE Vector getAcceleration(const Vector &r) const
Returns the gravitational acceleration at given radius r.
Definition: Functions.h:43
INLINE Float getEnergy() const
Returns the gravitational potential energy of the sphere.
Definition: Functions.h:50
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
INLINE TCounter size() const
Definition: ArrayView.h:101
Container holding derivatives and the storage they accumulate to.
Definition: Derivative.h:173
Represents a term or terms appearing in evolutionary equations.
Definition: EquationTerm.h:22
Interface for computing gravitational interactions of particles.
Definition: IGravity.h:14
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
Non-owning wrapper of pointer.
Definition: RawPtr.h:19
Implements IEquationTerm interface using SphericalGravity.
virtual void initialize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
virtual void setDerivatives(DerivativeHolder &UNUSED(derivatives), const RunSettings &UNUSED(settings)) override
virtual void finalize(IScheduler &UNUSED(scheduler), Storage &storage, const Float UNUSED(t)) override
virtual void create(Storage &UNUSED(storage), IMaterial &UNUSED(material)) const override
Spherically symmetrized gravitational force.
virtual RawPtr< const IBasicFinder > getFinder() const override
Optionally returns a finder used by the gravity implementation.
virtual void evalAll(IScheduler &scheduler, ArrayView< Vector > dv, Statistics &UNUSED(stats)) const override
SphericalGravity(const Vector &center=Vector(0._f))
virtual void build(IScheduler &UNUSED(scheduler), const Storage &storage) override
virtual Vector eval(const Vector &r0) const override
Evaluates the gravitational acceleration at given point.
virtual Float evalEnergy(IScheduler &UNUSED(scheduler), Statistics &UNUSED(stats)) const override
Object holding various statistics about current run.
Definition: Statistics.h:22
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Array< TValue > & getD2t(const QuantityId key)
Retrieves a quantity second derivative from the storage, given its key and value type.
Definition: Storage.cpp:243
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
@ DENSITY
Density at zero pressure.