Solver#

There are two ways to solve a problem with ponio, the first one is with the function ponio::solve(), the second one is with an iterator with ponio::time_iterator.

Function#

The function ponio::solve() takes care of the time loop, you can’t control it. This is sufficient in many cases.

template<typename Problem_t, typename Algorithm_t, typename state_t, typename value_t, typename Observer_t>
state_t ponio::solve(Problem_t &pb, Algorithm_t &&algo, state_t const &u0, ponio::time_span<value_t> const &t_span, value_t dt, Observer_t &&obs)#

solve a problem on a specific time range with a specific method

Parameters:
  • pb – problem to solve, it could by any function or functor with a call operator with following parameter (value_t tn, state_t& un).

  • algo – choosen method to solve the problem pb

  • u0 – initial condition \(u_0 = u(t=0)\)

  • t_span – container \([t_\text{start} , t_\text{end}]\) with possible intermediate time value where solver should go

  • dt – time step value \(\Delta t\)

  • obs – observer that do something with current time, solution and time step at each iteration

Returns:

returns the last value of solution \(u^n\)

Example of solving Curtiss-Hirschfelder problem with RK(4, 4). The ODE is defined by

\[\begin{split}\begin{cases} \dot{y} = k(\cos(t) - y) \\ y(0) = 2 \end{cases}\end{split}\]

with \(k=50\).

auto f = [](double t, double y)
{
   double k = 50;
   return k * ( std::cos(t) - y );
};

double y0 = 2.0;
double dt = 0.01;

ponio::solver(f, ponio::runge_kutta::rk_44(), y0, {0., 2.}, dt, "output.txt"_fobs);

Iterator#

When you need to control the time loop you have to build a ponio::solver_range and then iterate on it with a ponio::time_iterator.

Solver range class#

template<typename value_t, typename state_t, typename method_t, typename problem_t>
struct solver_range#

structure that stores begin and end time_iterator of a range of solutions

Template Parameters:
  • value_t – type of time and time step

  • state_t – type of solution \(u^n\)

  • method_t – type of numerical method to solve problem

  • problem_t – type of problem

Public Functions

inline solver_range(iterator_type const &begin, sentinel_type const &end)#

Construct a new solver range object.

Parameters:
inline auto &begin()#

returns an iterator to the beginning solver_range

inline auto const &cbegin() const#

returns a constant iterator to the beginning solver_range

inline auto const &begin() const#

returns a constant iterator to the beginning solver_range

inline auto &end()#

returns an iterator to the ending solver_range

inline auto const &cend() const#

returns a constant iterator to the ending solver_range

inline auto const &end() const#

returns a constant iterator to the ending solver_range

Helper function for solver_range

template<typename value_t, typename state_t, typename algorithm_t, typename problem_t>
auto ponio::make_solver_range(problem_t &pb, algorithm_t &&algo, state_t const &u0, ponio::time_span<value_t> const &t_span, value_t dt)#

makes a range of solutions at each time

Template Parameters:
  • value_t – type of time and time step

  • state_t – type of solution \(u^n\)

  • algorithm_t – type of numerical method to solve problem

  • problem_t – type of problem

Parameters:
  • pb – problem to solve, it could be any function of functor with a call operator with following parameter (value_t tn, state_t const& un)

  • algo – choosen method to solve the problem pb

  • u0 – initial condition \(u_0 = u(t=0)\)

  • t_span – container \([t_\text{start} , t_\text{end}]\) with possible intermediate time value where solver should go

  • dt – time step value \(\Delta t\)

Returns:

returns the range with all solutions

Time iterator class#

template<typename value_t, typename state_t, typename method_t, typename problem_t>
struct time_iterator#

iterator on ponio::solver_range

Template Parameters:
  • value_t – type of time value

  • state_t – type of solution \(u^n\)

  • method_t – type of object used to iterate (an instance of ponio::method)

  • problem_t – type of callable object problem \(f: t, u \mapsto f(t, u)\)

Public Types

using difference_type = value_t#

type of difference between two iterators, returns difference of current time of each iterator

using value_type = current_solution<value_t, state_t>#

type of stored value

using pointer = value_type*#

type of pointer on stored value

using reference = value_type&#

type of reference on stored value

using const_pointer = value_type const*#

type of constant pointer on stored value

using const_reference = value_type const&#

type of constant reference on stored value

using iterator_category = std::output_iterator_tag#

specify the category of iterator, here corresponds to output iterator (see iterator tags for more information)

Public Functions

inline time_iterator(problem_t &pb_, method_t &&meth_, state_t const &u0, ponio::time_span<value_t> const &t_span_, value_t dt)#

Construct a new time iterator object.

Note

In user interface ponio::time_iterator object is build by ponio::solver_range member functions.

