|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r68564 - in sandbox/odeint/branches/karsten: . boost/numeric/odeint/stepper libs/numeric/odeint/test
From: karsten.ahnert_at_[hidden]
Date: 2011-01-30 06:40:06
Author: karsten
Date: 2011-01-30 06:40:02 EST (Sun, 30 Jan 2011)
New Revision: 68564
URL: http://svn.boost.org/trac/boost/changeset/68564
Log:
* unit test stepper copying
* introducing stepper_with_ranges unit test
* small bug fixing in controlled_error_stepper
Added:
sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_with_ranges.cpp (contents, props changed)
Text files modified:
sandbox/odeint/branches/karsten/TODO | 7
sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/controlled_error_stepper.hpp | 7
sandbox/odeint/branches/karsten/libs/numeric/odeint/test/Jamfile | 1
sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_copying.cpp | 467 +++++++++++++++++++++++++++++++++++++++
4 files changed, 476 insertions(+), 6 deletions(-)
Modified: sandbox/odeint/branches/karsten/TODO
==============================================================================
--- sandbox/odeint/branches/karsten/TODO (original)
+++ sandbox/odeint/branches/karsten/TODO 2011-01-30 06:40:02 EST (Sun, 30 Jan 2011)
@@ -3,8 +3,11 @@
OK * test standard_algebra
OK * test fusion_algebra
* test vector_space_algebra, maybe with some proto lib
- * test copying
- * test, if copy construct of stepper_base is called when explicit_euler is used
+ NEARLY DONE * test copying
+ * include controlled_error_stepper_fsal
+ * include dense_output_explicit
+ * inlcude dense_output_controlled_explicit_fsal
+ OK * test, if copy construct of stepper_base is called when explicit_euler is used
* test gsl
* test explicit stepper with ranges
* test units with dense output
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-30 06:40:02 EST (Sun, 30 Jan 2011)
@@ -119,7 +119,8 @@
{
boost::numeric::odeint::copy( stepper.m_dxdt , m_dxdt );
boost::numeric::odeint::copy( stepper.m_xerr , m_xerr );
- boost::numeric::odeint::copy( stepper.m_dnew , m_xnew );
+ boost::numeric::odeint::copy( stepper.m_xnew , m_xnew );
+ m_max_rel_error = stepper.m_max_rel_error;
}
public:
@@ -164,8 +165,8 @@
controlled_error_stepper& operator=( const controlled_error_stepper &stepper )
{
- m_stepper( stepper.m_stepper );
- m_error_checker( stepper.m_error_checker );
+ m_stepper = stepper.m_stepper;
+ m_error_checker = stepper.m_error_checker;
copy( stepper );
return *this;
}
Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/test/Jamfile
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/test/Jamfile (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/test/Jamfile 2011-01-30 06:40:02 EST (Sun, 30 Jan 2011)
@@ -26,4 +26,5 @@
[ run fusion_algebra.cpp ]
[ run stepper_with_units.cpp ]
[ run stepper_copying.cpp ]
+ [ run stepper_with_ranges.cpp ]
;
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-01-30 06:40:02 EST (Sun, 30 Jan 2011)
@@ -5,15 +5,480 @@
* Author: karsten
*/
+
#define BOOST_TEST_MODULE odeint_stepper_copying
#include <boost/test/unit_test.hpp>
+#include <boost/numeric/odeint/algebra/default_resize.hpp>
+#include <boost/numeric/odeint/stepper/explicit_euler.hpp>
+#include <boost/numeric/odeint/stepper/explicit_rk4.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/dense_output_explicit.hpp>
+#include <boost/numeric/odeint/stepper/dense_output_controlled_explicit_fsal.hpp>
+
+template< class T , size_t Dim >
+class test_array
+{
+public:
+
+ const static size_t dim = Dim;
+ typedef T value_type;
+ typedef value_type* iterator;
+ typedef const value_type* const_iterator;
+
+ value_type& operator[]( size_t i )
+ {
+ return m_data[i];
+ }
+
+ const value_type& operator[]( size_t i ) const
+ {
+ return m_data[i];
+ }
+
+ iterator begin( void )
+ {
+ return m_data;
+ }
+
+ iterator end( void )
+ {
+ return m_data + dim;
+ }
+
+ const_iterator begin( void ) const
+ {
+ return m_data;
+ }
+
+ const_iterator end( void ) const
+ {
+ return m_data + dim;
+ }
+
+
+private:
+
+ value_type m_data[dim];
+};
+
+template< class T , size_t Dim >
+class test_array2 : public test_array< T , Dim >
+{
+};
+
+
+
+/*
+ * Explicit testing if copying was successful is difficult,
+ * hence we only test if the number of copy operations is right.
+ *
+ * Otherwise one has to prepare the states.
+ */
+
+size_t construct_count = 0;
+size_t construct2_count = 0;
+size_t destruct_count = 0;
+size_t destruct2_count = 0;
+size_t copy_count = 0;
+size_t copy2_count = 0;
+
+void reset_counter( void )
+{
+ construct_count = 0;
+ construct2_count = 0;
+ destruct_count = 0;
+ destruct2_count = 0;
+ copy_count = 0;
+ copy2_count = 0;
+}
+
+
+namespace boost { namespace numeric { namespace odeint {
+
+template< class T , size_t Dim >
+struct construct_impl< test_array< T , Dim > >
+{
+ static void construct( test_array< T , Dim > &arr )
+ {
+ ++construct_count;
+ }
+};
+
+template< class T , size_t Dim >
+struct construct_impl< test_array2< T , Dim > >
+{
+ static void construct( test_array2< T , Dim > &arr )
+ {
+ ++construct2_count;
+ }
+};
+
+
+template< class T , size_t Dim >
+struct destruct_impl< test_array< T , Dim > >
+{
+ static void destruct( test_array< T , Dim > &arr )
+ {
+ ++destruct_count;
+ }
+};
+
+template< class T , size_t Dim >
+struct destruct_impl< test_array2< T , Dim > >
+{
+ static void destruct( test_array2< T , Dim > &arr )
+ {
+ ++destruct2_count;
+ }
+};
+
+
+template< class T , size_t Dim >
+struct copy_impl< test_array< T , Dim > , test_array< T , Dim > >
+{
+ static void copy( const test_array< T , Dim > &from , test_array< T , Dim > &to )
+ {
+ ++copy_count;
+ }
+};
+
+template< class T , size_t Dim >
+struct copy_impl< test_array2< T , Dim > , test_array2< T , Dim > >
+{
+ static void copy( const test_array2< T , Dim > &from , test_array2< T , Dim > &to )
+ {
+ ++copy2_count;
+ }
+};
+
+
+} } }
+
+
+
+typedef test_array< double , 3 > state_type;
+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_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;
+typedef boost::numeric::odeint::controlled_error_stepper< dopri5_type > controlled_dopri5_type;
+typedef boost::numeric::odeint::dense_output_explicit< euler_type > dense_output_euler_type;
+typedef boost::numeric::odeint::dense_output_controlled_explicit_fsal< controlled_dopri5_type > dense_output_dopri5_type;
+
+#define CHECK_COUNTERS( c1 , c2 , c3 , c4 , c5 , c6 ) \
+ BOOST_CHECK_EQUAL( construct_count , size_t( c1 ) ); \
+ BOOST_CHECK_EQUAL( construct2_count , size_t( c2 ) ); \
+ BOOST_CHECK_EQUAL( destruct_count , size_t( c3 ) ); \
+ BOOST_CHECK_EQUAL( destruct2_count , size_t( c4) ); \
+ BOOST_CHECK_EQUAL( copy_count , size_t( c5 ) ) ; \
+ BOOST_CHECK_EQUAL( copy2_count, size_t( c6 ) )
+
BOOST_AUTO_TEST_SUITE( stepper_copying )
-BOOST_AUTO_TEST_CASE( explicit_euler_copying )
+/*
+ * Construct + Destruct
+ * 1 deriv_type in explicit_stepper_base
+ */
+BOOST_AUTO_TEST_CASE( explicit_euler_construct )
+{
+ reset_counter();
+ {
+ euler_type euler;
+ }
+ CHECK_COUNTERS( 0 , 1 , 0 , 1 , 0 , 0 );
+}
+
+
+/*
+ * Construct + Destruct
+ * 2 * 1 deriv_type in explicit_stepper_base
+ *
+ * Copying
+ * 1 deriv_type in explicit_stepper_base
+ */
+BOOST_AUTO_TEST_CASE( explicit_euler_copy_construct )
+{
+ reset_counter();
+ {
+ euler_type euler;
+ euler_type euler2( euler );
+ }
+ CHECK_COUNTERS( 0 , 1 + 1 , 0 , 1 + 1 , 0 , 1 );
+}
+
+/*
+ * Construct + Destruct
+ * 2 * 1 deriv_type in explicit_stepper_base
+ *
+ * Copying
+ * 1 deriv_type in explicit_stepper_base
+ */
+BOOST_AUTO_TEST_CASE( explicit_euler_assign )
{
+ reset_counter();
+ {
+ euler_type euler;
+ euler_type euler2;
+ euler2 = euler;
+ }
+ CHECK_COUNTERS( 0 , 2 , 0 , 2 , 0 , 1 );
}
+/*
+ * 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_construct )
+{
+ reset_counter();
+ {
+ rk4_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_copy_construct )
+{
+ reset_counter();
+ {
+ rk4_type rk4;
+ rk4_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_assign )
+{
+ reset_counter();
+ {
+ rk4_type rk4;
+ rk4_type rk4_2;
+ rk4 = rk4_2;
+ }
+ CHECK_COUNTERS( 2 , 8 , 2 , 8 , 1 , 4 );
+}
+
+/*
+ * Construct + Destruct
+ * 2 explicit_rk54_ck:
+ * 2 * 1 deriv_type in explicit_error_stepper_base
+ * 2 * 5 deriv_type in explicit_error_rk54_ck
+ * 2 * 1 state_type in explicit_error_rk4
+ * 1 controlled_stepper:
+ * 1 deriv_type
+ * 2 state_type
+ *
+ * Copying
+ * 1 copy process of explicit_rk54_ck:
+ * 1 deriv_type from explicit_error_stepper_base
+ * 5 deriv_type from explicit_error_rk54_ck
+ * 1 state_type from explicit_error_rk54_ck
+ */
+BOOST_AUTO_TEST_CASE( controlled_rk54_construct )
+{
+ reset_counter();
+ {
+ controlled_rk54_type stepper;
+ }
+ CHECK_COUNTERS( 4 , 13 , 4 , 13 , 1 , 6 );
+}
+
+
+/*
+ * Construct + Destruct
+ * 3 explicit_rk54_ck:
+ * 3 * 1 deriv_type in explicit_error_stepper_base
+ * 3 * 5 deriv_type in explicit_error_rk54_ck
+ * 3 * 1 state_type in explicit_error_rk4
+ * 2 controlled_stepper:
+ * 2 * 1 deriv_type
+ * 2 * 2 state_type
+ *
+ * Copying
+ * 1 copy process of explicit_rk54_ck:
+ * 1 deriv_type from explicit_error_stepper_base
+ * 5 deriv_type from explicit_error_rk54_ck
+ * 1 state_type from explicit_error_rk54_ck
+ *
+ * 1 process of copying controlled_error_stepper
+ * 1 deriv_type from explicit_error_stepper_base
+ * 5 deriv_type from explicit_error_rk54_ck
+ * 1 state_type from explicit_error_rk54_ck
+ * 1 deriv_type from controlled_error_stepper
+ * 2 state_type from controlled_error_stepper
+ */
+BOOST_AUTO_TEST_CASE( controlled_rk54_copy_construct )
+{
+ reset_counter();
+ {
+ controlled_rk54_type stepper;
+ controlled_rk54_type stepper2( stepper );
+ }
+ CHECK_COUNTERS( 7 , 20 , 7 , 20 , 4 , 13 );
+}
+
+/*
+ * Construct + Destruct
+ * 4 explicit_rk54_ck:
+ * 4 * 1 deriv_type in explicit_error_stepper_base
+ * 4 * 5 deriv_type in explicit_error_rk54_ck
+ * 4 * 1 state_type in explicit_error_rk4
+ * 2 controlled_stepper:
+ * 2 * 1 deriv_type
+ * 2 * 2 state_type
+ *
+ * Copying
+ * 2 copy process of explicit_rk54_ck:
+ * 2 * 1 deriv_type from explicit_error_stepper_base
+ * 2 * 5 deriv_type from explicit_error_rk54_ck
+ * 2 * 1 state_type from explicit_error_rk54_ck
+ *
+ * 1 process of copying controlled_error_stepper
+ * 1 deriv_type from explicit_error_stepper_base
+ * 5 deriv_type from explicit_error_rk54_ck
+ * 1 state_type from explicit_error_rk54_ck
+ * 1 deriv_type from controlled_error_stepper
+ * 2 state_type from controlled_error_stepper
+ */
+BOOST_AUTO_TEST_CASE( controlled_rk54_assign )
+{
+ reset_counter();
+ {
+ controlled_rk54_type stepper;
+ controlled_rk54_type stepper2;
+ stepper2 = stepper;
+ }
+ CHECK_COUNTERS( 8 , 26 , 8 , 26 , 5 , 19 );
+}
+
+
+BOOST_AUTO_TEST_CASE( controlled_dopri5_construct )
+{
+ reset_counter();
+ {
+ controlled_dopri5_type dopri5;
+ }
+ // CHECK_COUNTERS( 1 , 1 , 1 , 1 , 1 );
+}
+
+BOOST_AUTO_TEST_CASE( controlled_dopri5_copy_construct )
+{
+ reset_counter();
+ {
+ controlled_dopri5_type dopri5;
+ controlled_dopri5_type dopri5_2( dopri5 );
+ }
+ // CHECK_COUNTERS( 1 , 1 , 1 , 1 , 1 );
+}
+
+BOOST_AUTO_TEST_CASE( controlled_dopri5_assign )
+{
+ reset_counter();
+ {
+ controlled_dopri5_type dopri5;
+ controlled_dopri5_type dopri5_2;
+ dopri5_2 = dopri5;
+ }
+ // CHECK_COUNTERS( 1 , 1 , 1 , 1 , 1 );
+}
+
+BOOST_AUTO_TEST_CASE( dense_output_euler_construct )
+{
+ reset_counter();
+ {
+ dense_output_euler_type euler;
+ }
+ // CHECK_COUNTERS( 1 , 1 , 1 , 1 , 1 );
+}
+
+BOOST_AUTO_TEST_CASE( dense_output_euler_copy_construct )
+{
+ reset_counter();
+ {
+ dense_output_euler_type euler;
+ dense_output_euler_type euler2( euler );
+ }
+ // CHECK_COUNTERS( 1 , 1 , 1 , 1 , 1 );
+}
+
+BOOST_AUTO_TEST_CASE( dense_output_euler_assign )
+{
+ reset_counter();
+ {
+ dense_output_euler_type euler;
+ dense_output_euler_type euler2;
+ euler2 = euler;
+ }
+ // CHECK_COUNTERS( 1 , 1 , 1 , 1 , 1 );
+}
+
+BOOST_AUTO_TEST_CASE( dense_output_dopri5_construct )
+{
+ reset_counter();
+ {
+ dense_output_dopri5_type dopri5;
+ }
+ // CHECK_COUNTERS( 1 , 1 , 1 , 1 , 1 );
+}
+
+BOOST_AUTO_TEST_CASE( dense_output_dopri5_copy_construct )
+{
+ reset_counter();
+ {
+ dense_output_dopri5_type dopri5;
+ dense_output_dopri5_type dopri5_2( dopri5 );
+ }
+ // CHECK_COUNTERS( 1 , 1 , 1 , 1 , 1 );
+}
+
+BOOST_AUTO_TEST_CASE( dense_output_dopri5_assign )
+{
+ reset_counter();
+ {
+ dense_output_dopri5_type dopri5;
+ dense_output_dopri5_type dopri5_2;
+ dopri5_2 = dopri5;
+ }
+ // CHECK_COUNTERS( 1 , 1 , 1 , 1 , 1 );
+}
+
+
+
+
+
+
+
+
+
BOOST_AUTO_TEST_SUITE_END()
Added: sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_with_ranges.cpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/test/stepper_with_ranges.cpp 2011-01-30 06:40:02 EST (Sun, 30 Jan 2011)
@@ -0,0 +1,56 @@
+/*
+ * stepper_with_ranges.cpp
+ *
+ * Created on: Jan 30, 2011
+ * Author: karsten
+ */
+
+#define BOOST_TEST_MODULE odeint_stepper_with_ranges
+
+#include <boost/test/unit_test.hpp>
+
+#include <vector>
+#include <tr1/array>
+#include <utility>
+
+#include <boost/numeric/odeint/stepper/explicit_euler.hpp>
+
+typedef std::vector< double > state_type;
+typedef std::tr1::array< double , 3 > state_type2;
+
+struct lorenz
+{
+ template< class State , class Deriv >
+ void operator()( const State &x , Deriv &dxdt , double t )
+ {
+ const double sigma = 10.0;
+ const double R = 28.0;
+ const double b = 8.0 / 3.0;
+
+// dxdt[0] = sigma * ( x[1] - x[0] );
+// dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
+// dxdt[2] = x[0]*x[1] - b * x[2];
+ }
+};
+
+BOOST_AUTO_TEST_SUITE( stepper_with_ranges )
+
+BOOST_AUTO_TEST_CASE( explicit_euler_with_range )
+{
+ std::vector< double > x( 3 * 2 );
+ boost::numeric::odeint::explicit_euler< state_type > euler;
+ std::pair< std::vector< double >::iterator , std::vector< double >::iterator > r( x.begin() , x.begin() + 3 );
+ euler.do_step( lorenz() , r , 0.0 , 0.1 );
+ euler.do_step( lorenz() , std::make_pair( x.begin() + 3 , x.begin() + 6 ) , 0.1 , 0.1 );
+}
+
+BOOST_AUTO_TEST_CASE( explicit_euler_with_array )
+{
+ state_type2 x;
+ boost::numeric::odeint::explicit_euler< state_type > euler;
+ euler.do_step( lorenz() , x , 0.0 , 0.1 );
+ euler.do_step( lorenz() , x , 0.1 , 0.1 );
+}
+
+
+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