BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Vertex.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_CL_VERTEX_HPP
13#define BELFEM_CL_VERTEX_HPP
14
15#include "typedefs.hpp"
16#include "assert.hpp"
17#include "cl_Mesh_Basis.hpp"
18#include "Mesh_Enums.hpp"
19
20namespace belfem
21{
22 namespace mesh
23 {
24 // forward declarations for nodes and edges
25 class Node ;
26 class Element;
27 class Facet;
28 class Edge ;
29
30 class Vertex : public Basis
31 {
32 protected:
34 Node ** mNodes = nullptr ;
35
37 Edge ** mEdges = nullptr ;
38
40 Face ** mFaces = nullptr ;
41
43 Facet ** mFacets = nullptr ;
44
46 Element ** mElements = nullptr ;
47
49 uint8_t mNodeCounter = 0 ;
50 uint8_t mNodeCapacity = 0 ;
51
53 uint8_t mEdgeCounter = 0 ;
54 uint8_t mEdgeCapacity = 0 ;
55
57 uint8_t mFaceCounter = 0 ;
58 uint8_t mFaceCapacity = 0 ;
59
62 uint16_t mFacetCounter = 0 ;
63 uint16_t mFacetCapacity = 0 ;
64
66 uint8_t mElementCounter = 0 ;
67 uint8_t mElementCapacity = 0 ;
68
69//------------------------------------------------------------------------------
70 public:
71//------------------------------------------------------------------------------
72
73 Vertex();
74
75 ~Vertex() override;
76
77//------------------------------------------------------------------------------
78
83 entity_type() const override ;
84
85//------------------------------------------------------------------------------
86// nodes
87//------------------------------------------------------------------------------
88
89 void
91
92 void
94
95 void
96 allocate_node_container( const uint aCounter=0 );
97
98 void
99 add_node( Node * aNode );
100
101 void
102 insert_node( Node * aNode, const uint aIndex );
103
104 uint
105 number_of_nodes() const override ;
106
107 Node *
108 node( const uint aIndex ) override;
109
110 const Node *
111 node( const uint aIndex ) const override ;
112
113//------------------------------------------------------------------------------
114// edges
115//------------------------------------------------------------------------------
116
117 void
119
120 void
122
123 void
124 allocate_edge_container( const uint aCounter=0 );
125
126 void
127 add_edge( Edge * aEdge );
128
129 void
130 insert_edge( Edge * aEdge, const uint aIndex );
131
132 uint
133 number_of_edges() const override ;
134
135 Edge *
136 edge( const uint aIndex ) override;
137
138 const Edge *
139 edge( const uint aIndex ) const override ;
140
141//------------------------------------------------------------------------------
142// faces
143//------------------------------------------------------------------------------
144
145 void
147
148 void
150
151 void
152 allocate_face_container( const uint aCounter=0 );
153
154 void
155 add_face( Face * aFace );
156
157 uint
158 number_of_faces() const override ;
159
160 Face *
161 face( const uint aIndex ) override;
162
163 const Face *
164 face( const uint aIndex ) const override ;
165
166//------------------------------------------------------------------------------
167// facets
168//------------------------------------------------------------------------------
169
170 void
172
173 void
175
176 void
177 allocate_facet_container( const uint aNumFacets=0 );
178
179 void
180 add_facet( Facet * aFacet );
181
182 virtual uint
183 number_of_facets() const ;
184
185 virtual Facet *
186 facet( const uint aIndex );
187
188 virtual const Facet *
189 facet( const uint aIndex ) const ;
190
191//------------------------------------------------------------------------------
192// elements
193//------------------------------------------------------------------------------
194
195 void
196 reset_element_container() override;
197
198 void
200
201 void
202 allocate_element_container( const uint aCounter=0 );
203
204 void
205 add_element( Element * aElement );
206
207 uint
208 number_of_elements() const override ;
209
210 Element *
211 element( const uint aIndex ) override;
212
213 virtual const Element *
214 element( const uint aIndex ) const ;
215
216//------------------------------------------------------------------------------
217
218 virtual void
219 flag_nodes( const uint8_t aIndex = 0 );
220
221 virtual void
222 unflag_nodes( const uint8_t aIndex = 0 );
223
224//------------------------------------------------------------------------------
225 protected:
226//------------------------------------------------------------------------------
227
231 void
233
234//------------------------------------------------------------------------------
235
241 size_t
242 array_memory() const ;
243
244//------------------------------------------------------------------------------
245 };
246
247
248//------------------------------------------------------------------------------
249
250 inline void
252 {
253 BELFEM_ASSERT( mNodeCounter < 255, "Node counter overflow." );
254 ++mNodeCounter ;
255 }
256
257//------------------------------------------------------------------------------
258
259 inline void
261 {
262 BELFEM_ASSERT( mEdgeCounter < 255, "Edge counter overflow." );
263 ++mEdgeCounter ;
264 }
265
266//------------------------------------------------------------------------------
267
268 inline void
270 {
271 BELFEM_ASSERT( mFaceCounter < 255, "Face counter overflow." );
272 ++mFaceCounter ;
273 }
274
275//------------------------------------------------------------------------------
276
277 inline void
279 {
280 BELFEM_ASSERT( mFacetCounter < 65535, "Facet counter overflow." );
281 ++mFacetCounter ;
282 }
283
284//------------------------------------------------------------------------------
285
286 inline void
288 {
289 BELFEM_ASSERT( mElementCounter < 255, "Element counter overflow." );
291 }
292
293//------------------------------------------------------------------------------
294
295 inline uint
297 {
298 return mNodeCounter ;
299 }
300
301//------------------------------------------------------------------------------
302
303 inline size_t
305 {
306 size_t tMem = this->number_of_vertices() * sizeof( graph::Vertex * );
307
308 tMem += this->number_of_dofs() * sizeof( graph::Vertex * );
309
310 // sources and weights are parallel arrays with the same slot count
311 tMem += this->number_of_sources() * ( sizeof( Basis * ) + sizeof( real ) );
312
313 tMem += mNodeCapacity * sizeof( Node * );
314 tMem += mEdgeCapacity * sizeof( Edge * );
315 tMem += mFaceCapacity * sizeof( Face * );
316 tMem += mFacetCapacity * sizeof( Facet * );
317 tMem += mElementCapacity * sizeof( Element * );
318
319 return tMem ;
320 }
321
322//------------------------------------------------------------------------------
323
324 inline uint
326 {
327 return mEdgeCounter ;
328 }
329
330//------------------------------------------------------------------------------
331
332 inline uint
334 {
335 return mFacetCounter ;
336 }
337
338//------------------------------------------------------------------------------
339
340 inline uint
342 {
343 return mElementCounter ;
344 }
345
346//------------------------------------------------------------------------------
347
348 inline Node *
349 Vertex::node( const uint aIndex )
350 {
351 BELFEM_ASSERT( aIndex < ( uint ) mNodeCapacity,
352 "Node index %u is out of bounds for element %u, must be < %u.",
353 ( unsigned int ) aIndex,
354 ( unsigned int ) this->id(),
355 ( unsigned int ) mNodeCapacity );
356
357 return mNodes[ aIndex ];
358 }
359
360//------------------------------------------------------------------------------
361
362 inline const Node *
363 Vertex::node( const uint aIndex ) const
364 {
365 BELFEM_ASSERT( aIndex < ( uint ) mNodeCapacity,
366 "Node index %u is out of bounds for element %u, must be < %u.",
367 ( unsigned int ) aIndex,
368 ( unsigned int ) this->id(),
369 ( unsigned int ) mNodeCapacity );
370
371 return mNodes[ aIndex ];
372 }
373
374//------------------------------------------------------------------------------
375
376 inline Edge *
377 Vertex::edge( const uint aIndex )
378 {
379 BELFEM_ASSERT( aIndex < ( uint ) mEdgeCapacity,
380 "Edge index %u is out of bounds for element %u, must be < %u.",
381 ( unsigned int ) aIndex,
382 ( unsigned int ) this->id(),
383 ( unsigned int ) mEdgeCapacity );
384
385 return mEdges[ aIndex ];
386 }
387
388//------------------------------------------------------------------------------
389
390 inline const Edge *
391 Vertex::edge( const uint aIndex ) const
392 {
393 BELFEM_ASSERT( aIndex < ( uint ) mEdgeCapacity,
394 "Edge index %u is out of bounds for element %u, must be < %u.",
395 ( unsigned int ) aIndex,
396 ( unsigned int ) this->id(),
397 ( unsigned int ) mEdgeCapacity );
398
399 return mEdges[ aIndex ];
400 }
401
402//------------------------------------------------------------------------------
403
404 inline uint
406 {
407 return mFaceCounter ;
408 }
409
410 inline Face *
411 Vertex::face( const uint aIndex )
412 {
413 BELFEM_ASSERT( aIndex < ( uint ) mFaceCapacity,
414 "Face index %u is out of bounds for face %u, must be < %u.",
415 ( unsigned int ) aIndex,
416 ( unsigned int ) this->id(),
417 ( unsigned int ) mFaceCapacity );
418
419 return mFaces[ aIndex ];
420 }
421
422 inline const Face *
423 Vertex::face( const uint aIndex ) const
424 {
425 BELFEM_ASSERT( aIndex < ( uint ) mFaceCapacity,
426 "Face index %u is out of bounds for face %u, must be < %u.",
427 ( unsigned int ) aIndex,
428 ( unsigned int ) this->id(),
429 ( unsigned int ) mFaceCapacity );
430
431 return mFaces[ aIndex ];
432 }
433
434//------------------------------------------------------------------------------
435
436 inline Facet *
437 Vertex::facet( const uint aIndex )
438 {
439 BELFEM_ASSERT( aIndex < ( uint ) mFacetCapacity,
440 "Facet index %u is out of bounds for element %u, must be < %u.",
441 ( unsigned int ) aIndex,
442 ( unsigned int ) this->id(),
443 ( unsigned int ) mFacetCapacity );
444
445 return mFacets[ aIndex ];
446 }
447
448//------------------------------------------------------------------------------
449
450 inline const Facet *
451 Vertex::facet( const uint aIndex ) const
452 {
453 BELFEM_ASSERT( aIndex < ( uint ) mFacetCapacity,
454 "Facet index %u is out of bounds for element %u, must be < %u.",
455 ( unsigned int ) aIndex,
456 ( unsigned int ) this->id(),
457 ( unsigned int ) mFacetCapacity );
458
459 return mFacets[ aIndex ];
460 }
461
462//------------------------------------------------------------------------------
463
464 inline Element *
465 Vertex::element( const uint aIndex )
466 {
467 BELFEM_ASSERT( aIndex < ( uint ) mElementCapacity,
468 "Element index %u is out of bounds for element %u, must be < %u.",
469 ( unsigned int ) aIndex,
470 ( unsigned int ) this->id(),
471 ( unsigned int ) mElementCapacity );
472
473 return mElements[ aIndex ];
474 }
475
476//------------------------------------------------------------------------------
477
478 inline const Element *
479 Vertex::element( const uint aIndex ) const
480 {
481 BELFEM_ASSERT( aIndex < ( uint ) mElementCapacity,
482 "Element index %u is out of bounds for element %u, must be < %u.",
483 ( unsigned int ) aIndex,
484 ( unsigned int ) this->id(),
485 ( unsigned int ) mElementCapacity );
486
487 return mElements[ aIndex ];
488 }
489
490//------------------------------------------------------------------------------
491
492 inline EntityType
494 {
495 BELFEM_ERROR( false, "invalid call to abstract class");
496 return EntityType::UNDEFINED ;
497 }
498
499//------------------------------------------------------------------------------
500 }
501}
502#endif //BELFEM_CL_VERTEX_HPP
#define BELFEM_ERROR(aCheck,...)
Definition assert.hpp:264
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Graph node with an adjacency list; the vertex type the graph algorithms operate on.
Definition cl_Graph_Vertex.hpp:32
uint number_of_vertices() const
Definition cl_Graph_Vertex.hpp:321
uint number_of_dofs() const
Definition cl_Mesh_Basis.hpp:303
uint number_of_sources() const
Definition cl_Mesh_Basis.hpp:240
Basis()
Definition cl_Mesh_Basis.cpp:21
Special Edge class for NEDELEC-Type elements.
Definition cl_Edge.hpp:30
Lagrange Element baseclass.
Definition cl_Element.hpp:35
Definition cl_Face.hpp:29
Definition cl_Facet.hpp:24
Definition cl_Node.hpp:30
Edge * edge()
Definition cl_Segment.hpp:146
Element * element()
expose the element pointer
Definition cl_Segment.hpp:140
Edge ** mEdges
pointer to edges
Definition cl_Vertex.hpp:37
uint number_of_faces() const override
Definition cl_Vertex.hpp:405
void reset_element_container() override
Definition cl_Vertex.cpp:259
uint8_t mFaceCounter
number of faces connected to this vertex
Definition cl_Vertex.hpp:57
uint8_t mEdgeCounter
number of edges connected to this vertex
Definition cl_Vertex.hpp:53
void add_facet(Facet *aFacet)
Definition cl_Vertex.cpp:250
Element * element(const uint aIndex) override
Definition cl_Vertex.hpp:465
uint number_of_nodes() const override
Definition cl_Vertex.hpp:296
virtual uint number_of_facets() const
Definition cl_Vertex.hpp:333
EntityType entity_type() const override
returns the type of this mesh vertex
Definition cl_Vertex.hpp:493
void add_node(Node *aNode)
Definition cl_Vertex.cpp:88
virtual Facet * facet(const uint aIndex)
Definition cl_Vertex.hpp:437
uint8_t mNodeCapacity
Definition cl_Vertex.hpp:50
void reset_face_container()
Definition cl_Vertex.cpp:173
void increment_edge_counter()
Definition cl_Vertex.hpp:260
void increment_node_counter()
Definition cl_Vertex.hpp:251
virtual void unflag_nodes(const uint8_t aIndex=0)
Definition cl_Vertex.cpp:315
void allocate_edge_container(const uint aCounter=0)
Definition cl_Vertex.cpp:127
uint16_t mFacetCapacity
Definition cl_Vertex.hpp:63
uint16_t mFacetCounter
Definition cl_Vertex.hpp:62
uint8_t mFaceCapacity
Definition cl_Vertex.hpp:58
uint8_t mNodeCounter
number of nodes connected to this vertex
Definition cl_Vertex.hpp:49
void reset_facet_container()
Definition cl_Vertex.cpp:214
void increment_element_counter()
Definition cl_Vertex.hpp:287
void add_face(Face *aFace)
Definition cl_Vertex.cpp:205
uint8_t mElementCounter
number of elements connected to this vertex
Definition cl_Vertex.hpp:66
void insert_edge(Edge *aEdge, const uint aIndex)
Definition cl_Vertex.cpp:159
Face ** mFaces
pointer to faces
Definition cl_Vertex.hpp:40
void allocate_node_container(const uint aCounter=0)
Definition cl_Vertex.cpp:65
Face * face(const uint aIndex) override
Definition cl_Vertex.hpp:411
void reset_edge_container()
Definition cl_Vertex.cpp:113
void allocate_face_container(const uint aCounter=0)
Definition cl_Vertex.cpp:185
Element ** mElements
pointer to elements
Definition cl_Vertex.hpp:46
uint number_of_elements() const override
Definition cl_Vertex.hpp:341
virtual void flag_nodes(const uint8_t aIndex=0)
Definition cl_Vertex.cpp:304
void reset_node_container()
Definition cl_Vertex.cpp:51
uint number_of_edges() const override
Definition cl_Vertex.hpp:325
void add_edge(Edge *aEdge)
Definition cl_Vertex.cpp:150
void increment_facet_counter()
Definition cl_Vertex.hpp:278
void allocate_element_container(const uint aCounter=0)
Definition cl_Vertex.cpp:273
Node ** mNodes
pointer to nodes
Definition cl_Vertex.hpp:34
uint8_t mElementCapacity
Definition cl_Vertex.hpp:67
void allocate_facet_container(const uint aNumFacets=0)
Definition cl_Vertex.cpp:228
Node * node(const uint aIndex) override
Definition cl_Vertex.hpp:349
Edge * edge(const uint aIndex) override
Definition cl_Vertex.hpp:377
Vertex()
Definition cl_Vertex.cpp:24
void insert_node(Node *aNode, const uint aIndex)
Definition cl_Vertex.cpp:97
void delete_containers()
must be called by destructor
Definition cl_Vertex.cpp:38
void add_element(Element *aElement)
Definition cl_Vertex.cpp:295
size_t array_memory() const
Definition cl_Vertex.hpp:304
Facet ** mFacets
pointer to facets
Definition cl_Vertex.hpp:43
uint8_t mEdgeCapacity
Definition cl_Vertex.hpp:54
void increment_face_counter()
Definition cl_Vertex.hpp:269
Definition cl_EF_EdgeFunction.hpp:17
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30
EntityType
Definition Mesh_Enums.hpp:116
@ UNDEFINED
Definition Mesh_Enums.hpp:124
double real
Definition typedefs.hpp:36