21 using Tscal = shambase::VecComponent<Tvec>;
31 const Tvec *__restrict cell0block_aabb_lower,
32 const Tscal *__restrict block_cell_sizes) {
33 const u32 cell_global_id = (
u32)
id;
35 const u32 block_id = cell_global_id / AMRBlock::block_size;
36 const u32 cell_loc_id = cell_global_id % AMRBlock::block_size;
39 const Tvec cblock_min = cell0block_aabb_lower[block_id];
40 const Tscal delta_cell = block_cell_sizes[block_id];
42 std::array<u32, 3> lcoord_arr = AMRBlock::get_coord(cell_loc_id);
43 Tvec offset = Tvec{lcoord_arr[0], lcoord_arr[1], lcoord_arr[2]} * delta_cell;
45 Tvec aabb_min = cblock_min + offset;
46 Tvec aabb_max = aabb_min + delta_cell;
48 return {aabb_min, aabb_max};
51 inline static Tscal get_face_surface(
54 const Tvec *__restrict cell0block_aabb_lower,
55 const Tscal *__restrict block_cell_sizes,
58 = get_cell_aabb(id_a, cell0block_aabb_lower, block_cell_sizes);
60 = get_cell_aabb(id_b, cell0block_aabb_lower, block_cell_sizes);
64 Tvec delta_face = face_aabb.
delt();
69 Tscal smd = dxfact / 2;
71 delta_face.x() = (delta_face.x() < smd) ? 1 : delta_face.x();
72 delta_face.y() = (delta_face.y() < smd) ? 1 : delta_face.y();
73 delta_face.z() = (delta_face.z() < smd) ? 1 : delta_face.z();
75 return delta_face.x() * delta_face.y() * delta_face.z();
78 inline void operator()(
80 const Tscal *__restrict flux_rho_face_xp,
81 const Tscal *__restrict flux_rho_face_xm,
82 const Tscal *__restrict flux_rho_face_yp,
83 const Tscal *__restrict flux_rho_face_ym,
84 const Tscal *__restrict flux_rho_face_zp,
85 const Tscal *__restrict flux_rho_face_zm,
86 const Tvec *__restrict flux_rhov_face_xp,
87 const Tvec *__restrict flux_rhov_face_xm,
88 const Tvec *__restrict flux_rhov_face_yp,
89 const Tvec *__restrict flux_rhov_face_ym,
90 const Tvec *__restrict flux_rhov_face_zp,
91 const Tvec *__restrict flux_rhov_face_zm,
92 const Tscal *__restrict block_cell_sizes,
93 const Tvec *__restrict cell0block_aabb_lower,
100 Tscal *__restrict dt_rho,
101 Tvec *__restrict dt_rhov)
const {
104 const u32 id_a = tid / ndust;
106 const u32 ndust_off_loc = tid % ndust;
108 const u32 block_id = id_a / AMRBlock::block_size;
109 const u32 cell_loc_id = id_a % AMRBlock::block_size;
111 Tscal V_i = block_cell_sizes[block_id];
112 V_i = V_i * V_i * V_i;
115 Tvec dtrhov = {0, 0, 0};
117 auto add_flux = [&](
const auto &graph_iter,
const Tscal *flux_rho,
const Tvec *flux_rhov) {
118 graph_iter.for_each_object_link_id(id_a, [&](
u32 id_b,
u32 link_id) {
120 id_a, id_b, cell0block_aabb_lower, block_cell_sizes, dxfact);
121 dtrho -= flux_rho[link_id * ndust + ndust_off_loc] * S_ij;
122 dtrhov -= flux_rhov[link_id * ndust + ndust_off_loc] * S_ij;
126 add_flux(graph_iter_xp, flux_rho_face_xp, flux_rhov_face_xp);
127 add_flux(graph_iter_xm, flux_rho_face_xm, flux_rhov_face_xm);
128 add_flux(graph_iter_yp, flux_rho_face_yp, flux_rhov_face_yp);
129 add_flux(graph_iter_ym, flux_rho_face_ym, flux_rhov_face_ym);
130 add_flux(graph_iter_zp, flux_rho_face_zp, flux_rhov_face_zp);
131 add_flux(graph_iter_zm, flux_rho_face_zm, flux_rhov_face_zm);
136 dt_rho[id_a * ndust + ndust_off_loc] = dtrho;
137 dt_rhov[id_a * ndust + ndust_off_loc] = dtrhov;
143 auto edges = get_edges();
145 edges.spans_dtrho.ensure_sizes(edges.block_counts.indexes);
146 edges.spans_dtrhov.ensure_sizes(edges.block_counts.indexes);
148 auto get_graph_neigh = [&](Direction dir,
u64 patch_id) ->
const AMRGraph & {
151 const CellGraphEdge &cell_neigh_graph = edges.cell_neigh_graph;
154 const std::unique_ptr<AMRGraph> &graph_link = oriented_cell_graph.graph_links[dir];
159 auto &q = shamsys::instance::get_compute_scheduler().
get_queue();
161 edges.block_counts.indexes.for_each([&](
u64 patch_id,
const u64 &block_count) {
162 const AMRGraph &graph_neigh_xp = get_graph_neigh(Direction::xp, patch_id);
163 const AMRGraph &graph_neigh_xm = get_graph_neigh(Direction::xm, patch_id);
164 const AMRGraph &graph_neigh_yp = get_graph_neigh(Direction::yp, patch_id);
165 const AMRGraph &graph_neigh_ym = get_graph_neigh(Direction::ym, patch_id);
166 const AMRGraph &graph_neigh_zp = get_graph_neigh(Direction::zp, patch_id);
167 const AMRGraph &graph_neigh_zm = get_graph_neigh(Direction::zm, patch_id);
169 auto get_face_buf = [&](
auto &neigh_link_field) ->
const auto & {
170 return neigh_link_field.link_fields.get(patch_id).link_graph_field;
173 const auto &buf_flux_rho_face_xp = get_face_buf(edges.flux_rho_face_xp);
174 const auto &buf_flux_rho_face_xm = get_face_buf(edges.flux_rho_face_xm);
175 const auto &buf_flux_rho_face_yp = get_face_buf(edges.flux_rho_face_yp);
176 const auto &buf_flux_rho_face_ym = get_face_buf(edges.flux_rho_face_ym);
177 const auto &buf_flux_rho_face_zp = get_face_buf(edges.flux_rho_face_zp);
178 const auto &buf_flux_rho_face_zm = get_face_buf(edges.flux_rho_face_zm);
179 const auto &buf_flux_rhov_face_xp = get_face_buf(edges.flux_rhov_face_xp);
180 const auto &buf_flux_rhov_face_xm = get_face_buf(edges.flux_rhov_face_xm);
181 const auto &buf_flux_rhov_face_yp = get_face_buf(edges.flux_rhov_face_yp);
182 const auto &buf_flux_rhov_face_ym = get_face_buf(edges.flux_rhov_face_ym);
183 const auto &buf_flux_rhov_face_zp = get_face_buf(edges.flux_rhov_face_zp);
184 const auto &buf_flux_rhov_face_zm = get_face_buf(edges.flux_rhov_face_zm);
186 auto &block_cell_sizes = edges.spans_block_cell_sizes.get_spans().get(patch_id);
187 auto &cell0block_aabb_lower = edges.spans_cell0block_aabb_lower.get_spans().get(patch_id);
189 auto &dt_rho_patch = edges.spans_dtrho.get_spans().get(patch_id);
190 auto &dt_rhov_patch = edges.spans_dtrhov.get_spans().get(patch_id);
192 u32 cell_count = block_count * AMRBlock::block_size * ndust;
196 sham::MultiRef{buf_flux_rho_face_xp, buf_flux_rho_face_xm, buf_flux_rho_face_yp,
197 buf_flux_rho_face_ym, buf_flux_rho_face_zp, buf_flux_rho_face_zm,
198 buf_flux_rhov_face_xp, buf_flux_rhov_face_xm, buf_flux_rhov_face_yp,
199 buf_flux_rhov_face_ym, buf_flux_rhov_face_zp, buf_flux_rhov_face_zm,
200 block_cell_sizes, cell0block_aabb_lower, graph_neigh_xp,
201 graph_neigh_xm, graph_neigh_yp, graph_neigh_ym,
202 graph_neigh_zp, graph_neigh_zm},