Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66710 - sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/generic_stepper
From: mario.mulansky_at_[hidden]
Date: 2010-11-24 10:20:47


Author: mariomulansky
Date: 2010-11-24 10:20:45 EST (Wed, 24 Nov 2010)
New Revision: 66710
URL: http://svn.boost.org/trac/boost/changeset/66710

Log:
added stage category for first, intermediate and last stage
todo: do_step
Text files modified:
   sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/generic_stepper/rk_test.cpp | 19 +++++----
   sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/generic_stepper/runge_kutta_stepper.hpp | 75 +++++++++++++++++++++++++++++----------
   2 files changed, 65 insertions(+), 29 deletions(-)

Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/generic_stepper/rk_test.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/generic_stepper/rk_test.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/generic_stepper/rk_test.cpp 2010-11-24 10:20:45 EST (Wed, 24 Nov 2010)
@@ -41,16 +41,17 @@
 
     euler_stepper euler( fusion::vector0<>() , b , c );
     euler.print_vals();
+ cout << typeid(euler_stepper::stage_vector_base).name() << endl;
 
- boost::array< double , 1 > a2 = {{ 0.5 }};
- boost::array< double , 2 > b2 = {{ 0.0 , 0.5 }};
- boost::array< double , 2 > c2 = {{ 0.0 , 1.0 }};
-
- cout << typeid(midpoint_stepper::coef_a_type).name() << endl;
- cout << typeid(midpoint_stepper::coef_b_type).name() << endl;
- cout << typeid(midpoint_stepper::coef_c_type).name() << endl;
- cout << typeid(midpoint_stepper::stage_vector_base).name() << endl;
-
+// boost::array< double , 1 > a2 = {{ 0.5 }};
+// boost::array< double , 2 > b2 = {{ 0.0 , 1.0 }};
+// boost::array< double , 2 > c2 = {{ 0.0 , 0.5 }};
+//
+// cout << typeid(midpoint_stepper::coef_a_type).name() << endl;
+// cout << typeid(midpoint_stepper::coef_b_type).name() << endl;
+// cout << typeid(midpoint_stepper::coef_c_type).name() << endl;
+// cout << typeid(midpoint_stepper::stage_vector_base).name() << endl;
+//
 // midpoint_stepper midpoint( fusion::make_vector( a2 ) , b2 , c2 );
 // midpoint.print_vals();
 

Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/generic_stepper/runge_kutta_stepper.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/generic_stepper/runge_kutta_stepper.hpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/generic_stepper/runge_kutta_stepper.hpp 2010-11-24 10:20:45 EST (Wed, 24 Nov 2010)
@@ -17,6 +17,11 @@
 #include <boost/fusion/container.hpp>
 #include <boost/fusion/algorithm.hpp>
 #include <boost/fusion/include/mpl.hpp>
+#include <boost/fusion/view/zip_view.hpp>
+#include <boost/fusion/include/zip_view.hpp>
+#include <boost/fusion/algorithm/transformation/push_back.hpp>
+#include <boost/fusion/include/push_back.hpp>
+
 
 #include <boost/array.hpp>
 
@@ -37,11 +42,22 @@
     typedef typename boost::array< T , Constant::value > type;
 };
 
+struct first_stage {};
+struct intermediate_stage {};
+struct last_stage {};
 
-template< class T , class Constant >
-struct stage_wrapper
+template< typename T , size_t N , typename StageCategory >
+struct stage_fusion
+{
+ //typedef typename fusion::result_of::as_vector< mpl::vector< size_t , T , boost::array< T , N > , StageCategory > >::type type;
+ typedef fusion::vector4< size_t , T , boost::array< T , N > , StageCategory > type;
+ typedef fusion::vector4< size_t , T , boost::array< T , N > , StageCategory >& ref_type;
+};
+
+template< class T , class Constant , class StageCategory >
+struct stage_fusion_wrapper
 {
- typedef typename fusion::result_of::as_vector< mpl::vector< size_t , T , boost::array< T , Constant::value > > >::type type;
+ typedef typename stage_fusion< T , Constant::value , StageCategory >::type type;
 };
 
 struct print_stage
