Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
AMRCellStencil.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
21#include <array>
22#include <variant>
23namespace shammodels::amr::cell {
24
25 struct SameLevel {
26 u64 cell_idx;
27 };
28
29 struct Levelp1 {
30 u64 cell_child_idxs_base;
31
32 template<class AMRBlock, class Fct>
33 void for_all_indexes(Fct &&f) {
34
35 f(cell_child_idxs_base + AMRBlock::get_index({0, 0, 0}));
36 f(cell_child_idxs_base + AMRBlock::get_index({0, 0, 1}));
37 f(cell_child_idxs_base + AMRBlock::get_index({0, 1, 0}));
38 f(cell_child_idxs_base + AMRBlock::get_index({0, 1, 1}));
39 f(cell_child_idxs_base + AMRBlock::get_index({1, 0, 0}));
40 f(cell_child_idxs_base + AMRBlock::get_index({1, 0, 1}));
41 f(cell_child_idxs_base + AMRBlock::get_index({1, 1, 0}));
42 f(cell_child_idxs_base + AMRBlock::get_index({1, 1, 1}));
43 }
44 };
45
46 struct Levelm1 {
47 u64 cell_idx;
48 };
49
50 struct None {};
51
56 struct alignas(8) StencilElement {
57
58 enum { SAME, LEVELP1, LEVELM1, NONE } tag = NONE;
59
60 union {
61 SameLevel level_d0;
62 Levelm1 level_dm1;
63 Levelp1 level_dp1;
64 None none;
65 };
66
67 static StencilElement make_none() {
69 ret.tag = NONE;
70 ret.none = {};
71 return ret;
72 }
73 static StencilElement make_same_level(SameLevel l) {
75 ret.tag = SAME;
76 ret.level_d0 = l;
77 return ret;
78 }
79 static StencilElement make_level_p1(Levelp1 l) {
81 ret.tag = LEVELP1;
82 ret.level_dp1 = l;
83 return ret;
84 }
85 static StencilElement make_level_m1(Levelm1 l) {
87 ret.tag = LEVELM1;
88 ret.level_dm1 = l;
89 return ret;
90 }
91
92 template<class Visitor1, class Visitor2, class Visitor3, class Visitor4>
93 inline void visitor(Visitor1 &&f1, Visitor2 &&f2, Visitor3 &&f3, Visitor4 &&f4) {
94 switch (tag) {
95 case SAME : f1(level_d0); break;
96 case LEVELM1: f2(level_dm1); break;
97 case LEVELP1: f3(level_dp1); break;
98 case NONE : f4(none); break;
99 }
100 }
101 };
102
103} // namespace shammodels::amr::cell
utility to manipulate AMR blocks
std::uint64_t u64
64 bit unsigned integer
Traits for C++ types.
static constexpr u32 get_index(std::array< u32, dim > coord) noexcept
Get the local index within the AMR block.
Definition AMRBlock.hpp:52
Stencil element, describe the state of a cell relative to another.