SimpleBoundaryData.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  private:
39  TemporalId temporal_id_{};
40  boost::optional<LocalVars> local_data_{};
41  boost::optional<RemoteVars> remote_data_{};
42 };
43 
44 template <typename TemporalId, typename LocalVars, typename RemoteVars>
46  TemporalId temporal_id, LocalVars vars) noexcept {
47  ASSERT(not local_data_, "Already received local data.");
48  ASSERT(not remote_data_ or temporal_id == temporal_id_,
49  "Received local data at " << temporal_id
50  << ", but already have remote data at " << temporal_id_);
51  temporal_id_ = std::move(temporal_id);
52  local_data_ = std::move(vars);
53 }
54 
55 template <typename TemporalId, typename LocalVars, typename RemoteVars>
57  TemporalId temporal_id, RemoteVars vars) noexcept {
58  ASSERT(not remote_data_, "Already received remote data.");
59  ASSERT(not local_data_ or temporal_id == temporal_id_,
60  "Received remote data at " << temporal_id
61  << ", but already have local data at " << temporal_id_);
62  temporal_id_ = std::move(temporal_id);
63  remote_data_ = std::move(vars);
64 }
65 
66 template <typename TemporalId, typename LocalVars, typename RemoteVars>
69  ASSERT(local_data_ and remote_data_,
70  "Tried to extract boundary data, but do not have "
71  << (local_data_ ? "remote" : remote_data_ ? "local" : "any")
72  << " data.");
73  const auto result =
74  std::make_pair(std::move(*local_data_), std::move(*remote_data_));
75  local_data_ = boost::none;
76  remote_data_ = boost::none;
77  return result;
78 }
79 
80 template <typename TemporalId, typename LocalVars, typename RemoteVars>
82  PUP::er& p) noexcept {
83  p | temporal_id_;
84  p | local_data_;
85  p | remote_data_;
86 }
87 
88 } // namespace dg
Storage of boundary data on two sides of a mortar.
Definition: SimpleBoundaryData.hpp:23
std::pair< LocalVars, RemoteVars > extract() noexcept
Return the inserted data and reset the state to empty.
Definition: SimpleBoundaryData.hpp:68
Definition: InitializeElement.hpp:63
void local_insert(TemporalId temporal_id, LocalVars vars) noexcept
Add a value. This function must be called once between calls to extract.
Definition: SimpleBoundaryData.hpp:45
#define ASSERT(a, m)
Assert that an expression should be true.
Definition: Assert.hpp:49
Defines helper functions for working with boost.
Defines macro ASSERT.
void remote_insert(TemporalId temporal_id, RemoteVars vars) noexcept
Add a value. This function must be called once between calls to extract.
Definition: SimpleBoundaryData.hpp:56