Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68402 - in sandbox/odeint/branches/karsten: boost/numeric/odeint/algebra boost/numeric/odeint/stepper libs/numeric/odeint/test
From: karsten.ahnert_at_[hidden]
Date: 2011-01-23 16:39:31


Author: karsten
Date: 2011-01-23 16:39:18 EST (Sun, 23 Jan 2011)
New Revision: 68402
URL: http://svn.boost.org/trac/boost/changeset/68402

Log:
* changing rel_error, should work now with boost::units
Text files modified:
   sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/standard_operations.hpp | 50 ++++++++++++++++++++++++++++++++++++++-
   sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/controlled_error_stepper.hpp | 7 ++---
   sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/error_checker.hpp | 21 ++++++++--------
   sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_concepts.cpp | 6 ++--
   sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_with_units.cpp | 10 ++++----
   5 files changed, 69 insertions(+), 25 deletions(-)

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/standard_operations.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/standard_operations.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/standard_operations.hpp 2011-01-23 16:39:18 EST (Sun, 23 Jan 2011)
@@ -17,11 +17,53 @@
 #include <cmath> // for std::max
 
 #include <boost/utility/result_of.hpp>
+#include <boost/units/quantity.hpp>
 
 namespace boost {
 namespace numeric {
 namespace odeint {
 
+/*
+ * Conversion of boost::units for use in standard_operations::rel_error
+ */
+namespace detail
+{
+ template< class T >
+ struct get_value_impl
+ {
+ static T value( const T &t ) { return t; }
+ typedef T result_type;
+ };
+
+ 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;
+ };
+
+ 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; }
+ };
+
+ 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 ); }
+ };
+
+ template< class T , class V >
+ void set_value( T &t , const V &v ) { return set_value_impl< T , V >::set_value( t , v ); }
+}
+
+
 
 /*
  * Notes:
@@ -185,10 +227,12 @@
 
 
 
+
+
         /*
          * for usage in for_each2
          *
- * ToDo : check if T1, T2, T3 are units and if so convert them to normal floats
+ * Works with boost::units by eliminating the unit
          */
         template< class Fac1 = double >
         struct rel_error
@@ -203,7 +247,9 @@
                 void operator()( const T1 &t1 , const T2 &t2 , T3 &t3 ) const
                 {
                         using std::abs;
- t3 = abs( t3 ) / ( m_eps_abs + m_eps_rel * ( m_a_x * abs( t1 ) + m_a_dxdt * abs( t2 ) ) );
+ using detail::get_value;
+ using detail::set_value;
+ set_value( t3 , abs( get_value( t3 ) ) / ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_value( t1 ) ) + m_a_dxdt * abs( get_value( t2 ) ) ) ) );
                 }
         };
 

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-01-23 16:39:18 EST (Sun, 23 Jan 2011)
@@ -39,10 +39,9 @@
  */
 template<
     class ErrorStepper ,
- class ErrorChecker = error_checker_standard< typename ErrorStepper::state_type ,
- typename ErrorStepper::time_type ,
- typename ErrorStepper::algebra_type ,
- typename ErrorStepper::operations_type > ,
+ class ErrorChecker = error_checker_standard< typename ErrorStepper::value_type ,
+ typename ErrorStepper::algebra_type ,
+ typename ErrorStepper::operations_type > ,
     class AdjustSizePolicy = typename ErrorStepper::adjust_size_policy ,
     class ErrorStepperCategory = typename ErrorStepper::stepper_category
>

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/error_checker.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/error_checker.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/error_checker.hpp 2011-01-23 16:39:18 EST (Sun, 23 Jan 2011)
@@ -23,8 +23,7 @@
 
 template
 <
- class State ,
- class Time ,
+ class Value ,
         class Algebra = standard_algebra ,
         class Operations = standard_operations
