$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r57557 - in sandbox/odeint: boost/numeric/odeint libs/numeric/odeint/examples libs/numeric/odeint/stuff/gsl_compare
From: karsten.ahnert_at_[hidden]
Date: 2009-11-10 16:48:13
Author: karsten
Date: 2009-11-10 16:48:12 EST (Tue, 10 Nov 2009)
New Revision: 57557
URL: http://svn.boost.org/trac/boost/changeset/57557
Log:
added some integrate with constants step variants
Added:
   sandbox/odeint/boost/numeric/odeint/observer.hpp   (contents, props changed)
Text files modified: 
   sandbox/odeint/boost/numeric/odeint/integrator.hpp                             |    12 ++-                                     
   sandbox/odeint/boost/numeric/odeint/integrator_constant_step.hpp               |   113 ++++++++++++++++++++++++++++++++++----- 
   sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrate_constant_step.cpp |    16 ++++-                                   
   sandbox/odeint/libs/numeric/odeint/stuff/gsl_compare/lorenz_stepper_cmp.cpp    |     2                                         
   4 files changed, 119 insertions(+), 24 deletions(-)
Modified: sandbox/odeint/boost/numeric/odeint/integrator.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/integrator.hpp	(original)
+++ sandbox/odeint/boost/numeric/odeint/integrator.hpp	2009-11-10 16:48:12 EST (Tue, 10 Nov 2009)
@@ -44,15 +44,19 @@
 
         observer(t, state, system);
         
