SPH
Analysis.h
Go to the documentation of this file.
1 #pragma once
2 
7 
12 #include "system/Settings.h"
13 
15 
16 class Storage;
17 class Path;
18 class ILogger;
19 struct PlotPoint;
20 enum class QuantityId;
21 namespace Post {
22 enum class HistogramId;
23 }
24 
26 
27 namespace Post {
28 
36 Array<Size> findNeighbourCounts(const Storage& storage, const Float particleRadius);
37 
38 
39 enum class ComponentFlag {
41  OVERLAP = 0,
42 
44  SEPARATE_BY_FLAG = 1 << 0,
45 
50  ESCAPE_VELOCITY = 1 << 1,
51 
54  SORT_BY_MASS = 1 << 2,
55 };
56 
67 Size findComponents(const Storage& storage,
68  const Float particleRadius,
69  const Flags<ComponentFlag> flags,
70  Array<Size>& indices);
71 
76  const Float particleRadius,
77  const Flags<ComponentFlag> flags);
78 
79 
80 struct Tumbler {
83 
86 };
87 
93 Array<Tumbler> findTumblers(const Storage& storage, const Float limit);
94 
96 enum class MoonEnum {
98  RUNAWAY,
99  MOON,
100  IMPACTOR,
101  UNOBSERVABLE,
102 };
103 
125 Array<MoonEnum> findMoons(const Storage& storage, const Float radius = 1._f, const Float limit = 0._f);
126 
138  const Size i,
139  const Float radius = 1._f,
140  const Float limit = 0._f);
141 
145  ArrayView<const Size> idxs = nullptr);
146 
150  const Vector& r0,
151  ArrayView<const Size> idxs = nullptr);
152 
156  ArrayView<const Size> idxs = nullptr);
157 
162  const Vector& r0,
163  const Vector& v0,
164  ArrayView<const Size> idxs = nullptr);
165 
169  ArrayView<const Size> idxs = nullptr);
170 
185 Float getSphericity(IScheduler& scheduler, const Storage& strorage, const Float resolution = 0.05_f);
186 
191 enum class HistogramId {
193  RADII = -1,
194 
199 
201  VELOCITIES = -3,
202 
205 
208  ROTATIONAL_PERIOD = -5,
209 
211  ROTATIONAL_AXIS = -6,
212 };
213 
215 
217 enum class HistogramSource {
219  COMPONENTS,
220 
222  PARTICLES,
223 };
224 
225 
228 
233 
238 
241 
247 
254 
257  bool centerBins = true;
258 
261 
263  Float radius = 2._f;
264 
267 
269 
273  Function<bool(Size index)> validator = [](Size UNUSED(index)) { return true; };
274 };
275 
277 struct HistPoint {
280 
283 
284  bool operator==(const HistPoint& other) const;
285 };
286 
291 
294  const ExtHistogramId id,
295  const HistogramSource source,
296  const HistogramParams& params);
297 
305  const ExtHistogramId id,
306  const HistogramSource source,
307  const HistogramParams& params);
308 
309 
312 private:
313  Float a, b;
314 
315 public:
321  : a(slope)
322  , b(offset) {}
323 
325  INLINE Float operator()(const Float x) const {
326  return a * x + b;
327  }
328 
330  Float slope() const {
331  return a;
332  }
333 
335  Float offset() const {
336  return b;
337  }
338 
342  Float solve(const Float y) const {
343  SPH_ASSERT(a != 0._f);
344  return (y - b) / a;
345  }
346 };
347 
352 LinearFunction getLinearFit(ArrayView<const PlotPoint> points);
353 
354 
356 private:
357  Float a, b, c;
358 
359 public:
361  QuadraticFunction(const Float a, const Float b, const Float c)
362  : a(a)
363  , b(b)
364  , c(c) {}
365 
366  INLINE Float operator()(const Float x) const {
367  return (a * x + b) * x + c;
368  }
369 
370  Float quadratic() const {
371  return a;
372  }
373  Float linear() const {
374  return b;
375  }
376  Float constant() const {
377  return c;
378  }
379 
385  SPH_ASSERT(a != 0);
386  const Float disc = sqr(b) - 4._f * a * (c - y);
387  if (disc < 0._f) {
388  return EMPTY_ARRAY;
389  } else if (disc == 0._f) {
390  return { -b / (2._f * a) };
391  } else {
392  const Float sqrtDisc = sqrt(disc);
393  Float x1 = (-b - sqrtDisc) / (2._f * a);
394  Float x2 = (-b + sqrtDisc) / (2._f * a);
395  if (x1 > x2) {
396  std::swap(x1, x2);
397  }
398  return { x1, x2 };
399  }
400  }
401 };
402 
403 QuadraticFunction getQuadraticFit(ArrayView<const PlotPoint> points);
404 
405 } // namespace Post
406 
SPH_EXTEND_ENUM(QuantityId, Post::HistogramId)
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
const float radius
Definition: CurveDialog.cpp:18
Wrapper of type containing either a value or an error message.
Generic wrappers of lambdas, functors and other callables.
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
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
Definition: MathUtils.h:67
INLINE T sqrt(const T f)
Return a squared root of a value.
Definition: MathUtils.h:78
constexpr Float INFTY
Definition: MathUtils.h:38
#define INLINE
Macros for conditional compilation based on selected compiler.
Definition: Object.h:31
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
QuantityId
Unique IDs of basic quantities of SPH particles.
Definition: QuantityIds.h:19
NAMESPACE_SPH_BEGIN const struct EmptyArray EMPTY_ARRAY
Wrapper of an integral value providing functions for reading and modifying individual bits.
Definition: Flags.h:20
Interface providing generic (text, human readable) output of the program.
Definition: Logger.h:22
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
Object representing a path on a filesystem.
Definition: Path.h:17
Class representing an ordinary 1D linear function.
Definition: Analysis.h:311
Float solve(const Float y) const
Finds a value of x such that f(x) = y for given y.
Definition: Analysis.h:342
Float offset() const
Returns the offset in y-direction.
Definition: Analysis.h:335
INLINE Float operator()(const Float x) const
Evaluates the linear function for given value.
Definition: Analysis.h:325
Float slope() const
Returns the slope of the function.
Definition: Analysis.h:330
LinearFunction(const Float slope, const Float offset)
Creates a new linear function.
Definition: Analysis.h:320
StaticArray< Float, 2 > solve(const Float y) const
Returns solutions of a quadratic equation y = a*x^2 + b*x + c.
Definition: Analysis.h:384
Float quadratic() const
Definition: Analysis.h:370
Float constant() const
Definition: Analysis.h:376
QuadraticFunction(const Float a, const Float b, const Float c)
y = a*x^2 + b*x + c
Definition: Analysis.h:361
INLINE Float operator()(const Float x) const
Definition: Analysis.h:366
Float linear() const
Definition: Analysis.h:373
Array with fixed number of allocated elements.
Definition: StaticArray.h:19
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Symmetric tensor of 2nd order.
Generic storage and input/output routines of settings.
Definition: Analysis.h:21
Array< MoonEnum > findMoons(const Storage &storage, const Float radius=1._f, const Float limit=0._f)
Find a potential satellites of the largest body.
Definition: Analysis.cpp:367
Array< HistPoint > getDifferentialHistogram(ArrayView< const Float > values, const HistogramParams &params)
Computes the differential histogram from given values.
Definition: Analysis.cpp:861
Array< Size > findNeighbourCounts(const Storage &storage, const Float particleRadius)
Finds the number of neighbours of each particle.
Definition: Analysis.cpp:22
HistogramSource
Source data used to construct the histogram.
Definition: Analysis.h:217
@ COMPONENTS
Equivalent radii of connected chunks of particles (SPH framework)
@ PARTICLES
Radii of individual particles, considering particles as spheres (N-body framework)
LinearFunction getLinearFit(ArrayView< const PlotPoint > points)
Finds a linear fit to a set of points.
Definition: Analysis.cpp:914
QuadraticFunction getQuadraticFit(ArrayView< const PlotPoint > points)
Definition: Analysis.cpp:935
Array< Size > findLargestComponent(const Storage &storage, const Float particleRadius, const Flags< ComponentFlag > flags)
Returns the indices of particles belonging to the largest remnant.
Definition: Analysis.cpp:216
Vector getAngularFrequency(ArrayView< const Float > m, ArrayView< const Vector > r, ArrayView< const Vector > v, const Vector &r0, const Vector &v0, ArrayView< const Size > idxs=nullptr)
Computes the immediate vector of angular frequency of a rigid body.
Definition: Analysis.cpp:514
ComponentFlag
Definition: Analysis.h:39
@ OVERLAP
Specifies that overlapping particles belong into the same component.
@ SEPARATE_BY_FLAG
Specifies that particles with different flag belong to different component, even if they overlap.
Size findComponents(const Storage &storage, const Float particleRadius, const Flags< ComponentFlag > flags, Array< Size > &indices)
Finds and marks connected components (a.k.a. separated bodies) in the array of vertices.
Definition: Analysis.cpp:86
Vector getCenterOfMass(ArrayView< const Float > m, ArrayView< const Vector > r, ArrayView< const Size > idxs=nullptr)
Computes the center of mass.
Definition: Analysis.cpp:461
Array< Tumbler > findTumblers(const Storage &storage, const Float limit)
Find all tumbling asteroids.
Definition: Analysis.cpp:441
SymmetricTensor getInertiaTensor(ArrayView< const Float > m, ArrayView< const Vector > r, const Vector &r0, ArrayView< const Size > idxs=nullptr)
Computes the total inertia tensor of particles with respect to given center.
Definition: Analysis.cpp:484
MoonEnum
Potential relationship of the body with a respect to the largest remnant (fragment).
Definition: Analysis.h:96
@ LARGEST_FRAGMENT
This is the largest fragment (or remnant, depending on definition)
@ UNOBSERVABLE
Body is smaller than the user-defined observational limit.
@ RUNAWAY
Body is on hyperbolic trajectory, ejected away from the largest remnant (fragment)
@ IMPACTOR
Body is on collisional course with the largest remnant (fragment)
@ MOON
Body is on elliptical trajectory, it is a potential sattelite.
Array< HistPoint > getCumulativeHistogram(const Storage &storage, const ExtHistogramId id, const HistogramSource source, const HistogramParams &params)
Computes cumulative (integral) histogram of particles in the storage.
Definition: Analysis.cpp:814
HistogramId
Quantity from which the histogram is constructed.
Definition: Analysis.h:191
@ VELOCITIES
Particle velocities.
@ ROTATIONAL_AXIS
Distribution of axis directions, from -pi to pi.
@ ROTATIONAL_FREQUENCY
Rotational frequency in revs/day.
@ RADII
Particle radii or equivalent radii of components.
Float getSphericity(IScheduler &scheduler, const Storage &strorage, const Float resolution=0.05_f)
Computes the sphericity coefficient of a body.
Definition: Analysis.cpp:550
Size findMoonCount(ArrayView< const Float > m, ArrayView< const Vector > r, ArrayView< const Vector > v, const Size i, const Float radius=1._f, const Float limit=0._f)
Find the number of moons of given body.
Definition: Analysis.cpp:415
void swap(Sph::Array< T, TCounter > &ar1, Sph::Array< T, TCounter > &ar2)
Definition: Array.h:580
Point in 2D plot.
Definition: Point.h:16
Point in the histogram.
Definition: Analysis.h:277
Size count
Number of particles/components.
Definition: Analysis.h:282
Float value
Value of the quantity.
Definition: Analysis.h:279
bool operator==(const HistPoint &other) const
Definition: Analysis.cpp:572
Parameters used by histogram of components.
Definition: Analysis.h:260
Float radius
Radius of particles in units of their smoothing lengths.
Definition: Analysis.h:263
Flags< Post::ComponentFlag > flags
Determines how the particles are clustered into the components.
Definition: Analysis.h:266
Parameters of the histogram.
Definition: Analysis.h:227
Float velocityCutoff
Cutoff value (upper bound) of particle velocity for inclusion in the histogram.
Definition: Analysis.h:253
Float referenceDensity
Reference density, used when computing particle radii from their masses.
Definition: Analysis.h:240
Function< bool(Size index)> validator
Function used for inclusiong/exclusion of values in the histogram.
Definition: Analysis.h:273
Float massCutoff
Cutoff value (lower bound) of particle mass for inclusion in the histogram.
Definition: Analysis.h:246
Interval range
Range of values from which the histogram is constructed.
Definition: Analysis.h:232
struct Post::HistogramParams::ComponentParams components
Size binCnt
Number of histogram bins.
Definition: Analysis.h:237
Size index
Index of particle (body)
Definition: Analysis.h:82
Float beta
Angle between the current angular velocity and the angular momentum.
Definition: Analysis.h:85