BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_IWG_Timestep.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_IWG_TIMESTEP_HPP
13#define BELFEM_CL_IWG_TIMESTEP_HPP
14
15
16#include "cl_IWG.hpp"
17#include "en_SolverEnums.hpp"
19
20namespace belfem
21{
22 namespace fem
23 {
24 class Element ;
25
32 class IWG_Timestep: public IWG
33 {
34 // Unit-test seam, no runtime cost and no public API widened.
35 //
36 // The BDF coefficients ( mAlpha, mBeta ) and the step-size history
37 // that determines them ( mH, mStepCount ) are private on purpose.
38 // The production writers are shift_fields, reset_fields,
39 // restore_savepoint — each needing an initialized DofManager —
40 // and, since 2026-08-15, the validated memdump seam
41 // restore_history_state ( which needs none ). Without this
42 // declaration the
43 // variable-step coefficient formulas below are reachable by no
44 // test at all: they are pure arithmetic, but their inputs cannot
45 // be posed and their outputs cannot be read.
46 //
47 // The probe is defined in tests/fem/test_BdfTimestepMethod.cpp and
48 // exists only there. Nothing in src/ may use it.
49 friend class BdfCoefficientProbe ;
50
52
53
54
55 Cell< Cell< Vector< real > * > > mFieldData ;
56
57 real mAlpha = 1.0 ;
58 Vector< real > mBeta ;
60
61 // true if BDF coefficients must be recomputed before the next assembly
62 bool mCoeffsDirty = true ;
63
64 // savepoint storage: deep copies of the dof fields and the step-size
65 // history, so a rejected coupled timestep can restore the state
66 // across any number of shift_fields calls ( see make_savepoint )
67 Cell< Cell< Vector< real > > > mFieldSnapshot ;
68 Vector< real > mHSnapshot ;
69 real mDeltaTimeSnapshot = BELFEM_QUIET_NAN ;
70 real mHDroppedSnapshot = BELFEM_QUIET_NAN ;
71 uint mStepCountSnapshot = 0 ;
72 bool mHaveSavepoint = false ;
73
74 // the step size that falls off the end of mH on a shift: the
75 // rotation destroys it, but reset_fields must restore it for a
76 // BDF5 retry, which reads mH( 3 )
77 real mHDropped = BELFEM_QUIET_NAN ;
78
79 // number of timesteps started ( shifted ), drives the startup order ramp
80 uint mStepCount = 0 ;
81
82 // order of the scheme actually running this step ( startup ramp
83 // may run below the configured mOrder ); consumed by collect_qhist
84 uint mOrderActive = 1 ;
85
86 // remember whether the scheme was configured with a stiffness matrix
87 bool mHaveStiffness = true ;
88
89 // timestepping pointer as configured by set_timestepping_method
90 void
91 ( IWG_Timestep:: * mTimestep )(
92 Matrix< real > & aJ,
93 Vector< real > & aRHS );
94
95 // scheme that actually runs this step; differs from mTimestep only
96 // during the startup ramp of a BDF-p run ( step 1: BDF1, step 2: BDF2, ... )
97 void
98 ( IWG_Timestep:: * mTimestepActive )(
99 Matrix< real > & aJ,
100 Vector< real > & aRHS ) = nullptr ;
101
102//------------------------------------------------------------------------------
103 protected:
104//------------------------------------------------------------------------------
105 //real mDeltaTime = 1.0 ;
107
109
110//------------------------------------------------------------------------------
111 public:
112//------------------------------------------------------------------------------
113
114 IWG_Timestep( const IwgType aType,
115 const ModelDimensionality aDimensionality,
116 const IwgMode aMode=IwgMode::Iterative,
117 const SymmetryMode aSymmetryMode=SymmetryMode::Unsymmetric,
118 const DofMode aDofMode=DofMode::AllBlocksEqual,
119 const SideSetDofLinkMode aSideSetDofLinkMode=SideSetDofLinkMode::FacetOnly );
120
121
122 ~IWG_Timestep() override ;
123
124 // set the timestepping method
125 void
126 set_timestepping_method( const EulerMethod aMethod, const bool aHaveStiffness = true ) override;
127
128 // return the timestepping method
130 method() const override;
131
132 // BDF order actually running this step ( startup ramp )
133 uint
134 order_active() const;
135
136 // BDF order the UPCOMING assembly will run; ask this, not
137 // order_active(), before the step has been assembled
138 uint
139 order_pending() const;
140
141//------------------------------------------------------------------------------
142
143 void
145 Element * aElement,
146 Matrix< real > & aJacobian,
147 Vector< real > & aRHS ) override;
148
149//------------------------------------------------------------------------------
150
151 void
152 shift_fields() override;
153
154//------------------------------------------------------------------------------
155
156//------------------------------------------------------------------------------
157
166 void
168
169//------------------------------------------------------------------------------
170
215 const Vector< real > &
217
218//------------------------------------------------------------------------------
219
220 void
221 reset_fields() override;
222
223//------------------------------------------------------------------------------
224
233 void
235
236//------------------------------------------------------------------------------
237
241 void
243
244//------------------------------------------------------------------------------
245
261 void
263 Vector< real > & aH,
264 uint & aStepCount,
265 real & aLastDeltaTime ) const ;
266
267//------------------------------------------------------------------------------
268
277 void
279 Cell< string > & aParents,
280 Cell< string > & aHistory,
281 const uint aDepth = 0 ) const ;
282
283//------------------------------------------------------------------------------
284
304 bool
306 const Vector< real > & aH,
307 const uint aStepCount,
308 const real aLastDeltaTime ) ;
309
310 //------------------------------------------------------------------------------
311
313 matrices() override ;
314
315//------------------------------------------------------------------------------
316 protected:
317//------------------------------------------------------------------------------
318
332 void
333 compute_mkf( Element * aElement) override;
334
335//------------------------------------------------------------------------------
336
337 void
339 Vector< real > & aRHS );
340
341//------------------------------------------------------------------------------
342
343 void
344 set_field( DofManagerBase * aField ) override;
345
346//------------------------------------------------------------------------------
347 private:
348//------------------------------------------------------------------------------
349
350 // The startup ramp, in one place. BDF-p needs p history states, so
351 // the first steps run the highest order the history supports.
352 // Const and side-effect free, so it can be asked before the lazy
353 // recompute has fired; compute_bdf_coefficients assigns its result
354 // to mOrderActive, and order_pending() reports it to the log.
355 inline uint
356 ramped_order() const
357 {
358 switch( mMethod )
359 {
364 {
365 return ( mOrder > 1 && mStepCount < mOrder )
366 ? ( mStepCount > 0 ? mStepCount : 1 )
367 : mOrder ;
368 }
369 default :
370 {
371 // every other scheme is single-state
372 return 1 ;
373 }
374 }
375 }
376
377//------------------------------------------------------------------------------
378
379 void
380 create_old_dof_fields();
381
382//------------------------------------------------------------------------------
383
384 void
385 static_subfield( Matrix< real > & aM, Vector< real > & aRHS );
386
387//------------------------------------------------------------------------------
388 void
389 explicit_euler( Matrix< real > & aM, Vector< real > & aRHS );
390
391//------------------------------------------------------------------------------
392
393 void
394 crank_nicolson( Matrix< real > & aM, Vector< real > & aRHS );
395
396//------------------------------------------------------------------------------
397
398 void
399 galerkin( Matrix< real > & aM, Vector< real > & aRHS );
400
401//------------------------------------------------------------------------------
402
403 void
404 mass_matrix_only(
405 Matrix< real > & aJ,
406 Vector< real > & aRHS );
407//------------------------------------------------------------------------------
408
409 void
410 stiffness_matrix_only(
411 Matrix< real > & aJ,
412 Vector< real > & aRHS );
413
414//------------------------------------------------------------------------------
415
416 void
417 bdf1(
418 Matrix< real > & aJ,
419 Vector< real > & aRHS );
420
421//------------------------------------------------------------------------------
422
423 void
424 bdf2(
425 Matrix< real > & aJ,
426 Vector< real > & aRHS );
427
428//------------------------------------------------------------------------------
429
430 void
431 bdf3(
432 Matrix< real > & aJ,
433 Vector< real > & aRHS );
434
435//------------------------------------------------------------------------------
436
437 void
438 bdf4(
439 Matrix< real > & aJ,
440 Vector< real > & aRHS );
441
442//------------------------------------------------------------------------------
443
444 void
445 bdf5(
446 Matrix< real > & aJ,
447 Vector< real > & aRHS );
448
449//------------------------------------------------------------------------------
450
451 void
452 bdf1_nok(
453 Matrix< real > & aJ,
454 Vector< real > & aRHS );
455
456//------------------------------------------------------------------------------
457
458 void
459 bdf2_nok(
460 Matrix< real > & aJ,
461 Vector< real > & aRHS );
462
463//------------------------------------------------------------------------------
464
465 void
466 bdf3_nok(
467 Matrix< real > & aJ,
468 Vector< real > & aRHS );
469
470//------------------------------------------------------------------------------
471
472 void
473 bdf4_nok(
474 Matrix< real > & aJ,
475 Vector< real > & aRHS );
476
477//------------------------------------------------------------------------------
478
479 void
480 bdf5_nok(
481 Matrix< real > & aJ,
482 Vector< real > & aRHS );
483
484//------------------------------------------------------------------------------
485
486 void
487 compute_bdf_coeffs_2();
488
489//------------------------------------------------------------------------------
490
491 void
492 compute_bdf_coeffs_3();
493
494//------------------------------------------------------------------------------
495
496 void
497 compute_bdf_coeffs_4();
498
499//------------------------------------------------------------------------------
500
501 void
502 compute_bdf_coeffs_5();
503
504//------------------------------------------------------------------------------
505
506 void
507 derivative( Matrix< real > & aJ,
508 Vector< real > & aRHS );
509
510//------------------------------------------------------------------------------
511
512 void
513 euler_no_stiffness( Matrix< real > & aJ,
514 Vector< real > & aRHS );
515
516//------------------------------------------------------------------------------
517
518 void
519 derivative_no_stiffness( Matrix< real > & aJ,
520 Vector< real > & aRHS );
521
522
523//------------------------------------------------------------------------------
524
525 uint
526 timestepping_order() const override ;
527
528//------------------------------------------------------------------------------
529 };
530
531//------------------------------------------------------------------------------
532
533 // return the timestepping method
534 inline EulerMethod
536 {
537 return mMethod ;
538 }
539
540//------------------------------------------------------------------------------
541
542 // BDF order actually running this step ( startup ramp may sit below
543 // the configured order ); the controller's step-growth clamp reads it
544 inline uint
546 {
547 return mOrderActive ;
548 }
549
550//------------------------------------------------------------------------------
551
552 // BDF order the UPCOMING assembly will run. The coefficients are
553 // recomputed lazily, on the first element of a step, so between
554 // shift_fields and that first assembly mOrderActive still holds the
555 // PREVIOUS step's order. Anything reporting the order before assembly
556 // -- the timestep header, above all -- must ask this instead of
557 // order_active(), or it lags the ramp by one step.
558 inline uint
560 {
561 return mCoeffsDirty ? this->ramped_order() : mOrderActive ;
562 }
563
564//------------------------------------------------------------------------------
565
566 inline uint
568 {
569 return mOrder ;
570 }
571
572//------------------------------------------------------------------------------
573 }
574}
575
576#endif //BELFEM_CL_IWG_TIMESTEP_HPP
Cell is a wrapper around the standard vector.
Definition cl_Cell.hpp:42
abstract interface of the dof manager as seen by the group classes and the IWG; DofManager is its onl...
Definition cl_FEM_DofManagerBase.hpp:44
Definition cl_FEM_Element.hpp:41
void compute_jacobian_and_rhs(Element *aElement, Matrix< real > &aJacobian, Vector< real > &aRHS) override
Definition cl_IWG_Timestep.cpp:796
EulerMethod method() const override
Definition cl_IWG_Timestep.hpp:535
void save_history_state(Vector< real > &aH, uint &aStepCount, real &aLastDeltaTime) const
Export the multi-step integrator state for the memdump, so a warm restart can resume at full BDF orde...
Definition cl_IWG_Timestep.cpp:650
void compute_bdf_coefficients()
compute BDF coefficients (alpha, beta) for variable-step BDF and select the scheme for the upcoming s...
Definition cl_IWG_Timestep.cpp:401
TimestepMatrices * matrices() override
Definition cl_IWG_Timestep.cpp:725
void compute_timestep(Matrix< real > &aJ, Vector< real > &aRHS)
Definition cl_IWG_Timestep.cpp:826
void make_savepoint()
save a deep copy of all dof fields, the step-size history and the step counter.
Definition cl_IWG_Timestep.cpp:584
void reset_fields() override
called by main file to copy fields from last timestep eg.
Definition cl_IWG_Timestep.cpp:541
void compute_mkf(Element *aElement) override
a default interface to compute the matrices of a timestepping scheme of shape of
Definition cl_IWG_Timestep.cpp:733
friend class BdfCoefficientProbe
Definition cl_IWG_Timestep.hpp:49
void set_field(DofManagerBase *aField) override
Definition cl_IWG_Timestep.cpp:839
TimestepMatrices * mTimeStepMatrices
Definition cl_IWG_Timestep.hpp:108
bool restore_history_state(const Vector< real > &aH, const uint aStepCount, const real aLastDeltaTime)
Counterpart of save_history_state.
Definition cl_IWG_Timestep.cpp:663
void shift_fields() override
called by main file to copy fields into last timestep eg.
Definition cl_IWG_Timestep.cpp:362
void history_field_labels(Cell< string > &aParents, Cell< string > &aHistory, const uint aDepth=0) const
the dof labels ( aParents ) and their numbered history labels ( aHistory, label + "0"....
Definition cl_IWG_Timestep.cpp:257
void set_timestepping_method(const EulerMethod aMethod, const bool aHaveStiffness=true) override
Definition cl_IWG_Timestep.cpp:62
const Vector< real > & collect_qhist()
The beta-weighted dof history of the scheme running this step:
Definition cl_IWG_Timestep.cpp:741
uint mOrder
Definition cl_IWG_Timestep.hpp:106
void restore_savepoint()
restore the state stored by make_savepoint
Definition cl_IWG_Timestep.cpp:623
IWG_Timestep(const IwgType aType, const ModelDimensionality aDimensionality, const IwgMode aMode=IwgMode::Iterative, const SymmetryMode aSymmetryMode=SymmetryMode::Unsymmetric, const DofMode aDofMode=DofMode::AllBlocksEqual, const SideSetDofLinkMode aSideSetDofLinkMode=SideSetDofLinkMode::FacetOnly)
Definition cl_IWG_Timestep.cpp:32
uint order_pending() const
Definition cl_IWG_Timestep.hpp:559
uint order_active() const
Definition cl_IWG_Timestep.hpp:545
virtual uint timestepping_order() const
Definition cl_IWG.cpp:2212
IWG(const IWG &)=delete
Container for element-level DENSE matrices in transient nonlinear FEM.
Definition cl_TimestepMatrices.hpp:71
Definition cl_IFB_LINE3.hpp:21
SideSetDofLinkMode
how the dofs of a sideset element are linked to its facet, master and slave elements ( six modes plus...
Definition en_IWG_SideSetDofLinkMode.hpp:25
@ FacetOnly
Definition en_IWG_SideSetDofLinkMode.hpp:26
USER GUIDES:
Definition cl_Capacitor.cpp:16
IwgMode
Definition en_IWGs.hpp:81
@ Iterative
Definition en_IWGs.hpp:83
IwgType
Definition en_IWGs.hpp:64
EulerMethod
Definition en_SolverEnums.hpp:47
@ BackwardDifference1
Definition en_SolverEnums.hpp:52
@ BackwardDifference5
Definition en_SolverEnums.hpp:56
@ BackwardDifference2
Definition en_SolverEnums.hpp:53
@ BackwardDifference3
Definition en_SolverEnums.hpp:54
@ BackwardDifference4
Definition en_SolverEnums.hpp:55
DofMode
Definition cl_IWG.hpp:38
@ AllBlocksEqual
Definition cl_IWG.hpp:39
unsigned int uint
Definition typedefs.hpp:30
ModelDimensionality
Definition en_IWGs.hpp:20
SymmetryMode
Definition en_SolverEnums.hpp:36
@ Unsymmetric
Definition en_SolverEnums.hpp:37
double real
Definition typedefs.hpp:36
#define BELFEM_QUIET_NAN
Definition typedefs.hpp:87