2
0
mirror of https://github.com/boostorg/odeint.git synced 2026-02-20 02:52:07 +00:00

added const step iterator

This commit is contained in:
Karsten Ahnert
2012-06-27 08:26:09 +02:00
parent 0f126ac9e4
commit 5b48c56451
5 changed files with 259 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ exe simple1d : simple1d.cpp ;
exe stochastic_euler : stochastic_euler.cpp : : <cxxflags>-std=c++0x ;
exe generation_functions : generation_functions.cpp : : <cxxflags>-std=c++0x ;
exe heun : heun.cpp : : <cxxflags>-std=c++0x ;
exe const_step_iterator : const_step_iterator.cpp ;
# build-project mtl ;
# build-project ublas ;

View File

@@ -0,0 +1,60 @@
/*
* const_step_ode_iterator.cpp
*
* Created on: Jun 26, 2012
* Author: karsten
*/
#include <iostream>
#include <utility>
#include <algorithm>
#include <boost/array.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta4.hpp>
#include <boost/numeric/odeint/iterator/const_step_iterator.hpp>
using namespace boost::numeric::odeint;
const double sigma = 10.0;
const double R = 28.0;
const double b = 8.0 / 3.0;
struct lorenz
{
template< class State , class Deriv >
void operator()( const State &x_ , Deriv &dxdt_ , double t ) const
{
typename boost::range_iterator< const State >::type x = boost::begin( x_ );
typename boost::range_iterator< Deriv >::type dxdt = boost::begin( dxdt_ );
dxdt[0] = sigma * ( x[1] - x[0] );
dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
dxdt[2] = -b * x[2] + x[0] * x[1];
}
};
struct printer
{
std::ostream &m_out ;
printer( std::ostream &out = std::cout ) : m_out( out ) { }
template< class State >
void operator()( const State &s )
{
m_out << s[0] << "\t" << s[1] << "\t" << s[2] << "\n";
}
};
int main( int argc , char **argv )
{
typedef boost::array< double , 3 > state_type;
runge_kutta4< state_type > stepper;
state_type x = {{ 10.0 , 10.0 , 10.0 }};
std::for_each( make_const_step_iterator( stepper , lorenz() , x , 0.0 , 0.01 ) ,
make_const_step_iterator( stepper , lorenz() , x , 10.0 , 0.01 ) , printer() );
return 0;
}

View File

@@ -45,5 +45,6 @@ test-suite "odeint"
[ run integrate_implicit.cpp ]
[ run generation.cpp ]
[ run trivial_state.cpp ]
[ run const_step_iterator.cpp ]
: <testing.launcher>valgrind
;
;

View File

@@ -0,0 +1,88 @@
/*
* const_step_ode_iterator.cpp
*
* Created on: Jun 26, 2012
* Author: karsten
*/
#define BOOST_TEST_MODULE odeint_const_step_iterator
#include <iostream>
#include <utility>
#include <algorithm>
#include <boost/test/unit_test.hpp>
#include <boost/static_assert.hpp>
#include <boost/array.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta4.hpp>
#include <boost/numeric/odeint/iterator/const_step_iterator.hpp>
using namespace boost::numeric::odeint;
const double sigma = 10.0;
const double R = 28.0;
const double b = 8.0 / 3.0;
//[ system_function_without_perturbations
struct lorenz
{
template< class State , class Deriv >
void operator()( const State &x_ , Deriv &dxdt_ , double t ) const
{
typename boost::range_iterator< const State >::type x = boost::begin( x_ );
typename boost::range_iterator< Deriv >::type dxdt = boost::begin( dxdt_ );
dxdt[0] = sigma * ( x[1] - x[0] );
dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
dxdt[2] = -b * x[2] + x[0] * x[1];
}
};
//]
BOOST_AUTO_TEST_SUITE( const_step_iterator_test )
BOOST_AUTO_TEST_CASE( empty_test )
{
}
struct printer
{
template< class State >
void operator()( const State &s )
{
std::cerr << "huhu" << std::endl;
}
};
BOOST_AUTO_TEST_CASE( compile_test )
{
typedef boost::array< double , 3 > state_type;
runge_kutta4< state_type > stepper;
state_type x = {{ 10.0 , 10.0 , 10.0 }};
std::for_each( make_const_step_iterator( stepper , lorenz() , x , 0.0 , 0.01 ) ,
make_const_step_iterator( stepper , lorenz() , x , 10.0 , 0.01 ) , printer() );
}
// BOOST_AUTO_TEST_CASE( test_is_pair )
// {
// typedef std::pair< int , int > type1;
// typedef std::pair< int& , int > type2;
// typedef std::pair< int , int& > type3;
// typedef std::pair< int& , int& > type4;
// typedef std::pair< const int , int > type5;
// typedef std::pair< const int& , int > type6;
// BOOST_STATIC_ASSERT(( is_pair< type1 >::value ));
// BOOST_STATIC_ASSERT(( is_pair< type2 >::value ));
// BOOST_STATIC_ASSERT(( is_pair< type3 >::value ));
// BOOST_STATIC_ASSERT(( is_pair< type4 >::value ));
// BOOST_STATIC_ASSERT(( is_pair< type5 >::value ));
// BOOST_STATIC_ASSERT(( is_pair< type6 >::value ));
// }
BOOST_AUTO_TEST_SUITE_END()