Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get BOOST odeint to work with Adams-Bashforth-Moulton

Tags:

c++

boost

I am having some trouble getting the Adams-Bashforth-Moulton method from the BOOST odeint library to work. I have succeeded with Bulirsch-Stoer, but for some reason Adams-Bashforth-Moulton just returns nan whenever I try to use an order > 2. If I use order 1 or 2, I get double the true answer. I have reduced my code to:

#include <iostream>
#include <boost/array.hpp>
#include <boost/numeric/odeint.hpp>
#include <boost/version.hpp>


typedef boost::array<long double, 2> state_type;
using namespace boost::numeric::odeint;

class Boost_odeint_rhs{
    public:
        Boost_odeint_rhs(){
        }

        void operator() (const state_type &x, state_type &dxdt, const double t)
        {
            dxdt[0] = 1;
            dxdt[1] = 2;
        }
};


int main() {

    std::cout << "using boost "
              << BOOST_VERSION / 100000 << "."
              << BOOST_VERSION / 100 % 1000 << "."
              << BOOST_VERSION % 100 << std::endl;

    std::cout << "integrating vector [1,2] over (0,1)" << std::endl;

    Boost_odeint_rhs rhs;
    state_type Bint;
    Bint[0] = 0.0;
    Bint[1] = 0.0;

    adams_bashforth_moulton< 2 , state_type > stepper;
    //bulirsch_stoer< state_type > stepper( 1e-5 , 0.0 , 0.0 , 1.0 );

    integrate_adaptive( stepper , rhs , Bint , 0.0 , 1.0 , 1e-3 );

    std::cout << "returned integral = " << Bint[0] << " "<< Bint[1] << std::endl;
}

I am using BOOST 1.54.0 and GCC 4.8.2 on Ubuntu 14.04

Thanks in advance.

like image 516
Nick Ayres Avatar asked Aug 06 '14 16:08

Nick Ayres


1 Answers

Looks like a strange error. When I change

typedef boost::array< long double , 2 > state_type

to

typedef boost::array< double , 2 > state_type

it works. But of course this is not a real solution, but maybe this is a workaround for you. Nevertheless, I am trying to find the problem and to provide a solution.

Update: This is a bug in odeint. But it has already been fixed and will the fix will be available in the next version of boost (which should be appear very soon). You can also use the current version from odeint github repository.

like image 197
headmyshoulder Avatar answered Nov 01 '22 11:11

headmyshoulder