Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72328 - in sandbox/odeint/branches/karsten: boost/numeric/odeint/algebra boost/numeric/odeint/stepper libs/numeric/odeint/ideas/fusion_runge_kutta/performance libs/numeric/odeint/test
From: mario.mulansky_at_[hidden]
Date: 2011-06-01 11:07:31


Author: mariomulansky
Date: 2011-06-01 11:07:30 EDT (Wed, 01 Jun 2011)
New Revision: 72328
URL: http://svn.boost.org/trac/boost/changeset/72328

Log:
added explicit_rk4_generic
added copy constructor and assign operator to generic_rk, not finished yet - stepper_copying still fails due to missing deriv_type initializations
Added:
   sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_rk4_generic.hpp (contents, props changed)
Text files modified:
   sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/default_operations.hpp | 94 +++++++++++++++++++++++----------------
   sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_generic_rk.hpp | 49 +++++++++++++++++---
   sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_odeint_rk4_lorenz.cpp | 11 +++-
   sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_copying.cpp | 61 +++++++++++++++++++++++++
   4 files changed, 165 insertions(+), 50 deletions(-)

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/default_operations.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/default_operations.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/default_operations.hpp 2011-06-01 11:07:30 EDT (Wed, 01 Jun 2011)
@@ -29,46 +29,62 @@
 /*
  * Conversion of boost::units for use in standard_operations::rel_error and standard_operations::maximum
  */
-namespace detail
-{
-
- template< class T >
- struct get_value_impl
- {
- static T value( const T &t ) { return t; }
- typedef T result_type;
- };
-
- #ifndef __CUDACC__
- template< class Unit , class T >
- struct get_value_impl< boost::units::quantity< Unit , T > >
- {
- static T value( const boost::units::quantity< Unit , T > &t ) { return t.value(); }
- typedef T result_type;
- };
- #endif
-
- template< class T >
- typename get_value_impl< T >::result_type get_value( const T &t ) { return get_value_impl< T >::value( t ); }
-
-
-
- template< class T , class V >
- struct set_value_impl
- {
- static void set_value( T &t , const V &v ) { t = v; }
- };
-
- #ifndef __CUDACC__
- template< class Unit , class T , class V >
- struct set_value_impl< boost::units::quantity< Unit , T > , V >
- {
- static void set_value( boost::units::quantity< Unit , T > &t , const V &v ) { t = boost::units::quantity< Unit , T >::from_value( v ); }
- };
- #endif
+namespace detail {
 
- template< class T , class V >
- void set_value( T &t , const V &v ) { return set_value_impl< T , V >::set_value( t , v ); }
+ template<class T>
+ struct get_value_impl
+ {
+ static T value(const T &t)
+ {
+ return t;
+ }
+ typedef T result_type;
+ };
+
+ #ifndef __CUDACC__
+ template<class Unit , class T>
+ struct get_value_impl<boost::units::quantity<Unit , T> >
+ {
+ static T value(const boost::units::quantity<Unit , T> &t)
+ {
+ return t.value();
+ }
+ typedef T result_type;
+ };
+ #endif
+
+ template<class T>
+ typename get_value_impl<T>::result_type get_value(const T &t)
+ {
+ return get_value_impl<T>::value(t);
+ }
+
+ template<class T , class V>
+ struct set_value_impl
+ {
+ static void set_value(T &t , const V &v)
+ {
+ t = v;
+ }
+ };
+
+ #ifndef __CUDACC__
+ template<class Unit , class T , class V>
+ struct set_value_impl<boost::units::quantity<Unit , T> , V>
+ {
+ static void set_value(boost::units::quantity<Unit , T> &t , const V &v)
+ {
+ t = boost::units::quantity<Unit , T>::from_value(v);
+ }
+ };
+ #endif
+
+ template<class T , class V>
+
+ void set_value(T &t , const V &v)
+ {
+ return set_value_impl<T , V>::set_value(t , v);
+ }
 
 }
 

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_generic_rk.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_generic_rk.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_generic_rk.hpp 2011-06-01 11:07:30 EDT (Wed, 01 Jun 2011)
@@ -33,7 +33,7 @@
 #include <boost/numeric/odeint/stepper/detail/generic_rk_operations.hpp>
 //#include "fusion_foreach_performance.hpp"
 
-#include <iostream>
+//#include <iostream>
 
 namespace mpl = boost::mpl;
 namespace fusion = boost::fusion;
@@ -96,7 +96,7 @@
         typedef typename stepper_base_type::stepper_type stepper_type;
 
 
- typedef mpl::range_c< size_t , 1 , StageCount > stage_indices;
+ typedef mpl::range_c< size_t , 1 , StageCount > stage_indices;
 
     typedef typename fusion::result_of::as_vector
     <
@@ -211,14 +211,47 @@
 
     };
 
+
+private:
+
+ void initialize( void )
+ {
+ boost::numeric::odeint::construct( m_x_tmp );
+ }
+
+ void copy( const explicit_generic_rk &rk )
+ {
+ boost::numeric::odeint::copy( rk.m_x_tmp , m_x_tmp );
+ }
+
+
 public:
 
