bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
mesh_topology.h
Go to the documentation of this file.
1#ifndef MESH_TOPOLOGY_H
2#define MESH_TOPOLOGY_H
3
4#include "bitrl/bitrl_types.h"
7
8#include <vector>
9
10namespace bitrl
11{
12namespace utils
13{
14namespace geom
15{
16
17template <int spacedim> class Element;
18template <int spacedim, int topodim> class FaceElement;
19template <int dim> class Node;
20
35template <int spacedim> class MeshTopology
36{
37
38 public:
41
44
45 typedef std::vector<MeshConnectivity>::iterator element_connectivity_iterator;
46
49
52
53 typedef typename std::vector<Node<spacedim> *>::iterator node_iterator;
54 typedef typename std::vector<Node<spacedim> *>::const_iterator const_node_iterator;
55
56 typedef typename std::vector<Element<spacedim> *>::iterator element_iterator;
57 typedef typename std::vector<Element<spacedim> *>::const_iterator const_element_iterator;
58
59 typedef typename std::vector<edge_ptr_t>::iterator edge_iterator;
60 typedef typename std::vector<edge_ptr_t>::const_iterator const_edge_iterator;
61
62 typedef typename std::vector<face_ptr_t>::iterator face_iterator;
63 typedef typename std::vector<face_ptr_t>::const_iterator const_face_iterator;
64
68 void reserve_n_nodes(uint_t n) { nodes_.reserve(n); }
69
73 void reserve_n_elements(uint_t n) { elements_.reserve(n); }
74
78 void reserve_n_edges(uint_t n) { edges_.reserve(n); }
79
84
89
94
99
104
109
114
119
124
128 void clear_topology();
129
133 uint_t n_nodes() const { return nodes_.size(); }
134
138 uint_t n_elements() const { return elements_.size(); }
139
143 uint_t n_edges() const { return edges_.size(); }
144
148 uint_t n_faces() const;
149
154
158 const Node<spacedim> *node(uint_t i) const;
159
164
168 const Element<spacedim> *element(uint_t i) const;
169
174
179
183 void faces(const MeshConnectivity &faces_idx, std::vector<cface_ptr_t> &faces_ptr) const;
184
185 node_iterator nodes_begin() { return nodes_.begin(); }
186 node_iterator nodes_end() { return nodes_.end(); }
187
188 const_node_iterator nodes_begin() const { return nodes_.begin(); }
189 const_node_iterator nodes_end() const { return nodes_.end(); }
190
191 element_iterator elements_begin() { return elements_.begin(); }
192 element_iterator elements_end() { return elements_.end(); }
193
194 const_element_iterator elements_begin() const { return elements_.begin(); }
195 const_element_iterator elements_end() const { return elements_.end(); }
196
199
202
205
208
209 private:
210 std::vector<Node<spacedim> *> nodes_;
211 std::vector<edge_ptr_t> edges_;
212 std::vector<face_ptr_t> faces_;
213 std::vector<Element<spacedim> *> elements_;
214
219 template <typename T, typename C> T *add_entity(T *t, C &c);
220};
221
222template <int spacedim>
223inline MeshTopology<spacedim>::MeshTopology() : nodes_(), elements_(), edges_(), faces_()
224{
225}
226
227template <int spacedim> inline Node<spacedim> *MeshTopology<spacedim>::node(uint_t i)
228{
229
230 if (i >= nodes_.size())
231 {
232 throw std::logic_error("Invalid index: " + std::to_string(i) + " not in [0, " +
233 std::to_string(nodes_.size()));
234 }
235
236 return nodes_[i];
237}
238
239template <int spacedim> inline const Node<spacedim> *MeshTopology<spacedim>::node(uint_t i) const
240{
241
242 if (i >= nodes_.size())
243 {
244 throw std::logic_error("Invalid index: " + std::to_string(i) + " not in [0, " +
245 std::to_string(nodes_.size()));
246 }
247
248 return nodes_[i];
249}
250
252{
253
254 if (i >= nodes_.size())
255 {
256 throw std::logic_error("Invalid index: " + std::to_string(i) + " not in [0, " +
257 std::to_string(elements_.size()));
258 }
259
260 return elements_[i];
261}
262
263template <int spacedim>
265{
266
267 if (i >= nodes_.size())
268 {
269 throw std::logic_error("Invalid index: " + std::to_string(i) + " not in [0, " +
270 std::to_string(elements_.size()));
271 }
272
273 return elements_[i];
274}
275
276template <int spacedim>
278{
279 return edges_.begin();
280}
281
282template <int spacedim>
284{
285 return edges_.end();
286}
287
288template <int spacedim>
291{
292 return edges_.begin();
293}
294
295template <int spacedim>
298{
299 return edges_.end();
300}
301
302template <int spacedim>
304{
305 return faces_.begin();
306}
307
309{
310 return edges_.begin();
311}
312
313template <int spacedim>
315{
316 return faces_.end();
317}
318
320{
321 return edges_.end();
322}
323
324template <int spacedim>
327{
328 return faces_.begin();
329}
330
332{
333 return edges_.begin();
334}
335
336template <int spacedim>
339{
340 return faces_.end();
341}
342
344{
345 return edges_.end();
346}
347
348template <int spacedim> inline void MeshTopology<spacedim>::reserve_n_faces(uint_t n)
349{
350 faces_.reserve(n);
351}
352
353template <> inline void MeshTopology<2>::reserve_n_faces(uint_t n) { edges_.reserve(n); }
354
355template <int spacedim> inline uint_t MeshTopology<spacedim>::n_faces() const
356{
357 return faces_.size();
358}
359
360template <> inline uint_t MeshTopology<2>::n_faces() const { return edges_.size(); }
361
362} // namespace geom
363} // namespace utils
364} // namespace bitrl
365#endif
Wraps the notion of an element.
Definition element.h:30
MeshConnectivity class stores the various connectivities for a mesh object.
Definition mesh_connectivity.h:21
Definition mesh_topology.h:36
void clear_topology_elements()
delete the elements of the topology
Definition mesh_topology.cpp:78
void reserve_n_faces(uint_t n)
reserve memory for n edges
Definition mesh_topology.h:348
std::vector< edge_ptr_t >::const_iterator const_edge_iterator
Definition mesh_topology.h:60
node_iterator nodes_end()
Definition mesh_topology.h:186
element_traits< Element< spacedim > >::cface_ptr_t cface_ptr_t
Definition mesh_topology.h:51
edge_ptr_t add_edge(edge_ptr_t edge)
add a new edge in the mesh and get back the pointer
void clear_topology_edges()
delete the edges of the topology
element_iterator elements_end()
Definition mesh_topology.h:192
uint_t n_edges() const
get the number of edges in the mesh
Definition mesh_topology.h:143
element_traits< Element< spacedim > >::cedge_ptr_t cedge_ptr_t
Definition mesh_topology.h:50
Element< spacedim > * add_element(Element< spacedim > *e)
add a new element in the mesh and get back the pointer
Definition mesh_topology.cpp:57
const_element_iterator elements_end() const
Definition mesh_topology.h:195
MeshTopology()
Constructor.
Definition mesh_topology.h:223
const_element_iterator elements_begin() const
Definition mesh_topology.h:194
element_iterator elements_begin()
Definition mesh_topology.h:191
std::vector< Element< spacedim > * >::const_iterator const_element_iterator
Definition mesh_topology.h:57
edge_iterator edges_begin()
Definition mesh_topology.h:277
std::vector< Element< spacedim > * >::iterator element_iterator
Definition mesh_topology.h:56
void clear_topology()
clear the topology
Definition mesh_topology.cpp:94
face_ptr_t face(uint_t f)
Definition mesh_topology.cpp:103
element_traits< Element< spacedim > >::face_ptr_t face_ptr_t
Definition mesh_topology.h:48
node_iterator nodes_begin()
Definition mesh_topology.h:185
const_node_iterator nodes_begin() const
Definition mesh_topology.h:188
void clear_topology_faces()
delete the faces of the topology
face_iterator faces_begin()
Definition mesh_topology.h:303
Node< spacedim > * node(uint_t i)
read/write access to the i-th node of the mesh
Definition mesh_topology.h:227
std::vector< face_ptr_t >::iterator face_iterator
Definition mesh_topology.h:62
std::vector< edge_ptr_t >::iterator edge_iterator
Definition mesh_topology.h:59
element_traits< Element< spacedim > >::edge_ptr_t edge_ptr_t
Definition mesh_topology.h:47
uint_t n_faces() const
get the number of edges in the mesh
Definition mesh_topology.h:355
Node< spacedim > * add_node(Node< spacedim > *n)
add a new node to the mesh and get back the pointer
Definition mesh_topology.cpp:52
std::vector< Node< spacedim > * >::const_iterator const_node_iterator
Definition mesh_topology.h:54
void reserve_n_nodes(uint_t n)
reserve memory for n nodes
Definition mesh_topology.h:68
face_ptr_t add_face(face_ptr_t face)
add a new face in the mesh and get back the pointer
void reserve_n_elements(uint_t n)
reserve memory for n elements
Definition mesh_topology.h:73
void clear_topology_nodes()
delete the nodes of the topology
Definition mesh_topology.cpp:62
std::vector< face_ptr_t >::const_iterator const_face_iterator
Definition mesh_topology.h:63
uint_t n_elements() const
get the number of elements in the mesh
Definition mesh_topology.h:138
void reserve_n_edges(uint_t n)
reserve memory for n edges
Definition mesh_topology.h:78
std::vector< Node< spacedim > * >::iterator node_iterator
Definition mesh_topology.h:53
const_node_iterator nodes_end() const
Definition mesh_topology.h:189
Element< spacedim > * element(uint_t i)
read/write access to the i-th element of the mesh
Definition mesh_topology.h:251
std::vector< MeshConnectivity >::iterator element_connectivity_iterator
Definition mesh_topology.h:45
uint_t n_nodes() const
get the number of nodes in the mesh
Definition mesh_topology.h:133
void faces(const MeshConnectivity &faces_idx, std::vector< cface_ptr_t > &faces_ptr) const
~MeshTopology()
Constructor.
Definition mesh_topology.cpp:50
face_iterator faces_end()
Definition mesh_topology.h:314
edge_iterator edges_end()
Definition mesh_topology.h:283
Wraps the notion of a node. A node is simply a point in dim-space that can hold dofs.
Definition node.h:24
OutT resolve(const std::string &name, const std::map< std::string, std::any > &input)
Definition std_map_utils.h:25
Definition bitrl_consts.h:14
std::size_t uint_t
uint_t
Definition bitrl_types.h:43
Definition element_traits.h:16