Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
NodeJacobiPreconditioner.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"
27
29
30 template<class Tvec, class TgridVec>
32 StackEntry stack_loc{};
33 auto edges = get_edges();
34
35 edges.spans_block_cell_sizes.check_sizes(edges.sizes.indexes);
36 edges.spans_x.check_sizes(edges.sizes.indexes);
37 edges.spans_y.ensure_sizes(edges.sizes.indexes);
38
39 auto &q = shamsys::instance::get_compute_scheduler().get_queue();
40
41 edges.cell_neigh_graph.graph.for_each(
42 [&](u64 id, const OrientedAMRGraph<Tvec, TgridVec> &oriented_cell_graph) {
43 auto &cell_sizes_span = edges.spans_block_cell_sizes.get_spans().get(id);
44 auto &x_span = edges.spans_x.get_spans().get(id);
45 auto &y_span = edges.spans_y.get_spans().get(id);
46
47 auto get_graph = [&](Direction dir) -> const AMRGraph & {
48 return shambase::get_check_ref(oriented_cell_graph.graph_links[dir]);
49 };
50
51 const AMRGraph &graph_neigh_xp = get_graph(Direction::xp);
52 const AMRGraph &graph_neigh_xm = get_graph(Direction::xm);
53 const AMRGraph &graph_neigh_yp = get_graph(Direction::yp);
54 const AMRGraph &graph_neigh_ym = get_graph(Direction::ym);
55 const AMRGraph &graph_neigh_zp = get_graph(Direction::zp);
56 const AMRGraph &graph_neigh_zm = get_graph(Direction::zm);
57
58 u32 cell_count = edges.sizes.indexes.get(id) * block_size;
59
61 q,
63 cell_sizes_span,
64 x_span,
65 graph_neigh_xp,
66 graph_neigh_xm,
67 graph_neigh_yp,
68 graph_neigh_ym,
69 graph_neigh_zp,
70 graph_neigh_zm},
71 sham::MultiRef{y_span},
72 cell_count,
73 [block_size = block_size](
74 u32 cell_global_id,
75 const Tscal *__restrict cell_sizes,
76 const Tscal *__restrict x,
77 const AMRGraph::ro_access graph_iter_xp,
78 const AMRGraph::ro_access graph_iter_xm,
79 const AMRGraph::ro_access graph_iter_yp,
80 const AMRGraph::ro_access graph_iter_ym,
81 const AMRGraph::ro_access graph_iter_zp,
82 const AMRGraph::ro_access graph_iter_zm,
83 Tscal *__restrict y) {
84 Tscal weight = jacobi_weight_7pt<Tscal, Tvec>(
85 cell_sizes,
86 block_size,
87 cell_global_id,
88 graph_iter_xp,
89 graph_iter_xm,
90 graph_iter_yp,
91 graph_iter_ym,
92 graph_iter_zp,
93 graph_iter_zm);
94 y[cell_global_id] = x[cell_global_id] / weight;
95 });
96 });
97 }
98
99 template<class Tvec, class TgridVec>
101 std::string tex = R"tex(
102 Jacobi preconditioner
103 \begin{equation}
104 {spans_y}_i = {spans_x}_i / A_{ii}
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.
Diagonal preconditioner of the PCG Poisson solver.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Compute y <- M^-1 x, being the diagonal of the matrix of NodeSpMVPoisson3D as given by jacobi_weight...
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 jacobi_weight_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)
Get the weight of the Jacobi preconditioner of the 7-point Laplacian.
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.
Definition MultiRef.hpp:33