BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_FEM_Kernel.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_KERNEL_HPP
13#define BELFEM_CL_FEM_KERNEL_HPP
14
15#include "typedefs.hpp"
16#include "cl_Vector.hpp"
17#include "cl_Matrix.hpp"
18#include "cl_Mesh.hpp"
19#include "cl_Cell.hpp"
20#include "cl_Map.hpp"
21#include "cl_Material.hpp"
22
23#include "cl_FEM_Dof.hpp"
25#include "cl_FEM_Block.hpp"
28
29#include "cl_FEM_DofManager.hpp"
30#include "cl_CommTable.hpp"
31#include "en_IWGs.hpp"
32
33namespace belfem
34{
35//------------------------------------------------------------------------------
36
37 namespace fem
38 {
39 class IwgFactory ;
40
41 class Controller ;
42
49 class Kernel
50 {
51 // rank of this proc
52 const proc_t mCommRank;
53
54 // how many procs contribute to this kernel
55 const proc_t mCommSize;
56
57 // pointer to parameter list
58 KernelParameters * mParams;
59
60 // pointer to mesh (points to empty mesh unless root kernel)
61 Mesh * mMesh;
62
63 // offset for fields, in case fields already exist on mesh
64 // when Kernel is generated
65 const uint mFieldOffset ;
66
67 // submesh ( points to local mesh unless this is root)
68 Mesh * mSubMesh = nullptr;
69
70 Controller * mController = nullptr ;
71
72
73 // flag telling if the kernel destroys the parameters on exit
74 bool mOwnParameters = false ;
75
76 proc_t mMyCommIndex = 0 ;
77
78 Vector< index_t > mNumElementsPerBlock;
79
80 Cell< DofManager * > mDofManagers ;
81 Cell< IWG * > mIWGs ;
82
83 Cell< Material * > mMaterials;
84 Map< string, Material * > mMaterialMap;
85
86 Cell< PhysicalBoundaryCondition * > mBoundaryConditions ;
87
89
90 bool mOwnCommTables = false ;
91 bool mOwnMesh = false ;
92 bool mOwnSubmesh = false ;
93
94//------------------------------------------------------------------------------
95 public:
96//------------------------------------------------------------------------------
97
98 Kernel( KernelParameters * aKernelParameters );
99
100//------------------------------------------------------------------------------
101
102 ~Kernel();
103
104//------------------------------------------------------------------------------
105
109 const KernelParameters *
110 params();
111
112//------------------------------------------------------------------------------
113
117 DofManager *
118 dofmgr( const uint aIndex=0 );
119
120//------------------------------------------------------------------------------
121
127 Material *
128 material( const string & aLabel );
129
130//------------------------------------------------------------------------------
131
136 void
137 add_material( const string aLabel, Material * aMaterial );
138
139//------------------------------------------------------------------------------
140
145 void
147
148//------------------------------------------------------------------------------
149
155
156//------------------------------------------------------------------------------
157
163
164//------------------------------------------------------------------------------
165
169 void
171
172//------------------------------------------------------------------------------
173
174
175 const mesh::CommTable *
176 comm_table( const uint aProc ) const ;
177
179 comm_tables() const ;
180
181//------------------------------------------------------------------------------
182
183 const proc_t &
184 number_of_procs() const ;
185
186//------------------------------------------------------------------------------
187
191 const uint &
192 field_offset() const ;
193
194//------------------------------------------------------------------------------
195
201 Mesh *
202 mesh();
203
204//------------------------------------------------------------------------------
205
206 IWG *
207 create_equation( const IwgType aEquationType,
208 const ModelDimensionality aModelDimensionality = ModelDimensionality::UNDEFINED,
209 const Vector< id_t > aBlocks={},
210 const Vector< id_t > aSideSets={} );
211
212//------------------------------------------------------------------------------
213
219 void
220 add_equation( IWG * aEquation );
221
222//------------------------------------------------------------------------------
223
224 DofManager *
225 create_field( IWG * aEquation );
226
227//------------------------------------------------------------------------------
228
229 bool
230 is_master() const ;
231
232//------------------------------------------------------------------------------
233
237 void
238 claim_parameter_ownership( const bool aFlag = true );
239
240//------------------------------------------------------------------------------
241
242 void
243 set_controller( Controller * aController );
244
245//------------------------------------------------------------------------------
246
247 Controller *
248 controller() ;
249
250//------------------------------------------------------------------------------
251
257 bool
258 has_controller() const ;
259
260//------------------------------------------------------------------------------
261
262 // make sure that all elements have positive volume
263 void
265
266//------------------------------------------------------------------------------
267
268 uint
269 number_of_dof_managers() const ;
270
271//------------------------------------------------------------------------------
272 private:
273//------------------------------------------------------------------------------
274
278 void
279 distribute_mesh();
280
281//------------------------------------------------------------------------------
282
288 void
289 create_dof_graph( Cell< Dof * > & aGraph );
290
291//------------------------------------------------------------------------------
292
302 void
303 collect_elements(
304 const Vector< id_t > & aBlockIDs,
305 const Vector< id_t > & aSideSetIDs,
306 Cell< mesh::Element * > & aElements );
307
308
309//------------------------------------------------------------------------------
310
312 get_entity( const id_t aID, const EntityType aType ) ;
313
314//------------------------------------------------------------------------------
315
316 void
317 partition_mesh();
318
319//------------------------------------------------------------------------------
320 };
321//------------------------------------------------------------------------------
322
323 inline const mesh::CommTable *
324 Kernel::comm_table( const uint aProc ) const
325 {
326 BELFEM_ASSERT( mCommRank == 0, "Only master may call the comm table." );
327 return mCommTables( aProc );
328 }
329
332 {
333 return mCommTables ;
334 }
335
336 inline const proc_t &
338 {
339 return mCommSize ;
340 }
341
342//------------------------------------------------------------------------------
343
344 inline const uint &
346 {
347 return mFieldOffset ;
348 }
349
350//------------------------------------------------------------------------------
351
354 {
355 return mBoundaryConditions ;
356 }
357
358//------------------------------------------------------------------------------
359
362 {
363 for ( PhysicalBoundaryCondition* tBC : mBoundaryConditions )
364 {
365 for (id_t tID : tBC->domains())
366 {
367 if (tID == aID)
368 {
369 return tBC ;
370 }
371 }
372 }
373 BELFEM_ERROR(false, "Sideset is not associated to a boundary contition") ;
374 return nullptr ;
375 }
376
377//------------------------------------------------------------------------------
378
379 inline Mesh *
381 {
382 return mCommRank == 0 ? mMesh : mSubMesh ;
383 }
384
385//------------------------------------------------------------------------------
386
387 inline uint
389 {
390 return mDofManagers.size();
391 }
392
393//------------------------------------------------------------------------------
394
395 inline bool
397 {
398 return mCommRank == 0 ;
399 }
400
401//------------------------------------------------------------------------------
402
403 inline bool
405 {
406 return mController != nullptr ;
407 }
408
409//------------------------------------------------------------------------------
410
411 inline mesh::Basis *
412 Kernel::get_entity( const id_t aID, const EntityType aType )
413 {
414 switch( aType )
415 {
416 case( EntityType::NODE ) :
417 {
418 return this->mesh()->node( aID );
419 }
420 case( EntityType::EDGE ) :
421 {
422 return this->mesh()->edge( aID );
423 }
424 case( EntityType::FACE ) :
425 {
426 return this->mesh()->face( aID );
427 }
428 case( EntityType::FACET ) :
429 {
430 return this->mesh()->facet( aID );
431 }
432 case( EntityType::ELEMENT ) :
433 {
434 return this->mesh()->element( aID );
435 }
436 default:
437 {
438 BELFEM_ERROR( false, "Invalid entity type");
439 return nullptr ;
440 }
441 }
442 }
443
444 }
445//------------------------------------------------------------------------------
446}
447#endif //BELFEM_CL_FEM_KERNEL_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
Hash map (unordered key-value).
Definition cl_Map.hpp:75
Base class for all materials in BELFEM.
Definition cl_Material.hpp:279
Top-level container for all mesh entities.
Definition cl_Mesh.hpp:60
mesh::Facet * facet(const id_t aID)
Definition cl_Mesh.hpp:1428
mesh::Element * element(const id_t aID)
Definition cl_Mesh.hpp:1352
Nonlinear iteration controller: relaxation, timestep adaptation and convergence policy.
Definition cl_FEM_Controller.hpp:38
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
Creates IWG instances by equation type.
Definition cl_IwgFactory.hpp:30
Cell< PhysicalBoundaryCondition * > & boundary_conditions()
expose the boundary condition container
Definition cl_FEM_Kernel.hpp:353
Kernel(KernelParameters *aKernelParameters)
Definition cl_FEM_Kernel.cpp:46
const Cell< const mesh::CommTable * > & comm_tables() const
Definition cl_FEM_Kernel.hpp:331
const KernelParameters * params()
expose parameter object
Definition cl_FEM_Kernel.cpp:641
PhysicalBoundaryCondition * boundary_condition(id_t aID)
expose a boundary condition for a specific sideset ID
Definition cl_FEM_Kernel.hpp:361
bool is_master() const
Definition cl_FEM_Kernel.hpp:396
Material * material(const string &aLabel)
returns the material object registered under aLabel ( add_material ).
Definition cl_FEM_Kernel.cpp:745
Controller * controller()
Definition cl_FEM_Kernel.cpp:1209
void compute_element_volumes()
Definition cl_FEM_Kernel.cpp:865
bool has_controller() const
true once set_controller() has attached a Controller; callers that may legitimately run without one a...
Definition cl_FEM_Kernel.hpp:404
IWG * create_equation(const IwgType aEquationType, const ModelDimensionality aModelDimensionality=ModelDimensionality::UNDEFINED, const Vector< id_t > aBlocks={}, const Vector< id_t > aSideSets={})
Definition cl_FEM_Kernel.cpp:549
void claim_parameter_ownership(const bool aFlag=true)
if this flag is set, the kernel will destroy the parameters
Definition cl_FEM_Kernel.cpp:793
void set_controller(Controller *aController)
Definition cl_FEM_Kernel.cpp:1201
DofManager * create_field(IWG *aEquation)
Definition cl_FEM_Kernel.cpp:612
uint number_of_dof_managers() const
Definition cl_FEM_Kernel.hpp:388
DofManager * dofmgr(const uint aIndex=0)
expose a field
Definition cl_FEM_Kernel.cpp:737
void add_material(const string aLabel, Material *aMaterial)
manually add a material to the kernel.
Definition cl_FEM_Kernel.cpp:758
void compute_boundary_conditions(real aTime)
Compute the boundary condition and update the Dofs at a given time.
Definition cl_FEM_Kernel.cpp:782
const uint & field_offset() const
returns the number of fields that existed before Kernel was created
Definition cl_FEM_Kernel.hpp:345
Mesh * mesh()
returns the mesh on the master and the submesh on other
Definition cl_FEM_Kernel.hpp:380
void add_boundary_condition(PhysicalBoundaryCondition *aBC)
manually add the BCs to the kernel.
Definition cl_FEM_Kernel.cpp:773
const proc_t & number_of_procs() const
Definition cl_FEM_Kernel.hpp:337
const mesh::CommTable * comm_table(const uint aProc) const
Definition cl_FEM_Kernel.hpp:324
void add_equation(IWG *aEquation)
special function to add an equation that has already been created.
Definition cl_FEM_Kernel.cpp:604
Definition cl_FEM_KernelParameters.hpp:29
Definition cl_FEM_PhysicalBoundaryCondition.hpp:37
Definition cl_Mesh_Basis.hpp:33
Definition cl_CommTable.hpp:25
Definition cl_IFB_LINE3.hpp:21
USER GUIDES:
Definition cl_Capacitor.cpp:16
IwgType
Definition en_IWGs.hpp:64
unsigned int uint
Definition typedefs.hpp:30
unsigned int id_t
Definition typedefs.hpp:41
ModelDimensionality
Definition en_IWGs.hpp:20
@ UNDEFINED
Definition en_IWGs.hpp:25
int proc_t
Definition commtypes.hpp:29
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
@ ELEMENT
Definition Mesh_Enums.hpp:122
double real
Definition typedefs.hpp:36
Definition __init__.py:1