BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Graph_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_GRAPH_NODE_HPP
13#define BELFEM_CL_GRAPH_NODE_HPP
14
15#include <limits>
16
17#include "typedefs.hpp"
18#include "assert.hpp"
19#include "cl_Cell.hpp"
20
21namespace belfem
22{
23 namespace graph
24 {
31 class Vertex
32 {
33//------------------------------------------------------------------------------
34
35 // id of this node
36 id_t mID = gNoID;
37
38 // index of this node
39 index_t mIndex = gNoIndex;
40
41 // owner of this node
42 proc_t mOwner = gNoOwner;
43
44 // level of this node
45 index_t mLevel = 0;
46
47 // bitwise flags for this vertex
48 uint8_t mFlags = 0;
49
50//------------------------------------------------------------------------------
51 protected:
52//------------------------------------------------------------------------------
53
54 // counter for connected vertices
55 uint32_t mVertexCounter = 0;
56
57 // container for other vertices
58 Vertex ** mVertices = nullptr;
59
60//------------------------------------------------------------------------------
61 public:
62//------------------------------------------------------------------------------
63
64 Vertex() = default;
65
66//------------------------------------------------------------------------------
67
68 virtual ~Vertex();
69
70//------------------------------------------------------------------------------
71
72 inline void
73 set_id( const id_t aID );
74
75//------------------------------------------------------------------------------
76
77 inline id_t
78 id() const;
79
80//------------------------------------------------------------------------------
81
82 virtual inline void
83 set_index( const index_t aIndex );
84
85//------------------------------------------------------------------------------
86
87 virtual inline index_t
88 index() const;
89
90//------------------------------------------------------------------------------
91
92 virtual inline void
93 set_owner( const proc_t aOwner );
94
95//------------------------------------------------------------------------------
96
97 virtual inline proc_t
98 owner() const;
99
100//------------------------------------------------------------------------------
101
102 inline index_t
103 level() const ;
104
105//------------------------------------------------------------------------------
106
107 inline void
108 set_level( const index_t aLevel );
109
110//------------------------------------------------------------------------------
111
112 virtual inline void
113 flag( const uint8_t aIndex = 0 );
114
115//------------------------------------------------------------------------------
116
117 virtual inline void
118 unflag( const uint8_t aIndex = 0 );
119
120//------------------------------------------------------------------------------
121
122 virtual inline bool
123 is_flagged( const uint8_t aIndex = 0 ) const;
124
125//------------------------------------------------------------------------------
126
127 inline void
129
130//------------------------------------------------------------------------------
131
132 void
134
135//------------------------------------------------------------------------------
136
137 void
138 init_vertex_container( const uint aSize );
139
140//------------------------------------------------------------------------------
141
142 void
144
145//------------------------------------------------------------------------------
146
147 inline void
148 insert_vertex( Vertex * aVertex );
149
150//------------------------------------------------------------------------------
151
152 inline uint
153 number_of_vertices() const;
154
155//------------------------------------------------------------------------------
156
157 virtual inline Vertex *
158 vertex( const uint aIndex )
159 {
161 "Vertex Index %d out of bounds, which must be less than %d",
162 ( int ) aIndex,
163 ( int ) mVertexCounter );
164
165 return mVertices[ aIndex ];
166 }
167
168//------------------------------------------------------------------------------
169
170 virtual inline auto
171 vertex( const uint aIndex ) const
172 -> decltype( this )
173 {
175 "Vertex Index %d out of bounds, which must be less than %d",
176 ( int ) aIndex,
177 ( int ) mVertexCounter );
178
179 return mVertices[ aIndex ];
180 }
181
182//------------------------------------------------------------------------------
183
184 virtual void
186
187//------------------------------------------------------------------------------
188
189 virtual void
191
192//------------------------------------------------------------------------------
193
197 void
199
200//------------------------------------------------------------------------------
201
202 void
204
205 };
206
207//------------------------------------------------------------------------------
208
209 void
210 Vertex::set_id( const id_t aID )
211 {
212 mID = aID;
213 }
214
215//------------------------------------------------------------------------------
216
217 id_t
219 {
220 return mID;
221 }
222
223//------------------------------------------------------------------------------
224
225 void
227 {
228 mIndex = aIndex;
229 }
230
231//------------------------------------------------------------------------------
232
233 index_t
235 {
236 return mIndex;
237 }
238
239//------------------------------------------------------------------------------
240
241 void
242 Vertex::set_owner( const proc_t aOwner )
243 {
244 mOwner = aOwner;
245 }
246
247//------------------------------------------------------------------------------
248
249 proc_t
251 {
252 return mOwner;
253 }
254
255//------------------------------------------------------------------------------
256
257 index_t
259 {
260 return mLevel ;
261 }
262
263//------------------------------------------------------------------------------
264
265 inline void Vertex::set_level(const index_t aLevel )
266 {
267 mLevel = aLevel ;
268 }
269
270//------------------------------------------------------------------------------
271
272 void
273 Vertex::flag( const uint8_t aIndex )
274 {
275 BELFEM_ASSERT( aIndex < 8, "Flag index %u out of bounds (must be < 8)",
276 ( unsigned int ) aIndex );
277 mFlags |= ( 1 << aIndex );
278 }
279
280//------------------------------------------------------------------------------
281
282 void
283 Vertex::unflag( const uint8_t aIndex )
284 {
285 BELFEM_ASSERT( aIndex < 8, "Flag index %u out of bounds (must be < 8)",
286 ( unsigned int ) aIndex );
287 mFlags &= ~( 1 << aIndex );
288 }
289
290//------------------------------------------------------------------------------
291
292 bool
293 Vertex::is_flagged( const uint8_t aIndex ) const
294 {
295 BELFEM_ASSERT( aIndex < 8, "Flag index %u out of bounds (must be < 8)",
296 ( unsigned int ) aIndex );
297 return mFlags & ( 1 << aIndex );
298 }
299
300//------------------------------------------------------------------------------
301
302 void
304 {
305 BELFEM_ASSERT( mVertexCounter < std::numeric_limits<uint32_t>::max(), "Vertex counter overflow." );
307 }
308
309//------------------------------------------------------------------------------
310
311 void
313 {
314 BELFEM_ASSERT( mVertexCounter < std::numeric_limits<uint32_t>::max(), "Vertex counter overflow." );
315 mVertices[ mVertexCounter++ ] = aVertex;
316 }
317
318//------------------------------------------------------------------------------
319
320 uint
322 {
323 return mVertexCounter;
324 }
325
326//------------------------------------------------------------------------------
327 }
328
330
331}
332#endif //BELFEM_CL_GRAPH_NODE_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
id_t id() const
Definition cl_Graph_Vertex.hpp:218
virtual index_t index() const
Definition cl_Graph_Vertex.hpp:234
index_t level() const
Definition cl_Graph_Vertex.hpp:258
void insert_vertex(Vertex *aVertex)
Definition cl_Graph_Vertex.hpp:312
virtual Vertex * vertex(const uint aIndex)
Definition cl_Graph_Vertex.hpp:158
void set_id(const id_t aID)
Definition cl_Graph_Vertex.hpp:210
void set_level(const index_t aLevel)
Definition cl_Graph_Vertex.hpp:265
virtual auto vertex(const uint aIndex) const -> decltype(this)
Definition cl_Graph_Vertex.hpp:171
Vertex ** mVertices
Definition cl_Graph_Vertex.hpp:58
virtual proc_t owner() const
Definition cl_Graph_Vertex.hpp:250
void increment_vertex_counter()
Definition cl_Graph_Vertex.hpp:303
virtual void flag(const uint8_t aIndex=0)
Definition cl_Graph_Vertex.hpp:273
virtual void set_index(const index_t aIndex)
Definition cl_Graph_Vertex.hpp:226
virtual void reset_element_container()
Definition cl_Graph_Vertex.cpp:90
virtual bool is_flagged(const uint8_t aIndex=0) const
Definition cl_Graph_Vertex.hpp:293
uint32_t mVertexCounter
Definition cl_Graph_Vertex.hpp:55
virtual void set_owner(const proc_t aOwner)
Definition cl_Graph_Vertex.hpp:242
virtual void init_element_container()
Definition cl_Graph_Vertex.cpp:82
virtual void unflag(const uint8_t aIndex=0)
Definition cl_Graph_Vertex.hpp:283
void reset_vertex_container()
Definition cl_Graph_Vertex.cpp:69
void sort_vertices()
sorts the vertices according to their index
Definition cl_Graph_Vertex.cpp:101
void init_vertex_container()
Definition cl_Graph_Vertex.cpp:32
void reverse_vertices()
Definition cl_Graph_Vertex.cpp:122
uint number_of_vertices() const
Definition cl_Graph_Vertex.hpp:321
Definition cl_Graph_Vertex.cpp:21
USER GUIDES:
Definition cl_Capacitor.cpp:16
Cell< graph::Vertex * > Graph
Definition cl_Graph_Vertex.hpp:329
constexpr id_t gNoID
Definition typedefs.hpp:58
unsigned int uint
Definition typedefs.hpp:30
unsigned int id_t
Definition typedefs.hpp:41
int proc_t
Definition commtypes.hpp:29
constexpr index_t gNoIndex
Definition typedefs.hpp:57
constexpr proc_t gNoOwner
Definition typedefs.hpp:59
uint32_t index_t
Definition typedefs.hpp:52