InterfaceActionHelpers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <unordered_map>
8 
10 #include "DataStructures/Tensor/EagerMath/Magnitude.hpp"
11 #include "Domain/Direction.hpp"
12 #include "Domain/FaceNormal.hpp"
13 #include "Domain/Mesh.hpp"
14 #include "Domain/Tags.hpp"
15 #include "NumericalAlgorithms/DiscontinuousGalerkin/FluxCommunicationTypes.hpp"
16 #include "NumericalAlgorithms/DiscontinuousGalerkin/MortarHelpers.hpp"
17 #include "NumericalAlgorithms/DiscontinuousGalerkin/Tags.hpp"
18 
19 namespace DgActions_detail {
20 template <typename Metavariables, typename DataBoxType, typename DirectionsTag,
21  typename NumericalFlux>
22 auto compute_packaged_data(
23  const DataBoxType& box,
25  const NumericalFlux& normal_dot_numerical_flux_computer,
26  const DirectionsTag /*meta*/, const Metavariables /*meta*/) noexcept ->
28  constexpr size_t volume_dim = Metavariables::system::volume_dim;
29 
30  using flux_comm_types = dg::FluxCommunicationTypes<Metavariables>;
31 
32  using package_arguments =
33  typename Metavariables::normal_dot_numerical_flux::type::argument_tags;
34 
35  const auto &face_mesh =
36  db::get<Tags::Interface<DirectionsTag, Tags::Mesh<volume_dim - 1>>>(box)
37  .at(direction);
38 
39  return db::apply<tmpl::transform<
40  package_arguments, tmpl::bind<Tags::Interface, DirectionsTag, tmpl::_1>>>(
41  [&face_mesh, &direction,
42  &normal_dot_numerical_flux_computer ](const auto&... args) noexcept {
43  typename flux_comm_types::PackagedData ret(
44  face_mesh.number_of_grid_points(), 0.0);
45  normal_dot_numerical_flux_computer.package_data(make_not_null(&ret),
46  args.at(direction)...);
47  return ret;
48  },
49  box);
50 }
51 
52 template <typename Metavariables, typename DataBoxType, typename DirectionsTag,
53  typename NumericalFlux>
54 auto compute_local_mortar_data(
55  const DataBoxType& box,
57  const NumericalFlux& normal_dot_numerical_flux_computer,
58  const DirectionsTag /*meta*/, const Metavariables /*meta*/) noexcept ->
60  constexpr size_t volume_dim = Metavariables::system::volume_dim;
61 
62  using flux_comm_types = dg::FluxCommunicationTypes<Metavariables>;
63 
64  using normal_dot_fluxes_tag =
65  Tags::Interface<DirectionsTag,
66  typename flux_comm_types::normal_dot_fluxes_tag>;
67 
68  const auto &face_mesh =
69  db::get<Tags::Interface<Tags::BoundaryDirectionsInterior<volume_dim>,
70  Tags::Mesh<volume_dim - 1>>>(box)
71  .at(direction);
72 
73  const auto packaged_data =
74  compute_packaged_data(box, direction, normal_dot_numerical_flux_computer,
75  DirectionsTag{}, Metavariables{});
76 
77  typename flux_comm_types::LocalData interface_data{};
78  interface_data.magnitude_of_face_normal = db::get<Tags::Interface<
79  DirectionsTag,
81  .at(direction);
82 
83  interface_data.mortar_data.initialize(face_mesh.number_of_grid_points());
84  interface_data.mortar_data.assign_subset(packaged_data);
85 
86  if (tmpl::size<typename flux_comm_types::LocalMortarData::tags_list>::value !=
87  tmpl::size<typename flux_comm_types::PackagedData::tags_list>::value) {
88  // The local fluxes were not (all) included in the packaged
89  // data, so we need to add them to the mortar data
90  // explicitly.
91  const auto &normal_dot_fluxes =
92  db::get<normal_dot_fluxes_tag>(box).at(direction);
93  interface_data.mortar_data.assign_subset(normal_dot_fluxes);
94  }
95 
96  return interface_data;
97 }
98 } // namespace DgActions_detail
Defines class template Direction.
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
The type of the data needed for the local part of the flux numerical flux computations. Contains the PackagedData, the normal fluxes, and MagnitudeOfFaceNormal.
Definition: FluxCommunicationTypes.hpp:60
A particular Side along a particular coordinate Axis.
Definition: Direction.hpp:23
Defines classes and functions used for manipulating DataBox&#39;s.
Definition: InterfaceActionHelpers.hpp:19
Types related to flux communication.
Definition: FluxCommunicationTypes.hpp:37
Defines the class template Mesh.
Declares function unnormalized_face_normal.
const auto & get(const DataBox< TagList > &box) noexcept
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:1211
The computational grid of the Element in the DataBox.
Definition: Tags.hpp:75
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, but it may be necessary to perform the conversion explicitly when type deduction is desired.
Definition: Gsl.hpp:863
Defines tags related to domain quantities.
The magnitude of a (co)vector.
Definition: Magnitude.hpp:53
Definition: SolvePoissonProblem.hpp:38
Variables< typename Metavariables::normal_dot_numerical_flux::type::package_tags > PackagedData
The type of the Variables sent to neighboring elements.
Definition: FluxCommunicationTypes.hpp:45
Tag which is either a SimpleTag for quantities on an interface, base tag to a compute item which acts...
Definition: Tags.hpp:217
constexpr T & at(std::array< T, N > &arr, Size index)
Retrieve a entry from a container, with checks in Debug mode that the index being retrieved is valid...
Definition: Gsl.hpp:124