Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
BallabioTsLimiter.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"
21#include "shambackends/vec.hpp"
26
27#define NODE_EDGES(X_RO, X_RW) \
28 /* counts */ \
29 X_RO(shamrock::solvergraph::Indexes<u32>, part_counts) \
30 \
31 /* fields */ \
32 X_RO(shamrock::solvergraph::IFieldSpan<Tscal>, hpart) \
33 X_RO(shamrock::solvergraph::IFieldSpan<Tscal>, cs) \
34 \
35 X_RW(shamrock::solvergraph::IFieldSpan<Tscal>, t_j)
36
38
39 template<class Tvec>
40 class BallabioTsLimiter : public shamrock::solvergraph::INode {
41
42 using Tscal = shambase::VecComponent<Tvec>;
43
44 u32 ndust;
45
46 public:
47 BallabioTsLimiter(u32 ndust) : ndust(ndust) {}
48
49 EXPAND_NODE_EDGES(NODE_EDGES)
50
52
54
55 auto edges = get_edges();
56
57 auto &part_counts = edges.part_counts.indexes;
58
59 edges.t_j.ensure_sizes(part_counts);
60
61 auto &q = shamsys::instance::get_compute_scheduler().get_queue();
62
63 part_counts.for_each([&](u64 id, u32 count) {
65 q,
66 sham::MultiRef{edges.hpart.get_spans().get(id), edges.cs.get_spans().get(id)},
67 sham::MultiRef{edges.t_j.get_spans().get(id)},
68 count * ndust,
69 [ndust = ndust](
70 u32 thread_id,
71 const Tscal *__restrict hpart,
72 const Tscal *__restrict cs,
73 Tscal *__restrict t_j) {
74 u32 id_a = thread_id / ndust;
75
76 Tscal h_a = hpart[id_a];
77 Tscal cs_a = cs[id_a];
78
79 t_j[thread_id] = sycl::min(t_j[thread_id], h_a / cs_a);
80 });
81 });
82 }
83
84 inline virtual std::string _impl_get_label() const { return "BallabioTsLimiter"; };
85
86 inline virtual std::string _impl_get_tex() const {
87
88 auto part_counts = get_ro_edge_base(0).get_tex_symbol();
89 auto hpart = get_ro_edge_base(1).get_tex_symbol();
90 auto cs = get_ro_edge_base(2).get_tex_symbol();
91 auto t_j = get_rw_edge_base(0).get_tex_symbol();
92
93 std::string tex = R"tex(
94 BallabioTsLimiter
95
96 \begin{align}
97 {t_j}_{i,j} &= \min\left({t_j}_{i,j}, \frac{{hpart}_i}{{cs}_i}\right) \\
98 i &\in [0,{part_counts}) \\
99 j &\in [0,{ndust})
100 \end{align}
101 )tex";
102
103 shambase::replace_all(tex, "{part_counts}", part_counts);
104 shambase::replace_all(tex, "{ndust}", shambase::format("{}", ndust));
105 shambase::replace_all(tex, "{hpart}", hpart);
106 shambase::replace_all(tex, "{cs}", cs);
107 shambase::replace_all(tex, "{t_j}", t_j);
108
109 return tex;
110 };
111 };
112} // namespace shammodels::sph::modules
113
114#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
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
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:137
const IEdge & get_ro_edge_base(int slot)
Get a reference to a read only edge.
Definition INode.hpp:128
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.
Definition MultiRef.hpp:33