BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_FEM_Postprocessor.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, through
4 * 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_POSTPROCESSOR_HPP
13#define BELFEM_CL_FEM_POSTPROCESSOR_HPP
14
15#include "typedefs.hpp"
16#include "cl_Mesh.hpp"
17#include "cl_FEM_Kernel.hpp"
18
19namespace belfem
20{
21 namespace fem
22 {
24 {
25
26 protected:
30 const uint mOrder ;
31 private:
32
33 // block IDs used on this post processor
34 Cell< id_t > mBlockIDs ;
35
36 Cell< index_t > mMyNodeIndices ;
37 Cell< index_t > mMyOwnedNodeIndices ;
38 Cell< index_t > mMyElementIndices ;
39 Cell< index_t > mMyEdgeIndices ;
40 Cell< index_t > mMyFaceIndices ;
41
42 Cell< Vector< index_t > > mAllNodeIndices ;
43 Cell< Vector< index_t > > mAllOwnedNodeIndices ;
44
45 Cell< Vector< index_t > > mAllEdgeIndices ;
46 Cell< Vector< index_t > > mAllFaceIndices ;
47
48 // vector with polynomial coefficients
49 // we use a matrix so that we can use the trans() function
50 Matrix< real > mPoly ;
51
52 DynamicBitset * mNodeBitset = nullptr ;
53 DynamicBitset * mEdgeBitset = nullptr ;
54 DynamicBitset * mFaceBitset = nullptr ;
55 DynamicBitset * mElementBitset = nullptr ;
56
57 void
58 ( Postprocessor::*mFunComputePoly )( const Vector< real > & aX );
59
60 void
61 ( Postprocessor::*mFunPoly2D )( const real x, const real y );
62
63 void
64 ( Postprocessor::*mFunPoly3D )( const real x, const real y, const real z );
65
66 bool mIsInitialized = false ;
67
68 bool mHaveEdges = false ;
69 bool mHaveFaces = false ;
70
71 ElementType mElementType = ElementType::EMPTY ;
72 id_t mLastElementID = gNoID ;
73 id_t mLastBlockID = gNoID ;
74 Matrix< real > mVandermonde ;
75 Map< mesh::Node * , Matrix< real > * > mNodeMatrices ;
76
77 //Cell< Matrix< real > > mNodeCoefficients ;
78
79 uint mNumCoefficients = 0 ;
80
81 Vector< real > mNull ;
82
83 protected:
84
86
87
92
93 Kernel * mKernel = nullptr;
94 Mesh * mMesh = nullptr;
95 DofManager * mField = nullptr;
96 IWG * mEquation = nullptr;
97 Material * mMaterial = nullptr;
98 Element * mElement = nullptr ;
99 Block * mBlock = nullptr ;
101
102//------------------------------------------------------------------------------
103 public:
104//------------------------------------------------------------------------------
105
106 Postprocessor( Kernel * aKernel , DofManager * aField = nullptr );
107
108 virtual ~Postprocessor() ;
109
110 void
111 set_field( DofManager * aField );
112
113 void
114 set_source_fields( const Cell< string > & aFields );
115
116 void
117 set_target_fields( const Cell< string > & aFields );
118
119 const Cell< string > &
120 source_fields() const ;
121
122 const Cell< string > &
123 target_fields() const ;
124
125 void
126 set_block_ids( const Vector< id_t > & aBlockIDs );
127
128 void
129 set_block_ids( const Cell< id_t > & aBlockIDs );
130
131 virtual void
132 initialize();
133
134 void
136
137 void
139
140 virtual void
141 run();
142
143 DofManager *
144 projector() ;
145
146//------------------------------------------------------------------------------
147 protected:
148//------------------------------------------------------------------------------
149
150 const Matrix< real > &
151 compute_poly( const Vector< real > & aX );
152
153 void
155
156 virtual const Vector< real > &
157 compute( const uint aK );
158
159 virtual void
161
162 const Cell< id_t > &
163 block_ids() const ;
164
165 // needed for maxwell postproc
166 // to create element fields
167 const Cell< index_t > &
168 my_element_indices() const ;
169
170//------------------------------------------------------------------------------
171 private:
172//------------------------------------------------------------------------------
173
174 void
175 create_target_fields();
176
177 void
178 check_if_we_have_edges_and_faces();
179
180 void
181 select_elements_and_owned_nodes();
182
183 void
184 select_all_relevant_nodes();
185
186 void
187 synch_node_indices( const bool aOwnedOnly );
188
189 void
190 select_edges();
191
192 void
193 select_faces();
194
195 void
196 select_polynomial();
197
198 // funciton needed by constructor
199 uint
200 get_interpolation_order( const Mesh * aMesh ) const;
201
202 void
203 compute_node_matrices();
204
205 void
206 compute_element_coeffs(
207 mesh::Node * aNode,
208 Matrix< real > & aNodeCoords,
209 Map< mesh::Element*, Matrix< real > * > & aElementData );
210
211
212 void
213 compute_element_coeffs(
214 mesh::Element * aElement,
215 Matrix< real > & aNodeCoords,
216 Map< mesh::Element*, Matrix< real > * > & aElementData );
217
218 void
219 check_element_coeffs_done( mesh::Element * aElement, Map< mesh::Element*, Matrix< real > * > & aElementData );
220
221 void
222 synch_source_field( const string & aField );
223
224//------------------------------------------------------------------------------
225// EVALUATION ROUTINES
226//------------------------------------------------------------------------------
227
228 void
229 compute_poly_2d( const Vector< real > & aX );
230
231 void
232 compute_poly_3d( const Vector< real > & aX );
233
234 void
235 poly1_2d( const real x, const real y );
236
237 void
238 poly2_2d( const real x, const real y );
239
240 void
241 poly3_2d( const real x, const real y );
242
243 void
244 poly4_2d( const real x, const real y );
245
246 void
247 poly1_3d( const real x, const real y, const real z );
248
249 void
250 poly2_3d( const real x, const real y, const real z );
251
252 void
253 poly3_3d( const real x, const real y, const real z );
254
255 void
256 poly4_3d( const real x, const real y, const real z );
257 };
258
259 inline
260 DofManager *
262 {
263 return mField;
264 }
265
266 inline void
268 {
269 mSourceFields = aFields ;
270 mNumSourceFields = aFields.size() ;
271 }
272
273 inline void
275 {
276 mTargetFields = aFields ;
277 mNumTargetFields = aFields.size() ;
278 }
279
280 inline const Cell< string > &
282 {
283 return mSourceFields;
284 }
285
286 inline const Cell< string > &
288 {
289 return mTargetFields;
290 }
291
292 inline const Matrix< real > &
294 {
295 (this->*mFunComputePoly)( aX );
296 return mPoly;
297 }
298
299 inline void
300 Postprocessor::compute_poly_2d( const Vector< real > & aX )
301 {
302 (this->*mFunPoly2D )( aX( 0 ), aX( 1 ) );
303 }
304
305 inline void
306 Postprocessor::compute_poly_3d( const Vector< real > & aX )
307 {
308 (this->*mFunPoly3D )( aX( 0 ), aX( 1 ), aX( 2 ) );
309 }
310
311 inline void
312 Postprocessor::poly1_2d( const real x, const real y )
313 {
314 mPoly( 0, 0 ) = 1.0 ;
315 mPoly( 1, 0 ) = x ;
316 mPoly( 2, 0 ) = y ;
317 }
318
319 inline void
320 Postprocessor::poly2_2d( const real x, const real y )
321 {
322 mPoly( 0, 0 ) = 1.0 ;
323 mPoly( 1, 0 ) = x ;
324 mPoly( 2, 0 ) = y ;
325 mPoly( 3, 0 ) = x*x ;
326 mPoly( 4, 0 ) = x*y ;
327 mPoly( 5, 0 ) = y*y ;
328 }
329
330 inline void
331 Postprocessor::poly3_2d( const real x, const real y )
332 {
333 mPoly( 0, 0 ) = 1.0 ;
334 mPoly( 1, 0 ) = x ;
335 mPoly( 2, 0 ) = y ;
336 mPoly( 3, 0 ) = x*x ;
337 mPoly( 4, 0 ) = x*y ;
338 mPoly( 5, 0 ) = y*y ;
339 mPoly( 6, 0 ) = mPoly( 3, 0 )*x ;
340 mPoly( 7, 0 ) = mPoly( 3, 0 )*y ;
341 mPoly( 8, 0 ) = x * mPoly( 5, 0 );
342 mPoly( 9, 0 ) = y * mPoly( 5, 0 );
343 }
344
345 inline void
346 Postprocessor::poly4_2d( const real x, const real y )
347 {
348 mPoly( 0, 0 ) = 1.0 ;
349 mPoly( 1, 0 ) = x ;
350 mPoly( 2, 0 ) = y ;
351 mPoly( 3, 0 ) = x*x ;
352 mPoly( 4, 0 ) = x*y ;
353 mPoly( 5, 0 ) = y*y ;
354 mPoly( 6, 0 ) = mPoly( 3, 0 )*x ; // x^3
355 mPoly( 7, 0 ) = mPoly( 3, 0 )*y ; // x^2 * y
356 mPoly( 8, 0 ) = x * mPoly( 5, 0 ); // x * y^2
357 mPoly( 9, 0 ) = y * mPoly( 5, 0 ); // y^3
358 mPoly( 10, 0 ) = mPoly( 3, 0 ) * mPoly( 3, 0 ); // x^4
359 mPoly( 11, 0 ) = mPoly( 6, 0 ) * y ; // x^3 * y
360 mPoly( 12, 0 ) = mPoly( 3, 0 ) * mPoly( 5, 0 ) ; // x^2*y^2
361 mPoly( 13, 0 ) = x * mPoly( 9, 0 ) ; // x * y^3
362 mPoly( 14, 0 ) = mPoly( 5, 0 ) * mPoly( 5, 0 ) ; // y^4
363 }
364
365 inline void
366 Postprocessor::poly1_3d( const real x, const real y, const real z )
367 {
368 mPoly( 0, 0 ) = 1.0 ;
369 mPoly( 1, 0 ) = x ;
370 mPoly( 2, 0 ) = y ;
371 mPoly( 3, 0 ) = z ;
372 }
373
374 inline void
375 Postprocessor::poly2_3d( const real x, const real y, const real z )
376 {
377 mPoly( 0, 0 ) = 1.0 ;
378 mPoly( 1, 0 ) = x ;
379 mPoly( 2, 0 ) = y ;
380 mPoly( 3, 0 ) = z ;
381 mPoly( 4, 0 ) = x*x ;
382 mPoly( 5, 0 ) = x*y ;
383 mPoly( 6, 0 ) = y*y ;
384 mPoly( 7, 0 ) = y*z ;
385 mPoly( 8, 0 ) = z*z ;
386 mPoly( 9, 0 ) = z*x ;
387 }
388
389 inline void
390 Postprocessor::poly3_3d( const real x, const real y, const real z )
391 {
392 mPoly( 0, 0 ) = 1.0 ;
393 mPoly( 1, 0 ) = x ;
394 mPoly( 2, 0 ) = y ;
395 mPoly( 3, 0 ) = z ;
396 mPoly( 4, 0 ) = x*x ;
397 mPoly( 5, 0 ) = x*y ;
398 mPoly( 6, 0 ) = y*y ;
399 mPoly( 7, 0 ) = y*z ;
400 mPoly( 8, 0 ) = z*z ;
401 mPoly( 9, 0 ) = z*x ;
402 mPoly( 10, 0 ) = mPoly( 4, 0 ) * x ; // x^3
403 mPoly( 11, 0 ) = mPoly( 4, 0 ) * y ; // x^2 * y
404 mPoly( 12, 0 ) = x * mPoly( 6, 0 ) ; // x * y^2 ;
405 mPoly( 13, 0 ) = y * mPoly( 6, 0 ) ; // y^3
406 mPoly( 14, 0 ) = z * mPoly( 6, 0 ) ; // y^2 * z
407 mPoly( 15, 0 ) = y * mPoly( 8, 0 ) ; // y * z^2
408 mPoly( 16, 0 ) = z * mPoly( 8, 0 ) ; // z^3
409 mPoly( 17, 0 ) = x * mPoly( 8, 0 ) ; // z^2 * x
410 mPoly( 18, 0 ) = mPoly( 4, 0 ) * z ; // x^2 * z
411 mPoly( 19, 0 ) = x * y * z ;
412 }
413
414 inline void
415 Postprocessor::poly4_3d( const real x, const real y, const real z )
416 {
417 mPoly( 0, 0 ) = 1.0 ;
418 mPoly( 1, 0 ) = x ;
419 mPoly( 2, 0 ) = y ;
420 mPoly( 3, 0 ) = z ;
421 mPoly( 4, 0 ) = x*x ;
422 mPoly( 5, 0 ) = x*y ;
423 mPoly( 6, 0 ) = y*y ;
424 mPoly( 7, 0 ) = y*z ;
425 mPoly( 8, 0 ) = z*z ;
426 mPoly( 9, 0 ) = z*x ;
427 mPoly( 10, 0 ) = mPoly( 4, 0 ) * x ; // x^3
428 mPoly( 11, 0 ) = mPoly( 4, 0 ) * y ; // x^2 * y
429 mPoly( 12, 0 ) = x * mPoly( 6, 0 ) ; // x * y^2 ;
430 mPoly( 13, 0 ) = y * mPoly( 6, 0 ) ; // y^3
431 mPoly( 14, 0 ) = z * mPoly( 6, 0 ) ; // y^2 * z
432 mPoly( 15, 0 ) = y * mPoly( 8, 0 ) ; // y * z^2
433 mPoly( 16, 0 ) = z * mPoly( 8, 0 ) ; // z^3
434 mPoly( 17, 0 ) = x * mPoly( 8, 0 ) ; // z^2 * x
435 mPoly( 18, 0 ) = mPoly( 4, 0 ) * z ; // x^2 * z
436 mPoly( 19, 0 ) = x * y * z ;
437 mPoly( 20, 0 ) = mPoly( 4, 0 ) * mPoly( 4, 0 ) ; // x^4
438 mPoly( 21, 0 ) = mPoly( 4, 0 ) * mPoly( 5, 0 ) ; // x^3 * y
439 mPoly( 22, 0 ) = mPoly( 4, 0 ) * mPoly( 6, 0 ) ; // x^2 * y^2
440 mPoly( 23, 0 ) = mPoly( 5, 0 ) * mPoly( 6, 0 ) ; // x * y^3
441 mPoly( 24, 0 ) = mPoly( 6, 0 ) * mPoly( 6, 0 ) ; // y^4
442 mPoly( 25, 0 ) = mPoly( 6, 0 ) * mPoly( 7, 0 ) ; // y^3 * z
443 mPoly( 26, 0 ) = mPoly( 6, 0 ) * mPoly( 8, 0 ) ; // y^2 * z^2
444 mPoly( 27, 0 ) = mPoly( 7, 0 ) * mPoly( 8, 0 ) ; // y * z^3
445 mPoly( 28, 0 ) = mPoly( 8, 0 ) * mPoly( 8, 0 ) ; // z^4
446 mPoly( 29, 0 ) = mPoly( 9, 0 ) * mPoly( 8, 0 ) ; // z^3 * x
447 mPoly( 30, 0 ) = mPoly( 4, 0 ) * mPoly( 8, 0 ) ; // x^2 * z^2
448 mPoly( 31, 0 ) = mPoly( 9, 0 ) * mPoly( 4, 0 ) ; // z * x^3
449 mPoly( 32, 0 ) = mPoly( 4, 0 ) * mPoly( 7, 0 ) ; // x^2 * y * z
450 mPoly( 33, 0 ) = mPoly( 6, 0 ) * mPoly( 9, 0 ) ; // x * y^2 * z
451 mPoly( 34, 0 ) = mPoly( 5, 0 ) * mPoly( 8, 0 ) ; // x * y * z^2
452 }
453
454 inline const Cell< id_t > &
456 {
457 return mBlockIDs ;
458 }
459
460 inline const Cell< index_t > &
462 {
463 return mMyElementIndices ;
464 }
465
466
467 }
468}
469#endif //BELFEM_CL_FEM_POSTPROCESSOR_HPP
size_t size() const
return the size of the Cell
Definition cl_Cell.hpp:181
Runtime-sized bitset; one bit per flag, packed into 64-bit words.
Definition cl_DynamicBitset.hpp:33
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
Definition cl_FEM_Block.hpp:35
Definition cl_FEM_Calculator.hpp:600
this class creates the DOFs based on the passed equation object.
Definition cl_FEM_DofManager.hpp:55
Definition cl_FEM_Element.hpp:41
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
void set_source_fields(const Cell< string > &aFields)
Definition cl_FEM_Postprocessor.hpp:267
Kernel * mKernel
Definition cl_FEM_Postprocessor.hpp:93
uint mNumSourceFields
Definition cl_FEM_Postprocessor.hpp:90
virtual void initialize()
Definition cl_FEM_Postprocessor.cpp:93
virtual void run()
Definition cl_FEM_Postprocessor.cpp:1171
void recover_fields()
Definition cl_FEM_Postprocessor.cpp:951
const Cell< index_t > & my_element_indices() const
Definition cl_FEM_Postprocessor.hpp:461
void set_block_ids(const Vector< id_t > &aBlockIDs)
Definition cl_FEM_Postprocessor.cpp:76
IWG * mEquation
Definition cl_FEM_Postprocessor.hpp:96
const Matrix< real > & compute_poly(const Vector< real > &aX)
Definition cl_FEM_Postprocessor.hpp:293
const Cell< string > & target_fields() const
Definition cl_FEM_Postprocessor.hpp:287
const uint mOrder
Definition cl_FEM_Postprocessor.hpp:30
DomainType mDomainType
Definition cl_FEM_Postprocessor.hpp:85
void synch_source_fields()
Definition cl_FEM_Postprocessor.cpp:137
Element * mElement
Definition cl_FEM_Postprocessor.hpp:98
DofManager * projector()
Definition cl_FEM_Postprocessor.hpp:261
void synch_target_fields(Matrix< real > &aData)
Definition cl_FEM_Postprocessor.cpp:146
DofManager * mField
Definition cl_FEM_Postprocessor.hpp:95
const proc_t mCommSize
Definition cl_FEM_Postprocessor.hpp:28
const Cell< string > & source_fields() const
Definition cl_FEM_Postprocessor.hpp:281
void set_target_fields(const Cell< string > &aFields)
Definition cl_FEM_Postprocessor.hpp:274
void set_field(DofManager *aField)
Definition cl_FEM_Postprocessor.cpp:63
uint mNumTargetFields
Definition cl_FEM_Postprocessor.hpp:91
const proc_t mCommRank
Definition cl_FEM_Postprocessor.hpp:27
Block * mBlock
Definition cl_FEM_Postprocessor.hpp:99
Cell< string > mSourceFields
Definition cl_FEM_Postprocessor.hpp:89
Mesh * mMesh
Definition cl_FEM_Postprocessor.hpp:94
const Cell< id_t > & block_ids() const
Definition cl_FEM_Postprocessor.hpp:455
virtual const Vector< real > & compute(const uint aK)
Definition cl_FEM_Postprocessor.cpp:635
Postprocessor(Kernel *aKernel, DofManager *aField=nullptr)
Definition cl_FEM_Postprocessor.cpp:20
const uint mNumDimensions
Definition cl_FEM_Postprocessor.hpp:29
virtual void update_element_dofs()
Definition cl_FEM_Postprocessor.cpp:642
Material * mMaterial
Definition cl_FEM_Postprocessor.hpp:97
Cell< string > mTargetFields
Definition cl_FEM_Postprocessor.hpp:88
Calculator * mCalculator
Definition cl_FEM_Postprocessor.hpp:100
Definition cl_IFB_LINE3.hpp:21
USER GUIDES:
Definition cl_Capacitor.cpp:16
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
ElementType
Element types.
Definition Mesh_Enums.hpp:27
@ EMPTY
Definition Mesh_Enums.hpp:28
double real
Definition typedefs.hpp:36
DomainType
Definition en_DomainType.hpp:20
@ Default
Definition en_DomainType.hpp:21
float x
Definition test_curve_frame.py:28
Definition Element.py:1
Definition Node.py:1