- explicit_generic_rk( const coef_a_type &a ,
- const coef_b_type &b ,
- const coef_c_type &c )
- : m_stages( a , b , c )
+ explicit_generic_rk( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c )
+ : m_stages( a , b , c ) , m_x_tmp()
 
- { }
+ {
+ initialize();
+ }
+
+ explicit_generic_rk( const explicit_generic_rk &rk )
+ : stepper_base_type( rk ) , m_stages( rk.m_stages ) , m_x_tmp()
+ {
+ initialize();
+ copy( rk );
+ }
+
+ explicit_generic_rk& operator=( const explicit_generic_rk &rk )
+ {
+ stepper_base_type::operator=( rk );
+ copy( rk );
+ return *this;
+ }
+
+ ~explicit_generic_rk( void )
+ {
+ boost::numeric::odeint::destruct( m_x_tmp );
+ }
 
 
     template< class System , class StateIn , class DerivIn , class StateOut >
@@ -234,7 +267,7 @@
     state_type m_x_tmp;
 
 protected:
- state_type m_F[StageCount-1];
+ deriv_type m_F[StageCount-1];
 
 };
 

Added: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_rk4_generic.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_rk4_generic.hpp 2011-06-01 11:07:30 EDT (Wed, 01 Jun 2011)
@@ -0,0 +1,84 @@
+/*
+ * explicit_rk4_generic.hpp
+ *
+ * Created on: Jun 1, 2011
+ * Author: mario
+ */
+
+#ifndef EXPLICIT_RK4_GENERIC_HPP_
+#define EXPLICIT_RK4_GENERIC_HPP_
+
+#include <boost/fusion/container.hpp>
+
+#include <boost/numeric/odeint/stepper/explicit_generic_rk.hpp>
+#include <boost/numeric/odeint/algebra/range_algebra.hpp>
+#include <boost/numeric/odeint/algebra/default_operations.hpp>
+
+#include <boost/array.hpp>
+
+
+namespace fusion = boost::fusion;
+
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+namespace constants_generic {
+
+ const boost::array< double , 1 > rk4_a1 = {{ 0.5 }};
+ const boost::array< double , 2 > rk4_a2 = {{ 0.0 , 0.5 }};
+ const boost::array< double , 3 > rk4_a3 = {{ 0.0 , 0.0 , 1.0 }};
+
+ const boost::array< double , 4 > rk4_b = {{ 1.0/6 , 1.0/3 , 1.0/3 , 1.0/6 }};
+ const boost::array< double , 4 > rk4_c = {{ 0.0 , 0.5 , 0.5 , 1.0 }};
+
+}
+
+template<
+ class State ,
+ class Value = double ,
+ class Deriv = State ,
+ class Time = Value ,
+ class Algebra = range_algebra ,
+ class Operations = default_operations ,
+ class AdjustSizePolicy = adjust_size_initially_tag
+ >
+class explicit_rk4_generic : public explicit_generic_rk< 4 , 4 , State , Value , Deriv , Value ,
+ Algebra , Operations , AdjustSizePolicy >
+{
+
+public:
+
+ typedef explicit_generic_rk< 4 , 4 , State , Value , Deriv , Value ,
+ Algebra , Operations , AdjustSizePolicy > stepper_base_type;
+
+ typedef typename stepper_base_type::state_type state_type;
+ typedef typename stepper_base_type::value_type value_type;
+ typedef typename stepper_base_type::deriv_type deriv_type;
+ typedef typename stepper_base_type::time_type time_type;
+ typedef typename stepper_base_type::algebra_type algebra_type;
+ typedef typename stepper_base_type::operations_type operations_type;
+ typedef typename stepper_base_type::adjust_size_policy adjust_size_policy;
+ typedef typename stepper_base_type::stepper_type stepper_type;
+
+ explicit_rk4_generic( void ) : stepper_base_type(
+ fusion::make_vector( constants_generic::rk4_a1 , constants_generic::rk4_a2 , constants_generic::rk4_a3 ) ,
+ constants_generic::rk4_b , constants_generic::rk4_c )
+ { }
+
+ explicit_rk4_generic& operator=( const explicit_rk4_generic &rk )
+ {
+ stepper_base_type::operator=( rk );
+ return *this;
+ }
+
+
+};
+
+}
+}
+}
+
+
+#endif /* EXPLICIT_RK4_GENERIC_HPP_ */

Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_odeint_rk4_lorenz.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_odeint_rk4_lorenz.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_odeint_rk4_lorenz.cpp 2011-06-01 11:07:30 EDT (Wed, 01 Jun 2011)
@@ -1,6 +1,7 @@
 #include <boost/array.hpp>
 
-#include <boost/numeric/odeint/stepper/explicit_generic_rk.hpp>
+//#include <boost/numeric/odeint/stepper/explicit_generic_rk.hpp>
+#include <boost/numeric/odeint/stepper/explicit_rk4_generic.hpp>
 #include <boost/numeric/odeint/algebra/array_algebra.hpp>
 
 #include "rk_performance_test_case.hpp"
