OGS 6.1.0-1721-g6382411ad
NumLib::BackwardDifferentiationFormula Class Referencefinal

Detailed Description

Backward differentiation formula.

Definition at line 452 of file TimeDiscretization.h.

#include <TimeDiscretization.h>

Inheritance diagram for NumLib::BackwardDifferentiationFormula:
Collaboration diagram for NumLib::BackwardDifferentiationFormula:

Public Member Functions

 BackwardDifferentiationFormula (const unsigned num_steps)
 
 ~BackwardDifferentiationFormula () override
 
void setInitialState (const double t0, GlobalVector const &x0) override
 Sets the initial condition. More...
 
double getRelativeChangeFromPreviousTimestep (GlobalVector const &x, MathLib::VecNormType norm_type) override
 
void pushState (const double, GlobalVector const &x, InternalMatrixStorage const &) override
 
void popState (GlobalVector &x) override
 
void nextTimestep (const double t, const double delta_t) override
 
double getCurrentTime () const override
 
double getNewXWeight () const override
 Returns $ \alpha = \partial \hat x / \partial x_N $. More...
 
void getWeightedOldX (GlobalVector &y) const override
 Returns $ x_O $. More...
 
- Public Member Functions inherited from NumLib::TimeDiscretization
 TimeDiscretization ()=default
 
void getXdot (GlobalVector const &x_at_new_timestep, GlobalVector &xdot) const
 
virtual ~TimeDiscretization ()=default
 
virtual bool isLinearTimeDisc () const
 
virtual double getDxDx () const
 
virtual GlobalVector const & getCurrentX (GlobalVector const &x_at_new_timestep) const
 
virtual bool needsPreload () const
 

Private Member Functions

std::size_t eff_num_steps () const
 

Private Attributes

const unsigned _num_steps
 The order of the BDF method. More...
 
double _t
 $ t_C $ More...
 
double _delta_t
 the timestep size More...
 
std::vector< GlobalVector * > _xs_old
 solutions from the preceding timesteps More...
 
unsigned _offset = 0
 allows treating _xs_old as circular buffer More...
 

Additional Inherited Members

- Protected Member Functions inherited from NumLib::TimeDiscretization
double computeRelativeChangeFromPreviousTimestep (GlobalVector const &x, GlobalVector const &x_old, MathLib::VecNormType norm_type)
 
- Protected Attributes inherited from NumLib::TimeDiscretization
std::unique_ptr< GlobalVector > _dx
 Used to store $ u_{n+1}-u_{n}$. More...
 

Constructor & Destructor Documentation

◆ BackwardDifferentiationFormula()

NumLib::BackwardDifferentiationFormula::BackwardDifferentiationFormula ( const unsigned  num_steps)
inlineexplicit

Constructs a new instance.

Parameters
num_stepsThe order of the BDF to be used (= the number of timesteps kept in the internal history buffer). Valid range: 1 through 6.
Note
Until a sufficient number of timesteps has been computed to be able to use the full num_steps order BDF, lower order BDFs are used in the first timesteps.

Definition at line 467 of file TimeDiscretization.h.

468  : _num_steps(num_steps)
469  {
470  assert(1 <= num_steps && num_steps <= 6);
471  _xs_old.reserve(num_steps);
472  }
std::vector< GlobalVector * > _xs_old
solutions from the preceding timesteps
const unsigned _num_steps
The order of the BDF method.

◆ ~BackwardDifferentiationFormula()

NumLib::BackwardDifferentiationFormula::~BackwardDifferentiationFormula ( )
inlineoverride

Definition at line 474 of file TimeDiscretization.h.

References NumLib::GlobalVectorProvider::provider, and NumLib::VectorProvider::releaseVector().

475  {
476  for (auto* x : _xs_old)
478  }
static NUMLIB_EXPORT VectorProvider & provider
std::vector< GlobalVector * > _xs_old
solutions from the preceding timesteps
virtual void releaseVector(GlobalVector const &x)=0

Member Function Documentation

◆ eff_num_steps()

