Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57253 - in sandbox/odeint: boost/numeric boost/numeric/odeint libs/numeric/odeint/examples
From: mario.mulansky_at_[hidden]
Date: 2009-10-30 14:44:27


Author: mariomulansky
Date: 2009-10-30 14:44:26 EDT (Fri, 30 Oct 2009)
New Revision: 57253
URL: http://svn.boost.org/trac/boost/changeset/57253

Log:
+integrator
+example lorenz_integrator
Added:
   sandbox/odeint/boost/numeric/odeint/integrator.hpp (contents, props changed)
   sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrator.cpp (contents, props changed)
Text files modified:
   sandbox/odeint/boost/numeric/odeint.hpp | 1 +
   sandbox/odeint/boost/numeric/odeint/stepsize_controller_standard.hpp | 2 --
   sandbox/odeint/libs/numeric/odeint/examples/lorenz.cpp | 2 +-
   sandbox/odeint/libs/numeric/odeint/examples/lorenz_controlled.cpp | 10 +++++-----
   4 files changed, 7 insertions(+), 8 deletions(-)

Modified: sandbox/odeint/boost/numeric/odeint.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint.hpp 2009-10-30 14:44:26 EDT (Fri, 30 Oct 2009)
@@ -18,5 +18,6 @@
 #include <boost/numeric/odeint/euler.hpp>
 #include <boost/numeric/odeint/runge_kutta_4.hpp>
 #include <boost/numeric/odeint/stepsize_controller_standard.hpp>
+#include <boost/numeric/odeint/integrator.hpp>
 
 #endif // BOOST_NUMERIC_ODEINT_HPP

