File indexing completed on 2024-11-15 09:19:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED
0019 #define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED
0020
0021 #include <boost/numeric/odeint/util/unwrap_reference.hpp>
0022 #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
0023 #include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
0024 #include <boost/numeric/odeint/util/unit_helper.hpp>
0025
0026 #include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
0027
0028 namespace boost {
0029 namespace numeric {
0030 namespace odeint {
0031 namespace detail {
0032
0033
0034 template< class Stepper , class System , class State , class Time , class Observer >
0035 size_t integrate_adaptive_checked(
0036 Stepper stepper , System system , State &start_state ,
0037 Time &start_time , Time end_time , Time &dt ,
0038 Observer observer, controlled_stepper_tag
0039 );
0040
0041
0042
0043 template< class Stepper , class System , class State , class Time , class Observer>
0044 Time integrate_n_steps(
0045 Stepper stepper , System system , State &start_state ,
0046 Time start_time , Time dt , size_t num_of_steps ,
0047 Observer observer , stepper_tag )
0048 {
0049 typename odeint::unwrap_reference< Observer >::type &obs = observer;
0050 typename odeint::unwrap_reference< Stepper >::type &st = stepper;
0051
0052 Time time = start_time;
0053
0054 for( size_t step = 0; step < num_of_steps ; ++step )
0055 {
0056 obs( start_state , time );
0057 st.do_step( system , start_state , time , dt );
0058
0059
0060 time = start_time + static_cast< typename unit_value_type<Time>::type >( step+1 ) * dt;
0061 }
0062 obs( start_state , time );
0063
0064 return time;
0065 }
0066
0067
0068
0069 template< class Stepper , class System , class State , class Time , class Observer >
0070 Time integrate_n_steps(
0071 Stepper stepper , System system , State &start_state ,
0072 Time start_time , Time dt , size_t num_of_steps ,
0073 Observer observer , controlled_stepper_tag )
0074 {
0075 typename odeint::unwrap_reference< Observer >::type &obs = observer;
0076
0077 Time time = start_time;
0078 Time time_step = dt;
0079
0080 for( size_t step = 0; step < num_of_steps ; ++step )
0081 {
0082 obs( start_state , time );
0083
0084 detail::integrate_adaptive(stepper, system, start_state, time, static_cast<Time>(time + time_step), dt,
0085 null_observer(), controlled_stepper_tag());
0086
0087
0088 time = start_time + static_cast< typename unit_value_type<Time>::type >(step+1) * time_step;
0089 }
0090 obs( start_state , time );
0091
0092 return time;
0093 }
0094
0095
0096
0097 template< class Stepper , class System , class State , class Time , class Observer >
0098 Time integrate_n_steps(
0099 Stepper stepper , System system , State &start_state ,
0100 Time start_time , Time dt , size_t num_of_steps ,
0101 Observer observer , dense_output_stepper_tag )
0102 {
0103 typename odeint::unwrap_reference< Observer >::type &obs = observer;
0104 typename odeint::unwrap_reference< Stepper >::type &st = stepper;
0105
0106 Time time = start_time;
0107 const Time end_time = start_time + static_cast< typename unit_value_type<Time>::type >(num_of_steps) * dt;
0108
0109 st.initialize( start_state , time , dt );
0110
0111 size_t step = 0;
0112
0113 while( step < num_of_steps )
0114 {
0115 while( less_with_sign( time , st.current_time() , st.current_time_step() ) )
0116 {
0117 st.calc_state( time , start_state );
0118 obs( start_state , time );
0119 ++step;
0120
0121
0122 time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * dt;
0123 }
0124
0125
0126 if( less_with_sign( static_cast<Time>(st.current_time()+st.current_time_step()) ,
0127 end_time ,
0128 st.current_time_step() ) )
0129 {
0130 st.do_step( system );
0131 }
0132 else if( less_with_sign( st.current_time() , end_time , st.current_time_step() ) )
0133 {
0134 st.initialize( st.current_state() , st.current_time() , static_cast<Time>(end_time - st.current_time()) );
0135 st.do_step( system );
0136 }
0137 }
0138
0139
0140 while( st.current_time() < end_time )
0141 {
0142 if( less_with_sign( end_time ,
0143 static_cast<Time>(st.current_time()+st.current_time_step()) ,
0144 st.current_time_step() ) )
0145 st.initialize( st.current_state() , st.current_time() , static_cast<Time>(end_time - st.current_time()) );
0146 st.do_step( system );
0147 }
0148
0149
0150 obs( st.current_state() , end_time );
0151
0152 return time;
0153 }
0154
0155
0156 }
0157 }
0158 }
0159 }
0160
0161 #endif