SPH
GravitySolver.cpp
Go to the documentation of this file.
3 #include "objects/Exceptions.h"
4 #include "quantities/Quantity.h"
7 #include "sph/kernel/Kernel.h"
12 #include "system/Factory.h"
13 #include "system/Statistics.h"
14 
16 
17 template <typename TSphSolver>
19  const RunSettings& settings,
20  const EquationHolder& equations)
21  : GravitySolver(scheduler, settings, equations, Factory::getBoundaryConditions(settings)) {}
22 
23 template <typename TSphSolver>
25  const RunSettings& settings,
26  const EquationHolder& equations,
28  : GravitySolver(scheduler, settings, equations, std::move(bc), Factory::getGravity(settings)) {}
29 
30 template <typename TSphSolver>
32  const RunSettings& settings,
33  const EquationHolder& equations,
36  : TSphSolver(scheduler, settings, equations, std::move(bc))
37  , gravity(std::move(gravity)) {
38 
39  // make sure acceleration are being accumulated
40  Accumulated& results = this->derivatives.getAccumulated();
42 }
43 
44 template <>
46  const RunSettings& settings,
47  const EquationHolder& equations,
50  : SymmetricSolver<DIMENSIONS>(scheduler, settings, equations, std::move(bc))
51  , gravity(std::move(gravity)) {
52 
53  // make sure acceleration are being accumulated
54  for (ThreadData& data : threadData) {
55  Accumulated& results = data.derivatives.getAccumulated();
57  }
58 }
59 
60 template <typename TSphSolver>
62 
63 template <typename TSphSolver>
66 
67  // first, do asymmetric evaluation of gravity:
68 
69  // build gravity tree
70  Timer timer;
71  gravity->build(this->scheduler, storage);
73 
74  // get acceleration buffer corresponding to first thread (to save some memory + time)
75  Accumulated& accumulated = this->getAccumulated();
77 
78  // evaluate gravity for each particle
79  timer.restart();
80  gravity->evalAll(this->scheduler, dv, stats);
82 
83  // second, compute SPH derivatives using given solver
84  timer.restart();
85  TSphSolver::loop(storage, stats);
86  stats.set(StatisticsId::SPH_EVAL_TIME, int(timer.elapsed(TimerUnit::MILLISECOND)));
87 }
88 
89 template <>
91  // gravity is evaluated asymmetrically, so we can simply put everything in the first (or any) accumulated
92  ThreadData& data = this->threadData.value(0);
93  return data.derivatives.getAccumulated();
94 }
95 
96 template <>
98  return this->derivatives.getAccumulated();
99 }
100 
101 template <>
103  return this->derivatives.getAccumulated();
104 }
105 
106 template <>
108  RawPtr<const IBasicFinder> finder = gravity->getFinder();
109  if (!finder) {
110  // no finder provided, just call the default implementation
111  return AsymmetricSolver::getFinder(r);
112  } else {
113  return finder.get();
114  }
115 }
116 
117 template <>
119  RawPtr<const IBasicFinder> finder = gravity->getFinder();
120  if (!finder) {
121  // no finder provided, just call the default implementation
123  } else {
124  return finder.get();
125  }
126 }
127 
128 template <>
131  // Symmetric solver currently does not use this, we just implement it to make the templates work ...
132  // If implemented, make sure to include RANK in the created tree - BarnesHut currently does not do that
134 }
135 
136 template <typename TSphSolver>
138  TSphSolver::sanityCheck(storage);
139  // check that we don't solve gravity twice
141  if (this->equations.template contains<SphericalGravityEquation>()) {
142  throw InvalidSetup(
143  "Cannot use SphericalGravity in GravitySolver; only one solver of gravity is allowed");
144  }
145 }
146 
148 template class GravitySolver<AsymmetricSolver>;
149 // template class GravitySolver<DensityIndependentSolver>;
151 
@ SHARED
Multiple derivatives may accumulate into the buffer.
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
Definition: Assert.h:100
SPH solver with asymmetric particle evaluation.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Boundary conditions.
Density-independent formulation of SPH.
constexpr int DIMENSIONS
Number of spatial dimensions in the code.
Definition: Globals.h:22
SPH solver including gravity.
SPH kernels.
#define VERBOSE_LOG
Helper macro, creating.
Definition: Logger.h:242
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
Additional forces that do not depend on spatial derivatives.
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
Holder of quantity values and their temporal derivatives.
@ SECOND
Quantity with 1st and 2nd derivative.
Simple model of gravity, valid only for homogeneous spheres.
Statistics gathered and periodically displayed during the run.
@ SPH_EVAL_TIME
Wallclock duration of evaluation of SPH derivatives.
@ GRAVITY_BUILD_TIME
Wallclock duration of gravity tree building.
@ GRAVITY_EVAL_TIME
Wallclock duration of gravity evaluation.
Basic SPH solver, evaluating all interactions symmetrically.
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
Container holding equation terms.
Definition: EquationTerm.h:238
Extension of a generic SPH solver, including gravitational interactions of particles.
Definition: GravitySolver.h:22
virtual void sanityCheck(const Storage &storage) const override
Accumulated & getAccumulated()
Returns the accumulated storage, either thread-local or shared one based on SPH solver.
GravitySolver(IScheduler &scheduler, const RunSettings &settings, const EquationHolder &equations)
Creates the gravity solver, used implementation of gravity given by settings parameters.
virtual RawPtr< const IBasicFinder > getFinder(ArrayView< const Vector > r) override
virtual void loop(Storage &storage, Statistics &stats) override
virtual RawPtr< const IBasicFinder > getFinder(ArrayView< const Vector > r)
Returns a finder, already build using the provided positions.
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
Non-owning wrapper of pointer.
Definition: RawPtr.h:19
INLINE T * get() const
Definition: RawPtr.h:67
Object holding various statistics about current run.
Definition: Statistics.h:22
Statistics & set(const StatisticsId idx, TValue &&value)
Sets new values of a statistic.
Definition: Statistics.h:52
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Basic solver for integration of SPH equations.
Basic time-measuring tool. Starts automatically when constructed.
Definition: Timer.h:27
Creating code components based on values from settings.
constexpr Float gravity
Gravitational constant (CODATA 2014)
Definition: Constants.h:29
Provides a convenient way to construct objects from settings.
Definition: Factory.h:46
AutoPtr< IGravity > getGravity(const RunSettings &settings)
Definition: Factory.cpp:325
AutoPtr< ISymmetricFinder > getFinder(const RunSettings &settings)
Definition: Factory.cpp:156
AutoPtr< IBoundaryCondition > getBoundaryConditions(const RunSettings &settings, SharedPtr< IDomain > domain)
Definition: Factory.cpp:460
Overload of std::swap for Sph::Array.
Definition: Array.h:578