31 using Direction = shammodels::basegodunov::modules::Direction;
34 template<
class Tscal,
class ACCField>
35 inline std::array<Tscal, 3> get_3d_minus_phi_grad(
36 const Tscal *cell_sizes,
38 const u32 cell_global_id,
39 const AMRGraphLinkiterator &graph_iter_xp,
40 const AMRGraphLinkiterator &graph_iter_xm,
41 const AMRGraphLinkiterator &graph_iter_yp,
42 const AMRGraphLinkiterator &graph_iter_ym,
43 const AMRGraphLinkiterator &graph_iter_zp,
44 const AMRGraphLinkiterator &graph_iter_zm,
45 ACCField &&field_access) {
47 auto cur_cell_block_id = cell_global_id / block_size;
49 auto get_gradient_dir = [&](
auto &graph_links, Direction dir) -> Tscal {
51 auto cell_center_dist = cell_sizes[cur_cell_block_id];
53 u32 cnt = graph_links.for_each_object_link_cnt(cell_global_id, [&](
u32 id_b) {
54 auto neigh_block_id = id_b / block_size;
56 int sign = 1 - 2 * (dir % 2);
57 acc += sign * (field_access(id_b) - field_access(cell_global_id));
59 if (cell_sizes[neigh_block_id] > cell_sizes[cur_cell_block_id]) {
65 if (cell_sizes[neigh_block_id] < cell_sizes[cur_cell_block_id]) {
69 return (cnt > 0) ? acc / (cell_center_dist * fac * cnt) : Tscal{0};
72 Tscal delta_xp = get_gradient_dir(graph_iter_xp, Direction::xp);
73 Tscal delta_xm = get_gradient_dir(graph_iter_xm, Direction::xm);
74 Tscal delta_yp = get_gradient_dir(graph_iter_yp, Direction::yp);
75 Tscal delta_ym = get_gradient_dir(graph_iter_ym, Direction::ym);
76 Tscal delta_zp = get_gradient_dir(graph_iter_zp, Direction::zp);
77 Tscal delta_zm = get_gradient_dir(graph_iter_zm, Direction::zm);
79 Tscal phi_gx = -0.5 * (delta_xp + delta_xm);
80 Tscal phi_gy = -0.5 * (delta_yp + delta_ym);
81 Tscal phi_gz = -0.5 * (delta_zp + delta_zm);
83 return {phi_gx, phi_gy, phi_gz};
90 template<
class Tvec,
class Tgr
idVec>
93 auto edges = get_edges();
95 edges.spans_block_cell_sizes.check_sizes(edges.sizes.indexes);
96 edges.spans_phi.check_sizes(edges.sizes.indexes);
97 edges.spans_phi_g.ensure_sizes(edges.sizes.indexes);
99 auto &q = shamsys::instance::get_compute_scheduler().get_queue();
101 edges.cell_neigh_graph.graph.for_each(
103 auto &cell_sizes_span = edges.spans_block_cell_sizes.get_spans().get(
id);
104 auto &phi_span = edges.spans_phi.get_spans().get(
id);
105 auto &phi_g_span = edges.spans_phi_g.get_spans().get(
id);
107 auto get_graph = [&](Direction dir) ->
const AMRGraph & {
111 const AMRGraph &graph_neigh_xp = get_graph(Direction::xp);
112 const AMRGraph &graph_neigh_xm = get_graph(Direction::xm);
113 const AMRGraph &graph_neigh_yp = get_graph(Direction::yp);
114 const AMRGraph &graph_neigh_ym = get_graph(Direction::ym);
115 const AMRGraph &graph_neigh_zp = get_graph(Direction::zp);
116 const AMRGraph &graph_neigh_zm = get_graph(Direction::zm);
118 u32 cell_count = edges.sizes.indexes.get(
id) * block_size;
133 [block_size = block_size](
135 const Tscal *__restrict cell_sizes,
136 const Tscal *__restrict phi,
143 Tvec *__restrict phi_g) {
144 auto g = get_3d_minus_phi_grad<Tscal>(
157 phi_g[cell_global_id] = {g[0], g[1], g[2]};
162 template<
class Tvec,
class Tgr
idVec>
164 std::string tex = R
"tex(
165 Self-gravity acceleration
167 {spans_phi_g}_i = -(\nabla {spans_phi})_i
171 replace_edges_tex_symbols(tex);
Header file describing a Node Instance.
Self-gravity acceleration on the AMR grid.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Compute the gravitational acceleration of every cell.
void _impl_evaluate_internal()
evaluate the node
virtual std::string _impl_get_tex() const
get the tex of the node
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 & 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 the basegodunov model modules
This file contains the definition for the stacktrace related functionality.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
A class that references multiple buffers or similar objects.