@@ -49,7 +65,10 @@
     template< typename Stage >
     void operator() ( const Stage &stage ) const
     {
- std::cout<< fusion::at_c<0>( stage ) << " " << fusion::at_c<1>( stage ) << " " << std::endl;
+ std::cout<< "stage: " << fusion::at_c<0>( stage ) << " c:" << fusion::at_c<1>( stage ) << " ";
+ for( size_t i=0 ; i < fusion::at_c<2>( stage ).size() ; ++i )
+ std::cout << "a["<<i<<"]:" << fusion::at_c<2>( stage )[i] << " ";
+ std::cout << std::endl;
     }
 };
 
@@ -71,7 +90,7 @@
             stage_indices ,
             mpl::inserter
             <
- mpl::vector0<> ,
+ mpl::vector0< > ,
                 mpl::push_back< mpl::_1 , array_wrapper< double , mpl::_2 > >
>
>::type
@@ -82,36 +101,45 @@
     typedef boost::array< double , stage_count > coef_c_type;
 
 
- typedef typename fusion::result_of::as_vector<
+ typedef //typename fusion::result_of::as_vector<
         typename mpl::copy<
             stage_indices,
             mpl::inserter
               <
                 mpl::vector0<> ,
- mpl::push_back< mpl::_1 , stage_wrapper< double , mpl::_2 > >
+ mpl::push_back< mpl::_1 , stage_fusion_wrapper< double , mpl::_2 , intermediate_stage > >
>
- >::type
- >::type stage_vector_base;
+ >::type stage_vector_base0;
+ //>::type
+
+ typedef typename fusion::result_of::as_vector<
+ typename mpl::push_back<
+ stage_vector_base0 ,
+ typename stage_fusion_wrapper< double , mpl::integral_c< size_t , stage_count > , last_stage >::type
+ >::type
+ >::type stage_vector_base;
 
 
     struct stage_vector_type : public stage_vector_base
     {
         struct init_stage{
 
- const coef_a_type &m_a;
- const coef_b_type &m_c;
+ const coef_c_type &m_c;
 
- init_stage( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c )
- : m_a( a ) , m_c( c ) {}
+ init_stage( const coef_b_type &b , const coef_c_type &c )
+ : m_c( c ) {}
 
 
- template< typename Stage >
- void operator() ( const Stage &stage ) const
+ template< typename T , size_t N , typename StageCategory>
+ void operator() (
+ fusion::vector2< fusion::vector4< size_t , T , boost::array< T , N > , StageCategory >& ,
+ //stage_fusion< T , N , StageCategory >::ref_type ,
+ boost::array< T , N > > stage ) const
             {
- const size_t n = fusion::at_c<2>( stage ).size();
- fusion::at_c<0>( stage ) = n;
- fusion::at_c<1>( stage ) = m_c[n];
- fusion::at_c<2>( stage ) = m_a[n];
+ std::cout << N << std::endl;
+ fusion::at_c<0>( fusion::at_c<0>(stage) ) = N;
+ fusion::at_c<1>( fusion::at_c<0>(stage) ) = m_c[N-1];
+ fusion::at_c<2>( fusion::at_c<0>(stage) ) = fusion::at_c<1>( stage );
             }
 
         };
@@ -119,7 +147,14 @@
 
         stage_vector_type( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c )
         {
- fusion::for_each( static_cast< stage_vector_base& >( *this ) , init_stage( a , b , c ) );
+ //typedef typename fusion::result_of::push_back< const coef_a_type , const coef_b_type >::type ab_type;
+ typedef fusion::joint_view< const coef_a_type , const fusion::single_view< coef_b_type > > ab_type;
+ const ab_type ab = fusion::push_back( a , b );
+ // iterate stage and c in parallel
+ typedef fusion::vector< stage_vector_base& , const ab_type& > zipped_stage;
+
+ fusion::for_each( fusion::zip_view<zipped_stage>( zipped_stage( static_cast< stage_vector_base& >( *this ) , ab ) ) ,
+ init_stage( b , c ) );
         }
     };
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk