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
19#include "shamcomm/logs.hpp"
20#include "shammath/riemann.hpp"
23
25
26 template<class T>
28 auto edges = get_edges();
29
30 edges.spans_field.check_sizes(edges.sizes.indexes);
31
32 T loc_val = {};
33 edges.spans_field.get_refs().for_each([&](u32 i, PatchDataField<T> &field_ref) {
34 loc_val += field_ref.compute_sum();
35 });
36
37 T global_sum = shamalgs::collective::allreduce_sum(loc_val);
38
39 edges.mean_val.value = (global_sum / edges.total_volume.value);
40
41 // logger::raw_ln(loc_val, global_sum, edges.mean_val.value,edges.total_volume.value);
42 }
43
44 template<class T>
46
47 auto block_count = get_ro_edge_base(0).get_tex_symbol();
48 auto field = get_ro_edge_base(1).get_tex_symbol();
49 auto total_volume = get_ro_edge_base(2).get_tex_symbol();
50 auto mean = get_rw_edge_base(0).get_tex_symbol();
51
52 std::string tex = R"tex(
53 Compute cell mass
54
55 \begin{align}
56 {mean} &=\sum_{i\in \Omega} {field}_i / {total_volume} \\
57 \Omega = [0,{block_count} * N_{\rm cell/block}) \\
58 N_{\rm cell/block} & = {block_size}
59 \end{align}
60 )tex";
61
62 shambase::replace_all(tex, "{total_volume}", total_volume);
63 shambase::replace_all(tex, "{field}", field);
64 shambase::replace_all(tex, "{mean}", mean);
65 shambase::replace_all(tex, "{block_count}", block_count);
66 shambase::replace_all(tex, "{block_size}", shambase::format("{}", block_size));
67
68 return tex;
69 }
70
71} // namespace shammodels::basegodunov::modules
72
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:183
namespace for the basegodunov model modules
From original version by Thomas Guillet (T.A.Guillet@exeter.ac.uk)