Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ComputeMass.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
16
19#include "shammath/riemann.hpp"
22
23namespace {
24
25 template<class Tscal>
26 struct KernelComputeMass {
27
28 inline static void kernel(
29 const shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tscal>>
30 &spans_cell_sizes,
31 const shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tscal>> &spans_rho,
32 shambase::DistributedData<shamrock::PatchDataFieldSpanPointer<Tscal>> &spans_mass,
33 const shambase::DistributedData<u32> &sizes,
34 u32 block_size) {
35
36 shambase::DistributedData<u32> cell_counts
37 = sizes.map<u32>([&](u64 id, u32 block_count) {
38 u32 cell_count = block_count * block_size;
39 return cell_count;
40 });
41
43 shamsys::instance::get_compute_scheduler_ptr(),
44 sham::DDMultiRef{spans_cell_sizes, spans_rho},
45 sham::DDMultiRef{spans_mass},
46 cell_counts,
47 [block_size](
48 u32 i,
49 const Tscal *__restrict csize,
50 const Tscal *__restrict rho,
51 Tscal *__restrict mass) {
52 u32 block_id = i / block_size;
53 Tscal dV = csize[block_id];
54 dV = dV * dV * dV;
55
56 mass[i] = rho[i] * dV;
57 });
58 }
59 };
60
61} // namespace
62
64
65 template<class Tvec, class TgridVec>
67 auto edges = get_edges();
68
69 edges.spans_block_cell_sizes.check_sizes(edges.sizes.indexes);
70 edges.spans_rhos.check_sizes(edges.sizes.indexes);
71
72 edges.spans_mass.ensure_sizes(edges.sizes.indexes);
73
74 KernelComputeMass<Tscal>::kernel(
75 edges.spans_block_cell_sizes.get_spans(),
76 edges.spans_rhos.get_spans(),
77 edges.spans_mass.get_spans(),
78 edges.sizes.indexes,
79 block_size);
80 }
81
82 template<class Tvec, class TgridVec>
84 std::string tex = R"tex(
85 Compute cell mass
86
87 \begin{align}
88 {spans_mass}_i &= {spans_rhos}_i {spans_block_cell_sizes}_i^3 \\
89 i &\in [0,{sizes} * N_{\rm cell/block}) \\
90 N_{\rm cell/block} & = {block_size}
91 \end{align}
92 )tex";
93
94 replace_edges_tex_symbols(tex);
95
96 shambase::replace_all(tex, "{block_size}", sham::format("{}", block_size));
97
98 return tex;
99 }
100
101} // namespace shammodels::basegodunov::modules
102
constexpr const char * sizes
Temporary sizes for h-iteration.
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_tex() const
get the tex of the node
void distributed_data_kernel_call(sham::DeviceScheduler_ptr dev_sched, RefIn in, RefOut in_out, const shambase::DistributedData< index_t > &thread_counts, Functor &&func)
A variant of sham::kernel_call for distributed data.
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
Umbrella header pulling in the gas states and all gas Riemann solvers (Rusanov, HLL,...