@@ -10,7 +11,7 @@
 using namespace boost::numeric::odeint;
 
 typedef boost::array< double , 3 > state_type;
-typedef explicit_generic_rk< 4 , 4 , state_type , double , state_type , double , array_algebra > rk4_type;
+/*typedef explicit_generic_rk< 4 , 4 , state_type , double , state_type , double , array_algebra > rk4_type;
 
 typedef rk4_type::coef_a_type coef_a_type;
 typedef rk4_type::coef_b_type coef_b_type;
@@ -23,13 +24,17 @@
 const coef_a_type a = fusion::make_vector( a1 , a2 , a3 );
 const coef_b_type b = {{ 1.0/6 , 1.0/3 , 1.0/3 , 1.0/6 }};
 const coef_c_type c = {{ 0.0 , 0.5 , 0.5 , 1.0 }};
+*/
+
+typedef explicit_rk4_generic< state_type , double , state_type , double , array_algebra > rk4_type;
+
 
 class rk4_wrapper
 {
 
 public:
 
- rk4_wrapper() : m_stepper( a , b , c )
+ rk4_wrapper()
     { }
 
     void reset_init_cond()

Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_copying.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_copying.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_copying.cpp 2011-06-01 11:07:30 EDT (Wed, 01 Jun 2011)
@@ -16,6 +16,7 @@
 
 #include <boost/numeric/odeint/stepper/explicit_euler.hpp>
 #include <boost/numeric/odeint/stepper/explicit_rk4.hpp>
+#include <boost/numeric/odeint/stepper/explicit_rk4_generic.hpp>
 #include <boost/numeric/odeint/stepper/explicit_error_rk54_ck.hpp>
 #include <boost/numeric/odeint/stepper/explicit_error_dopri5.hpp>
 #include <boost/numeric/odeint/stepper/controlled_error_stepper.hpp>
@@ -167,6 +168,7 @@
 typedef test_array2< double , 3 > deriv_type;
 typedef boost::numeric::odeint::explicit_euler< state_type , double , deriv_type > euler_type;
 typedef boost::numeric::odeint::explicit_rk4< state_type , double , deriv_type > rk4_type;
+typedef boost::numeric::odeint::explicit_rk4_generic< state_type , double , deriv_type > rk4_generic_type;
 typedef boost::numeric::odeint::explicit_error_rk54_ck< state_type , double , deriv_type > rk54_type;
 typedef boost::numeric::odeint::explicit_error_dopri5< state_type , double , deriv_type > dopri5_type;
 typedef boost::numeric::odeint::controlled_error_stepper< rk54_type > controlled_rk54_type;
@@ -291,6 +293,65 @@
         CHECK_COUNTERS( 2 , 8 , 2 , 8 , 1 , 4 );
 }
 
+
+/*
+ * Construct + Destruct
+ * 1 deriv_type in explicit_stepper_base
+ * 3 deriv_type in explicit_rk4
+ * 1 state_type in explicit_rk4
+ */
+BOOST_AUTO_TEST_CASE( explicit_rk4_generic_construct )
+{
+ reset_counter();
+ {
+ rk4_generic_type rk4;
+ }
+ CHECK_COUNTERS( 1 , 4 , 1 , 4 , 0 , 0 );
+}
+
+/*
+ * Construct + Destruct
+ * 2 * 1 deriv_type in explicit_stepper_base
+ * 2 * 3 deriv_type in explicit_rk4
+ * 2 * 1 state_type in explicit_rk4
+ *
+ * Copying
+ * 1 deriv_type in explicit_stepper_base
+ * 3 deriv_type in explicit_stepper_base
+ * 1 state_type in explicit_stepper_base
+ */
+BOOST_AUTO_TEST_CASE( explicit_rk4_generic_copy_construct )
+{
+ reset_counter();
+ {
+ rk4_generic_type rk4;
+ rk4_generic_type rk4_2( rk4 );
+ }
+ CHECK_COUNTERS( 2 , 8 , 2 , 8 , 1 , 4 );
+}
+
+/*
+ * Construct + Destruct
+ * 2 * 1 deriv_type in explicit_stepper_base
+ * 2 * 3 deriv_type in explicit_rk4
+ * 2 * 1 state_type in explicit_rk4
+ *
+ * Copying
+ * 1 deriv_type in explicit_stepper_base
+ * 3 deriv_type in explicit_stepper_base
+ * 1 state_type in explicit_stepper_base
+ */
+BOOST_AUTO_TEST_CASE( explicit_rk4_generic_assign )
+{
+ reset_counter();
+ {
+ rk4_generic_type rk4;
+ rk4_generic_type rk4_2;
+ rk4 = rk4_2;
+ }
+ CHECK_COUNTERS( 2 , 8 , 2 , 8 , 1 , 4 );
+}
+
 /*
  * Construct + Destruct
  * 2 explicit_rk54_ck:


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