Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57229 - in sandbox/odeint/boost/numeric/odeint: . detail
From: karsten.ahnert_at_[hidden]
Date: 2009-10-29 12:42:06


Author: karsten
Date: 2009-10-29 12:42:06 EDT (Thu, 29 Oct 2009)
New Revision: 57229
URL: http://svn.boost.org/trac/boost/changeset/57229

Log:
some small changes in euler.hpp
Added:
   sandbox/odeint/boost/numeric/odeint/detail/
   sandbox/odeint/boost/numeric/odeint/detail/accumulators.hpp (contents, props changed)
   sandbox/odeint/boost/numeric/odeint/stepsize_controller_standard.hpp (contents, props changed)
Text files modified:
   sandbox/odeint/boost/numeric/odeint/euler.hpp | 50 ++++++++++++++++++++++++++++++++++-----
   sandbox/odeint/boost/numeric/odeint/resizer.hpp | 12 ++++++++
   2 files changed, 54 insertions(+), 8 deletions(-)

Added: sandbox/odeint/boost/numeric/odeint/detail/accumulators.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/boost/numeric/odeint/detail/accumulators.hpp 2009-10-29 12:42:06 EDT (Thu, 29 Oct 2009)
@@ -0,0 +1,54 @@
+/* Boost odeint/detail/accumulators.hpp header file
+
+ Copyright 2009 Karsten Ahnert
+ Copyright 2009 Mario Mulansky
+ Copyright 2009 Andre Bergner
+
+ Some accumulators for odeint
+
+ 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_DETAIL_ACCUMULATORS_HPP
+#define BOOST_NUMERIC_ODEINT_DETAIL_ACCUMULATORS_HPP
+
+
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+namespace detail {
+
+ template< class InputIterator ,
+ class OutputIterator ,
+ class T >
+ void multiply_and_add( InputIterator first1 ,
+ InputIterator last1 ,
+ OutputIterator first2 ,
+ T dt )
+ {
+ while( first1 != last1 )
+ (*first1++) += dt * (*first2++);
+ }
+
+ template< class InputIterator1 ,
+ class InputIterator2 ,
+ class OutputIterator >
+ void substract_and_assign( InputIterator1 first1 ,
+ InputIterator1 last1 ,
+ InputIterator2 first2 ,
+ OutputIterator first3 )
+ {
+ while( first1 != last1 )
+ ( *first3++ ) = ( *first1++ ) - ( *first2++ );
+ }
+
+}
+}
+}
+}
+
+
+#endif //BOOST_NUMERIC_ODEINT_DETAIL_ACCUMULATORS_HPP

Modified: sandbox/odeint/boost/numeric/odeint/euler.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/euler.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint/euler.hpp 2009-10-29 12:42:06 EDT (Thu, 29 Oct 2009)
@@ -19,9 +19,12 @@
 
 #include <boost/concept_check.hpp>
 
+#include <boost/numeric/odeint/detail/accumulators.hpp>
 #include <boost/numeric/odeint/concepts/state_concept.hpp>
 #include <boost/numeric/odeint/resizer.hpp>
 
+
+
 namespace boost {
 namespace numeric {
 namespace odeint {
@@ -32,8 +35,11 @@
>
     class ode_step_euler
     {
+ // check the concept of the ContainerType
         BOOST_CLASS_REQUIRE( ContainerType , boost::numeric::odeint, StateType );
+
         ContainerType dxdt;
+ ContainerType xtemp;
         ResizeType resizer;
 
         typedef typename ContainerType::iterator iterator;
@@ -41,20 +47,50 @@
 
     public:
 
- template< class DynamicalSystem , class TimeType>
+ template< class DynamicalSystem , class TimeType >
+ void next_step( DynamicalSystem system ,
+ ContainerType &x ,
+ ContainerType &dxdt ,
+ TimeType t ,
+ TimeType dt )
+ {
+ detail::multiply_and_add( x.begin() , x.end() , dxdt.begin() , dt );
+ }
+
+ template< class DynamicalSystem , class TimeType >
         void next_step( DynamicalSystem system ,
                         ContainerType &x ,
                         TimeType t ,
                         TimeType dt )
         {
- if( !resizer.same_size(x, dxdt) ) resizer.resize(x, dxdt);
+ resizer.check_size_and_resize( x , dxdt );
             system( x , dxdt , t );
- iterator state_begin = x.begin();
- iterator state_end = x.end();
- iterator derivative_begin = dxdt.begin();
- while( state_begin != state_end )
- (*state_begin++) += dt * (*derivative_begin++);
+ next_step( system , x , dxdt , t , dt );
         }
+
+
+ template< class DynamicalSystem , class TimeType >
+ void next_step( DynamicalSystem system ,
+ ContainerType &x ,
+ TimeType t ,
+ TimeType dt ,
+ ContainerType &xerr )
+ {
+ resizer.check_size_and_resize( x , dxdt );
+ resizer.check_size_and_resize( x , xerr );
+
+ xtemp = x;
+ TimeType dt2 = 0.5*dt;
+
+ system( x , dxdt , t );
+
+ next_step( system , x , dxdt , t , dt );
+ next_step( system , xtemp , dxdt , t , dt2 );
+ next_step( system , xtemp , t+dt2 , dt2 );
+
+ detail::substract_and_assign( x.begin() , x.end() , xtemp.begin() , xerr.begin() );
+ }
+
     };
 
 } // namespace odeint

Modified: sandbox/odeint/boost/numeric/odeint/resizer.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/resizer.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint/resizer.hpp 2009-10-29 12:42:06 EDT (Thu, 29 Oct 2009)
@@ -31,10 +31,15 @@
             dxdt.resize( x.size() );
         }
         
- bool same_size( const ContainerType &x1 , ContainerType &x2 ) const
+ bool same_size( const ContainerType &x1 , const ContainerType &x2 ) const
         {
             return (x1.size() == x2.size());
         }
+
+ void check_size_and_resize( const ContainerType &x1 , ContainerType &x2 ) const
+ {
+ if( same_size( x1 , x2 ) ) resize( x1 , x2 );
+ }
     };
 
     /* Template Specialization for fixed size array - no resizing can happen */
