在C 类中调用ODE求解器(ODEINT)
Calling ODE solver (odeint) within c++ class
我需要求解使用Odeint库设置的ODE方程。" main.cpp"文件仅为调用计算(以后将延长,此处简单版本可以保持代码清洁)
main.cpp
#include "calc.h"
int main()
{
calc c;
c.startC();
return 0;
}
这是计算标头starc();公开。 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
这是主要计算部分。同样在这里发生错误: 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;
}
此操作以:
的" ode solver初始化"级别以错误结尾'((calc*)this)->calc::solveO' cannot be used as a member pointer,
since it is of type '<unresolved overloaded function type>'
此调用有什么问题:
this->*solveO
,在" integnate_const"内调用solveo的正确方法是什么?
编辑:多亏了 @tobi303和@rbelli的帮助,现在可以使用。在这里,我发布了总结,TL:DR解释:
最简单的解决方案是使solveo和printr自由功能并致电:
integrate_const(make_dense_output<stepper_type>( 1E-12, 1E-6 ), solveO, y, 0.0, 1.0, dt , printR);
如果integrate_const
采用函数指针,则无法传递成员函数指针。成员函数指针与函数指针不同,因为它们隐含地需要this
作为参数。
由于您不使用solveO
中的任何类成员,因此可以简单地使其成为免费功能:
void solveO( const vector_type &y , vector_type &ODE , const double t )
{
dy[0] = y[1];
dy[1] = -y[0] - g*y[1];
}
相关文章:
- boost odeint什么时候真正调用观测者
- 将 boost::odeint 与向量类一起使用,而无需调整向量的大小
- Eigen::VectorXd 和 Boost::Odeint,不起作用
- 减少使用 GSL 用于 ODE 系统的编译资源
- 与 boost odeint 集成期间的析构函数调用
- 在 ODEINT 中通过 if 语句选择步进器
- 为什么 odeint 在较新版本的 odeint 中失败?
- boost odeint 中的受控误差步进器是否支持复杂的数据类型?
- 编译错误 C2440,并在 boost odeint 中使用make_dense_output
- 使用推力的 ODE 求解器的 CUDA 编程
- C++程序在 ODE 上超时
- 如何使用R中的RCPP使用C ode求解器
- Boost ODEINT:具有自定义类和向量空间代数的受控步进器
- runge-kutta第四阶使用C 解决第二阶ode
- 是通过BOOST.UNITS支持尺寸分析的Boost Odeint
- 使用 boost::numeric::odeint 积分非线性函数 f'(x, y, z) = a + b*I
- 微分方程的解在 boost::odeint 和 scipy.integrate 中完全不同
- 模板实例化与Armadillo和Boost :: Numeric :: Odeint
- 在C 类中调用ODE求解器(ODEINT)
- odeint中的推力和刚性ODE解算器