Boost odeint中的受控误差步进器是否支持复杂的数据类型? [英] Do controlled error steppers in boost odeint support complex data types?

查看:135
本文介绍了Boost odeint中的受控误差步进器是否支持复杂的数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了使用受控错误步进器和复杂状态类型的odeint库问题.我修改了带有复杂stuart landau方程的示例中的代码,使其包含自适应积分器.现在的代码如下:

I encountered a problem with the odeint library using a controlled error stepper together with a complex state type. The code from the example with the complex stuart landau equation, I modified such that it includes an adaptive integrator. The code looks like this now:

#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;
    }
};
//]


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.precision(10);
        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 );

    bulirsch_stoer< state_type > stepper( 1E-12 , 1E-12 , 1 , 1 );

    const double dt = 0.1;

    //]
    integrate_adaptive( stepper , stuart_landau( 2.0 , 1.0 ) , x , 0.0 , 10.0 , dt , streaming_observer( cout ) );

    return 0;
}

但是,如果我将步进器的定义更改为

However, if I change the definition of the stepper to

bulirsch_stoer< state_type, complex< double > > stepper( 1E-12 , 1E-12 , 1 , 1 );

编译失败. 我的问题是:受控错误步进器是否不支持复杂数据类型?如果是这样,那么有解决该问题的方法.或者,是否可以为复杂的数据类型定义自己的矢量代数?

compilation fails. My question is: Are complex data types not supported in controlled error steppers? If so, is there a method to circumvent the problem, which arises. Or, is it possible to define an own vector algebra for the complex data type?

推荐答案

odeint库确实支持复杂的数据类型,包括受控步进器.

The odeint library does support complex data types, including controlled steppers.

例如,要获得4/5阶Dormand-Prince方法的受控步进器,您可以执行以下操作:

As an example, to obtain a controlled stepper in the case of the 4th/5th order Dormand-Prince method you can do this:

runge_kutta_dopri5< state_type > stepper;
auto c_stepper = make_controlled(1.E-12, 1.E-12, stepper); 
integrate_adaptive(c_stepper, stuart_landau( 2.0 , 1.0 ) , x , 0.0 , 10.0 , dt , streaming_observer( cout ) );

state_type的类型定义为

typedef complex< double > state_type;

Bulirsch-Stoer算法本质上已经是受控的步进器.因此,在这种情况下,无法应用make_controlled或其他策略来创建受控步进器. odeint库中没有这样的模板,因为这没有意义.

The Bulirsch-Stoer algorithm that is implemented in odeint, however, is already inherently a controlled stepper. It is therefore not possible to apply make_controlled or other strategies to create controlled steppers in this case. There is no such template in the odeint library because it would not make sense.

您发布的第一个代码已经集成了ODE,复杂的值和受控的步进器.目前尚不清楚您要通过将步进器更改为

The first code that you posted already integrates the ODE, with complex values and with a controlled stepper. It is not clear what you are trying to achieve by changing the stepper to

bulirsch_stoer< complex<double>, complex<double> > stepper( 1E-12 , 1E-12 , 1 , 1 );

这篇关于Boost odeint中的受控误差步进器是否支持复杂的数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