Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ComputeCellAABB.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
21
22namespace {
23
24 template<class Tvec, class TgridVec>
25 struct KernelComputeCellAABB {
26 using Tscal = shambase::VecComponent<Tvec>;
27
28 inline static void kernel(
29 const shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<TgridVec>>
30 &spans_block_min,
31 const shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<TgridVec>>
32 &spans_block_max,
33 shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tscal>>
34 &spans_block_cell_sizes,
35 shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tvec>>
36 &spans_cell0block_aabb_lower,
37 const shambase::DistributedData<u32> &sizes,
38 u32 block_nside,
39 Tscal grid_coord_to_pos_fact) {
40
41 const shambase::DistributedData<u32> &block_counts = sizes;
42
43 Tscal one_over_Nside = 1. / block_nside;
44
45 Tscal dxfact = grid_coord_to_pos_fact;
46
48 shamsys::instance::get_compute_scheduler_ptr(),
49 sham::DDMultiRef{spans_block_min, spans_block_max},
50 sham::DDMultiRef{spans_block_cell_sizes, spans_cell0block_aabb_lower},
51 block_counts,
52 [one_over_Nside, dxfact](
53 u32 i,
54 const TgridVec *__restrict acc_block_min,
55 const TgridVec *__restrict acc_block_max,
56 Tscal *__restrict bsize,
57 Tvec *__restrict aabb_lower) {
58 TgridVec lower = acc_block_min[i];
59 TgridVec upper = acc_block_max[i];
60
61 Tvec lower_flt = lower.template convert<Tscal>() * dxfact;
62
63 // size from the int coords difference, so that it does not depend on the block
64 // position
65 Tvec block_cell_size
66 = (upper - lower).template convert<Tscal>() * (dxfact * one_over_Nside);
67
68 Tscal res = block_cell_size.x();
69
70 bsize[i] = res;
71 aabb_lower[i] = lower_flt;
72 });
73 }
74 };
75
76} // namespace
77
79
80 template<class Tvec, class TgridVec>
82 auto edges = get_edges();
83
84 edges.spans_block_min.check_sizes(edges.sizes.indexes);
85 edges.spans_block_max.check_sizes(edges.sizes.indexes);
86
87 edges.spans_block_cell_sizes.ensure_sizes(edges.sizes.indexes);
88 edges.spans_cell0block_aabb_lower.ensure_sizes(edges.sizes.indexes);
89
90 KernelComputeCellAABB<Tvec, TgridVec>::kernel(
91 edges.spans_block_min.get_spans(),
92 edges.spans_block_max.get_spans(),
93 edges.spans_block_cell_sizes.get_spans(),
94 edges.spans_cell0block_aabb_lower.get_spans(),
95 edges.sizes.indexes,
96 block_nside,
97 grid_coord_to_pos_fact);
98 }
99
100 template<class Tvec, class TgridVec>
102
103 auto block_count = get_ro_edge_base(0).get_tex_symbol();
104 auto block_min = get_ro_edge_base(1).get_tex_symbol();
105 auto block_max = get_ro_edge_base(2).get_tex_symbol();
106 auto block_cell_sizes = get_rw_edge_base(0).get_tex_symbol();
107 auto cell0block_aabb_lower = get_rw_edge_base(1).get_tex_symbol();
108
109 std::string tex = R"tex(
110 Compute cell AABBs
111
112 \begin{align}
113 {block_cell_sizes}_i &= \mathbf{e}_x \cdot ({block_max}_i - {block_min}_i) (\chi / block_{\rm nside}) \\
114 {cell0block_aabb_lower}_i &= ({block_min}_i) (\chi / block_{\rm nside}) \\
115 i &\in [0,{block_count})\\
116 \chi &= {grid_coord_to_pos_fact}\\
117 block_{\rm nside} &= {block_nside}
118 \end{align}
119 )tex";
120
121 shambase::replace_all(tex, "{block_count}", block_count);
122 shambase::replace_all(tex, "{block_min}", block_min);
123 shambase::replace_all(tex, "{block_max}", block_max);
124 shambase::replace_all(tex, "{block_cell_sizes}", block_cell_sizes);
125 shambase::replace_all(tex, "{cell0block_aabb_lower}", cell0block_aabb_lower);
126 shambase::replace_all(tex, "{block_nside}", sham::format("{}", block_nside));
128 tex, "{grid_coord_to_pos_fact}", sham::format("{}", grid_coord_to_pos_fact));
129
130 return tex;
131 }
132
133} // namespace shammodels::basegodunov::modules
134
constexpr const char * sizes
Temporary sizes for h-iteration.
Header file describing a Node Instance.
std::uint32_t u32
32 bit unsigned integer
virtual std::string _impl_get_tex() const
get the tex of the node
IEdge & get_rw_edge_base(int slot)
Get a reference to a read write edge and cast it to the type IEdge.
Definition INode.hpp:147
const IEdge & get_ro_edge_base(int slot)
Get a reference to a read only edge.
Definition INode.hpp:138
void distributed_data_kernel_call(sham::DeviceScheduler_ptr dev_sched, RefIn in, RefOut in_out, const shambase::DistributedData< index_t > &thread_counts, Functor &&func)
A variant of sham::kernel_call for distributed data.
void replace_all(std::string &inout, std::string_view what, std::string_view with)
replace all occurence of a search string with another
Definition string.hpp:106
namespace for the basegodunov model modules