BELFEM 0.9.4
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 <type_traits>
16
17#include "typedefs.hpp"
18#include "cl_Mesh.hpp"
19#include "cl_FEM_Kernel.hpp"
20
21namespace belfem
22{
23 namespace fem
24 {
26 {
27
28 protected:
32 const uint mOrder ;
33 private:
34
35 // block IDs used on this post processor
36 Cell< id_t > mBlockIDs ;
37
38 Cell< index_t > mMyNodeIndices ;
39 Cell< index_t > mMyOwnedNodeIndices ;
40 Cell< index_t > mMyElementIndices ;
41 Cell< index_t > mMyEdgeIndices ;
42 Cell< index_t > mMyFaceIndices ;
43
44 Cell< Vector< index_t > > mAllNodeIndices ;
45 Cell< Vector< index_t > > mAllOwnedNodeIndices ;
46
47 Cell< Vector< index_t > > mAllEdgeIndices ;
48 Cell< Vector< index_t > > mAllFaceIndices ;
49
50 // vector with polynomial coefficients
51 // we use a matrix so that we can use the trans() function
52 Matrix< real > mPoly ;
53
54 DynamicBitset * mNodeBitset = nullptr ;
55 DynamicBitset * mEdgeBitset = nullptr ;
56 DynamicBitset * mFaceBitset = nullptr ;
57 DynamicBitset * mElementBitset = nullptr ;
58
59 void
60 ( Postprocessor::*mFunComputePoly )( const Vector< real > & aX );
61
62 void
63 ( Postprocessor::*mFunPoly2D )( const real x, const real y );
64
65 void
66 ( Postprocessor::*mFunPoly3D )( const real x, const real y, const real z );
67
68 bool mIsInitialized = false ;
69
70 bool mHaveEdges = false ;
71 bool mHaveFaces = false ;
72
73 ElementType mElementType = ElementType::EMPTY ;
74 id_t mLastElementID = gNoID ;
75 id_t mLastBlockID = gNoID ;
76 Matrix< real > mVandermonde ;
77 Map< mesh::Node * , Matrix< real > * > mNodeMatrices ;
78
79 // the local frame the fit of one node is written in: origin and
80 // in-plane scale for every postprocessor; shell normal, tangents
81 // and thickness scale only in shell mode. Fixed-size geometry,
82 // not linear algebra: a loop that pairs a component with mesh
83 // data runs to mNumDimensions, and the components beyond it stay
84 // zero. The 3D tangent construction writes only two components
85 // of T1 and relies on the third being zero
86 struct NodeFrame
87 {
88 real Origin[ 3 ] = { 0.0, 0.0, 0.0 };
89 real Normal[ 3 ] = { 0.0, 0.0, 0.0 };
90 real T1[ 3 ] = { 0.0, 0.0, 0.0 };
91 real T2[ 3 ] = { 0.0, 0.0, 0.0 };
92 real H = 1.0 ;
93 real Tau = 1.0 ;
94 };
95
96 // one frame per selected node, held from one build of the node
97 // matrices to the next; a Vector member would put a backend
98 // object and its heap buffers into every node
99 static_assert( std::is_trivially_copyable< NodeFrame >::value,
100 "NodeFrame must stay plain data" );
101
103
104 uint mNumCoefficients = 0 ;
105
106 // shell mode: linear thin-shell layers ( PENTA6TS, QUAD4TS ) are fit
107 // in ( s1, s2, eta ), eta the curvilinear offset through the stack
108 bool mShellLocal = false ;
109
110 // shell mode, per local node index: 1 if the node lies on the
111 // element's bottom face, 0 if on its top face
112 Cell< uint > mIsBottomNode ;
113
114 // scratch of the element currently linked by link_patch_element()
115 Matrix< real > mNodeCoords ;
116 Matrix< real > mIntPoints ;
117 Vector< real > mZeta ;
118 Vector< real > mShellDirection ;
119 real mElementThickness = 1.0 ;
120
121 // scratch for one local coordinate, and for the per-point results
122 Vector< real > mLocalPoint ;
123 Vector< real > mOffset ;
124 Matrix< real > mPointValues ;
125 Matrix< real > mNodeRhs ;
126
127 // scratch for recovery_block_inverse(), called by invert_node_matrix()
128 Matrix< real > mSchur ;
129 Vector< real > mCoupling ;
130 Vector< real > mSchurCoupling ;
131 Matrix< real > mSvdU ;
132 Matrix< real > mSvdVT ;
133 Vector< real > mSvdS ;
134 Vector< real > mSvdWork ;
135
136 // node fits in which invert_node_matrix() dropped a direction
137 index_t mNumTruncated = 0 ;
138
139 Vector< real > mNull ;
140
141 protected:
142
144
145
150
151 Kernel * mKernel = nullptr;
152 Mesh * mMesh = nullptr;
153 DofManager * mField = nullptr;
154 IWG * mEquation = nullptr;
155 Material * mMaterial = nullptr;
156 Element * mElement = nullptr ;
157 Block * mBlock = nullptr ;
159
160//------------------------------------------------------------------------------
161 public:
162//------------------------------------------------------------------------------
163
168 Postprocessor( Kernel * aKernel , DofManager * aField = nullptr );
169
170 virtual ~Postprocessor() ;
171
172 void
173 set_field( DofManager * aField );
174
175 void
176 set_source_fields( const Cell< string > & aFields );
177
178 void
179 set_target_fields( const Cell< string > & aFields );
180
181 const Cell< string > &
182 source_fields() const ;
183
184 const Cell< string > &
185 target_fields() const ;
186
187 void
188 set_block_ids( const Vector< id_t > & aBlockIDs );
189
190 void
191 set_block_ids( const Cell< id_t > & aBlockIDs );
192
193 virtual void
194 initialize();
195
196 void
198
199 void
201
202 virtual void
203 run();
204
205 DofManager *
206 projector() ;
207
210 index_t
212
213//------------------------------------------------------------------------------
214 protected:
215//------------------------------------------------------------------------------
216
217 const Matrix< real > &
218 compute_poly( const Vector< real > & aX );
219
220 void
222
223 virtual const Vector< real > &
224 compute( const uint aK );
225
226 virtual void
228
229 const Cell< id_t > &
230 block_ids() const ;
231
232 // needed for maxwell postproc
233 // to create element fields
234 const Cell< index_t > &
235 my_element_indices() const ;
236
237//------------------------------------------------------------------------------
238 private:
239//------------------------------------------------------------------------------
240
241 void
242 create_target_fields();
243
244 void
245 check_if_we_have_edges_and_faces();
246
247 void
248 select_elements_and_owned_nodes();
249
250 void
251 select_all_relevant_nodes();
252
253 void
254 synch_node_indices( const bool aOwnedOnly );
255
256 void
257 select_edges();
258
259 void
260 select_faces();
261
262 void
263 select_polynomial();
264
265 // funciton needed by constructor
266 uint
267 get_interpolation_order( const Mesh * aMesh ) const;
268
269 void
270 compute_node_matrices();
271
272 void
273 select_recovery_mode();
274
275 void
276 link_patch_element( mesh::Element * aElement );
277
278 uint
279 local_node_index( const mesh::Element * aElement, const mesh::Node * aNode ) const ;
280
281 real
282 shell_offset( const uint aLocalNode, const uint aK ) const ;
283
284 void
285 compute_node_frame( mesh::Node * aNode, NodeFrame & aFrame );
286
287 void
288 add_node_gram( mesh::Node * aNode, const NodeFrame & aFrame );
289
290 void
291 compute_local_poly( const NodeFrame & aFrame, const uint aLocalNode, const uint aK );
292
293 void
294 invert_node_matrix( Matrix< real > & aInverse );
295
296 void
297 delete_node_matrices();
298
299 void
300 accumulate_node_rhs(
301 mesh::Node * aTarget,
302 const uint aLocalNode,
303 const real aWeight,
304 Map< mesh::Node *, Matrix< real > * > & aNodeCoeffs );
305
306 void
307 synch_source_field( const string & aField );
308
309//------------------------------------------------------------------------------
310// EVALUATION ROUTINES
311//------------------------------------------------------------------------------
312
313 void
314 compute_poly_2d( const Vector< real > & aX );
315
316 void
317 compute_poly_3d( const Vector< real > & aX );
318
319 void
320 poly1_2d( const real x, const real y );
321
322 void
323 poly2_2d( const real x, const real y );
324
325 void
326 poly3_2d( const real x, const real y );
327
328 void
329 poly4_2d( const real x, const real y );
330
331 void
332 poly1_3d( const real x, const real y, const real z );
333
334 void
335 poly2_3d( const real x, const real y, const real z );
336
337 void
338 poly3_3d( const real x, const real y, const real z );
339
340 void
341 poly4_3d( const real x, const real y, const real z );
342 };
343
344 inline
345 DofManager *
347 {
348 return mField;
349 }
350
351 inline index_t
353 {
354 return mNumTruncated ;
355 }
356
357 inline void
359 {
360 mSourceFields = aFields ;
361 mNumSourceFields = aFields.size() ;
362 }
363
364 inline void
366 {
367 mTargetFields = aFields ;
368 mNumTargetFields = aFields.size() ;
369 }
370
371 inline const Cell< string > &
373 {
374 return mSourceFields;
375 }
376
377 inline const Cell< string > &
379 {
380 return mTargetFields;
381 }
382
383 inline const Matrix< real > &
385 {
386 (this->*mFunComputePoly)( aX );
387 return mPoly;
388 }
389
390 inline void
391 Postprocessor::compute_poly_2d( const Vector< real > & aX )
392 {
393 (this->*mFunPoly2D )( aX( 0 ), aX( 1 ) );
394 }
395
396 inline void
397 Postprocessor::compute_poly_3d( const Vector< real > & aX )
398 {
399 (this->*mFunPoly3D )( aX( 0 ), aX( 1 ), aX( 2 ) );
400 }
401
402 inline void
403 Postprocessor::poly1_2d( const real x, const real y )
404 {
405 mPoly( 0, 0 ) = 1.0 ;
406 mPoly( 1, 0 ) = x ;
407 mPoly( 2, 0 ) = y ;
408 }
409
410 inline void
411 Postprocessor::poly2_2d( const real x, const real y )
412 {
413 mPoly( 0, 0 ) = 1.0 ;
414 mPoly( 1, 0 ) = x ;
415 mPoly( 2, 0 ) = y ;
416 mPoly( 3, 0 ) = x*x ;
417 mPoly( 4, 0 ) = x*y ;
418 mPoly( 5, 0 ) = y*y ;
419 }
420
421 inline void
422 Postprocessor::poly3_2d( const real x, const real y )
423 {
424 mPoly( 0, 0 ) = 1.0 ;
425 mPoly( 1, 0 ) = x ;
426 mPoly( 2, 0 ) = y ;
427 mPoly( 3, 0 ) = x*x ;
428 mPoly( 4, 0 ) = x*y ;
429 mPoly( 5, 0 ) = y*y ;
430 mPoly( 6, 0 ) = mPoly( 3, 0 )*x ;
431 mPoly( 7, 0 ) = mPoly( 3, 0 )*y ;
432 mPoly( 8, 0 ) = x * mPoly( 5, 0 );
433 mPoly( 9, 0 ) = y * mPoly( 5, 0 );
434 }
435
436 inline void
437 Postprocessor::poly4_2d( const real x, const real y )
438 {
439 mPoly( 0, 0 ) = 1.0 ;
440 mPoly( 1, 0 ) = x ;
441 mPoly( 2, 0 ) = y ;
442 mPoly( 3, 0 ) = x*x ;
443 mPoly( 4, 0 ) = x*y ;
444 mPoly( 5, 0 ) = y*y ;
445 mPoly( 6, 0 ) = mPoly( 3, 0 )*x ; // x^3
446 mPoly( 7, 0 ) = mPoly( 3, 0 )*y ; // x^2 * y
447 mPoly( 8, 0 ) = x * mPoly( 5, 0 ); // x * y^2
448 mPoly( 9, 0 ) = y * mPoly( 5, 0 ); // y^3
449 mPoly( 10, 0 ) = mPoly( 3, 0 ) * mPoly( 3, 0 ); // x^4
450 mPoly( 11, 0 ) = mPoly( 6, 0 ) * y ; // x^3 * y
451 mPoly( 12, 0 ) = mPoly( 3, 0 ) * mPoly( 5, 0 ) ; // x^2*y^2
452 mPoly( 13, 0 ) = x * mPoly( 9, 0 ) ; // x * y^3
453 mPoly( 14, 0 ) = mPoly( 5, 0 ) * mPoly( 5, 0 ) ; // y^4
454 }
455
456 inline void
457 Postprocessor::poly1_3d( const real x, const real y, const real z )
458 {
459 mPoly( 0, 0 ) = 1.0 ;
460 mPoly( 1, 0 ) = x ;
461 mPoly( 2, 0 ) = y ;
462 mPoly( 3, 0 ) = z ;
463 }
464
465 inline void
466 Postprocessor::poly2_3d( const real x, const real y, const real z )
467 {
468 mPoly( 0, 0 ) = 1.0 ;
469 mPoly( 1, 0 ) = x ;
470 mPoly( 2, 0 ) = y ;
471 mPoly( 3, 0 ) = z ;
472 mPoly( 4, 0 ) = x*x ;
473 mPoly( 5, 0 ) = x*y ;
474 mPoly( 6, 0 ) = y*y ;
475 mPoly( 7, 0 ) = y*z ;
476 mPoly( 8, 0 ) = z*z ;
477 mPoly( 9, 0 ) = z*x ;
478 }
479
480 inline void
481 Postprocessor::poly3_3d( const real x, const real y, const real z )
482 {
483 mPoly( 0, 0 ) = 1.0 ;
484 mPoly( 1, 0 ) = x ;
485 mPoly( 2, 0 ) = y ;
486 mPoly( 3, 0 ) = z ;
487 mPoly( 4, 0 ) = x*x ;
488 mPoly( 5, 0 ) = x*y ;
489 mPoly( 6, 0 ) = y*y ;
490 mPoly( 7, 0 ) = y*z ;
491 mPoly( 8, 0 ) = z*z ;
492 mPoly( 9, 0 ) = z*x ;
493 mPoly( 10, 0 ) = mPoly( 4, 0 ) * x ; // x^3
494 mPoly( 11, 0 ) = mPoly( 4, 0 ) * y ; // x^2 * y
495 mPoly( 12, 0 ) = x * mPoly( 6, 0 ) ; // x * y^2 ;
496 mPoly( 13, 0 ) = y * mPoly( 6, 0 ) ; // y^3
497 mPoly( 14, 0 ) = z * mPoly( 6, 0 ) ; // y^2 * z
498 mPoly( 15, 0 ) = y * mPoly( 8, 0 ) ; // y * z^2
499 mPoly( 16, 0 ) = z * mPoly( 8, 0 ) ; // z^3
500 mPoly( 17, 0 ) = x * mPoly( 8, 0 ) ; // z^2 * x
501 mPoly( 18, 0 ) = mPoly( 4, 0 ) * z ; // x^2 * z
502 mPoly( 19, 0 ) = x * y * z ;
503 }
504
505 inline void
506 Postprocessor::poly4_3d( const real x, const real y, const real z )
507 {
508 mPoly( 0, 0 ) = 1.0 ;
509 mPoly( 1, 0 ) = x ;
510 mPoly( 2, 0 ) = y ;
511 mPoly( 3, 0 ) = z ;
512 mPoly( 4, 0 ) = x*x ;
513 mPoly( 5, 0 ) = x*y ;
514 mPoly( 6, 0 ) = y*y ;
515 mPoly( 7, 0 ) = y*z ;
516 mPoly( 8, 0 ) = z*z ;
517 mPoly( 9, 0 ) = z*x ;
518 mPoly( 10, 0 ) = mPoly( 4, 0 ) * x ; // x^3
519 mPoly( 11, 0 ) = mPoly( 4, 0 ) * y ; // x^2 * y
520 mPoly( 12, 0 ) = x * mPoly( 6, 0 ) ; // x * y^2 ;
521 mPoly( 13, 0 ) = y * mPoly( 6, 0 ) ; // y^3
522 mPoly( 14, 0 ) = z * mPoly( 6, 0 ) ; // y^2 * z
523 mPoly( 15, 0 ) = y * mPoly( 8, 0 ) ; // y * z^2
524 mPoly( 16, 0 ) = z * mPoly( 8, 0 ) ; // z^3
525 mPoly( 17, 0 ) = x * mPoly( 8, 0 ) ; // z^2 * x
526 mPoly( 18, 0 ) = mPoly( 4, 0 ) * z ; // x^2 * z
527 mPoly( 19, 0 ) = x * y * z ;
528 mPoly( 20, 0 ) = mPoly( 4, 0 ) * mPoly( 4, 0 ) ; // x^4
529 mPoly( 21, 0 ) = mPoly( 4, 0 ) * mPoly( 5, 0 ) ; // x^3 * y
530 mPoly( 22, 0 ) = mPoly( 4, 0 ) * mPoly( 6, 0 ) ; // x^2 * y^2
531 mPoly( 23, 0 ) = mPoly( 5, 0 ) * mPoly( 6, 0 ) ; // x * y^3
532 mPoly( 24, 0 ) = mPoly( 6, 0 ) * mPoly( 6, 0 ) ; // y^4
533 mPoly( 25, 0 ) = mPoly( 6, 0 ) * mPoly( 7, 0 ) ; // y^3 * z
534 mPoly( 26, 0 ) = mPoly( 6, 0 ) * mPoly( 8, 0 ) ; // y^2 * z^2
535 mPoly( 27, 0 ) = mPoly( 7, 0 ) * mPoly( 8, 0 ) ; // y * z^3
536 mPoly( 28, 0 ) = mPoly( 8, 0 ) * mPoly( 8, 0 ) ; // z^4
537 mPoly( 29, 0 ) = mPoly( 9, 0 ) * mPoly( 8, 0 ) ; // z^3 * x
538 mPoly( 30, 0 ) = mPoly( 4, 0 ) * mPoly( 8, 0 ) ; // x^2 * z^2
539 mPoly( 31, 0 ) = mPoly( 9, 0 ) * mPoly( 4, 0 ) ; // z * x^3
540 mPoly( 32, 0 ) = mPoly( 4, 0 ) * mPoly( 7, 0 ) ; // x^2 * y * z
541 mPoly( 33, 0 ) = mPoly( 6, 0 ) * mPoly( 9, 0 ) ; // x * y^2 * z
542 mPoly( 34, 0 ) = mPoly( 5, 0 ) * mPoly( 8, 0 ) ; // x * y * z^2
543 }
544
545 inline const Cell< id_t > &
547 {
548 return mBlockIDs ;
549 }
550
551 inline const Cell< index_t > &
553 {
554 return mMyElementIndices ;
555 }
556
557
558 }
559}
560#endif //BELFEM_CL_FEM_POSTPROCESSOR_HPP
size_t size() const
Definition cl_Cell.hpp:189
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:270
Top-level container for all mesh entities.
Definition cl_Mesh.hpp:60
Definition cl_FEM_Block.hpp:35
Definition cl_FEM_Calculator.hpp:596
Main workhorse: DOF management, assembly coordination and the solver interface.
Definition cl_FEM_DofManager.hpp:52
Definition cl_FEM_Element.hpp:41
Prototype for Integrator of Weak Form Governing Equation.
Definition cl_IWG.hpp:81
Top-level orchestrator.
Definition cl_FEM_Kernel.hpp:56
void set_source_fields(const Cell< string > &aFields)
Definition cl_FEM_Postprocessor.hpp:358
Kernel * mKernel
Definition cl_FEM_Postprocessor.hpp:151
uint mNumSourceFields
Definition cl_FEM_Postprocessor.hpp:148
virtual void initialize()
Definition cl_FEM_Postprocessor.cpp:97
virtual void run()
Definition cl_FEM_Postprocessor.cpp:1416
void recover_fields()
Definition cl_FEM_Postprocessor.cpp:1262
const Cell< index_t > & my_element_indices() const
Definition cl_FEM_Postprocessor.hpp:552
void set_block_ids(const Vector< id_t > &aBlockIDs)
Definition cl_FEM_Postprocessor.cpp:80
IWG * mEquation
Definition cl_FEM_Postprocessor.hpp:154
const Matrix< real > & compute_poly(const Vector< real > &aX)
Definition cl_FEM_Postprocessor.hpp:384
const Cell< string > & target_fields() const
Definition cl_FEM_Postprocessor.hpp:378
const uint mOrder
Definition cl_FEM_Postprocessor.hpp:32
DomainType mDomainType
Definition cl_FEM_Postprocessor.hpp:143
void synch_source_fields()
Definition cl_FEM_Postprocessor.cpp:140
Element * mElement
Definition cl_FEM_Postprocessor.hpp:156
DofManager * projector()
Definition cl_FEM_Postprocessor.hpp:346
void synch_target_fields(Matrix< real > &aData)
Definition cl_FEM_Postprocessor.cpp:149
DofManager * mField
Definition cl_FEM_Postprocessor.hpp:153
const proc_t mCommSize
Definition cl_FEM_Postprocessor.hpp:30
const Cell< string > & source_fields() const
Definition cl_FEM_Postprocessor.hpp:372
void set_target_fields(const Cell< string > &aFields)
Definition cl_FEM_Postprocessor.hpp:365
void set_field(DofManager *aField)
Definition cl_FEM_Postprocessor.cpp:67
uint mNumTargetFields
Definition cl_FEM_Postprocessor.hpp:149
const proc_t mCommRank
Definition cl_FEM_Postprocessor.hpp:29
Block * mBlock
Definition cl_FEM_Postprocessor.hpp:157
Cell< string > mSourceFields
Definition cl_FEM_Postprocessor.hpp:147
Mesh * mMesh
Definition cl_FEM_Postprocessor.hpp:152
const Cell< id_t > & block_ids() const
Definition cl_FEM_Postprocessor.hpp:546
virtual const Vector< real > & compute(const uint aK)
Definition cl_FEM_Postprocessor.cpp:638
index_t number_of_truncated_patches() const
node fits of this rank in which the inversion dropped a direction; set by initialize()
Definition cl_FEM_Postprocessor.hpp:352
Postprocessor(Kernel *aKernel, DofManager *aField=nullptr)
Collective.
Definition cl_FEM_Postprocessor.cpp:27
const uint mNumDimensions
Definition cl_FEM_Postprocessor.hpp:31
virtual void update_element_dofs()
Definition cl_FEM_Postprocessor.cpp:645
Material * mMaterial
Definition cl_FEM_Postprocessor.hpp:155
Cell< string > mTargetFields
Definition cl_FEM_Postprocessor.hpp:146
Calculator * mCalculator
Definition cl_FEM_Postprocessor.hpp:158
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
uint32_t index_t
Definition typedefs.hpp:52
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:37
Definition Element.py:1
Definition Node.py:1
y
Definition test_stadium.py:44