Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ComputeNextRho.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
19
21#include "shambase/string.hpp"
26
28
29 template<class Tvec>
31 StackEntry stack_loc{};
32 auto edges = get_edges();
33
34 edges.spans_rho.check_sizes(edges.sizes_with_ghost.indexes);
35 edges.spans_dt_rho.check_sizes(edges.sizes.indexes);
36 edges.rho_next.ensure_sizes(edges.sizes_with_ghost.indexes);
37
38 Tscal dt = edges.dt.value;
39
40 auto &q = shamsys::instance::get_compute_scheduler().get_queue();
41
42 edges.sizes_with_ghost.indexes.for_each([&](u64 id, u32 block_count_with_ghost) {
43 auto &rho_span = edges.spans_rho.get_spans().get(id);
44 auto &dt_rho_span = edges.spans_dt_rho.get_spans().get(id);
45 auto &rho_next_span = edges.rho_next.get_spans().get(id);
46
47 u32 cell_count = edges.sizes.indexes.get(id) * block_size;
48 u32 cell_count_with_ghost = block_count_with_ghost * block_size;
49
51 q,
52 sham::MultiRef{rho_span, dt_rho_span},
53 sham::MultiRef{rho_next_span},
54 cell_count_with_ghost,
55 [dt, cell_count](
56 u32 i,
57 const Tscal *__restrict rho,
58 const Tscal *__restrict dt_rho,
59 Tscal *__restrict rho_next) {
60 rho_next[i] = (i < cell_count) ? rho[i] + dt * dt_rho[i] : rho[i];
61 });
62 });
63 }
64
65 template<class Tvec>
67 auto dt = get_ro_edge_base(0).get_tex_symbol();
68 auto rho = get_ro_edge_base(3).get_tex_symbol();
69 auto dt_rho = get_ro_edge_base(4).get_tex_symbol();
70 auto rho_next = get_rw_edge_base(0).get_tex_symbol();
71
72 std::string tex = R"tex(
73 Density at the end of the time step
74
75 \begin{align}
76 {rho_next}_i &= {rho}_i + {dt} {dt_rho}_i
77 \end{align}
78 )tex";
79
80 shambase::replace_all(tex, "{rho_next}", rho_next);
81 shambase::replace_all(tex, "{rho}", rho);
82 shambase::replace_all(tex, "{dt_rho}", dt_rho);
83 shambase::replace_all(tex, "{dt}", dt);
84
85 return tex;
86 }
87
88} // namespace shammodels::basegodunov::modules
89
Node computing the gas density at the end of the time step.
Header file describing a Node Instance.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Compute the gas density at , , without modifying .
virtual std::string _impl_get_tex() const
get the tex of the node
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:147
const IEdge & get_ro_edge_base(int slot)
Get a reference to a read only edge.
Definition INode.hpp:138
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 basegodunov model modules
This file contains the definition for the stacktrace related functionality.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
A class that references multiple buffers or similar objects.
Definition MultiRef.hpp:33