Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <ostream> 7 : #include <optional> 8 : #include <pup.h> // IWYU pragma: keep 9 : #include <utility> 10 : 11 : #include "Utilities/ErrorHandling/Assert.hpp" 12 : #include "Utilities/Serialization/PupStlCpp17.hpp" 13 : 14 : namespace dg { 15 : 16 : /// \ingroup DiscontinuousGalerkinGroup 17 : /// \brief Storage of boundary data on two sides of a mortar 18 : /// 19 : /// Typically, values are inserted into this container by the flux 20 : /// communication actions. 21 : template <typename TemporalId, typename LocalVars, typename RemoteVars> 22 1 : class SimpleMortarData { 23 : public: 24 0 : SimpleMortarData() = default; 25 0 : SimpleMortarData(const SimpleMortarData&) = default; 26 0 : SimpleMortarData(SimpleMortarData&&) = default; 27 0 : SimpleMortarData& operator=(const SimpleMortarData&) = default; 28 0 : SimpleMortarData& operator=(SimpleMortarData&&) = default; 29 0 : ~SimpleMortarData() = default; 30 : 31 : /// The argument is ignored. It exists for compatibility with 32 : /// BoundaryHistory. 33 1 : explicit SimpleMortarData(const size_t /*integration_order*/) {} 34 : 35 : /// These functions do nothing. They exist for compatibility with 36 : /// BoundaryHistory. 37 : /// @{ 38 1 : size_t integration_order() const { return 0; } 39 1 : void integration_order(const size_t /*integration_order*/) {} 40 : /// @} 41 : 42 : /// Add a value. This function must be called once between calls to 43 : /// extract. 44 : /// @{ 45 1 : void local_insert(TemporalId temporal_id, LocalVars vars); 46 1 : void remote_insert(TemporalId temporal_id, RemoteVars vars); 47 : /// @} 48 : 49 : /// Return the inserted data and reset the state to empty. 50 1 : std::pair<LocalVars, RemoteVars> extract(); 51 : 52 : // NOLINTNEXTLINE(google-runtime-references) 53 0 : void pup(PUP::er& p); 54 : 55 : /// Retrieve the local data at `temporal_id` 56 1 : const LocalVars& local_data(const TemporalId& temporal_id) const { 57 : ASSERT(local_data_, "Local data not available."); 58 : ASSERT(temporal_id == temporal_id_, 59 : "Only have local data at temporal_id " 60 : << temporal_id_ << ", but requesting at " << temporal_id); 61 : return *local_data_; 62 : }; 63 : 64 : /// Retrieve the remote data at `temporal_id` 65 1 : const RemoteVars& remote_data(const TemporalId& temporal_id) const { 66 : ASSERT(remote_data_, "Remote data not available."); 67 : ASSERT(temporal_id == temporal_id_, 68 : "Only have remote data at temporal_id " 69 : << temporal_id_ << ", but requesting at " << temporal_id); 70 : return *remote_data_; 71 : }; 72 : 73 : private: 74 0 : TemporalId temporal_id_{}; 75 0 : std::optional<LocalVars> local_data_{}; 76 0 : std::optional<RemoteVars> remote_data_{}; 77 : }; 78 : 79 : template <typename TemporalId, typename LocalVars, typename RemoteVars> 80 : void SimpleMortarData<TemporalId, LocalVars, RemoteVars>::local_insert( 81 : TemporalId temporal_id, LocalVars vars) { 82 : ASSERT(not local_data_.has_value(), "Already received local data."); 83 : ASSERT(not remote_data_.has_value() or temporal_id == temporal_id_, 84 : "Received local data at " << temporal_id 85 : << ", but already have remote data at " 86 : << temporal_id_); 87 : temporal_id_ = std::move(temporal_id); 88 : local_data_ = std::move(vars); 89 : } 90 : 91 : template <typename TemporalId, typename LocalVars, typename RemoteVars> 92 : void SimpleMortarData<TemporalId, LocalVars, RemoteVars>::remote_insert( 93 : TemporalId temporal_id, RemoteVars vars) { 94 : ASSERT(not remote_data_.has_value(), "Already received remote data."); 95 : ASSERT(not local_data_.has_value() or temporal_id == temporal_id_, 96 : "Received remote data at " << temporal_id 97 : << ", but already have local data at " 98 : << temporal_id_); 99 : temporal_id_ = std::move(temporal_id); 100 : remote_data_ = std::move(vars); 101 : } 102 : 103 : template <typename TemporalId, typename LocalVars, typename RemoteVars> 104 : std::pair<LocalVars, RemoteVars> 105 : SimpleMortarData<TemporalId, LocalVars, RemoteVars>::extract() { 106 : ASSERT(local_data_.has_value() and remote_data_.has_value(), 107 : "Tried to extract boundary data, but do not have " 108 : << (local_data_ ? "remote" : remote_data_ ? "local" : "any") 109 : << " data."); 110 : auto result = 111 : std::make_pair(std::move(*local_data_), std::move(*remote_data_)); 112 : local_data_ = std::nullopt; 113 : remote_data_ = std::nullopt; 114 : return result; 115 : } 116 : 117 : template <typename TemporalId, typename LocalVars, typename RemoteVars> 118 : void SimpleMortarData<TemporalId, LocalVars, RemoteVars>::pup(PUP::er& p) { 119 : p | temporal_id_; 120 : p | local_data_; 121 : p | remote_data_; 122 : } 123 : 124 : } // namespace dg