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
16#include "shambase/assert.hpp"
18#include "shammath/AABB.hpp"
21#include <stdexcept>
22
23template<class TgridVec>
25 TgridVec>::_impl_evaluate_internal() {
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, id_found, GhostLayerCandidateInfos{xoff, yoff, zoff});
71 });
72 }
73 });
74}
75
76template<class TgridVec>
78 const {
79 auto sim_box = get_ro_edge_base(0).get_tex_symbol();
80 auto patch_tree = get_ro_edge_base(1).get_tex_symbol();
81 auto patch_boxes = get_ro_edge_base(2).get_tex_symbol();
82 auto ghost_layers_candidates = get_rw_edge_base(0).get_tex_symbol();
83
84 std::string tex = R"tex(
85 Find Ghost Layer Candidates
86
87 \begin{algorithm}[H]
88 \caption{Find Ghost Layer Candidates Algorithm}
89 \SetAlgoLined
90 \SetKwInOut{Input}{Input}
91 \SetKwInOut{Output}{Output}
92 \Input{Simulation box, patch tree, patch boxes}
93 \Output{Ghost layer candidates}
94 \BlankLine
95 \For{each paving tile offset $(x_{\rm off}, y_{\rm off}, z_{\rm off})$}{
96 \uIf{periodic in $x$}{$x_{\rm off} \in \{-1, 0, 1\}$}
97 \Else{$x_{\rm off} = 0$}
98 \uIf{periodic in $y$}{$y_{\rm off} \in \{-1, 0, 1\}$}
99 \Else{$y_{\rm off} = 0$}
100 \uIf{periodic in $z$}{$z_{\rm off} \in \{-1, 0, 1\}$}
101 \Else{$z_{\rm off} = 0$}
102 \BlankLine
103 \For{each local patch $P_i$}{
104 $B_i \leftarrow$ patch box of $P_i$\;
105 $B_i^{\rm mapped} \leftarrow f(B_i, x_{\rm off}, y_{\rm off}, z_{\rm off})$\;
106 \BlankLine
107 \For{each tree node $T_j$}{
108 $B_j \leftarrow$ tree node box\;
109 \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))$}{
110 Add ghost layer candidate: $(P_i, P_j, x_{\rm off}, y_{\rm off}, z_{\rm off})$\;
111 }
112 }
113 }
114 }
115 \end{algorithm}
116
117 \textbf{Note:} $f(B, x, y, z)$ is the paving function that maps box $B$ by offset $(x, y, z)$
118 )tex";
119
120 shambase::replace_all(tex, "{sim_box}", sim_box);
121 shambase::replace_all(tex, "{patch_tree}", patch_tree);
122 shambase::replace_all(tex, "{patch_boxes}", patch_boxes);
123 shambase::replace_all(tex, "{ghost_layers_candidates}", ghost_layers_candidates);
124
125 return tex;
126}
127
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.
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
Axis-Aligned bounding box.
Definition AABB.hpp:99