3

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.

user22097
  • 229
  • 3
  • 13

1 Answers1

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.

headmyshoulder
  • 6,240
  • 2
  • 20
  • 27
  • Thanks. I checked out the integrate_conditional branch, and compiled integrate_conditional.cpp. But I got a compile error: _'boost/type_traits/integral_constant.hpp': No such file or directory_ while compiling f:\workspace\odeint-v2\boost\numeric\odeint\stepper\stepper_categories.hpp. The folder, type_traits, does not exist under 'boost' folder. I'm compiling it with MS VS 2010. Could you suggest me how I can solve it? – user22097 Aug 30 '13 at 09:57
  • integral_constant.hpp comes from the main boost directory. You need to add boost to your include path too. – headmyshoulder Aug 30 '13 at 11:22
  • This is great! Now, my next question is if I can use it with runge_kutta_dopri5. I simply replaced _runge_kutta4< state_type > rk4;_ by _auto stepper = make_dense_output( 1.0e-6 , 1.0e-5 , runge_kutta_dopri5< state_type >() );_. And replaced the first argument of _integrate_conditional()_, accordingly. But the observed output stays at time = 0, going in an infinit loop. What am I missing? – user22097 Aug 31 '13 at 14:00
  • I fear it is not working with dopri5 since it is a controlled stepper and the implementation is not finished right yet. Sorry. – headmyshoulder Aug 31 '13 at 20:02