Neighbors.hpp
Go to the documentation of this file.
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 /// \file
5 /// Defines class template Neighbors.
6 
7 #pragma once
8 
9 #include <cstddef>
10 #include <iosfwd>
11 #include <unordered_set>
12 
13 #include "Domain/OrientationMap.hpp"
14 
15 /// \cond
16 namespace PUP {
17 class er;
18 } // namespace PUP
19 template <size_t VolumeDim>
20 class ElementId;
21 /// \endcond
22 
23 /// \ingroup ComputationalDomainGroup
24 /// Information about the neighbors of an Element in a particular direction.
25 ///
26 /// \tparam VolumeDim the volume dimension.
27 template <size_t VolumeDim>
28 class Neighbors {
29  public:
30  /// Construct with the ids and orientation of the neighbors.
31  ///
32  /// \param ids the ids of the neighbors.
33  /// \param orientation the OrientationMap of the neighbors.
35  OrientationMap<VolumeDim> orientation) noexcept;
36 
37  /// Default constructor for Charm++ serialization.
38  Neighbors() = default;
39  ~Neighbors() = default;
40  Neighbors(const Neighbors<VolumeDim>& neighbor) = default;
41  Neighbors(Neighbors<VolumeDim>&&) noexcept = default;
42  Neighbors& operator=(const Neighbors& rhs) = default;
43  Neighbors& operator=(Neighbors&&) noexcept = default;
44 
45  const std::unordered_set<ElementId<VolumeDim>>& ids() const noexcept {
46  return ids_;
47  }
48 
49  const OrientationMap<VolumeDim>& orientation() const noexcept {
50  return orientation_;
51  }
52 
53  /// Reset the ids of the neighbors.
54  void set_ids_to(
55  const std::unordered_set<ElementId<VolumeDim>> new_ids) noexcept {
56  ids_ = std::move(new_ids);
57  }
58 
59  /// Add ids of neighbors.
60  /// Adding an existing neighbor is allowed.
61  void add_ids(
62  const std::unordered_set<ElementId<VolumeDim>>& additional_ids) noexcept;
63 
64  /// Serialization for Charm++
65  void pup(PUP::er& p) noexcept; // NOLINT
66 
67  /// The number of neighbors
68  size_t size() const noexcept { return ids_.size(); }
69 
70  typename std::unordered_set<ElementId<VolumeDim>>::iterator begin() noexcept {
71  return ids_.begin();
72  }
73 
74  typename std::unordered_set<ElementId<VolumeDim>>::iterator end() noexcept {
75  return ids_.end();
76  }
77 
78  typename std::unordered_set<ElementId<VolumeDim>>::const_iterator begin()
79  const noexcept {
80  return ids_.begin();
81  }
82 
83  typename std::unordered_set<ElementId<VolumeDim>>::const_iterator end() const
84  noexcept {
85  return ids_.end();
86  }
87 
88  typename std::unordered_set<ElementId<VolumeDim>>::const_iterator cbegin()
89  const noexcept {
90  return ids_.begin();
91  }
92 
93  typename std::unordered_set<ElementId<VolumeDim>>::const_iterator cend() const
94  noexcept {
95  return ids_.end();
96  }
97 
98  private:
100  OrientationMap<VolumeDim> orientation_;
101 };
102 
103 /// Output operator for Neighborss.
104 template <size_t VolumeDim>
106  const Neighbors<VolumeDim>& n) noexcept;
107 
108 template <size_t VolumeDim>
109 bool operator==(const Neighbors<VolumeDim>& lhs,
110  const Neighbors<VolumeDim>& rhs) noexcept;
111 
112 template <size_t VolumeDim>
113 bool operator!=(const Neighbors<VolumeDim>& lhs,
114  const Neighbors<VolumeDim>& rhs) noexcept;
Definition: Strahlkorper.hpp:14
An ElementId uniquely labels an Element. It is constructed from the BlockId of the Block to which the...
Definition: ElementId.hpp:36
void set_ids_to(const std::unordered_set< ElementId< VolumeDim >> new_ids) noexcept
Reset the ids of the neighbors.
Definition: Neighbors.hpp:54
std::ostream & operator<<(std::ostream &os, const Neighbors< VolumeDim > &n) noexcept
Output operator for Neighborss.
Definition: Neighbors.cpp:28
Information about the neighbors of an Element in a particular direction.
Definition: Neighbors.hpp:28
size_t size() const noexcept
The number of neighbors.
Definition: Neighbors.hpp:68