SPH
NBodySolver.h
Go to the documentation of this file.
1 #pragma once
2 
7 
9 #include "thread/ThreadLocal.h"
10 #include "timestepping/ISolver.h"
11 
13 
14 class ISymmetricFinder;
15 class ICollisionHandler;
16 class IOverlapHandler;
17 class IGravity;
18 struct CollisionRecord;
19 class CollisionStats;
20 enum class CollisionResult;
21 enum class OverlapEnum;
22 
24 class HardSphereSolver : public ISolver {
25 private:
27  AutoPtr<IGravity> gravity;
28 
29  IScheduler& scheduler;
30 
31  struct ThreadData {
34 
36  Array<CollisionRecord> collisions;
37  };
38 
39  ThreadLocal<ThreadData> threadData;
40 
45 
47  FlatSet<Size> removed;
48 
50  Array<Float> searchRadii;
51 
52  struct {
53 
56 
59 
60  } collision;
61 
62  struct {
63 
66 
69 
70  } overlap;
71 
72  struct {
74  bool use;
75 
78 
79  } rigidBody;
80 
84 
85 public:
87  HardSphereSolver(IScheduler& scheduler, const RunSettings& settings);
88 
90  HardSphereSolver(IScheduler& scheduler, const RunSettings& settings, AutoPtr<IGravity>&& gravity);
91 
93  HardSphereSolver(IScheduler& scheduler,
94  const RunSettings& settings,
95  AutoPtr<IGravity>&& gravity,
96  AutoPtr<ICollisionHandler>&& collisionHandler,
97  AutoPtr<IOverlapHandler>&& overlapHandler);
98 
99  ~HardSphereSolver() override;
100 
101  virtual void integrate(Storage& storage, Statistics& stats) override;
102 
104  virtual void collide(Storage& storage, Statistics& stats, const Float dt) override;
105 
106  virtual void create(Storage& storage, IMaterial& material) const override;
107 
108 private:
109  void rotateLocalFrame(Storage& storage, const Float dt);
110 
111  enum class SearchEnum {
114  FIND_LOWER_RANK,
115 
117  USE_RADII,
118  };
119 
120  CollisionRecord findClosestCollision(const Size i,
121  const SearchEnum opt,
122  const Interval interval,
123  Array<NeighbourRecord>& neighs);
124 
129  Optional<Float> checkCollision(const Vector& r1,
130  const Vector& v1,
131  const Vector& r2,
132  const Vector& v2,
133  const Float dt) const;
134 };
135 
137 class SoftSphereSolver : public ISolver {
139  AutoPtr<IGravity> gravity;
140 
141  IScheduler& scheduler;
142 
143  struct ThreadData {
145  Array<NeighbourRecord> neighs;
146  };
147 
148  ThreadLocal<ThreadData> threadData;
149 
151  struct {
154  } force;
155 
156 public:
157  SoftSphereSolver(IScheduler& scheduler, const RunSettings& settings);
158 
159  SoftSphereSolver(IScheduler& scheduler, const RunSettings& settings, AutoPtr<IGravity>&& gravity);
160 
161  ~SoftSphereSolver() override;
162 
163  virtual void integrate(Storage& storage, Statistics& stats) override;
164 
165  virtual void create(Storage& storage, IMaterial& material) const override;
166 };
167 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
CollisionResult
Definition: Collision.h:15
Container storing sorted unique values.
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 interface for all solvers.
#define NAMESPACE_SPH_END
Definition: Object.h:12
Template for thread-local storage.
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
Solver computing gravitational interactions of hard-sphere particles.
Definition: NBodySolver.h:24
HardSphereSolver(IScheduler &scheduler, const RunSettings &settings)
Creates the solver, using the gravity implementation specified by settings.
Definition: NBodySolver.cpp:17
Float allowedRatio
Limit ovelap of particle to be classified as "overlap" rather than "collision".
Definition: NBodySolver.h:68
virtual void collide(Storage &storage, Statistics &stats, const Float dt) override
Checks and resolves particle collisions.
bool use
Use moment of inertia of individual particles.
Definition: NBodySolver.h:74
AutoPtr< IOverlapHandler > handler
Handler used to resolve particle overlaps.
Definition: NBodySolver.h:65
virtual void integrate(Storage &storage, Statistics &stats) override
Computes derivatives of all time-dependent quantities.
Definition: NBodySolver.cpp:96
AutoPtr< ICollisionHandler > handler
Handler used to resolve particle collisions.
Definition: NBodySolver.h:55
Float maxAngle
Maximum rotation of a particle in a single (sub)step.
Definition: NBodySolver.h:77
~HardSphereSolver() override
AutoPtr< ISymmetricFinder > finder
Finder for searching the neighbours.
Definition: NBodySolver.h:58
virtual void create(Storage &storage, IMaterial &material) const override
Initializes all quantities needed by the solver in the storage.
Abstraction of collision outcome.
Definition: Collision.h:29
Interface for computing gravitational interactions of particles.
Definition: IGravity.h:14
Material settings and functions specific for one material.
Definition: IMaterial.h:110
Handles overlaps of particles.
Definition: Collision.h:54
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
Extension of IBasicFinder, allowing to search only particles with lower rank in smoothing length.
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
Solver computing gravitational interactions and repulsive forces between particles.
Definition: NBodySolver.h:137
virtual void create(Storage &storage, IMaterial &material) const override
Initializes all quantities needed by the solver in the storage.
~SoftSphereSolver() override
SoftSphereSolver(IScheduler &scheduler, const RunSettings &settings)
virtual void integrate(Storage &storage, Statistics &stats) override
Computes derivatives of all time-dependent quantities.
Object holding various statistics about current run.
Definition: Statistics.h:22
Container storing all quantities used within the simulations.
Definition: Storage.h:230
OverlapEnum
Definition: Settings.h:826