Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69385 - in sandbox/odeint/branches/karsten: . boost/numeric/odeint/stepper boost/numeric/odeint/util boost/numeric/odeint/util/detail libs/numeric/odeint/test
From: karsten.ahnert_at_[hidden]
Date: 2011-02-28 09:29:27


Author: karsten
Date: 2011-02-28 09:29:09 EST (Mon, 28 Feb 2011)
New Revision: 69385
URL: http://svn.boost.org/trac/boost/changeset/69385

Log:
ranges and the controlled_steppers
Added:
   sandbox/odeint/branches/karsten/boost/numeric/odeint/util/detail/
   sandbox/odeint/branches/karsten/boost/numeric/odeint/util/detail/is_range.hpp (contents, props changed)
Text files modified:
   sandbox/odeint/branches/karsten/TODO | 6 +-
   sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/controlled_error_stepper.hpp | 97 ++++++++++++++++++++++++++++++++-------
   sandbox/odeint/branches/karsten/boost/numeric/odeint/util/copy.hpp | 24 +++++++++
   sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_with_ranges.cpp | 34 ++++++++++++++
   4 files changed, 139 insertions(+), 22 deletions(-)

Modified: sandbox/odeint/branches/karsten/TODO
==============================================================================
--- sandbox/odeint/branches/karsten/TODO (original)
+++ sandbox/odeint/branches/karsten/TODO 2011-02-28 09:29:09 EST (Mon, 28 Feb 2011)
@@ -16,11 +16,11 @@
   OK * move error_checker into controlled_stepper
   * rename controlled_stepper to a more specific name
 * ranges:
- OK * explicit_stepper_and_error_stepper_fsal_base
+ * test ranges in symplectic_rkn_stepper
   * dense_output
- * controlled_error_stepper
   * integrate functions
- * test ranges in symplectic_rkn_stepper
+ OK * explicit_stepper_and_error_stepper_fsal_base
+ OK * controlled_error_stepper
   OK * check comments (spelling and if the comment is true, in some versions dxdt is already const)
   OK * check names of the impl functions
 * general:

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/controlled_error_stepper.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/controlled_error_stepper.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/controlled_error_stepper.hpp 2011-02-28 09:29:09 EST (Mon, 28 Feb 2011)
@@ -188,13 +188,22 @@
         template< class System , class StateInOut >
         controlled_step_result try_step( System system , StateInOut &x , time_type &t , time_type &dt )
         {
- typename boost::unwrap_reference< System >::type &sys = system;
- m_dxdt_size_adjuster.adjust_size_by_policy( x , adjust_size_policy() );
- sys( x , m_dxdt ,t );
- return try_step( system , x , m_dxdt , t , dt );
+ return try_step_v1( system , x , t, dt );
+ }
+
+ template< class System , class StateInOut >
+ controlled_step_result try_step( System system , const StateInOut &x , time_type &t , time_type &dt )
+ {
+ return try_step_v1( system , x , t, dt );
         }
 
- // try_step( sys , x , dxdt , t , dt )
+
+
+ /*
+ * Version 2 : try_step( sys , x , dxdt , t , dt )
+ *
+ * this version does not solve the forwarding problem, boost.range can not be used
+ */
         template< class System , class StateInOut , class DerivIn >
         controlled_step_result try_step( System system , StateInOut &x , const DerivIn &dxdt , time_type &t , time_type &dt )
         {
@@ -207,7 +216,11 @@
                 return res;
         }
 
- // try_step( sys , in , t , out , dt )
+ /*
+ * Version 3 : try_step( sys , in , t , out , dt )
+ *
+ * this version does not solve the forwarding problem, boost.range can not be used
+ */
         template< class System , class StateIn , class StateOut >
         controlled_step_result try_step( System system , const StateIn &in , time_type &t , StateOut &out , time_type &dt )
         {
@@ -218,7 +231,11 @@
         }
 
 
