Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ComputeSumOverV.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
17#include "shambase/string.hpp"
19#include "shamcomm/logs.hpp"
20#include "shammath/riemann.hpp"
24
26
27 template<class T>
29 auto edges = get_edges();
30
31 edges.spans_field.check_sizes(edges.sizes.indexes);
32
33 T loc_val = {};
34 edges.spans_field.get_refs().for_each([&](u32 i, PatchDataField<T> &field_ref) {
35 loc_val += field_ref.compute_sum();
36 });
37
38 T global_sum = shamalgs::collective::allreduce_sum(loc_val);
39
40 edges.mean_val.value = (global_sum / edges.total_volume.value);
41
42 // logger::raw_ln(loc_val, global_sum, edges.mean_val.value,edges.total_volume.value);
43 }
44
45 template<class T>
47 std::string tex = R"tex(
48 Compute cell mass
49
50 \begin{align}
51 {mean_val} &=\sum_{i\in \Omega} {spans_field}_i / {total_volume} \\
52 \Omega = [0,{sizes} * N_{\rm cell/block}) \\
53 N_{\rm cell/block} & = {block_size}
54 \end{align}
55 )tex";
56
57 replace_edges_tex_symbols(tex);
58
59 shambase::replace_all(tex, "{block_size}", sham::format("{}", block_size));
60
61 return tex;
62 }
63
64} // namespace shammodels::basegodunov::modules
65
Header file describing a Node Instance.
std::uint32_t u32
32 bit unsigned integer
virtual std::string _impl_get_tex() const
get the tex of the node
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,...