c++ - odeint 复杂状态类型示例无法编译

标签 c++ boost ode complextype odeint

我尝试在 Mac OS X 10.9.2 g++ 5.1 上的 boost_1_55_0 中运行 [odeint 复杂状态类型示例代码。

下面的代码是网站上解决 Stuart-Landau 振荡器的拷贝

#include <iostream>
#include <complex>
#include <boost/array.hpp>

#include <boost/numeric/odeint.hpp>

using namespace std;
using namespace boost::numeric::odeint;

//[ stuart_landau_system_function
typedef complex< double > state_type;

struct stuart_landau
{
    double m_eta;
    double m_alpha;

    stuart_landau( double eta = 1.0 , double alpha = 1.0 )
    : m_eta( eta ) , m_alpha( alpha ) { }

    void operator()( const state_type &x , state_type &dxdt , double t ) const
    {
        const complex< double > I( 0.0 , 1.0 );
        dxdt = ( 1.0 + m_eta * I ) * x - ( 1.0 + m_alpha * I ) * norm( x ) * x;
    }
};
//]


/*
//[ stuart_landau_system_function_alternative
double eta = 1.0;
double alpha = 1.0;

void stuart_landau( const state_type &x , state_type &dxdt , double t )
{
    const complex< double > I( 0.0 , 1.0 );
    dxdt = ( 1.0 + m_eta * I ) * x - ( 1.0 + m_alpha * I ) * norm( x ) * x;
}
//]
*/


struct streaming_observer
{
    std::ostream& m_out;

    streaming_observer( std::ostream &out ) : m_out( out ) { }

    template< class State >
    void operator()( const State &x , double t ) const
    {
        m_out << t;
        m_out << "\t" << x.real() << "\t" << x.imag() ;
        m_out << "\n";
    }
};




int main( int argc , char **argv )
{
    //[ stuart_landau_integration
    state_type x = complex< double >( 1.0 , 0.0 );

    const double dt = 0.1;

    typedef runge_kutta4< state_type > stepper_type;

    integrate_const( stepper_type() , stuart_landau( 2.0 , 1.0 ) , x , 0.0 , 10.0 , dt , streaming_observer( cout ) );
    //]

    return 0;
}

上面的示例代码无法编译。 9 个错误生成并结束于:

'boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4, 4, std::__1::complex<double>, double, std::__1::complex<double>, double,
      boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, 4, std::__1::complex<double>, double, std::__1::complex<double>,
      double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>::do_step_v1<stuart_landau, std::__1::complex<double> >'
      requested here
        do_step_v1( system , x , t , dt );
        ^
/usr/include/boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp:62:17: note: in instantiation of function template specialization
      'boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4, 4, std::__1::complex<double>, double, std::__1::complex<double>, double,
      boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, 4, std::__1::complex<double>, double, std::__1::complex<double>,
      double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>::do_step<stuart_landau, std::__1::complex<double> >' requested
      here
        stepper.do_step( system , start_state , end , end_time - end );
                ^
/usr/include/boost/numeric/odeint/integrate/integrate_const.hpp:50:24: note: in instantiation of function template specialization
      'boost::numeric::odeint::detail::integrate_adaptive<boost::numeric::odeint::runge_kutta4<std::__1::complex<double>, double, std::__1::complex<double>, double, boost::numeric::odeint::range_algebra,
      boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, stuart_landau, std::__1::complex<double>, double, streaming_observer>' requested here
        return detail::integrate_adaptive(
                       ^
main.cpp:84:5: note: in instantiation of function template specialization 'boost::numeric::odeint::integrate_const<boost::numeric::odeint::runge_kutta4<std::__1::complex<double>, double,
      std::__1::complex<double>, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, stuart_landau,
      std::__1::complex<double>, double, streaming_observer>' requested here
    integrate_const( stepper_type() , stuart_landau( 2.0 , 1.0 ) , x , 0.0 , 10.0 , dt , streaming_observer( cout ) );
^

错误是什么?

最佳答案

您使用的功能仅存在于 odeint 的 github 版本中。将步进器的 typedef 替换为

typedef runge_kutta4< state_type , double ,
                      state_type , double ,
                      vector_space_algebra > stepper_type;

自动代数检测目前仅适用于 github 版本的 odeint。我们尝试将此功能纳入下一个官方 boost 版本。

关于c++ - odeint 复杂状态类型示例无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22852091/

相关文章:

Boost Jam 与 Jam

python - 相空间中的轨迹 - 溢出错误 : (34, 'Result too large' )

r - deSolve:无法理解如何使用根函数提前停止 ode 求解器

c++ - 定义类 X 的析构函数,它继承自指向对象 Y 的指针 vector 并具有指向 Z 的指针数组

c++ - 如何调用boost multi_index元素的非常量成员函数

c++ - 缓存的 getter/计算模式|带依赖跟踪的 boost 类

python - odeint <-> interp1d 相互作用中可能存在的错误?

c++ - 以 map 作为参数的函数不起作用

c++ - 尝试编译一个qt项目,在各个地方出现输入/输出错误

c++ - 在复制构造函数中复制唯一指针数组的内容