Line data Source code
1 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/Structure/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 a host Element in a particular direction. 25 : /// 26 : /// \tparam VolumeDim the volume dimension. 27 : template <size_t VolumeDim> 28 1 : class Neighbors { 29 : public: 30 : /// Construct with the ids and orientation of the neighbors relative to the 31 : /// host. 32 : /// 33 : /// \param ids the ids of the neighbors. 34 : /// \param orientation This OrientationMap takes objects in the logical 35 : /// coordinate frame of the host Element and maps them to the logical 36 : /// coordinate frame of the neighbor Element. 37 1 : Neighbors(std::unordered_set<ElementId<VolumeDim>> ids, 38 : OrientationMap<VolumeDim> orientation); 39 : 40 : /// Default constructor for Charm++ serialization. 41 1 : Neighbors() = default; 42 0 : ~Neighbors() = default; 43 0 : Neighbors(const Neighbors<VolumeDim>& neighbor) = default; 44 0 : Neighbors(Neighbors<VolumeDim>&&) = default; 45 0 : Neighbors& operator=(const Neighbors& rhs) = default; 46 0 : Neighbors& operator=(Neighbors&&) = default; 47 : 48 0 : const std::unordered_set<ElementId<VolumeDim>>& ids() const { return ids_; } 49 : 50 0 : const OrientationMap<VolumeDim>& orientation() const { return orientation_; } 51 : 52 : /// Reset the ids of the neighbors. 53 1 : void set_ids_to(const std::unordered_set<ElementId<VolumeDim>> new_ids) { 54 : ids_ = std::move(new_ids); 55 : } 56 : 57 : /// Add ids of neighbors. 58 : /// Adding an existing neighbor is allowed. 59 1 : void add_ids(const std::unordered_set<ElementId<VolumeDim>>& additional_ids); 60 : 61 : /// Serialization for Charm++ 62 : // NOLINTNEXTLINE(google-runtime-references) 63 1 : void pup(PUP::er& p); 64 : 65 : /// The number of neighbors 66 1 : size_t size() const { return ids_.size(); } 67 : 68 0 : typename std::unordered_set<ElementId<VolumeDim>>::iterator begin() { 69 : return ids_.begin(); 70 : } 71 : 72 0 : typename std::unordered_set<ElementId<VolumeDim>>::iterator end() { 73 : return ids_.end(); 74 : } 75 : 76 0 : typename std::unordered_set<ElementId<VolumeDim>>::const_iterator begin() 77 : const { 78 : return ids_.begin(); 79 : } 80 : 81 0 : typename std::unordered_set<ElementId<VolumeDim>>::const_iterator end() 82 : const { 83 : return ids_.end(); 84 : } 85 : 86 0 : typename std::unordered_set<ElementId<VolumeDim>>::const_iterator cbegin() 87 : const { 88 : return ids_.begin(); 89 : } 90 : 91 0 : typename std::unordered_set<ElementId<VolumeDim>>::const_iterator cend() 92 : const { 93 : return ids_.end(); 94 : } 95 : 96 : private: 97 0 : std::unordered_set<ElementId<VolumeDim>> ids_; 98 0 : OrientationMap<VolumeDim> orientation_; 99 : }; 100 : 101 : /// Output operator for Neighborss. 102 : template <size_t VolumeDim> 103 1 : std::ostream& operator<<(std::ostream& os, const Neighbors<VolumeDim>& n); 104 : 105 : template <size_t VolumeDim> 106 0 : bool operator==(const Neighbors<VolumeDim>& lhs, 107 : const Neighbors<VolumeDim>& rhs); 108 : 109 : template <size_t VolumeDim> 110 0 : bool operator!=(const Neighbors<VolumeDim>& lhs, 111 : const Neighbors<VolumeDim>& rhs);