$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r57310 - in sandbox/odeint: boost/numeric/odeint libs/numeric/odeint/examples
From: karsten.ahnert_at_[hidden]
Date: 2009-11-03 10:11:16
Author: karsten
Date: 2009-11-03 10:11:15 EST (Tue, 03 Nov 2009)
New Revision: 57310
URL: http://svn.boost.org/trac/boost/changeset/57310
Log:
small changes
Text files modified: 
   sandbox/odeint/boost/numeric/odeint/euler.hpp                                  |   100 +++++++++++++++++++++++++-------------- 
   sandbox/odeint/boost/numeric/odeint/integrator_constant_step.hpp               |    19 +++++--                                 
   sandbox/odeint/boost/numeric/odeint/resizer.hpp                                |    33 +++++++++----                           
   sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrate_constant_step.cpp |    24 ++++++++                                
   4 files changed, 122 insertions(+), 54 deletions(-)
Modified: sandbox/odeint/boost/numeric/odeint/euler.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/euler.hpp	(original)
+++ sandbox/odeint/boost/numeric/odeint/euler.hpp	2009-11-03 10:11:15 EST (Tue, 03 Nov 2009)
@@ -30,80 +30,106 @@
 namespace odeint {
 
     template<
-	class ContainerType ,
-	class ResizeType = resizer< ContainerType >
+	class Container ,
+	class Time = double ,
+	class Resizer = resizer< Container >
 	>
     class ode_step_euler
     {
-	// check the concept of the ContainerType
-        BOOST_CLASS_REQUIRE( ContainerType , boost::numeric::odeint, StateType );
 
-        ContainerType m_dxdt;
-	ContainerType m_xtemp;
-        ResizeType m_resizer;
 
+	// provide basic typedefs
     public:
 
-
-	// provide ContainerType, ResizeType, iterator and value_type to users of this class
-	typedef ContainerType container_type;
-	typedef ResizeType resize_type;
-        typedef typename container_type::iterator iterator;
+	typedef Container container_type;
+	typedef Resizer resizer_type;
+	typedef Time time_type;
         typedef typename container_type::value_type value_type;
+        typedef typename container_type::iterator iterator;
+
+
+
+
+	// check the concept of the ContainerType
+    private:
+
+        BOOST_CLASS_REQUIRE( container_type , boost::numeric::odeint, StateType );
+
+
+
+
+	// private members
+    private:
+
+        container_type m_dxdt;
+	container_type m_xtemp;
+        resizer_type m_resizer;
+
+
+
+
+	// public interface
+    public:
 
         const unsigned int order() { return 1; }
 
-	template< class DynamicalSystem , class TimeType >
+
+
+	template< class DynamicalSystem >
         void next_step( DynamicalSystem system ,
-                        ContainerType &x ,
-			const ContainerType &dxdt ,
-                        TimeType t ,
-                        TimeType dt )
+                        container_type &x ,
+			const container_type &dxdt ,
+                        time_type t ,
+                        time_type dt )
         {
             detail::it_algebra::scale_and_add( x.begin() , x.end() , dxdt.begin() , dt );
         }
 
-        template< class DynamicalSystem , class TimeType >
+
+
+        template< class DynamicalSystem >
         void next_step( DynamicalSystem system ,
-                        ContainerType &x ,
-                        TimeType t ,
-                        TimeType dt )
+                        container_type &x ,
+                        time_type t ,
+                        time_type dt )
         {
             m_resizer.adjust_size( x , m_dxdt );
             system( x , m_dxdt , t );
             next_step( system , x , m_dxdt , t , dt );
         }
 
-	template< class DynamicalSystem , class TimeType >
+
+
+	template< class DynamicalSystem >
         void next_step( DynamicalSystem system ,
-			ContainerType &x ,
-			const ContainerType &dxdt ,
-			TimeType t ,
-			TimeType dt ,
-			ContainerType &xerr )
+			container_type &x ,
+			const container_type &dxdt ,
+			time_type t ,
+			time_type dt ,
+			container_type &xerr )
         {
             m_resizer.adjust_size( x , xerr );
 
             m_xtemp = x;
-	    TimeType dt2 = 0.5 * dt;
+	    time_type dt2 = 0.5 * dt;
 
             next_step( system , x , dxdt , t , dt );
             next_step( system , m_xtemp , dxdt , t , dt2 );
             next_step( system , m_xtemp , t+dt2 , dt2 );
 
-	    detail::it_algebra::substract_and_assign( x.begin() , x.end() , m_xtemp.begin() , xerr.begin() );
+	    detail::it_algebra::substract_and_assign(
+		x.begin() , x.end() , m_xtemp.begin() , xerr.begin()
+		);
         }
 
 
 
-
-
-	template< class DynamicalSystem , class TimeType >
+	template< class DynamicalSystem >
         void next_step( DynamicalSystem system ,
-                        ContainerType &x ,
-                        TimeType t ,
-                        TimeType dt ,
-			ContainerType &xerr )
+                        container_type &x ,
+                        time_type t ,
+                        time_type dt ,
+			container_type &xerr )
         {
             m_resizer.check_size_and_resize( x , m_dxdt );
             system( x , m_dxdt , t );
@@ -111,6 +137,8 @@
         }
     };
 
+
+
 } // namespace odeint
 } // namespace numeric
 } // namespace boost