Added: sandbox/odeint/boost/numeric/odeint/integrator.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/boost/numeric/odeint/integrator.hpp 2009-10-30 14:44:26 EDT (Fri, 30 Oct 2009)
@@ -0,0 +1,67 @@
+/* Boost odeint/integrator.hpp header file
+
+ Copyright 2009 Karsten Ahnert
+ Copyright 2009 Mario Mulansky
+
+ This file includes standard integration methods with adaptive stepsize.
+
+ 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_INTEGRATOR_HPP
+#define BOOST_NUMERIC_ODEINT_INTEGRATOR_HPP
+
+#include <boost/numeric/odeint/stepsize_controller_standard.hpp>
+#include <boost/numeric/odeint/resizer.hpp>
+#include <vector>
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+ class integrator {
+
+ public:
+ template< class StepType,
+ class DynamicalSystem,
+ class StateType,
+ class T >
+ size_t integrate(StepType &stepper, DynamicalSystem &system, StateType &x,
+ std::vector<T> &times, std::vector<StateType> &x_vec,
+ T dt = 1E-4, T eps_abs = 1E-7,
+ T eps_rel = 1E-8, T a_x = 1.0 , T a_dxdt = 1.0)
+ {
+ if( times.size() != x_vec.size() ) throw;
+ step_controller_standard< StateType, T >
+ controller(eps_abs, eps_rel, a_x, a_dxdt );
+
+ typename std::vector<T>::iterator t_iter = times.begin();
+ typename std::vector<StateType>::iterator x_iter = x_vec.begin();
+ controlled_step_result result;
+ T t = *t_iter;
+
+ while( t_iter < times.end() ) {
+
+ if( t >= *t_iter ) {
+ *x_iter++ = x;
+ t_iter++;
+ }
+
+ result = controller.controlled_step( stepper, system, x, t, dt );
+ while( result != SUCCESS ) {
+ result = controller.controlled_step( stepper, system, x, t, dt );
+ if( dt < 1E-10 ) throw;
+ }
+ }
+ return 0;
+ }
+ };
+
+
+} // namespace odeint
+} // namespace numeric
+} // namespace boost
+
+#endif

Modified: sandbox/odeint/boost/numeric/odeint/stepsize_controller_standard.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/stepsize_controller_standard.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint/stepsize_controller_standard.hpp 2009-10-30 14:44:26 EDT (Fri, 30 Oct 2009)
@@ -22,8 +22,6 @@
 #include <boost/numeric/odeint/concepts/state_concept.hpp>
 #include <boost/numeric/odeint/resizer.hpp>
 
-#include <iostream>
-
 namespace boost {
 namespace numeric {
 namespace odeint {

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-30 14:44:26 EDT (Fri, 30 Oct 2009)
@@ -2,7 +2,7 @@
  
  Copyright 2009 Karsten Ahnert
 
- Shows, the usage of odeint, and integrates the Lorenz equations,
+ Shows the usage of odeint, and integrates the Lorenz equations,
  a deterministic chaotic system
 
  dx/dt = sigma * ( x - y)

Modified: sandbox/odeint/libs/numeric/odeint/examples/lorenz_controlled.cpp
==============================================================================
--- sandbox/odeint/libs/numeric/odeint/examples/lorenz_controlled.cpp (original)
+++ sandbox/odeint/libs/numeric/odeint/examples/lorenz_controlled.cpp 2009-10-30 14:44:26 EDT (Fri, 30 Oct 2009)
@@ -1,8 +1,8 @@
-/* Boost numeric/odeint/examples/lorenz_array.cpp
+/* Boost numeric/odeint/examples/lorenz_controlled.cpp
  
  Copyright 2009 Karsten Ahnert
 
- Shows, the usage of odeint, and integrates the Lorenz equations,
+ Shows the usage of odeint by integrating the Lorenz equations,
  a deterministic chaotic system
 
  dx/dt = sigma * ( x - y)
@@ -35,8 +35,8 @@
 
 const size_t olen = 10000;
 
-const double eps_abs = 1E-3;
-const double eps_rel = 1E-3;
+const double eps_abs = 1E-7;
+const double eps_rel = 1E-8;
 
 const double min_dt = 1E-10;
 
@@ -62,7 +62,7 @@
                                                                     1.0, 1.0);
     
     double t = 0.0;
- double dt = 0.01;
+ double dt = 1E-4;
     controlled_step_result result;
 
     cout.precision(5);

Added: sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrator.cpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrator.cpp 2009-10-30 14:44:26 EDT (Fri, 30 Oct 2009)
@@ -0,0 +1,84 @@
+/* Boost numeric/odeint/examples/lorenz_integrator.cpp
+
+ Copyright 2009 Karsten Ahnert
+ Copyright 2009 Mario Mulansky
+
+ Shows the usage of odeint integrator by integrating the Lorenz equations,
+ a deterministic chaotic system
+
+ dx/dt = sigma * ( x - y)
+ dy/dt = R*x - y - x*z
+ dz/dt = x*y - b*z
+
+ mit sigma = 10, r=28, b = 8/3
+
+ 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 <iostream>
+#include <vector>
+#include <list>
+#include <tr1/array>
+
+#include <boost/numeric/odeint.hpp>
+
+#define tab "\t"
+
+using namespace std;
+using namespace std::tr1;
+using namespace boost::numeric::odeint;
+
+const double sigma = 10.0;
+const double R = 28.0;
+const double b = 8.0 / 3.0;
+
+const double eps_abs = 1E-3;
+const double eps_rel = 1E-3;
+
+const size_t time_points = 100;
+
+typedef array<double, 3> state_type;
+
+void lorenz( state_type &x , state_type &dxdt , double t )
+{
+ dxdt[0] = sigma * ( x[1] - x[0] );
+ dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
+ dxdt[2] = x[0]*x[1] - b * x[2];
+}
+
+int main( int argc , char **argv )
+{
+ state_type x;
+ x[0] = 1.0;
+ x[1] = 0.0;
+ x[2] = 20.0;
+
+ vector<state_type> x_t_vec(time_points);
+ vector<double> times(time_points);
+ for( size_t i=0; i<time_points; i++ ) {
+ times[i] = 0.1*i;
+ }
+
+ ode_step_euler< state_type > euler;
+ integrator odeint;
+ odeint.integrate( euler, lorenz, x, times, x_t_vec);
+
+ cout.precision(5);
+ cout.setf(ios::fixed,ios::floatfield);
+
+
+ for( size_t i=0; i<time_points; i++ ) {
+ //cout << "current state: " ;
+ cout << times[i] << tab;
+ cout << x_t_vec[i][0] << tab << x_t_vec[i][1] << tab << x_t_vec[i][2] << endl;
+ }
+
+ return 0;
+}
+
+/*
+ Compile with
+ g++ -Wall -I$BOOST_ROOT -I../../../../ lorenz_array.cpp
+*/


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