Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
FindGhostLayerIndices.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
16#include "shambase/assert.hpp"
20#include "shammath/AABB.hpp"
27#include <stdexcept>
28
29namespace {
30
31 template<class TgridVec>
32 sham::DeviceBuffer<u32> get_ids_in_ghost(
33 const sham::DeviceScheduler_ptr &dev_sched,
35 const sham::DeviceBuffer<TgridVec> &block_min,
36 const sham::DeviceBuffer<TgridVec> &block_max,
37 const shammath::AABB<TgridVec> &test_volume,
38 u32 obj_cnt) {
39
40 if (obj_cnt > 0) {
41 // buffer of booleans to store result of the condition
42 sham::DeviceBuffer<u32> mask(obj_cnt, dev_sched);
43
45 q,
46 sham::MultiRef{block_min, block_max},
47 sham::MultiRef{mask},
48 obj_cnt,
49 [test_volume](
50 u32 id,
51 const TgridVec *__restrict block_min,
52 const TgridVec *__restrict block_max,
53 u32 *__restrict is_in_ghost) {
54 is_in_ghost[id] = shammath::AABB<TgridVec>(block_min[id], block_max[id])
55 .get_intersect(test_volume)
56 .is_not_empty();
57 });
58
59 return shamalgs::stream_compact(dev_sched, mask, obj_cnt);
60 } else {
61 return sham::DeviceBuffer<u32>(0, dev_sched);
62 }
63 }
64} // namespace
65
66template<class TgridVec>
68 auto edges = get_edges();
69
70 // inputs
71 auto &sim_box = edges.sim_box.value;
72 auto &patch_data_layers = edges.patch_data_layers;
73 auto &ghost_layers_candidates = edges.ghost_layers_candidates;
74 auto &patch_boxes = edges.patch_boxes;
75
76 // outputs
77 auto &idx_in_ghost = edges.idx_in_ghost;
78
79 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
80 sham::DeviceQueue &q = shambase::get_check_ref(dev_sched).get_queue();
81
82 auto paving_function = get_paving(mode, sim_box);
83
84 auto &patch_data_layers_ref = patch_data_layers.get_const_refs();
85
86 // map candidates to indexes in ghosts
87 idx_in_ghost.buffers = ghost_layers_candidates.values.template map<sham::DeviceBuffer<u32>>(
88 [&](u64 sender,
89 u64 receiver,
91 shamrock::patch::PatchDataLayer &sender_patch = patch_data_layers_ref.get(sender).get();
92
93 PatchDataField<TgridVec> &block_min = sender_patch.get_field<TgridVec>(0);
94 PatchDataField<TgridVec> &block_max = sender_patch.get_field<TgridVec>(1);
95
96 auto brecv = patch_boxes.values.get(receiver);
97
98 auto test_volume
99 = paving_function.f_aabb_inv(brecv, infos.xoff, infos.yoff, infos.zoff);
100
101 return get_ids_in_ghost(
102 dev_sched,
103 q,
104 block_min.get_buf(),
105 block_max.get_buf(),
106 test_volume,
107 sender_patch.get_obj_cnt());
108 });
109}
110
111template<class TgridVec>
116
Header file describing a Node Instance.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Shamrock assertion utility.
A buffer allocated in USM (Unified Shared Memory)
A SYCL queue associated with a device and a context.
virtual std::string _impl_get_tex() const
get the tex of the node
PatchDataLayer container class, the layout is described in patchdata_layout.
This header file contains utility functions related to exception handling in the code.
void kernel_call(sham::DeviceQueue &q, RefIn in, RefOut in_out, u32 n, Functor &&func, SourceLocation &&callsite=SourceLocation{})
Submit a kernel to a SYCL queue.
std::tuple< std::optional< sycl::buffer< u32 > >, u32 > stream_compact(sycl::queue &q, sycl::buffer< u32 > &buf_flags, u32 len)
Stream compaction algorithm.
Definition numeric.cpp:84
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
Definition memory.hpp:110
A class that references multiple buffers or similar objects.
Axis-Aligned bounding box.
Definition AABB.hpp:99
bool is_not_empty() const noexcept
Checks if the AABB is non-empty.
Definition AABB.hpp:268
AABB get_intersect(AABB other) const noexcept
Compute the intersection of two AABB.
Definition AABB.hpp:234