details_boost_range.qbk 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. [/============================================================================
  2. Boost.odeint
  3. Copyright 2012 Karsten Ahnert
  4. Copyright 2012 Mario Mulansky
  5. Use, modification and distribution is subject to the Boost Software License,
  6. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. http://www.boost.org/LICENSE_1_0.txt)
  8. =============================================================================/]
  9. [section Using boost::range]
  10. Most steppers in odeint also accept the state give as a range. A range is
  11. sequence of values modeled by a range concept. See __boost_range for an
  12. overview over existing concepts and examples of ranges. This means that the
  13. `state_type` of the stepper need not necessarily be used to call the `do_step` method.
  14. One use-case for __boost_range in odeint has been shown in __tut_chaotic_system where the state consists of two parts: one for the original system and one for the perturbations. The ranges are used to initialize (solve) only the system part where the perturbation part is not touched, that is a range consisting only of the system part is used. After that the complete state including the perturbations is solved.
  15. Another use case is a system consisting of coupled units where you want to initialize each unit separately with the ODE of the uncoupled unit. An example is a chain of coupled van-der-Pol-oscillators which are initialized uniformly from the uncoupled van-der-Pol-oscillator. Then you can use __boost_range to solve only one individual oscillator in the chain.
  16. In short, you can __boost_range to use one state within two system functions which expect states with different sizes.
  17. An example was given in the __tut_chaotic_system tutorial. Using Boost.Range usually means that your system function needs to adapt to the iterators of Boost.Range. That is, your function is called with a range and you need to get the iterators from that range. This can easily be done. You have to implement your system as a class or a struct and you have to templatize the `operator()`. Then you can use the `range_iterator`-meta function and `boost::begin` and `boost::end` to obtain the iterators of your range:
  18. ``
  19. class sys
  20. {
  21. template< class State , class Deriv >
  22. void operator()( const State &x_ , Deriv &dxdt_ , double t ) const
  23. {
  24. typename boost::range_iterator< const State >::type x = boost::begin( x_ );
  25. typename boost::range_iterator< Deriv >::type dxdt = boost::begin( dxdt_ );
  26. // fill dxdt
  27. }
  28. };
  29. ``
  30. If your range is a random access-range you can also apply the bracket operator to the iterator to access the elements in the range:
  31. ``
  32. class sys
  33. {
  34. template< class State , class Deriv >
  35. void operator()( const State &x_ , Deriv &dxdt_ , double t ) const
  36. {
  37. typename boost::range_iterator< const State >::type x = boost::begin( x_ );
  38. typename boost::range_iterator< Deriv >::type dxdt = boost::begin( dxdt_ );
  39. dxdt[0] = f1( x[0] , x[1] );
  40. dxdt[1] = f2( x[0] , x[1] );
  41. }
  42. };
  43. ``
  44. The following two tables show which steppers and which algebras are compatible with __boost_range.
  45. [include range_table.qbk]
  46. [endsect]