OGS 6.2.1-499-g3b941532c.dirty.20191012113459
NumLib::BackwardDifferentiationFormula Class Referencefinal

Detailed Description

Backward differentiation formula.

Definition at line 465 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 getCurrentTimeIncrement () 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 = std::numeric_limits<double>::quiet_NaN()
 $ 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 480 of file TimeDiscretization.h.

481  : _num_steps(num_steps)
482  {
483  assert(1 <= num_steps && num_steps <= 6);
484  _xs_old.reserve(num_steps);
485  }
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 487 of file TimeDiscretization.h.

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

488  {
489  for (auto* x : _xs_old)
490  {
492  }
493  }
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 527 of file TimeDiscretization.h.

527 { 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 519 of file TimeDiscretization.h.

◆ getCurrentTimeIncrement()

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

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

Implements NumLib::TimeDiscretization.

Definition at line 520 of file TimeDiscretization.h.

520 { return _delta_t; }

◆ getNewXWeight()

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

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

Implements NumLib::TimeDiscretization.

Definition at line 119 of file TimeDiscretization.cpp.

References NumLib::detail::BDF_Coeffs.

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

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

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

514  {
515  _t = t;
516  _delta_t = delta_t;
517  }

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

References MathLib::LinAlg::copy().

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

◆ 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.

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

◆ setInitialState()

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

Sets the initial condition.

Implements NumLib::TimeDiscretization.

Definition at line 495 of file TimeDiscretization.h.

References NumLib::GlobalVectorProvider::provider.

496  {
497  _t = t0;
498  _xs_old.push_back(
500  }
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
Initial value:
=
std::numeric_limits<double>::quiet_NaN()

the timestep size

Definition at line 530 of file TimeDiscretization.h.

◆ _num_steps

const unsigned NumLib::BackwardDifferentiationFormula::_num_steps
private

The order of the BDF method.

Definition at line 528 of file TimeDiscretization.h.

◆ _offset

unsigned NumLib::BackwardDifferentiationFormula::_offset = 0
private

allows treating _xs_old as circular buffer

Definition at line 534 of file TimeDiscretization.h.

◆ _t

double NumLib::BackwardDifferentiationFormula::_t = std::numeric_limits<double>::quiet_NaN()
private

$ t_C $

Definition at line 529 of file TimeDiscretization.h.

◆ _xs_old

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

solutions from the preceding timesteps

Definition at line 533 of file TimeDiscretization.h.


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