简体   繁体   English

odeint隐式欧拉简单示例

[英]odeint implicit euler simple example

I am interested in solving a system of ODEs with odeint library using an implicit scheme and I have difficulties to implement a simple implicit_euler example. 我感兴趣的使用隐式常微分方程解的系统odeint库,我有困难,实现一个简单的implicit_euler例子。

Looking at the documentation, I managed to make work explicit steppers, adaptive ones, as well as the rosenbrock4 stepper. 通过查看文档,我设法使工作显式步进器,自适应步进器以及rosenbrock4步进器成为rosenbrock4 The former seem to be semi-implicit. 前者似乎是半隐式的。 Therefore I was interested in implementing a fully implicit scheme (and at the same time retrieve the jacobian matrix at each time step). 因此,我对实现完全隐式的方案感兴趣(并且同时在每个时间步骤都检索了jacobian矩阵)。 But I did not manage to find documentation and working examples of this stepper. 但是我没有找到该步进器的文档和工作示例。 What I have is 我有的是

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 ));

The error is the following: 错误如下:

C:\\boost_1_55_0\\boost\\numeric\\odeint\\stepper\\implicit_euler.hpp:94 : error: C2064: term does not evaluate to a function taking 3 arguments class does not define an ' operator() ' or a user defined conversion operator to a pointer-to-function or reference-to-function that takes appropriate number of arguments C:\\boost_1_55_0\\boost\\numeric\\odeint\\stepper\\implicit_euler.hpp:94 :错误:C2064:术语未评估为具有3个参数的函数类未定义' operator() '或用户定义的转换运算符带有适当数量参数的指向函数的指针或指向函数的引用

My question now is: does someone know how to make it work, or can someone point me towards a more detailed documentation than this one: 我现在的问题是:有人知道如何使它起作用,或者有人可以向我指出比这更详细的文档:

codeproject documentation 代码项目文档

or this one: 或这一个:

main odeint page 主节点页面

Thanks 谢谢

Unfortunately, the implicit Euler method and the Rosenbrock solver (another implicit solver) do not have the same interface. 不幸的是,隐式Euler方法和Rosenbrock求解器(另一个隐式求解器)没有相同的接口。 In detail, the implicit Euler expects a function for the Jacobian with this signature 详细而言,隐式Euler期望具有该签名的Jacobian函数

void jacobian( const state_type &x , matrix_type &jacobi , const value_type t );

Hence, you need to change your definition of stiff_system_jacobi to 因此,您需要将stiff_system_jacobi的定义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;
    }
};

If your system is really non autonomous you need to enhance you state type by one additional coordinate which represents the time and has trivial dynamics dt/dt = 1. 如果您的系统确实是非自治的,则需要通过一种附加的坐标来增强状态类型,该坐标表示时间并且动态dt / dt = 1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM