Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57110 - in sandbox/odeint: boost/numeric/odeint libs/numeric/odeint/examples
From: mario.mulansky_at_[hidden]
Date: 2009-10-23 13:29:47


Author: mariomulansky
Date: 2009-10-23 13:29:46 EDT (Fri, 23 Oct 2009)
New Revision: 57110
URL: http://svn.boost.org/trac/boost/changeset/57110

Log:
adjusted lorenz.cpp to latest changes in euler,
added same_size methods to resizer
Text files modified:
   sandbox/odeint/boost/numeric/odeint/euler.hpp | 54 ++++++++++++++++++++++++---------------
   sandbox/odeint/libs/numeric/odeint/examples/lorenz.cpp | 4 --
   2 files changed, 34 insertions(+), 24 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-10-23 13:29:46 EDT (Fri, 23 Oct 2009)
@@ -25,27 +25,39 @@
 namespace odeint {
 
 
- template< class ContainerType > class container_resizer
+ template< class ContainerType >
+ class resizer
     {
     public:
- void resize( const ContainerType &x , ContainerType &dxdt ) const
+ void resize( const ContainerType &x , ContainerType &dxdt ) const
         {
- if( x.size() != dxdt.size() ) dxdt.resize( x.size() );
- }
+ dxdt.resize( x.size() );
+ }
+
+ bool same_size( const ContainerType &x1 , ContainerType &x2 ) const
+ {
+ return (x1.size() == x2.size());
+ }
     };
 
     template< class T , size_t N >
- class container_resizer< std::tr1::array< 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
+ void resize( const std::tr1::array<T,N> &x , std::tr1::array<T,N> &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
         {
- }
+ return true; // if this was false, the code wouldn't compile
+ }
     };
 
     template<
         class ContainerType ,
- class ResizeType = container_resizer< ContainerType >
+ class ResizeType = resizer< ContainerType >
>
     class ode_step_euler
     {
@@ -57,20 +69,20 @@
 
     public:
 
- template< class DynamicalSystem , class TimeType>
- void next_step( DynamicalSystem system ,
- ContainerType &x ,
- TimeType t ,
- TimeType dt )
+ template< class DynamicalSystem , class TimeType>
+ void next_step( DynamicalSystem system ,
+ ContainerType &x ,
+ TimeType t ,
+ TimeType dt )
         {
- resizer.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++);
- }
+ if( !resizer.same_size(x, dxdt) ) resizer.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++);
+ }
     };
 
 

Modified: sandbox/odeint/libs/numeric/odeint/examples/lorenz.cpp
==============================================================================
--- sandbox/odeint/libs/numeric/odeint/examples/lorenz.cpp (original)
+++ sandbox/odeint/libs/numeric/odeint/examples/lorenz.cpp 2009-10-23 13:29:46 EDT (Fri, 23 Oct 2009)
@@ -39,9 +39,7 @@
 const double dt = 0.01;
 const size_t olen = 10000;
 
-//typedef array<double, 3> state_type;
 typedef vector<double> state_type;
-//typedef list<double> state_type;
 
 void lorenz( state_type &x , state_type &dxdt , double t )
 {
@@ -58,7 +56,7 @@
     x[1] = 0.0;
     x[2] = 0.0;
 
- ode_step_euler_container< state_type > euler;
+ ode_step_euler< state_type > euler;
 
     double t = 0.0;
     for( size_t oi=0 ; oi<olen ; ++oi,t+=dt )


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