Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72743 - in sandbox/odeint/branches/karsten: boost/numeric/odeint/external/gsl libs/numeric/odeint/test_external/gsl
From: mario.mulansky_at_[hidden]
Date: 2011-06-24 10:53:48


Author: mariomulansky
Date: 2011-06-24 10:53:47 EDT (Fri, 24 Jun 2011)
New Revision: 72743
URL: http://svn.boost.org/trac/boost/changeset/72743

Log:
added test case for gsl_vector
Text files modified:
   sandbox/odeint/branches/karsten/boost/numeric/odeint/external/gsl/gsl_vector_adaptor.hpp | 107 ++++++++++++++++++++-------------------
   sandbox/odeint/branches/karsten/libs/numeric/odeint/test_external/gsl/check_gsl.cpp | 27 ++++++++++
   2 files changed, 83 insertions(+), 51 deletions(-)

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/external/gsl/gsl_vector_adaptor.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/external/gsl/gsl_vector_adaptor.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/external/gsl/gsl_vector_adaptor.hpp 2011-06-24 10:53:47 EDT (Fri, 24 Jun 2011)
@@ -25,7 +25,6 @@
 #include <boost/numeric/odeint/util/destruct.hpp>
 #include <boost/numeric/odeint/util/copy.hpp>
 #include <boost/numeric/odeint/util/resize.hpp>
-#include <boost/numeric/odeint/util/default_adjust_size.hpp>
 
 using namespace std;
 
@@ -175,73 +174,79 @@
 };
 
 template<>
-void construct( gsl_vector &x )
+struct construct_impl< gsl_vector >
 {
- x.owner = 0;
- x.size = 0;
- x.stride = 0;
- x.block = 0;
- x.data = 0;
-}
+ static void construct( gsl_vector &x )
+ {
+ x.owner = 0;
+ x.size = 0;
+ x.stride = 0;
+ x.block = 0;
+ x.data = 0;
+ }
+};
 
 template<>
-void destruct( gsl_vector &x )
+struct destruct_impl< gsl_vector >
 {
- if( x.owner != 0 )
- {
- gsl_block_free( x.block );
- }
- x.owner = 0;
- x.size = 0;
- x.stride = 0;
- x.block = 0;
- x.data = 0;
-}
+ static void destruct( gsl_vector &x )
+ {
+ if( x.owner != 0 )
+ {
+ gsl_block_free( x.block );
+ }
+ x.owner = 0;
+ x.size = 0;
+ x.stride = 0;
+ x.block = 0;
+ x.data = 0;
+ }
+};
 
 
 template<>
-void resize( const gsl_vector &x , gsl_vector &dxdt )
+struct resize_impl< gsl_vector , gsl_vector >
 {
- if( dxdt.owner != 0 )
- {
- gsl_block_free( dxdt.block );
- }
- dxdt.size = 0;
-
- if( x.size == 0 ) return;
-
- gsl_block *block = gsl_block_alloc( x.size );
- if( block == 0 ) throw std::bad_alloc( );
-
- dxdt.data = block->data ;
- dxdt.size = x.size;
- dxdt.stride = 1;
- dxdt.block = block;
- dxdt.owner = 1;
-}
+ static void resize( const gsl_vector &x , gsl_vector &dxdt )
+ {
+ if( dxdt.owner != 0 )
+ {
+ gsl_block_free( dxdt.block );
+ }
+ dxdt.size = 0;
+
+ if( x.size == 0 ) return;
+
+ gsl_block *block = gsl_block_alloc( x.size );
+ if( block == 0 ) throw std::bad_alloc( );
+
+ dxdt.data = block->data ;
+ dxdt.size = x.size;
+ dxdt.stride = 1;
+ dxdt.block = block;
+ dxdt.owner = 1;
+ }
+};
 
 template<>
-bool same_size( const gsl_vector &x1 , const gsl_vector &x2 )
+struct same_size_impl< gsl_vector , gsl_vector >
 {
- return x1.size == x2.size;
-}
-
-struct default_adjust_size {
-
- template<>
- void adjust_size( const gsl_vector &x1 , gsl_vector &x2 )
+ static bool same_size( const gsl_vector &x1 , const gsl_vector &x2 )
     {
- if( !same_size( x1 , x2 ) ) resize( x1 , x2 );
+ return x1.size == x2.size;
     }
 };
 
+
 template<>
-void copy( const gsl_vector &from , gsl_vector &to )
+struct copy_impl< gsl_vector , gsl_vector >
 {
- adjust_size( from , to );
- gsl_vector_memcpy( &to , &from );
-}
-
+ static void copy( const gsl_vector &from , gsl_vector &to )
+ {
+ resize( from , to );
+ gsl_vector_memcpy( &to , &from );
+ }
+};
 
 } // odeint
 } // numeric

Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/test_external/gsl/check_gsl.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/test_external/gsl/check_gsl.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/test_external/gsl/check_gsl.cpp 2011-06-24 10:53:47 EDT (Fri, 24 Jun 2011)
@@ -13,13 +13,40 @@
 #define BOOST_TEST_MODULE odeint_gsl
 
 #include <gsl/gsl_vector.h>
+#include <boost/numeric/odeint/stepper/explicit_euler.hpp>
+#include <boost/numeric/odeint/external/gsl/gsl_vector_adaptor.hpp>
 
 #include <boost/test/unit_test.hpp>
 
 using namespace boost::unit_test;
+using namespace boost::numeric::odeint;
 
+typedef gsl_vector state_type;
 
+const double sigma = 10.0;
+const double R = 28.0;
+const double b = 8.0 / 3.0;
+
+void lorenz( const state_type &x , state_type &dxdt , double t )
+{
+ gsl_vector_set( &dxdt , 0 , sigma * ( gsl_vector_get(&x , 1 ) - gsl_vector_get( &x , 0 ) ) );
+ gsl_vector_set( &dxdt , 1 , R * gsl_vector_get( &x , 0 ) - gsl_vector_get( &x , 1 ) - gsl_vector_get( &x , 0 ) * gsl_vector_get( &x , 2) );
+ gsl_vector_set( &dxdt , 2 , gsl_vector_get( &x , 0 ) * gsl_vector_get( &x , 1 ) - b * gsl_vector_get( &x , 2) );
+}
 
 BOOST_AUTO_TEST_CASE( gsl )
 {
+ explicit_euler< state_type > euler;
+
+ state_type *x = gsl_vector_alloc( 3 );
+ gsl_vector_set( x , 0 , 1.0);
+ gsl_vector_set( x , 1 , 1.0);
+ gsl_vector_set( x , 2 , 2.0);
+
+ euler.do_step( lorenz , *x , 0.0 , 0.1 );
+
+ //cout << gsl_vector_get( x , 0 ) << " " << gsl_vector_get( x , 1 ) << " " << gsl_vector_get( x , 2 ) << endl;
+
+ gsl_vector_free( x );
+
 }


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