Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
global_var.hpp
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
10#pragma once
11
20
21enum GlobalVariableType { min, max, sum };
22
23template<GlobalVariableType vartype, class T>
25
26 std::unordered_map<u64, T> val_map;
27
28 bool is_reduced = false;
29
30 T final_val;
31
32 public:
33 template<class Lambda>
34 inline void compute_var_patch(PatchScheduler &sched, Lambda &&compute_fct) {
35
36 // sched.for_each_patch_buf([&](u64 id_patch, Patch cur_p, PatchDataBuffer &pdat_buf) {
39 static_assert(
40 std::is_same<decltype(compute_fct(id_patch, pdat)), T>::value,
41 "lambda funct should return the Global variable type");
42
43 val_map[id_patch] = compute_fct(id_patch, pdat);
44 });
45 }
46
47 void reduce_val();
48
49 inline T get_val() {
50 if (!is_reduced) {
52 "Global value has not been reduced");
53 }
54 return final_val;
55 }
56};
MPI scheduler.
std::uint64_t u64
64 bit unsigned integer
The MPI scheduler.
void for_each_patch_data(Function &&fct)
for each macro for patchadata example usage
PatchDataLayer container class, the layout is described in patchdata_layout.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
header for PatchData related function and declaration
Patch object that contain generic patch information.
Definition Patch.hpp:33