SPH
Setup.h
Go to the documentation of this file.
1 #pragma once
2 
7 
9 #include "quantities/IMaterial.h"
10 #include "quantities/Storage.h"
13 #include "system/Settings.h"
14 #include "system/Statistics.h"
15 #include "thread/Pool.h"
16 
18 
19 namespace Tests {
22 Storage getStorage(const Size particleCnt);
23 
25 Storage getGassStorage(const Size particleCnt, BodySettings settings, const IDomain& domain);
26 
28 Storage getGassStorage(const Size particleCnt,
30  const Float radius = 1.f);
31 
33 Storage getSolidStorage(const Size particleCnt, BodySettings settings, const IDomain& domain);
34 
36 Storage getSolidStorage(const Size particleCnt,
38  const Float radius = 1._f);
39 
41 Size getClosestParticle(const Storage& storage, const Vector& p);
42 
43 
46 template <typename TSolver, typename TLambda>
47 void computeField(Storage& storage, EquationHolder&& equations, TLambda&& lambda, const Size repeatCnt = 1) {
48  ArrayView<Vector> r, v, dv;
49  tie(r, v, dv) = storage.getAll<Vector>(QuantityId::POSITION);
50  for (Size i = 0; i < v.size(); ++i) {
51  v[i] = lambda(r[i]);
52  }
53  equations += makeTerm<ConstSmoothingLength>();
55  TSolver solver(pool, RunSettings::getDefaults(), std::move(equations));
56  solver.create(storage, storage.getMaterial(0));
57  Statistics stats;
58  for (Size i = 0; i < repeatCnt; ++i) {
59  solver.integrate(storage, stats);
60  }
61 }
62 
63 // Helper equation term using single derivative
64 template <typename TDerivative>
66  virtual void setDerivatives(DerivativeHolder& derivatives, const RunSettings& settings) override {
67  derivatives.require(makeAuto<TDerivative>(settings));
68  }
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),
75  Storage& UNUSED(storage),
76  const Float UNUSED(t)) override {}
77 
78  virtual void create(Storage& UNUSED(storage), IMaterial& UNUSED(material)) const override {}
79 };
80 
82 template <typename TDerivative, typename TSolver, typename TLambda>
83 void computeField(Storage& storage, TLambda&& lambda, const Size repeatCnt = 1) {
84  EquationHolder equations;
85  equations += makeTerm<SingleDerivativeMaker<TDerivative>>();
86  computeField<TSolver>(storage, std::move(equations), std::forward<TLambda>(lambda), repeatCnt);
87 }
88 
89 } // namespace Tests
90 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
const float radius
Definition: CurveDialog.cpp:18
Spatial derivatives to be computed by SPH discretization.
Object defining computational domain.
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 all particle materials.
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
Simple thread pool with fixed number of threads.
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
StaticArray< T0 &, sizeof...(TArgs)+1 > tie(T0 &t0, TArgs &... rest)
Creates a static array from a list of l-value references.
Definition: StaticArray.h:281
Statistics gathered and periodically displayed during the run.
Container for storing particle quantities and materials.
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
virtual void require(AutoPtr< IDerivative > &&derivative)
Adds derivative if not already present.
Definition: Derivative.cpp:77
Container holding equation terms.
Definition: EquationTerm.h:238
Base class for computational domains.
Definition: Domain.h:29
Represents a term or terms appearing in evolutionary equations.
Definition: EquationTerm.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
static const Settings & getDefaults()
\brief Returns a reference to object containing default values of all settings.
Object holding various statistics about current run.
Definition: Statistics.h:22
Container storing all quantities used within the simulations.
Definition: Storage.h:230
StaticArray< Array< TValue > &, 3 > getAll(const QuantityId key)
Retrieves quantity buffers from the storage, given its key and value type.
Definition: Storage.cpp:163
MaterialView getMaterial(const Size matIdx) const
Returns an object containing a reference to given material.
Definition: Storage.cpp:366
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.
Definition: Setup.h:19
Storage getSolidStorage(const Size particleCnt, BodySettings settings, const IDomain &domain)
Returns a storage with stress tensor.
Definition: Setup.cpp:59
void computeField(Storage &storage, EquationHolder &&equations, TLambda &&lambda, const Size repeatCnt=1)
Definition: Setup.h:47
Storage getStorage(const Size particleCnt)
Definition: Setup.cpp:12
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
Size getClosestParticle(const Storage &storage, const Vector &p)
Returns the index to the particle closest to given point.
Definition: Setup.cpp:94
virtual void initialize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: Setup.h:70
virtual void create(Storage &UNUSED(storage), IMaterial &UNUSED(material)) const override
Definition: Setup.h:78
virtual void finalize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage), const Float UNUSED(t)) override
Definition: Setup.h:74
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
Definition: Setup.h:66