OGS 6.2.1-76-gbb689931b
NumLib::CrankNicolson Class Referencefinal

Detailed Description

Generalized Crank-Nicolson scheme.

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

395  : _theta(theta),
397  {
398  }
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 400 of file TimeDiscretization.h.

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

401  {
403  }
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 432 of file TimeDiscretization.h.

432 { return _t; }

◆ getNewXWeight()

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

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

Implements NumLib::TimeDiscretization.

Definition at line 433 of file TimeDiscretization.h.

433 { 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 445 of file TimeDiscretization.h.

445 { 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 434 of file TimeDiscretization.h.

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

435  {
436  namespace LinAlg = MathLib::LinAlg;
437 
438  // y = x_old / delta_t
439  LinAlg::copy(_x_old, y);
440  LinAlg::scale(y, 1.0 / _delta_t);
441  }
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 447 of file TimeDiscretization.h.

447 { 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 443 of file TimeDiscretization.h.

443 { 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 426 of file TimeDiscretization.h.

427  {
428  _t = t;
429  _delta_t = delta_t;
430  }
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 421 of file TimeDiscretization.h.

References MathLib::LinAlg::copy().

422  {
424  }
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 414 of file TimeDiscretization.h.

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

416  {
418  strg.pushMatrices();
419  }
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 405 of file TimeDiscretization.h.

References MathLib::LinAlg::copy().

406  {
407  _t = t0;
409  }
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
Initial value:
=
std::numeric_limits<double>::quiet_NaN()

the timestep size

Definition at line 451 of file TimeDiscretization.h.

◆ _t

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

$ t_C $

Definition at line 450 of file TimeDiscretization.h.

◆ _theta

const double NumLib::CrankNicolson::_theta
private

the implicitness parameter $ \theta $

Definition at line 449 of file TimeDiscretization.h.

◆ _x_old

GlobalVector& NumLib::CrankNicolson::_x_old
private

the solution from the preceding timestep

Definition at line 453 of file TimeDiscretization.h.


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