SPH
InitialConditionJobs.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "sph/initial/Galaxy.h"
6 
8 
11 protected:
12  struct {
13  bool shape = false;
14  bool material = false;
16 
17 public:
18  MonolithicBodyIc(const std::string& name, const BodySettings& overrides = EMPTY_SETTINGS);
19 
20  virtual std::string className() const override {
21  return "create monolithic body";
22  }
23 
25  requires() const override;
26 
28  return { { "shape", JobType::GEOMETRY }, { "material", JobType::MATERIAL } };
29  }
30 
31  virtual VirtualSettings getSettings() override;
32 
33  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
34 
35 protected:
36  virtual void addParticleCategory(VirtualSettings& settings);
37 };
38 
39 
42 private:
43  BodySettings mainBody;
44  int layerCnt = 1;
45 
46 public:
47  explicit DifferentiatedBodyIc(const std::string& name);
48 
49  virtual std::string className() const override {
50  return "create differentiated body";
51  }
52 
55  { "base shape", JobType::GEOMETRY },
56  { "base material", JobType::MATERIAL },
57  };
58  for (int i = 0; i < layerCnt; ++i) {
59  slots.insert("shape " + std::to_string(i + 1), JobType::GEOMETRY);
60  slots.insert("material " + std::to_string(i + 1), JobType::MATERIAL);
61  }
62  return slots;
63  }
64 
65  virtual VirtualSettings getSettings() override;
66 
67  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
68 };
69 
71 private:
72  Vector r0 = Vector(0._f);
73  Vector v0 = Vector(0._f);
74  Float mass = Constants::M_sun;
75  Float radius = Constants::R_sun;
76  int flag = 0;
77 
78 public:
79  explicit SingleParticleIc(const std::string& name)
80  : IParticleJob(name) {}
81 
82  virtual std::string className() const override {
83  return "create single particle";
84  }
85 
87  return {};
88  }
89 
90  virtual VirtualSettings getSettings() override;
91 
92  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
93 };
94 
95 class ImpactorIc : public MonolithicBodyIc {
96 public:
97  ImpactorIc(const std::string& name, const BodySettings& overrides = EMPTY_SETTINGS)
98  : MonolithicBodyIc(name, overrides) {}
99 
100  virtual std::string className() const override {
101  return "create impactor";
102  }
103 
105  requires() const override {
107  map.insert("target", JobType::PARTICLES);
108  return map;
109  }
110 
112  return {
113  { "target", JobType::PARTICLES },
114  { "shape", JobType::GEOMETRY },
115  { "material", JobType::MATERIAL },
116  };
117  }
118 
119  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
120 
121 private:
122  virtual void addParticleCategory(VirtualSettings& settings) override;
123 };
124 
125 class EquilibriumIc : public IParticleJob {
126 private:
127  EnumWrapper solver;
128  int boundaryThreshold;
129 
130 public:
131  EquilibriumIc(const std::string& name);
132 
133  virtual std::string className() const override {
134  return "set equilibrium energy";
135  }
136 
138  return { { "particles", JobType::PARTICLES } };
139  }
140 
141  virtual VirtualSettings getSettings() override;
142 
143  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
144 };
145 
147 private:
148  EnumWrapper id;
149  EnumWrapper mode;
150 
151  Float centralValue = 1.f;
152  Float radialGrad = 0.f;
153 
154  ExtraEntry curve;
155 
156 public:
157  ModifyQuantityIc(const std::string& name);
158 
159  virtual std::string className() const override {
160  return "modify quantity";
161  }
162 
164  return { { "particles", JobType::PARTICLES } };
165  }
166 
167  virtual VirtualSettings getSettings() override;
168 
169  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
170 };
171 
173 private:
174  EnumWrapper id;
175 
176  Float mean = 1.f;
177  Float magnitude = 1.f;
178 
179 public:
180  NoiseQuantityIc(const std::string& name);
181 
182  virtual std::string className() const override {
183  return "Perlin noise";
184  }
185 
187  return { { "particles", JobType::PARTICLES } };
188  }
189 
190  virtual VirtualSettings getSettings() override;
191 
192  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
193 
194 private:
195  template <Size Dims, typename TSetter>
196  void randomize(IRunCallbacks& callbacks, ArrayView<const Vector> r, const TSetter& setter) const;
197 
198  Float perlin(const Grid<Vector>& gradients, const Vector& v) const;
199 
200  Float dotGradient(const Grid<Vector>& gradients, const Indices& i, const Vector& v) const;
201 };
202 
203 enum class NBodySettingsId {
205  TOTAL_MASS,
208  HEIGHT_SCALE,
213 };
214 
216 
217 class NBodyIc : public IParticleJob {
218 private:
219  NBodySettings settings;
220 
221 public:
222  NBodyIc(const std::string& name, const NBodySettings& overrides = EMPTY_SETTINGS);
223 
224  virtual std::string className() const override {
225  return "N-body ICs";
226  }
227 
229  return {};
230  }
231 
232  virtual VirtualSettings getSettings() override;
233 
234  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
235 };
236 
238 private:
239  int particleCnt = 10000;
241 
243  Float mass = Constants::M_sun;
244  Float n = 3._f;
245 
246 public:
247  explicit PolytropicStarIc(const std::string& name);
248 
249  virtual std::string className() const override {
250  return "polytrope ICs";
251  }
252 
254  return {};
255  }
256 
257  virtual VirtualSettings getSettings() override;
258 
259  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
260 };
261 
263 private:
264  Float radius = 1.e6_f;
265  Float centralDensity = 1000._f;
266  Float centralEnergy = 1000._f;
267  Float gamma = 4._f / 3._f;
268  int particleCnt = 10000;
269 
270 public:
271  explicit IsothermalSphereIc(const std::string& name);
272 
273  virtual std::string className() const override {
274  return "isothermal sphere ICs";
275  }
276 
278  return {};
279  }
280 
281  virtual VirtualSettings getSettings() override;
282 
283  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
284 };
285 
286 class GalaxyIc : public IParticleJob {
287 private:
288  GalaxySettings settings;
289 
290 public:
291  explicit GalaxyIc(const std::string& name, const GalaxySettings& overrides = EMPTY_SETTINGS);
292 
293  virtual std::string className() const override {
294  return "galaxy ICs";
295  }
296 
298  return {};
299  }
300 
301  virtual VirtualSettings getSettings() override;
302 
303  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
304 };
305 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
const float radius
Definition: CurveDialog.cpp:18
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
Three-dimensional dynamically-allocated container.
@ GEOMETRY
Job providing geometry.
@ MATERIAL
Job providing a material.
@ PARTICLES
Job providing particles.
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
BasicVector< Float > Vector
Definition: Vector.h:539
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
Creates a single differentiated body.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
DifferentiatedBodyIc(const std::string &name)
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
EquilibriumIc(const std::string &name)
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
Copyable wrapper of a IExtraEntry.
GalaxyIc(const std::string &name, const GalaxySettings &overrides=EMPTY_SETTINGS)
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
Definition: Grid.h:16
Base class for all jobs providing particle data.
Definition: Job.h:242
Callbacks executed by the simulation to provide feedback to the user.
Definition: IRun.h:27
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
ImpactorIc(const std::string &name, const BodySettings &overrides=EMPTY_SETTINGS)
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
virtual UnorderedMap< std::string, ExtJobType > requires() const override
List of slots that need to be connected to evaluate the job.
Helper object for storing three (possibly four) int or bool values.
Definition: Indices.h:16
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
IsothermalSphereIc(const std::string &name)
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
ModifyQuantityIc(const std::string &name)
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
Creates a single monolithic body.
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
struct MonolithicBodyIc::@13 slotUsage
virtual UnorderedMap< std::string, ExtJobType > requires() const override
List of slots that need to be connected to evaluate the job.
virtual void addParticleCategory(VirtualSettings &settings)
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
MonolithicBodyIc(const std::string &name, const BodySettings &overrides=EMPTY_SETTINGS)
NBodyIc(const std::string &name, const NBodySettings &overrides=EMPTY_SETTINGS)
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
NoiseQuantityIc(const std::string &name)
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
PolytropicStarIc(const std::string &name)
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
SingleParticleIc(const std::string &name)
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
INLINE TValue & insert(const TKey &key, const TValue &value)
Adds a new element into the map or sets new value of element with the same key.
Definition: UnorderedMap.h:51
Holds a map of virtual entries, associated with a unique name.
const EmptySettingsTag EMPTY_SETTINGS
Definition: Settings.h:32
@ PARAMETRIZED_SPIRALING
Parametrized spiraling scheme by Saff & Kuijlaars (1997)
constexpr Float R_sun
Solar radius.
Definition: Constants.h:57
constexpr Float M_sun
Definition: Constants.h:51
Wrapper of an enum.
Definition: Settings.h:37