Parameters:
  • pb_ – problem object that represent \(f: t, u \mapsto f(t, u)\)

  • meth_ponio::method object

  • u0 – initial value of state \(u\)

  • t_span_ – vector of initial time and final time with optional intermediate time

  • dt – time step value \(\Delta t\)

inline time_iterator(time_iterator const &rhs)#

Copy constructor of time_iterator.

Parameters:

rhs

inline time_iterator(time_iterator &&rhs) noexcept#

Move constructor of time_iterator.

Parameters:

rhs

inline time_iterator &operator=(time_iterator const &rhs)#

Equality operator of time_iterator.

Parameters:

rhs

Returns:

time_iterator&

inline time_iterator &operator=(time_iterator &&rhs) noexcept#

Equality operator of time_iterator.

Parameters:

rhs

Returns:

time_iterator&

inline void increment()#

increment current state by current time step

\((t^n, u^n, \Delta t^n ) \gets \phi(t^n, u^n, \Delta t^n)\) where \(\phi\) represents the method.

inline difference_type next_time() const#

get the next time value \(t^n + \Delta t^n\)

Returns:

difference_type

inline time_iterator &operator++()#

increment properly time_iterator in the solver_range (take care of end point and optionally middle points in given t_span)

inline time_iterator operator++(int)#

post fix increment time_iterator

inline reference operator*()#

dereference time_iterator and get current solution data member

inline const_reference operator*() const#

dereference time_iterator and get current solution data member

inline pointer operator->()#

accessor to current solution data member

inline const_pointer operator->() const#

accessor to current solution data member

inline auto &info()#

accessor to informations on iteration with algorithm

Returns:

auto&

inline auto const &info() const#

accessor to informations on iteration with algorithm

Returns:

auto const&

inline auto &stages()#

returns stages if need to access to them to resize or change condition on them

Returns:

auto&

inline auto const &stages() const#

returns stages if need to access to them

Returns:

auto const&

template<std::size_t I>
inline auto &stages(sub_method<I> subI)#

returns stages if need to access to them to resize or change condition on them

Returns:

auto&

template<std::size_t I>
inline auto const &stages(sub_method<I> subI) const#

returns stages if need to access to them

Returns:

auto const&

template<typename lambda_t>
inline void callback_on_stages(lambda_t &&f)#

call a callback function on each intermediate stage of method and also on temporary \(u^{n=1}\) state

Parameters:

f – callback function

Helper function for time_iterator

template<typename value_t, typename state_t, typename method_t, typename problem_t>
auto ponio::make_time_iterator(problem_t &pb, method_t &&meth, state_t const &u0, ponio::time_span<value_t> const &t_span, value_t dt)#

factory of time_iterator

Template Parameters:
  • value_t – type of time and time step

  • state_t – type of solution \(u^n\)

  • method_t – type of numerical method to solve problem

  • problem_t – type of problem

Parameters:
  • pb – problem to solve, it could be any function of functor with a call operator with following parameter (value_t tn, state_t const& un)

  • meth – choosen method to solve the problem pb

  • u0 – initial condition \(u_0 = u(t=0)\)

  • t_span – vector of initial time and final time with optional intermediate time

  • dt – time step value \(\Delta t\)

Returns:

auto

template<typename value_t, typename state_t>
struct current_solution#

store \((t^n, u^n, \Delta t^n)\)

Template Parameters:
  • value_t – type of time

  • state_t – type of solution \(u^n\)

Iteration information class#

If you need information on current iteration, ponio provides a ponio::iteration_info class to access to some information on algorithm:

  • number of stages,

  • number of evaluation of function (also count evaluation in Newton method for implicit methods),

  • a boolean to test if iterator is on a step given to ponio::make_solver_range() (t_span),

  • tolerance, error and a boolean to test if the iteration is succeed for adaptive time step methods.

template<typename tableau_t>
struct iteration_info#

stores information for and of current iteration in algorithm

Template Parameters:

tableau_t – type of Butcher tableau

Public Types

using value_t = typename tableau_t::value_t#

type of coefficient of Butcher tableau, same type to store error and tolerance

Public Functions

inline iteration_info(value_t tol = static_cast<value_t>(0))#

Construct a new iteration info object.

Parameters:

tol – tolerance for adaptive time step method

inline void reset_eval()#

reset number of evaluations to zero

Public Members

value_t error#

error makes on time iteration for adaptive time step method

bool success = true#

sets as true only for success iteration

bool is_step = false#

sets as true only if iterator is on a step given in solver

std::size_t number_of_stages#

number of stages of method

std::size_t number_of_eval#

number of evaluation of function

value_t tolerance#

tolerance for the method (for adaptive time step method)

value_t absolute_tolerance#

absolute tolerance for the method (for adaptive time step method)

value_t relative_tolerance#

relative tolerance for the method (for adaptive time step method)