InitializeInterfaces.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 <utility>
9 
12 #include "DataStructures/Tensor/EagerMath/Magnitude.hpp"
13 #include "Domain/FaceNormal.hpp"
14 #include "Domain/InterfaceComputeTags.hpp"
15 #include "Domain/Tags.hpp"
16 #include "ParallelAlgorithms/Initialization/MergeIntoDataBox.hpp"
17 #include "Utilities/TMPL.hpp"
19 
20 /// \cond
21 namespace Parallel {
22 template <typename Metavariables>
23 class ConstGlobalCache;
24 } // namespace Parallel
25 /// \endcond
26 
27 namespace dg {
28 namespace Initialization {
29 /// \ingroup InitializationGroup
30 /// %Tags that are to be sliced to the faces of the element
31 template <typename... Tags>
32 using slice_tags_to_face = tmpl::list<Tags...>;
33 
34 /// \ingroup InitializationGroup
35 /// %Tags that are to be sliced to the exterior side of the faces of the element
36 template <typename... Tags>
37 using slice_tags_to_exterior = tmpl::list<Tags...>;
38 
39 /// \ingroup InitializationGroup
40 /// Compute tags on the faces of the element
41 template <typename... Tags>
42 using face_compute_tags = tmpl::list<Tags...>;
43 
44 /// \ingroup InitializationGroup
45 /// Compute tags on the exterior side of the faces of the element
46 template <typename... Tags>
47 using exterior_compute_tags = tmpl::list<Tags...>;
48 } // namespace Initialization
49 
50 namespace Actions {
51 
52 namespace InitializeInterfaces_detail {
53 template <bool Enable, typename Metavariables>
54 struct InitExteriorVarsImpl {
55  template <typename DbTagsList>
57  db::DataBox<DbTagsList>&& box) noexcept {
58  return std::move(box);
59  }
60 };
61 
62 template <typename Metavariables>
63 struct InitExteriorVarsImpl<true, Metavariables> {
64  template <typename DbTagsList>
65  static auto apply(db::DataBox<DbTagsList>&& box) noexcept {
66  using system = typename Metavariables::system;
67  static constexpr size_t dim = system::volume_dim;
68  using vars_tag = typename system::variables_tag;
69  using exterior_vars_tag =
71 
72  db::item_type<exterior_vars_tag> exterior_boundary_vars{};
73  const auto& mesh = db::get<::Tags::Mesh<dim>>(box);
74  for (const auto& direction :
75  db::get<::Tags::Element<dim>>(box).external_boundaries()) {
76  exterior_boundary_vars[direction] = db::item_type<vars_tag>{
77  mesh.slice_away(direction.dimension()).number_of_grid_points()};
78  }
80  InitExteriorVarsImpl, db::AddSimpleTags<exterior_vars_tag>>(
81  std::move(box), std::move(exterior_boundary_vars));
82  }
83 };
84 } // namespace InitializeInterfaces_detail
85 
86 /// \ingroup InitializationGroup
87 /// \brief Initialize items related to the interfaces between Elements and on
88 /// external boundaries
89 ///
90 /// The `dg::Initialization::slice_tags_to_face` and
91 /// `dg::Initialization::slice_tags_to_exterior` types should be used for the
92 /// `SliceTagsToFace` and `SliceTagsToExterior` template parameters,
93 /// respectively. These are used to set additional volume quantities that are to
94 /// be sliced to the interfaces. Compute tags on the interfaces are controlled
95 /// using the `FaceComputeTags` and `ExteriorComputeTags` template parameters,
96 /// which should be passed the `dg::Initialization::face_compute_tags` and
97 /// `dg::Initialization::exterior_compute_tags` types, respectively.
98 ///
99 /// By default, this initializer also adds the system's `variables_tag` on
100 /// exterior (ghost) boundary faces. These are stored in a simple tag and
101 /// updated manually to impose boundary conditions. Set the
102 /// `AddExteriorVariables` template parameter to `false` to disable this
103 /// behavior.
104 ///
105 /// Uses:
106 /// - System:
107 /// * `volume_dim`
108 /// * `variables_tag`
109 /// * `magnitude_tag`
110 ///
111 /// DataBox changes:
112 /// - Adds:
113 /// * `Tags::Interface<Tags::BoundaryDirectionsExterior<volume_dim>,
114 /// variables_tag>` (as a simple tag)
115 /// * `face_tags<Tags::InternalDirections<Dim>>`
116 /// * `face_tags<Tags::BoundaryDirectionsInterior<Dim>>`
117 /// * `face_tags<Tags::BoundaryDirectionsExterior<Dim>>`
118 ///
119 /// - For `face_tags<Directions>`:
120 /// * `Directions`
121 /// * `Tags::Interface<Directions, Tags::Directions<Dim>>`
122 /// * `Tags::Interface<Directions, Tags::Mesh<Dim - 1>>`
123 /// * `Tags::Interface<Directions, Tags::Coordinates<Dim, Frame::Inertial>>`
124 /// (only on exterior faces)
125 /// * `Tags::Interface<Directions, Tags::UnnormalizedFaceNormal<Dim>>`
126 /// * `Tags::Interface<Directions, Tags::Magnitude<
127 /// Tags::UnnormalizedFaceNormal<Dim>>>`
128 /// * `Tags::Interface<Directions, Tags::Normalized<
129 /// Tags::UnnormalizedFaceNormal<Dim>>>`
130 ///
131 /// - Removes: nothing
132 /// - Modifies: nothing
133 template <
134  typename System,
135  typename SliceTagsToFace = Initialization::slice_tags_to_face<>,
136  typename SliceTagsToExterior = Initialization::slice_tags_to_exterior<>,
137  typename FaceComputeTags = Initialization::face_compute_tags<>,
138  typename ExteriorComputeTags = Initialization::exterior_compute_tags<>,
139  bool AddExteriorVariables = true>
141  private:
142  static constexpr size_t dim = System::volume_dim;
143 
144  template <typename TagToSlice, typename Directions>
145  struct make_slice_tag {
147  };
148 
149  template <typename ComputeTag, typename Directions>
150  struct make_compute_tag {
152  };
153 
154  template <typename Directions>
155  using face_tags = tmpl::flatten<tmpl::list<
158  tmpl::transform<SliceTagsToFace,
159  make_slice_tag<tmpl::_1, tmpl::pin<Directions>>>,
160  ::Tags::InterfaceCompute<Directions,
162  ::Tags::InterfaceCompute<Directions,
163  typename System::template magnitude_tag<
166  Directions,
168  tmpl::transform<FaceComputeTags,
169  make_compute_tag<tmpl::_1, tmpl::pin<Directions>>>>>;
170 
171  using exterior_face_tags = tmpl::flatten<tmpl::list<
175  ::Tags::InterfaceCompute<::Tags::BoundaryDirectionsExterior<dim>,
177  tmpl::transform<
178  SliceTagsToExterior,
179  make_slice_tag<tmpl::_1,
180  tmpl::pin<::Tags::BoundaryDirectionsExterior<dim>>>>,
182  ::Tags::BoundaryDirectionsExterior<dim>,
184  ::Tags::InterfaceCompute<::Tags::BoundaryDirectionsExterior<dim>,
185  ::Tags::UnnormalizedFaceNormalCompute<dim>>,
186  ::Tags::InterfaceCompute<::Tags::BoundaryDirectionsExterior<dim>,
187  typename System::template magnitude_tag<
188  ::Tags::UnnormalizedFaceNormal<dim>>>,
190  ::Tags::BoundaryDirectionsExterior<dim>,
191  ::Tags::NormalizedCompute<::Tags::UnnormalizedFaceNormal<dim>>>,
192  tmpl::transform<
193  ExteriorComputeTags,
194  make_compute_tag<
195  tmpl::_1, tmpl::pin<::Tags::BoundaryDirectionsExterior<dim>>>>>>;
196 
197  public:
198  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
199  typename ArrayIndex, typename ActionList,
200  typename ParallelComponent>
201  static auto apply(db::DataBox<DbTagsList>& box,
202  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
204  const ArrayIndex& /*array_index*/, ActionList /*meta*/,
205  const ParallelComponent* const /*meta*/) noexcept {
206  using compute_tags =
207  tmpl::append<face_tags<::Tags::InternalDirections<dim>>,
208  face_tags<::Tags::BoundaryDirectionsInterior<dim>>,
209  exterior_face_tags>;
210  return std::make_tuple(
212  db::AddSimpleTags<>, compute_tags>(
213  InitializeInterfaces_detail::InitExteriorVarsImpl<
214  AddExteriorVariables, Metavariables>::apply(std::move(box))));
215  }
216 };
217 } // namespace Actions
218 } // namespace dg
Derived tag for representing a compute item which acts on Tags on an interface. Can be retrieved usin...
Definition: InterfaceComputeTags.hpp:117
Defines class tuples::TaggedTuple.
Normalizes the (co)vector represented by Tag.
Definition: Magnitude.hpp:118
Definition: ConservativeSystem.hpp:34
The unnormalized face normal one form.
Definition: FaceNormal.hpp:69
tmpl::list< Tags... > exterior_compute_tags
Compute tags on the exterior side of the faces of the element.
Definition: InitializeInterfaces.hpp:47
Direction to an interface
Definition: Tags.hpp:299
Definition: ApplyBoundaryFluxesLocalTimeStepping.hpp:33
Computes the coordinates in the frame Frame on the faces defined by Direction. Intended to be prefixe...
Definition: InterfaceComputeTags.hpp:222
Contains functions that forward to Charm++ parallel functions.
Definition: Abort.hpp:13
Definition: FaceNormal.hpp:75
auto merge_into_databox(db::DataBox< DbTagsList > &&box, Args &&... args) noexcept
Add tags that are not yet in the DataBox.
Definition: MergeIntoDataBox.hpp:132
Computes the VolumeDim-1 dimensional mesh on an interface from the volume mesh. Tags::InterfaceComput...
Definition: InterfaceComputeTags.hpp:205
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:273
Defines classes and functions used for manipulating DataBox&#39;s.
tmpl::list< Tags... > slice_tags_to_exterior
Tags that are to be sliced to the exterior side of the faces of the element
Definition: InitializeInterfaces.hpp:37
tmpl::flatten< tmpl::list< Tags... > > AddSimpleTags
List of Tags to add to the DataBox.
Definition: DataBox.hpp:1222
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
Derived tag for representing a compute item which slices a Tag containing a Tensor or a Variables fro...
Definition: InterfaceComputeTags.hpp:156
Definition: DataBoxTag.hpp:29
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:135
Declares function unnormalized_face_normal.
constexpr auto apply(F &&f, const DataBox< BoxTags > &box, Args &&... args) noexcept
Apply the invokable f with argument Tags TagsList from DataBox box
Definition: DataBox.hpp:1623
The Element associated with the DataBox.
Definition: Tags.hpp:108
const auto & get(const DataBox< TagList > &box) noexcept
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:1206
Wraps the template metaprogramming library used (brigand)
typename DataBox_detail::item_type_impl< TagList, Tag >::type item_type
Get the type that can be written to the Tag. If it is a base tag then a TagList must be passed as a s...
Definition: DataBoxTag.hpp:461
Defines tags related to domain quantities.
tmpl::list< Tags... > slice_tags_to_face
Tags that are to be sliced to the faces of the element
Definition: InitializeInterfaces.hpp:32
tmpl::list< Tags... > face_compute_tags
Compute tags on the faces of the element.
Definition: InitializeInterfaces.hpp:42
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
The set of directions which correspond to external boundaries. To be used to represent data which exi...
Definition: Tags.hpp:223
Tag which is either a SimpleTag for quantities on an interface, base tag to a compute item which acts...
Definition: Tags.hpp:263
Initialize items related to the interfaces between Elements and on external boundaries.
Definition: InitializeInterfaces.hpp:140
Definition: ComputeTimeDerivative.hpp:28