Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
NodeSpMVPoisson3D.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
18
19#include "shambase/memory.hpp"
26
28
29 template<class Tvec, class TgridVec>
31 auto edges = get_edges();
32
33 edges.spans_block_cell_sizes.check_sizes(edges.sizes.indexes);
34 edges.spans_in.check_sizes(edges.sizes.indexes);
35 edges.spans_out.ensure_sizes(edges.sizes.indexes);
36
37 auto &q = shamsys::instance::get_compute_scheduler().get_queue();
38
39 edges.cell_neigh_graph.graph.for_each(
40 [&](u64 id, const OrientedAMRGraph<Tvec, TgridVec> &oriented_cell_graph) {
41 auto &cell_sizes_span = edges.spans_block_cell_sizes.get_spans().get(id);
42 auto &in_span = edges.spans_in.get_spans().get(id);
43 auto &out_span = edges.spans_out.get_spans().get(id);
44
45 auto get_graph = [&](Direction dir) -> const AMRGraph & {
46 return shambase::get_check_ref(oriented_cell_graph.graph_links[dir]);
47 };
48
49 const AMRGraph &graph_neigh_xp = get_graph(Direction::xp);
50 const AMRGraph &graph_neigh_xm = get_graph(Direction::xm);
51 const AMRGraph &graph_neigh_yp = get_graph(Direction::yp);
52 const AMRGraph &graph_neigh_ym = get_graph(Direction::ym);
53 const AMRGraph &graph_neigh_zp = get_graph(Direction::zp);
54 const AMRGraph &graph_neigh_zm = get_graph(Direction::zm);
55
56 u32 cell_count = edges.sizes.indexes.get(id) * block_size;
57
59 q,
61 cell_sizes_span,
62 in_span,
63 graph_neigh_xp,
64 graph_neigh_xm,
65 graph_neigh_yp,
66 graph_neigh_ym,
67 graph_neigh_zp,
68 graph_neigh_zm},
69 sham::MultiRef{out_span},
70 cell_count,
71 [block_size = block_size](
72 u32 cell_global_id,
73 const Tscal *__restrict cell_sizes,
74 const Tscal *__restrict in,
75 const AMRGraph::ro_access graph_iter_xp,
76 const AMRGraph::ro_access graph_iter_xm,
77 const AMRGraph::ro_access graph_iter_yp,
78 const AMRGraph::ro_access graph_iter_ym,
79 const AMRGraph::ro_access graph_iter_zp,
80 const AMRGraph::ro_access graph_iter_zm,
81 Tscal *__restrict out) {
82 out[cell_global_id] = laplacian_7pt<Tscal, Tvec>(
83 cell_sizes,
84 block_size,
85 cell_global_id,
86 graph_iter_xp,
87 graph_iter_xm,
88 graph_iter_yp,
89 graph_iter_ym,
90 graph_iter_zp,
91 graph_iter_zm,
92 [=](u32 id) {
93 return sycl::isnan(in[id]) ? Tscal{0} : in[id];
94 });
95 });
96 });
97 }
98
99 template<class Tvec, class TgridVec>
101 std::string tex = R"tex(
102 Poisson sparse matrix-vector product (7-point finite volume stencil)
103 \begin{equation}
104 {spans_out}_i = - \sum_{f \in \partial i} S_f \frac{{spans_in}_{j(f)} - {spans_in}_i}{d_{ij}}
105 \end{equation}
106 )tex";
107
108 replace_edges_tex_symbols(tex);
109
110 return tex;
111 }
112
113} // namespace shammodels::basegodunov::modules
114
7-point stencil for the discrete Laplacian operator
Header file describing a Node Instance.
Sparse matrix-vector product , being the 3D Poisson matrix.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Compute out <- A in, A being the matrix of the 7-point finite volume Laplacian of laplacian_7pt ( ,...
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...
Definition memory.hpp:112
namespace for the basegodunov model modules
T laplacian_7pt(const shambase::VecComponent< Tvec > *cell_sizes, const u32 block_size, const u32 cell_global_id, const AMRGraphLinkiterator &graph_iter_xp, const AMRGraphLinkiterator &graph_iter_xm, const AMRGraphLinkiterator &graph_iter_yp, const AMRGraphLinkiterator &graph_iter_ym, const AMRGraphLinkiterator &graph_iter_zp, const AMRGraphLinkiterator &graph_iter_zm, ACCField &&field_access)
Get the discretized (finite volume) Laplacian.
A class that references multiple buffers or similar objects.
Definition MultiRef.hpp:33