SPH
Functions.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "math/rng/Rng.h"
10 #include "objects/wrappers/Flags.h"
11 #include "physics/Constants.h"
12 
14 
16 namespace Analytic {
17 
19 class StaticSphere {
20 private:
22  Float r0;
23 
25  Float rho;
26 
27 public:
28  StaticSphere(const Float r0, const Float rho)
29  : r0(r0)
30  , rho(rho) {}
31 
33  INLINE Float getPressure(const Float r) const {
34  if (r > r0) {
35  return 0._f;
36  }
37  return 2._f / 3._f * PI * Constants::gravity * sqr(rho) * (sqr(r0) - sqr(r));
38  }
39 
43  INLINE Vector getAcceleration(const Vector& r) const {
44  const Float l = getLength(r);
45  const Float l0 = min(r0, l);
46  return -Constants::gravity * rho * sphereVolume(l0) * r / pow<3>(l);
47  }
48 
51  return -16._f / 15._f * sqr(PI) * sqr(rho) * Constants::gravity * pow<5>(r0);
52  }
53 };
54 
55 } // namespace Analytic
56 
58 namespace Rigid {
59 
62  return SymmetricTensor::identity() * (0.4_f * m * sqr(r));
63 }
64 
71  return I + m * (SymmetricTensor::identity() * getSqrLength(a) - symmetricOuter(a, a));
72 }
73 
74 } // namespace Rigid
75 
83  return sqrt(sphereVolume(1._f) * rho * Constants::gravity);
84 }
85 
93 Float evalBenzAsphaugScalingLaw(const Float D, const Float rho);
94 
100 Float getImpactEnergy(const Float R, const Float r, const Float v);
101 
114 Float getEffectiveImpactArea(const Float R, const Float r, const Float phi);
115 
124 Float getImpactorRadius(const Float R_pb, const Float v_imp, const Float QOverQ_D, const Float rho);
125 
136 Float getImpactorRadius(const Float R_pb,
137  const Float v_imp,
138  const Float phi,
139  const Float Q_effOverQ_D,
140  const Float rho);
141 
142 
143 class ImpactCone {
144 private:
145  AffineMatrix frame;
146  Float v_c;
147 
148  UniformRng rng;
149 
150 public:
151  explicit ImpactCone(const AffineMatrix& frame, const Float cutoffVelocity)
152  : frame(frame)
153  , v_c(cutoffVelocity) {}
154 
163  void getFragments(const Float m_tot, const Size N, Array<Vector>& r, Array<Vector>& v, Array<Float>& m) {
164  constexpr Float theta = PI / 4._f;
165  const Float m_frag = m_tot / N;
166  for (Size i = 0; i < N; ++i) {
167  const Float phi = 2._f * PI * rng();
169  v.push(frame * sphericalToCartesian(v_c, theta, phi));
170  r.push(frame.translation());
171  m.push(m_frag);
172  }
173  }
174 };
175 
176 class CollisionMC {
177 private:
178  UniformRng rng;
179 
180 public:
181  Array<Float> operator()(const Float QoverQ_D, const Float M_tot, const Float m_min) {
182  const Float largest = max(M_LR(QoverQ_D, M_tot), M_LF(QoverQ_D, M_tot));
183  const Float exponent = q(QoverQ_D) + 1._f;
184 
186  Array<Float> fragments;
187  fragments.push(largest);
188  Float m_partial = largest;
189  while (M_tot - m_partial > m_min) {
190  const Float m = pow(rng(), 1._f / exponent) - m_min;
191  if (m + m_partial > M_tot) {
192  continue;
193  }
194  fragments.push(m);
195  m_partial += m;
196  }
197  return fragments;
198  }
199 
200 private:
201  Float M_LR(const Float QoverQ_D, const Float M_tot) {
202  if (QoverQ_D < 1._f) {
203  return (-0.5_f * (QoverQ_D - 1._f) + 0.5_f) * M_tot;
204  } else {
205  return (-0.35_f * (QoverQ_D - 1._f) + 0.5_f) * M_tot;
206  }
207  }
208 
209  Float M_LF(const Float QoverQ_D, const Float M_tot) {
210  return 8.e-3_f * (QoverQ_D * exp(-sqr(0.25_f * QoverQ_D))) * M_tot;
211  }
212 
213  Float q(const Float QoverQ_D) {
214  return -10._f + 7._f * pow(QoverQ_D, 0.4_f) * exp(-QoverQ_D / 7._f);
215  }
216 };
217 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Definitions of physical constaints (in SI units).
Wrapper over enum allowing setting (and querying) individual bits of the stored value.
Float getImpactEnergy(const Float R, const Float r, const Float v)
Computes the impact energy Q from impact parameters.
Definition: Functions.cpp:18
Float getEffectiveImpactArea(const Float R, const Float r, const Float phi)
Returns the the ratio of the cross-sectional area of the impact and the total area of the impactor.
Definition: Functions.cpp:22
Float evalBenzAsphaugScalingLaw(const Float D, const Float rho)
Returns the critical energy Q_D^* as a function of body diameter.
Definition: Functions.cpp:5
INLINE Float getCriticalFrequency(const Float rho)
Computes the critical (break-up) angular velocity of a body.
Definition: Functions.h:82
Float getImpactorRadius(const Float R_pb, const Float v_imp, const Float QOverQ_D, const Float rho)
Calculates the impactor radius to satisfy required impact parameters.
Definition: Functions.cpp:35
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 max(const T &f1, const T &f2)
Definition: MathBasic.h:20
NAMESPACE_SPH_BEGIN constexpr INLINE T min(const T &f1, const T &f2)
Minimum & Maximum value.
Definition: MathBasic.h:15
constexpr INLINE Float pow< 5 >(const Float v)
Definition: MathUtils.h:140
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 INLINE Float pow< 3 >(const Float v)
Definition: MathUtils.h:132
constexpr INLINE Float pow(const Float v)
Power for floats.
constexpr INLINE Float sphereVolume(const Float radius)
Computes a volume of a sphere given its radius.
Definition: MathUtils.h:375
INLINE T exp(const T f)
Definition: MathUtils.h:269
constexpr Float PI
Mathematical constants.
Definition: MathUtils.h:361
#define INLINE
Macros for conditional compilation based on selected compiler.
Definition: Object.h:31
#define NAMESPACE_SPH_END
Definition: Object.h:12
Random number generators.
constexpr int N
Basic algebra for symmetric 2nd order tensors.
INLINE SymmetricTensor symmetricOuter(const Vector &v1, const Vector &v2)
SYMMETRIZED outer product of two vectors.
INLINE Float getLength(const Vector &v)
Returns the length of the vector. Enabled only for vectors of floating-point precision.
Definition: Vector.h:579
INLINE Float getSqrLength(const Vector &v)
Definition: Vector.h:574
INLINE Vector sphericalToCartesian(const Float r, const Float theta, const Float phi)
Constructs a vector from spherical coordinates.
Definition: Vector.h:788
INLINE Vector translation() const
Definition: AffineMatrix.h:49
Properties of a homogeneous sphere in rest (no temporal derivatives)
Definition: Functions.h:19
INLINE Float getPressure(const Float r) const
Return the pressure at given radius r of a sphere self-compressed by gravity.
Definition: Functions.h:33
INLINE Vector getAcceleration(const Vector &r) const
Returns the gravitational acceleration at given radius r.
Definition: Functions.h:43
INLINE Float getEnergy() const
Returns the gravitational potential energy of the sphere.
Definition: Functions.h:50
StaticSphere(const Float r0, const Float rho)
Definition: Functions.h:28
Generic dynamically allocated resizable storage.
Definition: Array.h:43
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
Definition: Array.h:306
Array< Float > operator()(const Float QoverQ_D, const Float M_tot, const Float m_min)
Definition: Functions.h:181
ImpactCone(const AffineMatrix &frame, const Float cutoffVelocity)
Definition: Functions.h:151
void getFragments(const Float m_tot, const Size N, Array< Vector > &r, Array< Vector > &v, Array< Float > &m)
Generates fragments at the impact point.
Definition: Functions.h:163
Symmetric tensor of 2nd order.
static INLINE SymmetricTensor identity()
Returns an identity tensor.
Random number generator with uniform distribution.
Definition: Rng.h:16
Contains analytic solutions of equations.
Definition: Functions.h:16
constexpr Float gravity
Gravitational constant (CODATA 2014)
Definition: Constants.h:29
Physics of rigid body.
Definition: Functions.h:58
INLINE SymmetricTensor sphereInertia(const Float m, const Float r)
Computes the inertia tensor of a homogeneous sphere.
Definition: Functions.h:61
INLINE SymmetricTensor parallelAxisTheorem(const SymmetricTensor &I, const Float m, const Vector &a)
Computes the inertia tensor with respect to given point.
Definition: Functions.h:70