Mortars.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <boost/functional/hash.hpp>
8 #include <cstddef>
9 #include <optional>
10 #include <tuple>
11 #include <unordered_map>
12 #include <utility>
13 #include <vector>
14 
22 #include "Domain/Structure/OrientationMap.hpp"
23 #include "Domain/Tags.hpp"
24 #include "Evolution/DiscontinuousGalerkin/Initialization/QuadratureTag.hpp"
25 #include "Evolution/DiscontinuousGalerkin/MortarData.hpp"
26 #include "Evolution/DiscontinuousGalerkin/MortarTags.hpp"
27 #include "Evolution/DiscontinuousGalerkin/NormalVectorTags.hpp"
29 #include "ParallelAlgorithms/Initialization/MutateAssign.hpp"
30 #include "Time/BoundaryHistory.hpp"
31 #include "Time/Tags.hpp"
32 #include "Time/TimeStepId.hpp"
33 #include "Utilities/TMPL.hpp"
34 
35 /// \cond
36 namespace Parallel {
37 template <typename Metavariables>
38 class GlobalCache;
39 } // namespace Parallel
40 namespace tuples {
41 template <class... Tags>
42 class TaggedTuple;
43 } // namespace tuples
44 /// \endcond
45 
47 namespace detail {
48 template <size_t Dim>
52  boost::hash<std::pair<Direction<Dim>, ElementId<Dim>>>>,
54  boost::hash<std::pair<Direction<Dim>, ElementId<Dim>>>>,
57  boost::hash<std::pair<Direction<Dim>, ElementId<Dim>>>>,
59  boost::hash<std::pair<Direction<Dim>, ElementId<Dim>>>>,
60  DirectionMap<Dim, std::optional<Variables<tmpl::list<
63 mortars_apply_impl(const std::vector<std::array<size_t, Dim>>& initial_extents,
64  Spectral::Quadrature quadrature, const Element<Dim>& element,
65  const TimeStepId& next_temporal_id,
66  const Mesh<Dim>& volume_mesh) noexcept;
67 } // namespace detail
68 
69 /*!
70  * \brief Initialize mortars between elements for exchanging boundary correction
71  * terms.
72  *
73  * Uses:
74  * - DataBox:
75  * - `Tags::Element<Dim>`
76  * - `Tags::Mesh<Dim>`
77  * - `BoundaryScheme::receive_temporal_id`
78  *
79  * DataBox changes:
80  * - Adds:
81  * - `Tags::MortarData<Dim>`
82  * - `Tags::MortarMesh<Dim>`
83  * - `Tags::MortarSize<Dim>`
84  * - `Tags::MortarNextTemporalId<Dim>`
85  * - `evolution::dg::Tags::NormalCovectorAndMagnitude<Dim>`
86  * - Removes: nothing
87  * - Modifies: nothing
88  */
89 template <size_t Dim, typename System>
90 struct Mortars {
92 
93  template <typename MappedType>
95 
96  public:
97  using initialization_tags = tmpl::list<::domain::Tags::InitialExtents<Dim>,
99 
100  using simple_tags = tmpl::list<
105  Dim, typename db::add_tag_prefix<
106  ::Tags::dt, typename System::variables_tag>::type>>;
107  using compute_tags = tmpl::list<>;
108 
109  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
110  typename ArrayIndex, typename ActionList,
111  typename ParallelComponent>
112  static auto apply(db::DataBox<DbTagsList>& box,
113  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
114  const Parallel::GlobalCache<Metavariables>& /*cache*/,
115  const ArrayIndex& /*array_index*/, ActionList /*meta*/,
116  const ParallelComponent* const /*meta*/) noexcept {
118  db::DataBox<DbTagsList>>) {
119  auto [mortar_data, mortar_meshes, mortar_sizes, mortar_next_temporal_ids,
120  normal_covector_quantities] =
121  detail::mortars_apply_impl(
123  db::get<evolution::dg::Tags::Quadrature>(box),
127  typename Tags::MortarDataHistory<
128  Dim, typename db::add_tag_prefix<
129  ::Tags::dt, typename System::variables_tag>::type>::type
130  boundary_data_history{};
131  if (Metavariables::local_time_stepping) {
132  for (const auto& mortar_id_and_data : mortar_data) {
133  // default initialize data
134  boundary_data_history[mortar_id_and_data.first];
135  }
136  }
137  ::Initialization::mutate_assign<simple_tags>(
138  make_not_null(&box), std::move(mortar_data), std::move(mortar_meshes),
139  std::move(mortar_sizes), std::move(mortar_next_temporal_ids),
140  std::move(normal_covector_quantities),
141  std::move(boundary_data_history));
142  return std::make_tuple(std::move(box));
143  } else {
144  ERROR(
145  "Missing a tag in the DataBox. Did you forget to terminate the "
146  "phase after removing options? The missing tag is "
147  "'domain::Tags::InitialExtents<Dim>'.");
148  return std::forward_as_tuple(std::move(box));
149  }
150  }
151 };
152 } // namespace evolution::dg::Initialization
DataBoxTag.hpp
utility
evolution::dg::Tags::Quadrature
The quadrature points to use initially.
Definition: QuadratureTag.hpp:29
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
std::pair
db::tag_is_retrievable_v
constexpr bool tag_is_retrievable_v
Definition: DataBox.hpp:61
evolution::dg::Tags::NormalCovectorAndMagnitude
The normal covector and its magnitude for all internal faces of an element.
Definition: NormalVectorTags.hpp:35
Tags.hpp
vector
domain::Tags::Element
Definition: Tags.hpp:97
db::add_tag_prefix
typename detail::add_tag_prefix_impl< Prefix, Tag, Args... >::type add_tag_prefix
Definition: PrefixHelpers.hpp:51
domain::Tags::Mesh
The computational grid of the Element in the DataBox.
Definition: Tags.hpp:107
evolution::dg::Initialization
Functionality for initializing the discontinuous Galerkin to evolve hyperbolic partial differential e...
Definition: Mortars.hpp:46
tuple
db::get
const auto & get(const DataBox< TagList > &box) noexcept
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:791
Tags::Next
Prefix indicating the value a quantity will take on the next iteration of the algorithm.
Definition: Prefixes.hpp:118
Element
Definition: Element.hpp:29
ElementId< Dim >
ERROR
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:37
evolution::dg::MortarData
Data on the mortar used to compute the boundary correction for the DG scheme.
Definition: MortarData.hpp:50
DataBox.hpp
evolution::dg::Initialization::Mortars
Initialize mortars between elements for exchanging boundary correction terms.
Definition: Mortars.hpp:90
cstddef
Neighbors.hpp
Spectral::MortarSize
ChildSize MortarSize
The portion of an element covered by a mortar.
Definition: Projection.hpp:23
domain::Tags::InitialExtents
Definition: Tags.hpp:70
array
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
evolution::dg::Tags::MagnitudeOfNormal
The magnitude of the unnormalized normal covector to the interface.
Definition: NormalVectorTags.hpp:18
evolution::dg::Tags::MortarMesh
Mesh on the mortars, indexed by (Direction, ElementId) pairs.
Definition: MortarTags.hpp:57
Spectral::Quadrature
Quadrature
The choice of quadrature method to compute integration weights.
Definition: Spectral.hpp:90
TimeStepId
Definition: TimeStepId.hpp:25
Variables.hpp
Element.hpp
Mesh
Holds the number of grid points, basis, and quadrature in each direction of the computational grid.
Definition: Mesh.hpp:49
DirectionMap
Definition: DirectionMap.hpp:15
TimeStepId.hpp
Tags::dt
Prefix indicating a time derivative.
Definition: Prefixes.hpp:29
evolution::dg::Tags::MortarData
Data on mortars, indexed by (Direction, ElementId) pairs.
Definition: MortarTags.hpp:27
optional
evolution::dg::Tags::NormalCovector
The normal covector to the interface.
Definition: NormalVectorTags.hpp:24
make_not_null
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion,...
Definition: Gsl.hpp:880
evolution::dg::Tags::MortarDataHistory
History of the data on mortars, indexed by (Direction, ElementId) pairs, and used by the linear multi...
Definition: MortarTags.hpp:43
Direction.hpp
evolution::dg::Tags::MortarNextTemporalId
The next temporal id at which to receive data on the specified mortar.
Definition: MortarTags.hpp:78
Prefixes.hpp
unordered_map
Parallel
Functionality for parallelization.
Definition: ElementReceiveInterpPoints.hpp:13
TMPL.hpp
Mesh.hpp
evolution::dg::Tags::MortarSize
Size of a mortar, relative to the element face. That is, the part of the face that it covers.
Definition: MortarTags.hpp:67