BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_FEM_Dof.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#ifndef BELFEM_CL_FEM_DOF_HPP
12#define BELFEM_CL_FEM_DOF_HPP
13
14#include "typedefs.hpp"
15#include "cl_Graph_Vertex.hpp"
16#include "cl_Node.hpp"
17#include "cl_Edge.hpp"
18#include "cl_Cell.hpp"
19#include "cl_Facet.hpp"
20
21namespace belfem
22{
23//------------------------------------------------------------------------------
24
25 namespace fem
26 {
27 class Dof : public graph::Vertex
28 {
29 // type of the current dof, needed for vectors
30 // temperature: always zero
31 // displacement: 1: ux, 2: uy, 3:uz
32 const uint mTypeID;
33
34 // pointer to node or edge of this flag
35 mesh::Basis * mMeshBasis ;
36
37 // value for multiplicities, needed for parallel
38 const uint mIndexOnEntity ;
39
40 // index of dof on field
41 const index_t mIndexOnField ;
42
43 // index of field on mesh, set by constructor
44 index_t mFieldIndex = gNoIndex ;
45
46 real mDirichletValue = 0.0 ; // BELFEM_QUIET_NAN;
47
48 // tells if a Dirichlet boundary condition is imposed
49 bool mFixedFlag = false;
50
51 // index for DOF on current proc
52 index_t mMyIndex = gNoIndex;
53
54 uint mNumberOfSources = 0 ;
55 Dof ** mSources = nullptr ;
56 real * mCoefficients = nullptr ;
57
58//------------------------------------------------------------------------------
59 public:
60//------------------------------------------------------------------------------
61
62 Dof( const id_t aID, const uint aType, mesh::Node * aNode );
63
64//------------------------------------------------------------------------------
65
66 Dof(
67 const id_t aID,
68 const uint aType,
69 mesh::Edge * aEdge,
70 const uint aIndexOnEdge,
71 const index_t aDofIndexOnField );
72
73//------------------------------------------------------------------------------
74
75 Dof(const id_t aID,
76 const uint aType,
77 mesh::Face * aFace,
78 uint aIndexOnFace,
79 const index_t aDofIndexOnField );
80
81//------------------------------------------------------------------------------
82
83 Dof( const id_t aID,
84 const uint aType,
85 mesh::Element * aElement,
86 const uint aIndexOnElement,
87 const index_t aDofIndexOnField );
88
89//------------------------------------------------------------------------------
90
91 Dof( const id_t aID,
92 const uint aType,
93 mesh::Facet * aFacet ,
94 const uint aIndexOnFacet,
95 const index_t aDofIndexOnField );
96
97//------------------------------------------------------------------------------
98
99 ~Dof() override;
100
101//------------------------------------------------------------------------------
102
103 bool
105
106//------------------------------------------------------------------------------
107
109 mesh_basis();
110
111//------------------------------------------------------------------------------
112
116 mesh::Node *
117 node();
118
119//------------------------------------------------------------------------------
120
124 mesh::Edge *
125 edge();
126
127//------------------------------------------------------------------------------
128
132 mesh::Face *
133 face();
134
135//------------------------------------------------------------------------------
136
141 element();
142
143//------------------------------------------------------------------------------
144
148 void
149 fix( const real aDirichletValue );
150
151//------------------------------------------------------------------------------
152
156 void
157 free();
158
159//------------------------------------------------------------------------------
160
164 bool
165 is_fixed() const;
166
167//------------------------------------------------------------------------------
168
172 bool
173 is_hanging() const;
174
175//------------------------------------------------------------------------------
176
180 bool
181 basis_is_hanging() const;
182
183//------------------------------------------------------------------------------
184
188 bool
189 is_node() const;
190
191//------------------------------------------------------------------------------
192
196 bool
197 is_edge() const;
198
199//------------------------------------------------------------------------------
200
204 bool
205 is_face() const;
206
207//------------------------------------------------------------------------------
208
212 bool
213 is_cell() const;
214
215//------------------------------------------------------------------------------
216
220 bool
221 is_lambda() const;
222
223//------------------------------------------------------------------------------
224
226 entity_type() const ;
227
228//------------------------------------------------------------------------------
229
233 real &
234 value();
235
236//------------------------------------------------------------------------------
237
241 Dof *
242 dof( const uint aIndex );
243
244//------------------------------------------------------------------------------
245
249 uint
250 type_id() const ;
251
252//------------------------------------------------------------------------------
253
257 uint
258 number_of_dofs() const ;
259
260//------------------------------------------------------------------------------
261
265 uint
266 index_on_entity() const ;
267
268//------------------------------------------------------------------------------
269
273 void
274 set_my_index( const index_t aIndex );
275//------------------------------------------------------------------------------
276
277 void
278 set_field_index( const index_t aIndex );
279
280//------------------------------------------------------------------------------
281
286 index_t
287 dof_index_on_field() const ;
288
289//------------------------------------------------------------------------------
290
294 index_t
295 field_index() const ;
296
297//------------------------------------------------------------------------------
298
302 index_t
303 my_index() const;
304
305//------------------------------------------------------------------------------
306
307 void
308 set_sources( Cell< Dof * > & aSources, Vector< real > & aWeights );
309
310 void
311 set_sources( Cell< Dof * > & aSources, Cell< real > & aWeights );
312
313//------------------------------------------------------------------------------
314
315 void
316 set_source( Dof * aSource, const real aWeight);
317
318//------------------------------------------------------------------------------
319
320 void
322
323//------------------------------------------------------------------------------
324
325 uint
326 number_of_sources() const;
327
328//------------------------------------------------------------------------------
329
330 Dof *
331 source( const uint aIndex );
332
333//------------------------------------------------------------------------------
334
335 real
336 weight( const uint aIndex ) const;
337
338//------------------------------------------------------------------------------
339
340 size_t
341 memory() const;
342
343//------------------------------------------------------------------------------
344 };
345
346//------------------------------------------------------------------------------
347
348 inline bool
350 {
351 return mMeshBasis->is_flagged() ;
352 }
353
354//------------------------------------------------------------------------------
355
356 inline mesh::Basis *
358 {
359 return mMeshBasis ;
360 }
361
362//------------------------------------------------------------------------------
363 inline mesh::Node *
365 {
366 BELFEM_ASSERT( this->is_node(),
367 "Tried to access DOF %lu as node, but it is not a node ",
368 ( long unsigned int ) mMyIndex );
369
370 return reinterpret_cast< mesh::Node * >( mMeshBasis ) ;
371 }
372
373//------------------------------------------------------------------------------
374
375 inline mesh::Edge *
377 {
378 BELFEM_ASSERT( this->is_edge(),
379 "Tried to access DOF %lu as edge, but it is not an edge",
380 ( long unsigned int ) mMyIndex );
381
382 return reinterpret_cast< mesh::Edge * >( mMeshBasis ) ;
383 }
384
385//------------------------------------------------------------------------------
386
387 inline mesh::Face *
389 {
390 BELFEM_ASSERT( this->is_face(),
391 "Tried to access DOF %lu as face, but it is not a Face",
392 ( long unsigned int ) mMyIndex );
393
394 return reinterpret_cast< mesh::Face * >( mMeshBasis ) ;
395 }
396
397//------------------------------------------------------------------------------
398
399 inline mesh::Element *
401 {
402 BELFEM_ASSERT( this->is_cell(),
403 "Tried to access DOF %lu as element, but it is not an element ",
404 ( long unsigned int ) mMyIndex );
405
406 return reinterpret_cast< mesh::Element * >( mMeshBasis );
407 }
408
409//------------------------------------------------------------------------------
410
411 inline void
412 Dof::fix( const real aDirichletValue )
413 {
414 mFixedFlag = true;
415 mDirichletValue = aDirichletValue;
416 }
417
418//------------------------------------------------------------------------------
419
420 inline void
422 {
423 mFixedFlag = false;
424 mDirichletValue = BELFEM_QUIET_NAN;
425 }
426
427//------------------------------------------------------------------------------
428
429 inline bool
431 {
432 return mFixedFlag;
433 }
434
435//------------------------------------------------------------------------------
436
437 inline bool
439 {
440 return mNumberOfSources > 0 ;
441 }
442
443//------------------------------------------------------------------------------
444
445 inline bool
447 {
448 return mMeshBasis->is_hanging() ;
449 }
450
451//------------------------------------------------------------------------------
452
453 inline bool
455 {
456 return mMeshBasis->entity_type() == EntityType::NODE ;
457 }
458
459//------------------------------------------------------------------------------
460
461 inline EntityType
463 {
464 return mMeshBasis->entity_type() ;
465 }
466
467
468//------------------------------------------------------------------------------
469
470 inline bool
472 {
473 return mMeshBasis->entity_type() == EntityType::EDGE ;
474 }
475
476//------------------------------------------------------------------------------
477
478 inline bool
480 {
481 return mMeshBasis->entity_type() == EntityType::FACE ;
482 }
483
484//------------------------------------------------------------------------------
485
486 inline bool
488 {
489 return mMeshBasis->entity_type() == EntityType::CELL ;
490 }
491
492//------------------------------------------------------------------------------
493
494 inline bool
496 {
497 return mMeshBasis->entity_type() == EntityType::FACET ;
498 }
499
500//------------------------------------------------------------------------------
501
502 inline real &
504 {
505 return mDirichletValue;
506 }
507
508//------------------------------------------------------------------------------
509
510 inline Dof *
511 Dof::dof( const uint aIndex )
512 {
514 "Index %u for DOF %lu out of bounds. ( must be less than %u )",
515 ( unsigned int ) aIndex,
516 ( long unsigned int ) this->id(),
517 ( unsigned int ) mVertexCounter );
518
519 return reinterpret_cast< Dof * >( mVertices[ aIndex ] );
520 }
521
522//------------------------------------------------------------------------------
523
524 inline uint
526 {
527 return mTypeID;
528 }
529
530//------------------------------------------------------------------------------
531
532 inline void
534 {
535 mMyIndex = aIndex ;
536 }
537
538//------------------------------------------------------------------------------
539
540 inline uint
542 {
543 return this->number_of_vertices();
544 }
545
546//------------------------------------------------------------------------------
547
548 inline uint
550 {
551 return mIndexOnEntity ;
552 }
553
554//------------------------------------------------------------------------------
555
556 inline void
558 {
559 mFieldIndex = aIndex ;
560 }
561
562//------------------------------------------------------------------------------
563
564 inline index_t
566 {
567 return mIndexOnField ;
568 }
569
570//------------------------------------------------------------------------------
571
572 inline index_t
574 {
575 return mFieldIndex ;
576 }
577
578//------------------------------------------------------------------------------
579
580 inline index_t
582 {
583 return mMyIndex;
584 }
585
586//------------------------------------------------------------------------------
587
588 inline uint
590 {
591 return mNumberOfSources ;
592 }
593
594//------------------------------------------------------------------------------
595
596 inline Dof *
597 Dof::source( const uint aIndex )
598 {
599 BELFEM_ASSERT( aIndex < mNumberOfSources,
600 "Source index %u out of range for dof %lu (must be < %u).",
601 ( unsigned int ) aIndex,
602 ( long unsigned int ) this->id(),
603 ( unsigned int ) mNumberOfSources );
604
605 return mSources[ aIndex ];
606 }
607
608//------------------------------------------------------------------------------
609
610 inline real
611 Dof::weight( const uint aIndex ) const
612 {
613 BELFEM_ASSERT( aIndex < mNumberOfSources,
614 "Source index %u out of range for dof %lu (must be < %u).",
615 ( unsigned int ) aIndex,
616 ( long unsigned int ) this->id(),
617 ( unsigned int ) mNumberOfSources );
618 return mCoefficients[ aIndex ];
619 }
620
621//------------------------------------------------------------------------------
622 }
623}
624
625#endif //BELFEM_CL_FEM_DOF_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Cell is a wrapper around the standard vector.
Definition cl_Cell.hpp:42
Definition cl_FEM_Dof.hpp:28
void fix(const real aDirichletValue)
impose a Diriclet boundary condition on this node
Definition cl_FEM_Dof.hpp:412
Dof * source(const uint aIndex)
Definition cl_FEM_Dof.hpp:597
void reset_sources()
Definition cl_FEM_Dof.cpp:190
void set_sources(Cell< Dof * > &aSources, Vector< real > &aWeights)
Definition cl_FEM_Dof.cpp:114
real & value()
return the Dirichlet value
Definition cl_FEM_Dof.hpp:503
bool basis_is_hanging() const
tells if basis of dof is hanging, needed during initialization
Definition cl_FEM_Dof.hpp:446
void free()
free this dof ( remove Diriclet condition )
Definition cl_FEM_Dof.hpp:421
bool is_cell() const
returns true if this dof is linked to a cell ( element-interior dof )
Definition cl_FEM_Dof.hpp:487
uint number_of_dofs() const
how many dofs are connected to this dof
Definition cl_FEM_Dof.hpp:541
void set_field_index(const index_t aIndex)
Definition cl_FEM_Dof.hpp:557
bool is_node() const
returns true if this dof is linked to a node
Definition cl_FEM_Dof.hpp:454
bool mesh_basis_is_flagged()
Definition cl_FEM_Dof.hpp:349
mesh::Face * face()
expose the face that is linked to this dof
Definition cl_FEM_Dof.hpp:388
bool is_fixed() const
tells if this dof is fixed
Definition cl_FEM_Dof.hpp:430
size_t memory() const
Definition cl_FEM_Dof.cpp:204
index_t field_index() const
returns the index of the field on the mesh
Definition cl_FEM_Dof.hpp:573
real weight(const uint aIndex) const
Definition cl_FEM_Dof.hpp:611
void set_my_index(const index_t aIndex)
set proc local index
Definition cl_FEM_Dof.hpp:533
EntityType entity_type() const
Definition cl_FEM_Dof.hpp:462
index_t dof_index_on_field() const
returns the corresponding index of the dof on the field
Definition cl_FEM_Dof.hpp:565
index_t my_index() const
get proc local index
Definition cl_FEM_Dof.hpp:581
bool is_hanging() const
tells if this dof is hanging
Definition cl_FEM_Dof.hpp:438
bool is_face() const
returns true if this dof is linked to a face
Definition cl_FEM_Dof.hpp:479
Dof * dof(const uint aIndex)
access a dof
Definition cl_FEM_Dof.hpp:511
mesh::Edge * edge()
expose the edge that is linked to this dof
Definition cl_FEM_Dof.hpp:376
uint type_id() const
return the type of this dof
Definition cl_FEM_Dof.hpp:525
void set_source(Dof *aSource, const real aWeight)
Definition cl_FEM_Dof.cpp:176
mesh::Basis * mesh_basis()
Definition cl_FEM_Dof.hpp:357
bool is_edge() const
returns true if this dof is linked to an edge
Definition cl_FEM_Dof.hpp:471
Dof(const id_t aID, const uint aType, mesh::Node *aNode)
Definition cl_FEM_Dof.cpp:20
bool is_lambda() const
returns true if this dof is linked to a facet
Definition cl_FEM_Dof.hpp:495
mesh::Node * node()
expose the node that is linked to this dof
Definition cl_FEM_Dof.hpp:364
uint index_on_entity() const
local index on mesh entity
Definition cl_FEM_Dof.hpp:549
mesh::Element * element()
expose the element that is linked to this dof
Definition cl_FEM_Dof.hpp:400
uint number_of_sources() const
Definition cl_FEM_Dof.hpp:589
Graph node with an adjacency list; the vertex type the graph algorithms operate on.
Definition cl_Graph_Vertex.hpp:32
Vertex ** mVertices
Definition cl_Graph_Vertex.hpp:58
uint32_t mVertexCounter
Definition cl_Graph_Vertex.hpp:55
uint number_of_vertices() const
Definition cl_Graph_Vertex.hpp:321
Definition cl_Mesh_Basis.hpp:33
Special Edge class for NEDELEC-Type elements.
Definition cl_Edge.hpp:30
Definition cl_Face.hpp:29
Definition cl_Facet.hpp:24
Definition cl_IFB_LINE3.hpp:21
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30
unsigned int id_t
Definition typedefs.hpp:41
EntityType
Definition Mesh_Enums.hpp:116
@ NODE
Definition Mesh_Enums.hpp:117
@ FACE
Definition Mesh_Enums.hpp:119
@ EDGE
Definition Mesh_Enums.hpp:118
@ FACET
Definition Mesh_Enums.hpp:121
@ CELL
Definition Mesh_Enums.hpp:120
constexpr index_t gNoIndex
Definition typedefs.hpp:57
uint32_t index_t
Definition typedefs.hpp:52
double real
Definition typedefs.hpp:36
Definition Element.py:1
Definition Node.py:1
#define BELFEM_QUIET_NAN
Definition typedefs.hpp:87