Reputation: 11
I am fairly new to c++ so please bear with me :) I am trying to figure out using the ODEint library from BOOST to solve systems of ODEs, but so far am having a lot of trouble just applying a stepper to a single 1 dimensional ODE. The attached code is what I think I understand to be more or less what is needed (note the function odeSolver() is intended to output the value of the solution at a specified point (x,t)). Apologies if I'm missing something that should be obvious, but when I try to build my project I get a series of error messages that will be detailed after the code.
#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)>)'
I have checked numerous times that all the right things are included and the versions line up, so it seems to me that the issue lies in the stepper "denseStepper" not having the type that integrate_const wants to take, but I can't figure out what in my code doesn't line up with the documentation. Any help at all to get me moving in roughly the right direction would be hugely appreciated, thank you :))
Upvotes: 1
Views: 73
Reputation: 3631
I had a similar compilation error using boost::odeint.
While it wasn't exactly the same error, it seems that it may be related.
Specifically, I was having errors with the instantiation of bool boost::numeric::odeint::dense_output_runge_kutta
.
This error appeared when I updated to boost version 1.85.0, but it was not present when using version 1.83.0.
So, while this is not an answer per se, you might consider regressing to 1.83.0 and see if this works for you.
Upvotes: 0