Hierarchy.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <cstddef>
8 #include <unordered_set>
9 #include <vector>
10 
11 /// \cond
12 template <size_t Dim>
13 struct ElementId;
14 /// \endcond
15 
17 
18 /*!
19  * \brief Coarsen the initial refinement levels of all blocks in the domain
20  *
21  * Simply decrement the refinement level uniformly over the entire domain.
22  * Doesn't do anything for blocks that are already fully coarsened, so if the
23  * return value equals the input argument the entire domain is fully coarsened.
24  * Decrementing the refinement level means combining two elements into one,
25  * thereby halving the number of elements per dimension.
26  *
27  * \tparam Dim The spatial dimension of the domain
28  * \param initial_refinement_levels The refinement level in each block of the
29  * domain and in every dimension.
30  * \return std::vector<std::array<size_t, Dim>> The coarsened refinement levels
31  * by decrementing every entry in `initial_refinement_levels` unless it is
32  * already zero.
33  */
34 template <size_t Dim>
36  std::vector<std::array<size_t, Dim>> initial_refinement_levels) noexcept;
37 
38 /*!
39  * \brief The element covering the `child_id` on the coarser grid.
40  *
41  * \tparam Dim The spatial dimension of the domain
42  * \param child_id The ID of an element on the finer grid
43  * \return ElementId<Dim> The ID of the element on the coarser grid that
44  * covers the `child_id`. This parent element covers at most two child elements
45  * per dimension.
46  */
47 template <size_t Dim>
48 ElementId<Dim> parent_id(const ElementId<Dim>& child_id) noexcept;
49 
50 /*!
51  * \brief The elements covering the `parent_id` on the finer grid.
52  *
53  * \tparam Dim The spatial dimension of the domain
54  * \param parent_id The ID of an element on the coarser grid
55  * \param children_refinement_levels The refinement level of the finer grid in
56  * this block
57  * \return std::unordered_set<ElementId<Dim>> The IDs of the elements on the
58  * finer grid that cover the `parent_id`. Returns an empty set if the
59  * `parent_id` is already on the finest grid. Else, returns at least one child
60  * (if the grids have the same refinement levels) and at most
61  * \f$2^\mathrm{Dim}\f$ children (if the grid is finer in every dimension).
62  */
63 template <size_t Dim>
66  const std::array<size_t, Dim>& children_refinement_levels) noexcept;
67 
68 } // namespace LinearSolver::multigrid
LinearSolver::multigrid::parent_id
ElementId< Dim > parent_id(const ElementId< Dim > &child_id) noexcept
The element covering the child_id on the coarser grid.
unordered_set
vector
ElementId
An ElementId uniquely labels an Element.
Definition: ElementId.hpp:50
cstddef
array
LinearSolver::multigrid::coarsen
std::vector< std::array< size_t, Dim > > coarsen(std::vector< std::array< size_t, Dim >> initial_refinement_levels) noexcept
Coarsen the initial refinement levels of all blocks in the domain.
LinearSolver::multigrid
Definition: Hierarchy.hpp:16
LinearSolver::multigrid::child_ids
std::unordered_set< ElementId< Dim > > child_ids(const ElementId< Dim > &parent_id, const std::array< size_t, Dim > &children_refinement_levels) noexcept
The elements covering the parent_id on the finer grid.