Bembel
 
Loading...
Searching...
No Matches
ElementTreeNode.hpp
1// This file is part of Bembel, the higher order C++ boundary element library.
2//
3// Copyright (C) 2022 see <http://www.bembel.eu>
4//
5// It was written as part of a cooperation of J. Doelz, H. Harbrecht, S. Kurz,
6// M. Multerer, S. Schoeps, and F. Wolf at Technische Universitaet Darmstadt,
7// Universitaet Basel, and Universita della Svizzera italiana, Lugano. This
8// source code is subject to the GNU General Public License version 3 and
9// provided WITHOUT ANY WARRANTY, see <http://www.bembel.eu> for further
10// information.
11
12#ifndef BEMBEL_SRC_CLUSTERTREE_ELEMENTTREENODE_HPP_
13#define BEMBEL_SRC_CLUSTERTREE_ELEMENTTREENODE_HPP_
14
15namespace Bembel {
16
22 public:
29 using iterator_category = std::forward_iterator_tag;
30 using difference_type = std::ptrdiff_t;
32 using pointer = value_type *;
33 using reference = value_type &;
34
38 explicit const_iterator(pointer ptr) : m_ptr(ptr) {}
39
43 reference operator*() const { return *m_ptr; }
47 const pointer operator->() const { return m_ptr; }
48
53 m_ptr = m_ptr->next_;
54 return *this;
55 }
56
61 const_iterator tmp = *this;
62 ++(*this);
63 return tmp;
64 }
65
69 friend bool operator==(const const_iterator &a, const const_iterator &b) {
70 return a.m_ptr == b.m_ptr;
71 }
75 friend bool operator!=(const const_iterator &a, const const_iterator &b) {
76 return a.m_ptr != b.m_ptr;
77 }
78
79 private:
80 pointer m_ptr;
81 };
85
89 : prev_(nullptr),
90 next_(nullptr),
91 id_(-1),
92 level_(-1),
93 patch_(-1),
94 radius_(std::numeric_limits<double>::infinity()) {
95 midpoint_ << 0., 0., 0.;
96 llc_ << 0., 0.;
97 }
102 midpoint_.swap(other.midpoint_);
103 llc_.swap(other.llc_);
104 vertices_ = std::move(other.vertices_);
105 radius_ = other.radius_;
106 id_ = other.id_;
107 patch_ = other.patch_;
108 sons_ = std::move(other.sons_);
109 adjcents_ = std::move(other.adjcents_);
110 }
111
135
138 void print() const {
139 std::cout << "{" << std::endl;
140 std::cout << "midpoint: " << midpoint_.transpose() << std::endl;
141 std::cout << "llc: " << llc_.transpose() << std::endl;
142 std::cout << "p s n: " << prev_ << " " << this << " " << next_
143 << std::endl;
144 std::cout << "neighbours: ";
145 for (auto i = 0; i < adjcents_.size(); ++i)
146 std::cout << adjcents_[i] << " ";
147 std::cout << std::endl;
148 std::cout << "vertices: ";
149 for (auto i = 0; i < vertices_.size(); ++i)
150 std::cout << vertices_[i] << " ";
151 std::cout << std::endl;
152 std::cout << "radius: " << radius_ << std::endl;
153 std::cout << "id: " << id_ << std::endl;
154 std::cout << "level: " << level_ << std::endl;
155 std::cout << "patch: " << patch_ << std::endl;
156 std::cout << "}" << std::endl;
157 return;
158 }
160
170 Eigen::Vector2d mapToReferenceElement(const Eigen::Vector2d &in) const {
171 Eigen::Vector2d out = (in - llc_) / get_h();
172 assert(out(0) >= 0. && out(0) <= 1. && out(1) >= 0. && out(1) <= 1.);
173 return out;
174 }
176
181 Eigen::Vector2d referenceMidpoint() const {
182 return llc_ + Eigen::Vector2d(0.5, 0.5) * get_h();
183 }
187
193 double get_h() const { return double(1) / double(1 << level_); }
195
200 int get_level() const { return level_; }
202
207 const ElementTreeNode &front() const {
208 const ElementTreeNode *ptr = this;
209 while (ptr->sons_.size()) ptr = std::addressof(ptr->sons_.front());
210 return *ptr;
211 }
213
218 const ElementTreeNode &back() const {
219 const ElementTreeNode *ptr = this;
220 while (ptr->sons_.size()) ptr = std::addressof(ptr->sons_.back());
221 return *ptr;
222 }
224
232 const ElementTreeNode &el = this->front();
233 return const_iterator(const_cast<ElementTreeNode *>(std::addressof(el)));
234 }
236
243 const ElementTreeNode &el = this->back();
244 return const_iterator(const_cast<ElementTreeNode *>(el.next_));
245 }
247
253 const_iterator begin() const { return cbegin(); }
255
262 return cend();
263 }
267 std::vector<ElementTreeNode> sons_;
268 std::vector<ElementTreeNode *> adjcents_;
269 std::vector<int> vertices_;
270 Eigen::Vector3d midpoint_;
271 Eigen::Vector2d llc_;
273 ElementTreeNode *next_;
274 double radius_;
275 int id_;
276 int level_;
277 int patch_;
278};
279} // namespace Bembel
280#endif // BEMBEL_SRC_CLUSTERTREE_ELEMENTTREENODE_HPP_
The ElementTreeNode corresponds to an element in the element tree.
int id_
radius of the element
const_iterator cend() const
Returns an iterator pointing to the element in the sequence after this ElementTreeNode.
int level_
element id with respect to the level
ElementTreeNode & operator=(const ElementTreeNode &other)=delete
Copy assignment operator (deleted).
const ElementTreeNode & front() const
Returns a const reference to the first son if any or itself.
ElementTreeNode(const ElementTreeNode &other)=delete
Copy constructor (deleted).
const_iterator begin() const
Returns an iterator pointing to the element in the sequence before this ElementTreeNodes.
int get_level() const
Get the level of refinement of the element.
std::vector< int > vertices_
neighbouring elements indices
void print() const
methods
Eigen::Vector2d llc_
midpoint of the element
ElementTreeNode(ElementTreeNode &&other) noexcept
Move constructor.
const_iterator cbegin() const
Returns an iterator pointing to the element in the sequence before this ElementTreeNodes.
ElementTreeNode * prev_
lower left corner on [0,1]^2
ElementTreeNode() noexcept
constructors
Eigen::Vector3d midpoint_
indices of the vertices
Eigen::Vector2d mapToReferenceElement(const Eigen::Vector2d &in) const
Maps a point in the reference domain of a patch to the reference element of this element.
int patch_
level of the element
double get_h() const
getter
std::vector< ElementTreeNode * > adjcents_
children
Eigen::Vector2d referenceMidpoint() const
Get the midpoint of this element with respect to the patch.
std::vector< ElementTreeNode > sons_
member variables
const_iterator end() const
Returns an iterator pointing to the element in the sequence after this ElementTreeNode.
ElementTreeNode & operator=(ElementTreeNode &&other)=delete
Move assignment operator (deleted).
const ElementTreeNode & back() const
Returns a const reference to the last son if any or itself.
Routines for the evalutation of pointwise errors.
constexpr int getFunctionSpaceOutputDimension()
iterator struct for element tree nodes. They may be used to iterator over the elements in a cluster....
const_iterator operator++(int)
Postfix increment.
reference operator*() const
Accesses the pointed-to element.
friend bool operator!=(const const_iterator &a, const const_iterator &b)
Compares the underlying iterators.
const_iterator & operator++()
Prefix increment.
const pointer operator->() const
Accesses the pointed-to element.
const_iterator(pointer ptr)
Constructs a new iterator.
friend bool operator==(const const_iterator &a, const const_iterator &b)
Compares the underlying iterators.