Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65691 - in sandbox/odeint/branches/karsten: boost/numeric boost/numeric/odeint/stepper boost/numeric/odeint/stepper/base libs/numeric/odeint/code_analyzer libs/numeric/odeint/test
From: karsten.ahnert_at_[hidden]
Date: 2010-09-30 06:12:16


Author: karsten
Date: 2010-09-30 06:12:12 EDT (Thu, 30 Sep 2010)
New Revision: 65691
URL: http://svn.boost.org/trac/boost/changeset/65691

Log:
* introducing the dense_output_explicit_euler stepper
* some minor changes in the stepper_base classes ( const correctness ... )
* introducing the check_dense_output_explicit_euler test
* introducing some source code analyzing tools, they are not finished yet
Added:
   sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/dense_output_explicit_euler.hpp (contents, props changed)
   sandbox/odeint/branches/karsten/libs/numeric/odeint/code_analyzer/
   sandbox/odeint/branches/karsten/libs/numeric/odeint/code_analyzer/check_includes.py (contents, props changed)
   sandbox/odeint/branches/karsten/libs/numeric/odeint/code_analyzer/make_header_defines.py (contents, props changed)
   sandbox/odeint/branches/karsten/libs/numeric/odeint/test/check_dense_output_explicit_euler.cpp (contents, props changed)
Text files modified:
   sandbox/odeint/branches/karsten/boost/numeric/odeint.hpp | 2 ++
   sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp | 4 ++--
   sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_euler.hpp | 4 ++++
   sandbox/odeint/branches/karsten/libs/numeric/odeint/test/Jamfile | 1 +
   sandbox/odeint/branches/karsten/libs/numeric/odeint/test/check_implicit_euler.cpp | 4 ++--
   5 files changed, 11 insertions(+), 4 deletions(-)

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint.hpp 2010-09-30 06:12:12 EDT (Thu, 30 Sep 2010)
@@ -25,4 +25,6 @@
 
 #include <boost/numeric/odeint/stepper/controlled_error_stepper.hpp>
 
+#include <boost/numeric/odeint/stepper/dense_output_explicit_euler.hpp>
+
 #endif // BOOST_NUMERIC_ODEINT_HPP

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp 2010-09-30 06:12:12 EDT (Thu, 30 Sep 2010)
@@ -88,7 +88,7 @@
         }
 
         template< class System >
- void do_step( System &system , const state_type &in , time_type t , const state_type &out , const time_type dt )
+ void do_step( System &system , const state_type &in , const time_type t , state_type &out , const time_type dt )
         {
                 m_size_adjuster.adjust_size_by_policy( in , adjust_size_policy() );
                 system( in , m_dxdt ,t );
@@ -108,7 +108,7 @@
         }
 
 
-private:
+protected:
 
         size_adjuster< state_type , 1 > m_size_adjuster;
         state_type m_dxdt;