-        while( t < end_time ) {
+        while( t < end_time )
+	{
             result = controller.controlled_step( stepper, system, state, t, dt );
-            if( result != STEP_SIZE_DECREASED ) { // we actually did a step forward
+            if( result != STEP_SIZE_DECREASED )
+	    { // we actually did a step forward
                 observer(t, state, system);
                 iterations++;
             }
-            while( result != SUCCESS ) {
+            while( result != SUCCESS )
+	    {
                 result = controller.controlled_step( stepper, system, state, t, dt );
-                if( result != STEP_SIZE_DECREASED ) { // we did a step
+                if( result != STEP_SIZE_DECREASED )
+		{ // we did a step
                     observer(t, state, system);
                     iterations++;
                 }
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-10 16:48:12 EST (Tue, 10 Nov 2009)
@@ -13,38 +13,119 @@
 #ifndef BOOST_NUMERIC_ODEINT_INTEGRATOR_CONSTANT_STEP_HPP_INCLUDED
 #define BOOST_NUMERIC_ODEINT_INTEGRATOR_CONSTANT_STEP_HPP_INCLUDED
 
-#include <stdexcept>
+#include <boost/numeric/odeint/observer.hpp>
 
 namespace boost {
 namespace numeric {
 namespace odeint {
 
 
-    template<
+    template< 
         class Stepper ,
         class DynamicalSystem ,
         class Observer
         >
-    void integrate(
-                   Stepper &stepper ,
-                   DynamicalSystem &system ,
-                   typename Stepper::time_type start_time ,
-                   typename Stepper::time_type dt ,
-                   typename Stepper::container_type &state ,
-                   typename Stepper::time_type end_time ,
-                   Observer &observer
-                   )
+    size_t integrate(
+	Stepper &stepper ,
+	DynamicalSystem &system ,
+	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" );
+	size_t iteration = 0;
+        while( start_time < end_time )
+	{
+	    observer( start_time , state , system );
+            stepper.next_step( system , state , start_time , dt );
+            start_time += dt;
+	    ++iteration;
+        }
+	observer( start_time , state , system );
+
+	return iteration;
+    }
+
+
+
+    template<
+        class Stepper ,
+        class DynamicalSystem
+        >
+    size_t integrate(
+	Stepper &stepper ,
+	DynamicalSystem &system ,
+	typename Stepper::time_type start_time ,
+	typename Stepper::time_type dt ,
+	typename Stepper::container_type &state ,
+	typename Stepper::time_type end_time
+	)
+    {
+	return integrate(
+	    stepper , system , start_time , dt , state , end_time ,
+	    do_nothing_observer<
+	    typename Stepper::time_type ,
+	    typename Stepper::container_type ,
+	    DynamicalSystem >
+	    );
+    }
+
 
-        observer( start_time , state , system );
-        while( start_time < end_time ) {
+
+    template<
+	class Stepper , 
+        class DynamicalSystem ,
+        class Observer
+        >
+    typename Stepper::time_type integrate_steps(
+	Stepper &stepper ,
+	DynamicalSystem &system ,
+	typename Stepper::time_type start_time ,
+	typename Stepper::time_type dt ,
+	typename Stepper::container_type &state ,
+	size_t num_of_steps ,
+	Observer &observer
+	)
+    {
+	size_t iteration = 0;
+        while( iteration < num_of_steps )
+	{
+	    observer( start_time , state , system );
             stepper.next_step( system , state , start_time , dt );
             start_time += dt;
-            observer( start_time , state , system );
+	    ++iteration;
         }
+	observer( start_time , state , system );
+
+	return start_time;
     }
+
+
+    template<
+	class Stepper , 
+        class DynamicalSystem
+	>
+    typename Stepper::time_type integrate_steps(
+	Stepper &stepper ,
+	DynamicalSystem &system ,
+	typename Stepper::time_type start_time ,
+	typename Stepper::time_type dt ,
+	typename Stepper::container_type &state ,
+	size_t num_of_steps 
+	)
+    {
+	return integrate_steps(
+	    stepper , system , start_time , dt , state , num_of_steps ,
+	    do_nothing_observer<
+	    typename Stepper::time_type ,
+	    typename Stepper::container_type ,
+	    DynamicalSystem >
+	    );
+    }
+
+    
     
    
 
Added: sandbox/odeint/boost/numeric/odeint/observer.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/boost/numeric/odeint/observer.hpp	2009-11-10 16:48:12 EST (Tue, 10 Nov 2009)
@@ -0,0 +1,33 @@
+/*
+ boost header: numeric/odeint/observer.hpp
+
+ Copyright 2009 Karsten Ahnert
+ Copyright 2009 Mario Mulansky
+ Copyright 2009 Andre Bergner
+
+ 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_OBSERVER_HPP_INCLUDED
+#define BOOST_NUMERIC_ODEINT_OBSERVER_HPP_INCLUDED
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+
+    template< class Time , class Container , class System >
+    void do_nothing_observer( Time , Container& , System& )
+    {
+    }
+    
+   
+
+} // odeint
+} // numeric
+} // boost
+
+
+#endif //BOOST_NUMERIC_ODEINT_OBSERVER_HPP_INCLUDED
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-10 16:48:12 EST (Tue, 10 Nov 2009)
@@ -65,13 +65,23 @@
 
     ode_step_runge_kutta_4< state_type , double > rk4;
     ode_step_euler< state_type , double > euler;
-    integrate( rk4 , lorenz , 0.0 , 0.01 , x , 100.0 , cout << _1 << tab << _2[0] << "\n" );
-//    integrate( euler , lorenz , 0.0 , 0.01 , x , 100.0 , cout << _1 << tab << _2[0] << "\n" );
+    integrate( rk4 , lorenz , 0.0 , 0.01 , x , 100.0 ,
+	       cout << _1 << tab << _2[0] << "\n" );
+
+    integrate_steps( rk4 , lorenz , 0.0 , 0.01 , x , 100 ,
+		     cout << _1 << tab << _2[0] << "\n" );
+
+    integrate( rk4 , lorenz , 0.0 , 0.01 , x , 100.0 );
+    integrate_steps( rk4 , lorenz , 0.0 , 0.01 , x , 1000 );
+
+/*    integrate( euler , lorenz , 0.0 , 0.01 , x , 100.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" ) );*/
+    copy( traj.begin() , traj.end() ,
+	  ostream_iterator<double>( cout , "\n" ) ); */
 
     
 
Modified: sandbox/odeint/libs/numeric/odeint/stuff/gsl_compare/lorenz_stepper_cmp.cpp
==============================================================================
--- sandbox/odeint/libs/numeric/odeint/stuff/gsl_compare/lorenz_stepper_cmp.cpp	(original)
+++ sandbox/odeint/libs/numeric/odeint/stuff/gsl_compare/lorenz_stepper_cmp.cpp	2009-11-10 16:48:12 EST (Tue, 10 Nov 2009)
@@ -158,5 +158,5 @@
 
 /*
   Compile with
-  g++ -Wall -O3 -I$BOOST_ROOT -I../../../../ lorenz_stepper_cmp.cpp -lgsl -lgslcblas
+  g++ -Wall -O3 -I$BOOST_ROOT -I../../../../../ lorenz_stepper_cmp.cpp -lgsl -lgslcblas
 */