1 /* 2 [auto_generated] 3 boost/numeric/odeint/integrate/detail/integrate_n_steps.hpp 4 5 [begin_description] 6 integrate steps implementation 7 [end_description] 8 9 Copyright 2009-2012 Karsten Ahnert 10 Copyright 2009-2012 Mario Mulansky 11 12 Distributed under the Boost Software License, Version 1.0. 13 (See accompanying file LICENSE_1_0.txt or 14 copy at http://www.boost.org/LICENSE_1_0.txt) 15 */ 16 17 #ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED 18 #define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED 19 20 #include <boost/numeric/odeint/util/unwrap_reference.hpp> 21 #include <boost/numeric/odeint/stepper/stepper_categories.hpp> 22 #include <boost/numeric/odeint/iterator/integrate/detail/integrate_adaptive.hpp> 23 #include <boost/numeric/odeint/iterator/integrate/detail/functors.hpp> 24 #include <boost/numeric/odeint/iterator/n_step_time_iterator.hpp> 25 #include <boost/numeric/odeint/util/unit_helper.hpp> 26 27 #include <boost/numeric/odeint/util/detail/less_with_sign.hpp> 28 29 namespace boost { 30 namespace numeric { 31 namespace odeint { 32 namespace detail { 33 34 // forward declaration 35 template< class Stepper , class System , class State , class Time , class Observer > 36 size_t integrate_adaptive( 37 Stepper stepper , System system , State &start_state , 38 Time &start_time , Time end_time , Time &dt , 39 Observer observer , controlled_stepper_tag 40 ); 41 42 43 /* basic version */ 44 template< class Stepper , class System , class State , class Time , class Observer> 45 Time integrate_n_steps( 46 Stepper stepper , System system , State &start_state , 47 Time start_time , Time dt , size_t num_of_steps , 48 Observer observer , stepper_tag ) 49 { 50 // ToDo: is there a better way to extract the final time? 51 Time t = start_time; // Assignment is only here to avoid warnings. 52 boost::for_each( make_n_step_time_range( stepper , system , start_state , 53 start_time , dt , num_of_steps ) , 54 obs_caller_time< Observer , Time >( t , observer ) ); 55 return t; 56 } 57 58 59 /* controlled version */ 60 template< class Stepper , class System , class State , class Time , class Observer> 61 Time integrate_n_steps( 62 Stepper stepper , System system , State &start_state , 63 Time start_time , Time dt , size_t num_of_steps , 64 Observer observer , controlled_stepper_tag ) 65 { 66 typename odeint::unwrap_reference< Observer >::type &obs = observer; 67 68 Time time = start_time; 69 Time time_step = dt; 70 71 for( size_t step = 0; step < num_of_steps ; ++step ) 72 { 73 obs( start_state , time ); 74 detail::integrate_adaptive( stepper , system , start_state , time , static_cast<Time>(time+time_step) , dt , 75 null_observer() , controlled_stepper_tag() ); 76 // direct computation of the time avoids error propagation happening when using time += dt 77 // we need clumsy type analysis to get boost units working here 78 time = start_time + static_cast< typename unit_value_type<Time>::type >(step+1) * time_step; 79 } 80 obs( start_state , time ); 81 82 return time; 83 } 84 85 86 /* dense output version */ 87 template< class Stepper , class System , class State , class Time , class Observer> 88 Time integrate_n_steps( 89 Stepper stepper , System system , State &start_state , 90 Time start_time , Time dt , size_t num_of_steps , 91 Observer observer , dense_output_stepper_tag ) 92 { 93 // ToDo: is there a better way to extract the final time? 94 Time t = start_time; // Assignment is only here to avoid warnings. 95 boost::for_each( make_n_step_time_range( stepper , system , start_state , 96 start_time , dt , num_of_steps ) , 97 obs_caller_time< Observer , Time >( t , observer ) ); 98 return t; 99 } 100 101 102 } 103 } 104 } 105 } 106 107 #endif /* BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED */ 108