BELFEM 0.9.4
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 // owns mVertices: a copy would free it twice
67 Vertex( const Vertex & ) = delete;
68 Vertex( Vertex && ) = delete;
69 Vertex & operator=( const Vertex & ) = delete;
70 Vertex & operator=( Vertex && ) = delete;
71
72//------------------------------------------------------------------------------
73
74 virtual ~Vertex();
75
76//------------------------------------------------------------------------------
77
78 inline void
79 set_id( const id_t aID );
80
81//------------------------------------------------------------------------------
82
83 inline id_t
84 id() const;
85
86//------------------------------------------------------------------------------
87
88 virtual inline void
89 set_index( const index_t aIndex );
90
91//------------------------------------------------------------------------------
92
93 virtual inline index_t
94 index() const;
95
96//------------------------------------------------------------------------------
97
98 virtual inline void
99 set_owner( const proc_t aOwner );
100
101//------------------------------------------------------------------------------
102
103 virtual inline proc_t
104 owner() const;
105
106//------------------------------------------------------------------------------
107
108 inline index_t
109 level() const ;
110
111//------------------------------------------------------------------------------
112
113 inline void
114 set_level( const index_t aLevel );
115
116//------------------------------------------------------------------------------
117
118 virtual inline void
119 flag( const uint8_t aIndex = 0 );
120
121//------------------------------------------------------------------------------
122
123 virtual inline void
124 unflag( const uint8_t aIndex = 0 );
125
126//------------------------------------------------------------------------------
127
128 virtual inline bool
129 is_flagged( const uint8_t aIndex = 0 ) const;
130
131//------------------------------------------------------------------------------
132
133 inline void
135
136//------------------------------------------------------------------------------
137
138 void
140
141//------------------------------------------------------------------------------
142
143 void
144 init_vertex_container( const uint aSize );
145
146//------------------------------------------------------------------------------
147
148 void
150
151//------------------------------------------------------------------------------
152
153 inline void
154 insert_vertex( Vertex * aVertex );
155
156//------------------------------------------------------------------------------
157
158 inline uint
159 number_of_vertices() const;
160
161//------------------------------------------------------------------------------
162
163 virtual inline Vertex *
164 vertex( const uint aIndex )
165 {
167 "Vertex Index %d out of bounds, which must be less than %d",
168 ( int ) aIndex,
169 ( int ) mVertexCounter );
170
171 return mVertices[ aIndex ];
172 }
173
174//------------------------------------------------------------------------------
175
176 virtual inline auto
177 vertex( const uint aIndex ) const
178 -> decltype( this )
179 {
181 "Vertex Index %d out of bounds, which must be less than %d",
182 ( int ) aIndex,
183 ( int ) mVertexCounter );
184
185 return mVertices[ aIndex ];
186 }
187
188//------------------------------------------------------------------------------
189
190 virtual void
192
193//------------------------------------------------------------------------------
194
195 virtual void
197
198//------------------------------------------------------------------------------
199
203 void
205
206//------------------------------------------------------------------------------
207
208 void
210
211 };
212
213//------------------------------------------------------------------------------
214
215 void
216 Vertex::set_id( const id_t aID )
217 {
218 mID = aID;
219 }
220
221//------------------------------------------------------------------------------
222
223 id_t
225 {
226 return mID;
227 }
228
229//------------------------------------------------------------------------------
230
231 void
233 {
234 mIndex = aIndex;
235 }
236
237//------------------------------------------------------------------------------
238
239 index_t
241 {
242 return mIndex;
243 }
244
245//------------------------------------------------------------------------------
246
247 void
248 Vertex::set_owner( const proc_t aOwner )
249 {
250 mOwner = aOwner;
251 }
252
253//------------------------------------------------------------------------------
254
255 proc_t
257 {
258 return mOwner;
259 }
260
261//------------------------------------------------------------------------------
262
263 index_t
265 {
266 return mLevel ;
267 }
268
269//------------------------------------------------------------------------------
270
271 inline void Vertex::set_level(const index_t aLevel )
272 {
273 mLevel = aLevel ;
274 }
275
276//------------------------------------------------------------------------------
277
278 void
279 Vertex::flag( const uint8_t aIndex )
280 {
281 BELFEM_ASSERT( aIndex < 8, "Flag index %u out of bounds (must be < 8)",
282 ( unsigned int ) aIndex );
283 mFlags |= ( 1 << aIndex );
284 }
285
286//------------------------------------------------------------------------------
287
288 void
289 Vertex::unflag( const uint8_t aIndex )
290 {
291 BELFEM_ASSERT( aIndex < 8, "Flag index %u out of bounds (must be < 8)",
292 ( unsigned int ) aIndex );
293 mFlags &= ~( 1 << aIndex );
294 }
295
296//------------------------------------------------------------------------------
297
298 bool
299 Vertex::is_flagged( const uint8_t aIndex ) const
300 {
301 BELFEM_ASSERT( aIndex < 8, "Flag index %u out of bounds (must be < 8)",
302 ( unsigned int ) aIndex );
303 return mFlags & ( 1 << aIndex );
304 }
305
306//------------------------------------------------------------------------------
307
308 // Debug tier: both counter guards run once per adjacency entry.
309 // A release build wraps at the counter's width instead of aborting
310 void
312 {
313 BELFEM_ASSERT( mVertexCounter < std::numeric_limits< decltype( mVertexCounter ) >::max(), "Vertex counter overflow." );
315 }
316
317//------------------------------------------------------------------------------
318
319 void
321 {
322 BELFEM_ASSERT( mVertexCounter < std::numeric_limits< decltype( mVertexCounter ) >::max(), "Vertex counter overflow." );
323 mVertices[ mVertexCounter++ ] = aVertex;
324 }
325
326//------------------------------------------------------------------------------
327
328 uint
330 {
331 return mVertexCounter;
332 }
333
334//------------------------------------------------------------------------------
335 }
336
338
339}
340#endif //BELFEM_CL_GRAPH_NODE_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Vertex & operator=(Vertex &&)=delete
id_t id() const
Definition cl_Graph_Vertex.hpp:224
virtual index_t index() const
Definition cl_Graph_Vertex.hpp:240
index_t level() const
Definition cl_Graph_Vertex.hpp:264
void insert_vertex(Vertex *aVertex)
Definition cl_Graph_Vertex.hpp:320
virtual Vertex * vertex(const uint aIndex)
Definition cl_Graph_Vertex.hpp:164
Vertex(const Vertex &)=delete
void set_id(const id_t aID)
Definition cl_Graph_Vertex.hpp:216
void set_level(const index_t aLevel)
Definition cl_Graph_Vertex.hpp:271
virtual auto vertex(const uint aIndex) const -> decltype(this)
Definition cl_Graph_Vertex.hpp:177
Vertex ** mVertices
Definition cl_Graph_Vertex.hpp:58
virtual proc_t owner() const
Definition cl_Graph_Vertex.hpp:256
void increment_vertex_counter()
Definition cl_Graph_Vertex.hpp:311
Vertex & operator=(const Vertex &)=delete
Vertex(Vertex &&)=delete
virtual void flag(const uint8_t aIndex=0)
Definition cl_Graph_Vertex.hpp:279
virtual void set_index(const index_t aIndex)
Definition cl_Graph_Vertex.hpp:232
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:299
uint32_t mVertexCounter
Definition cl_Graph_Vertex.hpp:55
virtual void set_owner(const proc_t aOwner)
Definition cl_Graph_Vertex.hpp:248
virtual void init_element_container()
Definition cl_Graph_Vertex.cpp:82
virtual void unflag(const uint8_t aIndex=0)
Definition cl_Graph_Vertex.hpp:289
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:329
Definition cl_Graph_Vertex.cpp:21
USER GUIDES:
Definition cl_Capacitor.cpp:16
Cell< graph::Vertex * > Graph
Definition cl_Graph_Vertex.hpp:337
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
T max(const Vector< T > &aVector)
Definition fn_AR_max.hpp:24
constexpr index_t gNoIndex
Definition typedefs.hpp:57
constexpr proc_t gNoOwner
Definition typedefs.hpp:59
uint32_t index_t
Definition typedefs.hpp:52