c++ - boost odeint 函数参数太多

标签 c++ boost odeint

我使用 boost/odeint 来求解一阶颂歌。

raman_system.h中系统的定义看起来如下:

class raman_signal_system {
    double alpha_s;
    double dB_to_neper;
    double g_pump_b;
    double P_p;

public:
    raman_signal_system()
        : alpha_s(0.00021181),
          dB_to_neper(0.23025850929940458),
          g_pump_b(0.00044446),
          P_p(0.494) {}

    void operator() (const double P_s, double& dPsdz, const double z)
    {
        dPsdz = -alpha_s * dB_to_neper * P_s + P_s * P_p * g_pump_b;
    }
};

我的main raman.cpp中的方法如下:

/**
 * @author Harun Kara
 * @date 23.01.2017
 * @brief Implementaion of the Raman amplification for fiber communications systems
 */

#include "raman_system.h"

#include <fstream>
#include <iostream>
#include <vector>

#include<boost/numeric/odeint.hpp>





int main(int argc, char *argv[]) {

    namespace odeint = boost::numeric::odeint;

    odeint::runge_kutta4< double > rk4;

    raman_signal_system sys();

    double P_s = 0.00079433;

    double z = 0.0; // initial (forward/signal)

    double l = 80e3; // Fiberlenght in m
    size_t steps = 200;

    const double dz = l/steps; // stepsize

    std::vector<double> P_s_vec;
    std::vector<double> places;
    P_s_vec.push_back(P_s);
    places.push_back(z);

    for( size_t i=0; i<steps; ++i ) {
        rk4.do_step( sys, P_s, z, dz );
        z += dz;

        P_s_vec.push_back(P_s);
        places.push_back(z);
    }

    return 0;
}

如果我尝试构建,则会收到以下错误:

/home/kara/raman/src/raman.cpp:43: required from here
/home/kara/raman/include/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp:229: error: too many arguments to function
         sys( x , m_dxdt.m_v ,t );

我找不到导致此错误的原因。请有人帮助我,找出我的代码有什么问题吗?

使用Boost 1.60.0、Qt、CMake

最佳答案

这一行

raman_signal_system sys();

被编译器识别为本地函数声明,因此会出现错误消息,表明传递给该函数的参数过多。

要使用变量的默认构造函数初始化变量,只需编写

raman_signal_system sys; // <<<< No parenthesis

一旦正确声明了 sys 变量,重载调用 operator() 应该可以正常工作:

sys( x , m_dxdt.m_v ,t );

关于c++ - boost odeint 函数参数太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41963340/

相关文章:

c++ - 如何将 std::vector 用于带句柄的类

c++ - 绑定(bind)两个参数

c++ - boost::future::那么它是如何实现的呢?

c++ - boost bimap 的 find() 问题

python - 使用 python 内置函数进行耦合 ODE

c++ - 为 Windows 10 通用应用构建 OpenCV

c++ - 函数调用完成返回对象后无法解释析构函数调用

c++ - 如何将访问非全局类的全局函数放在一个地方?

c++ - 传递参数以在 C++ 中 boost odeint

c++ - 如何使用 odeint 的标签系统为各种步进器类型做特定的工作