File indexing completed on 2025-01-18 09:42:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #ifndef BOOST_NUMERIC_ODEINT_ALGEBRA_ARRAY_ALGEBRA_HPP_INCLUDED
0023 #define BOOST_NUMERIC_ODEINT_ALGEBRA_ARRAY_ALGEBRA_HPP_INCLUDED
0024
0025 #include <algorithm>
0026 #include <boost/array.hpp>
0027
0028 #include <boost/numeric/odeint/algebra/norm_result_type.hpp>
0029
0030 namespace boost {
0031 namespace numeric {
0032 namespace odeint {
0033
0034 struct array_algebra
0035 {
0036
0037 template < template < typename, size_t > class Array, typename T,
0038 size_t dim, class Op >
0039 static void for_each1( Array< T, dim > &s1, Op op )
0040 {
0041 for( size_t i=0 ; i<dim ; ++i )
0042 op( s1[i] );
0043 }
0044
0045 template < template < typename, size_t > class Array, typename T,
0046 size_t dim, class Op >
0047 static void for_each2( Array< T, dim > &s1, const Array< T, dim > &s2,
0048 Op op )
0049 {
0050 for( size_t i=0 ; i<dim ; ++i )
0051 op( s1[i] , s2[i] );
0052 }
0053
0054 template < template < typename, size_t > class Array, typename T,
0055 size_t dim, class Op >
0056 static void for_each3( Array< T , dim > &s1 ,
0057 const Array< T , dim > &s2 ,
0058 const Array< T , dim > &s3 , Op op )
0059 {
0060 for( size_t i=0 ; i<dim ; ++i )
0061 op( s1[i] , s2[i] , s3[i] );
0062 }
0063
0064
0065 template < template < typename, size_t > class Array, typename T,
0066 size_t dim, class Op >
0067 static void for_each3( Array< T , dim > &s1 ,
0068 Array< T , dim > &s2 ,
0069 const Array< T , dim > &s3 , Op op )
0070 {
0071 for( size_t i=0 ; i<dim ; ++i )
0072 op( s1[i] , s2[i] , s3[i] );
0073 }
0074
0075 template < template < typename, size_t > class Array, typename T,
0076 size_t dim, class Op >
0077 static void for_each4( Array< T , dim > &s1 ,
0078 const Array< T , dim > &s2 ,
0079 const Array< T , dim > &s3 ,
0080 const Array< T , dim > &s4 , Op op )
0081 {
0082 for( size_t i=0 ; i<dim ; ++i )
0083 op( s1[i] , s2[i] , s3[i] , s4[i] );
0084 }
0085
0086 template < template < typename, size_t > class Array, typename T,
0087 size_t dim, class Op >
0088 static void for_each5( Array< T , dim > &s1 ,
0089 const Array< T , dim > &s2 ,
0090 const Array< T , dim > &s3 ,
0091 const Array< T , dim > &s4 ,
0092 const Array< T , dim > &s5 , Op op )
0093 {
0094 for( size_t i=0 ; i<dim ; ++i )
0095 op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] );
0096 }
0097
0098 template < template < typename, size_t > class Array, typename T,
0099 size_t dim, class Op >
0100 static void for_each6( Array< T , dim > &s1 ,
0101 const Array< T , dim > &s2 ,
0102 const Array< T , dim > &s3 ,
0103 const Array< T , dim > &s4 ,
0104 const Array< T , dim > &s5 ,
0105 const Array< T , dim > &s6 , Op op )
0106 {
0107 for( size_t i=0 ; i<dim ; ++i )
0108 op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] );
0109 }
0110
0111 template < template < typename, size_t > class Array, typename T,
0112 size_t dim, class Op >
0113 static void for_each7( Array< T , dim > &s1 ,
0114 const Array< T , dim > &s2 ,
0115 const Array< T , dim > &s3 ,
0116 const Array< T , dim > &s4 ,
0117 const Array< T , dim > &s5 ,
0118 const Array< T , dim > &s6 ,
0119 const Array< T , dim > &s7 , Op op )
0120 {
0121 for( size_t i=0 ; i<dim ; ++i )
0122 op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] );
0123 }
0124
0125 template < template < typename, size_t > class Array, typename T,
0126 size_t dim, class Op >
0127 static void for_each8( Array< T , dim > &s1 ,
0128 const Array< T , dim > &s2 ,
0129 const Array< T , dim > &s3 ,
0130 const Array< T , dim > &s4 ,
0131 const Array< T , dim > &s5 ,
0132 const Array< T , dim > &s6 ,
0133 const Array< T , dim > &s7 ,
0134 const Array< T , dim > &s8 , Op op )
0135 {
0136 for( size_t i=0 ; i<dim ; ++i )
0137 op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] );
0138 }
0139
0140 template < template < typename, size_t > class Array, typename T,
0141 size_t dim, class Op >
0142 static void for_each9( Array< T , dim > &s1 ,
0143 const Array< T , dim > &s2 ,
0144 const Array< T , dim > &s3 ,
0145 const Array< T , dim > &s4 ,
0146 const Array< T , dim > &s5 ,
0147 const Array< T , dim > &s6 ,
0148 const Array< T , dim > &s7 ,
0149 const Array< T , dim > &s8 ,
0150 const Array< T , dim > &s9 , Op op )
0151 {
0152 for( size_t i=0 ; i<dim ; ++i )
0153 op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] );
0154 }
0155
0156 template < template < typename, size_t > class Array, typename T,
0157 size_t dim, class Op >
0158 static void for_each10( Array< T , dim > &s1 ,
0159 const Array< T , dim > &s2 ,
0160 const Array< T , dim > &s3 ,
0161 const Array< T , dim > &s4 ,
0162 const Array< T , dim > &s5 ,
0163 const Array< T , dim > &s6 ,
0164 const Array< T , dim > &s7 ,
0165 const Array< T , dim > &s8 ,
0166 const Array< T , dim > &s9 ,
0167 const Array< T , dim > &s10 , Op op )
0168 {
0169 for( size_t i=0 ; i<dim ; ++i )
0170 op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] );
0171 }
0172
0173 template < template < typename, size_t > class Array, typename T,
0174 size_t dim, class Op >
0175 static void for_each11( Array< T , dim > &s1 ,
0176 const Array< T , dim > &s2 ,
0177 const Array< T , dim > &s3 ,
0178 const Array< T , dim > &s4 ,
0179 const Array< T , dim > &s5 ,
0180 const Array< T , dim > &s6 ,
0181 const Array< T , dim > &s7 ,
0182 const Array< T , dim > &s8 ,
0183 const Array< T , dim > &s9 ,
0184 const Array< T , dim > &s10 ,
0185 const Array< T , dim > &s11 , Op op )
0186 {
0187 for( size_t i=0 ; i<dim ; ++i )
0188 op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] );
0189 }
0190
0191 template < template < typename, size_t > class Array, typename T,
0192 size_t dim, class Op >
0193 static void for_each12( Array< T , dim > &s1 ,
0194 const Array< T , dim > &s2 ,
0195 const Array< T , dim > &s3 ,
0196 const Array< T , dim > &s4 ,
0197 const Array< T , dim > &s5 ,
0198 const Array< T , dim > &s6 ,
0199 const Array< T , dim > &s7 ,
0200 const Array< T , dim > &s8 ,
0201 const Array< T , dim > &s9 ,
0202 const Array< T , dim > &s10 ,
0203 const Array< T , dim > &s11 ,
0204 const Array< T , dim > &s12 , Op op )
0205 {
0206 for( size_t i=0 ; i<dim ; ++i )
0207 op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] , s12[i] );
0208 }
0209
0210 template < template < typename, size_t > class Array, typename T,
0211 size_t dim, class Op >
0212 static void for_each13( Array< T , dim > &s1 ,
0213 const Array< T , dim > &s2 ,
0214 const Array< T , dim > &s3 ,
0215 const Array< T , dim > &s4 ,
0216 const Array< T , dim > &s5 ,
0217 const Array< T , dim > &s6 ,
0218 const Array< T , dim > &s7 ,
0219 const Array< T , dim > &s8 ,
0220 const Array< T , dim > &s9 ,
0221 const Array< T , dim > &s10 ,
0222 const Array< T , dim > &s11 ,
0223 const Array< T , dim > &s12 ,
0224 const Array< T , dim > &s13 , Op op )
0225 {
0226 for( size_t i=0 ; i<dim ; ++i )
0227 op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] , s12[i] , s13[i] );
0228 }
0229
0230 template < template < typename, size_t > class Array, typename T,
0231 size_t dim, class Op >
0232 static void for_each14( Array< T , dim > &s1 ,
0233 const Array< T , dim > &s2 ,
0234 const Array< T , dim > &s3 ,
0235 const Array< T , dim > &s4 ,
0236 const Array< T , dim > &s5 ,
0237 const Array< T , dim > &s6 ,
0238 const Array< T , dim > &s7 ,
0239 const Array< T , dim > &s8 ,
0240 const Array< T , dim > &s9 ,
0241 const Array< T , dim > &s10 ,
0242 const Array< T , dim > &s11 ,
0243 const Array< T , dim > &s12 ,
0244 const Array< T , dim > &s13 ,
0245 const Array< T , dim > &s14 , Op op )
0246 {
0247 for( size_t i=0 ; i<dim ; ++i )
0248 op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] , s12[i] , s13[i] , s14[i] );
0249 }
0250
0251 template < template < typename, size_t > class Array, typename T,
0252 size_t dim, class Op >
0253 static void for_each15( Array< T , dim > &s1 ,
0254 const Array< T , dim > &s2 ,
0255 const Array< T , dim > &s3 ,
0256 const Array< T , dim > &s4 ,
0257 const Array< T , dim > &s5 ,
0258 const Array< T , dim > &s6 ,
0259 const Array< T , dim > &s7 ,
0260 const Array< T , dim > &s8 ,
0261 const Array< T , dim > &s9 ,
0262 const Array< T , dim > &s10 ,
0263 const Array< T , dim > &s11 ,
0264 const Array< T , dim > &s12 ,
0265 const Array< T , dim > &s13 ,
0266 const Array< T , dim > &s14 ,
0267 const Array< T , dim > &s15 , Op op )
0268 {
0269 for( size_t i=0 ; i<dim ; ++i )
0270 op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] , s12[i] , s13[i] , s14[i] , s15[i] );
0271 }
0272
0273
0274 template < template < typename, size_t > class Array, typename T,
0275 size_t dim>
0276 static typename norm_result_type< Array< T , dim > >::type norm_inf( const Array< T , dim > &s )
0277 {
0278 BOOST_USING_STD_MAX();
0279 using std::abs;
0280 typedef typename norm_result_type< Array< T , dim > >::type result_type;
0281 result_type init = static_cast< result_type >( 0 );
0282 for( size_t i=0 ; i<dim ; ++i )
0283 init = max BOOST_PREVENT_MACRO_SUBSTITUTION ( init , static_cast< result_type >(abs(s[i])) );
0284 return init;
0285 }
0286
0287 };
0288
0289 }
0290 }
0291 }
0292
0293 #endif