MortarData.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <optional>
8 #include <ostream>
9 #include <pup.h>
10 #include <utility>
11 #include <vector>
12 
13 #include "ErrorHandling/Assert.hpp"
15 #include "Parallel/PupStlCpp17.hpp"
16 #include "Time/TimeStepId.hpp"
17 
18 namespace evolution::dg {
19 /*!
20  * \brief Data on the mortar used to compute the boundary correction for the
21  * DG scheme.
22  *
23  * The class holds the local data that has been projected to the mortar as well
24  * as the neighbor data that has been projected to the mortar. The local and
25  * neighbor data is later used to compute the same unique boundary correction on
26  * the mortar for both elements. That is, the final boundary correction
27  * computation is done twice: once on each element touching the mortar. However,
28  * the computation is done in such a way that the results agree.
29  *
30  * In addition to the (type-erased) fields on both sides of the mortar, the face
31  * (not mortar!) mesh of the neighbor is stored. The mesh will be necessary
32  * when hybridizing DG with finite difference or finite volume schemes
33  * (DG-subcell).
34  *
35  * If the element and its neighbor have unaligned logical coordinate systems
36  * then the data is stored in the local logical coordinate's orientation
37  * (\f$\xi\f$ varies fastest). This means the action sending the data is
38  * responsible for reorienting the data on the mortar so it matches the
39  * neighbor's orientation.
40  *
41  * \tparam Dim the volume dimension of the mesh
42  */
43 template <size_t Dim>
44 class MortarData {
45  public:
46  /*!
47  * \brief Insert data onto the mortar.
48  *
49  * Exactly one local and neighbor insert call must be made between calls to
50  * `extract()`.
51  *
52  * The insert functions require that:
53  * - the data is inserted only once
54  * - the `TimeStepId` of the local and neighbor data are the same (this is
55  * only checked if the local/neighbor data was already inserted)
56  *
57  * \note it is not required that the number of grid points between the local
58  * and neighbor data be the same since one may be using FD/FV instead of DG
59  * and this switch is done locally in space and time in such a way that
60  * neighboring elements have no a priori knowledge about what well be
61  * received.
62  */
63  //@{
64  void insert_local_mortar_data(TimeStepId time_step_id,
65  Mesh<Dim - 1> local_interface_mesh,
66  std::vector<double> local_mortar_vars) noexcept;
67  void insert_neighbor_mortar_data(
68  TimeStepId time_step_id, Mesh<Dim - 1> neighbor_interface_mesh,
69  std::vector<double> neighbor_mortar_vars) noexcept;
70  //@}
71 
72  /// Return the inserted data and reset the state to empty.
73  ///
74  /// The first element is the local data while the second element is the
75  /// neighbor data.
76  auto extract() noexcept
79 
80  const TimeStepId& time_step_id() const noexcept { return time_step_id_; }
81 
82  auto local_mortar_data() const noexcept
83  -> const std::optional<std::pair<Mesh<Dim - 1>, std::vector<double>>>& {
84  return local_mortar_data_;
85  }
86 
87  auto neighbor_mortar_data() const noexcept
88  -> const std::optional<std::pair<Mesh<Dim - 1>, std::vector<double>>>& {
89  return neighbor_mortar_data_;
90  }
91 
92  // clang-tidy: google-runtime-references
93  void pup(PUP::er& p) noexcept; // NOLINT
94 
95  private:
96  TimeStepId time_step_id_{};
98  local_mortar_data_{};
100  neighbor_mortar_data_{};
101 };
102 
103 template <size_t Dim>
104 bool operator==(const MortarData<Dim>& lhs,
105  const MortarData<Dim>& rhs) noexcept;
106 template <size_t Dim>
107 bool operator!=(const MortarData<Dim>& lhs,
108  const MortarData<Dim>& rhs) noexcept;
109 } // namespace evolution::dg
evolution::dg::MortarData::insert_local_mortar_data
void insert_local_mortar_data(TimeStepId time_step_id, Mesh< Dim - 1 > local_interface_mesh, std::vector< double > local_mortar_vars) noexcept
Insert data onto the mortar.
Definition: MortarData.cpp:21
utility
std::pair
evolution::dg
Functionality for evolving hyperbolic partial differential equations using the discontinuous Galerkin...
Definition: ConservativeDuDt.hpp:22
vector
evolution::dg::MortarData
Data on the mortar used to compute the boundary correction for the DG scheme.
Definition: MortarData.hpp:44
cstddef
Assert.hpp
evolution::dg::MortarData::extract
auto extract() noexcept -> std::pair< std::pair< Mesh< Dim - 1 >, std::vector< double >>, std::pair< Mesh< Dim - 1 >, std::vector< double >>>
Return the inserted data and reset the state to empty.
Definition: MortarData.cpp:62
TimeStepId
Definition: TimeStepId.hpp:25
Mesh
Holds the number of grid points, basis, and quadrature in each direction of the computational grid.
Definition: Mesh.hpp:47
TimeStepId.hpp
optional
Mesh.hpp
ostream