|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57300 - in sandbox/odeint: boost/numeric boost/numeric/odeint libs/numeric/odeint/examples
From: karsten.ahnert_at_[hidden]
Date: 2009-11-03 06:00:34
Author: karsten
Date: 2009-11-03 06:00:33 EST (Tue, 03 Nov 2009)
New Revision: 57300
URL: http://svn.boost.org/trac/boost/changeset/57300
Log:
integrate constant step size added and finished
Added:
sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrate_constant_step.cpp (contents, props changed)
Text files modified:
sandbox/odeint/boost/numeric/odeint.hpp | 1 +
sandbox/odeint/boost/numeric/odeint/euler.hpp | 12 +++++-------
sandbox/odeint/boost/numeric/odeint/integrator_constant_step.hpp | 17 ++++++++++-------
sandbox/odeint/boost/numeric/odeint/resizer.hpp | 2 +-
4 files changed, 17 insertions(+), 15 deletions(-)
Modified: sandbox/odeint/boost/numeric/odeint.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint.hpp 2009-11-03 06:00:33 EST (Tue, 03 Nov 2009)
@@ -19,5 +19,6 @@
#include <boost/numeric/odeint/runge_kutta_4.hpp>
#include <boost/numeric/odeint/stepsize_controller_standard.hpp>
#include <boost/numeric/odeint/integrator.hpp>
+#include <boost/numeric/odeint/integrator_constant_step.hpp>
#endif // BOOST_NUMERIC_ODEINT_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-11-03 06:00:33 EST (Tue, 03 Nov 2009)
@@ -42,12 +42,13 @@
ContainerType m_xtemp;
ResizeType m_resizer;
- typedef typename ContainerType container_type;
- typedef typename ContainerType::iterator iterator;
- typedef typename ContainerType::value_type value_type;
-
public:
+ typedef ContainerType container_type;
+ typedef ResizerType resizer_type;
+ typedef typename container_type::iterator iterator;
+ typedef typename container_type::value_type value_type;
+
const unsigned int order() { return 1; }
template< class DynamicalSystem , class TimeType >
@@ -71,9 +72,6 @@
next_step( system , x , m_dxdt , t , dt );
}
-
-
-
template< class DynamicalSystem , class TimeType >
void next_step( DynamicalSystem system ,
ContainerType &x ,
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 06:00:33 EST (Tue, 03 Nov 2009)
@@ -13,6 +13,8 @@
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATOR_CONSTANT_STEP_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_INTEGRATOR_CONSTANT_STEP_HPP_INCLUDED
+#include <stdexcept>
+
namespace boost {
namespace numeric {
namespace odeint {
@@ -21,22 +23,23 @@
class Stepper ,
class DynamicalSystem ,
class TimeType ,
- class InsertIterator
+ class ContainerType
>
void integrate(
Stepper stepper ,
DynamicalSystem system ,
- TimeType dt ,
TimeType start_time ,
- Stepper::container_type state ,
- TimeType end_time ,
- InsertIterator inserter
+ TimeType dt ,
+ ContainerType &state ,
+ TimeType end_time
)
{
+ if( start_time > end_time )
+ throw std::invalid_argument( "integrate() : start_time > end_time" );
+
while( start_time < end_time )
{
- *inserter++ = state;
- stepper.next_step( system , state , t , dt );
+ stepper.next_step( system , state , start_time , dt );
start_time += dt;
}
}
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 06:00:33 EST (Tue, 03 Nov 2009)
@@ -38,7 +38,7 @@
void adjust_size( const ContainerType &x1 , ContainerType &x2 ) const
{
- if( same_size( x1 , x2 ) ) resize( x1 , x2 );
+ if( !same_size( x1 , x2 ) ) resize( x1 , x2 );
}
};
Added: sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrate_constant_step.cpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrate_constant_step.cpp 2009-11-03 06:00:33 EST (Tue, 03 Nov 2009)
@@ -0,0 +1,67 @@
+/* Boost numeric/odeint/examples/lorenz_integrate_constant_step.cpp
+
+ Copyright 2009 Karsten Ahnert
+
+ Shows the usage of odeint, and integrates 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 boost::numeric::odeint;
+
+const double sigma = 10.0;
+const double R = 28.0;
+const double b = 8.0 / 3.0;
+
+const double dt = 0.01;
+const size_t olen = 10000;
+
+typedef vector<double> 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(3);
+ x[0] = 1.0;
+ x[1] = 0.0;
+ x[2] = 0.0;
+
+ ode_step_euler< state_type > euler;
+ integrate( euler , lorenz , 0.0 , 0.01 , x , 10.0 );
+
+
+ return 0;
+}
+
+
+
+/*
+ Compile with
+ g++ -Wall -I$BOOST_ROOT -I../../../../ lorenz_integrate_constant_step.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