Controlled Runge Kutta Implementation Doesn't Match Documentation

Open
#91 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
43/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
documentation

Research direction

Read the controlled Runge-Kutta implementation in include/boost/numeric/odeint/stepper/controlled_runge_kutta.hpp alongside the linked steppers documentation. Confirm which step-size formula is intended, then update the documentation so it matches the confirmed behavior and verify the rendered formula is accurate.

Written by the indexing model from the issue text.

Description

In the case where the time step is increased the function increase_step is used from include/boost/numeric/odeint/stepper/controlled_runge_kutta.hpp which I've copied below:

    time_type increase_step(time_type dt, value_type error, const int stepper_order) const
    {
        // returns the increased time step
        BOOST_USING_STD_MIN();
        BOOST_USING_STD_MAX();
        using std::pow;

        // adjust the size if dt is smaller than max_dt (providede max_dt is not zero)
        if(error < 0.5)
        {
            // error should be > 0
            error = max BOOST_PREVENT_MACRO_SUBSTITUTION (
                    static_cast<value_type>( pow( static_cast<value_type>(5.0) , -static_cast<value_type>(stepper_order) ) ) ,
                    error);
            // time_type dt_old = dt;   unused variable warning 
            //error too small - increase dt and keep the evolution and limit scaling factor to 5.0
            dt *= static_cast<value_type>(9)/static_cast<value_type>(10) *
                  pow(error, static_cast<value_type>(-1) / stepper_order);
            if(m_max_dt != static_cast<time_type >(0))
                // limit to maximal stepsize
                dt = detail::min_abs(dt, m_max_dt);
        }
        return dt;
    }

Inside of the control flow, $error = \max(5^{-S}, error)$ and then dt is multiplied by $0.9 * error^{-1/S} = 0.9*\min(5, error^{-1/S})$ which limits the maximum step size change to a factor of 4.5.

The documentation here states that if val < 0.5 : dt​_new = dt​_current min( 0.9 pow( val , -1 / O​S ) , 5 ) which has the factor of 0.9 inside the minimum. In this case the maximum step size change is instead limited to a factor of 5.

I'll offer to attempt a PR for the documentation if someone confirms my understanding is correct.

Dominant language
C++
Stars
55
Forks
59
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/odeint

All issues in boostorg/odeint

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.