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,
83 TgridVec block_min = ptr_block_min[id_a];
84 TgridVec block_max = ptr_block_max[id_a];
86 TgridVec delta_cell = (block_max - block_min) / Block::side_size;
87 for (
u32 ix = 0; ix < Block::side_size; ix++) {
88 for (
u32 iy = 0; iy < Block::side_size; iy++) {
89 for (
u32 iz = 0; iz < Block::side_size; iz++) {
90 u32 i = Block::get_index({ix, iy, iz});
91 TgridVec cmin = block_min + delta_cell * TgridVec{ix, iy, iz};
92 TgridVec cmax = cmin + delta_cell;
93 cell_min[id_a * Block::block_size + i]
94 = cmin.template convert<Tscal>() * dxfact;
95 cell_max[id_a * Block::block_size + i]
96 = cmax.template convert<Tscal>() * dxfact;
107 auto &buf_field_to_render = field_getter(cur_p, pdat);
109 shammath::AABB<Tvec> tree_box(min_pos, max_pos);
110 u32 reduction_level = 0;
112 RTree tree = RTree::make_empty(dev_sched);
113 tree.rebuild_from_position_range(pos_min_cell, pos_max_cell, tree_box, reduction_level);
115 auto leaf_iterator = tree.get_object_iterator();
120 positions, pos_min_cell, pos_max_cell, leaf_iterator, buf_field_to_render},
124 const Tvec *positions,
128 const Tfield *buf_field_to_render,
130 Tvec pos_a = positions[id_a];
132 Tfield accumulator = {};
134 cell_finder.rtree_for(
135 [&](
u32 node_id, shammath::AABB<Tvec> node_aabb) ->
bool {
139 shammath::AABB<Tvec> cell_b = {min_pos[id_b], max_pos[id_b]};
142 Tfield val_cell = buf_field_to_render[id_b];
143 accumulator += val_cell;
147 ret[id_a] += accumulator;
151 shamalgs::collective::reduce_buffer_in_place_sum(ret, MPI_COMM_WORLD);
157 template<
class Tvec,
class Tgr
idVec,
class Tfield>
158 sham::DeviceBuffer<Tfield> GridRender<Tvec, TgridVec, Tfield>::compute_slice(
159 std::string field_name,
const sham::DeviceBuffer<Tvec> &positions) {
160 auto field_source_getter
161 = [&](
const shamrock::patch::Patch cur_p,
162 shamrock::patch::PatchDataLayer &pdat) ->
const sham::DeviceBuffer<Tfield> & {
163 return pdat.get_field<Tfield>(pdat.pdl().get_field_idx<Tfield>(field_name)).get_buf();
165 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).