SimpleMortarData.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <boost/none.hpp>
7 #include <boost/optional.hpp>
8 #include <ostream>
9 #include <pup.h> // IWYU pragma: keep
10 #include <utility>
11 
12 #include "ErrorHandling/Assert.hpp"
13 #include "Utilities/BoostHelpers.hpp" // IWYU pragma: keep
14 
15 namespace dg {
16 
17 /// \ingroup DiscontinuousGalerkinGroup
18 /// \brief Storage of boundary data on two sides of a mortar
19 ///
20 /// Typically, values are inserted into this container by the flux
21 /// communication actions.
22 template <typename TemporalId, typename LocalVars, typename RemoteVars>
24  public:
25  /// Add a value. This function must be called once between calls to
26  /// extract.
27  //@{
28  void local_insert(TemporalId temporal_id, LocalVars vars) noexcept;
29  void remote_insert(TemporalId temporal_id, RemoteVars vars) noexcept;
30  //@}
31 
32  /// Return the inserted data and reset the state to empty.
34 
35  // clang-tidy: google-runtime-references
36  void pup(PUP::er& p) noexcept; // NOLINT
37 
38  /// Retrieve the local data at `temporal_id`
39  const LocalVars& local_data(const TemporalId& temporal_id) const noexcept {
40  ASSERT(local_data_, "Local data not available.");
41  ASSERT(temporal_id == temporal_id_,
42  "Only have local data at temporal_id "
43  << temporal_id_ << ", but requesting at " << temporal_id);
44  return *local_data_;
45  };
46 
47  private:
48  TemporalId temporal_id_{};
49  boost::optional<LocalVars> local_data_{};
50  boost::optional<RemoteVars> remote_data_{};
51 };
52 
53 template <typename TemporalId, typename LocalVars, typename RemoteVars>
55  TemporalId temporal_id, LocalVars vars) noexcept {
56  ASSERT(not local_data_, "Already received local data.");
57  ASSERT(not remote_data_ or temporal_id == temporal_id_,
58  "Received local data at " << temporal_id
59  << ", but already have remote data at "
60  << temporal_id_);
61  temporal_id_ = std::move(temporal_id);
62  local_data_ = std::move(vars);
63 }
64 
65 template <typename TemporalId, typename LocalVars, typename RemoteVars>
67  TemporalId temporal_id, RemoteVars vars) noexcept {
68  ASSERT(not remote_data_, "Already received remote data.");
69  ASSERT(not local_data_ or temporal_id == temporal_id_,
70  "Received remote data at " << temporal_id
71  << ", but already have local data at "
72  << temporal_id_);
73  temporal_id_ = std::move(temporal_id);
74  remote_data_ = std::move(vars);
75 }
76 
77 template <typename TemporalId, typename LocalVars, typename RemoteVars>
80  ASSERT(local_data_ and remote_data_,
81  "Tried to extract boundary data, but do not have "
82  << (local_data_ ? "remote" : remote_data_ ? "local" : "any")
83  << " data.");
84  const auto result =
85  std::make_pair(std::move(*local_data_), std::move(*remote_data_));
86  local_data_ = boost::none;
87  remote_data_ = boost::none;
88  return result;
89 }
90 
91 template <typename TemporalId, typename LocalVars, typename RemoteVars>
93  PUP::er& p) noexcept {
94  p | temporal_id_;
95  p | local_data_;
96  p | remote_data_;
97 }
98 
99 } // namespace dg
Storage of boundary data on two sides of a mortar.
Definition: SimpleMortarData.hpp:23
Definition: ApplyBoundaryFluxesLocalTimeStepping.hpp:33
const LocalVars & local_data(const TemporalId &temporal_id) const noexcept
Retrieve the local data at temporal_id
Definition: SimpleMortarData.hpp:39
#define ASSERT(a, m)
Assert that an expression should be true.
Definition: Assert.hpp:51
void local_insert(TemporalId temporal_id, LocalVars vars) noexcept
Add a value. This function must be called once between calls to extract.
Definition: SimpleMortarData.hpp:54
Defines helper functions for working with boost.
std::pair< LocalVars, RemoteVars > extract() noexcept
Return the inserted data and reset the state to empty.
Definition: SimpleMortarData.hpp:79
void remote_insert(TemporalId temporal_id, RemoteVars vars) noexcept
Add a value. This function must be called once between calls to extract.
Definition: SimpleMortarData.hpp:66
Defines macro ASSERT.