Harun K.
Harun K.

Reputation: 43

boost odeint too many arguments to function

I use boost/odeint to solve an ode of first order.

The definition of the system in raman_system.h looks as follows:

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

My main method in raman.cpp as follows:

/**
 * @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;
}

If I try to build, I get the following error:

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

I couldn't find what causes this error. Can please someone help me, find out what is wrong with my code?

Using Boost 1.60.0, Qt, CMake

Upvotes: 2

Views: 457

Answers (1)

πάντα ῥεῖ
πάντα ῥεῖ

Reputation: 1

This line

raman_signal_system sys();

is recognized by the compiler as a local function declaration, hence the error message that too many arguments are passed to that function.

To initialize a variable using it's default constructor, simply write

raman_signal_system sys; // <<<< No parenthesis

Once the sys variable is declared correctly, the overloaded call operator() should work fine:

sys( x , m_dxdt.m_v ,t );

Upvotes: 2

Related Questions