Odeint隐式欧拉的简单例子

odeint implicit euler simple example

本文关键字:简单 Odeint      更新时间:2023-10-16

我对使用隐式方案解决odeint库的ode系统感兴趣,并且我很难实现一个简单的implicit_euler示例。

查看文档,我设法使工作显式步进器,自适应步进器,以及rosenbrock4步进器。前者似乎是半含蓄的。因此,我对实现一个完全隐式的方案很感兴趣(同时在每个时间步检索雅可比矩阵)。但我没有设法找到这个步骤的文档和工作示例。我有的是

typedef boost::numeric::ublas::vector< double > vector_type;
typedef boost::numeric::ublas::matrix< double > matrix_type;`
struct stiff_system
{
    void operator()( const vector_type &x , vector_type &dxdt , double /* t */ )
    {
        dxdt[ 0 ] = -101.0 * x[ 0 ] - 100.0 * x[ 1 ];
        dxdt[ 1 ] = x[ 0 ];
    }
};
struct stiff_system_jacobi
{
    void operator()( const vector_type & /* x */ , matrix_type &J , const double & /* t */ , vector_type &dfdt )
    {
    J( 0 , 0 ) = -101.0;
    J( 0 , 1 ) = -100.0;
    J( 1 , 0 ) = 1.0;
    J( 1 , 1 ) = 0.0;
    dfdt[0] = 0.0;
    dfdt[1] = 0.0;
    }
};
typedef implicit_euler< double > stepper_IE;
vector_type inout( 2 , 1.0 );
size_t steps = integrate_const( stepper_IE() ,
            std::make_pair( stiff_system() , stiff_system_jacobi() ) ,
            inout , 0.0 , 5.0 , 0.01, streaming_observer( std::cout, x_vec , times ));

错误如下:

C:boost_1_55_0boostnumericodeintstepperimplicit_euler.hpp:94:错误:C2064:术语不计算为具有3个参数的函数类没有定义一个"operator()"或用户定义的转换操作符,该转换操作符指向具有适当数量参数的指针到函数或引用到函数

我现在的问题是:有没有人知道如何使它工作,或者有人能给我指一个比这个更详细的文档:

codeproject上文档

或者这个

主页面

谢谢

不幸的是,隐式欧拉方法和Rosenbrock求解器(另一种隐式求解器)没有相同的接口。详细地说,隐式欧拉期望雅可比矩阵的函数具有以下签名

void jacobian( const state_type &x , matrix_type &jacobi , const value_type t );
因此,您需要将stiff_system_jacobi的定义更改为
struct stiff_system_jacobi
{
    void operator()( const vector_type & , matrix_type &J , const double & ) const
    {
        J( 0 , 0 ) = -101.0;
        J( 0 , 1 ) = -100.0;
        J( 1 , 0 ) = 1.0;
        J( 1 , 1 ) = 0.0;
    }
};

如果你的系统真的是非自治的,你需要通过一个额外的坐标来增强你的状态类型,这个坐标代表时间,并且具有微不足道的动态dt/dt = 1