- // try_step( sys , in , dxdt , t , out , dt )
+ /*
+ * Version 4 : try_step( sys , in , dxdt , t , out , dt )
+ *
+ * this version does not solve the forwarding problem, boost.range can not be used
+ */
         template< class System , class StateIn , class DerivIn , class StateOut >
         controlled_step_result try_step( System system , const StateIn &in , const DerivIn &dxdt , time_type &t , StateOut &out , time_type &dt )
         {
@@ -286,6 +303,17 @@
 
 private:
 
+
+ template< class System , class StateInOut >
+ controlled_step_result try_step_v1( System system , StateInOut &x , time_type &t , time_type &dt )
+ {
+ typename boost::unwrap_reference< System >::type &sys = system;
+ m_dxdt_size_adjuster.adjust_size_by_policy( x , adjust_size_policy() );
+ sys( x , m_dxdt ,t );
+ return try_step( system , x , m_dxdt , t , dt );
+ }
+
+
         stepper_type m_stepper;
         error_checker_type m_error_checker;
 
@@ -392,20 +420,30 @@
 
 
 
- // try_step( sys , x , t , dt )
+ /*
+ * Version 1 : try_step( sys , x , t , dt )
+ *
+ * The two overloads are needed in order to solve the forwarding problem
+ */
     template< class System , class StateInOut >
     controlled_step_result try_step( System system , StateInOut &x , time_type &t , time_type &dt )
     {
- if( m_dxdt_size_adjuster.adjust_size_by_policy( x , adjust_size_policy() ) || m_first_call )
- {
- typename boost::unwrap_reference< System >::type &sys = system;
- sys( x , m_dxdt ,t );
- m_first_call = false;
- }
- return try_step( system , x , m_dxdt , t , dt );
+ return try_step_v1( system , x , t , dt );
+ }
+
+ template< class System , class StateInOut >
+ controlled_step_result try_step( System system , const StateInOut &x , time_type &t , time_type &dt )
+ {
+ return try_step_v1( system , x , t , dt );
     }
 
- // try_step( sys , in , t , out , dt );
+
+
+ /*
+ * Version 2 : try_step( sys , in , t , out , dt );
+ *
+ * This version does not solve the forwarding problem, boost::range can not be used.
+ */
     template< class System , class StateIn , class StateOut >
     controlled_step_result try_step( System system , const StateIn &in , time_type &t , StateOut &out , time_type &dt )
     {
@@ -418,7 +456,12 @@
         return try_step( system , in , m_dxdt , t , out , dt );
     }
 
- // try_step( sys , x , dxdt , t , dt )
+
+ /*
+ * Version 3 : try_step( sys , x , dxdt , t , dt )
+ *
+ * This version does not solve the forwarding problem, boost::range can not be used.
+ */
     template< class System , class StateInOut , class DerivInOut >
     controlled_step_result try_step( System system , StateInOut &x , DerivInOut &dxdt , time_type &t , time_type &dt )
     {
@@ -433,7 +476,12 @@
             return res;
     }
 
- // try_step( sys , in , dxdt , t , out , dt )
+
+ /*
+ * Version 3 : try_step( sys , in , dxdt , t , out , dt )
+ *
+ * This version does not solve the forwarding problem, boost::range can not be used.
+ */
     template< class System , class StateIn , class DerivIn , class StateOut , class DerivOut >
     controlled_step_result try_step( System system , const StateIn &in , const DerivIn &dxdt_in , time_type &t ,
                     StateOut &out , DerivOut &dxdt_out , time_type &dt )
@@ -506,6 +554,19 @@
 
 private:
 
+ template< class System , class StateInOut >
+ controlled_step_result try_step_v1( System system , StateInOut &x , time_type &t , time_type &dt )
+ {
+ if( m_dxdt_size_adjuster.adjust_size_by_policy( x , adjust_size_policy() ) || m_first_call )
+ {
+ typename boost::unwrap_reference< System >::type &sys = system;
+ sys( x , m_dxdt ,t );
+ m_first_call = false;
+ }
+ return try_step( system , x , m_dxdt , t , dt );
+ }
+
+
     stepper_type m_stepper;
     error_checker_type m_error_checker;
 

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/util/copy.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/util/copy.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/util/copy.hpp 2011-02-28 09:29:09 EST (Mon, 28 Feb 2011)
@@ -8,10 +8,31 @@
 #ifndef BOOST_NUMERIC_ODEINT_UTIL_COPY_HPP_
 #define BOOST_NUMERIC_ODEINT_UTIL_COPY_HPP_
 
+#include <boost/range/algorithm/copy.hpp>
+
+#include <boost/utility/enable_if.hpp>
+
+#include <boost/numeric/odeint/util/detail/is_range.hpp>
+
 namespace boost {
 namespace numeric {
 namespace odeint {
 
+namespace detail
+{
+ template< class Container1 , class Container2 >
+ void do_copying( const Container1 &from , Container2 &to , boost::mpl::true_ )
+ {
+ boost::range::copy( from , boost::begin( to ) );
+ }
+
+ template< class Container1 , class Container2 >
+ void do_copying( const Container1 &from , Container2 &to , boost::mpl::false_ )
+ {
+ to = from;
+ }
+}
+
 /*
  * Default implementation of the copy operation used the assign operator
  * gsl_vector must copied differently
@@ -21,7 +42,8 @@
 {
         static void copy( const Container1 &from , Container2 &to )
         {
- to = from;
+ typedef typename boost::numeric::odeint::detail::is_range< Container1 >::type is_range_type;
+ detail::do_copying( from , to , is_range_type() );
         }
 };
 

Added: sandbox/odeint/branches/karsten/boost/numeric/odeint/util/detail/is_range.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/util/detail/is_range.hpp 2011-02-28 09:29:09 EST (Mon, 28 Feb 2011)
@@ -0,0 +1,124 @@
+// Boost.Range library
+//
+// Copyright Thorsten Ottosen 2003-2004. Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see http://www.boost.org/libs/range/
+//
+
+#ifndef BOOST_NUMERIC_ODEINT_UTIL_DETAIL_IS_RANGE_HPP
+#define BOOST_NUMERIC_ODEINT_UTIL_DETAIL_IS_RANGE_HPP
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif
+
+#include <cstddef>
+#include <boost/range/config.hpp>
+#include <boost/mpl/has_xxx.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/and.hpp>
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+
+
+ namespace range_detail
+ {
+ BOOST_MPL_HAS_XXX_TRAIT_DEF(iterator)
+ BOOST_MPL_HAS_XXX_TRAIT_DEF(const_iterator)
+ }
+
+namespace detail
+{
+
+ template< typename Range >
+ struct is_range : boost::mpl::and_<range_detail::has_iterator<Range>, range_detail::has_const_iterator<Range> >
+ {
+ };
+
+ //////////////////////////////////////////////////////////////////////////
+ // pair
+ //////////////////////////////////////////////////////////////////////////
+
+ template< typename iteratorT >
+ struct is_range< std::pair<iteratorT,iteratorT> > : boost::mpl::true_
+ {
+ };
+
+ template< typename iteratorT >
+ struct is_range< const std::pair<iteratorT,iteratorT> > : boost::mpl::true_
+ {
+ };
+
+ //////////////////////////////////////////////////////////////////////////
+ // array
+ //////////////////////////////////////////////////////////////////////////
+
+ template< typename elementT, std::size_t sz >
+ struct is_range< elementT[sz] > : boost::mpl::true_
+ {
+ };
+
+ template< typename elementT, std::size_t sz >
+ struct is_range< const elementT[sz] > : boost::mpl::true_
+ {
+ };
+
+ //////////////////////////////////////////////////////////////////////////
+ // string
+ //////////////////////////////////////////////////////////////////////////
+
+ template<>
+ struct is_range< char* > : boost::mpl::true_
+ {
+ };
+
+ template<>
+ struct is_range< wchar_t* > : boost::mpl::true_
+ {
+ };
+
+ template<>
+ struct is_range< const char* > : boost::mpl::true_
+ {
+ };
+
+ template<>
+ struct is_range< const wchar_t* > : boost::mpl::true_
+ {
+ };
+
+ template<>
+ struct is_range< char* const > : boost::mpl::true_
+ {
+ };
+
+ template<>
+ struct is_range< wchar_t* const > : boost::mpl::true_
+ {
+ };
+
+ template<>
+ struct is_range< const char* const > : boost::mpl::true_
+ {
+ };
+
+ template<>
+ struct is_range< const wchar_t* const > : boost::mpl::true_
+ {
+ };
+
+} // namespace detail
+
+} // namespaec odeint
+} // namespace numeric
+} // namespace boost
+
+
+
+#endif // BOOST_NUMERIC_ODEINT_UTIL_DETAIL_IS_RANGE_HPP

Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_with_ranges.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_with_ranges.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_with_ranges.cpp 2011-02-28 09:29:09 EST (Mon, 28 Feb 2011)
@@ -18,6 +18,8 @@
 #include <boost/numeric/odeint/stepper/explicit_euler.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>
+#include <boost/numeric/odeint/stepper/symplectic_euler.hpp>
 
 typedef std::vector< double > state_type;
 typedef std::tr1::array< double , 3 > state_type2;
@@ -159,6 +161,38 @@
         CHECK_VALUES( f.in , 0.0 , 1.1 , 2.2 , 3.3 , 4.0 , 5.0 );
 }
 
+BOOST_AUTO_TEST_CASE( controlled_error_stepper_rk54 )
+{
+ double t = 0.0 , dt = 0.1;
+ vector_fixture f;
+ boost::numeric::odeint::controlled_error_stepper< boost::numeric::odeint::explicit_error_rk54_ck< state_type > > stepper;
+ stepper.try_step( system2() , std::make_pair( f.in.begin() + 1 , f.in.begin() + 4 ) , t , dt );
+ CHECK_VALUES( f.in , 0.0 , 1.1 , 2.2 , 3.3 , 4.0 , 5.0 );
+}
+
+BOOST_AUTO_TEST_CASE( controlled_error_stepper_dopri5 )
+{
+ double t = 0.0 , dt = 0.1;
+ vector_fixture f;
+ boost::numeric::odeint::controlled_error_stepper< boost::numeric::odeint::explicit_error_dopri5< state_type > > stepper;
+ stepper.try_step( system2() , std::make_pair( f.in.begin() + 1 , f.in.begin() + 4 ) , t , dt );
+ CHECK_VALUES( f.in , 0.0 , 1.1 , 2.2 , 3.3 , 4.0 , 5.0 );
+}
+
+BOOST_AUTO_TEST_CASE( symplectic_euler_coor_func )
+{
+ vector_fixture f;
+ boost::numeric::odeint::symplectic_euler< state_type > euler;
+// euler.do_step( )
+}
+
+BOOST_AUTO_TEST_CASE( symplectic_euler_coor_and_mom_func )
+{
+ vector_fixture f;
+ boost::numeric::odeint::symplectic_euler< state_type > euler;
+// euler.do_step( )
+}
+
 
 
 BOOST_AUTO_TEST_SUITE_END()


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