SPH
Gravity.cpp
Go to the documentation of this file.
1 #include "bench/Session.h"
2 #include "gravity/BarnesHut.h"
4 #include "gravity/Moments.h"
5 #include "system/Settings.h"
6 #include "tests/Setup.h"
7 #include "thread/Tbb.h"
8 
9 using namespace Sph;
10 
11 static void benchmarkGravity(IGravity& gravity, Benchmark::Context& context) {
12  BodySettings settings;
13  settings.set(BodySettingsId::DENSITY, 100._f)
16  Storage storage = Tests::getGassStorage(100000, settings, 5.e3_f);
17 
18  /*ArrayView<Vector> r = storage.getValue<Vector>(QuantityId::POSITIONS);
19  ArrayView<Float> m = storage.getValue<Float>(QuantityId::MASSES);*/
21  gravity.build(pool, storage);
22  Statistics stats;
24  // context.log("particle count: ", dv.size());
25  while (context.running()) {
26  std::fill(dv.begin(), dv.end(), Vector(0._f));
27  gravity.evalAll(pool, dv, stats);
29  }
30  /*const int approx = stats.getOr<int>(StatisticsId::GRAVITY_NODES_APPROX, 0);
31  const int exact = stats.getOr<int>(StatisticsId::GRAVITY_NODES_EXACT, 0);
32  const int total = stats.getOr<int>(StatisticsId::GRAVITY_NODE_COUNT, 0);
33  context.log("approx: ", approx);
34  context.log("exact: ", exact);
35  context.log("total: ", total);*/
36 }
37 
38 BENCHMARK("BruteForceGravity", "[gravity]", Benchmark::Context& context) {
40  benchmarkGravity(gravity, context);
41 }
42 
43 BENCHMARK("BarnesHut Octupole 0.2", "[gravity]", Benchmark::Context& context) {
45  benchmarkGravity(gravity, context);
46 }
47 
48 BENCHMARK("BarnesHut Octupole 0.5", "[gravity]", Benchmark::Context& context) {
50  benchmarkGravity(gravity, context);
51 }
52 
53 BENCHMARK("BarnesHut Octupole 0.8", "[gravity]", Benchmark::Context& context) {
55  benchmarkGravity(gravity, context);
56 }
57 
58 BENCHMARK("BarnesHut Octupole 5", "[gravity]", Benchmark::Context& context) {
60  benchmarkGravity(gravity, context);
61 }
62 
63 /*BENCHMARK("BarnesHut Monopole 0.2", "[gravity]", Benchmark::Context& context) {
64  BarnesHut gravity(0.2_f, MultipoleOrder::MONOPOLE);
65  benchmarkGravity(gravity, context);
66 }*/
67 
68 BENCHMARK("BarnesHut Monopole 0.5", "[gravity]", Benchmark::Context& context) {
70  benchmarkGravity(gravity, context);
71 }
72 
73 static void benchmarkGravity(IGravity& gravity, IScheduler& scheduler, Benchmark::Context& context) {
74  BodySettings settings;
75  settings.set(BodySettingsId::DENSITY, 100._f).set(BodySettingsId::ENERGY, 10._f);
76  Storage storage = Tests::getGassStorage(1000000, settings, 5.e3_f);
77 
78  while (context.running()) {
79  gravity.build(scheduler, storage);
81  }
82 }
83 
84 BENCHMARK("BarnesHut build Sequential", "[gravity]", Benchmark::Context& context) {
86  benchmarkGravity(gravity, SEQUENTIAL, context);
87 }
88 
89 BENCHMARK("BarnesHut build ThreadPool", "[gravity]", Benchmark::Context& context) {
91  benchmarkGravity(gravity, *ThreadPool::getGlobalInstance(), context);
92 }
Barnes-Hut algorithm for computation of gravitational acceleration.
Simple gravity solver evaluating all particle pairs.
BENCHMARK("BruteForceGravity", "[gravity]", Benchmark::Context &context)
Definition: Gravity.cpp:38
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
SequentialScheduler SEQUENTIAL
Global instance of the sequential scheduler.
Definition: Scheduler.cpp:43
Benchmark.
INLINE void clobberMemory()
Definition: Session.h:190
Helper functions performing common tasks in unit testing and benchmarks.
Implements IScheduler interface using TBB.
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
INLINE Iterator< StorageType > begin()
Definition: ArrayView.h:55
INLINE Iterator< StorageType > end()
Definition: ArrayView.h:63
Multipole approximation of distance particle.
Definition: BarnesHut.h:43
Computes gravitational acceleration by summing up forces from all particle pairs.
Interface for computing gravitational interactions of particles.
Definition: IGravity.h:14
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Settings & set(const TEnum idx, TValue &&value, std::enable_if_t<!std::is_enum< std::decay_t< TValue >>::value, int >=0)
Saves a value into the settings.
Definition: Settings.h:226
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
Thread pool capable of executing tasks concurrently.
Definition: Pool.h:70
static SharedPtr< ThreadPool > getGlobalInstance()
Returns the global instance of the thread pool.
Definition: Pool.cpp:211
Generic storage and input/output routines of settings.
@ ENERGY
Initial specific internal energy.
@ DENSITY
Density at zero pressure.
constexpr Float gravity
Gravitational constant (CODATA 2014)
Definition: Constants.h:29
Definition: MemoryPool.h:5
Storage getGassStorage(const Size particleCnt, BodySettings settings, const IDomain &domain)
Returns a storage with ideal gas particles, having pressure, energy and sound speed.
Definition: Setup.cpp:29