|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58362 - in sandbox/odeint: boost/numeric/odeint boost/numeric/odeint/detail libs/numeric/odeint/examples
From: mario.mulansky_at_[hidden]
Date: 2009-12-13 13:30:04
Author: mariomulansky
Date: 2009-12-13 13:30:02 EST (Sun, 13 Dec 2009)
New Revision: 58362
URL: http://svn.boost.org/trac/boost/changeset/58362
Log:
rk_generic now uses container_traits
Text files modified:
sandbox/odeint/boost/numeric/odeint/detail/iterator_algebra.hpp | 34 ++++++++++++++++++++++-
sandbox/odeint/boost/numeric/odeint/stepper_rk4.hpp | 7 ++--
sandbox/odeint/boost/numeric/odeint/stepper_rk_generic.hpp | 56 +++++++++++++++++++--------------------
sandbox/odeint/libs/numeric/odeint/examples/Jamfile | 2
sandbox/odeint/libs/numeric/odeint/examples/lorenz_cmp_rk4_rk_generic.cpp | 1
5 files changed, 64 insertions(+), 36 deletions(-)
Modified: sandbox/odeint/boost/numeric/odeint/detail/iterator_algebra.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/detail/iterator_algebra.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint/detail/iterator_algebra.hpp 2009-12-13 13:30:02 EST (Sun, 13 Dec 2009)
@@ -118,9 +118,10 @@
InputIterator2 x2_begin )
{
while( y_begin != y_end )
- (*y_begin++) =
- alpha1 * (*x1_begin++) +
+ {
+ (*y_begin++) = alpha1 * (*x1_begin++) +
alpha2 * (*x2_begin++);
+ }
}
@@ -484,6 +485,35 @@
}
+ // computes y += alpha1*x1 + alpha2*x2 + alpha3*x3 + alpha4*x4
+ template <
+ class OutputIterator,
+ class InputIterator1,
+ class InputIterator2,
+ class InputIterator3,
+ class InputIterator4,
+ class T
+ >
+ inline void scale_sum_inplace(
+ OutputIterator y_begin,
+ OutputIterator y_end,
+ T alpha1,
+ InputIterator1 x1_begin,
+ T alpha2,
+ InputIterator2 x2_begin,
+ T alpha3,
+ InputIterator3 x3_begin,
+ T alpha4,
+ InputIterator4 x4_begin )
+ {
+ while( y_begin != y_end )
+ (*y_begin++) +=
+ alpha1 * (*x1_begin++) +
+ alpha2 * (*x2_begin++) +
+ alpha3 * (*x3_begin++) +
+ alpha4 * (*x4_begin++);
+ }
+
/* calculates tmp = y, y = x1 + alpha*x2, x1 = tmp */
template <
class OutputIterator,
Modified: sandbox/odeint/boost/numeric/odeint/stepper_rk4.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/stepper_rk4.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint/stepper_rk4.hpp 2009-12-13 13:30:02 EST (Sun, 13 Dec 2009)
@@ -95,7 +95,7 @@
val1, traits_type::begin(x),
dh, traits_type::begin(dxdt) );
- // dt * m_dxt = k2
+ // dt * m_dxt = k2
system( m_xt , m_dxt , th );
//m_xt = x + dh*m_dxt
scale_sum( traits_type::begin(m_xt) ,
@@ -110,13 +110,12 @@
val1, traits_type::begin(x) ,
dt, traits_type::begin(m_dxm) );
- // dt * m_dxh = k4
+ // dt * m_dxh = k4
system( m_xt , m_dxh , t + dt );
//x += dt/6 * ( m_dxdt + m_dxt + val2*m_dxm )
time_type dt6 = dt / static_cast<time_type>( 6.0 );
time_type dt3 = dt / static_cast<time_type>( 3.0 );
- scale_sum( traits_type::begin(x) , traits_type::end(x),
- val1, traits_type::begin(x),
+ scale_sum_inplace( traits_type::begin(x) , traits_type::end(x),
dt6 , traits_type::begin(dxdt),
dt3 , traits_type::begin(m_dxt),
dt3 , traits_type::begin(m_dxm),
Modified: sandbox/odeint/boost/numeric/odeint/stepper_rk_generic.hpp
==============================================================================
--- sandbox/odeint/boost/numeric/odeint/stepper_rk_generic.hpp (original)
+++ sandbox/odeint/boost/numeric/odeint/stepper_rk_generic.hpp 2009-12-13 13:30:02 EST (Sun, 13 Dec 2009)
@@ -97,7 +97,7 @@
{
typename container_vector::iterator x_iter = m_xvec.begin();
while( x_iter != m_xvec.end() ) {
- (*xiter_iter++) = (*x_iter++).begin();
+ (*xiter_iter++) = traits_type::begin(*x_iter++);
}
}
@@ -202,12 +202,12 @@
typename container_iterator_vector::iterator xiter_iter = m_xiter_vec.begin();
(*x_iter) = dxdt;
- (*xiter_iter++) = (*x_iter++).begin();
+ (*xiter_iter++) = traits_type::begin(*x_iter++);
while( x_iter != m_xvec.end() )
{
traits_type::adjust_size(x, (*x_iter));
- (*xiter_iter++) = (*x_iter++).begin();
+ (*xiter_iter++) = traits_type::begin(*x_iter++);
}
traits_type::adjust_size(x, m_xtmp);
@@ -218,18 +218,18 @@
while( x_iter != m_xvec.end() )
{
reset_iter(m_xiter_vec.begin());
- scale_sum_generic( m_xtmp.begin(), m_xtmp.end(),
+ scale_sum_generic( traits_type::begin(m_xtmp), traits_type::end(m_xtmp),
(*b_iter).begin(), (*b_iter).end(), dt,
- x.begin(), m_xiter_vec.begin() );
+ traits_type::begin(x), m_xiter_vec.begin() );
system( m_xtmp, *x_iter++ , t + dt*(*a_iter++) );
b_iter++;
}
reset_iter(m_xiter_vec.begin());
typename parameter_vector::const_iterator c_iter = m_c.begin();
- scale_sum_generic( x.begin(), x.end(),
+ scale_sum_generic( traits_type::begin(x), traits_type::end(x),
m_c.begin(), m_c.end(), dt,
- x.begin(), m_xiter_vec.begin() );
+ traits_type::begin(x), m_xiter_vec.begin() );
}
template< class DynamicalSystem >
@@ -262,31 +262,30 @@
template<
class Container ,
class Time = double ,
- class Resizer = resizer< Container >
+ class Traits = container_traits< Container >
>
- class stepper_rk_generic_ptr {
+ class stepper_rk_generic_ptr
+ {
+
// provide basic typedefs
public:
+ typedef const unsigned short order_type;
typedef Container container_type;
- typedef Resizer resizer_type;
typedef Time time_type;
- typedef const unsigned short order_type;
- typedef typename container_type::value_type value_type;
- typedef typename container_type::iterator iterator;
-
-
- // check the concept of the ContainerType
- private:
-
- BOOST_CLASS_REQUIRE( container_type ,
- boost::numeric::odeint, Container );
+ typedef Traits traits_type;
+ typedef typename traits_type::value_type value_type;
+ typedef typename traits_type::iterator iterator;
+ typedef typename traits_type::const_iterator const_iterator;
// private variables
private:
+
typedef std::vector< container_type > container_vector;
typedef std::vector< iterator > container_iterator_vector;
+ typedef std::vector< time_type > parameter_vector;
+ typedef std::vector< parameter_vector > parameter_matrix;
container_vector m_xvec;
container_iterator_vector m_xiter_vec;
@@ -297,14 +296,13 @@
order_type m_q;
- resizer_type m_resizer;
private:
void reset_iter(typename container_iterator_vector::iterator xiter_iter)
{
typename container_vector::iterator x_iter = m_xvec.begin();
while( x_iter != m_xvec.end() ) {
- (*xiter_iter++) = (*x_iter++).begin();
+ (*xiter_iter++) = traits_type::begin(*x_iter++);
}
}
@@ -386,10 +384,10 @@
typename container_iterator_vector::iterator xiter_iter = m_xiter_vec.begin();
(*x_iter) = dxdt;
- (*xiter_iter++) = (*x_iter++).begin();
+ (*xiter_iter++) = traits_type::begin(*x_iter++);
while( x_iter != m_xvec.end() )
- {
+ {
traits_type::adjust_size(x, (*x_iter));
(*xiter_iter++) = (*x_iter++).begin();
}
@@ -401,21 +399,21 @@
const time_type* b_iter = &m_b[0];
unsigned short b_len= 1;
while( x_iter != m_xvec.end() )
- {
+ {
reset_iter(m_xiter_vec.begin());
const time_type* b_end = b_iter + b_len;
- scale_sum_generic( m_xtmp.begin(), m_xtmp.end(),
+ scale_sum_generic( traits_type::begin(m_xtmp), traits_type::end(m_xtmp),
b_iter, b_end, dt,
- x.begin(), m_xiter_vec.begin() );
+ traits_type::begin(x), m_xiter_vec.begin() );
system( m_xtmp, *x_iter++ , t + dt*(*a_iter++) );
b_iter = b_end;
b_len++;
}
reset_iter(m_xiter_vec.begin());
- scale_sum_generic( x.begin(), x.end(),
+ scale_sum_generic( traits_type::begin(x), traits_type::end(x),
&m_c[0], &m_c[m_q], dt,
- x.begin(), m_xiter_vec.begin() );
+ traits_type::begin(x), m_xiter_vec.begin() );
}
Modified: sandbox/odeint/libs/numeric/odeint/examples/Jamfile
==============================================================================
--- sandbox/odeint/libs/numeric/odeint/examples/Jamfile (original)
+++ sandbox/odeint/libs/numeric/odeint/examples/Jamfile 2009-12-13 13:30:02 EST (Sun, 13 Dec 2009)
@@ -18,7 +18,7 @@
exe test_container_and_stepper : test_container_and_stepper.cpp ;
exe hamiltonian_test : hamiltonian_test.cpp ;
-# exe lorenz_cmp_rk4_rk_generic : lorenz_cmp_rk4_rk_generic.cpp ;
+exe lorenz_cmp_rk4_rk_generic : lorenz_cmp_rk4_rk_generic.cpp ;
exe lorenz_controlled : lorenz_controlled.cpp ;
exe lorenz_integrate_constant_step : lorenz_integrate_constant_step.cpp ;
exe lorenz_integrator : lorenz_integrator.cpp ;
Modified: sandbox/odeint/libs/numeric/odeint/examples/lorenz_cmp_rk4_rk_generic.cpp
==============================================================================
--- sandbox/odeint/libs/numeric/odeint/examples/lorenz_cmp_rk4_rk_generic.cpp (original)
+++ sandbox/odeint/libs/numeric/odeint/examples/lorenz_cmp_rk4_rk_generic.cpp 2009-12-13 13:30:02 EST (Sun, 13 Dec 2009)
@@ -21,6 +21,7 @@
#include <tr1/array>
#include <boost/numeric/odeint.hpp>
+#include <boost/numeric/odeint/stepper_rk_generic.hpp>
#define tab "\t"
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