|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60131 - in sandbox/odeint: . boost/numeric/odeint libs/numeric/odeint/test
From: karsten.ahnert_at_[hidden]
Date: 2010-03-03 16:23:31
Author: karsten
Date: 2010-03-03 16:23:30 EST (Wed, 03 Mar 2010)
New Revision: 60131
URL: http://svn.boost.org/trac/boost/changeset/60131
Log:
added unit test and started changeing the adjust size behavious
Added:
sandbox/odeint/libs/numeric/odeint/test/
sandbox/odeint/libs/numeric/odeint/test/Jamfile (contents, props changed)
sandbox/odeint/libs/numeric/odeint/test/check_stepper_concepts.cpp (contents, props changed)
Text files modified:
sandbox/odeint/Jamroot | 1
sandbox/odeint/ToDo | 15 ++++++
sandbox/odeint/boost/numeric/odeint/stepper_euler.hpp | 43 ++++++++++++++++++--
sandbox/odeint/boost/numeric/odeint/stepper_half_step.hpp | 82 ++++++++++++++++++++++++++++-----------
sandbox/odeint/boost/numeric/odeint/stepper_midpoint.hpp | 6 +
5 files changed, 114 insertions(+), 33 deletions(-)
Modified: sandbox/odeint/Jamroot
==============================================================================
--- sandbox/odeint/Jamroot (original)
+++ sandbox/odeint/Jamroot 2010-03-03 16:23:30 EST (Wed, 03 Mar 2010)
@@ -12,6 +12,7 @@
<include>$BOOST_ROOT ;
build-project libs/numeric/odeint/examples ;
+build-project libs/numeric/odeint/test ;
# build-project libs/numeric/odeint/doc ;
Modified: sandbox/odeint/ToDo
==============================================================================
--- sandbox/odeint/ToDo (original)
+++ sandbox/odeint/ToDo 2010-03-03 16:23:30 EST (Wed, 03 Mar 2010)
@@ -10,11 +10,22 @@
* In all steppers:
* const unsigned short -> short - DONE
* typedef typename traits_type::container_type container_type statt typedef Container container_type - DONE
-* in iterator algebra die funktionen welche maximas suchen durch die entsprechenden boost funktionen ersetzen - it not possible , DONE
+* Concept checks, für vernünftige Fehlermeldungen
+ * auch für checks ob abs() vorhanden ist
* check in all steppers the order
* rk78 die fehler implementieren
* references entfernen
+* check: orders and adjust_size() in :
+ * stepper_euler.hpp - DONE
+ * stepper_half_step.hpp - DONE
+ * stepper_midpoint.hpp
+ * stepper_rk4_classical.hpp
+ * stepper_rk4.hpp
+ * stepper_rk5_ck.hpp
+ * stepper_rk78_fehlberg.hpp
+ * stepper_rk_generic.hpp
+
Mario:
@@ -59,7 +70,7 @@
= Unit testing =
Karsten:
-* aufsetzen des Frameworks
+* aufsetzen des Frameworks - DONE
Modified: sandbox/odeint/boost/numeric/odeint/stepper_euler.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/stepper_euler.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint/stepper_euler.hpp 2010-03-03 16:23:30 EST (Wed, 03 Mar 2010)
@@ -35,8 +35,9 @@
>
class stepper_euler
{
-
+ //
// provide basic typedefs
+ //
public:
typedef unsigned short order_type;
@@ -48,19 +49,48 @@
typedef typename traits_type::const_iterator const_iterator;
-
+ //
// private members
+ //
private:
container_type m_dxdt;
+ //
// public interface
+ //
public:
- order_type order() const { return 1; }
+ // return the order of the stepper
+ order_type order_step() const { return 1; }
+
+
+ // standard constructor, m_dxdt is not adjusted
+ stepper_euler( void )
+ {
+ }
+
+
+
+ // contructor, which adjusts m_dxdt
+ stepper_euler( const container_type &x )
+ {
+ adjust_size( x );
+ }
+
+
+ // adjust the size of m_dxdt
+ void adjust_size( const container_type &x )
+ {
+ traits_type::adjust_size( x , m_dxdt );
+ }
+
+
+
+ // performs one step with the knowledge of dxdt(t)
template< class DynamicalSystem >
void do_step( DynamicalSystem &system ,
container_type &x ,
@@ -68,23 +98,26 @@
time_type t ,
time_type dt )
{
- //x = x + dt*dxdt
+ // x = x + dt*dxdt
detail::it_algebra::increment( traits_type::begin(x) ,
traits_type::end(x) ,
traits_type::begin(dxdt) ,
dt );
}
+
+
+ // performs one step
template< class DynamicalSystem >
void do_step( DynamicalSystem &system ,
container_type &x ,
time_type t ,
time_type dt )
{
- traits_type::adjust_size( x , m_dxdt );
system( x , m_dxdt , t );
do_step( system , x , m_dxdt , t , dt );
}
+
};
Modified: sandbox/odeint/boost/numeric/odeint/stepper_half_step.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/stepper_half_step.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint/stepper_half_step.hpp 2010-03-03 16:23:30 EST (Wed, 03 Mar 2010)
@@ -28,7 +28,9 @@
template< class Stepper >
class stepper_half_step
{
+ //
// provide basic typedefs
+ //
public:
typedef Stepper stepper_type;
@@ -42,8 +44,9 @@
-
+ //
// private members
+ //
private:
container_type m_dxdt;
@@ -51,42 +54,78 @@
stepper_type m_stepper;
+ //
// public interface
+ //
public:
- order_type order() const
+
+ // standard constructor
+ stepper_half_step( void )
+ {
+ }
+
+ // contructor, which adjust the size of internal containers
+ stepper_half_step( const container_type &x )
+ {
+ adjust_size( x );
+ }
+
+ // adjust the size of m_dxdt , m_xtemp und m_stepper
+ void adjust_size( const container_type &x )
+ {
+ m_stepper.adjust_size( x );
+ traits_type::adjust_size( x , m_dxdt );
+ traits_type::adjust_size( x , m_xtemp );
+ }
+
+ // the order of the step if a normal step is performed
+ order_type order_step( void ) const
+ {
+
+ return m_stepper.order_step();
+ }
+
+ // the order of the step if an error step is performed
+ order_type order_error_step( void ) const
{
- /* */
- return m_stepper.order();
+
+ return m_stepper.order_step();
}
- order_type order_error() const
+ // the order of the error term if the error step is performed
+ order_type order_error( void ) const
{
- /* Order of the error term is the order of the underlying stepper + 1 */
- return m_stepper.order() + 1;
+
+ return m_stepper.order_step() + 1;
}
+
+ // performs a normal step, without error calculation
template< class DynamicalSystem >
void do_step( DynamicalSystem &system ,
- container_type &x ,
- container_type &dxdt ,
- time_type t ,
- time_type dt )
+ container_type &x ,
+ const container_type &dxdt ,
+ time_type t ,
+ time_type dt )
{
m_stepper.do_step( system , x , dxdt , t , dt );
}
-
+ // performs a normal step, without error calculation
template< class DynamicalSystem >
void do_step( DynamicalSystem &system ,
- container_type &x ,
- time_type t ,
- time_type dt )
+ container_type &x ,
+ time_type t ,
+ time_type dt )
{
m_stepper.do_step( system , x , t , dt );
}
+
+
+ // performs a error step with error calculation
template< class DynamicalSystem >
void do_step( DynamicalSystem &system ,
container_type &x ,
@@ -95,16 +134,10 @@
time_type dt ,
container_type &xerr )
{
- traits_type::adjust_size( x , xerr );
-
- /*** BUG FOR BLITZ ARRAYS ***/
- /* for blitzz arrays, the copy constructor creates a REFERENCE and not a copy!!! */
- traits_type::adjust_size( x , m_xtemp );
- m_xtemp = container_type(x);
- /*** END BUG ***/
-
time_type dt2 = static_cast<time_type>(0.5) * dt;
+ m_xtemp = x;
+
do_step( system , m_xtemp , dxdt , t , dt );
do_step( system , x , dxdt , t , dt2 );
do_step( system , x , t+dt2 , dt2 );
@@ -119,6 +152,8 @@
+
+ // performs a error step with error calculation
template< class DynamicalSystem >
void do_step( DynamicalSystem &system ,
container_type &x ,
@@ -126,7 +161,6 @@
time_type dt ,
container_type &xerr )
{
- traits_type::adjust_size( x , m_dxdt );
system( x , m_dxdt , t );
do_step( system , x , m_dxdt , t , dt , xerr );
}
Modified: sandbox/odeint/boost/numeric/odeint/stepper_midpoint.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/stepper_midpoint.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint/stepper_midpoint.hpp 2010-03-03 16:23:30 EST (Wed, 03 Mar 2010)
@@ -34,7 +34,9 @@
>
class stepper_midpoint
{
+ //
// provide basic typedefs
+ //
public:
typedef unsigned short order_type;
@@ -90,8 +92,8 @@
const time_type t_1 = static_cast<time_type>( 1.0 );
const time_type t_05 = static_cast<time_type>( 0.5 );
- const time_type h = dt/static_cast<time_type>( m_stepcount );
- const time_type h2 = static_cast<time_type>( 2.0 )*h;
+ const time_type h = dt / static_cast<time_type>( m_stepcount );
+ const time_type h2 = static_cast<time_type>( 2.0 ) * h;
time_type th = t + h;
traits_type::adjust_size(x, m_x0);
Added: sandbox/odeint/libs/numeric/odeint/test/Jamfile
==============================================================================
--- (empty file)
+++ sandbox/odeint/libs/numeric/odeint/test/Jamfile 2010-03-03 16:23:30 EST (Wed, 03 Mar 2010)
@@ -0,0 +1,18 @@
+# (C) Copyright 2010 : Karsten Ahnert, Mario Mulansky
+# Distributed under 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)
+
+# bring in rules for testing
+import testing ;
+
+project
+ : requirements
+ <library>/boost/test//boost_unit_test_framework
+ <link>static
+ <include>../../../..
+ <include>$BOOST_ROOT
+ ;
+
+test-suite "odeint"
+ : [ run check_stepper_concepts.cpp ]
+ ;
Added: sandbox/odeint/libs/numeric/odeint/test/check_stepper_concepts.cpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/libs/numeric/odeint/test/check_stepper_concepts.cpp 2010-03-03 16:23:30 EST (Wed, 03 Mar 2010)
@@ -0,0 +1,133 @@
+/* Boost stepper_euler.cpp test file
+
+ Copyright 2009 Karsten Ahnert
+ Copyright 2009 Mario Mulansky
+
+ This file tests the use of the euler stepper
+
+ Distributed under 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)
+*/
+
+#include <vector>
+#include <tr1/array>
+
+#include <boost/test/unit_test.hpp>
+
+#include <boost/numeric/odeint/stepper_euler.hpp>
+#include <boost/numeric/odeint/stepper_half_step.hpp>
+
+using namespace boost::unit_test;
+using namespace boost::numeric::odeint;
+
+
+
+
+template< class Container >
+struct constant_system
+{
+ void operator()( const Container &x , Container &dxdt , double t )
+ {
+ dxdt[0] = 1.0;
+ }
+};
+
+
+
+template< class Stepper >
+void check_stepper_concept( Stepper &stepper ,
+ typename Stepper::order_type order_step )
+{
+ typedef Stepper stepper_type;
+ typedef typename stepper_type::container_type container_type;
+ typedef typename stepper_type::traits_type traits_type;
+ typedef typename stepper_type::value_type value_type;
+ typedef typename stepper_type::order_type order_type;
+ typedef typename stepper_type::time_type time_type;
+
+ constant_system< container_type > con;
+
+ BOOST_CHECK_EQUAL( order_step , stepper.order_step() );
+
+ container_type x( 1 , 0.0 ) ;
+ stepper.adjust_size( x );
+ stepper.do_step( con , x , 0.0 , 0.1 );
+ BOOST_CHECK_CLOSE( x[0] , 0.1 , 1.0e-14 );
+
+ container_type dxdt( 1 , 1.0 );
+ stepper.do_step( con , x , dxdt , 0.0 , 0.1 );
+ BOOST_CHECK_CLOSE( x[0] , 0.2 , 1.0e-14 );
+
+ stepper_type stepper2( x );
+ stepper_type stepper3;
+}
+
+
+
+
+template< class ErrorStepper >
+void check_error_stepper_concept(
+ ErrorStepper &stepper ,
+ typename ErrorStepper::order_type order_error_step ,
+ typename ErrorStepper::order_type order_error )
+{
+ typedef ErrorStepper stepper_type;
+ typedef typename stepper_type::container_type container_type;
+ typedef typename stepper_type::traits_type traits_type;
+ typedef typename stepper_type::value_type value_type;
+ typedef typename stepper_type::order_type order_type;
+ typedef typename stepper_type::time_type time_type;
+
+ constant_system< container_type > con;
+
+ BOOST_CHECK_EQUAL( order_error_step , stepper.order_error_step() );
+ BOOST_CHECK_EQUAL( order_error , stepper.order_error() );
+
+ container_type x( 1 , 0.0 ) , xerr( 1 , 0.0 );
+ stepper.adjust_size( x );
+
+ stepper.do_step( con , x , 0.0 , 0.1 , xerr );
+ BOOST_CHECK_CLOSE( x[0] , 0.1 , 1.0e-14 );
+ BOOST_CHECK_CLOSE( xerr[0] , 0.0 , 1.0e-14 );
+
+ container_type dxdt( 1 , 1.0 );
+ stepper.do_step( con , x , dxdt , 0.0 , 0.1 , xerr );
+ BOOST_CHECK_CLOSE( x[0] , 0.2 , 1.0e-14 );
+ BOOST_CHECK_CLOSE( xerr[0] , 0.0 , 1.0e-14 );
+
+ stepper_type stepper2( x );
+ stepper_type stepper3;
+}
+
+
+
+
+
+void test_euler_concept()
+{
+ stepper_euler< std::vector<double> > stepper;
+ check_stepper_concept( stepper , 1 );
+}
+
+
+
+void test_half_step_euler_concept()
+{
+ stepper_half_step< stepper_euler< std::vector< double > > > stepper;
+ check_stepper_concept( stepper , 1 );
+ check_error_stepper_concept( stepper , 1 , 2 );
+}
+
+
+
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("check stepper concepts");
+
+ test->add( BOOST_TEST_CASE( &test_euler_concept ) );
+ test->add( BOOST_TEST_CASE( &test_half_step_euler_concept ) );
+
+ return test;
+}
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