1 /* 2 [auto_generated] 3 boost/numeric/odeint/algebra/fusion_algebra.hpp 4 5 [begin_description] 6 Algebra for boost::fusion sequences. 7 [end_description] 8 9 Copyright 2011-2013 Karsten Ahnert 10 Copyright 2011-2013 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 18 #ifndef BOOST_NUMERIC_ODEINT_ALGEBRA_FUSION_ALGEBRA_HPP_INCLUDED 19 #define BOOST_NUMERIC_ODEINT_ALGEBRA_FUSION_ALGEBRA_HPP_INCLUDED 20 21 #include <algorithm> 22 23 #include <boost/numeric/odeint/config.hpp> 24 25 #include <boost/fusion/container/vector.hpp> 26 #include <boost/fusion/algorithm/iteration/for_each.hpp> 27 #include <boost/fusion/view/zip_view.hpp> 28 #include <boost/fusion/functional/generation/make_fused.hpp> 29 #include <boost/fusion/algorithm/iteration/accumulate.hpp> 30 31 namespace boost { 32 namespace numeric { 33 namespace odeint { 34 35 namespace detail { 36 37 template< class Value > 38 struct fusion_maximum 39 { 40 template< class Fac1 , class Fac2 > operator ()boost::numeric::odeint::detail::fusion_maximum41 Value operator()( Fac1 t1 , const Fac2 t2 ) const 42 { 43 using std::abs; 44 Value a1 = abs( get_unit_value( t1 ) ) , a2 = abs( get_unit_value( t2 ) ); 45 return ( a1 < a2 ) ? a2 : a1 ; 46 } 47 48 typedef Value result_type; 49 }; 50 } 51 52 /* specialize this if the fundamental numeric type in your fusion sequence is 53 * anything else but double (most likely not) 54 */ 55 template< typename Sequence > 56 struct fusion_traits { 57 typedef double value_type; 58 }; 59 60 struct fusion_algebra 61 { 62 template< class S1 , class Op > for_each1boost::numeric::odeint::fusion_algebra63 static void for_each1( S1 &s1 , Op op ) 64 { 65 boost::fusion::for_each( s1 , op ); 66 }; 67 68 69 template< class S1 , class S2 , class Op > for_each2boost::numeric::odeint::fusion_algebra70 static void for_each2( S1 &s1 , S2 &s2 , Op op ) 71 { 72 typedef boost::fusion::vector< S1& , S2& > Sequences; 73 Sequences sequences( s1 , s2 ); 74 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 75 } 76 77 78 template< class S1 , class S2 , class S3 , class Op > for_each3boost::numeric::odeint::fusion_algebra79 static void for_each3( S1 &s1 , S2 &s2 , S3 &s3 , Op op ) 80 { 81 typedef boost::fusion::vector< S1& , S2& , S3& > Sequences; 82 Sequences sequences( s1 , s2 , s3 ); 83 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 84 } 85 86 template< class S1 , class S2 , class S3 , class S4 , class Op > for_each4boost::numeric::odeint::fusion_algebra87 static void for_each4( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , Op op ) 88 { 89 typedef boost::fusion::vector< S1& , S2& , S3& , S4& > Sequences; 90 Sequences sequences( s1 , s2 , s3 , s4 ); 91 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 92 } 93 94 95 template< class S1 , class S2 , class S3 , class S4 , class S5 , class Op > for_each5boost::numeric::odeint::fusion_algebra96 static void for_each5( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , Op op ) 97 { 98 typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& > Sequences; 99 Sequences sequences( s1 , s2 , s3 , s4 , s5 ); 100 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 101 } 102 103 104 template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class Op > for_each6boost::numeric::odeint::fusion_algebra105 static void for_each6( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , Op op ) 106 { 107 typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& > Sequences; 108 Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 ); 109 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 110 } 111 112 113 template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class Op > for_each7boost::numeric::odeint::fusion_algebra114 static void for_each7( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , Op op ) 115 { 116 typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& > Sequences; 117 Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 ); 118 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 119 } 120 121 122 template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class Op > for_each8boost::numeric::odeint::fusion_algebra123 static void for_each8( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , Op op ) 124 { 125 BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 8 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" ); 126 typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& > Sequences; 127 Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 ); 128 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 129 } 130 131 template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class Op > for_each9boost::numeric::odeint::fusion_algebra132 static void for_each9( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , Op op ) 133 { 134 BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 9 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" ); 135 typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& > Sequences; 136 Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 ); 137 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 138 } 139 140 template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class Op > for_each10boost::numeric::odeint::fusion_algebra141 static void for_each10( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , Op op ) 142 { 143 BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 10 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" ); 144 typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& , S10& > Sequences; 145 Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 ); 146 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 147 } 148 149 template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class Op > for_each11boost::numeric::odeint::fusion_algebra150 static void for_each11( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , Op op ) 151 { 152 BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 11 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" ); 153 BOOST_STATIC_ASSERT_MSG( BOOST_RESULT_OF_NUM_ARGS >= 11 , "Macro Parameter BOOST_RESULT_OF_NUM_ARGS to small!" ); 154 typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& , S10& , S11& > Sequences; 155 Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 ); 156 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 157 } 158 159 template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class Op > for_each12boost::numeric::odeint::fusion_algebra160 static void for_each12( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , Op op ) 161 { 162 BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 12 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" ); 163 BOOST_STATIC_ASSERT_MSG( BOOST_RESULT_OF_NUM_ARGS >= 12 , "Macro Parameter BOOST_RESULT_OF_NUM_ARGS to small!" ); 164 typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& , S10& , S11& , S12& > Sequences; 165 Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 ); 166 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 167 } 168 169 template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class Op > for_each13boost::numeric::odeint::fusion_algebra170 static void for_each13( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , Op op ) 171 { 172 BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 13 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" ); 173 BOOST_STATIC_ASSERT_MSG( BOOST_RESULT_OF_NUM_ARGS >= 13 , "Macro Parameter BOOST_RESULT_OF_NUM_ARGS to small!" ); 174 typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& , S10& , S11& , S12& , S13& > Sequences; 175 Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 , s13 ); 176 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 177 } 178 179 template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class S14 , class Op > for_each14boost::numeric::odeint::fusion_algebra180 static void for_each14( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , S14 &s14 , Op op ) 181 { 182 BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 14 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" ); 183 BOOST_STATIC_ASSERT_MSG( BOOST_RESULT_OF_NUM_ARGS >= 14 , "Macro Parameter BOOST_RESULT_OF_NUM_ARGS to small!" ); 184 typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& , S10& , S11& , S12& , S13& , S14& > Sequences; 185 Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 , s13 , s14 ); 186 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 187 } 188 189 template< class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class S14 , class S15 , class Op > for_each15boost::numeric::odeint::fusion_algebra190 static void for_each15( S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , S14 &s14 , S15 &s15 , Op op ) 191 { 192 BOOST_STATIC_ASSERT_MSG( BOOST_FUSION_INVOKE_MAX_ARITY >= 15 , "Macro Parameter BOOST_FUSION_INVOKE_MAX_ARITY to small!" ); 193 BOOST_STATIC_ASSERT_MSG( BOOST_RESULT_OF_NUM_ARGS >= 15 , "Macro Parameter BOOST_RESULT_OF_NUM_ARGS to small!" ); 194 typedef boost::fusion::vector< S1& , S2& , S3& , S4& , S5& , S6& , S7& , S8& , S9& , S10& , S11& , S12& , S13& , S14& , S15& > Sequences; 195 Sequences sequences( s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 , s13 , s14 , s15 ); 196 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( op ) ); 197 } 198 199 template< class S > norm_infboost::numeric::odeint::fusion_algebra200 static typename fusion_traits< S >::value_type norm_inf( const S &s ) 201 { 202 typedef typename fusion_traits< S >::value_type value_type; 203 return boost::fusion::accumulate( s , static_cast<value_type>(0) , 204 detail::fusion_maximum<value_type>() ); 205 } 206 207 }; 208 209 210 211 } // odeint 212 } // numeric 213 } // boost 214 215 216 #endif // BOOST_NUMERIC_ODEINT_ALGEBRA_FUSION_ALGEBRA_HPP_INCLUDED 217