>
@@ -32,8 +31,7 @@
 {
 public:
 
- typedef State state_type;
- typedef Time time_type;
+ typedef Value value_type;
         typedef Algebra algebra_type;
         typedef Operations operations_type;
 
@@ -45,22 +43,23 @@
         /*
          * ToDo: implement constructor with epsilons
          */
- time_type error( const state_type &x_old , const state_type &dxdt_old , state_type &x_err , const time_type &dt )
+ template< class State , class Deriv , class Err >
+ value_type error( const State &x_old , const Deriv &dxdt_old , Err &x_err , const value_type &dt )
         {
                 // this overwrites x_err !
                 typename algebra_type::for_each3()( x_old , dxdt_old , x_err ,
- typename operations_type::template rel_error< time_type >( m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt*dt ) );
+ typename operations_type::template rel_error< value_type >( m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt*dt ) );
 
- time_type res = typename algebra_type::reduce()( x_err , typename operations_type::template maximum< time_type >() , 0.0 );
+ value_type res = typename algebra_type::reduce()( x_err , typename operations_type::template maximum< value_type >() , 0.0 );
                 return res;
         }
 
 private:
 
- time_type m_eps_abs;
- time_type m_eps_rel;
- time_type m_a_x;
- time_type m_a_dxdt;
+ value_type m_eps_abs;
+ value_type m_eps_rel;
+ value_type m_a_x;
+ value_type m_a_dxdt;
 };
 
 } // odeint

Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_concepts.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_concepts.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_concepts.cpp 2011-01-23 16:39:18 EST (Sun, 23 Jan 2011)
@@ -333,7 +333,7 @@
         {
                 vector_type x( 1 , 2.0 );
                 typename ControlledStepper::stepper_type error_stepper;
- error_checker_standard< typename ControlledStepper::state_type , typename ControlledStepper::time_type > error_checker;
+ error_checker_standard< typename ControlledStepper::value_type > error_checker;
                 ControlledStepper controlled_stepper( error_stepper , error_checker );
                 check_controlled_stepper_concept( controlled_stepper , constant_system_vector , x );
                 check_controlled_stepper_concept( controlled_stepper , boost::cref( constant_system_vector_class() ) , x );
@@ -349,7 +349,7 @@
                 vector_space_type x;
                 x.m_x = 2.0;
                 typename ControlledStepper::stepper_type error_stepper;
- error_checker_standard< typename ControlledStepper::state_type , typename ControlledStepper::time_type , vector_space_algebra > error_checker;
+ error_checker_standard< typename ControlledStepper::value_type , vector_space_algebra > error_checker;
                 ControlledStepper controlled_stepper( error_stepper , error_checker );
                 check_controlled_stepper_concept( controlled_stepper , constant_system_vector_space , x );
                 check_controlled_stepper_concept( controlled_stepper , boost::cref( constant_system_vector_space_class() ) , x );
@@ -365,7 +365,7 @@
                 array_type x;
                 x[0] = 2.0;
                 typename ControlledStepper::stepper_type error_stepper;
- error_checker_standard< typename ControlledStepper::state_type , typename ControlledStepper::time_type > error_checker;
+ error_checker_standard< typename ControlledStepper::value_type > error_checker;
                 ControlledStepper controlled_stepper( error_stepper , error_checker );
                 check_controlled_stepper_concept( controlled_stepper , constant_system_array , x );
                 check_controlled_stepper_concept( controlled_stepper , boost::cref( constant_system_array_class() ) , x );

Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_with_units.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_with_units.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_with_units.cpp 2011-01-23 16:39:18 EST (Sun, 23 Jan 2011)
@@ -185,15 +185,15 @@
         typedef typename stepper_type::deriv_type deriv_type;
         typedef typename stepper_type::time_type time_type;
         typedef typename stepper_type::order_type order_type;
- typedef typename stepper_type::algebra_type algebra_type;
- typedef typename stepper_type::operations_type operations_type;
+// typedef typename stepper_type::algebra_type algebra_type;
+// typedef typename stepper_type::operations_type operations_type;
 
         const time_type t( 0.0 * si::second );
         time_type dt( 0.1 * si::second );
         state_type x( 1.0 * si::meter , 0.0 * si::meter_per_second ) , xerr;
 
         // test call method one
- stepper.try_step( oscillator , x , t , dt );
+// stepper.try_step( oscillator , x , t , dt );
 }
 
 
@@ -260,8 +260,8 @@
 
 BOOST_AUTO_TEST_CASE_TEMPLATE( controlled_stepper_test , Stepper , controlled_stepper_types )
 {
-// Stepper stepper;
-// check_controlled_stepper( stepper );
+ Stepper stepper;
+ check_controlled_stepper( stepper );
 }
 
 


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