I need to solve ODE equations set with odeint library. "main.cpp" file is only to call calculation (it will be extended later, here simple version to keep code clean)
main.cpp
#include "calc.h"
int main()
{
calc c;
c.startC();
return 0;
}
Here is the calc header, starC(); is set public.
calc.h
#ifndef MAIN_H
#define MAIN_H
#include <iostream>
#include <boost/numeric/odeint.hpp>
#include <math.h>
using namespace std;
using namespace boost::numeric::odeint;
typedef std::vector< double > vector_type;
class calc
{
public:
int main();
void startC();
private:
void solveODE(const vector_type &y , vector_type &ODE , const double t );
void printR();
};
#endif // MAIN_H
Here is the main calculation part. Also here the error occurs:
calc.cpp
include <iostream>
#include <boost/numeric/odeint.hpp>
#include <math.h>
#include "calc.h"
using namespace std;
using namespace boost::numeric::odeint;
const double g = 0.15;
void calc::solveO( const vector_type &y , vector_type &ODE , const double t )
{
dy[0] = y[1];
dy[1] = -y[0] - g*y[1];
}
void calc::printR(const vector_type &y, const double t)
{
cout << t << endl;
cout << y[0] << endl;
}
void calc::startC()
{
const double dt = 0.1;
typedef runge_kutta_dopri5<vector_type> stepper_type;
vector_type y(2);
//Initial conditins
y[0]= 1.0;
y[1]= 0.0;
//Initializing of ODE solver
integrate_const(make_dense_output<stepper_type>( 1E-12, 1E-6 ),
this->*solveO, y, 0.0, 1.0, dt , printResults); //ERROR HERE
}
int calc::main()
{
return 0;
}
This operation ends with error on the level of "Initializing of ODE solver" with:
'((calc*)this)->calc::solveO' cannot be used as a member pointer,
since it is of type '<unresolved overloaded function type>'
What's wrong with this call:
this->*solveO
And what's the correct way to call solveO inside "integrate_const"?
Edit: Thanks to the help of @tobi303 and @rbelli it now works. Here I post sum-up, TL:DR explanation:
The easiest solution is to make solveO and printR free function and call:
integrate_const(make_dense_output<stepper_type>( 1E-12, 1E-6 ), solveO, y, 0.0, 1.0, dt , printR);