std::size_t NumLib::BackwardDifferentiationFormula::eff_num_steps ( ) const
inlineprivate

Definition at line 511 of file TimeDiscretization.h.

511 { return _xs_old.size(); }
std::vector< GlobalVector * > _xs_old
solutions from the preceding timesteps

◆ getCurrentTime()

double NumLib::BackwardDifferentiationFormula::getCurrentTime ( ) const
inlineoverridevirtual

Returns $ t_C $, i.e., the time at which the equation will be assembled.

Implements NumLib::TimeDiscretization.

Definition at line 504 of file TimeDiscretization.h.

◆ getNewXWeight()

double NumLib::BackwardDifferentiationFormula::getNewXWeight ( ) const
overridevirtual

Returns $ \alpha = \partial \hat x / \partial x_N $.

Implements NumLib::TimeDiscretization.

Definition at line 112 of file TimeDiscretization.cpp.

References NumLib::detail::BDF_Coeffs.

113 {
114  auto const k = eff_num_steps();
115  return detail::BDF_Coeffs[k - 1][0] / _delta_t;
116 }
const double BDF_Coeffs[6][7]
Coefficients used in the backward differentiation formulas.

◆ getRelativeChangeFromPreviousTimestep()

double NumLib::BackwardDifferentiationFormula::getRelativeChangeFromPreviousTimestep ( GlobalVector const &  x,
MathLib::VecNormType  norm_type 
)
overridevirtual

Get the relative change of solutions between two successive time steps by $ e_n = \|u^{n+1}-u^{n}\|/\|u^{n+1}\| $.

Parameters
xThe solution at the current timestep.
norm_typeThe type of global vector norm.

Implements NumLib::TimeDiscretization.

Definition at line 68 of file TimeDiscretization.cpp.

References NumLib::TimeDiscretization::computeRelativeChangeFromPreviousTimestep().

70 {
72  x, *_xs_old[_offset], norm_type);
73 }
std::vector< GlobalVector * > _xs_old
solutions from the preceding timesteps
unsigned _offset
allows treating _xs_old as circular buffer
double computeRelativeChangeFromPreviousTimestep(GlobalVector const &x, GlobalVector const &x_old, MathLib::VecNormType norm_type)

◆ getWeightedOldX()

void NumLib::BackwardDifferentiationFormula::getWeightedOldX ( GlobalVector &  y) const
overridevirtual

Returns $ x_O $.

Implements NumLib::TimeDiscretization.

Definition at line 118 of file TimeDiscretization.cpp.

References MathLib::LinAlg::axpy(), NumLib::detail::BDF_Coeffs, MathLib::LinAlg::copy(), and MathLib::LinAlg::scale().

119 {
120  namespace LinAlg = MathLib::LinAlg;
121 
122  auto const k = eff_num_steps();
123  auto const* const BDFk = detail::BDF_Coeffs[k - 1];
124 
125  // compute linear combination \sum_{i=0}^{k-1} BDFk_{k-i} \cdot x_{n+i}
126  LinAlg::copy(*_xs_old[_offset], y); // _xs_old[offset] = x_n
127  LinAlg::scale(y, BDFk[k]);
128 
129  for (unsigned i = 1; i < k; ++i)
130  {
131  auto const off = (_offset + i) % k;
132  LinAlg::axpy(y, BDFk[k - i], *_xs_old[off]);
133  }
134 
135  LinAlg::scale(y, 1.0 / _delta_t);
136 }
std::vector< GlobalVector * > _xs_old
solutions from the preceding timesteps
unsigned _offset
allows treating _xs_old as circular buffer
void axpy(MatrixOrVector &y, double const a, MatrixOrVector const &x)
Computes .
Definition: LinAlg.h:57
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:36
void scale(MatrixOrVector &x, double const a)
Scales x by a.
Definition: LinAlg.h:43
const double BDF_Coeffs[6][7]
Coefficients used in the backward differentiation formulas.

◆ nextTimestep()

void NumLib::BackwardDifferentiationFormula::nextTimestep ( const double  t,
const double  delta_t 
)
inlineoverridevirtual

