headmyshoulder / odeint-v2

odeint - solving ordinary differential equations in c++ v2
http://headmyshoulder.github.com/odeint-v2/
Other
341 stars 101 forks source link

number of equations not known until runtime #72

Closed dtamayo closed 11 years ago

dtamayo commented 11 years ago

Hi,

I'm not the best programmer and am mostly working off one of the examples, so I apologize if there's an easy fix for this. (At least in the example) the function rhs takes two boost::array<double, n>'s, where n is the number of equations in the system. In the application I want to code, n is not known until runtime, since it has to be read from an input file. I almost don't want to make a suggestion, since it's probably quite naive, but would it not be possible to code things using vectors instead to avoid this problem?

Thanks,

Dan

headmyshoulder commented 11 years ago

You can use a std::vector as state type. It can change its size dynamically during runtime. It works out of the box with odeint, just pass the vector as state type to odeints steppers.

dtamayo commented 11 years ago

Sorry for the uninformed question. Thanks for the very quick reply! Worked perfectly.