BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Mesh_Basis.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_MESH_BASIS_HPP
13#define BELFEM_CL_MESH_BASIS_HPP
14
15#include <limits>
16
17#include "typedefs.hpp"
18#include "cl_Graph_Vertex.hpp"
19#include "Mesh_Enums.hpp"
20#include "cl_Cell.hpp"
21#include "cl_Vector.hpp"
22
23namespace belfem
24{
25 namespace mesh
26 {
27 class Node ;
28 class Edge ;
29 class Face ;
30 class Element ;
31
32 class Basis : public graph::Vertex
33 {
34 // for hanging basis
38 uint16_t mNumberOfSources = 0 ;
39 Basis ** mSources = nullptr ;
40 real * mWeights = nullptr ;
41
42 uint8_t mNumberOfDofs = 0 ;
43 graph::Vertex ** mDofs ;
44
45//------------------------------------------------------------------------------
46 public:
47//------------------------------------------------------------------------------
48
49 Basis();
50
51 ~Basis() override ;
52
53//------------------------------------------------------------------------------
54
58 virtual EntityType
59 entity_type() const ;
60
61//------------------------------------------------------------------------------
62
63 virtual uint
64 number_of_nodes() const ;
65
66//------------------------------------------------------------------------------
67
68 virtual uint
69 number_of_edges() const ;
70
71//------------------------------------------------------------------------------
72
73 virtual uint
74 number_of_faces() const ;
75
76//------------------------------------------------------------------------------
77
78 virtual Node *
79 node( const uint aIndex );
80
81//------------------------------------------------------------------------------
82
83 virtual const Node *
84 node( const uint aIndex ) const ;
85
86//------------------------------------------------------------------------------
87
88 virtual Edge *
89 edge( const uint aIndex );
90
91//------------------------------------------------------------------------------
92
93 virtual const Edge *
94 edge( const uint aIndex ) const ;
95
96//------------------------------------------------------------------------------
97
98 virtual Face *
99 face( const uint aIndex=0 );
100
101//------------------------------------------------------------------------------
102
103 virtual const Face *
104 face( const uint aIndex=0 ) const ;
105
106//------------------------------------------------------------------------------
107
108 virtual uint
109 number_of_elements() const ;
110
111//------------------------------------------------------------------------------
112
113 virtual Element *
114 element( const uint aIndex );
115
116//------------------------------------------------------------------------------
117
118 bool
119 is_hanging() const ;
120
121//------------------------------------------------------------------------------
122
123 uint
124 number_of_sources() const ;
125
126//------------------------------------------------------------------------------
127
128 Basis *
129 source( const uint aIndex );
130
131//------------------------------------------------------------------------------
132
133 const Basis *
134 source( const uint aIndex ) const ;
135
136//------------------------------------------------------------------------------
137
138 Node *
139 source_node( const uint aIndex );
140
141//------------------------------------------------------------------------------
142
143 const Node *
144 source_node( const uint aIndex ) const ;
145
146//------------------------------------------------------------------------------
147
148 real
149 weight( const uint aIndex ) const ;
150
151//------------------------------------------------------------------------------
152
153 void
154 set_weight( const uint aIndex, const real aValue );
155
156//------------------------------------------------------------------------------
157
158 void
159 set_sources( Cell< Basis * > & aSources, const Vector< real > & aCoefficients );
160
161//------------------------------------------------------------------------------
162
163 void
164 set_sources( Cell< Basis * > & aSources, const Cell< real > & aCoefficients );
165
166//------------------------------------------------------------------------------
167
168 void
169 set_sources( Cell< Node * > & aSources, const Vector< real > & aCoefficients );
170
171//------------------------------------------------------------------------------
172
173 void
175
176//------------------------------------------------------------------------------
177
181 void
182 allocate_source_container( uint aNumSources );
183
184//------------------------------------------------------------------------------
185
188 void
189 add_source( Basis * aSource, const real aWeight=1.0 );
190
191//------------------------------------------------------------------------------
192
193 void
194 flag_sources();
195
196//------------------------------------------------------------------------------
197
198 void
200
201//------------------------------------------------------------------------------
202
203 void
205
206//------------------------------------------------------------------------------
207
208 void
210
211//------------------------------------------------------------------------------
212
213 void
214 insert_dof( graph::Vertex * aDof );
215
216//------------------------------------------------------------------------------
217
218 uint
219 number_of_dofs() const ;
220
221//------------------------------------------------------------------------------
222
224 dof( const uint aIndex );
225
226//------------------------------------------------------------------------------
227 };
228
229//----------------------------------------------------------------------------
230
231 inline bool
233 {
234 return mNumberOfSources > 0 ;
235 }
236
237//----------------------------------------------------------------------------
238
239 inline uint
241 {
242 return mNumberOfSources ;
243 }
244
245
246//------------------------------------------------------------------------------
247
248 inline void
250 {
251 // a wrapped counter would make allocate_dof_container skip its
252 // malloc and insert_dof write through an uninitialized pointer
253 BELFEM_ERROR( mNumberOfDofs < std::numeric_limits< decltype( mNumberOfDofs ) >::max(),
254 "Dof counter of basis %lu is full ( max %lu )",
255 ( long unsigned int ) this->id(),
256 ( long unsigned int ) std::numeric_limits< decltype( mNumberOfDofs ) >::max() );
257
258 ++mNumberOfDofs ;
259 }
260
261//------------------------------------------------------------------------------
262
263 inline void
265 {
266 if( mNumberOfDofs > 0 )
267 {
268 mDofs = ( graph::Vertex ** ) malloc( mNumberOfDofs * sizeof ( graph::Vertex * ) );
269 std::fill( mDofs, mDofs + mNumberOfDofs, nullptr );
270 mNumberOfDofs = 0 ;
271 }
272 }
273
274//------------------------------------------------------------------------------
275
276 inline void
278 {
279 if( mNumberOfDofs > 0 )
280 {
281 free( mDofs );
282 mDofs = nullptr ;
283 mNumberOfDofs = 0 ;
284 }
285 }
286
287//------------------------------------------------------------------------------
288
289 inline void
291 {
292 BELFEM_ERROR( mNumberOfDofs < std::numeric_limits< decltype( mNumberOfDofs ) >::max(),
293 "Dof counter of basis %lu is full ( max %lu )",
294 ( long unsigned int ) this->id(),
295 ( long unsigned int ) std::numeric_limits< decltype( mNumberOfDofs ) >::max() );
296
297 mDofs[ mNumberOfDofs++ ] = aDof ;
298 }
299
300//----------------------------------------------------------------------------
301
302 inline uint
304 {
305 return mNumberOfDofs ;
306 }
307
308//----------------------------------------------------------------------------
309
310 inline graph::Vertex *
311 Basis::dof( const uint aIndex )
312 {
313 BELFEM_ASSERT( aIndex < ( uint ) mNumberOfDofs, "Index %u out of bounds for basis %lu (expect < %u).",
314 ( unsigned int ) aIndex,
315 ( long unsigned int ) this->id(),
316 ( unsigned int ) mNumberOfDofs );
317
318 return mDofs[ aIndex ];
319 }
320
321//----------------------------------------------------------------------------
322
323 inline Basis *
324 Basis::source( const uint aIndex )
325 {
326 BELFEM_ASSERT( aIndex < ( uint ) mNumberOfSources, "Index %u out of bounds for basis %lu (must be < %u).",
327 ( unsigned int ) aIndex,
328 ( long unsigned int ) this->id(),
329 ( unsigned int ) mNumberOfSources );
330
331 return mSources[ aIndex ];
332 }
333
334//----------------------------------------------------------------------------
335
336 inline const Basis *
337 Basis::source( const uint aIndex ) const
338 {
339 BELFEM_ASSERT( aIndex < ( uint ) mNumberOfSources, "Index %u out of bounds for basis %lu (must be < %u).",
340 ( unsigned int ) aIndex,
341 ( long unsigned int ) this->id(),
342 ( unsigned int ) mNumberOfSources );
343
344 return mSources[ aIndex ];
345 }
346
347//----------------------------------------------------------------------------
348
349 inline real
350 Basis::weight( const uint aIndex ) const
351 {
352 BELFEM_ASSERT( aIndex < mNumberOfSources, "Index %u out of bounds for basis %lu (must be < %u).",
353 ( unsigned int ) aIndex,
354 ( long unsigned int ) this->id(),
355 ( unsigned int ) mNumberOfSources );
356
357 return mWeights[ aIndex ];
358 }
359
360//----------------------------------------------------------------------------
361
362 inline void
363 Basis::set_weight( const uint aIndex, const real aValue )
364 {
365 BELFEM_ASSERT( aIndex < ( uint ) mNumberOfSources, "Index %u out of bounds for basis %lu (must be < %u).",
366 ( unsigned int ) aIndex,
367 ( long unsigned int ) this->id(),
368 ( unsigned int ) mNumberOfSources );
369
370 mWeights[ aIndex ] = aValue ;
371 }
372//----------------------------------------------------------------------------
373 }
374}
375#endif //BELFEM_CL_MESH_BASIS_HPP
#define BELFEM_ERROR(aCheck,...)
Definition assert.hpp:264
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Cell is a wrapper around the standard vector.
Definition cl_Cell.hpp:42
Graph node with an adjacency list; the vertex type the graph algorithms operate on.
Definition cl_Graph_Vertex.hpp:32
Definition cl_Mesh_Basis.hpp:33
virtual Edge * edge(const uint aIndex)
Definition cl_Mesh_Basis.cpp:124
virtual uint number_of_nodes() const
Definition cl_Mesh_Basis.cpp:76
graph::Vertex * dof(const uint aIndex)
Definition cl_Mesh_Basis.hpp:311
void set_weight(const uint aIndex, const real aValue)
Definition cl_Mesh_Basis.hpp:363
bool is_hanging() const
Definition cl_Mesh_Basis.hpp:232
void insert_dof(graph::Vertex *aDof)
Definition cl_Mesh_Basis.hpp:290
void reset_source_container()
Definition cl_Mesh_Basis.cpp:290
void flag_sources()
Definition cl_Mesh_Basis.cpp:398
void add_source(Basis *aSource, const real aWeight=1.0)
Definition cl_Mesh_Basis.cpp:331
uint number_of_dofs() const
Definition cl_Mesh_Basis.hpp:303
uint number_of_sources() const
Definition cl_Mesh_Basis.hpp:240
void set_sources(Cell< Basis * > &aSources, const Vector< real > &aCoefficients)
Definition cl_Mesh_Basis.cpp:192
virtual Face * face(const uint aIndex=0)
Definition cl_Mesh_Basis.cpp:146
virtual EntityType entity_type() const
returns the type of this vertex
Definition cl_Mesh_Basis.cpp:67
Basis()
Definition cl_Mesh_Basis.cpp:21
void allocate_source_container(uint aNumSources)
Definition cl_Mesh_Basis.cpp:308
virtual Node * node(const uint aIndex)
Definition cl_Mesh_Basis.cpp:103
Node * source_node(const uint aIndex)
Definition cl_Mesh_Basis.cpp:166
virtual uint number_of_elements() const
Definition cl_Mesh_Basis.cpp:49
void reset_dof_container()
Definition cl_Mesh_Basis.hpp:277
virtual uint number_of_edges() const
Definition cl_Mesh_Basis.cpp:85
real weight(const uint aIndex) const
Definition cl_Mesh_Basis.hpp:350
virtual uint number_of_faces() const
Definition cl_Mesh_Basis.cpp:94
Basis * source(const uint aIndex)
Definition cl_Mesh_Basis.hpp:324
virtual Element * element(const uint aIndex)
Definition cl_Mesh_Basis.cpp:58
void increment_dof_counter()
Definition cl_Mesh_Basis.hpp:249
void allocate_dof_container()
Definition cl_Mesh_Basis.hpp:264
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_Node.hpp:30
Definition cl_EF_EdgeFunction.hpp:17
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30
T max(const Vector< T > &aVector)
Definition fn_AR_max.hpp:24
EntityType
Definition Mesh_Enums.hpp:116
double real
Definition typedefs.hpp:36