在 BOOST ODEint 中排列Integrate_const() 的参数类型时遇到问题

问题描述 投票:0回答:1

我对 C++ 相当陌生,所以请耐心等待:) 我正在尝试使用 BOOST 中的 ODEint 库来求解 ODE 系统,但到目前为止,仅将步进器应用于单个一维 ODE 就遇到了很多麻烦。所附代码是我认为我所理解的或多或少需要的代码(注意函数 odeSolver() 旨在输出指定点 (x,t) 处的解的值)。 如果我遗漏了一些应该显而易见的东西,我深表歉意,但是当我尝试构建我的项目时,我收到一系列错误消息,这些消息将在代码后详细说明。


#define ODEINT boost::numeric::odeint

// Global variables to store time and state values
std::vector<double> times;
std::vector<double> states;

// Define initial condition and time range
double x0 = 1.0; // initial condition
double t_start = 0.0;
double t_end = 5.0;
double dt = 0.1; // time step
int numSteps = (t_start - t_end) / dt;

void odeSystem(const double x, double& dxdt, const double t) {
    // Define simple ODE
    dxdt = -x;
}

float odeSolver(double X, double T) {

    auto denseStepper = ODEINT::make_dense_output<ODEINT::runge_kutta_cash_karp54<double>>(1.0e-6, 1.0e-6);

    ODEINT::integrate_const(
        denseStepper,
        odeSystem,
        x0,
        t_start,
        t_end,
        dt,
        std::function<void(const double&, const double)>([](const double& x, const double t) {
            times.push_back(t);
            states.push_back(x);
            })
    );

    int currentPt = (X - t_start) / dt;

    return states[currentPt];
}




1>D:\BOOST\boost_1_84_0\boost\numeric\odeint\stepper\generation\make_dense_output.hpp(60,55): 
error C2039: 'type': is not a member of 'boost::numeric::odeint::get_dense_output<Stepper>'    
with 
[           
Stepper=boost::numeric::odeint::runge_kutta_cash_karp54<double,double,double,double,boost::numeric::odeint::algebra_dispatcher_sfinae<double,void>::algebra_type,boost::numeric::odeint::operations_dispatcher_sfinae<double,void>::operations_type,boost::numeric::odeint::initially_resizer>    
]

2>D:\BOOST\boost_1_84_0\boost\numeric\odeint\stepper\generation\make_dense_output.hpp(60,26):
see declaration of 'boost::numeric::odeint::get_dense_output<Stepper>'
with
[
Stepper=boost::numeric::odeint::runge_kutta_cash_karp54<double,double,double,double,boost::numeric::odeint::algebra_dispatcher_sfinae<double,void>::algebra_type,boost::numeric::odeint::operations_dispatcher_sfinae<double,void>::operations_type,boost::numeric::odeint::initially_resizer>
]

3>D:\BOOST\boost_1_84_0\boost\numeric\odeint\stepper\generation\make_dense_output.hpp(60,55):
the template instantiation context (the oldest one first) is
D:\Visual Studio\source\repos\TestFiles\main.cpp(48,106):
see reference to class template instantiation 'boost::numeric::odeint::result_of::make_dense_output<boost::numeric::odeint::runge_kutta_cash_karp54<double,double,State,Value,boost::numeric::odeint::algebra_dispatcher_sfinae<StateType,void>::algebra_type,boost::numeric::odeint::operations_dispatcher_sfinae<StateType,void>::operations_type,boost::numeric::odeint::initially_resizer>>' being compiled
with
[
State=double,
Value=double,
StateType=double
]

4>D:\Visual Studio\source\repos\TestFiles\main.cpp(48,23): 
error C2514: 'boost::type': class template cannot be constructed

5>D:\BOOST\boost_1_84_0\boost\type.hpp(14,3):
see declaration of 'boost::type'

6>D:\Visual Studio\source\repos\TestFiles\main.cpp(50,13): error C2664: 
'size_t boost::numeric::odeint::integrate_const<boost::type,void(__cdecl *)(double,double &,double),double,double,std::function<void (const double &,double)>>(Stepper,System,State &,Time,Time,Time,Observer)': cannot convert argument 1 from 'boost::type' to 'Stepper'
with
[
Stepper=boost::type,
System=void (__cdecl *)(double,double &,double),
State=double,
Time=double,
Observer=std::function<void (const double &,double)>
 ]
and
[
Stepper=boost::type
]

7>D:\Visual Studio\source\repos\TestFiles\main.cpp(51,9):
The target type has no constructors

8>D:\BOOST\boost_1_84_0\boost\numeric\odeint\integrate\integrate_const.hpp(104,8):
see declaration of 'boost::numeric::odeint::integrate_const'

9>D:\Visual Studio\source\repos\TestFiles\main.cpp(50,13):
while trying to match the argument list '(boost::type, overloaded-function, double, double, double, double, std::function<void (const double &,double)>)'



我已经检查了无数次,确保包含所有正确的内容并且版本一致,所以在我看来,问题在于步进器“denseStepper”没有Integrated_const想要采用的类型,但我无法弄清楚我的代码中的内容与文档不符。任何帮助我朝着大致正确的方向前进的帮助都将非常感激,谢谢:))

c++ odeint
1个回答
0
投票

我在使用 boost::odeint 时遇到了类似的编译错误。 虽然这不是完全相同的错误,但似乎可能相关。 具体来说,我在

bool boost::numeric::odeint::dense_output_runge_kutta
的实例化中遇到了错误。

当我更新到boost版本1.85.0时出现此错误,但使用1.83.0版本时不存在。

因此,虽然这本身不是答案,但您可以考虑退回到 1.83.0,看看这是否适合您。

© www.soinside.com 2019 - 2024. All rights reserved.