Line data Source code
1 0 : // 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 : 16 : namespace LinearSolver::multigrid { 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> 35 1 : std::vector<std::array<size_t, Dim>> coarsen( 36 : std::vector<std::array<size_t, Dim>> initial_refinement_levels); 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 1 : ElementId<Dim> parent_id(const ElementId<Dim>& child_id); 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 at least one child 59 : * (if the grids have the same refinement levels) and at most 60 : * \f$2^\mathrm{Dim}\f$ children (if the grid is finer in every dimension). 61 : */ 62 : template <size_t Dim> 63 1 : std::unordered_set<ElementId<Dim>> child_ids( 64 : const ElementId<Dim>& parent_id, 65 : const std::array<size_t, Dim>& children_refinement_levels); 66 : 67 : } // namespace LinearSolver::multigrid