BELFEM 0.9.0
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 {
35 class DofData
36 {
38 DofManager * mParent;
39
41 Kernel * mKernel ;
42
44 Mesh * mMesh ;
45
47 Parameters * mParams ;
48
50 const proc_t mCommRank ;
51 const proc_t mCommSize ;
52
54 Cell< Dof * > mDOFs;
55
57 Cell< Dof * > mAbstractDOFs;
58
60 Cell< Dof * > mHangingDOFs ;
61
63 Map< index_t , index_t > mDofTypeToField ;
64
66 Map< id_t, Dof * > mDofMap ;
67
68 id_t mEdgeDofOffset = gNoID ;
69 id_t mFaceDofOffset = gNoID ;
70 id_t mCellDofOffset = gNoID ;
71 id_t mLambdaDofOffset = gNoID ;
72
73 Cell< Vector< index_t > > mDofIndexTables ;
74
75 // system wide dofs. Initialized here: SolverData binds const
76 // references to these at DofManager construction, BEFORE
77 // create_dofs() runs — an early read must see 0, not garbage
78 index_t mNumberOfFreeDofs = 0 ;
79 index_t mNumberOfFixedDofs = 0 ;
80 index_t mNumberOfHangingDofs = 0 ;
81 index_t mMyNumberOfFreeDofs = 0 ;
82 index_t mMyNumberOfFixedDofs = 0 ;
83 index_t mMyNumberOfHangingDofs = 0 ;
84 id_t mNumDofTypes = BELFEM_UINT_MAX ;
85
86//------------------------------------------------------------------------------
87 public:
88//------------------------------------------------------------------------------
89
90 DofData( DofManager * aParent,
91 Parameters * aParams ) ;
92
93//------------------------------------------------------------------------------
94
95 ~DofData() ;
96
97//------------------------------------------------------------------------------
98
99 void
100 create_dofs( IWG * aIWG );
101
102//------------------------------------------------------------------------------
103
104 void
105 create_field_map( IWG * aIwg );
106
107//------------------------------------------------------------------------------
108
113 dofs();
114
115//------------------------------------------------------------------------------
116
121 hanging_dofs();
122
123//----------------------------------------------------------------------------
124
128 bool
129 dof_exists( const id_t aID ) const;
130
131//------------------------------------------------------------------------------
132
133 index_t
134 doftype_to_field_index( const index_t aDofType );
135
136//------------------------------------------------------------------------------
137
138 // access one dof by its id
139 Dof *
140 dof( const id_t aID );
141
142//------------------------------------------------------------------------------
143
144 id_t
146 const id_t aNodeID,
147 const uint aDofType ) const ;
148
149//------------------------------------------------------------------------------
150
151 id_t
153 const id_t aEdgeID,
154 const uint aDofType ) const ;
155
156//------------------------------------------------------------------------------
157
158 id_t
160 const id_t aFaceID,
161 const uint aDofType ) const ;
162
163//------------------------------------------------------------------------------
164
165 id_t
167 const id_t aCellID,
168 const uint aDofType ) const ;
169
170//------------------------------------------------------------------------------
171
172 id_t
174 const id_t aFacetID,
175 const uint aDofType ) const ;
176
177//------------------------------------------------------------------------------
178
184 void
185 init_dof_values( const bool aFreeDofsOnly = false );
186
187//------------------------------------------------------------------------------
188
189 void
191 Cell< graph::Vertex * > & aFreeDofs,
192 Cell< graph::Vertex * > & aFixedDofs );
193
194//------------------------------------------------------------------------------
195
196 void
198 Cell< graph::Vertex * > & aFreeDofs,
199 Cell< graph::Vertex * > & aFixedDofs );
200
201//------------------------------------------------------------------------------
202
203 void
205
206//------------------------------------------------------------------------------
207
208 void
210 const Vector< id_t > & aGraphData,
211 Graph & aFreeDofs,
212 Graph & aFixedDofs );
213
214//------------------------------------------------------------------------------
215
216 const index_t &
217 number_of_free_dofs() const ;
218
219//------------------------------------------------------------------------------
220
221 const index_t &
222 number_of_fixed_dofs() const ;
223
224 const index_t &
225 number_of_hanging_dofs() const ;
226
227//------------------------------------------------------------------------------
228
229 void
230 reset();
231
232//------------------------------------------------------------------------------
233
237 uint
238 num_dofs_per_element( const id_t aBlockID ) const;
239
240//------------------------------------------------------------------------------
241
245 uint
246 num_dofs_per_facet( const id_t aSideSetID ) const;
247
248//------------------------------------------------------------------------------
249
250 const Vector< index_t > &
251 dof_indices( const uint aProc ) const;
252
253//------------------------------------------------------------------------------
254
255 void
257
258//------------------------------------------------------------------------------
259
260 void
262
263//------------------------------------------------------------------------------
264
265 void
267
268//-------------------------------------------------------------------------------
269
270 void
272
273//-------------------------------------------------------------------------------
274
277
278//-------------------------------------------------------------------------------
279
280 void
282
283//-------------------------------------------------------------------------------
284
285 const index_t &
286 my_number_of_free_dofs() const ;
287
288//-------------------------------------------------------------------------------
289
290 const index_t &
292//-------------------------------------------------------------------------------
293
294 const index_t &
296
297//------------------------------------------------------------------------------
298 private:
299//------------------------------------------------------------------------------
300
301 void
302 create_dof_map();
303
304//------------------------------------------------------------------------------
305
309 void
310 compute_max_ids( Vector< id_t > & aMaxEntityIDs );
311
312//-------------------------------------------------------------------------------
313
314 index_t
315 count_node_dofs( IWG * aIWG,
316 Vector< id_t > & aEntityIDs,
317 Vector< index_t > & aDofTypes,
318 Cell< Bitset<BELFEM_MAX_NUMPROCS> > & aProcFlags );
319
320//-----------------------------------------------------------------------------
321
322 index_t
323 count_edge_dofs( IWG * aIWG,
324 Vector< id_t > & aEntityIDs,
325 Vector< index_t > & aDofTypes,
326 Cell< Bitset<BELFEM_MAX_NUMPROCS> > & aProcFlags );
327
328//-----------------------------------------------------------------------------
329
330 index_t
331 count_face_dofs( IWG * aIWG,
332 Vector< id_t > & aEntityIDs,
333 Vector< index_t > & aDofTypes,
334 Cell< Bitset<BELFEM_MAX_NUMPROCS> > & aProcFlags );
335
336//-----------------------------------------------------------------------------
337
338 index_t
339 count_cell_dofs( IWG * aIWG,
340 Vector< id_t > & aEntityIDs,
341 Vector< index_t > & aDofTypes,
342 Cell< Bitset<BELFEM_MAX_NUMPROCS> > & aProcFlags );
343
344//-----------------------------------------------------------------------------
345
346 index_t
347 count_lambda_dofs( IWG * aIWG,
348 Vector< id_t > & aEntityIDs,
349 Vector< index_t > & aDofTypes,
350 Cell< Bitset<BELFEM_MAX_NUMPROCS> > & aProcFlags );
351
352//-----------------------------------------------------------------------------
353
354 index_t
355 count_dofs_for_proc(
356 const index_t aProc,
357 const Vector< id_t > & aDofIDs,
358 const Vector< id_t > & aEntityIDs,
359 const Vector< index_t > & aDofTypes,
360 const Cell< Bitset<BELFEM_MAX_NUMPROCS> > & aProcFlags,
361 Vector< id_t > & aProcDofIDs,
362 Vector< id_t > & aProcEntityIDs,
363 Vector< index_t > & aProcDofTypes );
364
365//-------------------------------------------------------------------------------
366
371 void
372 compute_dof_offsets( IWG * aIWG );
373
374//-------------------------------------------------------------------------------
375
376 void
377 remove_hanging_dofs_from_container();
378
379//-------------------------------------------------------------------------------
384 //void
385 //compute_adjacency(
386 // Dof * aDof,
387 // Cell< Dof * > & aWork,
388 // const bool aFixedFlag );
389
390//-------------------------------------------------------------------------------
391 };
392
393//------------------------------------------------------------------------------
394
395 inline Cell< Dof * > &
397 {
398 return mDOFs ;
399 }
400
401//------------------------------------------------------------------------------
402
403 inline Cell< Dof * > &
405 {
406 return mHangingDOFs ;
407 }
408
409//------------------------------------------------------------------------------
410
411 inline Dof *
412 DofData::dof( const id_t aID )
413 {
414 return mDofMap( aID );
415 }
416
417//------------------------------------------------------------------------------
418
419 inline bool
420 DofData::dof_exists( const id_t aID ) const
421 {
422 return mDofMap.key_exists( aID );
423 }
424
425//------------------------------------------------------------------------------
426
427 inline index_t
429 {
430 return mDofTypeToField( aDofType );
431 }
432
433//------------------------------------------------------------------------------
434
435 inline id_t
437 const id_t aNodeID,
438 const uint aDofType ) const
439 {
440 return aNodeID * mNumDofTypes + aDofType ;
441 }
442
443//------------------------------------------------------------------------------
444
445 inline id_t
447 const id_t aEdgeID,
448 const uint aDofType ) const
449 {
450 return mEdgeDofOffset + aEdgeID * mNumDofTypes + aDofType ;
451 }
452
453//------------------------------------------------------------------------------
454
455 inline id_t
457 const id_t aFaceID,
458 const uint aDofType ) const
459 {
460 return mFaceDofOffset + aFaceID * mNumDofTypes + aDofType ;
461 }
462
463//------------------------------------------------------------------------------
464
465 inline id_t
467 const id_t aCellID,
468 const uint aDofType ) const
469 {
470 return mCellDofOffset + aCellID * mNumDofTypes + aDofType ;
471 }
472
473//------------------------------------------------------------------------------
474
475 inline id_t
477 const id_t aFacetID,
478 const uint aDofType ) const
479 {
480 return mLambdaDofOffset + aFacetID * mNumDofTypes + aDofType ;
481 }
482
483//------------------------------------------------------------------------------
484
485 inline const index_t &
487 {
488 return mNumberOfFreeDofs ;
489 }
490
491//------------------------------------------------------------------------------
492
493 inline const index_t &
495 {
496 return mNumberOfFixedDofs ;
497 }
498
499//------------------------------------------------------------------------------
500
501 inline const index_t &
503 {
504 return mNumberOfHangingDofs ;
505 }
506//------------------------------------------------------------------------------
507
508 inline const Vector< index_t > &
509 DofData::dof_indices( const uint aProc ) const
510 {
511 BELFEM_ASSERT( mDofIndexTables.size() > 0,
512 "DofTables have not been allocated yet");
513
514 return mDofIndexTables( aProc );
515 }
516
517//------------------------------------------------------------------------------
518
519 template< typename T >
520 void
522 {
523 for ( T * tBasis : aBasis )
524 {
525 tBasis->allocate_dof_container();
526 }
527 }
528//------------------------------------------------------------------------------
529
530 inline Cell< Dof * > &
532 {
533 BELFEM_ASSERT( mCommRank == 0, "Abstract dofs can only be accessed by master");
534 return mAbstractDOFs;
535 }
536
537//-------------------------------------------------------------------------------
538
539 inline const index_t &
541 {
542 return mMyNumberOfFreeDofs;
543 }
544
545//-------------------------------------------------------------------------------
546
547 inline const index_t &
549 {
550 return mMyNumberOfFixedDofs;
551 }
552
553//-------------------------------------------------------------------------------
554
555 inline const index_t &
557 {
558 return mMyNumberOfHangingDofs;
559 }
560
561//------------------------------------------------------------------------------
562 } /* end namespace dofmgr */
563
564
565//------------------------------------------------------------------------------
566
567
568 } /* end namespace fem */
569} /* end namespace belfem */
570
571#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
Cell is a wrapper around the standard vector.
Definition cl_Cell.hpp:42
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
this class creates the DOFs based on the passed equation object.
Definition cl_FEM_DofManager.hpp:55
Prototype for Integrator of Weak Form Governing Equation.
Definition cl_IWG.hpp:81
Top-level orchestrator; owns the mesh, materials, boundary conditions and DOF managers.
Definition cl_FEM_Kernel.hpp:50
id_t lambda_dof_id(const id_t aFacetID, const uint aDofType) const
Definition cl_FEM_DofMgr_DofData.hpp:476
void collect_hanging_dofs()
Definition cl_FEM_DofMgr_DofData.cpp:2324
const index_t & my_number_of_hanging_dofs() const
Definition cl_FEM_DofMgr_DofData.hpp:556
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:3439
id_t edge_dof_id(const id_t aEdgeID, const uint aDofType) const
Definition cl_FEM_DofMgr_DofData.hpp:446
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:2933
const index_t & number_of_fixed_dofs() const
Definition cl_FEM_DofMgr_DofData.hpp:494
Cell< Dof * > & hanging_dofs()
expose the hanging dof container
Definition cl_FEM_DofMgr_DofData.hpp:404
const index_t & my_number_of_free_dofs() const
Definition cl_FEM_DofMgr_DofData.hpp:540
index_t doftype_to_field_index(const index_t aDofType)
Definition cl_FEM_DofMgr_DofData.hpp:428
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:3460
void create_dofwise_t_matrices_master()
Definition cl_FEM_DofMgr_DofData.cpp:3470
id_t face_dof_id(const id_t aFaceID, const uint aDofType) const
Definition cl_FEM_DofMgr_DofData.hpp:456
Cell< Dof * > & dofs()
expose the dof container
Definition cl_FEM_DofMgr_DofData.hpp:396
void create_dofs(IWG *aIWG)
Definition cl_FEM_DofMgr_DofData.cpp:108
void reset()
Definition cl_FEM_DofMgr_DofData.cpp:72
DofData(DofManager *aParent, Parameters *aParams)
Definition cl_FEM_DofMgr_DofData.cpp:49
bool dof_exists(const id_t aID) const
check if a dof exists, needed for bearing creation
Definition cl_FEM_DofMgr_DofData.hpp:420
void extract_abstract_dofs_from_mesh()
Definition cl_FEM_DofMgr_DofData.cpp:4136
void init_dof_values(const bool aFreeDofsOnly=false)
Definition cl_FEM_DofMgr_DofData.cpp:2841
void disconnect_dofs_from_mesh()
Definition cl_FEM_DofMgr_DofData.cpp:770
void create_field_map(IWG *aIwg)
Definition cl_FEM_DofMgr_DofData.cpp:648
const index_t & my_number_of_fixed_dofs() const
Definition cl_FEM_DofMgr_DofData.hpp:548
Dof * dof(const id_t aID)
Definition cl_FEM_DofMgr_DofData.hpp:412
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:3266
void connect_dofs_to_mesh()
Definition cl_FEM_DofMgr_DofData.cpp:746
void synchronize_dirichlet_bcs()
Definition cl_FEM_DofMgr_DofData.cpp:3055
id_t node_dof_id(const id_t aNodeID, const uint aDofType) const
Definition cl_FEM_DofMgr_DofData.hpp:436
id_t cell_dof_id(const id_t aCellID, const uint aDofType) const
Definition cl_FEM_DofMgr_DofData.hpp:466
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:3020
Cell< Dof * > & abstract_dofs()
Definition cl_FEM_DofMgr_DofData.hpp:531
const index_t & number_of_free_dofs() const
Definition cl_FEM_DofMgr_DofData.hpp:486
const Vector< index_t > & dof_indices(const uint aProc) const
Definition cl_FEM_DofMgr_DofData.hpp:509
const index_t & number_of_hanging_dofs() const
Definition cl_FEM_DofMgr_DofData.hpp:502
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:521
Definition cl_IFB_LINE3.hpp: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
uint32_t index_t
Definition typedefs.hpp:52
#define BELFEM_UINT_MAX
Definition typedefs.hpp:80