Indicate that the computation of a new timestep is being started now.

Warning
Currently changing timestep sizes are not supported. Thus, delta_t must not change throughout the entire time integration process! This is not checked by this code!

Implements NumLib::TimeDiscretization.

Definition at line 498 of file TimeDiscretization.h.

499  {
500  _t = t;
501  _delta_t = delta_t;
502  }

◆ popState()

void NumLib::BackwardDifferentiationFormula::popState ( GlobalVector &  x)
inlineoverridevirtual

Restores the given vector x to its old value. Used only for repeating of the time step with new time step size when the current time step is rejected. The restored x is only used as an initial guess for linear solver in the first Picard nonlinear iteration.

Parameters
xThe solution at the current time step, which is going to be reset to its previous value.

Implements NumLib::TimeDiscretization.

Definition at line 493 of file TimeDiscretization.h.

References MathLib::LinAlg::copy().

494  {
495  MathLib::LinAlg::copy(*_xs_old[_xs_old.size()-1], x);
496  }
std::vector< GlobalVector * > _xs_old
solutions from the preceding timesteps
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:36

◆ pushState()

void NumLib::BackwardDifferentiationFormula::pushState ( const double  t,
GlobalVector const &  x,
InternalMatrixStorage const &  strg 
)
overridevirtual

Indicate that the current timestep is done and that you will proceed to the next one.

Warning
Do not use this method for setting the initial condition, rather use setInitialState()!
Parameters
tThe current timestep.
xThe solution at the current timestep.
strgTrigger storing some internal state. Currently only used by the CrankNicolson scheme.

Implements NumLib::TimeDiscretization.

Definition at line 75 of file TimeDiscretization.cpp.

References MathLib::LinAlg::copy(), and NumLib::GlobalVectorProvider::provider.

78 {
79  namespace LinAlg = MathLib::LinAlg;
80  // TODO use boost circular buffer?
81 
82  // until _xs_old is filled, lower-order BDF formulas are used.
83  if (_xs_old.size() < _num_steps)
84  {
85  _xs_old.push_back(&NumLib::GlobalVectorProvider::provider.getVector(x));
86  }
87  else
88  {
90  _offset =
91  (_offset + 1) % _num_steps; // treat _xs_old as a circular buffer
92  }
93 }
static NUMLIB_EXPORT VectorProvider & provider
std::vector< GlobalVector * > _xs_old
solutions from the preceding timesteps
unsigned _offset
allows treating _xs_old as circular buffer
const unsigned _num_steps
The order of the BDF method.
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:36

◆ setInitialState()

void NumLib::BackwardDifferentiationFormula::setInitialState ( const double  t0,
GlobalVector const &  x0 
)
inlineoverridevirtual

Sets the initial condition.

Implements NumLib::TimeDiscretization.

Definition at line 480 of file TimeDiscretization.h.

References NumLib::GlobalVectorProvider::provider.

481  {
482  _t = t0;
483  _xs_old.push_back(
485  }
static NUMLIB_EXPORT VectorProvider & provider
std::vector< GlobalVector * > _xs_old
solutions from the preceding timesteps

Member Data Documentation

◆ _delta_t

double NumLib::BackwardDifferentiationFormula::_delta_t
private

the timestep size

Definition at line 514 of file TimeDiscretization.h.

◆ _num_steps

const unsigned NumLib::BackwardDifferentiationFormula::_num_steps
private

The order of the BDF method.

Definition at line 512 of file TimeDiscretization.h.

◆ _offset

unsigned NumLib::BackwardDifferentiationFormula::_offset = 0
private

allows treating _xs_old as circular buffer

Definition at line 517 of file TimeDiscretization.h.

◆ _t

double NumLib::BackwardDifferentiationFormula::_t
private

$ t_C $

Definition at line 513 of file TimeDiscretization.h.

◆ _xs_old

std::vector<GlobalVector*> NumLib::BackwardDifferentiationFormula::_xs_old
private

solutions from the preceding timesteps

Definition at line 516 of file TimeDiscretization.h.


The documentation for this class was generated from the following files: