在类中调用Boost :: odeint stepper.do_step()函数

时间:2016-03-01 14:10:41

标签: c++ boost odeint

我在这个问题上尝试做的是符合我在尝试做的事情:Dynamic Eigen vectors in Boost::odeint。但是现在我试图将它全部封装在一个类中,如下所示:

#include <iostream>
#include <Eigen/Core>
#include <cstdlib>
#include <boost/numeric/odeint.hpp>
#include <boost/numeric/odeint/external/eigen/eigen_algebra.hpp>

namespace odeint = boost::numeric::odeint;
typedef odeint::runge_kutta_dopri5<Eigen::VectorXd, double, Eigen::VectorXd, double, odeint::vector_space_algebra> stepper;

class foo
{
private:
    Eigen::VectorXd m_x;
    Eigen::MatrixXd m_A;
    double m_t, m_dt;
public:
    foo(int nr_of_states){ //ctor
        m_t = 0;
        m_dt = 1.0;
        m_x = Eigen::VectorXd(nr_of_states);
        m_A = Eigen::MatrixXd(nr_of_states, nr_of_states);

        srand(365);

        for (int i = 0; i < m_A.size(); i++){
            *(m_A.data()+i) = ((double)rand()/(double)RAND_MAX);}

        for (int i = 0; i < m_x.size(); i++){
            *(m_x.data()+i) = i;}
    }

    void ODE_function(const Eigen::VectorXd &x, Eigen::VectorXd &dxdt, double){
        dxdt = m_A * x;}

    void next_step(){
        odeint::integrate_adaptive(stepper(), ODE_function, m_x, m_t, (m_t+(1*m_dt)), m_dt);}

    Eigen::VectorXd get_states(){
        return m_x;}
};

int main()
{
    int nr_of_states;

    std::cout << "How many (random) states would you like to simulate?: ";
    std::cin >> nr_of_states;
    std::cout << std::endl;

    foo f1(nr_of_states);

    for (int i = 0; i < 100; i++){
        f1.next_step();}

    std::cout <<std::endl << "final state vector: " << std::endl << f1.get_states() << std::endl;

    return 0;
}

当我收到以下错误消息时,我正在使用MinGW 64位编译器编译上面的代码:

  

\升压\ boost_1_59_0 \升压\数字\ odeint \步进\基\ explicit_error_stepper_fsal_base.hpp | 297 |错误:   必须使用&#39;。&#39;或者&#39; - &gt; &#39;在&#39; sys中调用指向成员的函数   (...)&#39;,例如&#39;(... - &gt; * sys)(...)&#39; |

我原本想在这里做的可能吗?如果是,那么上面的代码应该如何调整?

0 个答案:

没有答案