headmyshoulder / odeint-v2

odeint - solving ordinary differential equations in c++ v2
http://headmyshoulder.github.com/odeint-v2/
Other
337 stars 102 forks source link

Complex type + controlled stepper fails compilation #244

Open mebelz opened 4 years ago

mebelz commented 4 years ago

Trying to integrate with this combination (complex type + controlled stepper) fails, with the error message:

/usr/include/boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp:103:22: error: no matching member function for
       call to 'try_step'
             res = st.try_step( system , start_state , start_time , dt );
                   ~~~^~~~~~~~

Interestingly, removing the value_type std::complex from the stepper definition seems to "fix" the issue? (which is returns if std::vector is then replaced with ublas::vector)

#include <iostream>
#include <vector>
#include <complex>

#include <boost/numeric/odeint.hpp>

typedef std::vector< std::complex<double> > state_type;

const double gam = 0.15;

void harmonic_oscillator( const state_type &x , state_type &dxdt , const double /* t */ )
{
    dxdt[0] = x[1];
    dxdt[1] = -x[0] - gam*x[1];
}

int main(int /* argc */ , char** /* argv */ )
{
    using namespace std;
    using namespace boost::numeric::odeint;
    state_type x(2);
    x[0] = 1.0;
    x[1] = 0.0;
    typedef runge_kutta_cash_karp54< state_type, std::complex<double> > error_stepper_type;
    integrate_adaptive( make_controlled< error_stepper_type >( 1.0e-10 , 1.0e-6 ) ,
                        harmonic_oscillator , x , 0.0 , 10.0 , 0.01 );
    return 0;
}