mirror of
https://github.com/boostorg/odeint.git
synced 2025-05-09 15:14:02 +00:00
fixes #139
This commit is contained in:
parent
9197519a2d
commit
720a926e45
27
include/boost/numeric/odeint/external/eigen/eigen.hpp
vendored
Normal file
27
include/boost/numeric/odeint/external/eigen/eigen.hpp
vendored
Normal file
@ -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 <boost/numeric/odeint/external/eigen/eigen_algebra.hpp>
|
||||
#include <boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp>
|
||||
#include <boost/numeric/odeint/external/eigen/eigen_resize.hpp>
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_EIGEN_EIGEN_HPP_INCLUDED
|
@ -71,6 +71,19 @@ operator/(const Eigen::MatrixBase<D1> &x1, const Eigen::MatrixBase<D2> &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
|
||||
|
||||
|
||||
|
49
include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp
vendored
Normal file
49
include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp
vendored
Normal file
@ -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
|
@ -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 )
|
||||
|
@ -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 )
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ project
|
||||
<library>/boost/test//boost_unit_test_framework
|
||||
<define>BOOST_ALL_NO_LIB=1
|
||||
<include>$(EIGEN_ROOT)
|
||||
<include>../../test
|
||||
<link>static
|
||||
# <cxxflags>-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 ]
|
||||
: <testing.launcher>valgrind
|
||||
;
|
||||
|
47
test_external/eigen/fail_integrate.cpp
Normal file
47
test_external/eigen/fail_integrate.cpp
Normal file
@ -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 <boost/config.hpp>
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MODULE odeint_dummy
|
||||
|
||||
#include <boost/numeric/odeint/integrate/integrate.hpp>
|
||||
#include <boost/numeric/odeint/external/eigen/eigen.hpp>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#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()
|
||||
|
69
test_external/eigen/integrate.cpp
Normal file
69
test_external/eigen/integrate.cpp
Normal file
@ -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 <boost/config.hpp>
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MODULE odeint_eigen_integrate
|
||||
|
||||
#include <boost/numeric/odeint/integrate/integrate.hpp>
|
||||
#include <boost/numeric/odeint/external/eigen/eigen.hpp>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#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()
|
Loading…
x
Reference in New Issue
Block a user