Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
NodeLinCombThreeVectors.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/string.hpp"
24
25namespace shamrock::solvergraph {
26
27 template<class T>
29 auto edges = get_edges();
30
31 edges.spans_x.check_sizes(edges.sizes.indexes);
32 edges.spans_y.check_sizes(edges.sizes.indexes);
33 edges.spans_z.ensure_sizes(edges.sizes.indexes);
34
35 Tscal alpha_0 = edges.alpha_0.data;
36 Tscal alpha_1 = edges.alpha_1.data;
37 Tscal alpha_2 = edges.alpha_2.data;
38
39 // as in BLAS, z is not read when alpha_0 == 0, so that it can be freshly allocated
40 bool read_z = alpha_0 != 0;
41
43 = edges.sizes.indexes.template map<u32>([&](u64 id, u32 obj_cnt) {
44 return obj_cnt * nvar;
45 });
46
48 shamsys::instance::get_compute_scheduler_ptr(),
49 sham::DDMultiRef{edges.spans_x.get_spans(), edges.spans_y.get_spans()},
50 sham::DDMultiRef{edges.spans_z.get_spans()},
51 val_cnts,
52 [alpha_0, alpha_1, alpha_2, read_z](
53 u32 i, const T *__restrict x, const T *__restrict y, T *__restrict z) {
54 // keep the left to right evaluation order, so that the rounding does not depend on
55 // read_z
56 z[i] = read_z ? alpha_0 * z[i] + alpha_1 * x[i] + alpha_2 * y[i]
57 : alpha_1 * x[i] + alpha_2 * y[i];
58 });
59 }
60
61 template<class T>
63 std::string tex = R"tex(
64 Linear combination of three vectors
65 \begin{equation}
66 {spans_z}_i \leftarrow {alpha_0} \, {spans_z}_i + {alpha_1} \, {spans_x}_i + {alpha_2} \, {spans_y}_i
67 \end{equation}
68 )tex";
69
70 replace_edges_tex_symbols(tex);
71
72 return tex;
73 }
74
75} // namespace shamrock::solvergraph
76
Header file describing a Node Instance.
Node computing the linear combination z <- alpha_0 * z + alpha_1 * x + alpha_2 * y on fields.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Represents a collection of objects distributed across patches identified by a u64 id.
Compute z <- alpha_0 * z + alpha_1 * x + alpha_2 * y on every value of every patch.
virtual std::string _impl_get_tex() const
get the tex of the node
void distributed_data_kernel_call(sham::DeviceScheduler_ptr dev_sched, RefIn in, RefOut in_out, const shambase::DistributedData< index_t > &thread_counts, Functor &&func)
A variant of sham::kernel_call for distributed data.
A variant of sham::MultiRef for distributed data.