Added: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/dense_output_explicit_euler.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/dense_output_explicit_euler.hpp 2010-09-30 06:12:12 EDT (Thu, 30 Sep 2010)
@@ -0,0 +1,107 @@
+/*
+ boost header: numeric/odeint/dense_output_explicit_euler.hpp
+
+ Copyright 2009 Karsten Ahnert
+ Copyright 2009 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)
+*/
+
+#ifndef BOOST_NUMERIC_ODEINT_DENSE_OUTPUT_EXPLICIT_EULER_HPP_INCLUDED
+#define BOOST_NUMERIC_ODEINT_DENSE_OUTPUT_EXPLICIT_EULER_HPP_INCLUDED
+
+#include <utility>
+
+#include <boost/numeric/odeint/stepper/explicit_euler.hpp>
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+template<
+ class State ,
+ class Time = double ,
+ class Algebra = standard_algebra< State > ,
+ class Operations = standard_operations< Time > ,
+ class AdjustSizePolicy = adjust_size_initially_tag
+ >
+class dense_output_explicit_euler
+{
+public:
+
+ typedef State state_type;
+ typedef Time time_type;
+ typedef Algebra algebra_type;
+ typedef Operations operations_type;
+ typedef AdjustSizePolicy adjust_size_policy;
+ typedef explicit_euler< state_type , time_type , algebra_type , operations_type , adjust_size_policy > stepper_type;
+
+ dense_output_explicit_euler( void )
+ : m_euler() , m_size_adjuster() ,
+ m_x1() , m_x2() , m_current_state( &m_x1 ) , m_old_state( &m_x2 ) ,
+ m_t( 0.0 ) , m_t_old( 0.0 ) , m_dt( 1.0 )
+ {
+ boost::numeric::odeint::construct( m_x1 );
+ boost::numeric::odeint::construct( m_x2 );
+ m_size_adjuster.register_state( 0 , m_x1 );
+ m_size_adjuster.register_state( 1 , m_x2 );
+ }
+
+ ~dense_output_explicit_euler( void )
+ {
+ boost::numeric::odeint::destruct( m_x1 );
+ boost::numeric::odeint::destruct( m_x2 );
+ }
+
+ void adjust_size( const state_type &x )
+ {
+ m_size_adjuster.adjust_size( x );
+ m_euler.adjust_size( x );
+ }
+
+ void initialize( const state_type x0 , const time_type t0 , const time_type dt0 )
+ {
+ boost::numeric::odeint::copy( x0 , *m_current_state );
+ m_t = t0;
+ m_dt = dt0;
+ }
+
+ template< class System >
+ std::pair< time_type , time_type > do_step( System &system )
+ {
+ m_euler.do_step( system , *m_current_state , m_t , *m_old_state , m_dt );
+ m_t_old = m_t;
+ m_t += m_dt;
+ std::swap( m_current_state , m_old_state );
+ return std::make_pair( m_t_old , m_dt );
+ }
+
+ void calc_state( time_type t , state_type &x )
+ {
+ time_type delta = t - m_t_old;
+ algebra_type::for_each3( x , *m_old_state , m_euler.m_dxdt , typename operations_type::scale_sum2( 1.0 , delta ) );
+ }
+
+ const state_type& current_state( void ) const { return *m_current_state; }
+ const time_type& current_time( void ) const { return m_t; }
+ const time_type& previous_state( void ) const { return *m_old_state; }
+ const time_type& previous_time( void ) const { return m_t_old; }
+
+private:
+
+ stepper_type m_euler;
+ size_adjuster< state_type , 2 > m_size_adjuster;
+ state_type m_x1 , m_x2;
+ state_type *m_current_state , *m_old_state;
+ time_type m_t , m_t_old , m_dt;
+};
+
+
+} // namespace odeint
+} // namespace numeric
+} // namespace boost
+
+
+#endif //BOOST_NUMERIC_ODEINT_DENSE_OUTPUT_EXPLICIT_EULER_HPP_INCLUDED

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_euler.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_euler.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_euler.hpp 2010-09-30 06:12:12 EDT (Thu, 30 Sep 2010)
@@ -23,6 +23,8 @@
 namespace numeric {
 namespace odeint {
 
+template< class State , class Time , class Algebra , class Operations , class AdjustSizePolicy >
+class dense_output_explicit_euler;
 
 template<
     class State ,
@@ -38,6 +40,8 @@
 {
 public :
 
+ friend class dense_output_explicit_euler< State , Time , Algebra , Operations , AdjustSizePolicy >;
+
         BOOST_ODEINT_EXPLICIT_STEPPERS_TYPEDEFS( explicit_euler , 1 );
 
         template< class System >

Added: sandbox/odeint/branches/karsten/libs/numeric/odeint/code_analyzer/check_includes.py
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/code_analyzer/check_includes.py 2010-09-30 06:12:12 EDT (Thu, 30 Sep 2010)
@@ -0,0 +1,48 @@
+#! /usr/bin/python
+
+import os
+import glob
+import subprocess
+
+
+topleveldir = "../../../"
+
+filename = []
+filename += glob.glob( topleveldir + "boost/numeric/odeint/*.hpp" )
+filename += glob.glob( topleveldir + "boost/numeric/odeint/algebra/*.hpp" )
+filename += glob.glob( topleveldir + "boost/numeric/odeint/algebra/detail/*.hpp" )
+filename += glob.glob( topleveldir + "boost/numeric/odeint/algebra/external/*.hpp" )
+filename += glob.glob( topleveldir + "boost/numeric/odeint/stepper/*.hpp" )
+filename += glob.glob( topleveldir + "boost/numeric/odeint/stepper/base/*.hpp" )
+filename += glob.glob( topleveldir + "boost/numeric/odeint/stepper/detail/*.hpp" )
+
+
+test_prog = '#include <INCLUDE>\n\
+\n\
+int main( void )\n\
+{\n\
+ return 0;\n\
+}\n\
+'
+
+count = 0
+for fn in filename :
+ fn = fn[len(topleveldir) : ]
+ prog = test_prog.replace( "INCLUDE" , fn )
+
+ file = open( "test.cc" , "w" )
+ file.write( prog )
+ file.close
+
+ cmd = ["g++" , "-I"+topleveldir , "-I$BOOST_ROOT" , "-c" , "test.cc" ]
+
+ print "Test " + fn + " : "
+# print prog
+ print "Commandline : " + subprocess.list2cmdline( cmd )
+
+ p = subprocess.Popen( subprocess.list2cmdline( cmd ) , shell=True)
+ sts = os.waitpid(p.pid, 0)[1]
+
+ print sts
+ print ""
+

Added: sandbox/odeint/branches/karsten/libs/numeric/odeint/code_analyzer/make_header_defines.py
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/code_analyzer/make_header_defines.py 2010-09-30 06:12:12 EDT (Thu, 30 Sep 2010)
@@ -0,0 +1,67 @@
+#! /usr/bin/python
+
+import os
+import glob
+
+initial_comment = '/* FILENAME header file\n\
+\n\
+ Copyright 2010 Karsten Ahnert\n\
+ Copyright 2010 Mario Mulansky\n\
+\n\
+ Distributed under the Boost Software License, Version 1.0.\n\
+ (See accompanying file LICENSE_1_0.txt or\n\
+ copy at http://www.boost.org/LICENSE_1_0.txt)\n\
+*/\n\
+\n\
+\n\
+\n\
+'
+print initial_comment
+
+
+topleveldir = "../../../"
+
+filenames = []
+filenames += glob.glob( topleveldir + "boost/numeric/odeint/*.hpp" )
+filenames += glob.glob( topleveldir + "boost/numeric/odeint/algebra/*.hpp" )
+filenames += glob.glob( topleveldir + "boost/numeric/odeint/algebra/detail/*.hpp" )
+filenames += glob.glob( topleveldir + "boost/numeric/odeint/algebra/external/*.hpp" )
+filenames += glob.glob( topleveldir + "boost/numeric/odeint/stepper/*.hpp" )
+filenames += glob.glob( topleveldir + "boost/numeric/odeint/stepper/base/*.hpp" )
+filenames += glob.glob( topleveldir + "boost/numeric/odeint/stepper/detail/*.hpp" )
+
+
+to_find = [ "#include" , "namespace" , "#ifndef" ]
+
+def find_first_of( str , to_find ) :
+ indices = []
+ for sub in to_find :
+ indices.append( str.find( sub ) )
+ while( indices.count( -1 ) > 0 ):
+ indices.remove( -1 )
+ if( len( indices ) == 0 ):
+ return -1
+ min_index = min( indices )
+ return min_index
+
+for fn in filenames :
+ content = open( fn ).read()
+ start = find_first_of( content , to_find )
+
+ if( start == -1 ) :
+ print "Nothing to replace found in " + fn
+ continue
+
+ if( start == 0 ):
+ print "In " + fn + " nothing to replace was found!"
+ else :
+ print "In " + fn + " the following string was found to be replaced : "
+ print content[0:start]
+ answer = raw_input( "Should this part be replaced with the Copyright comment? " )
+ print answer , answer.lower()
+ if( ( answer.lower() == "yes" ) or ( answer.lower() == "y" ) ):
+ print content.replace( content[0:start] , initial_comment.replace( "FILENAME" , fn[len(topleveldir):] ) )
+ print ""
+
+
+

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 2010-09-30 06:12:12 EDT (Thu, 30 Sep 2010)
@@ -28,6 +28,7 @@
         : check_stepper_concepts.cpp
           check_resize.cpp
           check_implicit_euler.cpp
+ check_dense_output_explicit_euler.cpp
         :
         : <link>static
         ;

Added: sandbox/odeint/branches/karsten/libs/numeric/odeint/test/check_dense_output_explicit_euler.cpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/test/check_dense_output_explicit_euler.cpp 2010-09-30 06:12:12 EDT (Thu, 30 Sep 2010)
@@ -0,0 +1,85 @@
+/* Boost check_implicit_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 <tr1/array>
+#include <fstream>
+#include <iostream>
+
+#include <boost/test/unit_test.hpp>
+
+#include <boost/numeric/odeint.hpp>
+#include <boost/numeric/odeint/stepper/implicit_euler.hpp>
+
+using namespace boost::unit_test;
+using namespace boost::numeric::odeint;
+
+typedef double value_type;
+typedef std::tr1::array< double , 2 > state_type;
+
+std::ostream& operator<<( std::ostream &out , const state_type &x )
+{
+ out << x[0] << "\t" << x[1];
+ return out;
+}
+
+void sys( const state_type &x , state_type &dxdt , const value_type t )
+{
+ dxdt[0] = x[1];
+ dxdt[1] = -x[0];
+}
+
+
+BOOST_AUTO_TEST_SUITE( dense_output_explicit_euler_test )
+
+BOOST_AUTO_TEST_CASE( test_euler )
+{
+ using std::abs;
+
+ dense_output_explicit_euler< state_type > stepper;
+ state_type x0;
+ x0[0] = 0.0;
+ x0[1] = 1.0;
+
+ stepper.initialize( x0 , 0.0 , 0.1 );
+// stepper.do_step( sys );
+
+ std::ofstream stepper_out( "stepper_states.dat" );
+ std::ofstream states_out( "states.dat" );
+
+
+ double t = stepper.current_time();
+ double t_end = 10.0;
+ double dt = 0.02;
+ state_type x;
+ while( t < t_end )
+ {
+ if( t < stepper.current_time() )
+ {
+ stepper.calc_state( t , x );
+ states_out << t << "\t" << x << std::endl;
+ }
+ else
+ {
+ stepper.do_step( sys );
+ stepper_out << stepper.current_time() << "\t" << stepper.current_state() << std::endl;
+ continue;
+ }
+ t += dt;
+ }
+
+// // compare with analytic solution of above system
+// BOOST_CHECK_MESSAGE( abs( x(0) - 20.0/81.0 ) < eps , x(0) - 20.0/81.0 );
+// BOOST_CHECK_MESSAGE( abs( x(1) - 10.0/9.0 ) < eps , x(0) - 10.0/9.0 );
+
+}
+
+BOOST_AUTO_TEST_SUITE_END()

Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/test/check_implicit_euler.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/test/check_implicit_euler.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/test/check_implicit_euler.cpp 2010-09-30 06:12:12 EDT (Thu, 30 Sep 2010)
@@ -27,13 +27,13 @@
 typedef boost::numeric::ublas::matrix< value_type > matrix_type;
 
 
-void sys( state_type &x , state_type &dxdt , const value_type t )
+void sys( const state_type &x , state_type &dxdt , const value_type t )
 {
     dxdt( 0 ) = x( 0 ) + 2 * x( 1 );
     dxdt( 1 ) = x( 1 );
 }
 
-void jacobi( state_type &x , matrix_type &jacobi , const value_type t )
+void jacobi( const state_type &x , matrix_type &jacobi , const value_type t )
 {
     jacobi( 0 , 0 ) = 1;
     jacobi( 0 , 1 ) = 2;


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