OGS 6.2.0-97-g4a610c866
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)
477  {
479  }
480  }
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 513 of file TimeDiscretization.h.

513 { 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 506 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 118 of file TimeDiscretization.cpp.

References NumLib::detail::BDF_Coeffs.

119 {
120  auto const k = eff_num_steps();
121  return detail::BDF_Coeffs[k - 1][0] / _delta_t;
122 }
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 74 of file TimeDiscretization.cpp.

References NumLib::TimeDiscretization::computeRelativeChangeFromPreviousTimestep().

76 {
78  x, *_xs_old[_offset], norm_type);
79 }
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 124 of file TimeDiscretization.cpp.

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

125 {
126  namespace LinAlg = MathLib::LinAlg;
127 
128  auto const k = eff_num_steps();
129  auto const* const BDFk = detail::BDF_Coeffs[k - 1];
130 
131  // compute linear combination \sum_{i=0}^{k-1} BDFk_{k-i} \cdot x_{n+i}
132  LinAlg::copy(*_xs_old[_offset], y); // _xs_old[offset] = x_n
133  LinAlg::scale(y, BDFk[k]);
134 
135  for (unsigned i = 1; i < k; ++i)
136  {
137  auto const off = (_offset + i) % k;
138  LinAlg::axpy(y, BDFk[k - i], *_xs_old[off]);
139  }
140 
141  LinAlg::scale(y, 1.0 / _delta_t);
142 }
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 500 of file TimeDiscretization.h.

501  {
502  _t = t;
503  _delta_t = delta_t;
504  }

◆ 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 495 of file TimeDiscretization.h.

References MathLib::LinAlg::copy().

496  {
497  MathLib::LinAlg::copy(*_xs_old[_xs_old.size()-1], x);
498  }
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 81 of file TimeDiscretization.cpp.

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

84 {
85  namespace LinAlg = MathLib::LinAlg;
86  // TODO use boost circular buffer?
87 
88  // until _xs_old is filled, lower-order BDF formulas are used.
89  if (_xs_old.size() < _num_steps)
90  {
91  _xs_old.push_back(&NumLib::GlobalVectorProvider::provider.getVector(x));
92  }
93  else
94  {
96  _offset =
97  (_offset + 1) % _num_steps; // treat _xs_old as a circular buffer
98  }
99 }
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 482 of file TimeDiscretization.h.

References NumLib::GlobalVectorProvider::provider.

483  {
484  _t = t0;
485  _xs_old.push_back(
487  }
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 516 of file TimeDiscretization.h.

◆ _num_steps

const unsigned NumLib::BackwardDifferentiationFormula::_num_steps
private

The order of the BDF method.

Definition at line 514 of file TimeDiscretization.h.

◆ _offset

unsigned NumLib::BackwardDifferentiationFormula::_offset = 0
private

allows treating _xs_old as circular buffer

Definition at line 519 of file TimeDiscretization.h.

◆ _t

double NumLib::BackwardDifferentiationFormula::_t
private

$ t_C $

Definition at line 515 of file TimeDiscretization.h.

◆ _xs_old

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

solutions from the preceding timesteps

Definition at line 518 of file TimeDiscretization.h.


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