I want to know what would be the best (computationally efficient, good-looking code) way to handle discontinuity using odeint. Is there any example code?
I am simulating something like a feedback controlled motor whose angle is measured digitally by a rotary encoder. Rotary encoder output, y, can be modeled like y=floor(angle) where angle is a real number.
I know, conceptually, what to do. During the simulation, I have to find the time when angle crosses integer values, then go back to the previous step, integrate up to that time of crossing, adjust the state, y, according to discontinuity, and restart integration from the same point of time.
After some googling, I found the code below. But I do not see the function, make_const_step_time_range, available in the library.
In page 18 of http://meetingcpp.com/tl_files/mcpp/slides/12/odeint.pdf:
auto iter = boost::find_if(
make_const_step_time_range(rk4,ode, x, t1, t2, dt),
[](const std::pair< state_type &, double> &x) {
return ( x.first[0] < 0.0 ); } );
I'm using boost_1_54_0.
Unfortunately, this feature is only present in the github version of odeint right now.
Btw. there we have a discussion about the same topic on our issue tracker and we actually have a real solution to your problem and similar ones. But this solution is not completed right now.