SpECTRE Documentation Coverage Report
Current view: top level - Parallel/Actions - Goto.hpp Hit Total Coverage
Commit: b1342d46f40e2d46bbd11d0cef68fd973031a24b Lines: 3 6 50.0 %
Date: 2020-09-24 20:24:42
Legend: Lines: hit not hit

          Line data    Source code
       1           0 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : #pragma once
       5             : 
       6             : #include <cstddef>
       7             : #include <tuple>
       8             : #include <type_traits>
       9             : 
      10             : #include "DataStructures/DataBox/DataBox.hpp"
      11             : #include "Utilities/TMPL.hpp"
      12             : #include "Utilities/TaggedTuple.hpp"
      13             : 
      14             : /// \cond
      15             : namespace Parallel {
      16             : template <typename Metavariables>
      17             : class GlobalCache;
      18             : }  // namespace Parallel
      19             : namespace db {
      20             : template <typename TagsList>
      21             : class DataBox;
      22             : }  // namespace db
      23             : /// \endcond
      24             : 
      25             : namespace Actions {
      26             : /// \ingroup ActionsGroup
      27             : /// Labels a location in the action list that can be jumped to using Goto.
      28             : ///
      29             : /// Uses:
      30             : /// - GlobalCache: nothing
      31             : /// - DataBox: nothing
      32             : ///
      33             : /// DataBox changes:
      34             : /// - Adds: nothing
      35             : /// - Removes: nothing
      36             : /// - Modifies: nothing
      37             : template <typename Tag>
      38           1 : struct Label {
      39             :   template <typename DbTags, typename... InboxTags, typename Metavariables,
      40             :             typename ArrayIndex, typename ActionList,
      41             :             typename ParallelComponent>
      42           0 :   static auto apply(db::DataBox<DbTags>& box,
      43             :                     const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
      44             :                     const Parallel::GlobalCache<Metavariables>& /*cache*/,
      45             :                     const ArrayIndex& /*array_index*/,
      46             :                     const ActionList /*meta*/,
      47             :                     const ParallelComponent* const /*meta*/) noexcept {
      48             :     static_assert(
      49             :         tmpl::count_if<ActionList,
      50             :                        std::is_same<tmpl::_1, tmpl::pin<Label<Tag>>>>::value ==
      51             :             1,
      52             :         "Duplicate label");
      53             :     return std::forward_as_tuple(std::move(box));
      54             :   }
      55             : };
      56             : 
      57             : /// \ingroup ActionsGroup
      58             : /// Jumps to a Label.
      59             : ///
      60             : /// Uses:
      61             : /// - GlobalCache: nothing
      62             : /// - DataBox: nothing
      63             : ///
      64             : /// DataBox changes:
      65             : /// - Adds: nothing
      66             : /// - Removes: nothing
      67             : /// - Modifies: nothing
      68             : template <typename Tag>
      69           1 : struct Goto {
      70             :   template <typename DbTags, typename... InboxTags, typename Metavariables,
      71             :             typename ArrayIndex, typename ActionList,
      72             :             typename ParallelComponent>
      73           0 :   static auto apply(db::DataBox<DbTags>& box,
      74             :                     const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
      75             :                     const Parallel::GlobalCache<Metavariables>& /*cache*/,
      76             :                     const ArrayIndex& /*array_index*/,
      77             :                     const ActionList /*meta*/,
      78             :                     const ParallelComponent* const /*meta*/) noexcept {
      79             :     constexpr size_t index =
      80             :         tmpl::index_of<ActionList, Actions::Label<Tag>>::value;
      81             :     return std::tuple<db::DataBox<DbTags>&&, bool, size_t>(std::move(box),
      82             :                                                            false, index);
      83             :   }
      84             : };
      85             : 
      86             : namespace Goto_detail {
      87             : 
      88             : template <typename ConditionTag>
      89             : struct RepeatEnd;
      90             : 
      91             : template <typename ConditionTag>
      92             : struct RepeatStart {
      93             :   template <typename DbTagsList, typename... InboxTags, typename Metavariables,
      94             :             typename ArrayIndex, typename ActionList,
      95             :             typename ParallelComponent>
      96             :   static std::tuple<db::DataBox<DbTagsList>&&, bool, size_t> apply(
      97             :       db::DataBox<DbTagsList>& box,
      98             :       tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
      99             :       const Parallel::GlobalCache<Metavariables>& /*cache*/,
     100             :       const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
     101             :       const ParallelComponent* const /*meta*/) noexcept {
     102             :     return {std::move(box), false,
     103             :             db::get<ConditionTag>(box)
     104             :                 ? tmpl::index_of<ActionList, RepeatEnd<ConditionTag>>::value + 1
     105             :                 : tmpl::index_of<ActionList, RepeatStart>::value + 1};
     106             :   }
     107             : };
     108             : 
     109             : template <typename ConditionTag>
     110             : struct RepeatEnd {
     111             :   template <typename DbTagsList, typename... InboxTags, typename Metavariables,
     112             :             typename ArrayIndex, typename ActionList,
     113             :             typename ParallelComponent>
     114             :   static std::tuple<db::DataBox<DbTagsList>&&, bool, size_t> apply(
     115             :       db::DataBox<DbTagsList>& box,
     116             :       tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
     117             :       const Parallel::GlobalCache<Metavariables>& /*cache*/,
     118             :       const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
     119             :       const ParallelComponent* const /*meta*/) noexcept {
     120             :     return {
     121             :         std::move(box), false,
     122             :         db::get<ConditionTag>(box)
     123             :             ? tmpl::index_of<ActionList, RepeatEnd>::value + 1
     124             :             : tmpl::index_of<ActionList, RepeatStart<ConditionTag>>::value + 1};
     125             :   }
     126             : };
     127             : 
     128             : }  // namespace Goto_detail
     129             : 
     130             : /// Repeats the `ActionList` until `ConditionTag` is `True`.
     131             : template <typename ConditionTag, typename ActionList>
     132           1 : using RepeatUntil =
     133             :     tmpl::flatten<tmpl::list<Goto_detail::RepeatStart<ConditionTag>, ActionList,
     134             :                              Goto_detail::RepeatEnd<ConditionTag>>>;
     135             : }  // namespace Actions

Generated by: LCOV version 1.14