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::IDataEdge<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.data;
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 std::string tex = R"tex(
99 SetDustStoppingTimeConstant
100
101 \begin{align}
102 {t_j}_{i,j} &= {t_j_0}_j \\
103 i &\in [0,{part_counts}) \\
104 j &\in [0,{ndust})
105 \end{align}
106 )tex";
107
108 replace_edges_tex_symbols(tex);
109
110 shambase::replace_all(tex, "{ndust}", sham::format("{}", ndust));
111
112 return tex;
113 };
114 };
115} // namespace shammodels::sph::modules
116
117#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:31
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:106
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.
Definition MultiRef.hpp:33