BELFEM 0.9.3
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_FEM_DofMgr_DofData.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_FEM_DOFMGR_DOFDATA_HPP
13#define BELFEM_CL_FEM_DOFMGR_DOFDATA_HPP
14
15#include "typedefs.hpp"
16#include "cl_Map.hpp"
17#include "cl_Cell.hpp"
18#include "cl_Bitset.hpp"
19#include "cl_Vector.hpp"
21#include "cl_IWG.hpp"
22
23namespace belfem
24{
25 class Mesh ;
26
27 namespace fem
28 {
29 class Dof ;
30 class DofManager ;
31 class Kernel ;
32
33 namespace dofmgr
34 {
40 class DofData
41 {
43 DofManager * mParent;
44
46 Kernel * mKernel ;
47
49 Mesh * mMesh ;
50
52 Parameters * mParams ;
53
55 const proc_t mCommRank ;
56 const proc_t mCommSize ;
57
59 Cell< Dof * > mDOFs;
60
62 Cell< Dof * > mAbstractDOFs;
63
65 Cell< Dof * > mHangingDOFs ;
66
68 Map< index_t , index_t > mDofTypeToField ;
69
71 Map< id_t, Dof * > mDofMap ;
72
73 id_t mEdgeDofOffset = gNoID ;
74 id_t mFaceDofOffset = gNoID ;
75 id_t mCellDofOffset = gNoID ;
76 id_t mLambdaDofOffset = gNoID ;
77
78 Cell< Vector< index_t > > mDofIndexTables ;
79
80 // system wide dofs. Initialized here: SolverData binds const
81 // references to these at DofManager construction, BEFORE
82 // create_dofs() runs — an early read must see 0, not garbage
83 index_t mNumberOfFreeDofs = 0 ;
84 index_t mNumberOfFixedDofs = 0 ;
85 index_t mNumberOfHangingDofs = 0 ;
86 index_t mMyNumberOfFreeDofs = 0 ;
87 index_t mMyNumberOfFixedDofs = 0 ;
88 index_t mMyNumberOfHangingDofs = 0 ;
89 id_t mNumDofTypes = BELFEM_UINT_MAX ;
90
91//------------------------------------------------------------------------------
92 public:
93//------------------------------------------------------------------------------
94
95 DofData( DofManager * aParent,
96 Parameters * aParams ) ;
97
98//------------------------------------------------------------------------------
99
100 ~DofData() ;
101
102//------------------------------------------------------------------------------
103
104 void
105 create_dofs( IWG * aIWG );
106
107//------------------------------------------------------------------------------
108
109 void
110 create_field_map( IWG * aIwg );
111
112//------------------------------------------------------------------------------
113
118 dofs();
119
120//------------------------------------------------------------------------------
121
126 hanging_dofs();
127
128//----------------------------------------------------------------------------
129
133 bool
134 dof_exists( const id_t aID ) const;
135
136//------------------------------------------------------------------------------
137
138 index_t
139 doftype_to_field_index( const index_t aDofType );
140
141//------------------------------------------------------------------------------
142
143 // access one dof by its id
144 Dof *
145 dof( const id_t aID );
146
147//------------------------------------------------------------------------------
148
149 id_t
151 const id_t aNodeID,
152 const uint aDofType ) const ;
153
154//------------------------------------------------------------------------------
155
156 id_t
158 const id_t aEdgeID,
159 const uint aDofType ) const ;
160
161//------------------------------------------------------------------------------
162
163 id_t
165 const id_t aFaceID,
166 const uint aDofType ) const ;
167
168//------------------------------------------------------------------------------
169
170 id_t
172 const id_t aCellID,
173 const uint aDofType ) const ;
174
175//------------------------------------------------------------------------------
176
177 id_t
179 const id_t aFacetID,
180 const uint aDofType ) const ;
181
182//------------------------------------------------------------------------------
183
189 void
190 init_dof_values( const bool aFreeDofsOnly = false );
191
192//------------------------------------------------------------------------------
193
194 void
196 Cell< graph::Vertex * > & aFreeDofs,
197 Cell< graph::Vertex * > & aFixedDofs );
198
199//------------------------------------------------------------------------------
200
201 void
203 Cell< graph::Vertex * > & aFreeDofs,
204 Cell< graph::Vertex * > & aFixedDofs );
205
206//------------------------------------------------------------------------------
207
208 void
210
211//------------------------------------------------------------------------------
212
213 void
215 const Vector< id_t > & aGraphData,
216 Graph & aFreeDofs,
217 Graph & aFixedDofs );
218
219//------------------------------------------------------------------------------
220
221 const index_t &
222 number_of_free_dofs() const ;
223
224//------------------------------------------------------------------------------
225
226 const index_t &
227 number_of_fixed_dofs() const ;
228
229 const index_t &
230 number_of_hanging_dofs() const ;
231
232//------------------------------------------------------------------------------
233
234 void
235 reset();
236
237//------------------------------------------------------------------------------
238
242 uint
243 num_dofs_per_element( const id_t aBlockID ) const;
244
245//------------------------------------------------------------------------------
246
250 uint
251 num_dofs_per_facet( const id_t aSideSetID ) const;
252
253//------------------------------------------------------------------------------
254
255 const Vector< index_t > &
256 dof_indices( const uint aProc ) const;
257
258//------------------------------------------------------------------------------
259
260 void
262
263//------------------------------------------------------------------------------
264
265 void
267
268//------------------------------------------------------------------------------
269
270 void
272
273//-------------------------------------------------------------------------------
274
275 void
277
278//-------------------------------------------------------------------------------
279
282
283//-------------------------------------------------------------------------------
284
285 void
287
288//-------------------------------------------------------------------------------
289
290 const index_t &
291 my_number_of_free_dofs() const ;
292
293//-------------------------------------------------------------------------------
294
295 const index_t &
297//-------------------------------------------------------------------------------
298
299 const index_t &
301
302//------------------------------------------------------------------------------
303 private:
304//------------------------------------------------------------------------------
305
306 void
307 create_dof_map();
308
309//------------------------------------------------------------------------------
310
314 void
315 compute_max_ids( Vector< id_t > & aMaxEntityIDs );
316
317//-------------------------------------------------------------------------------
318
319 index_t
320 count_node_dofs( IWG * aIWG,
321 Vector< id_t > & aEntityIDs,
322 Vector< index_t > & aDofTypes,
323 Cell< Bitset<BELFEM_MAX_NUMPROCS> > & aProcFlags );
324
325//-----------------------------------------------------------------------------
326
327 index_t
328 count_edge_dofs( IWG * aIWG,
329 Vector< id_t > & aEntityIDs,
330 Vector< index_t > & aDofTypes,
331 Cell< Bitset<BELFEM_MAX_NUMPROCS> > & aProcFlags );
332
333//-----------------------------------------------------------------------------
334
335 index_t
336 count_face_dofs( IWG * aIWG,
337 Vector< id_t > & aEntityIDs,
338 Vector< index_t > & aDofTypes,
339 Cell< Bitset<BELFEM_MAX_NUMPROCS> > & aProcFlags );
340
341//-----------------------------------------------------------------------------
342
343 index_t
344 count_cell_dofs( IWG * aIWG,
345 Vector< id_t > & aEntityIDs,
346 Vector< index_t > & aDofTypes,
347 Cell< Bitset<BELFEM_MAX_NUMPROCS> > & aProcFlags );
348
349//-----------------------------------------------------------------------------
350
351 index_t
352 count_lambda_dofs( IWG * aIWG,
353 Vector< id_t > & aEntityIDs,
354 Vector< index_t > & aDofTypes,
355 Cell< Bitset<BELFEM_MAX_NUMPROCS> > & aProcFlags );
356
357//-----------------------------------------------------------------------------
358
359 index_t
360 count_dofs_for_proc(
361 const index_t aProc,
362 const Vector< id_t > & aDofIDs,
363 const Vector< id_t > & aEntityIDs,
364 const Vector< index_t > & aDofTypes,
365 const Cell< Bitset<BELFEM_MAX_NUMPROCS> > & aProcFlags,
366 Vector< id_t > & aProcDofIDs,
367 Vector< id_t > & aProcEntityIDs,
368 Vector< index_t > & aProcDofTypes );
369
370//-------------------------------------------------------------------------------
371
376 void
377 compute_dof_offsets( IWG * aIWG );
378
379//-------------------------------------------------------------------------------
380
381 void
382 remove_hanging_dofs_from_container();
383
384//-------------------------------------------------------------------------------
389 //void
390 //compute_adjacency(
391 // Dof * aDof,
392 // Cell< Dof * > & aWork,
393 // const bool aFixedFlag );
394
395//-------------------------------------------------------------------------------
396 };
397
398//------------------------------------------------------------------------------
399
400 inline Cell< Dof * > &
402 {
403 return mDOFs ;
404 }
405
406//------------------------------------------------------------------------------
407
408 inline Cell< Dof * > &
410 {
411 return mHangingDOFs ;
412 }
413
414//------------------------------------------------------------------------------
415
416 inline Dof *
417 DofData::dof( const id_t aID )
418 {
419 return mDofMap( aID );
420 }
421
422//------------------------------------------------------------------------------
423
424 inline bool
425 DofData::dof_exists( const id_t aID ) const
426 {
427 return mDofMap.key_exists( aID );
428 }
429
430//------------------------------------------------------------------------------
431
432 inline index_t
434 {
435 return mDofTypeToField( aDofType );
436 }
437
438//------------------------------------------------------------------------------
439
440 inline id_t
442 const id_t aNodeID,
443 const uint aDofType ) const
444 {
445 return aNodeID * mNumDofTypes + aDofType ;
446 }
447
448//------------------------------------------------------------------------------
449
450 inline id_t
452 const id_t aEdgeID,
453 const uint aDofType ) const
454 {
455 return mEdgeDofOffset + aEdgeID * mNumDofTypes + aDofType ;
456 }
457
458//------------------------------------------------------------------------------
459
460 inline id_t
462 const id_t aFaceID,
463 const uint aDofType ) const
464 {
465 return mFaceDofOffset + aFaceID * mNumDofTypes + aDofType ;
466 }
467
468//------------------------------------------------------------------------------
469
470 inline id_t
472 const id_t aCellID,
473 const uint aDofType ) const
474 {
475 return mCellDofOffset + aCellID * mNumDofTypes + aDofType ;
476 }
477
478//------------------------------------------------------------------------------
479
480 inline id_t
482 const id_t aFacetID,
483 const uint aDofType ) const
484 {
485 return mLambdaDofOffset + aFacetID * mNumDofTypes + aDofType ;
486 }
487
488//------------------------------------------------------------------------------
489
490 inline const index_t &
492 {
493 return mNumberOfFreeDofs ;
494 }
495
496//------------------------------------------------------------------------------
497
498 inline const index_t &
500 {
501 return mNumberOfFixedDofs ;
502 }
503
504//------------------------------------------------------------------------------
505
506 inline const index_t &
508 {
509 return mNumberOfHangingDofs ;
510 }
511//------------------------------------------------------------------------------
512
513 inline const Vector< index_t > &
514 DofData::dof_indices( const uint aProc ) const
515 {
516 BELFEM_ASSERT( mDofIndexTables.size() > 0,
517 "DofTables have not been allocated yet");
518
519 return mDofIndexTables( aProc );
520 }
521
522//------------------------------------------------------------------------------
523
524 template< typename T >
525 void
527 {
528 for ( T * tBasis : aBasis )
529 {
530 tBasis->allocate_dof_container();
531 }
532 }
533//------------------------------------------------------------------------------
534
535 inline Cell< Dof * > &
537 {
538 BELFEM_ASSERT( mCommRank == 0, "Abstract dofs can only be accessed by master");
539 return mAbstractDOFs;
540 }
541
542//-------------------------------------------------------------------------------
543
544 inline const index_t &
546 {
547 return mMyNumberOfFreeDofs;
548 }
549
550//-------------------------------------------------------------------------------
551
552 inline const index_t &
554 {
555 return mMyNumberOfFixedDofs;
556 }
557
558//-------------------------------------------------------------------------------
559
560 inline const index_t &
562 {
563 return mMyNumberOfHangingDofs;
564 }
565
566//------------------------------------------------------------------------------
567 } /* end namespace dofmgr */
568
569
570//------------------------------------------------------------------------------
571
572
573 } /* end namespace fem */
574} /* end namespace belfem */
575
576#endif //BELFEM_CL_FEM_DOFMGR_DOFDATA_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Compile-time fixed-size bitset.
Definition cl_Bitset.hpp:32
A bounds-checked wrapper around std::vector.
Definition cl_Cell.hpp:45
Hash map (unordered key-value).
Definition cl_Map.hpp:75
Top-level container for all mesh entities.
Definition cl_Mesh.hpp:60
Definition cl_FEM_Dof.hpp:28
Main workhorse: DOF management, assembly coordination and the solver interface.
Definition cl_FEM_DofManager.hpp:52
Prototype for Integrator of Weak Form Governing Equation.
Definition cl_IWG.hpp:81
Top-level orchestrator.
Definition cl_FEM_Kernel.hpp:56
id_t lambda_dof_id(const id_t aFacetID, const uint aDofType) const
Definition cl_FEM_DofMgr_DofData.hpp:481
void collect_hanging_dofs()
Definition cl_FEM_DofMgr_DofData.cpp:1930
const index_t & my_number_of_hanging_dofs() const
Definition cl_FEM_DofMgr_DofData.hpp:561
uint num_dofs_per_element(const id_t aBlockID) const
computes the number of dofs per element on block
Definition cl_FEM_DofMgr_DofData.cpp:2980
id_t edge_dof_id(const id_t aEdgeID, const uint aDofType) const
Definition cl_FEM_DofMgr_DofData.hpp:451
void split_dof_container(Cell< graph::Vertex * > &aFreeDofs, Cell< graph::Vertex * > &aFixedDofs)
Temporarily splits the unified DOF container (mDOFs) into separate free and fixed DOF graphs for inde...
Definition cl_FEM_DofMgr_DofData.cpp:2498
const index_t & number_of_fixed_dofs() const
Definition cl_FEM_DofMgr_DofData.hpp:499
Cell< Dof * > & hanging_dofs()
expose the hanging dof container
Definition cl_FEM_DofMgr_DofData.hpp:409
const index_t & my_number_of_free_dofs() const
Definition cl_FEM_DofMgr_DofData.hpp:545
index_t doftype_to_field_index(const index_t aDofType)
Definition cl_FEM_DofMgr_DofData.hpp:433
uint num_dofs_per_facet(const id_t aSideSetID) const
computes the number of dofs per element on sideset
Definition cl_FEM_DofMgr_DofData.cpp:3000
void create_dofwise_t_matrices_master()
Definition cl_FEM_DofMgr_DofData.cpp:3010
id_t face_dof_id(const id_t aFaceID, const uint aDofType) const
Definition cl_FEM_DofMgr_DofData.hpp:461
Cell< Dof * > & dofs()
expose the dof container
Definition cl_FEM_DofMgr_DofData.hpp:401
void create_dofs(IWG *aIWG)
Definition cl_FEM_DofMgr_DofData.cpp:130
void reset()
Definition cl_FEM_DofMgr_DofData.cpp:71
DofData(DofManager *aParent, Parameters *aParams)
Definition cl_FEM_DofMgr_DofData.cpp:48
bool dof_exists(const id_t aID) const
check if a dof exists, needed for bearing creation
Definition cl_FEM_DofMgr_DofData.hpp:425
void extract_abstract_dofs_from_mesh()
Definition cl_FEM_DofMgr_DofData.cpp:3661
void init_dof_values(const bool aFreeDofsOnly=false)
Definition cl_FEM_DofMgr_DofData.cpp:2413
void disconnect_dofs_from_mesh()
Definition cl_FEM_DofMgr_DofData.cpp:686
void create_field_map(IWG *aIwg)
Definition cl_FEM_DofMgr_DofData.cpp:566
const index_t & my_number_of_fixed_dofs() const
Definition cl_FEM_DofMgr_DofData.hpp:553
Dof * dof(const id_t aID)
Definition cl_FEM_DofMgr_DofData.hpp:417
void reorder_dofs(const Vector< id_t > &aGraphData, Graph &aFreeDofs, Graph &aFixedDofs)
Reorders DOFs to optimize matrix bandwidth for efficient solving.
Definition cl_FEM_DofMgr_DofData.cpp:2807
void connect_dofs_to_mesh()
Definition cl_FEM_DofMgr_DofData.cpp:654
void synchronize_dirichlet_bcs()
Definition cl_FEM_DofMgr_DofData.cpp:2619
id_t node_dof_id(const id_t aNodeID, const uint aDofType) const
Definition cl_FEM_DofMgr_DofData.hpp:441
id_t cell_dof_id(const id_t aCellID, const uint aDofType) const
Definition cl_FEM_DofMgr_DofData.hpp:471
void restore_dof_container(Cell< graph::Vertex * > &aFreeDofs, Cell< graph::Vertex * > &aFixedDofs)
Restores the unified DOF container (mDOFs) from separate free and fixed DOF graphs after reordering i...
Definition cl_FEM_DofMgr_DofData.cpp:2584
Cell< Dof * > & abstract_dofs()
Definition cl_FEM_DofMgr_DofData.hpp:536
const index_t & number_of_free_dofs() const
Definition cl_FEM_DofMgr_DofData.hpp:491
const Vector< index_t > & dof_indices(const uint aProc) const
Definition cl_FEM_DofMgr_DofData.hpp:514
const index_t & number_of_hanging_dofs() const
Definition cl_FEM_DofMgr_DofData.hpp:507
this is a parameter object that contains the relevant information for managing the DOFs
Definition cl_FEM_DofMgr_Parameters.hpp:34
Definition cl_FEM_DofMgr_BearingData.cpp:23
void allocate_dof_containers(Cell< T * > aBasis)
Definition cl_FEM_DofMgr_DofData.hpp:526
Definition cl_IFB_LINE3.hpp:21
USER GUIDES:
Definition cl_Capacitor.cpp:16
Cell< graph::Vertex * > Graph
Definition cl_Graph_Vertex.hpp:331
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
uint32_t index_t
Definition typedefs.hpp:52
#define BELFEM_UINT_MAX
Definition typedefs.hpp:79