File indexing completed on 2025-01-18 09:42:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED
0019 #define BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED
0020
0021
0022
0023
0024 #include <boost/fusion/container/vector.hpp>
0025 #include <boost/fusion/container/generation/make_vector.hpp>
0026
0027 #include <boost/numeric/odeint/stepper/explicit_generic_rk.hpp>
0028 #include <boost/numeric/odeint/algebra/range_algebra.hpp>
0029 #include <boost/numeric/odeint/algebra/default_operations.hpp>
0030 #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
0031 #include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
0032
0033 #include <boost/array.hpp>
0034
0035 #include <boost/numeric/odeint/util/resizer.hpp>
0036
0037
0038
0039 namespace boost {
0040 namespace numeric {
0041 namespace odeint {
0042
0043 #ifndef DOXYGEN_SKIP
0044 template< class Value = double >
0045 struct rk4_coefficients_a1 : boost::array< Value , 1 >
0046 {
0047 rk4_coefficients_a1( void )
0048 {
0049 (*this)[0] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
0050 }
0051 };
0052
0053 template< class Value = double >
0054 struct rk4_coefficients_a2 : boost::array< Value , 2 >
0055 {
0056 rk4_coefficients_a2( void )
0057 {
0058 (*this)[0] = static_cast<Value>(0);
0059 (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
0060 }
0061 };
0062
0063
0064 template< class Value = double >
0065 struct rk4_coefficients_a3 : boost::array< Value , 3 >
0066 {
0067 rk4_coefficients_a3( void )
0068 {
0069 (*this)[0] = static_cast<Value>(0);
0070 (*this)[1] = static_cast<Value>(0);
0071 (*this)[2] = static_cast<Value>(1);
0072 }
0073 };
0074
0075 template< class Value = double >
0076 struct rk4_coefficients_b : boost::array< Value , 4 >
0077 {
0078 rk4_coefficients_b( void )
0079 {
0080 (*this)[0] = static_cast<Value>(1)/static_cast<Value>(6);
0081 (*this)[1] = static_cast<Value>(1)/static_cast<Value>(3);
0082 (*this)[2] = static_cast<Value>(1)/static_cast<Value>(3);
0083 (*this)[3] = static_cast<Value>(1)/static_cast<Value>(6);
0084 }
0085 };
0086
0087 template< class Value = double >
0088 struct rk4_coefficients_c : boost::array< Value , 4 >
0089 {
0090 rk4_coefficients_c( void )
0091 {
0092 (*this)[0] = static_cast<Value>(0);
0093 (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
0094 (*this)[2] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
0095 (*this)[3] = static_cast<Value>(1);
0096 }
0097 };
0098 #endif
0099
0100
0101
0102 template<
0103 class State ,
0104 class Value = double ,
0105 class Deriv = State ,
0106 class Time = Value ,
0107 class Algebra = typename algebra_dispatcher< State >::algebra_type ,
0108 class Operations = typename operations_dispatcher< State >::operations_type ,
0109 class Resizer = initially_resizer
0110 >
0111 #ifndef DOXYGEN_SKIP
0112 class runge_kutta4 : public explicit_generic_rk< 4 , 4 , State , Value , Deriv , Time ,
0113 Algebra , Operations , Resizer >
0114 #else
0115 class runge_kutta4 : public explicit_generic_rk
0116 #endif
0117 {
0118
0119 public:
0120
0121 #ifndef DOXYGEN_SKIP
0122 typedef explicit_generic_rk< 4 , 4 , State , Value , Deriv , Time ,
0123 Algebra , Operations , Resizer > stepper_base_type;
0124 #endif
0125 typedef typename stepper_base_type::state_type state_type;
0126 typedef typename stepper_base_type::value_type value_type;
0127 typedef typename stepper_base_type::deriv_type deriv_type;
0128 typedef typename stepper_base_type::time_type time_type;
0129 typedef typename stepper_base_type::algebra_type algebra_type;
0130 typedef typename stepper_base_type::operations_type operations_type;
0131 typedef typename stepper_base_type::resizer_type resizer_type;
0132
0133 #ifndef DOXYGEN_SKIP
0134 typedef typename stepper_base_type::wrapped_state_type wrapped_state_type;
0135 typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type;
0136 typedef typename stepper_base_type::stepper_type stepper_type;
0137 #endif
0138
0139 runge_kutta4( const algebra_type &algebra = algebra_type() ) : stepper_base_type(
0140 boost::fusion::make_vector( rk4_coefficients_a1<Value>() , rk4_coefficients_a2<Value>() , rk4_coefficients_a3<Value>() ) ,
0141 rk4_coefficients_b<Value>() , rk4_coefficients_c<Value>() , algebra )
0142 { }
0143
0144 };
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176 }
0177 }
0178 }
0179
0180
0181 #endif