Modified: sandbox/odeint/boost/numeric/odeint/integrator_constant_step.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/integrator_constant_step.hpp	(original)
+++ sandbox/odeint/boost/numeric/odeint/integrator_constant_step.hpp	2009-11-03 10:11:15 EST (Tue, 03 Nov 2009)
@@ -19,32 +19,39 @@
 namespace numeric {
 namespace odeint {
 
+
+
     template<
         class Stepper ,
         class DynamicalSystem ,
-	class TimeType ,
-	class ContainerType
+	class Observer
 	>
     void integrate(
         Stepper stepper ,
         DynamicalSystem system ,
-	TimeType start_time ,
-	TimeType dt ,
-	ContainerType &state ,
-	TimeType end_time
+	typename Stepper::time_type start_time ,
+	typename Stepper::time_type dt ,
+	typename Stepper::container_type &state ,
+	typename Stepper::time_type end_time ,
+	Observer observer
         )
     {
         if( start_time > end_time )
             throw std::invalid_argument( "integrate() : start_time > end_time" );
 
+	observer( start_time , state , system );
         while( start_time < end_time )
         {
             stepper.next_step( system , state , start_time , dt );
             start_time += dt;
+	    observer( start_time , state , system );
         }
     }
     
 
+
+    
+
 } // odeint
 } // numeric
 } // boost
Modified: sandbox/odeint/boost/numeric/odeint/resizer.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/resizer.hpp	(original)
+++ sandbox/odeint/boost/numeric/odeint/resizer.hpp	2009-11-03 10:11:15 EST (Tue, 03 Nov 2009)
@@ -19,47 +19,60 @@
 namespace numeric {
 namespace odeint {
 
-    template< class ContainerType > 
+    template< class Container > 
     class resizer
     {
+    public:
+
+	typedef Container container_type;
+
+
+    private:
         // we need a resizable container here (obviously...)
-	BOOST_CLASS_REQUIRE( ContainerType , boost::numeric::odeint, Resizable );
+	BOOST_CLASS_REQUIRE( container_type , boost::numeric::odeint, Resizable );
 
+	
     public:
-        void resize( const ContainerType &x , ContainerType &dxdt ) const
+        void resize( const container_type &x , container_type &dxdt ) const
         {
             dxdt.resize( x.size() );
         }
         
-        bool same_size( const ContainerType &x1 , const ContainerType &x2 ) const
+        bool same_size( const container_type &x1 , const container_type &x2 ) const
         {
             return (x1.size() == x2.size());
         }
 
-	void adjust_size( const ContainerType &x1 , ContainerType &x2 ) const
+	void adjust_size( const container_type &x1 , container_type &x2 ) const
         {
             if( !same_size( x1 , x2 ) ) resize( x1 , x2 );
         }
     };
 
+
+
     /* Template Specialization for fixed size array - no resizing can happen */
     template< class T , size_t N >
     class resizer< std::tr1::array< T , N > >
     {
     public:
-        void resize( const std::tr1::array<T,N> &x ,
-		     std::tr1::array<T,N> &dxdt ) const
+
+	typedef std::tr1::array< T , N > container_type;
+
+
+    public:
+
+        void resize( const container_type &x , container_type &dxdt ) const
         {
             throw; // should never be called
         }
 
-        const bool same_size( const std::tr1::array<T,N> &x1 ,
-			      std::tr1::array<T,N> &x2 ) const
+        const bool same_size( const container_type &x1 , const container_type &x2 ) const
         {
             return true; // if this was false, the code wouldn't compile
         }
 
-	void adjust_size( const  std::tr1::array<T,N> &x1 ,  std::tr1::array<T,N> &x2 ) const
+	void adjust_size( const container_type &x1 , container_type &x2 ) const
         {
             if( !same_size( x1 , x2 ) ) throw;
         }
Modified: sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrate_constant_step.cpp
==============================================================================
--- sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrate_constant_step.cpp	(original)
+++ sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrate_constant_step.cpp	2009-11-03 10:11:15 EST (Tue, 03 Nov 2009)
@@ -21,11 +21,23 @@
 #include <list>
 #include <tr1/array>
 
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/if.hpp>
+#include <boost/lambda/loops.hpp>
+#include <boost/lambda/switch.hpp>
+#include <boost/lambda/construct.hpp>
+#include <boost/lambda/casts.hpp>
+#include <boost/lambda/exceptions.hpp>
+#include <boost/lambda/numeric.hpp>
+#include <boost/lambda/algorithm.hpp>
+
 #include <boost/numeric/odeint.hpp>
 
 #define tab "\t"
 
 using namespace std;
+using namespace boost::lambda;
 using namespace boost::numeric::odeint;
 
 const double sigma = 10.0;
@@ -52,8 +64,16 @@
     x[1] = 0.0;
     x[2] = 0.0;
 
-    ode_step_euler< state_type > euler;
-    integrate( euler , lorenz , 0.0 , 0.01 , x , 10.0 );
+    ode_step_euler< state_type , double > euler;
+//    integrate( euler , lorenz , 0.0 , 0.01 , x , 10.0 , my_observer );
+    integrate( euler , lorenz , 0.0 , 0.01 , x , 1.0 , cout << _1 << tab << _2[0] << "\n" );
+
+    vector<double> traj;
+    back_insert_iterator< vector<double> > iter(traj);
+    integrate( euler , lorenz , 0.0 , 0.01 , x , 1.0 , var(*iter++) = _2[1] );
+    copy( traj.begin() , traj.end() , ostream_iterator<double>( cout , "\n" ) );
+
+    
 
 
     return 0;