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
19#include "shammath/riemann.hpp"
22
23namespace {
24
25 template<class Tscal>
26 struct KernelComputeMass {
27
28 inline static void kernel(
30 &spans_cell_sizes,
34 u32 block_size) {
35
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
85 auto block_count = get_ro_edge_base(0).get_tex_symbol();
86 auto cell_size = get_ro_edge_base(1).get_tex_symbol();
87 auto rho = get_ro_edge_base(2).get_tex_symbol();
88 auto mass = get_rw_edge_base(0).get_tex_symbol();
89
90 std::string tex = R"tex(
91 Compute cell mass
92
93 \begin{align}
94 {mass}_i &= {rho}_i {cell_size}_i^3 \\
95 i &\in [0,{block_count} * N_{\rm cell/block}) \\
96 N_{\rm cell/block} & = {block_size}
97 \end{align}
98 )tex";
99
100 shambase::replace_all(tex, "{cell_size}", cell_size);
101 shambase::replace_all(tex, "{rho}", rho);
102 shambase::replace_all(tex, "{mass}", mass);
103 shambase::replace_all(tex, "{block_count}", block_count);
104 shambase::replace_all(tex, "{block_size}", shambase::format("{}", block_size));
105
106 return tex;
107 }
108
109} // namespace shammodels::basegodunov::modules
110
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
Represents a collection of objects distributed across patches identified by a u64 id.
virtual std::string _impl_get_tex() const
get the tex of the node
Represents a span of data within a PatchDataField.
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:183
namespace for the basegodunov model modules
From original version by Thomas Guillet (T.A.Guillet@exeter.ac.uk)
A variant of sham::MultiRef for distributed data.