Discontinuous Galerkin Library
#include "dg/algorithm.h"
dg::SinglestepTimeloop< ContainerType > Struct Template Reference

Integrate using a for loop and a fixed time-step. More...

Inheritance diagram for dg::SinglestepTimeloop< ContainerType >:
[legend]

Public Types

using container_type = ContainerType
 
using value_type = dg::get_value_type< ContainerType >
 
- Public Types inherited from dg::aTimeloop< ContainerType >
using value_type = dg::get_value_type< ContainerType >
 
using container_type = ContainerType
 

Public Member Functions

 SinglestepTimeloop ()=default
 no allocation More...
 
 SinglestepTimeloop (std::function< void(value_type, const ContainerType &, value_type &, ContainerType &, value_type)> step, value_type dt=0)
 Construct using a std::function. More...
 
template<class Stepper , class ODE >
 SinglestepTimeloop (Stepper &&stepper, ODE &&ode, value_type dt=0)
 Bind the step function of a single step stepper. More...
 
template<class ... Params>
void construct (Params &&...ps)
 Perfect forward parameters to one of the constructors. More...
 
void set_dt (value_type dt)
 Set the constant timestep to be used in the integrate functions. More...
 
void integrate_steps (value_type t0, const container_type &u0, value_type t1, container_type &u1, unsigned steps)
 Integrate differential equation with a fixed number of steps. More...
 
virtual SinglestepTimeloopclone () const
 Abstract copy method that returns a copy of *this on the heap. More...
 
- Public Member Functions inherited from dg::aTimeloop< ContainerType >
void integrate (value_type t0, const ContainerType &u0, value_type t1, ContainerType &u1)
 Integrate a differential equation between given bounds. More...
 
void integrate (value_type &t0, const ContainerType &u0, value_type t1, ContainerType &u1, enum to mode)
 Build your own timeloop. More...
 
value_type get_dt () const
 The current timestep. More...
 
virtual aTimeloopclone () const =0
 Abstract copy method that returns a copy of *this on the heap. More...
 
virtual ~aTimeloop ()
 

Additional Inherited Members

- Protected Member Functions inherited from dg::aTimeloop< ContainerType >
 aTimeloop ()
 empty More...
 
 aTimeloop (const aTimeloop &)
 empty More...
 
aTimeloopoperator= (const aTimeloop &)
 return *this More...
 

Detailed Description

template<class ContainerType>
struct dg::SinglestepTimeloop< ContainerType >

Integrate using a for loop and a fixed time-step.

The implementation (of integrate) is equivalent to

dg::blas1::copy( u0, u1);
unsigned N = round((t1 - t0)/dt);
for( unsigned i=0; i<N; i++)
step( t0, u1, t0, u1, dt);
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
Definition: blas1.h:164

where dt is a given constant. If t1 needs to be matched exactly, the last timestep is shortened accordingly.

See also
AdaptiveTimeloop, MultistepTimeloop
Template Parameters
ContainerTypeAny class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag. Among others
  • dg::HVec (serial), dg::DVec (cuda / omp), dg::MHVec (mpi + serial) or dg::MDVec (mpi + cuda / omp)
  • std::vector<dg::DVec> (vector of shared device vectors), std::array<double, 4> (array of 4 doubles) or std::map < std::string, dg::DVec> ( a map of named vectors)
  • double (scalar) and other primitive types ...
If there are several ContainerTypes in the argument list, then TensorTraits must exist for all of them
See also
See The dg dispatch system for a detailed explanation of our type dispatch system

Member Typedef Documentation

◆ container_type

template<class ContainerType >
using dg::SinglestepTimeloop< ContainerType >::container_type = ContainerType

◆ value_type

template<class ContainerType >
using dg::SinglestepTimeloop< ContainerType >::value_type = dg::get_value_type<ContainerType>

Constructor & Destructor Documentation

◆ SinglestepTimeloop() [1/3]

template<class ContainerType >
dg::SinglestepTimeloop< ContainerType >::SinglestepTimeloop ( )
default

no allocation

◆ SinglestepTimeloop() [2/3]

template<class ContainerType >
dg::SinglestepTimeloop< ContainerType >::SinglestepTimeloop ( std::function< void(value_type, const ContainerType &, value_type &, ContainerType &, value_type)>  step,
value_type  dt = 0 
)
inline

Construct using a std::function.

Parameters
stepCalled in the timeloop as step( t0, u1, t0, u1, dt) . Has to advance the ode in-place by dt
dtThe constant timestep. Can be set later with set_dt. Can be negative.

◆ SinglestepTimeloop() [3/3]

template<class ContainerType >
template<class Stepper , class ODE >
dg::SinglestepTimeloop< ContainerType >::SinglestepTimeloop ( Stepper &&  stepper,
ODE &&  ode,
value_type  dt = 0 
)
inline

Bind the step function of a single step stepper.

Construct a lambda function that calls the step function of stepper with given parameters and stores it internally in a std::function

Template Parameters
Stepperpossible steppers are for example dg::RungeKutta, dg::ShuOsher and dg::ImplicitRungeKutta
Parameters
stepperIf constructed in-place (rvalue), will be copied into the lambda. If an lvalue, then the lambda stores a reference
Attention
If stepper is an lvalue then you need to make sure that stepper remains valid to avoid a "dangling reference"
Template Parameters
ODEThe ExplicitRHS or tuple type that corresponds to what is inserted into the step member of the Stepper
Parameters
oderhs or tuple
dtThe constant timestep. Can be set later with set_dt. Can be negative.

Member Function Documentation

◆ clone()

template<class ContainerType >
virtual SinglestepTimeloop * dg::SinglestepTimeloop< ContainerType >::clone ( ) const
inlinevirtual

Abstract copy method that returns a copy of *this on the heap.

Returns
a copy of *this on the heap
See also
dg::ClonePtr

Implements dg::aTimeloop< ContainerType >.

◆ construct()

template<class ContainerType >
template<class ... Params>
void dg::SinglestepTimeloop< ContainerType >::construct ( Params &&...  ps)
inline

Perfect forward parameters to one of the constructors.

Template Parameters
Paramsdeduced by the compiler
Parameters
psparameters forwarded to constructors

◆ integrate_steps()

template<class ContainerType >
void dg::SinglestepTimeloop< ContainerType >::integrate_steps ( value_type  t0,
const container_type u0,
value_type  t1,
container_type u1,
unsigned  steps 
)
inline

Integrate differential equation with a fixed number of steps.

Equivalent to

set_dt( (t1-t0)/(value_type)steps );
integrate( t0, u0, t1, u1);
void set_dt(value_type dt)
Set the constant timestep to be used in the integrate functions.
Definition: runge_kutta.h:1046
dg::get_value_type< ContainerType > value_type
Definition: runge_kutta.h:992
void integrate(value_type t0, const ContainerType &u0, value_type t1, ContainerType &u1)
Integrate a differential equation between given bounds.
Definition: ode.h:83
Parameters
t0initial time
u0initial condition
t1final time
u1(write-only) contains solution at t1 on return (may alias u0)
stepsnumber of steps

◆ set_dt()

template<class ContainerType >
void dg::SinglestepTimeloop< ContainerType >::set_dt ( value_type  dt)
inline

Set the constant timestep to be used in the integrate functions.

Parameters
dtnew timestep to use in integrate functions. Can be negative.

The documentation for this struct was generated from the following file: