Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
BuildTrees.cpp
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
20#include "shammath/AABB.hpp"
22#include <cmath>
23
25
26 template<class Tvec, template<class> class SPHKernel>
28
29 // interface_control
30 using GhostHandle = sph::BasicSPHGhostHandler<Tvec>;
31 using GhostHandleCache = typename GhostHandle::CacheMap;
32
33 StackEntry stack_loc{};
34
35 auto &merged_xyzh = storage.merged_xyzh.get();
36 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
37
39 = merged_xyzh.template map<RTree>([&](u64 id, shamrock::patch::PatchDataLayer &merged) {
40 PatchDataField<Tvec> &pos = merged.template get_field<Tvec>(0);
41 Tvec bmax = pos.compute_max();
42 Tvec bmin = pos.compute_min();
43
44 shammath::AABB<Tvec> aabb(bmin, bmax);
45
46 Tscal infty = std::numeric_limits<Tscal>::infinity();
47
48 // ensure that no particle is on the boundary of the AABB
49 // TODO: make this a aabb function at some point
50 aabb.lower[0] = std::nextafter(aabb.lower[0], -infty);
51 aabb.lower[1] = std::nextafter(aabb.lower[1], -infty);
52 aabb.lower[2] = std::nextafter(aabb.lower[2], -infty);
53 aabb.upper[0] = std::nextafter(aabb.upper[0], infty);
54 aabb.upper[1] = std::nextafter(aabb.upper[1], infty);
55 aabb.upper[2] = std::nextafter(aabb.upper[2], infty);
56
57 auto bvh = RTree::make_empty(dev_sched);
58 bvh.rebuild_from_positions(
59 pos.get_buf(), pos.get_obj_cnt(), aabb, solver_config.tree_reduction_level);
60
61 return bvh;
62 });
63
64 storage.merged_pos_trees.set(std::move(trees));
65 };
66
67} // namespace shammodels::sph::modules
68
69using namespace shammath;
70
74
std::uint64_t u64
64 bit unsigned integer
Represents a collection of objects distributed across patches identified by a u64 id.
Module for constructing spatial tree structures for SPH neighbor searches.
void build_merged_pos_trees()
Builds compressed leaf BVH trees for merged particle positions including ghosts.
PatchDataLayer container class, the layout is described in patchdata_layout.
namespace for math utility
Definition AABB.hpp:26
namespace for the sph model modules
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