29namespace shammodels::ramses::modules {
32 template<
class Tvec,
class Tgr
idVec,
class Tfield>
33 sham::DeviceBuffer<Tfield> GridRender<Tvec, TgridVec, Tfield>::compute_slice(
34 std::function<field_getter_t> field_getter,
const sham::DeviceBuffer<Tvec> &positions) {
36 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
39 sham::DeviceBuffer<Tfield> ret{positions.
get_size(), dev_sched};
40 ret.
fill(sham::VectorProperties<Tfield>::get_zero());
43 using RTree = shamtree::CompressedLeafBVH<u_morton, Tvec, 3>;
45 shamrock::patch::PatchCoordTransform<TgridVec> transf
46 = scheduler().get_sim_box().template get_patch_transform<TgridVec>();
48 scheduler().for_each_patchdata_nonempty([&](
const shamrock::patch::Patch cur_p,
49 shamrock::patch::PatchDataLayer &pdat) {
50 shammath::CoordRange<TgridVec> box = transf.to_obj_coord(cur_p);
52 PatchDataField<TgridVec> &block_min = pdat.get_field<TgridVec>(0);
53 PatchDataField<TgridVec> &block_max = pdat.get_field<TgridVec>(1);
55 auto &buf_block_min = block_min.get_buf();
56 auto &buf_block_max = block_max.get_buf();
58 using Block =
typename Config::AMRBlock;
59 u32 block_size = Block::block_size;
61 u64 num_obj = block_min.get_obj_cnt();
63 sham::DeviceBuffer<Tvec> pos_max_cell(num_obj * block_size, dev_sched);
64 sham::DeviceBuffer<Tvec> pos_min_cell(num_obj * block_size, dev_sched);
66 Tscal dxfact = solver_config.grid_coord_to_pos_fact;
70 sham::MultiRef{buf_block_min, buf_block_max},
71 sham::MultiRef{pos_min_cell, pos_max_cell},
75 const TgridVec *__restrict ptr_block_min,
76 const TgridVec *__restrict ptr_block_max,
79 Tvec block_min = ptr_block_min[id_a].template convert<Tscal>() * dxfact;
80 Tvec block_max = ptr_block_max[id_a].template convert<Tscal>() * dxfact;
82 Tvec delta_cell = (block_max - block_min) / Block::side_size;
83 for (
u32 ix = 0; ix < Block::side_size; ix++) {
84 for (
u32 iy = 0; iy < Block::side_size; iy++) {
85 for (
u32 iz = 0; iz < Block::side_size; iz++) {
86 u32 i = Block::get_index({ix, iy, iz});
87 Tvec delta_val = delta_cell * Tvec{ix, iy, iz};
88 cell_min[id_a * Block::block_size + i] = block_min + delta_val;
89 cell_max[id_a * Block::block_size + i]
90 = block_min + (delta_cell) + delta_val;
101 auto &buf_field_to_render = field_getter(cur_p, pdat);
103 shammath::AABB<Tvec> tree_box(min_pos, max_pos);
104 u32 reduction_level = 0;
106 RTree tree = RTree::make_empty(dev_sched);
107 tree.rebuild_from_position_range(pos_min_cell, pos_max_cell, tree_box, reduction_level);
109 auto leaf_iterator = tree.get_object_iterator();
114 positions, pos_min_cell, pos_max_cell, leaf_iterator, buf_field_to_render},
118 const Tvec *positions,
122 const Tfield *buf_field_to_render,
124 Tvec pos_a = positions[id_a];
126 Tfield accumulator = {};
128 cell_finder.rtree_for(
129 [&](
u32 node_id, shammath::AABB<Tvec> node_aabb) ->
bool {
133 shammath::AABB<Tvec> cell_b = {min_pos[id_b], max_pos[id_b]};
136 Tfield val_cell = buf_field_to_render[id_b];
137 accumulator += val_cell;
141 ret[id_a] += accumulator;
145 shamalgs::collective::reduce_buffer_in_place_sum(ret, MPI_COMM_WORLD);
151 template<
class Tvec,
class Tgr
idVec,
class Tfield>
152 sham::DeviceBuffer<Tfield> GridRender<Tvec, TgridVec, Tfield>::compute_slice(
153 std::string field_name,
const sham::DeviceBuffer<Tvec> &positions) {
154 auto field_source_getter
155 = [&](
const shamrock::patch::Patch cur_p,
156 shamrock::patch::PatchDataLayer &pdat) ->
const sham::DeviceBuffer<Tfield> & {
157 return pdat.get_field<Tfield>(pdat.pdl().get_field_idx<Tfield>(field_name)).get_buf();
159 return compute_slice(field_source_getter, positions);
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
void fill(T value, std::array< size_t, 2 > idx_range)
Fill a subpart of the buffer with a given value.
size_t get_size() const
Gets the number of elements in the buffer.
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.
T min(const sham::DeviceScheduler_ptr &sched, const sham::DeviceBuffer< T > &buf1, u32 start_id, u32 end_id)
Find the minimum element in a device buffer within a specified range.
T max(const sham::DeviceScheduler_ptr &sched, const sham::DeviceBuffer< T > &buf1, u32 start_id, u32 end_id)
Find the maximum element in a device buffer within a specified range.
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...
namespace for math utility
bool contains_asymmetric(T point) const noexcept
Check if point is in AABB using half-open interval [lower, upper).