SpECTRE Documentation Coverage Report
Current view: top level - Domain/Amr - Helpers.cpp Hit Total Coverage
Commit: ebec864322c50bab8dca0a90baf8d01875114261 Lines: 3 4 75.0 %
Date: 2020-11-25 20:28:50
Legend: Lines: hit not hit

          Line data    Source code
       1           0 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : #include "Domain/Amr/Helpers.hpp"
       5             : 
       6             : #include "Domain/Structure/Direction.hpp"       // IWYU pragma: keep
       7             : #include "Domain/Structure/ElementId.hpp"       // IWYU pragma: keep
       8             : #include "Domain/Structure/OrientationMap.hpp"  // IWYU pragma: keep
       9             : #include "Domain/Structure/SegmentId.hpp"       // IWYU pragma: keep
      10             : #include "ErrorHandling/Assert.hpp"
      11             : #include "Utilities/GenerateInstantiations.hpp"
      12             : #include "Utilities/Gsl.hpp"
      13             : 
      14             : namespace amr {
      15             : template <size_t VolumeDim>
      16           1 : std::array<size_t, VolumeDim> desired_refinement_levels(
      17             :     const ElementId<VolumeDim>& id,
      18             :     const std::array<amr::Flag, VolumeDim>& flags) noexcept {
      19             :   std::array<size_t, VolumeDim> result{};
      20             : 
      21             :   for (size_t d = 0; d < VolumeDim; ++d) {
      22             :     ASSERT(amr::Flag::Undefined != gsl::at(flags, d),
      23             :            "Undefined amr::Flag in dimension " << d);
      24             :     gsl::at(result, d) = gsl::at(id.segment_ids(), d).refinement_level();
      25             :     if (amr::Flag::Join == gsl::at(flags, d)) {
      26             :       --gsl::at(result, d);
      27             :     } else if (amr::Flag::Split == gsl::at(flags, d)) {
      28             :       ++gsl::at(result, d);
      29             :     }
      30             :   }
      31             :   return result;
      32             : }
      33             : 
      34             : template <size_t VolumeDim>
      35           1 : std::array<size_t, VolumeDim> desired_refinement_levels_of_neighbor(
      36             :     const ElementId<VolumeDim>& neighbor_id,
      37             :     const std::array<amr::Flag, VolumeDim>& neighbor_flags,
      38             :     const OrientationMap<VolumeDim>& orientation) noexcept {
      39             :   if (orientation.is_aligned()) {
      40             :     return desired_refinement_levels(neighbor_id, neighbor_flags);
      41             :   }
      42             :   std::array<size_t, VolumeDim> result{};
      43             :   for (size_t d = 0; d < VolumeDim; ++d) {
      44             :     ASSERT(amr::Flag::Undefined != gsl::at(neighbor_flags, d),
      45             :            "Undefined amr::Flag in dimension " << d);
      46             :     const size_t mapped_dim = orientation(d);
      47             :     gsl::at(result, d) =
      48             :         gsl::at(neighbor_id.segment_ids(), mapped_dim).refinement_level();
      49             :     if (amr::Flag::Join == gsl::at(neighbor_flags, mapped_dim)) {
      50             :       --gsl::at(result, d);
      51             :     } else if (amr::Flag::Split == gsl::at(neighbor_flags, mapped_dim)) {
      52             :       ++gsl::at(result, d);
      53             :     }
      54             :   }
      55             :   return result;
      56             : }
      57             : 
      58             : template <size_t VolumeDim>
      59           1 : bool has_potential_sibling(const ElementId<VolumeDim>& element_id,
      60             :                            const Direction<VolumeDim>& direction) noexcept {
      61             :   return direction.side() ==
      62             :          gsl::at(element_id.segment_ids(), direction.dimension())
      63             :              .side_of_sibling();
      64             : }
      65             : 
      66             : /// \cond
      67             : #define DIM(data) BOOST_PP_TUPLE_ELEM(0, data)
      68             : 
      69             : #define INSTANTIATE(_, data)                                                   \
      70             :   template std::array<size_t, DIM(data)> desired_refinement_levels<DIM(data)>( \
      71             :       const ElementId<DIM(data)>&,                                             \
      72             :       const std::array<amr::Flag, DIM(data)>&) noexcept;                       \
      73             :   template std::array<size_t, DIM(data)>                                       \
      74             :   desired_refinement_levels_of_neighbor<DIM(data)>(                            \
      75             :       const ElementId<DIM(data)>&, const std::array<amr::Flag, DIM(data)>&,    \
      76             :       const OrientationMap<DIM(data)>&) noexcept;                              \
      77             :   template bool has_potential_sibling(                                         \
      78             :       const ElementId<DIM(data)>& element_id,                                  \
      79             :       const Direction<DIM(data)>& direction) noexcept;
      80             : 
      81             : GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3))
      82             : 
      83             : #undef DIM
      84             : #undef INSTANTIATE
      85             : /// \endcond
      86             : }  // namespace amr

Generated by: LCOV version 1.14