31 : gravityConstant(gravityContant) {
37 : kernel(
std::move(kernel))
38 , gravityConstant(gravityContant) {}
51 dv[i] += this->evalImpl(actKernel, r[i], i);
56 struct NoSymmetrization {
60 return kernel.
grad(r1 - r2, r1[
H]);
63 return this->evalImpl(NoSymmetrization{ kernel }, r0,
Size(-1));
70 for (Size j = 0; j < m.size(); ++j) {
72 e += m[i] * m[j] * actKernel.value(r[i], r[j]);
76 return 0.5_f * gravityConstant * energy.accumulate();
84 template <
typename TKernel>
89 if (idx !=
Size(-1)) {
91 for (
Size i = 0; i < idx; ++i) {
92 a += m[i] * actKernel.grad(r[i], r0);
94 for (
Size i = idx + 1; i < r.
size(); ++i) {
95 a += m[i] * actKernel.grad(r[i], r0);
98 for (
Size i = 0; i < r.
size(); ++i) {
99 a += m[i] * actKernel.grad(r[i], r0);
102 return gravityConstant * a;
#define SPH_ASSERT(x,...)
Definitions of physical constaints (in SI units).
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Smoothing kernels for including gravity into SPH.
Base class for solvers of gravity.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ MASS
Paricles masses, always a scalar quantity.
INLINE void parallelFor(IScheduler &scheduler, const Size from, const Size to, TFunctor &&functor)
Executes a functor concurrently from all available threads.
Container for storing particle quantities and materials.
Template for thread-local storage.
Object providing safe access to continuous memory of data.
INLINE TCounter size() const
Computes gravitational acceleration by summing up forces from all particle pairs.
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 RawPtr< const IBasicFinder > getFinder() const override
Optionally returns a finder used by the gravity implementation.
BruteForceGravity(const Float gravityContant=Constants::gravity)
Default-construced gravity, assuming point-like particles.
BruteForceGravity(GravityLutKernel &&kernel, const Float gravityContant=Constants::gravity)
Constructs gravity using smoothing kernel.
virtual void evalAll(IScheduler &scheduler, ArrayView< Vector > dv, Statistics &UNUSED(stats)) const override
virtual Float evalEnergy(IScheduler &scheduler, Statistics &UNUSED(stats)) const override
Gravitational kernel approximated by LUT for close particles.
INLINE Vector grad(const Vector &r, const Float h) const
INLINE Float radius() const
Interface for computing gravitational interactions of particles.
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Non-owning wrapper of pointer.
Object holding various statistics about current run.
Container storing all quantities used within the simulations.
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Template for storing a copy of a value for every thread in given scheduler.
constexpr Float gravity
Gravitational constant (CODATA 2014)
Overload of std::swap for Sph::Array.