Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
SetDustStoppingTimeConstant.hpp
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
10#pragma once
11
18
19#include "shambase/string.hpp"
22#include "shambackends/vec.hpp"
28#include <vector>
29
30#define NODE_EDGES(X_RO, X_RW) \
31 /* scalars */ \
32 X_RO(shamrock::solvergraph::ScalarEdge<std::vector<Tscal>>, t_j_0) \
33 \
34 /* counts */ \
35 X_RO(shamrock::solvergraph::Indexes<u32>, part_counts) \
36 \
37 /* fields */ \
38 X_RW(shamrock::solvergraph::IFieldSpan<Tscal>, t_j)
39
41
42 template<class Tvec>
43 class SetDustStoppingTimeConstant : public shamrock::solvergraph::INode {
44
45 using Tscal = shambase::VecComponent<Tvec>;
46
47 u32 ndust;
48 std::unique_ptr<sham::DeviceBuffer<Tscal>> t_j_0;
49
50 public:
51 SetDustStoppingTimeConstant(u32 ndust) : ndust(ndust) {}
52
53 EXPAND_NODE_EDGES(NODE_EDGES)
54
56
58
59 auto edges = get_edges();
60
61 auto &part_counts = edges.part_counts.indexes;
62 const std::vector<Tscal> &inputs_tj = edges.t_j_0.value;
63 SHAM_ASSERT(inputs_tj.size() == ndust);
64
65 // ensure that the output edges are of size part_counts
66 edges.t_j.ensure_sizes(part_counts);
67
68 if (!t_j_0) {
69 t_j_0 = std::make_unique<sham::DeviceBuffer<Tscal>>(
70 ndust, shamsys::instance::get_compute_scheduler_ptr());
71 }
72 t_j_0->resize(ndust);
73 t_j_0->copy_from_stdvec(inputs_tj);
74
75 auto &q = shamsys::instance::get_compute_scheduler().get_queue();
76
77 part_counts.for_each([&](u64 id, u32 count) {
78 // call the kernel for each patches with part_counts.get(id_patch) threads of patch
79 // id_patch
81 q,
82 sham::MultiRef{*t_j_0},
83 sham::MultiRef{edges.t_j.get_spans().get(id)},
84 count * ndust,
85 [ndust
86 = ndust](u32 thread_id, const Tscal *__restrict t_j_0, Tscal *__restrict t_j) {
87 u32 jdust = thread_id % ndust;
88 t_j[thread_id] = t_j_0[jdust];
89 });
90 });
91 }
92
93 inline virtual std::string _impl_get_label() const {
94 return "SetDustStoppingTimeConstant";
95 };
96
97 inline virtual std::string _impl_get_tex() const {
98
99 auto t_j_0 = get_ro_edge_base(0).get_tex_symbol();
100 auto part_counts = get_ro_edge_base(1).get_tex_symbol();
101 auto t_j = get_rw_edge_base(0).get_tex_symbol();
102
103 std::string tex = R"tex(
104 SetDustStoppingTimeConstant
105
106 \begin{align}
107 {t_j}_{i,j} &= {t_j_0}_j \\
108 i &\in [0,{part_counts}) \\
109 j &\in [0,{ndust})
110 \end{align}
111 )tex";
112
113 shambase::replace_all(tex, "{t_j_0}", t_j_0);
114 shambase::replace_all(tex, "{part_counts}", part_counts);
115 shambase::replace_all(tex, "{ndust}", shambase::format("{}", ndust));
116 shambase::replace_all(tex, "{t_j}", t_j);
117
118 return tex;
119 };
120 };
121} // namespace shammodels::sph::modules
122
123#undef NODE_EDGES
Header file describing a Node Instance.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
#define SHAM_ASSERT(x)
Shorthand for SHAM_ASSERT_NAMED without a message.
Definition assert.hpp:67
virtual std::string _impl_get_label() const
get the label of the node
virtual std::string _impl_get_tex() const
get the tex of the node
Inode is node between data edges, takes multiple inputs, multiple outputs.
Definition INode.hpp:30
IEdge & get_rw_edge_base(int slot)
Get a reference to a read write edge and cast it to the type IEdge.
Definition INode.hpp:100
const IEdge & get_ro_edge_base(int slot)
Get a reference to a read only edge.
Definition INode.hpp:91
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.
void replace_all(std::string &inout, std::string_view what, std::string_view with)
replace all occurence of a search string with another
Definition string.hpp:110
namespace for the sph model modules
#define __shamrock_stack_entry()
Macro to create a stack entry.
A class that references multiple buffers or similar objects.