diff --git a/include/boost/numeric/odeint/external/eigen/eigen.hpp b/include/boost/numeric/odeint/external/eigen/eigen.hpp new file mode 100644 index 00000000..620acae5 --- /dev/null +++ b/include/boost/numeric/odeint/external/eigen/eigen.hpp @@ -0,0 +1,27 @@ +/* + [auto_generated] + boost/numeric/odeint/external/eigen/eigen.hpp + + [begin_description] + tba. + [end_description] + + Copyright 2009-2012 Karsten Ahnert + Copyright 2009-2012 Mario Mulansky + + 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_EXTERNAL_EIGEN_EIGEN_HPP_INCLUDED +#define BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_HPP_INCLUDED + + +#include +#include +#include + + +#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_HPP_INCLUDED diff --git a/include/boost/numeric/odeint/external/eigen/eigen_algebra.hpp b/include/boost/numeric/odeint/external/eigen/eigen_algebra.hpp index 6ca2026b..b4ee5c3b 100644 --- a/include/boost/numeric/odeint/external/eigen/eigen_algebra.hpp +++ b/include/boost/numeric/odeint/external/eigen/eigen_algebra.hpp @@ -71,6 +71,19 @@ operator/(const Eigen::MatrixBase &x1, const Eigen::MatrixBase &x2) { return x1.cwiseQuotient(x2); } + +template< typename D > +inline const +typename Eigen::CwiseUnaryOp< + typename Eigen::internal::scalar_abs_op< + typename Eigen::internal::traits< D >::Scalar > , + const D > +abs( const Eigen::MatrixBase< D > &m ) { + return m.cwiseAbs(); +} + + + } // end Eigen namespace diff --git a/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp b/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp new file mode 100644 index 00000000..6c8a3a27 --- /dev/null +++ b/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp @@ -0,0 +1,49 @@ +/* + [auto_generated] + boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp + + [begin_description] + tba. + [end_description] + + Copyright 2009-2012 Karsten Ahnert + Copyright 2009-2012 Mario Mulansky + + 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_EXTERNAL_EIGEN_EIGEN_ALGEBRA_DISPATCHER_HPP_INCLUDED +#define BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_ALGEBRA_DISPATCHER_HPP_INCLUDED + + +namespace boost { +namespace numeric { +namespace odeint { + + +template< class Derived > +struct algebra_dispatcher_sfinae< Derived , + typename boost::enable_if< typename boost::is_base_of< Eigen::MatrixBase< Derived > , Derived >::type >::type > +{ + typedef vector_space_algebra algebra_type; +}; + + +template < class Derived > +struct algebra_dispatcher_sfinae< Derived , + typename boost::enable_if< typename boost::is_base_of< Eigen::ArrayBase< Derived > , Derived >::type >::type > +{ + typedef vector_space_algebra algebra_type; +}; + + + +} // namespace odeint +} // namespace numeric +} // namespace boost + + +#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_ALGEBRA_DISPATCHER_HPP_INCLUDED diff --git a/include/boost/numeric/odeint/integrate/integrate.hpp b/include/boost/numeric/odeint/integrate/integrate.hpp index c02278a2..913f1ca1 100644 --- a/include/boost/numeric/odeint/integrate/integrate.hpp +++ b/include/boost/numeric/odeint/integrate/integrate.hpp @@ -48,7 +48,7 @@ integrate( System system , State &start_state , Time start_time , Time end_time return integrate_adaptive( stepper_type() , system , start_state , start_time , end_time , dt , observer ); } -template< class System , class State , class Time , class Observer , class Value > +template< class Value , class System , class State , class Time , class Observer > size_t integrate( System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer ) { @@ -68,6 +68,13 @@ size_t integrate( System system , State &start_state , Time start_time , Time en return integrate( system , start_state , start_time , end_time , dt , null_observer() ); } +template< class Value , class System , class State , class Time > +size_t integrate( System system , State &start_state , Time start_time , Time end_time , Time dt ) +{ + return integrate< Value >( system , start_state , start_time , end_time , dt , null_observer() ); +} + + /** * \fn integrate( System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer ) diff --git a/test/dummy_odes.hpp b/test/dummy_odes.hpp index 0797b276..7a92363f 100644 --- a/test/dummy_odes.hpp +++ b/test/dummy_odes.hpp @@ -55,6 +55,20 @@ struct constant_system_functor_fusion } }; +struct lorenz +{ + template< typename State , typename Deriv , typename Time > + void operator()( const State& x , Deriv& dxdt , const Time& t ) const + { + const Time sigma = 10.0; + const Time R = 28.0; + const Time b = 8.0 / 3.0; + 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]; + } +}; + template< class State , class Deriv , class Time > void constant_system_standard( const State &x , Deriv &dxdt , const Time t ) { diff --git a/test_external/eigen/Jamfile.v2 b/test_external/eigen/Jamfile.v2 index b508a0ea..489f67ce 100644 --- a/test_external/eigen/Jamfile.v2 +++ b/test_external/eigen/Jamfile.v2 @@ -18,6 +18,7 @@ project /boost/test//boost_unit_test_framework BOOST_ALL_NO_LIB=1 $(EIGEN_ROOT) + ../../test static # -D_SCL_SECURE_NO_WARNINGS ; @@ -29,5 +30,7 @@ test-suite "odeint" [ run resize.cpp ] [ run runge_kutta4.cpp ] [ run runge_kutta_dopri5.cpp ] + [ run integrate.cpp ] + [ compile-fail fail_integrate.cpp ] : valgrind ; diff --git a/test_external/eigen/fail_integrate.cpp b/test_external/eigen/fail_integrate.cpp new file mode 100644 index 00000000..4c71b018 --- /dev/null +++ b/test_external/eigen/fail_integrate.cpp @@ -0,0 +1,47 @@ +/* + [auto_generated] + fail_integrate.cpp + + [begin_description] + tba. + [end_description] + + Copyright 2009-2012 Karsten Ahnert + Copyright 2009-2012 Mario Mulansky + + 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 +#ifdef BOOST_MSVC + #pragma warning(disable:4996) +#endif + +#define BOOST_TEST_MODULE odeint_dummy + +#include +#include + +#include + +#include "dummy_odes.hpp" + +using namespace boost::unit_test; +using namespace boost::numeric::odeint; + + +BOOST_AUTO_TEST_SUITE( eigen_fail_integrate ) + +BOOST_AUTO_TEST_CASE( test ) +{ + typedef Eigen::Matrix< double , 1 , 1 > state_type; + state_type x; + x[0] = 10.0; + double t_start = 0.0 , t_end = 1.0 , dt = 0.1; + integrate( constant_system_functor_standard() , x , t_start , t_end , dt ); +} + +BOOST_AUTO_TEST_SUITE_END() + diff --git a/test_external/eigen/integrate.cpp b/test_external/eigen/integrate.cpp new file mode 100644 index 00000000..c64496a8 --- /dev/null +++ b/test_external/eigen/integrate.cpp @@ -0,0 +1,69 @@ +/* + [auto_generated] + integrate.cpp + + [begin_description] + tba. + [end_description] + + Copyright 2009-2012 Karsten Ahnert + Copyright 2009-2012 Mario Mulansky + + 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 +#ifdef BOOST_MSVC + #pragma warning(disable:4996) +#endif + +#define BOOST_TEST_MODULE odeint_eigen_integrate + +#include +#include + +#include + +#include "dummy_odes.hpp" + + +using namespace boost::unit_test; +using namespace boost::numeric::odeint; + + +BOOST_AUTO_TEST_SUITE( eigen_integrate ) + +BOOST_AUTO_TEST_CASE( test_const_sys ) +{ + typedef Eigen::Matrix< double , 1 , 1 > state_type; + state_type x; + x[0] = 10.0; + double t_start = 0.0 , t_end = 1.0 , dt = 0.1; + integrate< double >( constant_system_functor_standard() , x , t_start , t_end , dt ); + BOOST_CHECK_CLOSE( x[0] , 11.0 , 1.0e-13 ); +} + +BOOST_AUTO_TEST_CASE( test_lorenz ) +{ + typedef Eigen::Matrix< double , 3 , 1 > state_type; + state_type x; + x[0] = 10.0; + x[1] = 10.0; + x[2] = 10.0; + double t_start = 0.0 , t_end = 1000.0 , dt = 0.1; + integrate< double >( lorenz() , x , t_start , t_end , dt ); + + std::vector< double > x2( 3 ); + x2[0] = 10.0; + x2[1] = 10.0; + x2[2] = 10.0; + integrate( lorenz() , x2 , t_start , t_end , dt ); + + BOOST_CHECK_CLOSE( x[0] , x2[0] , 1.0e-13 ); + BOOST_CHECK_CLOSE( x[1] , x2[1] , 1.0e-13 ); + BOOST_CHECK_CLOSE( x[2] , x2[2] , 1.0e-13 ); +} + +BOOST_AUTO_TEST_SUITE_END()