Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
multipole_acceptance_crit.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
18#include "shammath/AABB.hpp"
19
20namespace shamtree::details {
21
22 template<class Tvec, class Tscal>
23 inline static bool mac_std_opti(
24 shammath::AABB<Tvec> a, shammath::AABB<Tvec> b, Tscal theta_crit) {
25 Tvec s_a = (a.upper - a.lower) / 2;
26 Tvec s_b = (b.upper - b.lower) / 2;
27 Tvec r_a = (a.upper + a.lower) / 2;
28 Tvec r_b = (b.upper + b.lower) / 2;
29 Tvec delta_ab = r_a - r_b;
30
31 Tscal delta_ab_sq = sham::dot(delta_ab, delta_ab);
32
33 if (delta_ab_sq == 0) {
34 return false;
35 }
36
37 Tscal s_a_max = sham::max_component(s_a);
38 Tscal s_b_max = sham::max_component(s_b);
39
40 Tscal sum_s = s_a_max + s_b_max;
41
42 Tscal theta_sq = sum_s * sum_s / delta_ab_sq;
43
44 return theta_sq < theta_crit * theta_crit;
45 }
46
47 template<class Tvec, class Tscal>
48 inline static bool mac_std(shammath::AABB<Tvec> a, shammath::AABB<Tvec> b, Tscal theta_crit) {
49 Tvec s_a = (a.upper - a.lower) / 2;
50 Tvec s_b = (b.upper - b.lower) / 2;
51 Tvec r_a = (a.upper + a.lower) / 2;
52 Tvec r_b = (b.upper + b.lower) / 2;
53 Tvec delta_ab = r_a - r_b;
54
55 Tscal delta_ab_sq = sham::dot(delta_ab, delta_ab);
56
57 if (delta_ab_sq == 0) {
58 return false;
59 }
60
61 Tscal s_a_sq = sham::dot(s_a, s_a);
62 Tscal s_b_sq = sham::dot(s_b, s_b);
63
64 Tscal theta_sq = (sycl::sqrt(s_a_sq) + sycl::sqrt(s_b_sq)) / sycl::sqrt(delta_ab_sq);
65
66 return theta_sq < theta_crit;
67 }
68
69 template<class Tvec, class Tscal>
70 inline static bool mac_quadratic(
71 shammath::AABB<Tvec> a, shammath::AABB<Tvec> b, Tscal theta_crit) {
72 Tvec s_a = (a.upper - a.lower);
73 Tvec s_b = (b.upper - b.lower);
74 Tvec r_a = (a.upper + a.lower) / 2;
75 Tvec r_b = (b.upper + b.lower) / 2;
76 Tvec delta_ab = r_a - r_b;
77
78 Tscal delta_ab_sq = sham::dot(delta_ab, delta_ab);
79
80 if (delta_ab_sq == 0) {
81 return false;
82 }
83
84 Tscal s_a_sq = sham::dot(s_a, s_a);
85 Tscal s_b_sq = sham::dot(s_b, s_b);
86
87 Tscal theta_sq = (s_a_sq + s_b_sq) / delta_ab_sq;
88
89 return theta_sq < theta_crit * theta_crit;
90 }
91
92 template<class Tvec, class Tscal>
93 inline static bool mac(shammath::AABB<Tvec> a, shammath::AABB<Tvec> b, Tscal theta_crit) {
94 return mac_std_opti(a, b, theta_crit);
95 }
96
97} // namespace shamtree::details
Axis-Aligned bounding box.
Definition AABB.hpp:99
T lower
Lower bound of the AABB.
Definition AABB.hpp:104
T upper
Upper bound of the AABB.
Definition AABB.hpp:105