GotoAction.hpp
1 // 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 "Utilities/TMPL.hpp"
12 
13 /// \cond
14 namespace Parallel {
15 template <typename Metavariables>
16 class ConstGlobalCache;
17 } // namespace Parallel
18 namespace db {
19 template <typename TagsList>
20 class DataBox;
21 } // namespace db
22 /// \endcond
23 
24 namespace Actions {
25 /// \ingroup ActionsGroup
26 /// Labels a location in the action list that can be jumped to using Goto.
27 ///
28 /// Uses:
29 /// - ConstGlobalCache: nothing
30 /// - DataBox: nothing
31 ///
32 /// DataBox changes:
33 /// - Adds: nothing
34 /// - Removes: nothing
35 /// - Modifies: nothing
36 template <typename Tag>
37 struct Label {
38  template <typename DbTags, typename... InboxTags, typename Metavariables,
39  typename ArrayIndex, typename ActionList,
40  typename ParallelComponent>
41  static auto apply(db::DataBox<DbTags>& box,
42  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
44  const ArrayIndex& /*array_index*/,
45  const ActionList /*meta*/,
46  const ParallelComponent* const /*meta*/) noexcept {
47  static_assert(
48  tmpl::count_if<ActionList,
49  std::is_same<tmpl::_1, tmpl::pin<Label<Tag>>>>::value ==
50  1,
51  "Duplicate label");
52  return std::forward_as_tuple(std::move(box));
53  }
54 };
55 
56 /// \ingroup ActionsGroup
57 /// Jumps to a Label.
58 ///
59 /// Uses:
60 /// - ConstGlobalCache: nothing
61 /// - DataBox: nothing
62 ///
63 /// DataBox changes:
64 /// - Adds: nothing
65 /// - Removes: nothing
66 /// - Modifies: nothing
67 template <typename Tag>
68 struct Goto {
69  template <typename DbTags, typename... InboxTags, typename Metavariables,
70  typename ArrayIndex, typename ActionList,
71  typename ParallelComponent>
72  static auto apply(db::DataBox<DbTags>& box,
73  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
75  const ArrayIndex& /*array_index*/,
76  const ActionList /*meta*/,
77  const ParallelComponent* const /*meta*/) noexcept {
78  constexpr size_t index =
79  tmpl::index_of<ActionList, Actions::Label<Tag>>::value;
80  return std::tuple<db::DataBox<DbTags>&&, bool, size_t>(std::move(box),
81  false, index);
82  }
83 };
84 } // namespace Actions
Defines class tuples::TaggedTuple.
Labels a location in the action list that can be jumped to using Goto.
Definition: GotoAction.hpp:37
Contains functions that forward to Charm++ parallel functions.
Definition: Abort.hpp:13
constexpr auto apply(F &&f, const DataBox< BoxTags > &box, Args &&... args)
Apply the function f with argument Tags TagsList from DataBox box
Definition: DataBox.hpp:1595
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:272
Jumps to a Label.
Definition: GotoAction.hpp:68
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Namespace for DataBox related things.
Definition: DataBox.hpp:33
Wraps the template metaprogramming library used (brigand)
Definition: SolvePoissonProblem.hpp:38
Definition: ComputeTimeDerivative.hpp:28