@@ -53,6 +58,11 @@
         {
             return true; // if this was false, the code wouldn't compile
         }
+
+ void check_size_and_resize( const std::tr1::array<T,N> &x1 , std::tr1::array<T,N> &x2 ) const
+ {
+ if( !same_size( x1 , x2 ) ) throw;
+ }
     };
 
 

Added: sandbox/odeint/boost/numeric/odeint/stepsize_controller_standard.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/boost/numeric/odeint/stepsize_controller_standard.hpp 2009-10-29 12:42:06 EDT (Thu, 29 Oct 2009)
@@ -0,0 +1,35 @@
+/* Boost odeint/stepsite_controller_standard.hpp header file
+
+ Copyright 2009 Karsten Ahnert
+ Copyright 2009 Mario Mulansky
+
+ This file includes the standard step size controller
+
+ It solves any ODE dx/dt = f(x,t) via
+ x(t+dt) = x(t) + dt*f(x,t)
+
+ 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_STEPSIZE_CONTROLLER_STANDARD_HPP
+#define BOOST_NUMERIC_ODEINT_STEPSIZE_CONTROLLER_STANDARD_HPP
+
+#include <boost/concept_check.hpp>
+
+#include <boost/numeric/odeint/concepts/state_concept.hpp>
+#include <boost/numeric/odeint/resizer.hpp>
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+
+
+} // namespace odeint
+} // namespace numeric
+} // namespace boost
+
+
+#endif // BOOST_NUMERIC_ODEINT_STEPSIZE_CONTROLLER_STANDARD_HPP


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