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>
26 auto edges = get_edges();
27
28 // inputs
29 auto &ids_to_check = edges.ids_to_check.data;
30 auto &sim_box = edges.sim_box.value;
31 auto &patch_tree = edges.patch_tree.get_patch_tree();
32 auto &patch_boxes = edges.patch_boxes;
33
34 using PtNode = typename SerialPatchTree<TgridVec>::PtNode;
35
36 // outputs
37 auto &ghost_layers_candidates = edges.ghost_layers_candidates.values;
38
39 auto paving = get_paving(mode, sim_box);
40
41 using namespace shamrock::patch;
42
43 // for each repetitions
44 for_each_paving_tile(mode, [&](i32 xoff, i32 yoff, i32 zoff) {
45 // for all local patches
46 for (auto id : ids_to_check) {
47 auto patch_box = patch_boxes.values.get(id);
48
49 // f(patch)
50 auto patch_box_mapped = paving.f_aabb(patch_box, xoff, yoff, zoff);
51
52 patch_tree.host_for_each_leafs(
53 [&](u64 tree_id, PtNode n) {
54 shammath::AABB<TgridVec> tree_cell{n.box_min, n.box_max};
55
56 // f(patch) V box =! empty (a surface is not an empty set btw)
57 // <=> is ghost layer != empty
58 return tree_cell.get_intersect(patch_box_mapped).is_not_empty();
59 },
60 [&](u64 id_found, PtNode n) {
61 // skip self intersection (but not if we are through a boundary)
62 if ((id_found == id) && (xoff == 0) && (yoff == 0) && (zoff == 0)) {
63 return;
64 }
65
66 // we have an ghost layer between
67 // patch `id` and patch `id_found` for this offset
68 // so we store that
69 ghost_layers_candidates.add_obj(
70 id,
71 id_found,
72 GhostLayerCandidateInfos{.xoff = xoff, .yoff = yoff, .zoff = zoff});
73 });
74 }
75 });
76}
77
78template<class TgridVec>
80 const {
81 auto sim_box = get_ro_edge_base(0).get_tex_symbol();
82 auto patch_tree = get_ro_edge_base(1).get_tex_symbol();
83 auto patch_boxes = get_ro_edge_base(2).get_tex_symbol();
84 auto ghost_layers_candidates = get_rw_edge_base(0).get_tex_symbol();
85
86 std::string tex = R"tex(
87 Find Ghost Layer Candidates
88
89 \begin{algorithm}[H]
90 \caption{Find Ghost Layer Candidates Algorithm}
91 \SetAlgoLined
92 \SetKwInOut{Input}{Input}
93 \SetKwInOut{Output}{Output}
94 \Input{Simulation box, patch tree, patch boxes}
95 \Output{Ghost layer candidates}
96 \BlankLine
97 \For{each paving tile offset $(x_{\rm off}, y_{\rm off}, z_{\rm off})$}{
98 \uIf{periodic in $x$}{$x_{\rm off} \in \{-1, 0, 1\}$}
99 \Else{$x_{\rm off} = 0$}
100 \uIf{periodic in $y$}{$y_{\rm off} \in \{-1, 0, 1\}$}
101 \Else{$y_{\rm off} = 0$}
102 \uIf{periodic in $z$}{$z_{\rm off} \in \{-1, 0, 1\}$}
103 \Else{$z_{\rm off} = 0$}
104 \BlankLine
105 \For{each local patch $P_i$}{
106 $B_i \leftarrow$ patch box of $P_i$\;
107 $B_i^{\rm mapped} \leftarrow f(B_i, x_{\rm off}, y_{\rm off}, z_{\rm off})$\;
108 \BlankLine
109 \For{each tree node $T_j$}{
110 $B_j \leftarrow$ tree node box\;
111 \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))$}{
112 Add ghost layer candidate: $(P_i, P_j, x_{\rm off}, y_{\rm off}, z_{\rm off})$\;
113 }
114 }
115 }
116 }
117 \end{algorithm}
118
119 \textbf{Note:} $f(B, x, y, z)$ is the paving function that maps box $B$ by offset $(x, y, z)$
120 )tex";
121
122 shambase::replace_all(tex, "{sim_box}", sim_box);
123 shambase::replace_all(tex, "{patch_tree}", patch_tree);
124 shambase::replace_all(tex, "{patch_boxes}", patch_boxes);
125 shambase::replace_all(tex, "{ghost_layers_candidates}", ghost_layers_candidates);
126
127 return tex;
128}
129
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
IEdge & get_rw_edge_base(int slot)
Get a reference to a read write edge and cast it to the type IEdge.
Definition INode.hpp:100
const IEdge & get_ro_edge_base(int slot)
Get a reference to a read only edge.
Definition INode.hpp:91
This header file contains utility functions related to exception handling in the code.
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:110
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