21 using Tscal = shambase::VecComponent<Tvec>;
28 const Tvec *__restrict cell0block_aabb_lower,
29 const Tscal *__restrict block_cell_sizes) {
30 const u32 cell_global_id = (
u32)
id;
32 const u32 block_id = cell_global_id / AMRBlock::block_size;
33 const u32 cell_loc_id = cell_global_id % AMRBlock::block_size;
36 const Tvec cblock_min = cell0block_aabb_lower[block_id];
37 const Tscal delta_cell = block_cell_sizes[block_id];
39 std::array<u32, 3> lcoord_arr = AMRBlock::get_coord(cell_loc_id);
40 Tvec offset = Tvec{lcoord_arr[0], lcoord_arr[1], lcoord_arr[2]} * delta_cell;
42 Tvec aabb_min = cblock_min + offset;
43 Tvec aabb_max = aabb_min + delta_cell;
45 return {aabb_min, aabb_max};
48 inline static Tscal get_face_surface(
51 const Tvec *__restrict cell0block_aabb_lower,
52 const Tscal *__restrict block_cell_sizes,
55 = get_cell_aabb(id_a, cell0block_aabb_lower, block_cell_sizes);
57 = get_cell_aabb(id_b, cell0block_aabb_lower, block_cell_sizes);
61 Tvec delta_face = face_aabb.
delt();
66 Tscal smd = dxfact / 2;
68 delta_face.x() = (delta_face.x() < smd) ? 1 : delta_face.x();
69 delta_face.y() = (delta_face.y() < smd) ? 1 : delta_face.y();
70 delta_face.z() = (delta_face.z() < smd) ? 1 : delta_face.z();
72 return delta_face.x() * delta_face.y() * delta_face.z();
77 inline void operator()(
79 const Tscal *__restrict flux_rho_face_xp,
80 const Tscal *__restrict flux_rho_face_xm,
81 const Tscal *__restrict flux_rho_face_yp,
82 const Tscal *__restrict flux_rho_face_ym,
83 const Tscal *__restrict flux_rho_face_zp,
84 const Tscal *__restrict flux_rho_face_zm,
85 const Tvec *__restrict flux_rhov_face_xp,
86 const Tvec *__restrict flux_rhov_face_xm,
87 const Tvec *__restrict flux_rhov_face_yp,
88 const Tvec *__restrict flux_rhov_face_ym,
89 const Tvec *__restrict flux_rhov_face_zp,
90 const Tvec *__restrict flux_rhov_face_zm,
91 const Tscal *__restrict flux_rhoe_face_xp,
92 const Tscal *__restrict flux_rhoe_face_xm,
93 const Tscal *__restrict flux_rhoe_face_yp,
94 const Tscal *__restrict flux_rhoe_face_ym,
95 const Tscal *__restrict flux_rhoe_face_zp,
96 const Tscal *__restrict flux_rhoe_face_zm,
97 const Tscal *__restrict block_cell_sizes,
98 const Tvec *__restrict cell0block_aabb_lower,
105 Tscal *__restrict dt_rho,
106 Tvec *__restrict dt_rhov,
107 Tscal *__restrict dt_rhoe)
const {
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};
118 auto add_flux = [&](
const auto &graph_iter,
119 const Tscal *flux_rho,
120 const Tvec *flux_rhov,
121 const Tscal *flux_rhoe) {
122 graph_iter.for_each_object_link_id(id_a, [&](
u32 id_b,
u32 link_id) {
124 id_a, id_b, cell0block_aabb_lower, block_cell_sizes, dxfact);
125 dtrho -= flux_rho[link_id] * S_ij;
126 dtrhov -= flux_rhov[link_id] * S_ij;
127 dtrhoe -= flux_rhoe[link_id] * S_ij;
131 add_flux(graph_iter_xp, flux_rho_face_xp, flux_rhov_face_xp, flux_rhoe_face_xp);
132 add_flux(graph_iter_xm, flux_rho_face_xm, flux_rhov_face_xm, flux_rhoe_face_xm);
133 add_flux(graph_iter_yp, flux_rho_face_yp, flux_rhov_face_yp, flux_rhoe_face_yp);
134 add_flux(graph_iter_ym, flux_rho_face_ym, flux_rhov_face_ym, flux_rhoe_face_ym);
135 add_flux(graph_iter_zp, flux_rho_face_zp, flux_rhov_face_zp, flux_rhoe_face_zp);
136 add_flux(graph_iter_zm, flux_rho_face_zm, flux_rhov_face_zm, flux_rhoe_face_zm);
142 dt_rho[id_a] = dtrho;
143 dt_rhov[id_a] = dtrhov;
144 dt_rhoe[id_a] = dtrhoe;
150 auto edges = get_edges();
152 edges.spans_dtrho.ensure_sizes(edges.block_counts.indexes);
153 edges.spans_dtrhov.ensure_sizes(edges.block_counts.indexes);
154 edges.spans_dtrhoe.ensure_sizes(edges.block_counts.indexes);
156 auto get_graph_neigh = [&](Direction dir,
u64 patch_id) ->
const AMRGraph & {
159 const CellGraphEdge &cell_neigh_graph = edges.cell_neigh_graph;
162 const std::unique_ptr<AMRGraph> &graph_link = oriented_cell_graph.graph_links[dir];
167 auto &q = shamsys::instance::get_compute_scheduler().
get_queue();
169 edges.block_counts.indexes.for_each([&](
u64 patch_id,
const u64 &block_count) {
170 const AMRGraph &graph_neigh_xp = get_graph_neigh(Direction::xp, patch_id);
171 const AMRGraph &graph_neigh_xm = get_graph_neigh(Direction::xm, patch_id);
172 const AMRGraph &graph_neigh_yp = get_graph_neigh(Direction::yp, patch_id);
173 const AMRGraph &graph_neigh_ym = get_graph_neigh(Direction::ym, patch_id);
174 const AMRGraph &graph_neigh_zp = get_graph_neigh(Direction::zp, patch_id);
175 const AMRGraph &graph_neigh_zm = get_graph_neigh(Direction::zm, patch_id);
177 auto get_face_buf = [&](
auto &neigh_link_field) ->
const auto & {
178 return neigh_link_field.link_fields.get(patch_id).link_graph_field;
181 const auto &buf_flux_rho_face_xp = get_face_buf(edges.flux_rho_face_xp);
182 const auto &buf_flux_rho_face_xm = get_face_buf(edges.flux_rho_face_xm);
183 const auto &buf_flux_rho_face_yp = get_face_buf(edges.flux_rho_face_yp);
184 const auto &buf_flux_rho_face_ym = get_face_buf(edges.flux_rho_face_ym);
185 const auto &buf_flux_rho_face_zp = get_face_buf(edges.flux_rho_face_zp);
186 const auto &buf_flux_rho_face_zm = get_face_buf(edges.flux_rho_face_zm);
187 const auto &buf_flux_rhov_face_xp = get_face_buf(edges.flux_rhov_face_xp);
188 const auto &buf_flux_rhov_face_xm = get_face_buf(edges.flux_rhov_face_xm);
189 const auto &buf_flux_rhov_face_yp = get_face_buf(edges.flux_rhov_face_yp);
190 const auto &buf_flux_rhov_face_ym = get_face_buf(edges.flux_rhov_face_ym);
191 const auto &buf_flux_rhov_face_zp = get_face_buf(edges.flux_rhov_face_zp);
192 const auto &buf_flux_rhov_face_zm = get_face_buf(edges.flux_rhov_face_zm);
193 const auto &buf_flux_rhoe_face_xp = get_face_buf(edges.flux_rhoe_face_xp);
194 const auto &buf_flux_rhoe_face_xm = get_face_buf(edges.flux_rhoe_face_xm);
195 const auto &buf_flux_rhoe_face_yp = get_face_buf(edges.flux_rhoe_face_yp);
196 const auto &buf_flux_rhoe_face_ym = get_face_buf(edges.flux_rhoe_face_ym);
197 const auto &buf_flux_rhoe_face_zp = get_face_buf(edges.flux_rhoe_face_zp);
198 const auto &buf_flux_rhoe_face_zm = get_face_buf(edges.flux_rhoe_face_zm);
200 auto &block_cell_sizes = edges.spans_block_cell_sizes.get_spans().get(patch_id);
201 auto &cell0block_aabb_lower = edges.spans_cell0block_aabb_lower.get_spans().get(patch_id);
203 auto &dt_rho_patch = edges.spans_dtrho.get_spans().get(patch_id);
204 auto &dt_rhov_patch = edges.spans_dtrhov.get_spans().get(patch_id);
205 auto &dt_rhoe_patch = edges.spans_dtrhoe.get_spans().get(patch_id);
207 u32 cell_count = block_count * AMRBlock::block_size;
211 sham::MultiRef{buf_flux_rho_face_xp, buf_flux_rho_face_xm, buf_flux_rho_face_yp,
212 buf_flux_rho_face_ym, buf_flux_rho_face_zp, buf_flux_rho_face_zm,
213 buf_flux_rhov_face_xp, buf_flux_rhov_face_xm, buf_flux_rhov_face_yp,
214 buf_flux_rhov_face_ym, buf_flux_rhov_face_zp, buf_flux_rhov_face_zm,
215 buf_flux_rhoe_face_xp, buf_flux_rhoe_face_xm, buf_flux_rhoe_face_yp,
216 buf_flux_rhoe_face_ym, buf_flux_rhoe_face_zp, buf_flux_rhoe_face_zm,
217 block_cell_sizes, cell0block_aabb_lower, graph_neigh_xp,
218 graph_neigh_xm, graph_neigh_yp, graph_neigh_ym,
219 graph_neigh_zp, graph_neigh_zm},