|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57565 - in sandbox/odeint: boost/numeric/odeint boost/numeric/odeint/concepts libs/numeric/odeint/examples
From: mario.mulansky_at_[hidden]
Date: 2009-11-11 09:14:53
Author: mariomulansky
Date: 2009-11-11 09:14:52 EST (Wed, 11 Nov 2009)
New Revision: 57565
URL: http://svn.boost.org/trac/boost/changeset/57565
Log:
use inserter
Text files modified:
sandbox/odeint/boost/numeric/odeint/concepts/state_concept.hpp | 10 +++---
sandbox/odeint/boost/numeric/odeint/euler.hpp | 2
sandbox/odeint/boost/numeric/odeint/integrator.hpp | 61 ++++++++++++++++++++-------------------
sandbox/odeint/boost/numeric/odeint/resizer.hpp | 2
sandbox/odeint/boost/numeric/odeint/runge_kutta_4.hpp | 2
sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrator.cpp | 5 +-
6 files changed, 43 insertions(+), 39 deletions(-)
Modified: sandbox/odeint/boost/numeric/odeint/concepts/state_concept.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/concepts/state_concept.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint/concepts/state_concept.hpp 2009-11-11 09:14:52 EST (Wed, 11 Nov 2009)
@@ -22,7 +22,7 @@
/* Concept StateType */
template<class X>
- struct StateType {
+ struct Container {
public:
typedef typename X::iterator iterator; // requires iterator typedef
@@ -30,7 +30,7 @@
// requires iterator being ForwardIterator
BOOST_CONCEPT_ASSERT((ForwardIterator<iterator>));
- BOOST_CONCEPT_USAGE(StateType)
+ BOOST_CONCEPT_USAGE(Container)
{
same_type(state.begin(), it); //requires begin() method
same_type(state.end(), it); // requires end() method
@@ -49,13 +49,13 @@
/* Concept Resizable */
template<class X>
- struct Resizable {
+ struct Resizer {
public:
- BOOST_CONCEPT_ASSERT((StateType<X>));
+ BOOST_CONCEPT_ASSERT((Container<X>));
- BOOST_CONCEPT_USAGE(Resizable)
+ BOOST_CONCEPT_USAGE(Resizer)
{
state.resize(1); // state has resize function
size_t n = 2;
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-11 09:14:52 EST (Wed, 11 Nov 2009)
@@ -55,7 +55,7 @@
private:
BOOST_CLASS_REQUIRE( container_type ,
- boost::numeric::odeint, StateType );
+ boost::numeric::odeint, Container );
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-11 09:14:52 EST (Wed, 11 Nov 2009)
@@ -81,45 +81,43 @@
whole intervale times.begin() - times.end().
Note that the values in times don't influence the stepsize, but only the
time points at which the state is stored into x_vec.
- */
+ */
template<
- class StepType,
+ class Stepper,
class DynamicalSystem,
class StepController,
- class T >
- size_t integrate(StepType &stepper,
+ class InsertIterator
+ >
+ size_t integrate(Stepper &stepper,
DynamicalSystem &system,
StepController &controller,
- typename StepType::container_type &x,
- std::vector<T> ×,
- std::vector<typename StepType::container_type> &x_vec,
- T dt)
+ typename Stepper::container_type &state,
+ std::vector<typename Stepper::time_type> ×,
+ InsertIterator state_inserter,
+ typename Stepper::time_type dt)
{
- if( times.size() != x_vec.size() ) throw;
-
// iterators for the time and state vectors
- typename std::vector<T>::iterator t_iter = times.begin();
- typename std::vector<typename StepType::container_type>::iterator x_iter = x_vec.begin();
+ typename std::vector<typename Stepper::time_type>::iterator t_iter = times.begin();
controlled_step_result result;
size_t iterations = 0;
- T t = *t_iter;
+ typename Stepper::time_type t = *t_iter;
while( true ) { // loop will break from inside
if( t >= *t_iter ) { // we've reached the next time point
- *x_iter++ = x; // save the state
+ *state_inserter++ = state; // save the state
t_iter++; // next time point
}
if( t_iter >= times.end() ) // reached end of integration time
break; // stop loop
- result = controller.controlled_step( stepper, system, x, t, dt );
+ result = controller.controlled_step( stepper, system, state, t, dt );
if( result != STEP_SIZE_DECREASED )
iterations++;
while( result != SUCCESS ) {
- result = controller.controlled_step( stepper, system, x, t, dt );
+ result = controller.controlled_step( stepper, system, state, t, dt );
if( result != STEP_SIZE_DECREASED )
iterations++;
if( !( t+dt > t) )
@@ -161,25 +159,30 @@
To avoid extensive chages in dt, the decrease factor is limited to 0.2 and
the increase factor to 5.0.
- */
- template< class StepType,
+ */
+ template< class Stepper,
class DynamicalSystem,
- class T >
- size_t integrate(StepType &stepper,
+ class InsertIterator
+ >
+ size_t integrate(Stepper &stepper,
DynamicalSystem &system,
- typename StepType::container_type &x,
- std::vector<T> ×,
- std::vector<typename StepType::container_type> &x_vec,
- T dt = 1E-4, T eps_abs = 1E-6,
- T eps_rel = 1E-7, T a_x = 1.0 , T a_dxdt = 1.0)
+ typename Stepper::container_type &x,
+ std::vector<typename Stepper::time_type> ×,
+ InsertIterator state_inserter,
+ typename Stepper::time_type dt = 1E-4,
+ typename Stepper::time_type eps_abs = 1E-6,
+ typename Stepper::time_type eps_rel = 1E-7,
+ typename Stepper::time_type a_x = 1.0 ,
+ typename Stepper::time_type a_dxdt = 1.0)
{
- if( times.size() != x_vec.size() ) throw;
// we use the standard controller for this adaptive integrator
- step_controller_standard< typename StepType::container_type, T, typename StepType::resizer_type>
- controller(eps_abs, eps_rel, a_x, a_dxdt ); // initialized with values from above
+ step_controller_standard< typename Stepper::container_type,
+ typename Stepper::time_type,
+ typename Stepper::resizer_type > controller(eps_abs, eps_rel, a_x, a_dxdt );
+ // initialized with values from above
// call the normal integrator
- return integrate(stepper, system, controller, x, times, x_vec, dt);
+ return integrate(stepper, system, controller, x, times, state_inserter, 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-11 09:14:52 EST (Wed, 11 Nov 2009)
@@ -29,7 +29,7 @@
private:
// we need a resizable container here (obviously...)
- BOOST_CLASS_REQUIRE( container_type , boost::numeric::odeint, Resizable );
+ BOOST_CLASS_REQUIRE( container_type , boost::numeric::odeint, Resizer );
public:
Modified: sandbox/odeint/boost/numeric/odeint/runge_kutta_4.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/runge_kutta_4.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint/runge_kutta_4.hpp 2009-11-11 09:14:52 EST (Wed, 11 Nov 2009)
@@ -54,7 +54,7 @@
private:
BOOST_CLASS_REQUIRE( container_type ,
- boost::numeric::odeint, StateType );
+ boost::numeric::odeint, Container );
Modified: sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrator.cpp
==============================================================================
--- sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrator.cpp (original)
+++ sandbox/odeint/libs/numeric/odeint/examples/lorenz_integrator.cpp 2009-11-11 09:14:52 EST (Wed, 11 Nov 2009)
@@ -19,6 +19,7 @@
#include <iostream>
#include <vector>
+#include <iterator>
#include <list>
#include <tr1/array>
@@ -55,14 +56,14 @@
x[1] = 0.0;
x[2] = 20.0;
- vector<state_type> x_t_vec(time_points);
+ vector<state_type> x_t_vec;
vector<double> times(time_points);
for( size_t i=0; i<time_points; i++ ) {
times[i] = 0.1*i;
}
ode_step_half_step< ode_step_euler< state_type > > euler;
- size_t steps = integrate( euler, lorenz, x, times, x_t_vec);
+ size_t steps = integrate( euler, lorenz, x, times, back_inserter(x_t_vec));
clog << "Steps: " << steps << endl;
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