SPH
Solvers.cpp
Go to the documentation of this file.
1 #include "bench/Session.h"
7 #include "system/Platform.h"
8 #include "system/Settings.h"
9 #include "tests/Setup.h"
10 #include "thread/Tbb.h"
12 #include <atomic>
13 #include <iostream>
14 
15 using namespace Sph;
16 
17 static void benchmarkSolver(ISolver& solver, Benchmark::Context& context) {
18  BodySettings settings;
19  settings.set(BodySettingsId::DENSITY, 100._f).set(BodySettingsId::ENERGY, 10._f);
20  Storage storage = Tests::getSolidStorage(2000000, settings);
21  IMaterial& material = storage.getMaterial(0);
22  solver.create(storage, material);
23 
24  Statistics stats;
25  while (context.running()) {
26  solver.integrate(storage, stats);
27  }
28 
29 #ifdef SPH_PROFILE
30  StdOutLogger logger;
31  Profiler::getInstance().printStatistics(logger);
32 #endif
33 }
34 
35 BENCHMARK("SymmetricSolver simple", "[solvers]", Benchmark::Context& context) {
36  RunSettings settings;
38  SymmetricSolver<DIMENSIONS> solver(pool, settings, getStandardEquations(settings));
39  benchmarkSolver(solver, context);
40 }
41 
42 BENCHMARK("AsymmetricSolver simple", "[solvers]", Benchmark::Context& context) {
43  RunSettings settings;
45  AsymmetricSolver solver(pool, settings, getStandardEquations(settings));
46  benchmarkSolver(solver, context);
47 }
48 
49 BENCHMARK("EnergyConservingSolver simple", "[solvers]", Benchmark::Context& context) {
50  RunSettings settings;
52  EnergyConservingSolver solver(pool, settings, getStandardEquations(settings));
53  benchmarkSolver(solver, context);
54 }
55 
56 BENCHMARK("GravitySolver simple", "[solvers]", Benchmark::Context& context) {
57  RunSettings settings;
59  GravitySolver<AsymmetricSolver> solver(pool, settings, getStandardEquations(settings));
60  benchmarkSolver(solver, context);
61 }
62 
63 #ifdef SPH_USE_TBB
64 template <typename TSolver>
65 void test(const std::string path) {
66  RunSettings settings;
68  std::ofstream ofs(path);
69  for (Size threadCnt = 1; threadCnt <= 16; ++threadCnt) {
70  Tbb tbb(threadCnt);
71 
72  TSolver solver(tbb, settings, getStandardEquations(settings));
73  BodySettings body;
74  SharedPtr<Storage> storage = makeShared<Storage>(Tests::getSolidStorage(5'000'000, body));
75  IMaterial& material = storage->getMaterial(0);
76  solver.create(*storage, material);
77 
78  PredictorCorrector integrator(storage, settings);
79  Statistics stats;
80 
81  // initialize and heat up
82  for (Size i = 0; i < 2; ++i) {
83  std::cout << "prepare " << i << std::endl;
84  integrator.step(tbb, solver, stats);
85  }
86 
87  Timer timer;
88  for (Size i = 0; i < 50; ++i) {
89  std::cout << "step " << i << std::endl;
90  integrator.step(tbb, solver, stats);
91  }
92  const int64_t duration = timer.elapsed(TimerUnit::MILLISECOND);
93  std::cout << threadCnt << " " << duration << std::endl;
94  ofs << threadCnt << " " << duration << std::endl;
95  }
96 }
97 
98 BENCHMARK("Thread scaling", "[solvers]", Benchmark::Context& context) {
99  test<AsymmetricSolver>("scaling_asym.txt");
100  test<SymmetricSolver<DIMENSIONS>>("scaling_sym.txt");
101  test<GravitySolver<AsymmetricSolver>>("scaling_gravity.txt");
102  while (context.running()) {
103  }
104 }
105 
106 #endif
SPH solver with asymmetric particle evaluation.
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
SPH solver including gravity.
System functions.
Benchmark.
Helper functions performing common tasks in unit testing and benchmarks.
BENCHMARK("SymmetricSolver simple", "[solvers]", Benchmark::Context &context)
Definition: Solvers.cpp:35
NAMESPACE_SPH_BEGIN EquationHolder getStandardEquations(const RunSettings &settings, const EquationHolder &other)
Standard SPH equation set, using density and specific energy as independent variables.
Standard SPH formulation that uses continuity equation for solution of density.
Basic SPH solver, evaluating all interactions symmetrically.
Implements IScheduler interface using TBB.
Algorithms for temporal evolution of the physical model.
Generic SPH solver, evaluating equations for each particle separately.
See Owen 2009: A compatibly differenced total energy conserving form of SPH.
Extension of a generic SPH solver, including gravitational interactions of particles.
Definition: GravitySolver.h:22
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
Base class for all solvers.
Definition: ISolver.h:20
virtual void integrate(Storage &storage, Statistics &stats)=0
Computes derivatives of all time-dependent quantities.
virtual void create(Storage &storage, IMaterial &material) const =0
Initializes all quantities needed by the solver in the storage.
Predictor-corrector second-order timestepping.
Definition: TimeStepping.h:97
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
Standard output logger.
Definition: Logger.h:138
Container storing all quantities used within the simulations.
Definition: Storage.h:230
MaterialView getMaterial(const Size matIdx) const
Returns an object containing a reference to given material.
Definition: Storage.cpp:366
Scheduler encapsulating Intel Thread Building Blocks (TBB).
Definition: Tbb.h:18
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
Basic time-measuring tool. Starts automatically when constructed.
Definition: Timer.h:27
int64_t elapsed(const TimerUnit unit) const
Returns elapsed time in timer units. Does not reset the timer.
Definition: Timer.cpp:55
Generic storage and input/output routines of settings.
@ ENERGY
Initial specific internal energy.
@ DENSITY
Density at zero pressure.
Definition: MemoryPool.h:5
Storage getSolidStorage(const Size particleCnt, BodySettings settings, const IDomain &domain)
Returns a storage with stress tensor.
Definition: Setup.cpp:59