diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/numeric/odeint/test/regression | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/numeric/odeint/test/regression')
5 files changed, 374 insertions, 0 deletions
diff --git a/src/boost/libs/numeric/odeint/test/regression/Jamfile.v2 b/src/boost/libs/numeric/odeint/test/regression/Jamfile.v2 new file mode 100644 index 00000000..bb085f46 --- /dev/null +++ b/src/boost/libs/numeric/odeint/test/regression/Jamfile.v2 @@ -0,0 +1,31 @@ +# Copyright 2012 Karsten Ahnert +# Copyright 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) + +# bring in rules for testing + + +import testing ; + +use-project boost : $(BOOST_ROOT) ; + +project + : requirements + <library>/boost/test//boost_unit_test_framework + <define>BOOST_ALL_NO_LIB=1 + <include>../../include + <link>static + <toolset>clang:<cxxflags>-Wno-unused-variable + +# <cxxflags>-D_SCL_SECURE_NO_WARNINGS + ; + +test-suite "odeint" + : + [ run regression_147.cpp ] + [ compile regression_149.cpp ] + [ run regression_168.cpp ] + [ run regression_189.cpp ] + : <testing.launcher>valgrind + ; diff --git a/src/boost/libs/numeric/odeint/test/regression/regression_147.cpp b/src/boost/libs/numeric/odeint/test/regression/regression_147.cpp new file mode 100644 index 00000000..7373782d --- /dev/null +++ b/src/boost/libs/numeric/odeint/test/regression/regression_147.cpp @@ -0,0 +1,88 @@ +/* + + [begin_description] + Test case for issue 147 + [end_description] + + Copyright 2011-2015 Karsten Ahnert + Copyright 2011-2015 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) + */ + + +// disable checked iterator warning for msvc + +#include <boost/config.hpp> +#ifdef BOOST_MSVC + #pragma warning(disable:4996) +#endif + +#define BOOST_TEST_MODULE odeint_regression_147 + +#include <utility> + +#include <boost/array.hpp> + +#include <boost/test/unit_test.hpp> + +#include <boost/mpl/vector.hpp> + +#include <boost/numeric/odeint.hpp> + +using namespace boost::unit_test; +using namespace boost::numeric::odeint; +namespace mpl = boost::mpl; + +typedef double state_type; + +void rhs( const state_type &x , state_type &dxdt , const double t ) +{ + dxdt = 1; +} + + +template<class Stepper, class InitStepper> +struct perform_init_test +{ + void operator()( void ) + { + double t = 0; + const double dt = 0.1; + + state_type x = 0; + + Stepper stepper; + InitStepper init_stepper; + stepper.initialize( init_stepper, rhs, x, t, dt ); + + // ab-stepper needs order-1 init steps: t and x should be (order-1)*dt + BOOST_CHECK_CLOSE( t , (stepper.order()-1)*dt , 1E-16 ); + BOOST_CHECK_CLOSE( x, ( stepper.order() - 1 ) * dt, 2E-14 ); + } +}; + +typedef mpl::vector< + euler< state_type > , + modified_midpoint< state_type > , + runge_kutta4< state_type > , + runge_kutta4_classic< state_type > , + runge_kutta_cash_karp54_classic< state_type > , + runge_kutta_cash_karp54< state_type > , + runge_kutta_dopri5< state_type > , + runge_kutta_fehlberg78< state_type > + > runge_kutta_steppers; + + +BOOST_AUTO_TEST_SUITE( regression_147_test ) + +BOOST_AUTO_TEST_CASE_TEMPLATE( init_test , InitStepper, + runge_kutta_steppers ) +{ + perform_init_test< adams_bashforth<4, state_type>, InitStepper > tester; + tester(); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/boost/libs/numeric/odeint/test/regression/regression_149.cpp b/src/boost/libs/numeric/odeint/test/regression/regression_149.cpp new file mode 100644 index 00000000..2790d683 --- /dev/null +++ b/src/boost/libs/numeric/odeint/test/regression/regression_149.cpp @@ -0,0 +1,93 @@ +/* + + [begin_description] + Test case for issue 149: + Error C2582 with msvc-10 when using iterator-based integration + [end_description] + + Copyright 2011-2015 Karsten Ahnert + Copyright 2011-2015 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) + */ + + +// disable checked iterator warning for msvc + +#include <boost/config.hpp> +#ifdef BOOST_MSVC + #pragma warning(disable:4996) +#endif + +#define BOOST_TEST_MODULE odeint_regression_147 + +#include <utility> +#include <iostream> + +#include <boost/test/unit_test.hpp> + +#include <boost/mpl/vector.hpp> +#include <boost/range/algorithm/find_if.hpp> + +#include <boost/numeric/odeint.hpp> + +using namespace boost::unit_test; +using namespace boost::numeric::odeint; +namespace mpl = boost::mpl; + +typedef std::vector<double> state_type; + +void rhs( const state_type &x , state_type &dxdt , const double t ) +{ +} + + +template<class Stepper> +struct perform_test +{ + void operator()( void ) + { + bulirsch_stoer< state_type > stepper( 1e-9, 0.0, 0.0, 0.0 ); + state_type x( 3, 10.0 ); + + print( boost::find_if( + make_adaptive_time_range( stepper, rhs, x, 0.0, 1.0, 0.01 ), + pred ) ); + + } + + static bool pred( const std::pair< const state_type &, double > &x ) + { + return ( x.first[0] < 0.0 ); + } + + template<class Iterator> + void print( Iterator iter ) + { + std::cout << iter->second << "\t" << iter->first[0] << "\t" + << iter->first[1] << "\t" << iter->first[2] << "\n"; + } +}; + +typedef mpl::vector< + euler< state_type > , + runge_kutta4< state_type > , + runge_kutta_cash_karp54< state_type > , + runge_kutta_dopri5< state_type > , + runge_kutta_fehlberg78< state_type > , + bulirsch_stoer< state_type > + > steppers; + + +BOOST_AUTO_TEST_SUITE( regression_147_test ) + +BOOST_AUTO_TEST_CASE_TEMPLATE( regression_147_test , Stepper, + steppers ) +{ + perform_test< Stepper > tester; + tester(); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/boost/libs/numeric/odeint/test/regression/regression_168.cpp b/src/boost/libs/numeric/odeint/test/regression/regression_168.cpp new file mode 100644 index 00000000..8349261a --- /dev/null +++ b/src/boost/libs/numeric/odeint/test/regression/regression_168.cpp @@ -0,0 +1,90 @@ +/* + + [begin_description] + Test case for issue 149: + Error C2582 with msvc-10 when using iterator-based integration + [end_description] + + Copyright 2011-2015 Karsten Ahnert + Copyright 2011-2015 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) + */ + + +// disable checked iterator warning for msvc + +#include <boost/config.hpp> +#ifdef BOOST_MSVC + #pragma warning(disable:4996) +#endif + +#define BOOST_TEST_MODULE odeint_regression_147 + +#include <utility> +#include <iostream> + +#include <boost/array.hpp> + +#include <boost/test/unit_test.hpp> + +#include <boost/mpl/vector.hpp> +#include <boost/range/algorithm/find_if.hpp> + +#include <boost/numeric/odeint.hpp> +#include <boost/numeric/odeint/algebra/fusion_algebra.hpp> +#include <boost/numeric/odeint/algebra/fusion_algebra_dispatcher.hpp> + + +#include <boost/units/systems/si/length.hpp> +#include <boost/units/systems/si/time.hpp> +#include <boost/units/systems/si/velocity.hpp> +#include <boost/units/systems/si/acceleration.hpp> +#include <boost/units/systems/si/io.hpp> + +#include <boost/fusion/container.hpp> + + +using namespace boost::unit_test; +using namespace boost::numeric::odeint; +namespace mpl = boost::mpl; + +namespace fusion = boost::fusion; +namespace units = boost::units; +namespace si = boost::units::si; + +typedef units::quantity< si::time , double > time_type; +typedef units::quantity< si::length , double > length_type; +typedef units::quantity< si::velocity , double > velocity_type; +typedef units::quantity< si::acceleration , double > acceleration_type; +typedef units::quantity< si::frequency , double > frequency_type; + +typedef fusion::vector< length_type , velocity_type > state_type; +typedef fusion::vector< velocity_type , acceleration_type > deriv_type; + + +struct oscillator +{ + frequency_type m_omega; + + oscillator( const frequency_type &omega = 1.0 * si::hertz ) : m_omega( omega ) { } + + void operator()( const state_type &x , deriv_type &dxdt , time_type t ) const + { + fusion::at_c< 0 >( dxdt ) = fusion::at_c< 1 >( x ); + fusion::at_c< 1 >( dxdt ) = - m_omega * m_omega * fusion::at_c< 0 >( x ); + } +}; + + +BOOST_AUTO_TEST_CASE( regression_168 ) +{ + typedef runge_kutta_dopri5< state_type , double , deriv_type , time_type > stepper_type; + + state_type x( 1.0 * si::meter , 0.0 * si::meter_per_second ); + + integrate_const( make_dense_output( 1.0e-6 , 1.0e-6 , stepper_type() ) , oscillator( 2.0 * si::hertz ) , + x , 0.0 * si::second , 100.0 * si::second , 0.1 * si::second); +}
\ No newline at end of file diff --git a/src/boost/libs/numeric/odeint/test/regression/regression_189.cpp b/src/boost/libs/numeric/odeint/test/regression/regression_189.cpp new file mode 100644 index 00000000..54530072 --- /dev/null +++ b/src/boost/libs/numeric/odeint/test/regression/regression_189.cpp @@ -0,0 +1,72 @@ +/* + + [begin_description] + Test case for issue 189: + Controlled Rosenbrock stepper fails to increase step size + [end_description] + + Copyright 2016 Karsten Ahnert + Copyright 2016 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) + */ + +#define BOOST_TEST_MODULE odeint_regression_189 + +#include <boost/numeric/odeint.hpp> + +#include <boost/test/unit_test.hpp> +#include <boost/phoenix/core.hpp> +#include <boost/phoenix/operator.hpp> + +using namespace boost::numeric::odeint; +namespace phoenix = boost::phoenix; + +typedef boost::numeric::ublas::vector< double > vector_type; +typedef boost::numeric::ublas::matrix< double > matrix_type; + +struct stiff_system +{ + void operator()( const vector_type &x , vector_type &dxdt , double /* t */ ) + { + dxdt[ 0 ] = -101.0 * x[ 0 ] - 100.0 * x[ 1 ]; + dxdt[ 1 ] = x[ 0 ]; + } +}; + +struct stiff_system_jacobi +{ + void operator()( const vector_type & /* x */ , matrix_type &J , const double & /* t */ , vector_type &dfdt ) + { + J( 0 , 0 ) = -101.0; + J( 0 , 1 ) = -100.0; + J( 1 , 0 ) = 1.0; + J( 1 , 1 ) = 0.0; + dfdt[0] = 0.0; + dfdt[1] = 0.0; + } +}; + + +BOOST_AUTO_TEST_CASE( regression_189 ) +{ + vector_type x( 2 , 1.0 ); + + size_t num_of_steps = integrate_const( make_dense_output< rosenbrock4< double > >( 1.0e-6 , 1.0e-6 ) , + std::make_pair( stiff_system() , stiff_system_jacobi() ) , + x , 0.0 , 50.0 , 0.01 , + std::cout << phoenix::arg_names::arg2 << " " << phoenix::arg_names::arg1[0] << "\n" ); + // regression: number of steps should be 74 + size_t num_of_steps_expected = 74; + BOOST_CHECK_EQUAL( num_of_steps , num_of_steps_expected ); + + vector_type x2( 2 , 1.0 ); + + size_t num_of_steps2 = integrate_const( make_dense_output< runge_kutta_dopri5< vector_type > >( 1.0e-6 , 1.0e-6 ) , + stiff_system() , x2 , 0.0 , 50.0 , 0.01 , + std::cout << phoenix::arg_names::arg2 << " " << phoenix::arg_names::arg1[0] << "\n" ); + num_of_steps_expected = 1531; + BOOST_CHECK_EQUAL( num_of_steps2 , num_of_steps_expected ); +} |