SPH
Functions.cpp
Go to the documentation of this file.
1 #include "physics/Functions.h"
2 
4 
6  const Float D_cgs = 100._f * D;
7  const Float rho_cgs = 1.e-3_f * rho;
8  // the scaling law parameters (in CGS units)
9  constexpr Float Q_0 = 9.e7_f;
10  constexpr Float B = 0.5_f;
11  constexpr Float a = -0.36_f;
12  constexpr Float b = 1.36_f;
13 
14  const Float Q_cgs = Q_0 * pow(D_cgs / 2._f, a) + B * rho_cgs * pow(D_cgs / 2._f, b);
15  return 1.e-4_f * Q_cgs;
16 }
17 
18 Float getImpactEnergy(const Float R, const Float r, const Float v) {
19  return 0.5_f * sphereVolume(r) * sqr(v) / sphereVolume(R);
20 }
21 
22 Float getEffectiveImpactArea(const Float R, const Float r, const Float phi) {
23  SPH_ASSERT(phi >= 0._f && phi <= PI / 2._f);
24  const Float d = (r + R) * sin(phi);
25  if (d < R - r) {
26  return 1._f;
27  } else {
28  const Float area = sqr(r) * acos((sqr(d) + sqr(r) - sqr(R)) / (2 * d * r)) +
29  sqr(R) * acos((sqr(d) + sqr(R) - sqr(r)) / (2 * d * R)) -
30  0.5_f * sqrt((R + r - d) * (d + r - R) * (d - r + R) * (d + r + R));
31  return area / (PI * sqr(r));
32  }
33 }
34 
35 Float getImpactorRadius(const Float R_pb, const Float v_imp, const Float QOverQ_D, const Float rho) {
36  // for 'regular' impact energy, simply compute the impactor radius by inverting Q=1/2 m_imp v^2/M_pb
37  const Float Q_D = evalBenzAsphaugScalingLaw(2._f * R_pb, rho);
38  const Float Q = QOverQ_D * Q_D;
39  return root<3>(2._f * Q / sqr(v_imp)) * R_pb;
40 }
41 
43  const Float v_imp,
44  const Float phi,
45  const Float Q_effOverQ_D,
46  const Float rho) {
47  // The effective impact energy depends on impactor radius, which is what we want to compute; needs
48  // to be solved by iterative algorithm. First, get an estimate of the radius by using the regular
49  // impact energy
50  Float r = getImpactorRadius(R_pb, v_imp, Q_effOverQ_D, rho);
51  if (almostEqual(getEffectiveImpactArea(R_pb, r, phi), 1._f, 1.e-4_f)) {
52  // (almost) whole impactor hits the target, no need to account for effective energy
53  return r;
54  }
55  // Effective energy LOWER than the regular energy, so we only need to increase the impactor, no
56  // need to check for smaller values.
57  Float lastR = LARGE;
58  const Float eps = 1.e-4_f * r;
59  while (abs(r - lastR) > eps) {
60  lastR = r;
61  const Float a = getEffectiveImpactArea(R_pb, r, phi);
62  // effective->regular = divide by a
63  r = getImpactorRadius(R_pb, v_imp, Q_effOverQ_D / a, rho);
64  }
65  return r;
66 }
67 
INLINE bool almostEqual(const AffineMatrix &m1, const AffineMatrix &m2, const Float eps=EPS)
Definition: AffineMatrix.h:278
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
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 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
NAMESPACE_SPH_BEGIN Float evalBenzAsphaugScalingLaw(const Float D, const Float rho)
Returns the critical energy Q_D^* as a function of body diameter.
Definition: Functions.cpp:5
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 sin(const T f)
Definition: MathUtils.h:296
INLINE T sqrt(const T f)
Return a squared root of a value.
Definition: MathUtils.h:78
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 Float root< 3 >(const Float f)
Definition: MathUtils.h:105
INLINE T acos(const T f)
Definition: MathUtils.h:306
INLINE auto abs(const T &f)
Definition: MathUtils.h:276
constexpr Float PI
Mathematical constants.
Definition: MathUtils.h:361
constexpr Float LARGE
Definition: MathUtils.h:34
#define NAMESPACE_SPH_END
Definition: Object.h:12