Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
FindGhostLayerCandidates.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
15
16#include "shambase/assert.hpp"
18#include "shammath/AABB.hpp"
21#include <stdexcept>
22
23template<class TgridVec>
27 auto edges = get_edges();
28
29 // inputs
30 auto &ids_to_check = edges.ids_to_check.data;
31 auto &sim_box = edges.sim_box.value;
32 auto &patch_tree = edges.patch_tree.get_patch_tree();
33 auto &patch_boxes = edges.patch_boxes;
34
35 using PtNode = typename SerialPatchTree<TgridVec>::PtNode;
36
37 // outputs
38 auto &ghost_layers_candidates = edges.ghost_layers_candidates.values;
39
40 auto paving = get_paving(mode, sim_box);
41
42 using namespace shamrock::patch;
43
44 // for each repetitions
45 for_each_paving_tile(mode, [&](i32 xoff, i32 yoff, i32 zoff) {
46 // for all local patches
47 for (auto id : ids_to_check) {
48 auto patch_box = patch_boxes.values.get(id);
49
50 // f(patch)
51 auto patch_box_mapped = paving.f_aabb(patch_box, xoff, yoff, zoff);
52
53 patch_tree.host_for_each_leafs(
54 [&](u64 tree_id, PtNode n) {
55 shammath::AABB<TgridVec> tree_cell{n.box_min, n.box_max};
56
57 // f(patch) V box =! empty (a surface is not an empty set btw)
58 // <=> is ghost layer != empty
59 return tree_cell.get_intersect(patch_box_mapped).is_not_empty();
60 },
61 [&](u64 id_found, PtNode n) {
62 // skip self intersection (but not if we are through a boundary)
63 if ((id_found == id) && (xoff == 0) && (yoff == 0) && (zoff == 0)) {
64 return;
65 }
66
67 // we have an ghost layer between
68 // patch `id` and patch `id_found` for this offset
69 // so we store that
70 ghost_layers_candidates.add_obj(
71 id,
72 id_found,
73 GhostLayerCandidateInfos{.xoff = xoff, .yoff = yoff, .zoff = zoff});
74 });
75 }
76 });
77}
78
79template<class TgridVec>
81 const {
82 std::string tex = R"tex(
83 Find Ghost Layer Candidates
84
85 \begin{algorithm}[H]
86 \caption{Find Ghost Layer Candidates Algorithm}
87 \SetAlgoLined
88 \SetKwInOut{Input}{Input}
89 \SetKwInOut{Output}{Output}
90 \Input{Simulation box, patch tree, patch boxes}
91 \Output{Ghost layer candidates}
92 \BlankLine
93 \For{each paving tile offset $(x_{\rm off}, y_{\rm off}, z_{\rm off})$}{
94 \uIf{periodic in $x$}{$x_{\rm off} \in \{-1, 0, 1\}$}
95 \Else{$x_{\rm off} = 0$}
96 \uIf{periodic in $y$}{$y_{\rm off} \in \{-1, 0, 1\}$}
97 \Else{$y_{\rm off} = 0$}
98 \uIf{periodic in $z$}{$z_{\rm off} \in \{-1, 0, 1\}$}
99 \Else{$z_{\rm off} = 0$}
100 \BlankLine
101 \For{each local patch $P_i$}{
102 $B_i \leftarrow$ patch box of $P_i$\;
103 $B_i^{\rm mapped} \leftarrow f(B_i, x_{\rm off}, y_{\rm off}, z_{\rm off})$\;
104 \BlankLine
105 \For{each tree node $T_j$}{
106 $B_j \leftarrow$ tree node box\;
107 \If{$B_i^{\rm mapped} \cap B_j \neq \emptyset$ \textbf{and} $(i \neq j$ \textbf{or} $(x_{\rm off}, y_{\rm off}, z_{\rm off}) \neq (0,0,0))$}{
108 Add ghost layer candidate: $(P_i, P_j, x_{\rm off}, y_{\rm off}, z_{\rm off})$\;
109 }
110 }
111 }
112 }
113 \end{algorithm}
114
115 \textbf{Note:} $f(B, x, y, z)$ is the paving function that maps box $B$ by offset $(x, y, z)$
116 )tex";
117
118 replace_edges_tex_symbols(tex);
119
120 return tex;
121}
122
std::uint64_t u64
64 bit unsigned integer
std::int32_t i32
32 bit integer
Shamrock assertion utility.
virtual std::string _impl_get_tex() const
get the tex of the node
This header file contains utility functions related to exception handling in the code.
#define __shamrock_stack_entry()
Macro to create a stack entry.
Axis-Aligned bounding box.
Definition AABB.hpp:99
bool is_not_empty() const noexcept
Checks if the AABB is non-empty.
Definition AABB.hpp:268
AABB get_intersect(AABB other) const noexcept
Compute the intersection of two AABB.
Definition AABB.hpp:234