OGS 6.2.0-97-g4a610c866
NumLib::CrankNicolson Class Referencefinal

Detailed Description

Generalized Crank-Nicolson scheme.

Definition at line 379 of file TimeDiscretization.h.

#include <TimeDiscretization.h>

Inheritance diagram for NumLib::CrankNicolson:
Collaboration diagram for NumLib::CrankNicolson:

Public Member Functions

 CrankNicolson (const double theta)
 
 ~CrankNicolson () 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 &strg) 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...
 
bool needsPreload () const override
 
double getTheta () const
 Returns $ \theta $. More...
 
GlobalVector const & getXOld () const
 Returns the solution from the preceding timestep. 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
 

Private Attributes

const double _theta
 the implicitness parameter $ \theta $ More...
 
double _t
 $ t_C $ More...
 
double _delta_t
 the timestep size More...
 
GlobalVector & _x_old
 the solution from the preceding timestep 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

◆ CrankNicolson()

NumLib::CrankNicolson::CrankNicolson ( const double  theta)
inlineexplicit

Constructs a new instance.

Parameters
thetaThe implicitness parameter $ \theta $. Some special values are:

Definition at line 390 of file TimeDiscretization.h.

391  : _theta(theta),
393  {
394  }
const double _theta
the implicitness parameter
static NUMLIB_EXPORT VectorProvider & provider
GlobalVector & _x_old
the solution from the preceding timestep

◆ ~CrankNicolson()

NumLib::CrankNicolson::~CrankNicolson ( )
inlineoverride

Definition at line 396 of file TimeDiscretization.h.

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

397  {
399  }
static NUMLIB_EXPORT VectorProvider & provider
GlobalVector & _x_old
the solution from the preceding timestep
virtual void releaseVector(GlobalVector const &x)=0

Member Function Documentation

◆ getCurrentTime()

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

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

Implements NumLib::TimeDiscretization.

Definition at line 428 of file TimeDiscretization.h.

428 { return _t; }

◆ getNewXWeight()

double NumLib::CrankNicolson::getNewXWeight ( ) const
inlineoverridevirtual

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

Implements NumLib::TimeDiscretization.

Definition at line 429 of file TimeDiscretization.h.

429 { return 1.0 / _delta_t; }
double _delta_t
the timestep size

◆ getRelativeChangeFromPreviousTimestep()

double NumLib::CrankNicolson::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 }
GlobalVector & _x_old
the solution from the preceding timestep
double computeRelativeChangeFromPreviousTimestep(GlobalVector const &x, GlobalVector const &x_old, MathLib::VecNormType norm_type)

◆ getTheta()

double NumLib::CrankNicolson::getTheta ( ) const
inline

Returns $ \theta $.

Definition at line 441 of file TimeDiscretization.h.

441 { return _theta; }
const double _theta
the implicitness parameter

◆ getWeightedOldX()

void NumLib::CrankNicolson::getWeightedOldX ( GlobalVector &  y) const
inlineoverridevirtual

Returns $ x_O $.

Implements NumLib::TimeDiscretization.

Definition at line 430 of file TimeDiscretization.h.

References MathLib::LinAlg::copy(), and MathLib::LinAlg::scale().

431  {
432  namespace LinAlg = MathLib::LinAlg;
433 
434  // y = x_old / delta_t
435  LinAlg::copy(_x_old, y);
436  LinAlg::scale(y, 1.0 / _delta_t);
437  }
double _delta_t
the timestep size
GlobalVector & _x_old
the solution from the preceding timestep
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

◆ getXOld()

GlobalVector const& NumLib::CrankNicolson::getXOld ( ) const
inline

Returns the solution from the preceding timestep.

Definition at line 443 of file TimeDiscretization.h.

443 { return _x_old; }
GlobalVector & _x_old
the solution from the preceding timestep

◆ needsPreload()

bool NumLib::CrankNicolson::needsPreload ( ) const
inlineoverridevirtual

Indicate that this scheme needs some additional assembly before the first timestep will be solved.

The CrankNicolson scheme needs such preload.

Reimplemented from NumLib::TimeDiscretization.

Definition at line 439 of file TimeDiscretization.h.

439 { return true; }

◆ nextTimestep()

void NumLib::CrankNicolson::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 422 of file TimeDiscretization.h.

423  {
424  _t = t;
425  _delta_t = delta_t;
426  }
double _delta_t
the timestep size

◆ popState()

void NumLib::CrankNicolson::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 417 of file TimeDiscretization.h.

References MathLib::LinAlg::copy().

418  {
420  }
GlobalVector & _x_old
the solution from the preceding timestep
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:36

◆ pushState()

void NumLib::CrankNicolson::pushState ( const double  t,
GlobalVector const &  x,
InternalMatrixStorage const &  strg 
)
inlineoverridevirtual

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

References MathLib::LinAlg::copy(), and NumLib::InternalMatrixStorage::pushMatrices().

412  {
414  strg.pushMatrices();
415  }
GlobalVector & _x_old
the solution from the preceding timestep
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:36

◆ setInitialState()

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

Sets the initial condition.

Implements NumLib::TimeDiscretization.

Definition at line 401 of file TimeDiscretization.h.

References MathLib::LinAlg::copy().

402  {
403  _t = t0;
405  }
GlobalVector & _x_old
the solution from the preceding timestep
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:36

Member Data Documentation

◆ _delta_t

double NumLib::CrankNicolson::_delta_t
private

the timestep size

Definition at line 447 of file TimeDiscretization.h.

◆ _t

double NumLib::CrankNicolson::_t
private

$ t_C $

Definition at line 446 of file TimeDiscretization.h.

◆ _theta

const double NumLib::CrankNicolson::_theta
private

the implicitness parameter $ \theta $

Definition at line 445 of file TimeDiscretization.h.

◆ _x_old

GlobalVector& NumLib::CrankNicolson::_x_old
private

the solution from the preceding timestep

Definition at line 448 of file TimeDiscretization.h.


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