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 std::string tex = R"tex(
88 BallabioTsLimiter
89
90 \begin{align}
91 {t_j}_{i,j} &= \min\left({t_j}_{i,j}, \frac{{hpart}_i}{{cs}_i}\right) \\
92 i &\in [0,{part_counts}) \\
93 j &\in [0,{ndust})
94 \end{align}
95 )tex";
96
97 replace_edges_tex_symbols(tex);
98
99 shambase::replace_all(tex, "{ndust}", sham::format("{}", ndust));
100
101 return tex;
102 };
103 };
104} // namespace shammodels::sph::modules
105
106#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
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