From 572091735f081a07665bf4e20ea06b9d6bed2605 Mon Sep 17 00:00:00 2001 From: Mario Mulansky Date: Wed, 27 Jun 2012 21:45:00 +0200 Subject: [PATCH 01/12] css update --- doc/boostbook.css | 9 ++++++++- doc/index.html | 8 +++++--- libs/numeric/odeint/doc/html/boostbook.css | 9 ++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/doc/boostbook.css b/doc/boostbook.css index 42e8996d..d8f7bf4d 100644 --- a/doc/boostbook.css +++ b/doc/boostbook.css @@ -73,7 +73,14 @@ } h1 { font-size: 140%; } - h2 { font-weight: bold; font-size: 140%; } + h2 { +/* changed by Mario Mulansky to show logo instead of title */ +height: 127px; +background: white url(logo.jpg) left no-repeat; +text-indent: -999px; +/* end change */ +font-weight: bold; font-size: 140%; +} h3 { font-weight: bold; font-size: 130%; } h4 { font-weight: bold; font-size: 120%; } h5 { font-weight: normal; font-style: italic; font-size: 110%; } diff --git a/doc/index.html b/doc/index.html index f3205b58..f079007d 100644 --- a/doc/index.html +++ b/doc/index.html @@ -3,11 +3,13 @@ Chapter 1. Boost.Numeric.Odeint - + +
+
Next
@@ -22,7 +24,7 @@
-

+

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)

@@ -94,7 +96,7 @@
- +

Last revised: June 25, 2012 at 12:11:49 GMT

Last revised: June 25, 2012 at 19:22:58 GMT


diff --git a/libs/numeric/odeint/doc/html/boostbook.css b/libs/numeric/odeint/doc/html/boostbook.css index 42e8996d..d8f7bf4d 100644 --- a/libs/numeric/odeint/doc/html/boostbook.css +++ b/libs/numeric/odeint/doc/html/boostbook.css @@ -73,7 +73,14 @@ } h1 { font-size: 140%; } - h2 { font-weight: bold; font-size: 140%; } + h2 { +/* changed by Mario Mulansky to show logo instead of title */ +height: 127px; +background: white url(logo.jpg) left no-repeat; +text-indent: -999px; +/* end change */ +font-weight: bold; font-size: 140%; +} h3 { font-weight: bold; font-size: 130%; } h4 { font-weight: bold; font-size: 120%; } h5 { font-weight: normal; font-style: italic; font-size: 110%; } From 6b3c6bc47a55eb4670aade14249197612895ad7b Mon Sep 17 00:00:00 2001 From: Mario Mulansky Date: Wed, 27 Jun 2012 22:54:08 +0200 Subject: [PATCH 02/12] checked value/time types in bulirsch stoer --- .../numeric/odeint/stepper/bulirsch_stoer.hpp | 54 +++++++------- .../stepper/bulirsch_stoer_dense_out.hpp | 72 ++++++++++--------- .../odeint/stepper/modified_midpoint.hpp | 4 +- .../odeint/test/stepper_with_units.cpp | 6 +- 4 files changed, 72 insertions(+), 64 deletions(-) diff --git a/boost/numeric/odeint/stepper/bulirsch_stoer.hpp b/boost/numeric/odeint/stepper/bulirsch_stoer.hpp index bb5db765..bd5c35c5 100644 --- a/boost/numeric/odeint/stepper/bulirsch_stoer.hpp +++ b/boost/numeric/odeint/stepper/bulirsch_stoer.hpp @@ -71,7 +71,8 @@ public: typedef bulirsch_stoer< State , Value , Deriv , Time , Algebra , Operations , Resizer > controlled_error_bs_type; - typedef std::vector< time_type > value_vector; + typedef std::vector< value_type > value_vector; + typedef std::vector< time_type > time_vector; typedef std::vector< value_vector > value_matrix; typedef std::vector< size_t > int_vector; typedef std::vector< wrapped_state_type > state_table_type; @@ -80,21 +81,22 @@ public: bulirsch_stoer( - time_type eps_abs = 1E-6 , time_type eps_rel = 1E-6 , - time_type factor_x = 1.0 , time_type factor_dxdt = 1.0 ) + value_type eps_abs = 1E-6 , value_type eps_rel = 1E-6 , + value_type factor_x = 1.0 , value_type factor_dxdt = 1.0 ) : m_error_checker( eps_abs , eps_rel , factor_x, factor_dxdt ) , m_midpoint() , m_last_step_rejected( false ) , m_first( true ) , - m_dt_last( 1.0E30 ) , m_t_last() , + /* , m_t_last() , m_current_k_opt() , m_algebra() , m_dxdt_resizer() , m_xnew_resizer() , m_resizer() , - m_xnew() , m_err() , m_dxdt() , + m_xnew() , m_err() , m_dxdt() ,*/ m_interval_sequence( m_k_max+1 ) , m_coeff( m_k_max+1 ) , m_cost( m_k_max+1 ) , m_table( m_k_max ) , STEPFAC1( 0.65 ) , STEPFAC2( 0.94 ) , STEPFAC3( 0.02 ) , STEPFAC4( 4.0 ) , KFAC1( 0.8 ) , KFAC2( 0.9 ) { + //m_dt_last = 1.0E30; for( unsigned short i = 0; i < m_k_max+1; i++ ) { m_interval_sequence[i] = 2 * (i+1); @@ -105,13 +107,13 @@ public: m_coeff[i].resize(i); for( size_t k = 0 ; k < i ; ++k ) { - const time_type r = static_cast< time_type >( m_interval_sequence[i] ) / static_cast< time_type >( m_interval_sequence[k] ); - m_coeff[i][k] = 1.0 / ( r*r - static_cast< time_type >( 1.0 ) ); // coefficients for extrapolation + const value_type r = static_cast< value_type >( m_interval_sequence[i] ) / static_cast< value_type >( m_interval_sequence[k] ); + m_coeff[i][k] = 1.0 / ( r*r - static_cast< value_type >( 1.0 ) ); // coefficients for extrapolation //std::cout << i << "," << k << " " << m_coeff[i][k] << '\t' ; } //std ::cout << std::endl; // crude estimate of optimal order - const time_type logfact( -log10( std::max( eps_rel , 1.0E-12 ) ) * 0.6 + 0.5 ); + const value_type logfact( -log10( std::max( eps_rel , 1.0E-12 ) ) * 0.6 + 0.5 ); m_current_k_opt = std::max( 1 , std::min( static_cast( m_k_max-1 ) , static_cast( logfact ) )); //m_current_k_opt = m_k_max - 1; //std::cout << m_cost[i] << std::endl; @@ -172,7 +174,7 @@ public: template< class System , class StateIn , class DerivIn , class StateOut > controlled_step_result try_step( System system , const StateIn &in , const DerivIn &dxdt , time_type &t , StateOut &out , time_type &dt ) { - static const time_type val1( static_cast< time_type >( 1.0 ) ); + static const value_type val1( 1.0 ); typename odeint::unwrap_reference< System >::type &sys = system; if( m_resizer.adjust_size( in , detail::bind( &controlled_error_bs_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) ) ) @@ -187,7 +189,7 @@ public: bool reject( true ); - value_vector h_opt( m_k_max+1 ); + time_vector h_opt( m_k_max+1 ); value_vector work( m_k_max+1 ); //std::cout << "t=" << t <<", dt=" << dt << "(" << m_dt_last << ")" << ", k_opt=" << m_current_k_opt << std::endl; @@ -208,8 +210,8 @@ public: extrapolate( k , m_table , m_coeff , out ); // get error estimate m_algebra.for_each3( m_err.m_v , out , m_table[0].m_v , - typename operations_type::template scale_sum2< time_type , time_type >( val1 , -val1 ) ); - const time_type error = m_error_checker.error( m_algebra , in , dxdt , m_err.m_v , dt ); + typename operations_type::template scale_sum2< value_type , value_type >( val1 , -val1 ) ); + const value_type error = m_error_checker.error( m_algebra , in , dxdt , m_err.m_v , dt ); h_opt[k] = calc_h_opt( dt , error , k ); work[k] = m_cost[k]/h_opt[k]; //std::cout << '\t' << "h_opt=" << h_opt[k] << ", work=" << work[k] << std::endl; @@ -225,7 +227,8 @@ public: { // leave order as is (except we were in first round) m_current_k_opt = std::min( static_cast(m_k_max)-1 , std::max( 2 , static_cast(k)+1 ) ); - new_h = h_opt[k] * m_cost[k+1]/m_cost[k]; + new_h = h_opt[k]; + new_h *= m_cost[k+1]/m_cost[k]; } else { m_current_k_opt = std::min( static_cast(m_k_max)-1 , std::max( 2 , static_cast(k) ) ); new_h = h_opt[k]; @@ -253,7 +256,8 @@ public: else if( (work[k] < KFAC2*work[k-1]) && !m_last_step_rejected ) { m_current_k_opt = std::min( static_cast(m_k_max-1) , static_cast(m_current_k_opt)+1 ); - new_h = h_opt[k]*m_cost[m_current_k_opt]/m_cost[k]; + new_h = h_opt[k]; + new_h *= m_cost[m_current_k_opt]/m_cost[k]; //std::cout << new_h << std::endl; } else new_h = h_opt[m_current_k_opt]; @@ -369,23 +373,23 @@ private: //polynomial extrapolation, see http://www.nr.com/webnotes/nr3web21.pdf { //std::cout << "extrapolate k=" << k << ":" << std::endl; - static const time_type val1 = static_cast< time_type >( 1.0 ); + static const value_type val1 = static_cast< value_type >( 1.0 ); for( int j=k-1 ; j>0 ; --j ) { //std::cout << '\t' << m_coeff[k][j]; m_algebra.for_each3( table[j-1].m_v , table[j].m_v , table[j-1].m_v , - typename operations_type::template scale_sum2< time_type , time_type >( val1 + coeff[k][j] , -coeff[k][j] ) ); + typename operations_type::template scale_sum2< value_type , value_type >( val1 + coeff[k][j] , -coeff[k][j] ) ); } //std::cout << std::endl << m_coeff[k][0] << std::endl; m_algebra.for_each3( xest , table[0].m_v , xest , - typename operations_type::template scale_sum2< time_type , time_type >( val1 + coeff[k][0] , -coeff[k][0]) ); + typename operations_type::template scale_sum2< value_type , value_type >( val1 + coeff[k][0] , -coeff[k][0]) ); } time_type calc_h_opt( time_type h , value_type error , size_t k ) const { - time_type expo=1.0/(2*k+1); - time_type facmin = std::pow( STEPFAC3 , expo ); - time_type fac; + value_type expo=1.0/(2*k+1); + value_type facmin = std::pow( STEPFAC3 , expo ); + value_type fac; if (error == 0.0) fac=1.0/facmin; else @@ -397,7 +401,7 @@ private: return h*fac; } - controlled_step_result set_k_opt( size_t k , const value_vector &work , const value_vector &h_opt , time_type &dt ) + controlled_step_result set_k_opt( size_t k , const value_vector &work , const time_vector &h_opt , time_type &dt ) { //std::cout << "finding k_opt..." << std::endl; if( k == 1 ) @@ -433,18 +437,18 @@ private: return ( (k == m_current_k_opt) || (k == m_current_k_opt+1) ); } - bool should_reject( time_type error , size_t k ) const + bool should_reject( value_type error , size_t k ) const { if( (k == m_current_k_opt-1) ) { - const time_type d = m_interval_sequence[m_current_k_opt] * m_interval_sequence[m_current_k_opt+1] / + const value_type d = m_interval_sequence[m_current_k_opt] * m_interval_sequence[m_current_k_opt+1] / (m_interval_sequence[0]*m_interval_sequence[0]); //step will fail, criterion 17.3.17 in NR return ( error > d*d ); } else if( k == m_current_k_opt ) { - const time_type d = m_interval_sequence[m_current_k_opt] / m_interval_sequence[0]; + const value_type d = m_interval_sequence[m_current_k_opt] / m_interval_sequence[0]; return ( error > d*d ); } else return error > 1.0; @@ -477,7 +481,7 @@ private: state_table_type m_table; // sequence of states for extrapolation - const time_type STEPFAC1 , STEPFAC2 , STEPFAC3 , STEPFAC4 , KFAC1 , KFAC2; + const value_type STEPFAC1 , STEPFAC2 , STEPFAC3 , STEPFAC4 , KFAC1 , KFAC2; }; diff --git a/boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp b/boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp index 0cbc400d..ba5f970e 100644 --- a/boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp +++ b/boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp @@ -87,7 +87,8 @@ public: typedef bulirsch_stoer_dense_out< State , Value , Deriv , Time , Algebra , Operations , Resizer > controlled_error_bs_type; - typedef std::vector< time_type > value_vector; + typedef std::vector< value_type > value_vector; + typedef std::vector< time_type > time_vector; typedef std::vector< value_vector > value_matrix; typedef std::vector< size_t > int_vector; typedef std::vector< wrapped_state_type > state_vector_type; @@ -100,18 +101,18 @@ public: bulirsch_stoer_dense_out( - time_type eps_abs = 1E-6 , time_type eps_rel = 1E-6 , - time_type factor_x = 1.0 , time_type factor_dxdt = 1.0 , + value_type eps_abs = 1E-6 , value_type eps_rel = 1E-6 , + value_type factor_x = 1.0 , value_type factor_dxdt = 1.0 , bool control_interpolation = false ) : m_error_checker( eps_abs , eps_rel , factor_x, factor_dxdt ) , m_midpoint() , m_control_interpolation( control_interpolation) , m_last_step_rejected( false ) , m_first( true ) , - m_t() , m_dt() , + /*m_t() , m_dt() , m_dt_last( 1.0E30 ) , m_t_last() , m_current_k_opt() , m_k_final(0) , m_algebra() , m_resizer() , - m_x1() , m_x2() , m_dxdt1() , m_dxdt2() , m_err() , + m_x1() , m_x2() , m_dxdt1() , m_dxdt2() , m_err() ,*/ m_current_state_x1( true ) , m_error( m_k_max ) , m_interval_sequence( m_k_max+1 ) , @@ -134,13 +135,13 @@ public: m_coeff[i].resize(i); for( size_t k = 0 ; k < i ; ++k ) { - const time_type r = static_cast< time_type >( m_interval_sequence[i] ) / static_cast< time_type >( m_interval_sequence[k] ); - m_coeff[i][k] = 1.0 / ( r*r - static_cast< time_type >( 1.0 ) ); // coefficients for extrapolation + const value_type r = static_cast< value_type >( m_interval_sequence[i] ) / static_cast< value_type >( m_interval_sequence[k] ); + m_coeff[i][k] = 1.0 / ( r*r - static_cast< value_type >( 1.0 ) ); // coefficients for extrapolation //std::cout << i << "," << k << " " << m_coeff[i][k] << '\t' ; } //std ::cout << std::endl; // crude estimate of optimal order - const time_type logfact( -log10( std::max( eps_rel , 1.0E-12 ) ) * 0.6 + 0.5 ); + const value_type logfact( -log10( std::max( eps_rel , 1.0E-12 ) ) * 0.6 + 0.5 ); m_current_k_opt = std::max( 1 , std::min( static_cast( m_k_max-1 ) , static_cast( logfact ) )); //m_current_k_opt = m_k_max - 1; //std::cout << m_cost[i] << std::endl; @@ -173,7 +174,7 @@ public: template< class System , class StateIn , class DerivIn , class StateOut , class DerivOut > controlled_step_result try_step( System system , const StateIn &in , const DerivIn &dxdt , time_type &t , StateOut &out , DerivOut &dxdt_new , time_type &dt ) { - static const time_type val1( static_cast< time_type >( 1.0 ) ); + static const value_type val1( 1.0 ); typename odeint::unwrap_reference< System >::type &sys = system; // if( m_resizer.adjust_size( in , detail::bind( &controlled_error_bs_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) ) ) @@ -183,7 +184,7 @@ public: bool reject( true ); - value_vector h_opt( m_k_max+1 ); + time_vector h_opt( m_k_max+1 ); value_vector work( m_k_max+1 ); m_k_final = 0; @@ -205,8 +206,8 @@ public: extrapolate( k , m_table , m_coeff , out ); // get error estimate m_algebra.for_each3( m_err.m_v , out , m_table[0].m_v , - typename operations_type::template scale_sum2< time_type , time_type >( val1 , -val1 ) ); - const time_type error = m_error_checker.error( m_algebra , in , dxdt , m_err.m_v , dt ); + typename operations_type::template scale_sum2< value_type , value_type >( val1 , -val1 ) ); + const value_type error = m_error_checker.error( m_algebra , in , dxdt , m_err.m_v , dt ); h_opt[k] = calc_h_opt( dt , error , k ); work[k] = m_cost[k]/h_opt[k]; //std::cout << '\t' << "h_opt=" << h_opt[k] << ", work=" << work[k] << std::endl; @@ -412,15 +413,15 @@ private: void extrapolate( size_t k , StateVector &table , const value_matrix &coeff , StateInOut &xest , size_t order_start_index = 0 ) //polynomial extrapolation, see http://www.nr.com/webnotes/nr3web21.pdf { - static const time_type val1 = static_cast< time_type >( 1.0 ); + static const value_type val1( 1.0 ); for( int j=k-1 ; j>0 ; --j ) { m_algebra.for_each3( table[j-1].m_v , table[j].m_v , table[j-1].m_v , - typename operations_type::template scale_sum2< time_type , time_type >( val1 + coeff[k + order_start_index][j + order_start_index] , + typename operations_type::template scale_sum2< value_type , value_type >( val1 + coeff[k + order_start_index][j + order_start_index] , -coeff[k + order_start_index][j + order_start_index] ) ); } m_algebra.for_each3( xest , table[0].m_v , xest , - typename operations_type::template scale_sum2< time_type , time_type >( val1 + coeff[k + order_start_index][0 + order_start_index] , + typename operations_type::template scale_sum2< value_type , value_type >( val1 + coeff[k + order_start_index][0 + order_start_index] , -coeff[k + order_start_index][0 + order_start_index]) ); } @@ -431,25 +432,25 @@ private: { // result is written into table[0] //std::cout << "extrapolate k=" << k << ":" << std::endl; - static const time_type val1 = static_cast< time_type >( 1.0 ); + static const value_type val1( 1.0 ); for( int j=k ; j>1 ; --j ) { //std::cout << '\t' << coeff[k + order_start_index][j + order_start_index - 1]; m_algebra.for_each3( table[j-1].m_v , table[j].m_v , table[j-1].m_v , - typename operations_type::template scale_sum2< time_type , time_type >( val1 + coeff[k + order_start_index][j + order_start_index - 1] , + typename operations_type::template scale_sum2< value_type , value_type >( val1 + coeff[k + order_start_index][j + order_start_index - 1] , -coeff[k + order_start_index][j + order_start_index - 1] ) ); } //std::cout << std::endl << coeff[k + order_start_index][order_start_index] << std::endl; m_algebra.for_each3( table[0].m_v , table[1].m_v , table[0].m_v , - typename operations_type::template scale_sum2< time_type , time_type >( val1 + coeff[k + order_start_index][order_start_index] , + typename operations_type::template scale_sum2< value_type , value_type >( val1 + coeff[k + order_start_index][order_start_index] , -coeff[k + order_start_index][order_start_index]) ); } time_type calc_h_opt( time_type h , value_type error , size_t k ) const { - time_type expo=1.0/(m_interval_sequence[k-1]); - time_type facmin = std::pow( STEPFAC3 , expo ); - time_type fac; + value_type expo=1.0/(m_interval_sequence[k-1]); + value_type facmin = std::pow( STEPFAC3 , expo ); + value_type fac; if (error == 0.0) fac=1.0/facmin; else @@ -468,18 +469,18 @@ private: return ( (k == m_current_k_opt) || (k == m_current_k_opt+1) ); } - bool should_reject( time_type error , size_t k ) const + bool should_reject( value_type error , size_t k ) const { if( (k == m_current_k_opt-1) ) { - const time_type d = m_interval_sequence[m_current_k_opt] * m_interval_sequence[m_current_k_opt+1] / + const value_type d = m_interval_sequence[m_current_k_opt] * m_interval_sequence[m_current_k_opt+1] / (m_interval_sequence[0]*m_interval_sequence[0]); //step will fail, criterion 17.3.17 in NR return ( error > d*d ); } else if( k == m_current_k_opt ) { - const time_type d = m_interval_sequence[m_current_k_opt+1] / m_interval_sequence[0]; + const value_type d = m_interval_sequence[m_current_k_opt+1] / m_interval_sequence[0]; return ( error > d*d ); } else return error > 1.0; @@ -500,8 +501,9 @@ private: // calculate finite difference approximations to derivatives at the midpoint for( int j = 0 ; j<=k ; j++ ) { - const time_type d = m_interval_sequence[j] / static_cast(2*dt); - time_type f = 1.0; //factor 1/2 here because our interpolation interval has length 2 !!! + /* not working with boost units... */ + const value_type d = m_interval_sequence[j] / ( 2*dt ); + value_type f = 1.0; //factor 1/2 here because our interpolation interval has length 2 !!! for( int kappa = 0 ; kappa <= 2*j+1 ; ++kappa ) { calculate_finite_difference( j , kappa , f , dxdt_start ); @@ -527,7 +529,7 @@ private: //std::cout << "extrapolation result: " << m_diffs[kappa][0].m_v << std::endl; // divide kappa-th derivative by kappa because we need these terms for dense output interpolation - m_algebra.for_each1( m_diffs[kappa][0].m_v , typename operations_type::template scale< value_type >( static_cast(d) ) ); + m_algebra.for_each1( m_diffs[kappa][0].m_v , typename operations_type::template scale< time_type >( static_cast(d) ) ); d *= dt/(2*(kappa+2)); @@ -608,13 +610,13 @@ private: } template< class DerivIn > - void calculate_finite_difference( size_t j , size_t kappa , time_type fac , const DerivIn &dxdt ) + void calculate_finite_difference( size_t j , size_t kappa , value_type fac , const DerivIn &dxdt ) { const int m = m_interval_sequence[j]/2-1; if( kappa == 0) // no calculation required for 0th derivative of f { m_algebra.for_each2( m_diffs[0][j].m_v , m_derivs[j][m].m_v , - typename operations_type::template scale_sum1< time_type >( fac ) ); + typename operations_type::template scale_sum1< value_type >( fac ) ); //std::cout << "j=" << j << ", kappa=" << kappa << ", m=" << m; //std::cout << ": m_diffs[" << kappa << "][" << j << "] = " << fac << " * f[" << m << "] "; //std::cout << "(size(f)=" << m_derivs[j].size() << ") = " << m_diffs[0][j].m_v << std::endl; @@ -630,8 +632,8 @@ private: //std::cout << "j=" << j << ", kappa=" << kappa << ", m=" << m << ": m_diffs[" << kappa << "][" << j_diffs << "] = " << fac << " ( 1*f[" << m+kappa << "]"; m_algebra.for_each2( m_diffs[kappa][j_diffs].m_v , m_derivs[j][m+kappa].m_v , - typename operations_type::template scale_sum1< time_type >( fac ) ); - time_type sign = -1.0; + typename operations_type::template scale_sum1< value_type >( fac ) ); + value_type sign = -1.0; int c = 1; //computes the j-th order finite difference for the kappa-th derivative of f at t+dt/2 using function evaluations stored in m_derivs for( int i = m+static_cast(kappa)-2 ; i >= m-static_cast(kappa) ; i -= 2 ) @@ -639,7 +641,7 @@ private: if( i >= 0 ) { m_algebra.for_each3( m_diffs[kappa][j_diffs].m_v , m_diffs[kappa][j_diffs].m_v , m_derivs[j][i].m_v , - typename operations_type::template scale_sum2< time_type , time_type >( 1.0 , + typename operations_type::template scale_sum2< value_type , value_type >( 1.0 , sign * fac * boost::math::binomial_coefficient< double >( kappa , c ) ) ); //std::cout << ( (sign > 0.0) ? " + " : " - " ) << // boost::math::binomial_coefficient< double >( kappa , c ) << "*f[" << i << "]"; @@ -647,7 +649,7 @@ private: else { m_algebra.for_each3( m_diffs[kappa][j_diffs].m_v , m_diffs[kappa][j_diffs].m_v , dxdt , - typename operations_type::template scale_sum2< time_type , time_type >( 1.0 , sign * fac ) ); + typename operations_type::template scale_sum2< value_type , value_type >( 1.0 , sign * fac ) ); //std::cout << ( (sign > 0.0) ? " + " : " - " ) << "dxdt"; } sign *= -1; @@ -681,12 +683,12 @@ private: boost::numeric::odeint::copy( m_mp_states[0].m_v , out ); // add remaining terms: x += a_1 theta + a2 theta^2 + ... + a_{2k} theta^{2k} - time_type theta_pow( theta ); + value_type theta_pow( theta ); for( size_t i=0 ; i<=2*m_k_final+1 ; ++i ) { //std::cout << "a_" << i+1 << " theta^" << i+1 << " = " << m_diffs[i][0].m_v[0] * std::pow( theta , i+1 ) << std::endl; m_algebra.for_each3( out , out , m_diffs[i][0].m_v , - typename operations_type::template scale_sum2< time_type >( static_cast(1) , theta_pow ) ); + typename operations_type::template scale_sum2< value_type >( static_cast(1) , theta_pow ) ); theta_pow *= theta; } } diff --git a/boost/numeric/odeint/stepper/modified_midpoint.hpp b/boost/numeric/odeint/stepper/modified_midpoint.hpp index c194972c..27749143 100644 --- a/boost/numeric/odeint/stepper/modified_midpoint.hpp +++ b/boost/numeric/odeint/stepper/modified_midpoint.hpp @@ -76,8 +76,8 @@ public : m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) ); - const time_type h = dt / static_cast( m_steps ); - const time_type h2 = static_cast( 2 ) * h; + const time_type h = dt / m_steps ; + const time_type h2 = 2 * h; typename odeint::unwrap_reference< System >::type &sys = system; diff --git a/libs/numeric/odeint/test/stepper_with_units.cpp b/libs/numeric/odeint/test/stepper_with_units.cpp index 0dc7fa6b..2139b689 100644 --- a/libs/numeric/odeint/test/stepper_with_units.cpp +++ b/libs/numeric/odeint/test/stepper_with_units.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include @@ -264,8 +265,9 @@ class fsal_error_stepper_types : public mpl::vector class controlled_stepper_types : public mpl::vector < - controlled_runge_kutta< runge_kutta_cash_karp54_classic< state_type , value_type , deriv_type , time_type , fusion_algebra > > , - controlled_runge_kutta< runge_kutta_dopri5< state_type , value_type , deriv_type , time_type , fusion_algebra > > + controlled_runge_kutta< runge_kutta_cash_karp54_classic< state_type , value_type , deriv_type , time_type , fusion_algebra > > , + controlled_runge_kutta< runge_kutta_dopri5< state_type , value_type , deriv_type , time_type , fusion_algebra > > + //, bulirsch_stoer< state_type , value_type , deriv_type , time_type , fusion_algebra > //, controlled_error_stepper< runge_kutta_fehlberg78< state_type , value_type , deriv_type , time_type , fusion_algebra > > > { }; From 885156ee63d907d81362c7050fd01e28e32c1a1d Mon Sep 17 00:00:00 2001 From: Karsten Ahnert Date: Fri, 29 Jun 2012 08:05:16 +0200 Subject: [PATCH 03/12] removed some stuff from the main branch, this stuff still exist in keepthisstuff --- .../odeint/code_analyzer/check_includes.py | 48 - libs/numeric/odeint/code_analyzer/glob_dir.py | 15 - .../odeint/code_analyzer/header_preamble.py | 48 - .../adam_bashforrth_moulton/coefficients.nb | 1237 ----------------- libs/numeric/odeint/ideas/algebra/Jamfile | 13 - libs/numeric/odeint/ideas/algebra/algebra.hpp | 65 - .../odeint/ideas/algebra/test_algebra.cpp | 41 - .../odeint/ideas/algebra_dispatcher.hpp | 39 - libs/numeric/odeint/ideas/butcher/Jamfile | 29 - libs/numeric/odeint/ideas/butcher/algebra.hpp | 199 --- .../odeint/ideas/butcher/butcher_lorenz.cpp | 66 - .../ideas/butcher/butcher_performance.cpp | 100 -- .../odeint/ideas/butcher/butcher_vdp.cpp | 67 - .../odeint/ideas/butcher/convert_value.hpp | 36 - .../odeint/ideas/butcher/diagnostic.hpp | 59 - .../ideas/butcher/explicit_runge_kutta.hpp | 159 --- .../ideas/butcher/predefined_steppers.hpp | 77 - libs/numeric/odeint/ideas/controller/Jamfile | 22 - .../stepper/controller/default_controller.hpp | 70 - .../stepper/controller/pi_controller.hpp | 114 -- .../stepper/controller/stiff_controller.hpp | 99 -- .../odeint/stepper/error_checker_explicit.hpp | 137 -- .../odeint/stepper/error_checker_l2_norm.hpp | 119 -- .../odeint/stepper/error_checker_max_norm.hpp | 109 -- .../stepper/generic_controlled_stepper.hpp | 179 --- .../generic_controlled_stepper_definition.hpp | 43 - .../generic_controlled_stepper_explicit.hpp | 207 --- ...neric_controlled_stepper_explicit_fsal.hpp | 454 ------ .../stepper/generic_dense_output_stepper.hpp | 208 --- ...eneric_dense_output_stepper_definition.hpp | 39 - .../odeint/util/number_of_elements.hpp | 55 - .../odeint/util/ref_or_value_holder.hpp | 82 -- .../odeint/ideas/controller/controller.cpp | 142 -- .../dense_out_dopri5_controller.cpp | 168 --- .../ideas/controller/dopri5_controller.cpp | 142 -- .../libs/numeric/odeint/test/Jamfile | 27 - .../odeint/test/error_checker_l2_norm.cpp | 110 -- .../odeint/test/error_checker_max_norm.cpp | 118 -- .../odeint/test/number_of_elements.cpp | 57 - .../odeint/test/ref_or_value_holder.cpp | 65 - .../odeint/ideas/controller/rb_controller.cpp | 223 --- .../ideas/controller/rb_dense_output.cpp | 77 - .../odeint/ideas/fusion_runge_kutta/Jamfile | 17 - .../fusion_runge_kutta/fusion_algebra.hpp | 197 --- .../fusion_explicit_error_rk.hpp | 58 - .../fusion_runge_kutta/fusion_explicit_rk.hpp | 211 --- .../fusion_explicit_rk_new.hpp | 212 --- .../fusion_foreach_performance.hpp | 39 - .../fusion_runge_kutta/performance/Jamfile | 131 -- .../performance/generic_odeint_rk4_lorenz.cpp | 71 - .../performance/generic_rk4_lorenz.cpp | 63 - .../performance/generic_rk4_phase_lattice.cpp | 71 - .../performance/generic_rk54ck.cpp | 97 -- .../performance/generic_rk54ck_lorenz.cpp | 76 - .../performance/gsl_rk4_lorenz.cpp | 66 - .../performance/gsl_rk54ck.cpp | 77 - .../performance/gsl_rk54ck_lorenz.cpp | 66 - .../performance/java/rk4.java | 62 - .../fusion_runge_kutta/performance/lorenz.hpp | 41 - .../performance/lorenz_gsl.hpp | 25 - .../performance/nr_rk4_lorenz.cpp | 79 -- .../performance/nr_rk4_phase_lattice.cpp | 80 -- .../performance/nr_rk54ck.cpp | 121 -- .../performance/nr_rk54ck_lorenz.cpp | 96 -- .../performance/odeint_rk4_lorenz.cpp | 57 - .../performance/odeint_rk4_lorenz_def_alg.cpp | 54 - .../performance/odeint_rk4_phase_lattice.cpp | 60 - .../performance/odeint_rk54ck.cpp | 83 -- .../performance/odeint_rk54ck_def_alg.cpp | 81 -- .../performance/odeint_rk54ck_lorenz.cpp | 57 - .../odeint_rk54ck_lorenz_def_alg.cpp | 56 - .../performance/perf_analysis.py | 51 - .../performance/perf_tests.py | 39 - .../performance/phase_lattice.hpp | 33 - .../performance/results.dat | 41 - .../performance/rk_performance_test_case.hpp | 56 - .../performance/rt_generic_rk4_lorenz.cpp | 73 - .../rt_generic_rk4_phase_lattice.cpp | 76 - .../ideas/fusion_runge_kutta/rt_algebra.hpp | 19 - .../fusion_runge_kutta/rt_explicit_rk.hpp | 79 -- .../fusion_runge_kutta/test_explicit_rk.cpp | 104 -- .../odeint/ideas/generic_stepper/Jamfile | 41 - .../ideas/generic_stepper/fusion_algebra.hpp | 105 -- .../ideas/generic_stepper/fusion_array.cpp | 114 -- .../ideas/generic_stepper/fusion_stepper.hpp | 294 ---- .../ideas/generic_stepper/generic_stepper.hpp | 259 ---- .../ideas/generic_stepper/performance.cpp | 130 -- .../generic_stepper/performance_fusion.cpp | 110 -- .../ideas/generic_stepper/performance_mpl.cpp | 97 -- .../generic_stepper/performance_odeint.cpp | 91 -- .../odeint/ideas/generic_stepper/rk_test.cpp | 56 - .../generic_stepper/runge_kutta_stepper.hpp | 296 ---- .../runge_kutta_stepper_fast.hpp | 201 --- .../odeint/ideas/generic_stepper/test.cpp | 54 - .../odeint/ideas/odeint_ref_problem.cpp | 227 --- .../odeint/ideas/operations_dispatcher.hpp | 35 - libs/numeric/odeint/ideas/rosenbrock4/Jamfile | 24 - .../odeint/ideas/rosenbrock4/rosenbrock4.cpp | 171 --- .../odeint/ideas/rosenbrock4/rosenbrock4.hpp | 247 ---- .../ideas/rosenbrock4/rosenbrock4_stepper.cpp | 144 -- .../odeint/ideas/state_wrapper/Jamfile | 19 - .../ideas/state_wrapper/explicit_euler.hpp | 90 -- .../ideas/state_wrapper/size_adjuster.hpp | 54 - .../odeint/ideas/state_wrapper/test_array.cpp | 34 - .../ideas/state_wrapper/test_gsl_vector.cpp | 68 - .../ideas/state_wrapper/test_vector.cpp | 32 - libs/numeric/odeint/ideas/taylor/Notes | 36 - libs/numeric/odeint/ideas/taylor/lorenz.nb | 474 ------- .../taylor/lorenz_special/lorenz_original.f | 140 -- .../taylor/lorenz_special/lorenz_special.f | 106 -- .../odeint/ideas/taylor/taylor_v1/Jamfile | 16 - .../odeint/ideas/taylor/taylor_v1/taylor.hpp | 372 ----- .../taylor/taylor_v1/taylor_controller.hpp | 148 -- .../taylor_v1/taylor_lorenz_evol_adaptive.cpp | 106 -- ...taylor_lorenz_evol_adaptive_statistics.cpp | 166 --- .../taylor_v1/taylor_lorenz_evol_direct.cpp | 80 -- .../ideas/taylor/taylor_v1/taylor_main.cpp | 83 -- .../odeint/ideas/taylor/taylor_v2/Jamfile | 15 - .../odeint/ideas/taylor/taylor_v2/taylor.hpp | 378 ----- .../taylor/taylor_v2/taylor_controller.hpp | 148 -- ...taylor_lorenz_evol_adaptive_statistics.cpp | 166 --- .../taylor_v2/taylor_lorenz_evol_direct.cpp | 80 -- .../ideas/taylor/taylor_v2/taylor_main.cpp | 83 -- .../odeint/ideas/taylor/taylor_v3/Jamfile | 15 - .../odeint/ideas/taylor/taylor_v3/taylor.hpp | 482 ------- .../taylor/taylor_v3/taylor_controller.hpp | 148 -- ...taylor_lorenz_evol_adaptive_statistics.cpp | 166 --- .../taylor_v3/taylor_lorenz_evol_direct.cpp | 80 -- .../ideas/taylor/taylor_v3/taylor_main.cpp | 83 -- .../odeint/ideas/taylor/taylor_v4/Jamfile | 14 - .../odeint/ideas/taylor/taylor_v4/taylor.hpp | 565 -------- ...taylor_lorenz_evol_adaptive_statistics.cpp | 239 ---- .../ideas/taylor/taylor_v4/taylor_main.cpp | 89 -- libs/numeric/odeint/ideas/units/Jamfile | 24 - .../odeint/ideas/units/adjust_size_units.hpp | 117 -- .../ideas/units/explicit_euler_units.hpp | 67 - .../units/explicit_stepper_base_units.hpp | 150 -- .../ideas/units/standard_operations_units.hpp | 55 - .../odeint/ideas/units/test_ranges.cpp | 33 - .../numeric/odeint/ideas/units/test_units.cpp | 64 - libs/numeric/odeint/regression_test/Jamfile | 48 - .../regression_test/adams_bashforth.cpp | 65 - .../adams_bashforth_moulton.cpp | 63 - .../controlled_stepper_evolution.cpp | 77 - .../dense_output_controlled_explicit.cpp | 91 -- .../regression_test/dense_output_explicit.cpp | 66 - .../dense_output_stepper_evolution.cpp | 108 -- .../regression_test/hamiltonian_steppers.cpp | 189 --- .../regression_test/integrate_functions.cpp | 172 --- .../odeint/regression_test/rosenbrock4.cpp | 278 ---- tex/survey_existing_implementations.tex | 107 -- 151 files changed, 17584 deletions(-) delete mode 100755 libs/numeric/odeint/code_analyzer/check_includes.py delete mode 100644 libs/numeric/odeint/code_analyzer/glob_dir.py delete mode 100644 libs/numeric/odeint/code_analyzer/header_preamble.py delete mode 100644 libs/numeric/odeint/ideas/adam_bashforrth_moulton/coefficients.nb delete mode 100644 libs/numeric/odeint/ideas/algebra/Jamfile delete mode 100644 libs/numeric/odeint/ideas/algebra/algebra.hpp delete mode 100644 libs/numeric/odeint/ideas/algebra/test_algebra.cpp delete mode 100644 libs/numeric/odeint/ideas/algebra_dispatcher.hpp delete mode 100644 libs/numeric/odeint/ideas/butcher/Jamfile delete mode 100644 libs/numeric/odeint/ideas/butcher/algebra.hpp delete mode 100644 libs/numeric/odeint/ideas/butcher/butcher_lorenz.cpp delete mode 100644 libs/numeric/odeint/ideas/butcher/butcher_performance.cpp delete mode 100644 libs/numeric/odeint/ideas/butcher/butcher_vdp.cpp delete mode 100644 libs/numeric/odeint/ideas/butcher/convert_value.hpp delete mode 100644 libs/numeric/odeint/ideas/butcher/diagnostic.hpp delete mode 100644 libs/numeric/odeint/ideas/butcher/explicit_runge_kutta.hpp delete mode 100644 libs/numeric/odeint/ideas/butcher/predefined_steppers.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/Jamfile delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/controller/default_controller.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/controller/pi_controller.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/controller/stiff_controller.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/error_checker_explicit.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/error_checker_l2_norm.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/error_checker_max_norm.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper_definition.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper_explicit.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper_explicit_fsal.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_dense_output_stepper.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_dense_output_stepper_definition.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/util/number_of_elements.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/boost/numeric/odeint/util/ref_or_value_holder.hpp delete mode 100644 libs/numeric/odeint/ideas/controller/controller.cpp delete mode 100644 libs/numeric/odeint/ideas/controller/dense_out_dopri5_controller.cpp delete mode 100644 libs/numeric/odeint/ideas/controller/dopri5_controller.cpp delete mode 100644 libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/Jamfile delete mode 100644 libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/error_checker_l2_norm.cpp delete mode 100644 libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/error_checker_max_norm.cpp delete mode 100644 libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/number_of_elements.cpp delete mode 100644 libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/ref_or_value_holder.cpp delete mode 100644 libs/numeric/odeint/ideas/controller/rb_controller.cpp delete mode 100644 libs/numeric/odeint/ideas/controller/rb_dense_output.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/Jamfile delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_algebra.hpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_explicit_error_rk.hpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_explicit_rk.hpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_explicit_rk_new.hpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_foreach_performance.hpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/Jamfile delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_odeint_rk4_lorenz.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk4_lorenz.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk4_phase_lattice.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk54ck.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk54ck_lorenz.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/gsl_rk4_lorenz.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/gsl_rk54ck.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/gsl_rk54ck_lorenz.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/java/rk4.java delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/lorenz.hpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/lorenz_gsl.hpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/nr_rk4_lorenz.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/nr_rk4_phase_lattice.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/nr_rk54ck.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/nr_rk54ck_lorenz.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk4_lorenz.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk4_lorenz_def_alg.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk4_phase_lattice.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk54ck.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk54ck_def_alg.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk54ck_lorenz.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk54ck_lorenz_def_alg.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/perf_analysis.py delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/perf_tests.py delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/phase_lattice.hpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/results.dat delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/rk_performance_test_case.hpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/rt_generic_rk4_lorenz.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/performance/rt_generic_rk4_phase_lattice.cpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/rt_algebra.hpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/rt_explicit_rk.hpp delete mode 100644 libs/numeric/odeint/ideas/fusion_runge_kutta/test_explicit_rk.cpp delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/Jamfile delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/fusion_algebra.hpp delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/fusion_array.cpp delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/fusion_stepper.hpp delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/generic_stepper.hpp delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/performance.cpp delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/performance_fusion.cpp delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/performance_mpl.cpp delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/performance_odeint.cpp delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/rk_test.cpp delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/runge_kutta_stepper.hpp delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/runge_kutta_stepper_fast.hpp delete mode 100644 libs/numeric/odeint/ideas/generic_stepper/test.cpp delete mode 100644 libs/numeric/odeint/ideas/odeint_ref_problem.cpp delete mode 100644 libs/numeric/odeint/ideas/operations_dispatcher.hpp delete mode 100644 libs/numeric/odeint/ideas/rosenbrock4/Jamfile delete mode 100644 libs/numeric/odeint/ideas/rosenbrock4/rosenbrock4.cpp delete mode 100644 libs/numeric/odeint/ideas/rosenbrock4/rosenbrock4.hpp delete mode 100644 libs/numeric/odeint/ideas/rosenbrock4/rosenbrock4_stepper.cpp delete mode 100644 libs/numeric/odeint/ideas/state_wrapper/Jamfile delete mode 100644 libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp delete mode 100644 libs/numeric/odeint/ideas/state_wrapper/size_adjuster.hpp delete mode 100644 libs/numeric/odeint/ideas/state_wrapper/test_array.cpp delete mode 100644 libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp delete mode 100644 libs/numeric/odeint/ideas/state_wrapper/test_vector.cpp delete mode 100644 libs/numeric/odeint/ideas/taylor/Notes delete mode 100644 libs/numeric/odeint/ideas/taylor/lorenz.nb delete mode 100644 libs/numeric/odeint/ideas/taylor/lorenz_special/lorenz_original.f delete mode 100644 libs/numeric/odeint/ideas/taylor/lorenz_special/lorenz_special.f delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v1/Jamfile delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v1/taylor.hpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_controller.hpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_lorenz_evol_adaptive.cpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_lorenz_evol_adaptive_statistics.cpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_lorenz_evol_direct.cpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_main.cpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v2/Jamfile delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v2/taylor.hpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_controller.hpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_lorenz_evol_adaptive_statistics.cpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_lorenz_evol_direct.cpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_main.cpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v3/Jamfile delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v3/taylor.hpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_controller.hpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_lorenz_evol_adaptive_statistics.cpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_lorenz_evol_direct.cpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_main.cpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v4/Jamfile delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v4/taylor.hpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v4/taylor_lorenz_evol_adaptive_statistics.cpp delete mode 100644 libs/numeric/odeint/ideas/taylor/taylor_v4/taylor_main.cpp delete mode 100644 libs/numeric/odeint/ideas/units/Jamfile delete mode 100644 libs/numeric/odeint/ideas/units/adjust_size_units.hpp delete mode 100644 libs/numeric/odeint/ideas/units/explicit_euler_units.hpp delete mode 100644 libs/numeric/odeint/ideas/units/explicit_stepper_base_units.hpp delete mode 100644 libs/numeric/odeint/ideas/units/standard_operations_units.hpp delete mode 100644 libs/numeric/odeint/ideas/units/test_ranges.cpp delete mode 100644 libs/numeric/odeint/ideas/units/test_units.cpp delete mode 100644 libs/numeric/odeint/regression_test/Jamfile delete mode 100644 libs/numeric/odeint/regression_test/adams_bashforth.cpp delete mode 100644 libs/numeric/odeint/regression_test/adams_bashforth_moulton.cpp delete mode 100644 libs/numeric/odeint/regression_test/controlled_stepper_evolution.cpp delete mode 100644 libs/numeric/odeint/regression_test/dense_output_controlled_explicit.cpp delete mode 100644 libs/numeric/odeint/regression_test/dense_output_explicit.cpp delete mode 100644 libs/numeric/odeint/regression_test/dense_output_stepper_evolution.cpp delete mode 100644 libs/numeric/odeint/regression_test/hamiltonian_steppers.cpp delete mode 100644 libs/numeric/odeint/regression_test/integrate_functions.cpp delete mode 100644 libs/numeric/odeint/regression_test/rosenbrock4.cpp delete mode 100644 tex/survey_existing_implementations.tex diff --git a/libs/numeric/odeint/code_analyzer/check_includes.py b/libs/numeric/odeint/code_analyzer/check_includes.py deleted file mode 100755 index ec5a4f5e..00000000 --- a/libs/numeric/odeint/code_analyzer/check_includes.py +++ /dev/null @@ -1,48 +0,0 @@ -#! /usr/bin/python - -import os -import glob -import subprocess - - -topleveldir = "../../../" - -filename = [] -filename += glob.glob( topleveldir + "boost/numeric/odeint/*.hpp" ) -filename += glob.glob( topleveldir + "boost/numeric/odeint/algebra/*.hpp" ) -filename += glob.glob( topleveldir + "boost/numeric/odeint/algebra/detail/*.hpp" ) -filename += glob.glob( topleveldir + "boost/numeric/odeint/algebra/external/*.hpp" ) -filename += glob.glob( topleveldir + "boost/numeric/odeint/stepper/*.hpp" ) -filename += glob.glob( topleveldir + "boost/numeric/odeint/stepper/base/*.hpp" ) -filename += glob.glob( topleveldir + "boost/numeric/odeint/stepper/detail/*.hpp" ) - - -test_prog = '#include \n\ -\n\ -int main( void )\n\ -{\n\ - return 0;\n\ -}\n\ -' - -count = 0 -for fn in filename : - fn = fn[len(topleveldir) : ] - prog = test_prog.replace( "INCLUDE" , fn ) - - file = open( "test.cc" , "w" ) - file.write( prog ) - file.close - - cmd = ["g++" , "-I"+topleveldir , "-I$BOOST_ROOT" , "-c" , "test.cc" ] - - print "Test " + fn + " : " -# print prog - print "Commandline : " + subprocess.list2cmdline( cmd ) - - p = subprocess.Popen( subprocess.list2cmdline( cmd ) , shell=True) - sts = os.waitpid(p.pid, 0)[1] - - print sts - print "" - diff --git a/libs/numeric/odeint/code_analyzer/glob_dir.py b/libs/numeric/odeint/code_analyzer/glob_dir.py deleted file mode 100644 index e7112f93..00000000 --- a/libs/numeric/odeint/code_analyzer/glob_dir.py +++ /dev/null @@ -1,15 +0,0 @@ -import fnmatch -import os - - -def glob_dir( dir , pattern , exclude = [ ] ): - matches = [] - for root , dirnames, filenames in os.walk( dir ): - exclude_dir = False - for e in exclude: - if root.find( e ) != -1: - exclude_dir = True - if exclude_dir == False: - for filename in fnmatch.filter( filenames , pattern ): - matches.append( [ root , filename , os.path.join(root, filename) ] ) - return matches diff --git a/libs/numeric/odeint/code_analyzer/header_preamble.py b/libs/numeric/odeint/code_analyzer/header_preamble.py deleted file mode 100644 index d3e73818..00000000 --- a/libs/numeric/odeint/code_analyzer/header_preamble.py +++ /dev/null @@ -1,48 +0,0 @@ -#! /usr/bin/python - -from glob_dir import * - -preamble_template = "/*\n\ - [auto_generated]\n\ - FILENAME\n\ - \n\ - [begin_description]\n\ - \n\ - [end_description]\n\ - \n\ - Copyright 2009-2011 Karsten Ahnert\n\ - Copyright 2009-2011 Mario Mulansky\n\ - \n\ - Distributed under the Boost Software License, Version 1.0.\n\ - (See accompanying file LICENSE_1_0.txt or\n\ - copy at http://www.boost.org/LICENSE_1_0.txt)\n\ -*/\n\ -\n\ -" - -def header_guard( file_desc ): - return file_desc[2].upper().replace( "/" , "_" ).replace( "." , "_" ) + "_INCLUDED" - -def insert_preamble( content , file_desc ): - preamble = preamble_template.replace( "FILENAME" , file_desc[2] ) - ret = preamble + "\n" - ret += "#ifndef " + header_guard( file_desc ) + "\n" - ret += "#define " + header_guard( file_desc ) + "\n\n" - ret += content - ret += "#endif // " + header_guard( file_desc ) + "\n" - return ret - - - -files = glob_dir( "../../../../boost" , "*.hpp" , [ "algebra" , "external" , "integrate" , "util" ] ) - -for f in files: - print str( f[2] ) #+ " " + header_guard( f ) - file = open( f[2] ) - content = file.read() - content = insert_preamble( content , f ) - file.close() - - file = open( f[2] , "w" ) - file.write( content ) - file.close() \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/adam_bashforrth_moulton/coefficients.nb b/libs/numeric/odeint/ideas/adam_bashforrth_moulton/coefficients.nb deleted file mode 100644 index b2273884..00000000 --- a/libs/numeric/odeint/ideas/adam_bashforrth_moulton/coefficients.nb +++ /dev/null @@ -1,1237 +0,0 @@ -(* Content-type: application/mathematica *) - -(*** Wolfram Notebook File ***) -(* http://www.wolfram.com/nb *) - -(* CreatedBy='Mathematica 7.0' *) - -(*CacheID: 234*) -(* Internal cache information: -NotebookFileLineBreakTest -NotebookFileLineBreakTest -NotebookDataPosition[ 145, 7] -NotebookDataLength[ 38044, 1228] -NotebookOptionsPosition[ 35928, 1164] -NotebookOutlinePosition[ 36264, 1179] -CellTagsIndexPosition[ 36221, 1176] -WindowFrame->Normal*) - -(* Beginning of Notebook Content *) -Notebook[{ -Cell[BoxData[{ - RowBox[{"Clear", "[", "\"\\"", "]"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"MyStyle", "[", "x_", "]"}], ":=", - RowBox[{"TraditionalForm", "[", - RowBox[{"Style", "[", - RowBox[{"x", ",", "Large"}], "]"}], "]"}]}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"MyStyleSmall", "[", "x_", "]"}], ":=", - RowBox[{"TraditionalForm", "[", "x", "]"}]}]}], "Input", - CellChangeTimes->{{3.467953724161771*^9, 3.467953745490753*^9}}], - -Cell[BoxData[{ - RowBox[{ - RowBox[{"yrep", "[", - RowBox[{"n_", ",", "k_"}], "]"}], ":=", - RowBox[{ - RowBox[{"y", "[", - RowBox[{"n", "-", "k"}], "]"}], "\[Rule]", - SubscriptBox["y", - RowBox[{"n", "-", "k"}]]}]}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"neatrep", "[", "x_", "]"}], ":=", - RowBox[{"x", "/.", - RowBox[{"Table", "[", - RowBox[{ - RowBox[{"yrep", "[", - RowBox[{"n", ",", "k"}], "]"}], ",", - RowBox[{"{", - RowBox[{"k", ",", - RowBox[{"-", "20"}], ",", "20"}], "}"}]}], - "]"}]}]}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"MyNeat", "[", "x_", "]"}], ":=", - RowBox[{"MyStyle", "[", - RowBox[{"neatrep", "[", "x", "]"}], "]"}]}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"MyNeatSmall", "[", "x_", "]"}], ":=", - RowBox[{"MyStyleSmall", "[", - RowBox[{"neatrep", "[", "x", "]"}], "]"}]}]}], "Input", - CellChangeTimes->{{3.514464959570836*^9, 3.514465120719865*^9}, { - 3.514527892691033*^9, 3.5145278939018183`*^9}}], - -Cell[BoxData[{ - RowBox[{ - RowBox[{"Nabla", "[", - RowBox[{"n_", ",", "0"}], "]"}], ":=", - RowBox[{"y", "[", "n", "]"}]}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Nabla", "[", - RowBox[{"n_", ",", "k_"}], "]"}], ":=", - RowBox[{ - RowBox[{"Nabla", "[", - RowBox[{"n", ",", - RowBox[{"k", "-", "1"}]}], "]"}], "-", - RowBox[{"Nabla", "[", - RowBox[{ - RowBox[{"n", "-", "1"}], ",", - RowBox[{"k", "-", "1"}]}], "]"}]}]}]}], "Input", - CellChangeTimes->{{3.514447522073597*^9, 3.5144476307630177`*^9}, { - 3.514464931916651*^9, 3.514464934924923*^9}}], - -Cell[CellGroupData[{ - -Cell["Explicit Adams Methods", "Subsubsection", - CellChangeTimes->{{3.5144675005769367`*^9, 3.514467506161409*^9}}], - -Cell["Define \[Gamma]", "Text", - CellChangeTimes->{{3.5144675211047497`*^9, 3.514467531440797*^9}}], - -Cell[BoxData[{ - RowBox[{ - RowBox[{"gamma", "[", "0", "]"}], ":=", "1"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"gamma", "[", "k_", "]"}], ":=", - RowBox[{"1", "-", - RowBox[{"Sum", "[", - RowBox[{ - RowBox[{ - RowBox[{"1", "/", - RowBox[{"(", - RowBox[{"j", "+", "1"}], ")"}]}], - RowBox[{"gamma", "[", - RowBox[{"k", "-", "j"}], "]"}]}], ",", - RowBox[{"{", - RowBox[{"j", ",", "1", ",", "k"}], "}"}]}], "]"}]}]}]}], "Input"], - -Cell["Define the approximation", "Text", - CellChangeTimes->{{3.514467538537239*^9, 3.514467542703155*^9}}], - -Cell[BoxData[ - RowBox[{ - RowBox[{"Appr", "[", "k_", "]"}], ":=", - RowBox[{"Sum", "[", - RowBox[{ - RowBox[{ - RowBox[{"gamma", "[", "j", "]"}], " ", - RowBox[{"Nabla", "[", - RowBox[{"n", ",", "j"}], "]"}]}], ",", - RowBox[{"{", - RowBox[{"j", ",", "0", ",", - RowBox[{"k", "-", "1"}]}], "}"}]}], "]"}]}]], "Input", - CellChangeTimes->{{3.51446729473982*^9, 3.514467351514332*^9}}], - -Cell[TextData[{ - "Print the first seven terms. Note that everywhere ", - Cell[BoxData[ - FormBox[ - RowBox[{ - SubscriptBox["x", "n"], "has", " ", "to", " ", "be", " ", - RowBox[{"added", "."}]}], TraditionalForm]], - FormatType->"TraditionalForm"] -}], "Text", - CellChangeTimes->{{3.514467545805399*^9, 3.514467568755361*^9}}], - -Cell[CellGroupData[{ - -Cell[BoxData[{ - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "0", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "1", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "2", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "3", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "4", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "5", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "6", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "7", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "8", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "9", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "10", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "11", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"Appr", "[", "12", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}]}], "Input", - CellChangeTimes->{{3.514467352952169*^9, 3.514467447032159*^9}, { - 3.5145278590674257`*^9, 3.514527871347169*^9}}], - -Cell[BoxData[ - FormBox["0", TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.514527896331929*^9}}], - -Cell[BoxData[ - FormBox[ - SubscriptBox["y", "n"], TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.5145278963599653`*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - FractionBox[ - RowBox[{"3", " ", - SubscriptBox["y", "n"]}], "2"], "-", - FractionBox[ - SubscriptBox["y", - RowBox[{"n", "-", "1"}]], "2"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.5145278964165277`*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - FractionBox[ - RowBox[{"5", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "12"], "-", - FractionBox[ - RowBox[{"4", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "3"], "+", - FractionBox[ - RowBox[{"23", " ", - SubscriptBox["y", "n"]}], "12"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.514527896470492*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - RowBox[{"-", - FractionBox[ - RowBox[{"3", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "8"]}], "+", - FractionBox[ - RowBox[{"37", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "24"], "-", - FractionBox[ - RowBox[{"59", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "24"], "+", - FractionBox[ - RowBox[{"55", " ", - SubscriptBox["y", "n"]}], "24"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.514527896525687*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - FractionBox[ - RowBox[{"251", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "720"], "-", - FractionBox[ - RowBox[{"637", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "360"], "+", - FractionBox[ - RowBox[{"109", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "30"], "-", - FractionBox[ - RowBox[{"1387", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "360"], "+", - FractionBox[ - RowBox[{"1901", " ", - SubscriptBox["y", "n"]}], "720"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.514527896580089*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - RowBox[{"-", - FractionBox[ - RowBox[{"95", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "288"]}], "+", - FractionBox[ - RowBox[{"959", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "480"], "-", - FractionBox[ - RowBox[{"3649", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "720"], "+", - FractionBox[ - RowBox[{"4991", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "720"], "-", - FractionBox[ - RowBox[{"2641", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "480"], "+", - FractionBox[ - RowBox[{"4277", " ", - SubscriptBox["y", "n"]}], "1440"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.514527896690482*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - FractionBox[ - RowBox[{"19087", " ", - SubscriptBox["y", - RowBox[{"n", "-", "6"}]]}], "60480"], "-", - FractionBox[ - RowBox[{"5603", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "2520"], "+", - FractionBox[ - RowBox[{"135713", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "20160"], "-", - FractionBox[ - RowBox[{"10754", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "945"], "+", - FractionBox[ - RowBox[{"235183", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "20160"], "-", - FractionBox[ - RowBox[{"18637", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "2520"], "+", - FractionBox[ - RowBox[{"198721", " ", - SubscriptBox["y", "n"]}], "60480"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.51452789675095*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - RowBox[{"-", - FractionBox[ - RowBox[{"5257", " ", - SubscriptBox["y", - RowBox[{"n", "-", "7"}]]}], "17280"]}], "+", - FractionBox[ - RowBox[{"32863", " ", - SubscriptBox["y", - RowBox[{"n", "-", "6"}]]}], "13440"], "-", - FractionBox[ - RowBox[{"115747", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "13440"], "+", - FractionBox[ - RowBox[{"2102243", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "120960"], "-", - FractionBox[ - RowBox[{"296053", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "13440"], "+", - FractionBox[ - RowBox[{"242653", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "13440"], "-", - FractionBox[ - RowBox[{"1152169", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "120960"], "+", - FractionBox[ - RowBox[{"16083", " ", - SubscriptBox["y", "n"]}], "4480"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.514527896813024*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - FractionBox[ - RowBox[{"1070017", " ", - SubscriptBox["y", - RowBox[{"n", "-", "8"}]]}], "3628800"], "-", - FractionBox[ - RowBox[{"4832053", " ", - SubscriptBox["y", - RowBox[{"n", "-", "7"}]]}], "1814400"], "+", - FractionBox[ - RowBox[{"19416743", " ", - SubscriptBox["y", - RowBox[{"n", "-", "6"}]]}], "1814400"], "-", - FractionBox[ - RowBox[{"45586321", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "1814400"], "+", - FractionBox[ - RowBox[{"862303", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "22680"], "-", - FractionBox[ - RowBox[{"69927631", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "1814400"], "+", - FractionBox[ - RowBox[{"47738393", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "1814400"], "-", - FractionBox[ - RowBox[{"21562603", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "1814400"], "+", - FractionBox[ - RowBox[{"14097247", " ", - SubscriptBox["y", "n"]}], "3628800"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.514527896883152*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - RowBox[{"-", - FractionBox[ - RowBox[{"25713", " ", - SubscriptBox["y", - RowBox[{"n", "-", "9"}]]}], "89600"]}], "+", - FractionBox[ - RowBox[{"20884811", " ", - SubscriptBox["y", - RowBox[{"n", "-", "8"}]]}], "7257600"], "-", - FractionBox[ - RowBox[{"2357683", " ", - SubscriptBox["y", - RowBox[{"n", "-", "7"}]]}], "181440"], "+", - FractionBox[ - RowBox[{"15788639", " ", - SubscriptBox["y", - RowBox[{"n", "-", "6"}]]}], "453600"], "-", - FractionBox[ - RowBox[{"222386081", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "3628800"], "+", - FractionBox[ - RowBox[{"269181919", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "3628800"], "-", - FractionBox[ - RowBox[{"28416361", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "453600"], "+", - FractionBox[ - RowBox[{"6648317", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "181440"], "-", - FractionBox[ - RowBox[{"104995189", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "7257600"], "+", - FractionBox[ - RowBox[{"4325321", " ", - SubscriptBox["y", "n"]}], "1036800"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.514527896964872*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - FractionBox[ - RowBox[{"26842253", " ", - SubscriptBox["y", - RowBox[{"n", "-", "10"}]]}], "95800320"], "-", - FractionBox[ - RowBox[{"52841941", " ", - SubscriptBox["y", - RowBox[{"n", "-", "9"}]]}], "17107200"], "+", - FractionBox[ - RowBox[{"2472634817", " ", - SubscriptBox["y", - RowBox[{"n", "-", "8"}]]}], "159667200"], "-", - FractionBox[ - RowBox[{"186080291", " ", - SubscriptBox["y", - RowBox[{"n", "-", "7"}]]}], "3991680"], "+", - FractionBox[ - RowBox[{"2492064913", " ", - SubscriptBox["y", - RowBox[{"n", "-", "6"}]]}], "26611200"], "-", - FractionBox[ - RowBox[{"82260679", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "623700"], "+", - FractionBox[ - RowBox[{"3539798831", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "26611200"], "-", - FractionBox[ - RowBox[{"1921376209", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "19958400"], "+", - FractionBox[ - RowBox[{"1572737587", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "31933440"], "-", - FractionBox[ - RowBox[{"2067948781", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "119750400"], "+", - FractionBox[ - RowBox[{"2132509567", " ", - SubscriptBox["y", "n"]}], "479001600"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.51452789705408*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - RowBox[{"-", - FractionBox[ - RowBox[{"4777223", " ", - SubscriptBox["y", - RowBox[{"n", "-", "11"}]]}], "17418240"]}], "+", - FractionBox[ - RowBox[{"30082309", " ", - SubscriptBox["y", - RowBox[{"n", "-", "10"}]]}], "9123840"], "-", - FractionBox[ - RowBox[{"17410248271", " ", - SubscriptBox["y", - RowBox[{"n", "-", "9"}]]}], "958003200"], "+", - FractionBox[ - RowBox[{"923636629", " ", - SubscriptBox["y", - RowBox[{"n", "-", "8"}]]}], "15206400"], "-", - FractionBox[ - RowBox[{"625551749", " ", - SubscriptBox["y", - RowBox[{"n", "-", "7"}]]}], "4561920"], "+", - FractionBox[ - RowBox[{"35183928883", " ", - SubscriptBox["y", - RowBox[{"n", "-", "6"}]]}], "159667200"], "-", - FractionBox[ - RowBox[{"41290273229", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "159667200"], "+", - FractionBox[ - RowBox[{"35689892561", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "159667200"], "-", - FractionBox[ - RowBox[{"15064372973", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "106444800"], "+", - FractionBox[ - RowBox[{"12326645437", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "191600640"], "-", - FractionBox[ - RowBox[{"6477936721", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "319334400"], "+", - FractionBox[ - RowBox[{"4527766399", " ", - SubscriptBox["y", "n"]}], "958003200"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.514467355009871*^9, 3.514467448673203*^9}, { - 3.5145278724703493`*^9, 3.51452789715303*^9}}] -}, Open ]] -}, Open ]], - -Cell[CellGroupData[{ - -Cell["Implicit Adams methods", "Subsubsection", - CellChangeTimes->{{3.5144675944623537`*^9, 3.514467608362565*^9}}], - -Cell["\<\ -The implicit adams methods are usually used as corrector for the explicit \ -steps. \ -\>", "Text", - CellChangeTimes->{{3.5144676105697937`*^9, 3.514467636163187*^9}}], - -Cell["Define thte coefficients", "Text", - CellChangeTimes->{{3.514467641131043*^9, 3.514467645683628*^9}}], - -Cell[BoxData[{ - RowBox[{ - RowBox[{"gammas", "[", "0", "]"}], ":=", "1"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"gammas", "[", "k_", "]"}], ":=", - RowBox[{"-", - RowBox[{"Sum", "[", - RowBox[{ - RowBox[{ - RowBox[{"1", "/", - RowBox[{"(", - RowBox[{"j", "+", "1"}], ")"}]}], - RowBox[{"gammas", "[", - RowBox[{"k", "-", "j"}], "]"}]}], ",", - RowBox[{"{", - RowBox[{"j", ",", "1", ",", "k"}], "}"}]}], "]"}]}]}]}], "Input", - CellChangeTimes->{{3.51446764717624*^9, 3.514467654082909*^9}, { - 3.5144680815705748`*^9, 3.514468119898904*^9}}], - -Cell["Define the approximation", "Text", - CellChangeTimes->{{3.514468160960372*^9, 3.514468166171316*^9}}], - -Cell[BoxData[ - RowBox[{ - RowBox[{"ApprS", "[", "k_", "]"}], ":=", - RowBox[{"Sum", "[", - RowBox[{ - RowBox[{ - RowBox[{"gammas", "[", "j", "]"}], " ", - RowBox[{"Nabla", "[", - RowBox[{ - RowBox[{"n", "+", "1"}], ",", "j"}], "]"}]}], ",", - RowBox[{"{", - RowBox[{"j", ",", "0", ",", "k"}], "}"}]}], "]"}]}]], "Input", - CellChangeTimes->{{3.514468167559917*^9, 3.514468225665447*^9}, - 3.514469378555846*^9, 3.514469450024321*^9}], - -Cell[TextData[{ - "Print the first seven terms. Note that everywhere ", - Cell[BoxData[ - FormBox[ - RowBox[{ - SubscriptBox["x", "n"], "has", " ", "to", " ", "be", " ", - RowBox[{"added", "."}]}], TraditionalForm]]] -}], "Text", - CellChangeTimes->{{3.514467545805399*^9, 3.514467568755361*^9}}], - -Cell[CellGroupData[{ - -Cell[BoxData[{ - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "0", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "1", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "2", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "3", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "4", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "5", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "6", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "7", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "8", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "9", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "10", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "11", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Expand", "[", - RowBox[{"Simplify", "[", - RowBox[{"ApprS", "[", "12", "]"}], "]"}], "]"}], "//", - "MyNeatSmall"}]}], "Input", - CellChangeTimes->{{3.514468253039894*^9, 3.5144682952815237`*^9}, { - 3.5144695004155483`*^9, 3.514469506581892*^9}, {3.514532203505896*^9, - 3.514532215643444*^9}}], - -Cell[BoxData[ - FormBox[ - SubscriptBox["y", - RowBox[{"n", "+", "1"}]], TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.514532222367462*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - FractionBox[ - SubscriptBox["y", "n"], "2"], "+", - FractionBox[ - SubscriptBox["y", - RowBox[{"n", "+", "1"}]], "2"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.514532222374004*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - RowBox[{"-", - FractionBox[ - SubscriptBox["y", - RowBox[{"n", "-", "1"}]], "12"]}], "+", - FractionBox[ - RowBox[{"2", " ", - SubscriptBox["y", "n"]}], "3"], "+", - FractionBox[ - RowBox[{"5", " ", - SubscriptBox["y", - RowBox[{"n", "+", "1"}]]}], "12"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.514532222417791*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - FractionBox[ - SubscriptBox["y", - RowBox[{"n", "-", "2"}]], "24"], "-", - FractionBox[ - RowBox[{"5", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "24"], "+", - FractionBox[ - RowBox[{"19", " ", - SubscriptBox["y", "n"]}], "24"], "+", - FractionBox[ - RowBox[{"3", " ", - SubscriptBox["y", - RowBox[{"n", "+", "1"}]]}], "8"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.5145322224423037`*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - RowBox[{"-", - FractionBox[ - RowBox[{"19", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "720"]}], "+", - FractionBox[ - RowBox[{"53", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "360"], "-", - FractionBox[ - RowBox[{"11", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "30"], "+", - FractionBox[ - RowBox[{"323", " ", - SubscriptBox["y", "n"]}], "360"], "+", - FractionBox[ - RowBox[{"251", " ", - SubscriptBox["y", - RowBox[{"n", "+", "1"}]]}], "720"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.514532222467699*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - FractionBox[ - RowBox[{"3", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "160"], "-", - FractionBox[ - RowBox[{"173", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "1440"], "+", - FractionBox[ - RowBox[{"241", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "720"], "-", - FractionBox[ - RowBox[{"133", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "240"], "+", - FractionBox[ - RowBox[{"1427", " ", - SubscriptBox["y", "n"]}], "1440"], "+", - FractionBox[ - RowBox[{"95", " ", - SubscriptBox["y", - RowBox[{"n", "+", "1"}]]}], "288"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.514532222494212*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - RowBox[{"-", - FractionBox[ - RowBox[{"863", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "60480"]}], "+", - FractionBox[ - RowBox[{"263", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "2520"], "-", - FractionBox[ - RowBox[{"6737", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "20160"], "+", - FractionBox[ - RowBox[{"586", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "945"], "-", - FractionBox[ - RowBox[{"15487", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "20160"], "+", - FractionBox[ - RowBox[{"2713", " ", - SubscriptBox["y", "n"]}], "2520"], "+", - FractionBox[ - RowBox[{"19087", " ", - SubscriptBox["y", - RowBox[{"n", "+", "1"}]]}], "60480"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.514532222525598*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - FractionBox[ - RowBox[{"275", " ", - SubscriptBox["y", - RowBox[{"n", "-", "6"}]]}], "24192"], "-", - FractionBox[ - RowBox[{"11351", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "120960"], "+", - FractionBox[ - RowBox[{"1537", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "4480"], "-", - FractionBox[ - RowBox[{"88547", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "120960"], "+", - FractionBox[ - RowBox[{"123133", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "120960"], "-", - FractionBox[ - RowBox[{"4511", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "4480"], "+", - FractionBox[ - RowBox[{"139849", " ", - SubscriptBox["y", "n"]}], "120960"], "+", - FractionBox[ - RowBox[{"5257", " ", - SubscriptBox["y", - RowBox[{"n", "+", "1"}]]}], "17280"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.514532222558278*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - RowBox[{"-", - FractionBox[ - RowBox[{"33953", " ", - SubscriptBox["y", - RowBox[{"n", "-", "7"}]]}], "3628800"]}], "+", - FractionBox[ - RowBox[{"156437", " ", - SubscriptBox["y", - RowBox[{"n", "-", "6"}]]}], "1814400"], "-", - FractionBox[ - RowBox[{"645607", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "1814400"], "+", - FractionBox[ - RowBox[{"1573169", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "1814400"], "-", - FractionBox[ - RowBox[{"31457", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "22680"], "+", - FractionBox[ - RowBox[{"2797679", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "1814400"], "-", - FractionBox[ - RowBox[{"2302297", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "1814400"], "+", - FractionBox[ - RowBox[{"2233547", " ", - SubscriptBox["y", "n"]}], "1814400"], "+", - FractionBox[ - RowBox[{"1070017", " ", - SubscriptBox["y", - RowBox[{"n", "+", "1"}]]}], "3628800"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.514532222593453*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - FractionBox[ - RowBox[{"8183", " ", - SubscriptBox["y", - RowBox[{"n", "-", "8"}]]}], "1036800"], "-", - FractionBox[ - RowBox[{"116687", " ", - SubscriptBox["y", - RowBox[{"n", "-", "7"}]]}], "1451520"], "+", - FractionBox[ - RowBox[{"335983", " ", - SubscriptBox["y", - RowBox[{"n", "-", "6"}]]}], "907200"], "-", - FractionBox[ - RowBox[{"462127", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "453600"], "+", - FractionBox[ - RowBox[{"6755041", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "3628800"], "-", - FractionBox[ - RowBox[{"8641823", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "3628800"], "+", - FractionBox[ - RowBox[{"200029", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "90720"], "-", - FractionBox[ - RowBox[{"1408913", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "907200"], "+", - FractionBox[ - RowBox[{"9449717", " ", - SubscriptBox["y", "n"]}], "7257600"], "+", - FractionBox[ - RowBox[{"25713", " ", - SubscriptBox["y", - RowBox[{"n", "+", "1"}]]}], "89600"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.514532222682352*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - RowBox[{"-", - FractionBox[ - RowBox[{"3250433", " ", - SubscriptBox["y", - RowBox[{"n", "-", "9"}]]}], "479001600"]}], "+", - FractionBox[ - RowBox[{"9071219", " ", - SubscriptBox["y", - RowBox[{"n", "-", "8"}]]}], "119750400"], "-", - FractionBox[ - RowBox[{"12318413", " ", - SubscriptBox["y", - RowBox[{"n", "-", "7"}]]}], "31933440"], "+", - FractionBox[ - RowBox[{"23643791", " ", - SubscriptBox["y", - RowBox[{"n", "-", "6"}]]}], "19958400"], "-", - FractionBox[ - RowBox[{"21677723", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "8870400"], "+", - FractionBox[ - RowBox[{"2227571", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "623700"], "-", - FractionBox[ - RowBox[{"33765029", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "8870400"], "+", - FractionBox[ - RowBox[{"12051709", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "3991680"], "-", - FractionBox[ - RowBox[{"296725183", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "159667200"], "+", - FractionBox[ - RowBox[{"164046413", " ", - SubscriptBox["y", "n"]}], "119750400"], "+", - FractionBox[ - RowBox[{"26842253", " ", - SubscriptBox["y", - RowBox[{"n", "+", "1"}]]}], "95800320"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.514532222716319*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - FractionBox[ - RowBox[{"4671", " ", - SubscriptBox["y", - RowBox[{"n", "-", "10"}]]}], "788480"], "-", - FractionBox[ - RowBox[{"68928781", " ", - SubscriptBox["y", - RowBox[{"n", "-", "9"}]]}], "958003200"], "+", - FractionBox[ - RowBox[{"384709327", " ", - SubscriptBox["y", - RowBox[{"n", "-", "8"}]]}], "958003200"], "-", - FractionBox[ - RowBox[{"87064741", " ", - SubscriptBox["y", - RowBox[{"n", "-", "7"}]]}], "63866880"], "+", - FractionBox[ - RowBox[{"501289903", " ", - SubscriptBox["y", - RowBox[{"n", "-", "6"}]]}], "159667200"], "-", - FractionBox[ - RowBox[{"91910491", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "17740800"], "+", - FractionBox[ - RowBox[{"1007253581", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "159667200"], "-", - FractionBox[ - RowBox[{"102212233", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "17740800"], "+", - FractionBox[ - RowBox[{"36465037", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "9123840"], "-", - FractionBox[ - RowBox[{"99642413", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "45619200"], "+", - FractionBox[ - RowBox[{"1374799219", " ", - SubscriptBox["y", "n"]}], "958003200"], "+", - FractionBox[ - RowBox[{"4777223", " ", - SubscriptBox["y", - RowBox[{"n", "+", "1"}]]}], "17418240"]}], TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.514532222764542*^9}}], - -Cell[BoxData[ - FormBox[ - RowBox[{ - RowBox[{"-", - FractionBox[ - RowBox[{"13695779093", " ", - SubscriptBox["y", - RowBox[{"n", "-", "11"}]]}], "2615348736000"]}], "+", - FractionBox[ - RowBox[{"2724891251", " ", - SubscriptBox["y", - RowBox[{"n", "-", "10"}]]}], "39626496000"], "-", - FractionBox[ - RowBox[{"30336027563", " ", - SubscriptBox["y", - RowBox[{"n", "-", "9"}]]}], "72648576000"], "+", - FractionBox[ - RowBox[{"406332786317", " ", - SubscriptBox["y", - RowBox[{"n", "-", "8"}]]}], "261534873600"], "-", - FractionBox[ - RowBox[{"229882484333", " ", - SubscriptBox["y", - RowBox[{"n", "-", "7"}]]}], "58118860800"], "+", - FractionBox[ - RowBox[{"529394045911", " ", - SubscriptBox["y", - RowBox[{"n", "-", "6"}]]}], "72648576000"], "-", - FractionBox[ - RowBox[{"4874320027", " ", - SubscriptBox["y", - RowBox[{"n", "-", "5"}]]}], "486486000"], "+", - FractionBox[ - RowBox[{"84400835489", " ", - SubscriptBox["y", - RowBox[{"n", "-", "4"}]]}], "8072064000"], "-", - FractionBox[ - RowBox[{"485500845331", " ", - SubscriptBox["y", - RowBox[{"n", "-", "3"}]]}], "58118860800"], "+", - FractionBox[ - RowBox[{"1346577425651", " ", - SubscriptBox["y", - RowBox[{"n", "-", "2"}]]}], "261534873600"], "-", - FractionBox[ - RowBox[{"551368413119", " ", - SubscriptBox["y", - RowBox[{"n", "-", "1"}]]}], "217945728000"], "+", - FractionBox[ - RowBox[{"6595204069", " ", - SubscriptBox["y", "n"]}], "4402944000"], "+", - FractionBox[ - RowBox[{"703604254357", " ", - SubscriptBox["y", - RowBox[{"n", "+", "1"}]]}], "2615348736000"]}], - TraditionalForm]], "Output", - CellChangeTimes->{{3.5144682568392572`*^9, 3.514468296869801*^9}, - 3.514469396864979*^9, 3.5144694520511827`*^9, 3.5144695076064157`*^9, { - 3.514532216284086*^9, 3.5145322228147984`*^9}}] -}, Open ]] -}, Open ]] -}, -WindowSize->{1680, 983}, -WindowMargins->{{0, Automatic}, {Automatic, 0}}, -FrontEndVersion->"7.0 for Linux x86 (64-bit) (November 11, 2008)", -StyleDefinitions->"Default.nb" -] -(* End of Notebook Content *) - -(* Internal cache information *) -(*CellTagsOutline -CellTagsIndex->{} -*) -(*CellTagsIndex -CellTagsIndex->{} -*) -(*NotebookFileOutline -Notebook[{ -Cell[545, 20, 464, 10, 77, "Input"], -Cell[1012, 32, 997, 29, 99, "Input"], -Cell[2012, 63, 580, 17, 55, "Input"], -Cell[CellGroupData[{ -Cell[2617, 84, 115, 1, 29, "Subsubsection"], -Cell[2735, 87, 99, 1, 31, "Text"], -Cell[2837, 90, 479, 15, 55, "Input"], -Cell[3319, 107, 106, 1, 31, "Text"], -Cell[3428, 110, 411, 12, 32, "Input"], -Cell[3842, 124, 331, 9, 31, "Text"], -Cell[CellGroupData[{ -Cell[4198, 137, 2279, 67, 297, "Input"], -Cell[6480, 206, 173, 3, 47, "Output"], -Cell[6656, 211, 197, 4, 47, "Output"], -Cell[6856, 217, 342, 10, 62, "Output"], -Cell[7201, 229, 479, 15, 62, "Output"], -Cell[7683, 246, 614, 20, 62, "Output"], -Cell[8300, 268, 715, 23, 62, "Output"], -Cell[9018, 293, 854, 28, 62, "Output"], -Cell[9875, 323, 965, 31, 62, "Output"], -Cell[10843, 356, 1115, 36, 62, "Output"], -Cell[11961, 394, 1241, 39, 62, "Output"], -Cell[13205, 435, 1383, 44, 62, "Output"], -Cell[14591, 481, 1517, 47, 62, "Output"], -Cell[16111, 530, 1678, 52, 62, "Output"] -}, Open ]] -}, Open ]], -Cell[CellGroupData[{ -Cell[17838, 588, 115, 1, 29, "Subsubsection"], -Cell[17956, 591, 175, 4, 31, "Text"], -Cell[18134, 597, 106, 1, 31, "Text"], -Cell[18243, 600, 593, 17, 55, "Input"], -Cell[18839, 619, 106, 1, 31, "Text"], -Cell[18948, 622, 463, 13, 32, "Input"], -Cell[19414, 637, 298, 8, 31, "Text"], -Cell[CellGroupData[{ -Cell[19737, 649, 2343, 68, 297, "Input"], -Cell[22083, 719, 294, 6, 47, "Output"], -Cell[22380, 727, 389, 10, 60, "Output"], -Cell[22772, 739, 548, 16, 62, "Output"], -Cell[23323, 757, 639, 19, 62, "Output"], -Cell[23965, 778, 808, 25, 62, "Output"], -Cell[24776, 805, 902, 28, 62, "Output"], -Cell[25681, 835, 1054, 33, 62, "Output"], -Cell[26738, 870, 1159, 36, 62, "Output"], -Cell[27900, 908, 1328, 41, 62, "Output"], -Cell[29231, 951, 1418, 44, 62, "Output"], -Cell[30652, 997, 1598, 49, 62, "Output"], -Cell[32253, 1048, 1705, 52, 62, "Output"], -Cell[33961, 1102, 1939, 58, 100, "Output"] -}, Open ]] -}, Open ]] -} -] -*) - -(* End of internal cache information *) diff --git a/libs/numeric/odeint/ideas/algebra/Jamfile b/libs/numeric/odeint/ideas/algebra/Jamfile deleted file mode 100644 index 1450760d..00000000 --- a/libs/numeric/odeint/ideas/algebra/Jamfile +++ /dev/null @@ -1,13 +0,0 @@ -# (C) Copyright 2010 : Karsten Ahnert, 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) - -#project -# : requirements -# BOOST_ALL_NO_LIB=1 -# ../../../../.. -# ; - -exe test_algebra - : test_algebra.cpp - ; diff --git a/libs/numeric/odeint/ideas/algebra/algebra.hpp b/libs/numeric/odeint/ideas/algebra/algebra.hpp deleted file mode 100644 index cbcce481..00000000 --- a/libs/numeric/odeint/ideas/algebra/algebra.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * range_algebra.hpp - * - * Created on: Feb 12, 2011 - * Author: karsten - */ - -#ifndef RANGE_ALGEBRA_HPP_ -#define RANGE_ALGEBRA_HPP_ - -#include -#include - -#include -#include - -struct algebra1 -{ - struct for_each1_impl - { - template< class S1 , class Op > - void operator()( S1 &s1 , Op op ) const - { - std::for_each( boost::begin( s1 ) , boost::end( s1 ) , op ); - tmp2 = 0.11; - } - typedef void result_type; - }; - - struct for_each2_impl - { - template< class S1 , class Op > - void operator()( S1 &s1 , Op op ) const - { - std::for_each( boost::begin( s1 ) , boost::end( s1 ) , op ); - std::cout << tmp2 << std::endl; - } - typedef void result_type; - }; - - - typedef boost::forward_adapter< for_each1_impl , 2 > for_each1; - - double tmp2; - -}; - - -// alternativ - -struct algebra2 -{ - template< class S1 , class Op > - void for_each1( S1 &s1 , Op op ) - { - tmp = 123.0; - std::for_each( boost::begin( s1 ) , boost::end( s1 ) , op ); - }; - - double tmp; -}; - - - -#endif /* RANGE_ALGEBRA_HPP_ */ diff --git a/libs/numeric/odeint/ideas/algebra/test_algebra.cpp b/libs/numeric/odeint/ideas/algebra/test_algebra.cpp deleted file mode 100644 index b4c173a8..00000000 --- a/libs/numeric/odeint/ideas/algebra/test_algebra.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * test_algebra.cpp - * - * Created on: Feb 12, 2011 - * Author: karsten - */ - -#include -#include - -#include "algebra.hpp" - -using namespace std; - -struct print -{ - template< class T > - void operator()( T t ) - { - cout << t << endl; - } -}; - -int main( int argc , char **argv ) -{ - algebra2 al; - vector< double > vec( 3 ); - vec[0] = 0.1; - vec[1] = 0.95; - vec[2] = 1.23; - - al.for_each1( vec , print() ); - cout << al.tmp << endl; - - algebra1 al2; - -// al2.for_each1()( vec , print() ); -// al.for_each2()( vec , print() ); - - return 0; -} diff --git a/libs/numeric/odeint/ideas/algebra_dispatcher.hpp b/libs/numeric/odeint/ideas/algebra_dispatcher.hpp deleted file mode 100644 index a27339d5..00000000 --- a/libs/numeric/odeint/ideas/algebra_dispatcher.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - boost header: BOOST_NUMERIC_ODEINT/algebra_dispatcher.hpp - - Copyright 2009 Karsten Ahnert - Copyright 2009 Mario Mulansky - Copyright 2009 Andre Bergner - - 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_BOOST_NUMERIC_ODEINT_ALGEBRA_DISPATCHER_HPP_INCLUDED -#define BOOST_BOOST_NUMERIC_ODEINT_ALGEBRA_DISPATCHER_HPP_INCLUDED - -namespace boost { -namespace numeric { -namespace odeint { - - -/* - * ToDo : Implement - */ -template< class Container , class Time > -struct algebra_dispatcher -{ - typedef Container container_type; - typedef Time time_type; - - typedef range_algebra< container_type > type; -}; - - -} // odeint -} // numeric -} // boost - - -#endif //BOOST_BOOST_NUMERIC_ODEINT_ALGEBRA_DISPATCHER_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/butcher/Jamfile b/libs/numeric/odeint/ideas/butcher/Jamfile deleted file mode 100644 index b826c8f7..00000000 --- a/libs/numeric/odeint/ideas/butcher/Jamfile +++ /dev/null @@ -1,29 +0,0 @@ -# (C) Copyright 2010 : Karsten Ahnert, 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) - -import os ; -import modules ; -import path ; - -path-constant HOME : [ os.environ HOME ] ; -path-constant CHRONO_ROOT : [ os.environ CHRONO_ROOT ] ; - -project - : requirements - BOOST_ALL_NO_LIB=1 - ../../../../.. - $(CHRONO_ROOT) - ; - -exe butcher_performance - : butcher_performance.cpp - ; - -exe butcher_lorenz - : butcher_lorenz.cpp - ; - -exe butcher_vdp - : butcher_vdp.cpp - ; \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/butcher/algebra.hpp b/libs/numeric/odeint/ideas/butcher/algebra.hpp deleted file mode 100644 index abdbba05..00000000 --- a/libs/numeric/odeint/ideas/butcher/algebra.hpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * algebra.hpp - * - * Created on: Nov 7, 2010 - * Author: karsten - */ - -#ifndef ALGEBRA_HPP_ -#define ALGEBRA_HPP_ - -#include -#include - -#include -#include - -#include "convert_value.hpp" - -namespace mpl = boost::mpl; - -template< class state_type , class coef_tye , class index > -struct algebra -{ - static void do_step( state_type &x_tmp , const state_type &x , const state_type *k_vector , const double dt ) - {} -}; - -template< class state_type , class coef_type > -struct algebra< state_type , coef_type , mpl::int_< 0 > > -{ - typedef boost::numeric::odeint::range_algebra std_algebra; - typedef boost::numeric::odeint::default_operations std_op; - - typedef typename state_type::iterator iterator; - typedef typename state_type::const_iterator const_iterator; - - static void do_step( state_type &x_tmp , const state_type &x , const state_type *k_vector , const double dt ) - { - const static double a1 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 0 > >::type >::get_value(); - -// iterator first1 = x_tmp.begin() , last1 = x_tmp.end(); -// const_iterator first2 = x.begin() , first3 = k_vector[0].begin(); -// while( first1 != last1 ) -// *first1++ = *first2++ + a1 * *first3++ ; - - - std_algebra::for_each3( x_tmp , x , k_vector[0] , - std_op::scale_sum2<>( 1.0 , a1 ) ); - - -// for( size_t i=0 ; i -struct algebra< state_type , coef_type , mpl::int_< 1 > > -{ - typedef boost::numeric::odeint::range_algebra std_algebra; - typedef boost::numeric::odeint::default_operations std_op; - - typedef typename state_type::iterator iterator; - typedef typename state_type::const_iterator const_iterator; - - static void do_step( state_type &x_tmp , const state_type &x , const state_type *k_vector , const double dt ) - { - const static double a1 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 0 > >::type >::get_value(); - const static double a2 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 1 > >::type >::get_value(); - -// iterator first1 = x_tmp.begin() , last1 = x_tmp.end(); -// const_iterator first2 = x.begin() , first3 = k_vector[0].begin() , first4 = k_vector[1].begin(); -// while( first1 != last1 ) -// *first1++ = *first2++ + a1 * *first3++ + a2 * *first4++; - - std_algebra::for_each4( x_tmp , x , k_vector[0] , k_vector[1] , - std_op::scale_sum3<>( 1.0 , a1 , a2 ) ); - -// for( size_t i=0 ; i >::type >::get_value() * k_vector[0][i] + -// dt * convert_value< typename mpl::at< coef_type , mpl::int_< 1 > >::type >::get_value() * k_vector[1][i]; -// } - } -}; - -template< class state_type , class coef_type > -struct algebra< state_type , coef_type , mpl::int_< 2 > > -{ - typedef boost::numeric::odeint::range_algebra std_algebra; - typedef boost::numeric::odeint::default_operations std_op; - - typedef typename state_type::iterator iterator; - typedef typename state_type::const_iterator const_iterator; - - static void do_step( state_type &x_tmp , const state_type &x , const state_type *k_vector , const double dt ) - { - const static double a1 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 0 > >::type >::get_value(); - const static double a2 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 1 > >::type >::get_value(); - const static double a3 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 2 > >::type >::get_value(); -// -// iterator first1 = x_tmp.begin() , last1 = x_tmp.end(); -// const_iterator first2 = x.begin() , first3 = k_vector[0].begin() , first4 = k_vector[1].begin() , first5 = k_vector[2].begin(); -// while( first1 != last1 ) -// *first1++ = *first2++ + a1 * *first3++ + a2 * *first4++ + a3 * *first5++; - - std_algebra::for_each5( x_tmp , x , k_vector[0] , k_vector[1] , k_vector[2] , - std_op::scale_sum4<>( 1.0 , a1 , a2 , a3 ) ); - -// for( size_t i=0 ; i >::type >::get_value() * k_vector[0][i] + -// dt * convert_value< typename mpl::at< coef_type , mpl::int_< 1 > >::type >::get_value() * k_vector[1][i] + -// dt * convert_value< typename mpl::at< coef_type , mpl::int_< 2 > >::type >::get_value() * k_vector[2][i]; -// } - } -}; - -template< class state_type , class coef_type > -struct algebra< state_type , coef_type , mpl::int_< 3 > > -{ - typedef boost::numeric::odeint::range_algebra std_algebra; - typedef boost::numeric::odeint::default_operations std_op; - - typedef typename state_type::iterator iterator; - typedef typename state_type::const_iterator const_iterator; - - static void do_step( state_type &x_tmp , const state_type &x , const state_type *k_vector , const double dt ) - { - const static double a1 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 0 > >::type >::get_value(); - const static double a2 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 1 > >::type >::get_value(); - const static double a3 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 2 > >::type >::get_value(); - const static double a4 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 3 > >::type >::get_value(); -// -// iterator first1 = x_tmp.begin() , last1 = x_tmp.end(); -// const_iterator first2 = x.begin() , first3 = k_vector[0].begin() , first4 = k_vector[1].begin() , first5 = k_vector[2].begin(); -// const_iterator first6 = k_vector[3].begin(); -// while( first1 != last1 ) -// *first1++ = *first2++ + a1 * *first3++ + a2 * *first4++ + a3 * *first5++ + a4 * *first6++; - - std_algebra::for_each6( x_tmp , x , k_vector[0] , k_vector[1] , k_vector[2] , k_vector[3] , - std_op::scale_sum5<>( 1.0 , a1 , a2 , a3 , a4 ) ); - -// for( size_t i=0 ; i >::type >::get_value() * k_vector[0][i] + -// dt * convert_value< typename mpl::at< coef_type , mpl::int_< 1 > >::type >::get_value() * k_vector[1][i] + -// dt * convert_value< typename mpl::at< coef_type , mpl::int_< 2 > >::type >::get_value() * k_vector[2][i] + -// dt * convert_value< typename mpl::at< coef_type , mpl::int_< 3 > >::type >::get_value() * k_vector[3][i]; -// } - } -}; - -template< class state_type , class coef_type > -struct algebra< state_type , coef_type , mpl::int_< 4 > > -{ - typedef boost::numeric::odeint::range_algebra std_algebra; - typedef boost::numeric::odeint::default_operations std_op; - - typedef typename state_type::iterator iterator; - typedef typename state_type::const_iterator const_iterator; - - static void do_step( state_type &x_tmp , const state_type &x , const state_type *k_vector , const double dt ) - { - const static double a1 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 0 > >::type >::get_value(); - const static double a2 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 1 > >::type >::get_value(); - const static double a3 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 2 > >::type >::get_value(); - const static double a4 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 3 > >::type >::get_value(); - const static double a5 = dt * convert_value< typename mpl::at< coef_type , mpl::int_< 4 > >::type >::get_value(); -// -// iterator first1 = x_tmp.begin() , last1 = x_tmp.end(); -// const_iterator first2 = x.begin() , first3 = k_vector[0].begin() , first4 = k_vector[1].begin() , first5 = k_vector[2].begin(); -// const_iterator first6 = k_vector[3].begin() , first7 = k_vector[4].begin(); -// while( first1 != last1 ) -// *first1++ = *first2++ + a1 * *first3++ + a2 * *first4++ + a3 * *first5++ + a4 * *first6++ + a5 * *first7++; - - std_algebra::for_each7( x_tmp , x , k_vector[0] , k_vector[1] , k_vector[2] , k_vector[3] , k_vector[4] , - std_op::scale_sum6<>( 1.0 , a1 , a2 , a3 , a4 , a5 ) ); - - -// for( size_t i=0 ; i >::type >::get_value() * k_vector[0][i] + -// dt * convert_value< typename mpl::at< coef_type , mpl::int_< 1 > >::type >::get_value() * k_vector[1][i] + -// dt * convert_value< typename mpl::at< coef_type , mpl::int_< 2 > >::type >::get_value() * k_vector[2][i] + -// dt * convert_value< typename mpl::at< coef_type , mpl::int_< 3 > >::type >::get_value() * k_vector[3][i] + -// dt * convert_value< typename mpl::at< coef_type , mpl::int_< 4 > >::type >::get_value() * k_vector[4][i]; -// } - } -}; - - - -#endif /* ALGEBRA_HPP_ */ diff --git a/libs/numeric/odeint/ideas/butcher/butcher_lorenz.cpp b/libs/numeric/odeint/ideas/butcher/butcher_lorenz.cpp deleted file mode 100644 index 0693ad00..00000000 --- a/libs/numeric/odeint/ideas/butcher/butcher_lorenz.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * butcher_test.cpp - * - * Created on: Nov 5, 2010 - * Author: karsten - */ - -#include -#include - -#include - -#include - -#include "predefined_steppers.hpp" - -#define tab "\t" - -using namespace std; - -typedef std::tr1::array< double , 3 > state_type; -typedef mpl_rk4_stepper< state_type > stepper_type; -typedef boost::numeric::odeint::runge_kutta4< state_type > stepper_std_type; - - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - - - - -int main( int argc , char **argv ) -{ - stepper_type stepper; - stepper_std_type stepper_std; - state_type x = {{ 1.0 , 1.0 , 2.0 }}; - state_type x_std = x; - - cout << "Tableau : " << endl; - stepper.print_tableau(); - cout << endl; - - double t = 0.0 , dt = 0.01; - ofstream fout( "lorenz.dat" ); - for( size_t i=0 ; i<10000 ; ++i ) - { - fout << t << tab; - fout << x[0] << tab << x[1] << tab << x[2] << tab; - fout << x_std[0] << tab << x_std[1] << tab << x_std[2] << "\n"; - - stepper.do_step( lorenz , x , t , dt ); - stepper_std.do_step( lorenz , x_std , t , dt ); - t += dt; - } - - - return 0; -} diff --git a/libs/numeric/odeint/ideas/butcher/butcher_performance.cpp b/libs/numeric/odeint/ideas/butcher/butcher_performance.cpp deleted file mode 100644 index 78f8b382..00000000 --- a/libs/numeric/odeint/ideas/butcher/butcher_performance.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * butcher_test.cpp - * - * Created on: Nov 5, 2010 - * Author: karsten - */ - -#include -#include - -#include - -#include -#include -#include -#include - -#include "predefined_steppers.hpp" - -#define tab "\t" - -using namespace std; -using namespace boost::accumulators; - -typedef accumulator_set< - double , stats< tag::mean , tag::variance > - > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - -typedef boost::timer timer_type; - - -typedef std::tr1::array< double , 3 > state_type; -typedef mpl_euler_stepper< state_type > stepper_type; -typedef boost::numeric::odeint::euler< state_type > stepper_std_type; - - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - const double sigma = 10.0; - const double R = 28.0; - const double 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] = x[0]*x[1] - b * x[2]; -} - - - - -int main( int argc , char **argv ) -{ - stepper_type stepper; - stepper_std_type stepper_std; - - const size_t num_of_steps = 20000000; - const size_t dt = 0.01; - - accumulator_type acc1 , acc2; - timer_type timer; - - srand48( 12312354 ); - - while( true ) - { - state_type x = {{ 10.0 * drand48() , 10.0 * drand48() , 10.0 * drand48() }}; - state_type x_std = x; - double t = 0.0 ; - double t_std = 0.0; - - timer.restart(); - for( size_t i=0 ; i -#include - -#include - -#include - -#include "predefined_steppers.hpp" - -#define tab "\t" - -using namespace std; - -typedef std::tr1::array< double , 2 > state_type; -typedef mpl_rk4_stepper< state_type > stepper_type; -typedef boost::numeric::odeint::runge_kutta4< state_type > stepper_std_type; - -void vdp( const state_type &x , state_type &dxdt , double t ) -{ - const double mu = 0.2; - dxdt[0] = x[1]; - dxdt[1] = -x[0] + mu * ( 1.0 - x[0]*x[0] ) * x[1]; -} - - - - - -int main( int argc , char **argv ) -{ - stepper_type midpoint; - stepper_std_type midpoint_std; - state_type x = {{ 1.0 , 1.0 }}; - state_type x_std = x; - - cout << "Tableau : " << endl; - midpoint.print_tableau(); - cout << endl; - - double t = 0.0 , dt = 0.01; - ofstream fout( "vdp.dat" ); - for( size_t i=0 ; i<10000 ; ++i ) - { - fout << t << tab; - fout << x[0] << tab << x[1] << tab ; - fout << x_std[0] << tab << x_std[1] << "\n"; - - midpoint.do_step( vdp , x , t , dt ); - midpoint_std.do_step( vdp , x_std , t , dt ); - t += dt; - } - - - -// cout << double( one_half::num ) / double( one_half::den ) << endl; -// cout << conv< one_half >::get_value() << endl; -// cout << conv< one >::get_value() << endl; - - return 0; -} diff --git a/libs/numeric/odeint/ideas/butcher/convert_value.hpp b/libs/numeric/odeint/ideas/butcher/convert_value.hpp deleted file mode 100644 index 74a5ba9f..00000000 --- a/libs/numeric/odeint/ideas/butcher/convert_value.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * convert_values.hpp - * - * Created on: Nov 7, 2010 - * Author: karsten - */ - -#ifndef CONVERT_VALUE_HPP_ -#define CONVERT_VALUE_HPP_ - - -#include - - -template< class T > -struct convert_value -{ - static double get_value( void ) - { - return double( T::value ); - } -}; - - -template< long N , long D > -struct convert_value< boost::ratio< N , D > > -{ - typedef typename boost::ratio< N , D > number; - static double get_value( void ) - { - return double( number::num ) / double( number::den ); - } -}; - - -#endif /* CONVERT_VALUE_HPP_ */ diff --git a/libs/numeric/odeint/ideas/butcher/diagnostic.hpp b/libs/numeric/odeint/ideas/butcher/diagnostic.hpp deleted file mode 100644 index f7d2dffc..00000000 --- a/libs/numeric/odeint/ideas/butcher/diagnostic.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * diagnostic.hpp - * - * Created on: Nov 7, 2010 - * Author: karsten - */ - -#ifndef DIAGNOSTIC_HPP_ -#define DIAGNOSTIC_HPP_ - -#include - -#include -#include -#include -#include - -#include "convert_value.hpp" - -namespace mpl = boost::mpl; - -struct print_value -{ - template< class T > - void operator()( T ) - { - std::cout << convert_value< T >::get_value() << " "; - } -}; - -struct print_vector -{ - template< class Vec > - void operator()( Vec ) - { - mpl::for_each< Vec >( print_value() ); - std::cout << "\n"; - } -}; - -struct print_tableau_vector -{ - template< class Vec > - void operator()( Vec ) - { - typedef typename mpl::at< Vec , mpl::int_< 0 > >::type index; - typedef typename mpl::at< Vec , mpl::int_< 1 > >::type c; - typedef typename mpl::at< Vec , mpl::int_< 2 > >::type coef; - - std::cout << "Size : " << mpl::size< Vec >::value << "\t"; - std::cout << convert_value< index >::get_value() << " "; - std::cout << convert_value< c >::get_value() << " "; - mpl::for_each< coef >( print_value() ); - std::cout << "\n"; - } -}; - - -#endif /* DIAGNOSTIC_HPP_ */ diff --git a/libs/numeric/odeint/ideas/butcher/explicit_runge_kutta.hpp b/libs/numeric/odeint/ideas/butcher/explicit_runge_kutta.hpp deleted file mode 100644 index 4899eb15..00000000 --- a/libs/numeric/odeint/ideas/butcher/explicit_runge_kutta.hpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * explicit_runge_kutta.hpp - * - * Created on: Nov 5, 2010 - * Author: karsten - */ - -#ifndef EXPLICIT_RUNGE_KUTTA_HPP_ -#define EXPLICIT_RUNGE_KUTTA_HPP_ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "convert_value.hpp" -#include "diagnostic.hpp" -#include "algebra.hpp" - -namespace mpl = boost::mpl; - - -/* - * c_1 | - * c_2 | a_{2,1} - * c_3 | a_{3,1} a_{3,2} - * ... - * c_s | a_{s,1} a_{s,2} ... a_{s,s-1} - * ----------------------------------- - * | b_1 b_2 b_{s-1} b_s - * - * ButcherA : the coefficients a_ij - * - * ButcherC : the time coefficients c_i - * - * ButcherC : the sum coefficients b_j - */ -template< class State , class ButcherA , class ButcherC , class ButcherB > -class explicit_runge_kutta -{ -public: - - typedef ButcherA butcher_a; - typedef ButcherB butcher_b; - typedef ButcherC butcher_c; - - static const size_t dim = mpl::size< ButcherC >::value; - - typedef mpl::range_c< size_t , 0 , dim > indices; - typedef typename mpl::push_back< butcher_a , butcher_b >::type butcher_right; - typedef mpl::zip_view< mpl::vector< indices , butcher_c , butcher_right > > butcher_tableau; - - - typedef double time_type; - typedef State state_type; - - - /* - * t , dt , system, x, k[] - */ - template< class System > - struct calculate_stage - { - System &system; - state_type &x , &x_tmp; - state_type *k_vector; - const double t; - const double dt; - - calculate_stage( System &_system , state_type &_x , state_type &_x_tmp , state_type *_k_vector , const double _t , const double _dt ) - : system( _system ) , x( _x ) , x_tmp( _x_tmp ) , k_vector( _k_vector ) , t( _t ) , dt( _dt ) - {} - - /* - * for( size_t j=0 ; j void operator()( Stage v ) - { - typedef typename mpl::at< Stage , mpl::int_< 0 > >::type index_type; - typedef typename mpl::at< Stage , mpl::int_< 1 > >::type time_value_type; - typedef typename mpl::at< Stage , mpl::int_< 2 > >::type coef_type; - - const static size_t index = index_type::value; - const static double time_value = convert_value< time_value_type >::get_value(); - - BOOST_STATIC_ASSERT(( ( mpl::size< coef_type >::value - 1 ) == index )); - -// cout << index << " " << time_value << " " << endl; - - if( index == 0 ) system( x , k_vector[index] , t + time_value * dt ); - else system( x_tmp , k_vector[index] , t + time_value * dt ); - - if( index == ( dim - 1 ) ) - algebra< state_type , coef_type , mpl::int_< index > >::do_step( x , x , k_vector , dt ); - else - algebra< state_type , coef_type , mpl::int_< index > >::do_step( x_tmp , x , k_vector , dt ); - }; - }; - - - explicit_runge_kutta( void ) - { - } - - template< class System > - void do_step( System &system , state_type &x , double t , const double dt ) - { - mpl::for_each< butcher_tableau >( calculate_stage< System >( system , x , m_x_tmp , m_k_vector , t , dt ) ); - } - - - - void print_butcher_a( void ) - { - mpl::for_each< butcher_a >( print_vector() ); - } - - void print_butcher_b( void ) - { - mpl::for_each< butcher_b >( print_value() ); - } - - void print_butcher_c( void ) - { - mpl::for_each< butcher_c >( print_value() ); - } - - void print_tableau( void ) - { - mpl::for_each< butcher_tableau >( print_tableau_vector() ); - } - - - -private: - - state_type m_k_vector[dim]; - state_type m_x_tmp; - - BOOST_STATIC_ASSERT(( dim > 0 )); - BOOST_STATIC_ASSERT(( dim == size_t( mpl::size< butcher_b >::value ) )); - BOOST_STATIC_ASSERT(( ( dim - 1 ) == mpl::size< butcher_a >::value )); -}; - - -#endif /* EXPLICIT_RUNGE_KUTTA_HPP_ */ diff --git a/libs/numeric/odeint/ideas/butcher/predefined_steppers.hpp b/libs/numeric/odeint/ideas/butcher/predefined_steppers.hpp deleted file mode 100644 index 603fc23a..00000000 --- a/libs/numeric/odeint/ideas/butcher/predefined_steppers.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * predefined_steppers.hpp - * - * Created on: Nov 7, 2010 - * Author: karsten - */ - -#ifndef PREDEFINED_STEPPERS_HPP_ -#define PREDEFINED_STEPPERS_HPP_ - -#include -#include - -#include "explicit_runge_kutta.hpp" - -typedef mpl::int_< 0 > null; -typedef mpl::int_< 1 > one; -typedef boost::ratio< 1 , 2 > one_half; -typedef boost::ratio< 1 , 3 > one_third; -typedef boost::ratio< 1 , 6 > one_sixth; - - - -/* - * euler : - * 0 | - * | 1 - */ - -typedef mpl::vector< null > euler_c; -typedef mpl::vector<> euler_a; -typedef mpl::vector< one > euler_b; - -template< class state_type > -struct mpl_euler_stepper : public explicit_runge_kutta< state_type , euler_a , euler_c , euler_b > { }; - - -/* - * midpoint : - * 0 | - * 1/2 | 1/2 - * ----------- - * | 0 1 - */ - -typedef mpl::vector< null , one_half > midpoint_c; -typedef mpl::vector< mpl::vector< one_half > > midpoint_a; -typedef mpl::vector< null , one > midpoint_b; - -template< class state_type > -struct mpl_midpoint_stepper : public explicit_runge_kutta< state_type , midpoint_a , midpoint_c , midpoint_b > { }; - - - - -/* - * classical Runge Kutta - * 0 | - * 1/2 | 1/2 - * 1/2 | 0 1/2 - * 1 | 0 0 1 - * ------------------ - * | 1/6 1/3 1/6 1/6 - * - */ -typedef mpl::vector< null , one_half , one_half , one > rk4_c; -typedef mpl::vector< - mpl::vector< one_half > , - mpl::vector< null , one_half > , - mpl::vector< null , null , one > - > rk4_a; -typedef mpl::vector< one_sixth , one_third , one_third , one_sixth > rk4_b; - -template< class state_type > -struct mpl_rk4_stepper : public explicit_runge_kutta< state_type , rk4_a , rk4_c , rk4_b > { }; - -#endif /* PREDEFINED_STEPPERS_HPP_ */ diff --git a/libs/numeric/odeint/ideas/controller/Jamfile b/libs/numeric/odeint/ideas/controller/Jamfile deleted file mode 100644 index d183446b..00000000 --- a/libs/numeric/odeint/ideas/controller/Jamfile +++ /dev/null @@ -1,22 +0,0 @@ -# (C) Copyright 2010 : Karsten Ahnert, 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) - -import os ; -import modules ; -import path ; - -project - : requirements - BOOST_ALL_NO_LIB=1 - ../../../../.. - . - ; - -exe controller : controller.cpp ; -exe rb_controller : rb_controller.cpp ; -exe dopri5_controller : dopri5_controller.cpp ; -exe dense_out_dopri5_controller : dense_out_dopri5_controller.cpp ; -exe rb_dense_output : rb_dense_output.cpp ; - -build-project libs/numeric/odeint/test ; \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/controller/default_controller.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/controller/default_controller.hpp deleted file mode 100644 index 98b158d4..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/controller/default_controller.hpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/stepper/controller/default_controller.hpp - - [begin_description] - Default controller for the use in the generic steppers. - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_STEPPER_CONTROLLER_DEFAULT_CONTROLLER_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_CONTROLLER_DEFAULT_CONTROLLER_HPP_INCLUDED - -#include - -#include - -namespace boost { -namespace numeric { -namespace odeint { - -class default_controller -{ -public: - - template< class Value , class Time , class Order > - controlled_step_result operator()( Value error , Time &t , Time &dt , Order stepper_order , Order error_order ) - { - using std::max; - using std::min; - using std::pow; - - if( error > 1.0 ) - { - // error too large - decrease dt ,limit scaling factor to 0.2 and reset state - dt *= max( 0.9 * pow( error , -1.0 / ( Value( error_order ) - 1.0 ) ) , 0.2 ); - return fail; - } - else - { - if( error < 0.5 ) - { - //error too small - increase dt and keep the evolution and limit scaling factor to 5.0 - t += dt; - dt *= min( 0.9 * pow( error , -1.0 / Value( stepper_order ) ) , 5.0 ); - return success; - } - else - { - t += dt; - return success; - } - } - - } -}; - - -} -} -} - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_CONTROLLER_DEFAULT_CONTROLLER_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/controller/pi_controller.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/controller/pi_controller.hpp deleted file mode 100644 index d0018a09..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/controller/pi_controller.hpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/stepper/controller/pi_controller.hpp - - [begin_description] - PI-controller for the use in the generic controller steppers. - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_STEPPER_CONTROLLER_PI_CONTROLLER_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_CONTROLLER_PI_CONTROLLER_HPP_INCLUDED - -#include - -#include - -namespace boost { -namespace numeric { -namespace odeint { - - -template< class Value > -class pi_controller -{ -public: - - typedef Value value_type; - - pi_controller( void ) - : m_err_old( static_cast< value_type >( 1.0e-4 ) ) , m_last_rejected( false ) { } - - - /* - * Returns true if err Ä 1, false otherwise. If step was successful, sets hnext to the estimated - * optimal stepsize for the next step. If the step failed, reduces h appropriately for another try. - * - * Set beta to a nonzero value for PI control. beta D 0:04–0.08 is a good default. - */ - template< class Time , class Order > - controlled_step_result operator()( value_type error , Time &t , Time &dt , Order stepper_order , Order error_order ) - { - using std::max; - using std::min; - using std::pow; - - // ToDo : adapt for values of stepper_order or error_order - const value_type beta = 0.02; - const value_type alpha = 0.2 - beta * 0.75; - const value_type safe = 0.9; - const value_type min_scale = 0.2; - const value_type max_scale = 10.0; - - - - if( error <= 1.0 ) - { - value_type scale = 1.0; - if( error == 0.0 ) - { - scale = max_scale; - } - else - { - // PI control if beta != 0. - scale = safe * pow( error ,-alpha ) * pow( m_err_old , beta ); - if( scale < min_scale ) - scale = min_scale; - if( scale > max_scale ) - scale = max_scale; - } - - if( m_last_rejected ) - { - dt *= min( scale , 1.0 ); - } - else - { - dt *= scale; - } - m_err_old = std::max( error , 1.0e-4 ); - m_last_rejected = false; - t += dt; - return success; - } - else - { - value_type scale = max( safe * pow( error , -alpha ) , min_scale ); - dt *= scale; - m_last_rejected = true; - return fail; - } - } - -private: - - value_type m_err_old; - bool m_last_rejected; -}; - - - -} -} -} - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_CONTROLLER_PI_CONTROLLER_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/controller/stiff_controller.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/controller/stiff_controller.hpp deleted file mode 100644 index a3f375a3..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/controller/stiff_controller.hpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/stepper/controller/stiff_controller.hpp - - [begin_description] - Controller for the use in the generic steppers in combination with solvers for stiff systems. - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_STEPPER_CONTROLLER_STIFF_CONTROLLER_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_CONTROLLER_STIFF_CONTROLLER_HPP_INCLUDED - -#include - -#include - -namespace boost { -namespace numeric { -namespace odeint { - - - -template< class Value > -class stiff_controller -{ -public: - - typedef Value value_type; - - stiff_controller( void ) - : m_first_step( true ) , m_last_rejected( false ) , - m_err_old( 0.0 ) , m_dt_old( 0.0 ) - { } - - template< class Order > - controlled_step_result operator()( value_type error , value_type &t , value_type &dt , Order stepper_order , Order error_order ) - { - typedef Value value_type; - - static const value_type safe = 0.9 , fac1 = 5.0 , fac2 = 1.0 / 6.0; - - value_type fac = std::max( fac2 ,std::min( fac1 , std::pow( error , 0.25 ) / safe ) ); - value_type dt_new = dt / fac; - if ( error <= 1.0 ) - { - if( m_first_step ) - { - m_first_step = false; - } - else - { - value_type fac_pred = ( m_dt_old / dt ) * pow( error * error / m_err_old , 0.25 ) / safe; - fac_pred = std::max( fac2 , std::min( fac1 , fac_pred ) ); - fac = std::max( fac , fac_pred ); - dt_new = dt / fac; - } - - m_dt_old = dt; - m_err_old = std::max( 0.01 , error ); - if( m_last_rejected ) - dt_new = ( dt >= 0.0 ? std::min( dt_new , dt ) : std::max( dt_new , dt ) ); - t += dt; - dt = dt_new; - m_last_rejected = false; - return success; - } - else - { - dt = dt_new; - m_last_rejected = true; - return fail; - } - - - } - -private: - - bool m_first_step; - bool m_last_rejected; - value_type m_err_old; - value_type m_dt_old; -}; - - - -} -} -} - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_CONTROLLER_STIFF_CONTROLLER_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/error_checker_explicit.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/error_checker_explicit.hpp deleted file mode 100644 index 4a85105a..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/error_checker_explicit.hpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/stepper/error_checker_explicit.hpp - - [begin_description] - Error checker for the use in the generic_controlled_steppers in combination with explicit_error_steppers. - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_STEPPER_ERROR_CHECKER_EXPLICIT_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_ERROR_CHECKER_EXPLICIT_HPP_INCLUDED - - -#include - - -namespace boost { -namespace numeric { -namespace odeint { - - -/* - * Error checker for controlled_error_stepper - * - * ToDo: remove, is redundant now - */ -template< class Value , class Algebra , class Operations > -class error_checker_explicit -{ -public: - - typedef Value value_type; - typedef Algebra algebra_type; - typedef Operations operations_type; - - - error_checker_explicit( - const value_type eps_abs = static_cast< value_type >( 1.0e-6 ) , - const value_type eps_rel = static_cast< value_type >( 1.0e-6 ) , - const value_type a_x = static_cast< value_type >( 1.0 ) , - const value_type a_dxdt = static_cast< value_type >( 1.0 ) ) - : m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) , m_a_x( a_x ) , m_a_dxdt( a_dxdt ) - { } - -// template< class State1 , class State2 , class Err , class Time > -// value_type error( const State1 &x_old , const State2 &x , const Err &x_err , const Time &dt ) -// { -// algebra.reduce3( x_err , x_old , x , typename operations_type::template rel_error< value_type >( m_eps_abs , m_eps_rel ) ); -// } - - - template< class State1 , class State2 , class Deriv , class Err , class Time > - value_type error( const State1 &x_old , const State2 &x , const Deriv &dxdt_old , Err &x_err , const Time &dt ) - { - // this overwrites x_err ! - algebra.for_each3( x_err , x_old , dxdt_old , - typename operations_type::template rel_error< value_type >( m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt * detail::get_value( dt ) ) ); - - value_type res = algebra.reduce( x_err , - typename operations_type::template maximum< value_type >() , static_cast< value_type >( 0.0 ) ); - return res; - } - -private: - - value_type m_eps_abs; - value_type m_eps_rel; - value_type m_a_x; - value_type m_a_dxdt; - algebra_type algebra; -}; - - - - - -/* - * Error checker for controlled_error_stepper - * - * ToDo: rename to error_checker_explicit_new - */ -template< class Value , class Algebra , class Operations > -class error_checker_explicit_new -{ -public: - - typedef Value value_type; - typedef Algebra algebra_type; - typedef Operations operations_type; - - - error_checker_explicit_new( - algebra_type &algebra , - const value_type eps_abs = static_cast< value_type >( 1.0e-6 ) , - const value_type eps_rel = static_cast< value_type >( 1.0e-6 ) , - const value_type a_x = static_cast< value_type >( 1.0 ) , - const value_type a_dxdt = static_cast< value_type >( 1.0 ) ) - : m_algebra( algebra ) , m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) , m_a_x( a_x ) , m_a_dxdt( a_dxdt ) - { } - - - template< class State1 , class State2 , class Deriv , class Err , class Time > - value_type error( const State1 &x_old , const State2 &x , const Deriv &dxdt_old , Err &x_err , const Time &dt ) - { - // this overwrites x_err ! - m_algebra.for_each3( x_err , x_old , dxdt_old , - typename operations_type::template rel_error< value_type >( m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt * detail::get_value( dt ) ) ); - - value_type res = m_algebra.reduce( x_err , - typename operations_type::template maximum< value_type >() , static_cast< value_type >( 0.0 ) ); - return res; - } - -private: - - algebra_type &m_algebra; - value_type m_eps_abs; - value_type m_eps_rel; - value_type m_a_x; - value_type m_a_dxdt; -}; - - - -} -} -} - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_ERROR_CHECKER_EXPLICIT_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/error_checker_l2_norm.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/error_checker_l2_norm.hpp deleted file mode 100644 index fb251b1d..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/error_checker_l2_norm.hpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/stepper/default_error_checker_l2_norm.hpp - - [begin_description] - Default error checker for the use in the generic_controlled_steppers. Works with all error_steppers, explicit_error_steppers and - explicit_error_stepper_fsal; - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_STEPPER_ERROR_CHECKER_L2_NORM_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_ERROR_CHECKER_L2_NORM_HPP_INCLUDED - -#include -#include -#include - -namespace boost { -namespace numeric { -namespace odeint { - - - -/* - * Calculate the error in a generic way: - * - * for steppers: err = ||( | err[i] | / ( eps_abs + eps_rel * | x[i] | ) )|| - * for explicit steppers: err = ||( | err[i] | ( eps_abs + eps_rel * ( a_x * | x[i] | + a_dxdt * | dxdt[i] * dt ] ) ) )|| - * for explicit fsal steppers: err = ||( | err[i] | ( eps_abs + eps_rel * ( a_x * | x[i] | + a_dxdt * | dxdt[i] * dt ] ) ) )|| - */ -template< class Value , class Algebra , class Operations , bool HoldsAlgebra = true > -class error_checker_l2_norm -{ -public: - - typedef Value value_type; - typedef Algebra algebra_type; - typedef Operations operations_type; - const static bool holds_algebra = HoldsAlgebra; - const static bool ref_algebra = !holds_algebra; - typedef ref_or_value_holder< algebra_type , ref_algebra > algebra_holder_type; - - error_checker_l2_norm( - typename algebra_holder_type::constructor_type algebra , - const value_type eps_abs = static_cast< value_type >( 1.0e-6 ) , - const value_type eps_rel = static_cast< value_type >( 1.0e-6 ) , - const value_type a_x = static_cast< value_type >( 1.0 ) , - const value_type a_dxdt = static_cast< value_type >( 1.0 )) - : m_algebra( algebra ) , - m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) , m_a_x( a_x ) , m_a_dxdt( a_dxdt ) - { } - - - // overload for steppers, x, x_old and x_err are available - template< class State1 , class State2 , class Err , class Time > - value_type error( const State1 &x_old , const State2 &x , const Err &x_err , const Time &dt ) - { - using std::sqrt; - value_type result = m_algebra.get().reduce3( x_old , x , x_err , - typename operations_type::template rel_error_l2< value_type >( m_eps_abs , m_eps_rel ) , - static_cast< value_type >( 0.0 ) ); - size_t num_elements = boost::numeric::odeint::number_of_elements( x_old ); - if( num_elements != 0 ) return sqrt( result ) / static_cast< value_type >( num_elements ); - return 0.0; - } - - - // overload for explicit steppers, x, x_old, dxdt_old and x_err are available - template< class State1 , class State2 , class Deriv , class Err , class Time > - value_type error( const State1 &x_old , const State2 &x , const Deriv &dxdt_old , Err &x_err , const Time &dt ) - { - using std::sqrt; - value_type result = m_algebra.get().reduce4( x_old , x , dxdt_old , x_err , - typename operations_type::template rel_error_l2_2< value_type >( m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt * detail::get_value( dt ) ) , - static_cast< value_type >( 0.0 ) ); - size_t num_elements = boost::numeric::odeint::number_of_elements( x_old ); - if( num_elements != 0 ) return sqrt( result ) / static_cast< value_type >( num_elements ); - return 0.0; - } - - - // overload for explicit fsal steppers, x, x_old, dxdt, dxdt_old and x_err are available - template< class StateOld , class State , class DerivOld , class Deriv , class Err , class Time > - value_type error( const StateOld &x_old , const State &x , const DerivOld &dxdt_old , const Deriv &dxdt , const Err &x_err , const Time &dt ) - { - using std::sqrt; - value_type result = m_algebra.get().reduce4( x_old , x , dxdt_old , x_err , - typename operations_type::template rel_error_l2_2< value_type >( m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt * detail::get_value( dt ) ) , - static_cast< value_type >( 0.0) ); - size_t num_elements = boost::numeric::odeint::number_of_elements( x_old ); - if( num_elements != 0 ) return sqrt( result ) / static_cast< value_type >( num_elements ); - return 0.0; - } - - - -private: - - algebra_holder_type m_algebra; - value_type m_eps_abs; - value_type m_eps_rel; - value_type m_a_x; - value_type m_a_dxdt; -}; - - -} -} -} - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_ERROR_CHECKER_EXPLICIT_L2_NORM_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/error_checker_max_norm.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/error_checker_max_norm.hpp deleted file mode 100644 index f22f6f96..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/error_checker_max_norm.hpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/stepper/default_error_checker_max_norm.hpp - - [begin_description] - Default error checker for the use in the generic_controlled_steppers. Works with all error_steppers, explicit_error_steppers and - explicit_error_stepper_fsal; - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_STEPPER_ERROR_CHECKER_MAX_NORM_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_ERROR_CHECKER_MAX_NORM_HPP_INCLUDED - - -#include - -namespace boost { -namespace numeric { -namespace odeint { - - - -/* - * Calculate the error in a generic way: - * - * for steppers: err = max_i( | err[i] | / ( eps_abs + eps_rel * | x[i] | ) ) - * for explicit steppers: err = max_i( | err[i] | ( eps_abs + eps_rel * ( a_x * | x[i] | + a_dxdt * | dxdt[i] * dt ] ) ) ) - * for explicit fsal steppers: err = max_i( | err[i] | ( eps_abs + eps_rel * ( a_x * | x[i] | + a_dxdt * | dxdt[i] * dt ] ) ) ) - */ -template< class Value , class Algebra , class Operations , bool HoldsAlgebra = true > -class error_checker_max_norm -{ -public: - - typedef Value value_type; - typedef Algebra algebra_type; - typedef Operations operations_type; - const static bool holds_algebra = HoldsAlgebra; - const static bool ref_algebra = !holds_algebra; - typedef ref_or_value_holder< algebra_type , ref_algebra > algebra_holder_type; - - error_checker_max_norm( - typename algebra_holder_type::constructor_type algebra , - const value_type eps_abs = static_cast< value_type >( 1.0e-6 ) , - const value_type eps_rel = static_cast< value_type >( 1.0e-6 ) , - const value_type a_x = static_cast< value_type >( 1.0 ) , - const value_type a_dxdt = static_cast< value_type >( 1.0 )) - : m_algebra( algebra ) , - m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) , m_a_x( a_x ) , m_a_dxdt( a_dxdt ) - { } - - - // overload for steppers, x, x_old and x_err are available - template< class State1 , class State2 , class Err , class Time > - value_type error( const State1 &x_old , const State2 &x , const Err &x_err , const Time &dt ) - { - value_type result = m_algebra.get().reduce3( x_old , x , x_err , - typename operations_type::template rel_error_max< value_type >( m_eps_abs , m_eps_rel ) , - static_cast< value_type >( 0.0 ) ); - return result; - } - - - // overload for explicit steppers, x, x_old, dxdt_old and x_err are available - template< class State1 , class State2 , class Deriv , class Err , class Time > - value_type error( const State1 &x_old , const State2 &x , const Deriv &dxdt_old , Err &x_err , const Time &dt ) - { - value_type result = m_algebra.get().reduce4( x_old , x , dxdt_old , x_err , - typename operations_type::template rel_error_max2< value_type >( m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt * detail::get_value( dt ) ) , - static_cast< value_type >( 0.0 ) ); - return result; - } - - - // overload for explicit fsal steppers, x, x_old, dxdt, dxdt_old and x_err are available - template< class StateOld , class State , class DerivOld , class Deriv , class Err , class Time > - value_type error( const StateOld &x_old , const State &x , const DerivOld &dxdt_old , const Deriv &dxdt , const Err &x_err , const Time &dt ) - { - value_type result = m_algebra.get().reduce4( x_old , x , dxdt_old , x_err , - typename operations_type::template rel_error_max2< value_type >( m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt * detail::get_value( dt ) ) , - static_cast< value_type >( 0.0) ); - return result; - } - - - -private: - - algebra_holder_type m_algebra; - value_type m_eps_abs; - value_type m_eps_rel; - value_type m_a_x; - value_type m_a_dxdt; -}; - - -} -} -} - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_ERROR_CHECKER_EXPLICIT_MAX_NORM_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper.hpp deleted file mode 100644 index d152a6cd..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper.hpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/stepper/generic_controlled_stepper.hpp - - [begin_description] - Implementation of the generic_controlled_stepper for the error_stepper_tag. Specialized versions - for explicit_error_stepper and explicit_error_stepper_tag also exist. - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_STEPPER_GENERIC_CONTROLLED_STEPPER_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_GENERIC_CONTROLLED_STEPPER_HPP_INCLUDED - - -#include -#include -#include -#include - -#include - -#include - - - -namespace boost { -namespace numeric { -namespace odeint { - - - - -template< - class ErrorStepper , - class ErrorChecker , - class Controller , - class Resizer > -class generic_controlled_stepper< ErrorStepper , ErrorChecker , Controller , Resizer , error_stepper_tag > -{ -public: - - typedef ErrorStepper stepper_type; - typedef ErrorChecker error_checker_type; - typedef Controller controller_type; - typedef Resizer resizer_type; - typedef typename stepper_type::state_type state_type; - typedef typename stepper_type::value_type value_type; - typedef typename stepper_type::time_type time_type; - typedef typename stepper_type::order_type order_type; - typedef explicit_controlled_stepper_tag stepper_category; - typedef state_wrapper< state_type > wrapped_state_type; - - - - generic_controlled_stepper( - const stepper_type &stepper = stepper_type() , - const error_checker_type &error_checker = error_checker_type() , - const controller_type &controller = controller_type() ) - : m_stepper( stepper ) , m_error_checker( error_checker ) , m_controller( controller ) , - m_xerr_resizer() , m_xnew_resizer() , - m_xerr() , m_xnew() { } - - /* - * Version 1 : try_step( sys , x , t , dt ) - * - * The overloads are needed to solve the forwarding problem - */ - template< class System , class StateInOut > - controlled_step_result try_step( System system , StateInOut &x , time_type &t , time_type &dt ) - { - m_xnew_resizer.adjust_size( x , boost::bind( &generic_controlled_stepper::template resize_m_xnew_impl< state_type > , boost::ref( *this ) , _1 ) ); - controlled_step_result result = try_step( system , x , t , m_xnew.m_v , dt ); - if( result == success ) - { - boost::numeric::odeint::copy( m_xnew.m_v , x ); - } - return result; - } - - template< class System , class StateInOut > - controlled_step_result try_step( System system , const StateInOut &x , time_type &t , time_type &dt ) - { - m_xnew_resizer.adjust_size( x , boost::bind( &generic_controlled_stepper::template resize_m_xnew_impl< state_type > , boost::ref( *this ) , _1 ) ); - controlled_step_result result = try_step( system , x , t , m_xnew.m_v , dt ); - if( result == success ) - { - boost::numeric::odeint::copy( m_xnew.m_v , x ); - } - return result; - } - - - - /* - * Version 2 : try_step( sys , in , t , out , dt ) - * - * this version does not solve the forwarding problem, boost.range can not be used - */ - template< class System , class StateIn , class StateOut > - controlled_step_result try_step( System system , const StateIn &in , time_type &t , StateOut &out , time_type &dt ) - { -// return try_step( system , in , m_dxdt.m_v , t , out , dt ); - // ToDo : implement - - m_xerr_resizer.adjust_size( in , boost::bind( &generic_controlled_stepper::template resize_m_xerr_impl< StateIn > , boost::ref( *this ) , _1 ) ); - m_stepper.do_step( system , in , t , out , dt , m_xerr.m_v ); - value_type error = m_error_checker.error( in , out , m_xerr.m_v , dt ); - return m_controller( error , t , dt , m_stepper.stepper_order , m_stepper.error_order ); - - } - - - - - - - - - template< class StateType > - void adjust_size( const StateType &x ) - { - resize_m_xerr_impl( x ); - resize_m_xnew_impl( x ); - m_stepper.adjust_size( x ); - } - - - stepper_type& stepper( void ) { return m_stepper; } - const stepper_type stepper( void ) const { return m_stepper; } - - -private: - - - template< class StateIn > - bool resize_m_xerr_impl( const StateIn &x ) - { - return adjust_size_by_resizeability( m_xerr , x , typename is_resizeable< wrapped_state_type >::type() ); - } - - template< class StateIn > - bool resize_m_xnew_impl( const StateIn &x ) - { - return adjust_size_by_resizeability( m_xnew , x , typename is_resizeable< wrapped_state_type >::type() ); - } - - - - - stepper_type m_stepper; - error_checker_type m_error_checker; - controller_type m_controller; - - resizer_type m_xerr_resizer; - resizer_type m_xnew_resizer; - - wrapped_state_type m_xerr; - wrapped_state_type m_xnew; - -}; - - - - -} -} -} - - - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_GENERIC_CONTROLLED_STEPPER_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper_definition.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper_definition.hpp deleted file mode 100644 index 5ff18340..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper_definition.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/stepper/generic_controlled_stepper_definition.hpp - - [begin_description] - Definition of the generic controlled stepper consisting of an error stepper, an error checker, - and a controller. - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_STEPPER_GENERIC_CONTROLLED_STEPPER_DEFINITION_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_GENERIC_CONTROLLED_STEPPER_DEFINITION_HPP_INCLUDED - - -namespace boost { -namespace numeric { -namespace odeint { - - -template< - class ErrorStepper , - class ErrorChecker , - class Controller , - class Resizer , - class ErrorStepperCategory = typename ErrorStepper::stepper_category > -class generic_controlled_stepper ; - - -} -} -} - - - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_GENERIC_CONTROLLED_STEPPER_DEFINITION_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper_explicit.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper_explicit.hpp deleted file mode 100644 index fd2c3987..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper_explicit.hpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/stepper/generic_controlled_stepper_explicit.hpp - - [begin_description] - Specialization of the generic_controlled_stepper for the explicit_error_stepper_tag. This class is for - runge_kutta54_cash_karp or runge_kutta78_ehlberg. - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_STEPPER_GENERIC_CONTROLLED_STEPPER_EXPLICIT_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_GENERIC_CONTROLLED_STEPPER_EXPLICIT_HPP_INCLUDED - -#include - -#include -#include -#include -#include - -#include - - -namespace boost { -namespace numeric { -namespace odeint { - - - -template< class ErrorStepper , class ErrorChecker , class Controller , class Resizer > -class generic_controlled_stepper< ErrorStepper , ErrorChecker , Controller , Resizer , explicit_error_stepper_tag > -{ -public: - - typedef ErrorStepper stepper_type; - typedef ErrorChecker error_checker_type; - typedef Controller controller_type; - typedef Resizer resizer_type; - typedef typename stepper_type::state_type state_type; - typedef typename stepper_type::value_type value_type; - typedef typename stepper_type::deriv_type deriv_type; - typedef typename stepper_type::time_type time_type; - typedef typename stepper_type::order_type order_type; - typedef explicit_controlled_stepper_tag stepper_category; - typedef state_wrapper< state_type > wrapped_state_type; - typedef state_wrapper< deriv_type > wrapped_deriv_type; - - - - generic_controlled_stepper( - const stepper_type &stepper = stepper_type() , - const error_checker_type &error_checker = error_checker_type() , - const controller_type &controller = controller_type() ) - : m_stepper( stepper ) , m_error_checker( error_checker ) , m_controller( controller ) , - m_dxdt_resizer() , m_xerr_resizer() , m_xnew_resizer() , - m_dxdt() , m_xerr() , m_xnew() { } - - - - /* - * Version 1 : try_step( sys , x , t , dt ) - * - * The overloads are needed to solve the forwarding problem - */ - template< class System , class StateInOut > - controlled_step_result try_step( System system , StateInOut &x , time_type &t , time_type &dt ) - { - return try_step_v1( system , x , t, dt ); - } - - template< class System , class StateInOut > - controlled_step_result try_step( System system , const StateInOut &x , time_type &t , time_type &dt ) - { - return try_step_v1( system , x , t, dt ); - } - - - /* - * Version 2 : try_step( sys , x , dxdt , t , dt ) - * - * this version does not solve the forwarding problem, boost.range can not be used - */ - template< class System , class StateInOut , class DerivIn > - controlled_step_result try_step( System system , StateInOut &x , const DerivIn &dxdt , time_type &t , time_type &dt ) - { - m_xnew_resizer.adjust_size( x , boost::bind( &generic_controlled_stepper::template resize_m_xnew_impl< StateInOut > , boost::ref( *this ) , _1 ) ); - controlled_step_result res = try_step( system , x , dxdt , t , m_xnew.m_v , dt ); - if( res == success ) - { - boost::numeric::odeint::copy( m_xnew.m_v , x ); - } - return res; - } - - /* - * Version 3 : try_step( sys , in , t , out , dt ) - * - * this version does not solve the forwarding problem, boost.range can not be used - */ - template< class System , class StateIn , class StateOut > - controlled_step_result try_step( System system , const StateIn &in , time_type &t , StateOut &out , time_type &dt ) - { - typename boost::unwrap_reference< System >::type &sys = system; - m_dxdt_resizer.adjust_size( in , boost::bind( &generic_controlled_stepper::template resize_m_dxdt_impl< StateIn > , boost::ref( *this ) , _1 ) ); - sys( in , m_dxdt.m_v , t ); - return try_step( system , in , m_dxdt.m_v , t , out , dt ); - } - - - /* - * Version 4 : try_step( sys , in , dxdt , t , out , dt ) - * - * this version does not solve the forwarding problem, boost.range can not be used - */ - template< class System , class StateIn , class DerivIn , class StateOut > - controlled_step_result try_step( System system , const StateIn &in , const DerivIn &dxdt , time_type &t , StateOut &out , time_type &dt ) - { - m_xerr_resizer.adjust_size( in , boost::bind( &generic_controlled_stepper::template resize_m_xerr_impl< StateIn > , boost::ref( *this ) , _1 ) ); - m_stepper.do_step( system , in , dxdt , t , out , dt , m_xerr.m_v ); - value_type error = m_error_checker.error( in , out , dxdt , m_xerr.m_v , dt ); - return m_controller( error , t , dt , m_stepper.stepper_order() , m_stepper.error_order() ); - } - - - - - - - template< class StateType > - void adjust_size( const StateType &x ) - { - resize_m_xerr_impl( x ); - resize_m_dxdt_impl( x ); - resize_m_xnew_impl( x ); - m_stepper.adjust_size( x ); - } - - - stepper_type& stepper( void ) { return m_stepper; } - const stepper_type stepper( void ) const { return m_stepper; } - - -private: - - - template< class StateIn > - bool resize_m_xerr_impl( const StateIn &x ) - { - return adjust_size_by_resizeability( m_xerr , x , typename is_resizeable< wrapped_state_type >::type() ); - } - - template< class StateIn > - bool resize_m_dxdt_impl( const StateIn &x ) - { - return adjust_size_by_resizeability( m_dxdt , x , typename is_resizeable< wrapped_deriv_type >::type() ); - } - - template< class StateIn > - bool resize_m_xnew_impl( const StateIn &x ) - { - return adjust_size_by_resizeability( m_xnew , x , typename is_resizeable< wrapped_state_type >::type() ); - } - - - template< class System , class StateInOut > - controlled_step_result try_step_v1( System system , StateInOut &x , time_type &t , time_type &dt ) - { - typename boost::unwrap_reference< System >::type &sys = system; - m_dxdt_resizer.adjust_size( x , boost::bind( &generic_controlled_stepper::template resize_m_dxdt_impl< StateInOut > , boost::ref( *this ) , _1 ) ); - sys( x , m_dxdt.m_v ,t ); - return try_step( system , x , m_dxdt.m_v , t , dt ); - } - - - stepper_type m_stepper; - error_checker_type m_error_checker; - controller_type m_controller; - - resizer_type m_dxdt_resizer; - resizer_type m_xerr_resizer; - resizer_type m_xnew_resizer; - - wrapped_deriv_type m_dxdt; - wrapped_state_type m_xerr; - wrapped_state_type m_xnew; -}; - - - - - - -} -} -} - - - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_GENERIC_CONTROLLED_STEPPER_EXPLICIT_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper_explicit_fsal.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper_explicit_fsal.hpp deleted file mode 100644 index 591a35c8..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_controlled_stepper_explicit_fsal.hpp +++ /dev/null @@ -1,454 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/stepper/generic_controlled_stepper_explicit_fsal.hpp - - [begin_description] - Specialization of the generic_controlled_stepper for the explicit_error_stepper_fsal_tag. This class is for - runge_kutta_dopri5. - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_STEPPER_GENERIC_CONTROLLED_STEPPER_EXPLICIT_FSAL_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_GENERIC_CONTROLLED_STEPPER_EXPLICIT_FSAL_HPP_INCLUDED - -#include - -#include -#include -#include -#include - -#include - - -namespace boost { -namespace numeric { -namespace odeint { - - - -template< class ErrorStepper , class ErrorChecker , class Controller , class Resizer > -class generic_controlled_stepper< ErrorStepper , ErrorChecker , Controller , Resizer , explicit_error_stepper_fsal_tag > -{ -public: - - typedef ErrorStepper stepper_type; - typedef ErrorChecker error_checker_type; - typedef Controller controller_type; - typedef Resizer resizer_type; - typedef typename stepper_type::state_type state_type; - typedef typename stepper_type::value_type value_type; - typedef typename stepper_type::deriv_type deriv_type; - typedef typename stepper_type::time_type time_type; - typedef typename stepper_type::order_type order_type; - typedef explicit_controlled_stepper_fsal_tag stepper_category; - typedef state_wrapper< state_type > wrapped_state_type; - typedef state_wrapper< deriv_type > wrapped_deriv_type; - - - - generic_controlled_stepper( - const stepper_type &stepper = stepper_type() , - const error_checker_type &error_checker = error_checker_type() , - const controller_type &controller = controller_type() ) - : m_stepper( stepper ) , m_error_checker( error_checker ) , m_controller( controller ) , - m_dxdt_resizer() , m_xerr_resizer() , m_xnew_resizer() , m_dxdt_new_resizer() , - m_xerr() , - m_first_call( true ) - { } - - - /* - * Version 1 : try_step( sys , x , t , dt ) - * - * The two overloads are needed in order to solve the forwarding problem - */ - template< class System , class StateInOut > - controlled_step_result try_step( System system , StateInOut &x , time_type &t , time_type &dt ) - { - return try_step_v1( system , x , t , dt ); - } - - template< class System , class StateInOut > - controlled_step_result try_step( System system , const StateInOut &x , time_type &t , time_type &dt ) - { - return try_step_v1( system , x , t , dt ); - } - - - - /* - * Version 2 : try_step( sys , in , t , out , dt ); - * - * This version does not solve the forwarding problem, boost::range can not be used. - */ - template< class System , class StateIn , class StateOut > - controlled_step_result try_step( System system , const StateIn &in , time_type &t , StateOut &out , time_type &dt ) - { - if( m_dxdt_resizer.adjust_size( in , boost::bind( &generic_controlled_stepper::template resize_m_dxdt_impl< StateIn > , boost::ref( *this ) , _1 ) ) || m_first_call ) - { - typename boost::unwrap_reference< System >::type &sys = system; - sys( in , m_dxdt.m_v ,t ); - m_first_call = false; - } - return try_step( system , in , m_dxdt.m_v , t , out , dt ); - } - - - /* - * Version 3 : try_step( sys , x , dxdt , t , dt ) - * - * This version does not solve the forwarding problem, boost::range can not be used. - */ - template< class System , class StateInOut , class DerivInOut > - controlled_step_result try_step( System system , StateInOut &x , DerivInOut &dxdt , time_type &t , time_type &dt ) - { - m_xnew_resizer.adjust_size( x , boost::bind( &generic_controlled_stepper::template resize_m_xnew_impl< StateInOut > , boost::ref( *this ) , _1 ) ); - m_dxdt_new_resizer.adjust_size( x , boost::bind( &generic_controlled_stepper::template resize_m_dxdt_new_impl< StateInOut > , boost::ref( *this ) , _1 ) ); - controlled_step_result res = try_step( system , x , dxdt , t , m_xnew.m_v , m_dxdt_new.m_v , dt ); - if( res == success ) - { - boost::numeric::odeint::copy( m_xnew.m_v , x ); - boost::numeric::odeint::copy( m_dxdt_new.m_v , dxdt ); - } - return res; - } - - - /* - * Version 4 : try_step( sys , in , dxdt , t , out , dxdtout , dt ) - * - * This version does not solve the forwarding problem, boost::range can not be used. - */ - template< class System , class StateIn , class DerivIn , class StateOut , class DerivOut > - controlled_step_result try_step( System system , const StateIn &in , const DerivIn &dxdt_in , time_type &t , - StateOut &out , DerivOut &dxdt_out , time_type &dt ) - { - m_xerr_resizer.adjust_size( in , boost::bind( &generic_controlled_stepper::template resize_m_xerr_impl< StateIn > , boost::ref( *this ) , _1 ) ); - m_stepper.do_step( system , in , dxdt_in , t , out , dxdt_out , dt , m_xerr.m_v ); - value_type error = m_error_checker.error( in , out , dxdt_in , m_xerr.m_v , dt ); - return m_controller( error , t , dt , m_stepper.stepper_order() , m_stepper.error_order() ); - } - - - - - - - - - - template< class StateType > - void adjust_size( const StateType &x ) - { - resize_m_xerr_impl( x ); - resize_m_dxdt_impl( x ); - resize_m_xnew_impl( x ); - resize_m_dxdt_new_impl( x ); - m_stepper.adjust_size( x ); - } - - - stepper_type& stepper( void ) { return m_stepper; } - const stepper_type stepper( void ) const { return m_stepper; } - - -private: - - - - template< class System , class StateInOut > - controlled_step_result try_step_v1( System system , StateInOut &x , time_type &t , time_type &dt ) - { - if( m_dxdt_resizer.adjust_size( x , boost::bind( &generic_controlled_stepper::template resize_m_dxdt_impl< StateInOut > , boost::ref( *this ) , _1 ) ) || m_first_call ) - { - typename boost::unwrap_reference< System >::type &sys = system; - sys( x , m_dxdt.m_v , t ); - m_first_call = false; - } - return try_step( system , x , m_dxdt.m_v , t , dt ); - } - - - - template< class StateIn > - bool resize_m_xerr_impl( const StateIn &x ) - { - return adjust_size_by_resizeability( m_xerr , x , typename is_resizeable< wrapped_state_type >::type() ); - } - - template< class StateIn > - bool resize_m_dxdt_impl( const StateIn &x ) - { - return adjust_size_by_resizeability( m_dxdt , x , typename is_resizeable< wrapped_deriv_type >::type() ); - } - - template< class StateIn > - bool resize_m_xnew_impl( const StateIn &x ) - { - return adjust_size_by_resizeability( m_xnew , x , typename is_resizeable< wrapped_state_type >::type() ); - } - - template< class StateIn > - bool resize_m_dxdt_new_impl( const StateIn &x ) - { - return adjust_size_by_resizeability( m_dxdt_new , x , typename is_resizeable< wrapped_deriv_type >::type() ); - } - - - - - - stepper_type m_stepper; - error_checker_type m_error_checker; - controller_type m_controller; - - resizer_type m_dxdt_resizer; - resizer_type m_xerr_resizer; - resizer_type m_xnew_resizer; - resizer_type m_dxdt_new_resizer; - - wrapped_deriv_type m_dxdt; - wrapped_deriv_type m_dxdt_new; - wrapped_state_type m_xerr; - wrapped_state_type m_xnew; - - bool m_first_call; -}; - - - - - -//template< class ErrorStepper , class ErrorChecker , class Resizer > -//class controlled_runge_kutta< ErrorStepper , ErrorChecker , Resizer , explicit_error_stepper_fsal_tag > -//{ -// -//public: -// -// typedef ErrorStepper stepper_type; -// typedef typename stepper_type::state_type state_type; -// typedef typename stepper_type::value_type value_type; -// typedef typename stepper_type::deriv_type deriv_type; -// typedef typename stepper_type::time_type time_type; -// typedef typename stepper_type::order_type order_type; -// typedef typename stepper_type::algebra_type algebra_type; -// typedef typename stepper_type::operations_type operations_type; -// typedef Resizer resizer_type; -// typedef ErrorChecker error_checker_type; -// typedef explicit_controlled_stepper_fsal_tag stepper_category; -// typedef typename stepper_type::wrapped_state_type wrapped_state_type; -// typedef typename stepper_type::wrapped_deriv_type wrapped_deriv_type; -// -// typedef controlled_runge_kutta< ErrorStepper , ErrorChecker , Resizer , explicit_error_stepper_tag > controlled_stepper_type; -// -// controlled_runge_kutta( -// const error_checker_type &error_checker = error_checker_type() , -// const stepper_type &stepper = stepper_type() -// ) -// : m_stepper( stepper ) , m_error_checker( error_checker ) , -// m_first_call( true ) -// { } -// -// /* -// * Version 1 : try_step( sys , x , t , dt ) -// * -// * The two overloads are needed in order to solve the forwarding problem -// */ -// template< class System , class StateInOut > -// controlled_step_result try_step( System system , StateInOut &x , time_type &t , time_type &dt ) -// { -// return try_step_v1( system , x , t , dt ); -// } -// -// template< class System , class StateInOut > -// controlled_step_result try_step( System system , const StateInOut &x , time_type &t , time_type &dt ) -// { -// return try_step_v1( system , x , t , dt ); -// } -// -// -// -// /* -// * Version 2 : try_step( sys , in , t , out , dt ); -// * -// * This version does not solve the forwarding problem, boost::range can not be used. -// */ -// template< class System , class StateIn , class StateOut > -// controlled_step_result try_step( System system , const StateIn &in , time_type &t , StateOut &out , time_type &dt ) -// { -// if( m_dxdt_resizer.adjust_size( in , boost::bind( &controlled_runge_kutta::template resize_m_dxdt_impl< StateIn > , boost::ref( *this ) , _1 ) ) || m_first_call ) -// { -// typename boost::unwrap_reference< System >::type &sys = system; -// sys( in , m_dxdt.m_v ,t ); -// m_first_call = false; -// } -// return try_step( system , in , m_dxdt.m_v , t , out , dt ); -// } -// -// -// /* -// * Version 3 : try_step( sys , x , dxdt , t , dt ) -// * -// * This version does not solve the forwarding problem, boost::range can not be used. -// */ -// template< class System , class StateInOut , class DerivInOut > -// controlled_step_result try_step( System system , StateInOut &x , DerivInOut &dxdt , time_type &t , time_type &dt ) -// { -// m_xnew_resizer.adjust_size( x , boost::bind( &controlled_runge_kutta::template resize_m_xnew_impl< StateInOut > , boost::ref( *this ) , _1 ) ); -// m_dxdt_new_resizer.adjust_size( x , boost::bind( &controlled_runge_kutta::template resize_m_dxdt_new_impl< StateInOut > , boost::ref( *this ) , _1 ) ); -// controlled_step_result res = try_step( system , x , dxdt , t , m_xnew.m_v , m_dxdtnew.m_v , dt ); -// if( res == success ) -// { -// boost::numeric::odeint::copy( m_xnew.m_v , x ); -// boost::numeric::odeint::copy( m_dxdtnew.m_v , dxdt ); -// } -// return res; -// } -// -// -// /* -// * Version 3 : try_step( sys , in , dxdt , t , out , dt ) -// * -// * This version does not solve the forwarding problem, boost::range can not be used. -// */ -// template< class System , class StateIn , class DerivIn , class StateOut , class DerivOut > -// controlled_step_result try_step( System system , const StateIn &in , const DerivIn &dxdt_in , time_type &t , -// StateOut &out , DerivOut &dxdt_out , time_type &dt ) -// { -// using std::max; -// using std::min; -// using std::pow; -// -// m_xerr_resizer.adjust_size( in , boost::bind( &controlled_runge_kutta::template resize_m_xerr_impl< StateIn > , boost::ref( *this ) , _1 ) ); -// -// //fsal: m_stepper.get_dxdt( dxdt ); -// //fsal: m_stepper.do_step( sys , x , dxdt , t , dt , m_x_err ); -// m_stepper.do_step( system , in , dxdt_in , t , out , dxdt_out , dt , m_xerr.m_v ); -// -// // this potentially overwrites m_x_err! (standard_error_checker does, at least) -// value_type max_rel_err = m_error_checker.error( m_stepper.algebra() , in , dxdt_in , m_xerr.m_v , dt ); -// -// if( max_rel_err > 1.1 ) -// { -// // error too large - decrease dt ,limit scaling factor to 0.2 and reset state -// dt *= max( 0.9 * pow( max_rel_err , -1.0 / ( m_stepper.error_order() - 1.0 ) ) , 0.2 ); -// return fail; -// } -// else -// { -// if( max_rel_err < 0.5 ) -// { -// //error too small - increase dt and keep the evolution and limit scaling factor to 5.0 -// t += dt; -// dt *= min( 0.9 * pow( max_rel_err , -1.0 / m_stepper.stepper_order() ) , 5.0 ); -// return success; -// } -// else -// { -// t += dt; -// return success; -// } -// } -// } -// -// -// -// -// template< class StateType > -// void adjust_size( const StateType &x ) -// { -// resize_m_xerr_impl( x ); -// resize_m_dxdt_impl( x ); -// resize_m_dxdt_new_impl( x ); -// resize_m_xnew_impl( x ); -// } -// -// -// stepper_type& stepper( void ) -// { -// return m_stepper; -// } -// -// const stepper_type& stepper( void ) const -// { -// return m_stepper; -// } -// -// -// -//private: -// -// -// template< class StateIn > -// bool resize_m_xerr_impl( const StateIn &x ) -// { -// return adjust_size_by_resizeability( m_xerr , x , typename is_resizeable::type() ); -// } -// -// template< class StateIn > -// bool resize_m_dxdt_impl( const StateIn &x ) -// { -// return adjust_size_by_resizeability( m_dxdt , x , typename is_resizeable::type() ); -// } -// -// template< class StateIn > -// bool resize_m_dxdt_new_impl( const StateIn &x ) -// { -// return adjust_size_by_resizeability( m_dxdtnew , x , typename is_resizeable::type() ); -// } -// -// template< class StateIn > -// bool resize_m_xnew_impl( const StateIn &x ) -// { -// return adjust_size_by_resizeability( m_xnew , x , typename is_resizeable::type() ); -// } -// -// -// template< class System , class StateInOut > -// controlled_step_result try_step_v1( System system , StateInOut &x , time_type &t , time_type &dt ) -// { -// if( m_dxdt_resizer.adjust_size( x , boost::bind( &controlled_runge_kutta::template resize_m_dxdt_impl< StateInOut > , boost::ref( *this ) , _1 ) ) || m_first_call ) -// { -// typename boost::unwrap_reference< System >::type &sys = system; -// sys( x , m_dxdt.m_v , t ); -// m_first_call = false; -// } -// return try_step( system , x , m_dxdt.m_v , t , dt ); -// } -// -// -// stepper_type m_stepper; -// error_checker_type m_error_checker; -// -// resizer_type m_dxdt_resizer; -// resizer_type m_xerr_resizer; -// resizer_type m_xnew_resizer; -// resizer_type m_dxdt_new_resizer; -// -// wrapped_deriv_type m_dxdt; -// wrapped_state_type m_xerr; -// wrapped_state_type m_xnew; -// wrapped_deriv_type m_dxdtnew; -// bool m_first_call; -//}; - - - - - -} -} -} - - - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_GENERIC_CONTROLLED_STEPPER_EXPLICIT_FSAL_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_dense_output_stepper.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_dense_output_stepper.hpp deleted file mode 100644 index 00db1aa3..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_dense_output_stepper.hpp +++ /dev/null @@ -1,208 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/stepper/generic_dense_output_stepper.hpp - - [begin_description] - Implementation of a generic dense output stepper - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_STEPPER_GENERIC_DENSE_OUTPUT_STEPPER_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_GENERIC_DENSE_OUTPUT_STEPPER_HPP_INCLUDED - - -#include -#include -#include - -#include - - - -namespace boost { -namespace numeric { -namespace odeint { - - -template< class ControlledStepper > -class generic_dense_output_stepper< ControlledStepper , controlled_stepper_tag > -{ -public: - - void copy_variables( const generic_dense_output_stepper &stepper ) - { - m_stepper = stepper.m_stepper; - m_x1 = stepper.m_x1; - m_x2 = stepper.m_x2; - if( stepper.m_current_state == ( & ( stepper.m_x1 ) ) ) - { - m_current_state = &m_x1; - m_old_state = &m_x2; - } - else - { - m_current_state = &m_x2; - m_old_state = &m_x1; - } - m_t = stepper.m_t; - m_t_old = stepper.m_t_old; - m_dt = stepper.m_dt; - } - -public: - - typedef ControlledStepper controlled_stepper_type; - typedef typename controlled_stepper_type::stepper_type stepper_type; - typedef typename stepper_type::value_type value_type; - typedef typename stepper_type::state_type state_type; - typedef typename stepper_type::time_type time_type; - typedef typename stepper_type::deriv_type deriv_type; - typedef typename stepper_type::resizer_type resizer_type; - typedef state_wrapper< state_type > wrapped_state_type; - typedef state_wrapper< deriv_type > wrapped_deriv_type; - - typedef dense_output_stepper_tag stepper_category; - - typedef generic_dense_output_stepper< ControlledStepper > dense_output_stepper_type; - - generic_dense_output_stepper( const controlled_stepper_type &stepper = controlled_stepper_type() ) - : m_stepper( stepper ) , - m_x1() , m_x2() , m_current_state( &m_x1.m_v ) , m_old_state( &m_x2.m_v ) , - m_t() , m_t_old() , m_dt() - { } - - generic_dense_output_stepper( const generic_dense_output_stepper &rb ) - : m_current_state( &m_x1.m_v ) , m_old_state( &m_x2.m_v ) - { } - - generic_dense_output_stepper& operator=( const generic_dense_output_stepper &rb ) - { - copy_variables( rb ); - return *this; - } - - - - template< class StateType > - void initialize( const StateType &x0 , const time_type &t0 , const time_type &dt0 ) - { - m_resizer.adjust_size( x0 , boost::bind( &dense_output_stepper_type::template resize_impl< StateType > , boost::ref( *this ) , _1 ) ); - *m_current_state = x0; - m_t = t0; - m_dt = dt0; - } - - template< class System > - std::pair< time_type , time_type > do_step( System system ) - { - const size_t max_count = 1000; - - controlled_step_result res = fail; - m_t_old = m_t; - size_t count = 0; - do - { - res = m_stepper.try_step( system , *m_current_state , m_t , *m_old_state , m_dt ); - if( count++ == max_count ) - throw std::overflow_error( "generic_dense_output_stepper : too much iterations!"); - } - while( res == fail ); - m_stepper.stepper().prepare_dense_output(); - std::swap( m_current_state , m_old_state ); - return std::make_pair( m_t_old , m_t ); - } - - - /* - * The two overloads are needed in order to solve the forwarding problem. - */ - template< class StateOut > - void calc_state( const time_type &t , StateOut &x ) - { - m_stepper.stepper().calc_state( t , x , *m_old_state , m_t_old , *m_current_state , m_t ); - } - - template< class StateOut > - void calc_state( const time_type &t , const StateOut &x ) - { - m_stepper.stepper().calc_state( t , x , *m_old_state , m_t_old , *m_current_state , m_t ); - } - - - template< class StateType > - void adjust_size( const StateType &x ) - { - m_stepper.adjust_size( x ); - resize_impl( x ); - } - - - - - const state_type& current_state( void ) const - { - return *m_current_state; - } - - const time_type& current_time( void ) const - { - return m_t; - } - - const time_type& previous_state( void ) const - { - return *m_old_state; - } - - const time_type& previous_time( void ) const - { - return m_t_old; - } - - const time_type& current_time_step( void ) const - { - return m_dt; - } - - - - -private: - - template< class StateIn > - bool resize_impl( const StateIn &x ) - { - bool resized = false; - resized |= adjust_size_by_resizeability( m_x1 , x , typename is_resizeable::type() ); - resized |= adjust_size_by_resizeability( m_x2 , x , typename is_resizeable::type() ); - return resized; - } - - - controlled_stepper_type m_stepper; - resizer_type m_resizer; - wrapped_state_type m_x1 , m_x2; - state_type *m_current_state , *m_old_state; - time_type m_t , m_t_old , m_dt; - - -}; - - - - -} -} -} - - - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_GENERIC_DENSE_OUTPUT_STEPPER_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_dense_output_stepper_definition.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_dense_output_stepper_definition.hpp deleted file mode 100644 index 76baa897..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/stepper/generic_dense_output_stepper_definition.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/stepper/generic_dense_output_stepper_definition.hpp - - [begin_description] - Definition of the generic dense output stepper encapsulating a stepper capable of calculating intermediate steps. - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_STEPPER_GENERIC_DENSE_OUTPUT_STEPPER_DEFINITION_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_GENERIC_DENSE_OUTPUT_STEPPER_DEFINITION_HPP_INCLUDED - - -namespace boost { -namespace numeric { -namespace odeint { - - -template< - class Stepper , - class StepperCategory = typename Stepper::stepper_category > -class generic_dense_output_stepper ; - - -} -} -} - - - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_GENERIC_DENSE_OUTPUT_STEPPER_DEFINITION_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/util/number_of_elements.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/util/number_of_elements.hpp deleted file mode 100644 index 8d2d8dea..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/util/number_of_elements.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/util/number_of_elements.hpp - - [begin_description] - Generic number of elements (size) function. - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_UTIL_NUMBER_OF_ELEMENTS_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_UTIL_NUMBER_OF_ELEMENTS_HPP_INCLUDED - - - -namespace boost { -namespace numeric { -namespace odeint { - -template< class T > -struct number_of_elements_impl -{ - typedef typename T::size_type size_type; - typedef size_type result_type; - - static result_type number_of_elements( const T &x ) - { - return x.size(); - } - - -}; - - -template< class T > -typename number_of_elements_impl< T >::result_type number_of_elements( const T &x ) -{ - return number_of_elements_impl< T >::number_of_elements( x ); -} - - -} // namespace odeint -} // namespace numeric -} // namespace boost - - - -#endif // BOOST_NUMERIC_ODEINT_UTIL_NUMBER_OF_ELEMENTS_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/util/ref_or_value_holder.hpp b/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/util/ref_or_value_holder.hpp deleted file mode 100644 index 46daaec2..00000000 --- a/libs/numeric/odeint/ideas/controller/boost/numeric/odeint/util/ref_or_value_holder.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - [auto_generated] - boost/numeric/odeint/util/ref_or_value_holder.hpp - - [begin_description] - Util class for holding either a value or a reference. - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_UTIL_REF_OR_VALUE_HOLDER_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_UTIL_REF_OR_VALUE_HOLDER_HPP_INCLUDED - - -namespace boost { -namespace numeric { -namespace odeint { - -/* - * ToDo : find nice names for the types in ref_or_value_holder - */ - -template< class T , bool RefOrVariable > struct ref_or_value_holder ; -// template< class T , bool RefOrVariable > struct cref_or_value_holder ; - -template< class T > -struct ref_or_value_holder< T , true > -{ - typedef T value_type; - typedef T& holder_type; - typedef T& constructor_type; - typedef T& reference_type; - - holder_type m_t; - ref_or_value_holder( constructor_type t ) : m_t( t ) { } - reference_type get( void ) { return m_t; } -}; - -template< class T > -struct ref_or_value_holder< T , false > -{ - typedef T value_type; - typedef T holder_type; - typedef const T& constructor_type; - typedef T& reference_type; - - holder_type m_t; - ref_or_value_holder( constructor_type t ) : m_t( t ) { } - reference_type get( void ) { return m_t; } -}; - -//template< class T > -//struct cref_or_value_holder< T , true > -//{ -// const T &m_t; -// cref_or_value_holder( const T &t ) : m_t( t ) { } -// const T& get( void ) { return m_t; } -//}; -// -//template< class T > -//struct cref_or_value_holder< T , false > -//{ -// const T m_t; -// cref_or_value_holder( const T &t ) : m_t( t ) { } -// const T& get( void ) { return m_t; } -//}; - - -} // namespace odeint -} // namespace numeric -} // namespace boost - - - -#endif // BOOST_NUMERIC_ODEINT_UTIL_REF_OR_VALUE_HOLDER_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/controller/controller.cpp b/libs/numeric/odeint/ideas/controller/controller.cpp deleted file mode 100644 index e507d2ba..00000000 --- a/libs/numeric/odeint/ideas/controller/controller.cpp +++ /dev/null @@ -1,142 +0,0 @@ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - - -#define tab "\t" - -namespace boost { -namespace numeric { -namespace odeint { - - - - -/* - * move this class into controller_runge_kutta.hpp - */ -template< class Stepper > -class controlled_runge_kutta_explicit : - public generic_controlled_stepper< - Stepper , - error_checker_explicit_new< typename Stepper::value_type , typename Stepper::algebra_type , typename Stepper::operations_type > , - default_controller , - typename Stepper::resizer_type , - typename Stepper::stepper_category > -{ -public: - - typedef generic_controlled_stepper< - Stepper , - error_checker_explicit_new< typename Stepper::value_type , typename Stepper::algebra_type , typename Stepper::operations_type > , - default_controller , - typename Stepper::resizer_type , - typename Stepper::stepper_category > base_type; - typedef error_checker_explicit_new< typename Stepper::value_type , typename Stepper::algebra_type , typename Stepper::operations_type > error_checker_type; - typedef typename Stepper::value_type value_type; - - controlled_runge_kutta_explicit( const Stepper &stepper = Stepper() , - const value_type eps_abs = static_cast< value_type >( 1.0e-6 ) , - const value_type eps_rel = static_cast< value_type >( 1.0e-6 ) , - const value_type a_x = static_cast< value_type >( 1.0 ) , - const value_type a_dxdt = static_cast< value_type >( 1.0 ) ) - : base_type( stepper , - error_checker_type( base_type::stepper().algebra() , eps_abs , eps_rel , a_x , a_dxdt ) - ) { } -}; - - -} -} -} - - - - -typedef boost::array< double , 3 > state_type; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - const double sigma = 10.0; - const double R = 28.0; - const double 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]; -} - - -int main( int argc , char **argv ) -{ - using namespace std; - using namespace boost::numeric::odeint; - - generic_controlled_stepper< - runge_kutta_cash_karp54< state_type > , - error_checker_explicit< double , range_algebra , default_operations > , - default_controller , - initially_resizer , - explicit_error_stepper_tag > stepper1; - - controlled_runge_kutta< runge_kutta_cash_karp54< state_type > > stepper2; - controlled_runge_kutta_explicit< runge_kutta_cash_karp54< state_type > > stepper3; - - generic_controlled_stepper< - runge_kutta_cash_karp54< state_type > , - error_checker_explicit< double , range_algebra , default_operations > , - pi_controller< double > , - initially_resizer , - explicit_error_stepper_tag > stepper4; - - - state_type x1 = {{ 10.0 , 10.0 , 10.0 }}; - state_type x2 = x1; - state_type x3 = x1; - state_type x4 = x1; - - boost::timer timer; - const double t_max = 100000.0; - - timer.restart(); - size_t steps1 = integrate_adaptive( stepper1 , lorenz , x1 , 0.0 , t_max , 0.1 ); - double t1 = timer.elapsed(); - cout << steps1 << tab << t1 << tab << x1[0] << tab << x1[1] << tab << x1[2] << endl; - - timer.restart(); - size_t steps2 = integrate_adaptive( stepper2 , lorenz , x2 , 0.0 , t_max , 0.1 ); - double t2 = timer.elapsed(); - cout << steps2 << tab << t2 << tab << x2[0] << tab << x2[1] << tab << x2[2] << endl; - - timer.restart(); - size_t steps3 = integrate_adaptive( stepper3 , lorenz , x3 , 0.0 , t_max , 0.1 ); - double t3 = timer.elapsed(); - cout << steps3 << tab << t3 << tab << x3[0] << tab << x3[1] << tab << x3[2] << endl; - - timer.restart(); - size_t steps4 = integrate_adaptive( stepper4 , lorenz , x4 , 0.0 , t_max , 0.1 ); - double t4 = timer.elapsed(); - cout << steps4 << tab << t4 << tab << x4[0] << tab << x4[1] << tab << x4[2] << endl; - - - - - return 0; -} diff --git a/libs/numeric/odeint/ideas/controller/dense_out_dopri5_controller.cpp b/libs/numeric/odeint/ideas/controller/dense_out_dopri5_controller.cpp deleted file mode 100644 index 57d2edfa..00000000 --- a/libs/numeric/odeint/ideas/controller/dense_out_dopri5_controller.cpp +++ /dev/null @@ -1,168 +0,0 @@ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - - -#define tab "\t" - -namespace boost { -namespace numeric { -namespace odeint { - - - - -/* - * move this class into controller_runge_kutta.hpp - */ -template< class Stepper > -class controlled_runge_kutta_explicit : - public generic_controlled_stepper< - Stepper , - error_checker_explicit_new< typename Stepper::value_type , typename Stepper::algebra_type , typename Stepper::operations_type > , - default_controller , - typename Stepper::resizer_type , - typename Stepper::stepper_category > -{ -public: - - typedef generic_controlled_stepper< - Stepper , - error_checker_explicit_new< typename Stepper::value_type , typename Stepper::algebra_type , typename Stepper::operations_type > , - default_controller , - typename Stepper::resizer_type , - typename Stepper::stepper_category > base_type; - typedef error_checker_explicit_new< typename Stepper::value_type , typename Stepper::algebra_type , typename Stepper::operations_type > error_checker_type; - typedef typename Stepper::value_type value_type; - - controlled_runge_kutta_explicit( const Stepper &stepper = Stepper() , - const value_type eps_abs = static_cast< value_type >( 1.0e-6 ) , - const value_type eps_rel = static_cast< value_type >( 1.0e-6 ) , - const value_type a_x = static_cast< value_type >( 1.0 ) , - const value_type a_dxdt = static_cast< value_type >( 1.0 ) ) - : base_type( stepper , - error_checker_type( base_type::stepper().algebra() , eps_abs , eps_rel , a_x , a_dxdt ) - ) { } -}; - - -} -} -} - - - - -typedef boost::array< double , 3 > state_type; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - const double sigma = 10.0; - const double R = 28.0; - const double 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]; -} - - -int main( int argc , char **argv ) -{ - using namespace std; - using namespace boost::numeric::odeint; - - dense_output_runge_kutta< - generic_controlled_stepper< - runge_kutta_dopri5< state_type > , - error_checker_explicit< double , range_algebra , default_operations > , - default_controller , - initially_resizer , - explicit_error_stepper_fsal_tag > > stepper1; - - dense_output_runge_kutta< controlled_runge_kutta< runge_kutta_dopri5< state_type > > > stepper2; - - dense_output_runge_kutta< controlled_runge_kutta_explicit< runge_kutta_dopri5< state_type > > > stepper3; - - dense_output_runge_kutta< - generic_controlled_stepper< - runge_kutta_dopri5< state_type > , - error_checker_explicit< double , range_algebra , default_operations > , - pi_controller< double > , - initially_resizer , - explicit_error_stepper_fsal_tag > > stepper4; - - typedef generic_controlled_stepper< - runge_kutta_dopri5< state_type > , - error_checker_max_norm< double , range_algebra , default_operations > , - default_controller , - initially_resizer , - explicit_error_stepper_fsal_tag > controller5_type; - typedef dense_output_runge_kutta< controller5_type > stepper5_type; - range_algebra al; - stepper5_type stepper5 = stepper5_type( - controller5_type( runge_kutta_dopri5< state_type >() , - error_checker_max_norm< double , range_algebra , default_operations >( al ) ) ); - - - - state_type x1 = {{ 10.0 , 10.0 , 10.0 }}; - state_type x2 = x1; - state_type x3 = x1; - state_type x4 = x1; - state_type x5 = x1; - - boost::timer timer; - const double t_max = 1000000.0; - - timer.restart(); - size_t steps1 = integrate_const( stepper1 , lorenz , x1 , 0.0 , t_max , 10.0 ); - double t1 = timer.elapsed(); - cout << steps1 << tab << t1 << tab << x1[0] << tab << x1[1] << tab << x1[2] << endl; - - timer.restart(); - size_t steps2 = integrate_const( stepper2 , lorenz , x2 , 0.0 , t_max , 10.0 ); - double t2 = timer.elapsed(); - cout << steps2 << tab << t2 << tab << x2[0] << tab << x2[1] << tab << x2[2] << endl; - - timer.restart(); - size_t steps3 = integrate_const( stepper3 , lorenz , x3 , 0.0 , t_max , 10.0 ); - double t3 = timer.elapsed(); - cout << steps3 << tab << t3 << tab << x3[0] << tab << x3[1] << tab << x3[2] << endl; - - timer.restart(); - size_t steps4 = integrate_const( stepper4 , lorenz , x4 , 0.0 , t_max , 10.0 ); - double t4 = timer.elapsed(); - cout << steps4 << tab << t4 << tab << x4[0] << tab << x4[1] << tab << x4[2] << endl; - - timer.restart(); - size_t steps5 = integrate_const( stepper5 , lorenz , x5 , 0.0 , t_max , 10.0 ); - double t5 = timer.elapsed(); - cout << steps5 << tab << t5 << tab << x5[0] << tab << x5[1] << tab << x5[2] << endl; - - - - - - return 0; -} - diff --git a/libs/numeric/odeint/ideas/controller/dopri5_controller.cpp b/libs/numeric/odeint/ideas/controller/dopri5_controller.cpp deleted file mode 100644 index 50176f2a..00000000 --- a/libs/numeric/odeint/ideas/controller/dopri5_controller.cpp +++ /dev/null @@ -1,142 +0,0 @@ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - - -#define tab "\t" - -namespace boost { -namespace numeric { -namespace odeint { - - - - -/* - * move this class into controller_runge_kutta.hpp - */ -template< class Stepper > -class controlled_runge_kutta_explicit : - public generic_controlled_stepper< - Stepper , - error_checker_explicit_new< typename Stepper::value_type , typename Stepper::algebra_type , typename Stepper::operations_type > , - default_controller , - typename Stepper::resizer_type , - typename Stepper::stepper_category > -{ -public: - - typedef generic_controlled_stepper< - Stepper , - error_checker_explicit_new< typename Stepper::value_type , typename Stepper::algebra_type , typename Stepper::operations_type > , - default_controller , - typename Stepper::resizer_type , - typename Stepper::stepper_category > base_type; - typedef error_checker_explicit_new< typename Stepper::value_type , typename Stepper::algebra_type , typename Stepper::operations_type > error_checker_type; - typedef typename Stepper::value_type value_type; - - controlled_runge_kutta_explicit( const Stepper &stepper = Stepper() , - const value_type eps_abs = static_cast< value_type >( 1.0e-6 ) , - const value_type eps_rel = static_cast< value_type >( 1.0e-6 ) , - const value_type a_x = static_cast< value_type >( 1.0 ) , - const value_type a_dxdt = static_cast< value_type >( 1.0 ) ) - : base_type( stepper , - error_checker_type( base_type::stepper().algebra() , eps_abs , eps_rel , a_x , a_dxdt ) - ) { } -}; - - -} -} -} - - - - -typedef boost::array< double , 3 > state_type; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - const double sigma = 10.0; - const double R = 28.0; - const double 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]; -} - - -int main( int argc , char **argv ) -{ - using namespace std; - using namespace boost::numeric::odeint; - - generic_controlled_stepper< - runge_kutta_dopri5< state_type > , - error_checker_explicit< double , range_algebra , default_operations > , - default_controller , - initially_resizer , - explicit_error_stepper_fsal_tag > stepper1; - - controlled_runge_kutta< runge_kutta_dopri5< state_type > > stepper2; - - controlled_runge_kutta_explicit< runge_kutta_dopri5< state_type > > stepper3; - - generic_controlled_stepper< - runge_kutta_dopri5< state_type > , - error_checker_explicit< double , range_algebra , default_operations > , - pi_controller< double > , - initially_resizer , - explicit_error_stepper_fsal_tag > stepper4; - - - state_type x1 = {{ 10.0 , 10.0 , 10.0 }}; - state_type x2 = x1; - state_type x3 = x1; - state_type x4 = x1; - - boost::timer timer; - const double t_max = 100000.0; - - timer.restart(); - size_t steps1 = integrate_adaptive( stepper1 , lorenz , x1 , 0.0 , t_max , 0.1 ); - double t1 = timer.elapsed(); - cout << steps1 << tab << t1 << tab << x1[0] << tab << x1[1] << tab << x1[2] << endl; - - timer.restart(); - size_t steps2 = integrate_adaptive( stepper2 , lorenz , x2 , 0.0 , t_max , 0.1 ); - double t2 = timer.elapsed(); - cout << steps2 << tab << t2 << tab << x2[0] << tab << x2[1] << tab << x2[2] << endl; - - timer.restart(); - size_t steps3 = integrate_adaptive( stepper3 , lorenz , x3 , 0.0 , t_max , 0.1 ); - double t3 = timer.elapsed(); - cout << steps3 << tab << t3 << tab << x3[0] << tab << x3[1] << tab << x3[2] << endl; - - timer.restart(); - size_t steps4 = integrate_adaptive( stepper4 , lorenz , x4 , 0.0 , t_max , 0.1 ); - double t4 = timer.elapsed(); - cout << steps4 << tab << t4 << tab << x4[0] << tab << x4[1] << tab << x4[2] << endl; - - - - - return 0; -} diff --git a/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/Jamfile b/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/Jamfile deleted file mode 100644 index 93b8ec6e..00000000 --- a/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/Jamfile +++ /dev/null @@ -1,27 +0,0 @@ -# (C) Copyright 2010 : Karsten Ahnert, 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 - /boost/test//boost_unit_test_framework - BOOST_ALL_NO_LIB=1 - ../../../.. - static -# -D_SCL_SECURE_NO_WARNINGS - ; - -test-suite "odeint" - : - [ run ref_or_value_holder.cpp ] - [ run error_checker_max_norm.cpp ] - [ run number_of_elements.cpp ] - [ run error_checker_l2_norm.cpp ] - : valgrind - ; \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/error_checker_l2_norm.cpp b/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/error_checker_l2_norm.cpp deleted file mode 100644 index 6bcf610a..00000000 --- a/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/error_checker_l2_norm.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * is_pair.cpp - * - * Created on: Feb 12, 2011 - * Author: karsten - */ - -#define BOOST_TEST_MODULE odeint_error_checker_max_norm - -#include - -#include -#include - -#include -#include -#include - -#include - -using namespace boost::numeric::odeint; - -#include -using namespace std; - -BOOST_AUTO_TEST_SUITE( error_checker_max_norm_test ) - -BOOST_AUTO_TEST_CASE( test_version1 ) -{ - // computes err = max( x_err / ( eps_abs + eps_rel * max( x , x_old ) ) ); - - range_algebra algebra; - error_checker_l2_norm< double , range_algebra , default_operations > error_checker( algebra , 1.0e-3 , 1.0e-4 ); - - double dt , err; - boost::array< double , 2 > x , x_old , x_err; - - x[0] = 1.0 ; x[1] = 2.0; - x_old[0] = 0.5 ; x_old[1] = 1.5; - x_err[0] = 0.01 ; x_err[1] = 0.02; - - // err1 = 0.01 / ( 0.001 + 0.0001 * max( 1.0 , 0.5 ) ) - // err1 = 0.01 / ( 0.0011 ) - // err1 = 9.090909090 - // err2 = 0.02 / ( 0.001 + 0.0001 * max( 2.0 , 1 ) ) - // err2 = 0.02 / ( 0.0012 ) - // err2 = 16.6666666666666666 - // err = sqrt( err1 * err1 + err2 + err2 ) - - err = error_checker.error( x_old , x , x_err , dt ); - BOOST_CHECK_CLOSE( err , 9.49239703496 , 1.0e-10 ); - - x_err[0] *= -1.0; - err = error_checker.error( x_old , x , x_err , dt ); - BOOST_CHECK_CLOSE( err , 9.49239703496 , 1.0e-10 ); - - x[0] *= -1.0; - err = error_checker.error( x_old , x , x_err , dt ); - BOOST_CHECK_CLOSE( err , 9.49239703496 , 1.0e-10 ); - - x_old[0] *= -1.0; - err = error_checker.error( x_old , x , x_err , dt ); - BOOST_CHECK_CLOSE( err , 9.49239703496 , 1.0e-10 ); -} - -BOOST_AUTO_TEST_CASE( test_version2 ) -{ - range_algebra algebra; - error_checker_l2_norm< double , range_algebra , default_operations > error_checker( algebra , 1.0e-3 , 1.0e-4 , 0.5 , 1.5 ); - - double dt = 0.02 , err; - boost::array< double , 2 > x , x_old , x_err , dxdt_old , dxdt; - - x[0] = 1.0 ; x[1] = 2.0; - x_old[0] = 0.5 ; x_old[1] = 1.5; - x_err[0] = 0.01 ; x_err[1] = 0.02; - dxdt_old[0] = 2.0 ; dxdt_old[1] = 4.0; - dxdt[0] = 1000.0 , dxdt[1] = 255555.0; - - // err1 = 0.01 / ( 0.001 + 0.0001 * ( 0.5 * 0.5 + 0.02 * 1.5 * 2.0 ) ) - // err1 = 0.01 / ( 0.001 + 0.0001 * ( 0.25 + 0.06 ) ) - // err1 = 0.01 / ( 0.001031 - // err1 = 9.699321048 - // err2 = 0.02 / ( 0.001 + 0.0001 * ( 0.5 * 1.5 + 0.02 * 1.5 * 4.0 ) ) - // err2 = 0.02 / ( 0.001 + 0.0001 * ( 0.75 + 0.12 ) ) - // err2 = 0.02 / ( 0.001087 ) - // err2 = 18.399264029 - - err = error_checker.error( x_old , x , dxdt_old , x_err , dt ); - BOOST_CHECK_CLOSE( err , 10.3996363591 , 1.0e-8 ); - - err = error_checker.error( x_old , x , dxdt_old , dxdt , x_err , dt ); - BOOST_CHECK_CLOSE( err , 10.3996363591 , 1.0e-8 ); - - x_err[0] *= -1.0; - err = error_checker.error( x_old , x , dxdt_old , x_err , dt ); - BOOST_CHECK_CLOSE( err , 10.3996363591 , 1.0e-8 ); - - x_old[0] *= -1.0; - err = error_checker.error( x_old , x , dxdt_old , x_err , dt ); - BOOST_CHECK_CLOSE( err , 10.3996363591 , 1.0e-8 ); - - dxdt_old[0] *= 1.0; - err = error_checker.error( x_old , x , dxdt_old , x_err , dt ); - BOOST_CHECK_CLOSE( err , 10.3996363591 , 1.0e-8 ); -} - - - -BOOST_AUTO_TEST_SUITE_END() diff --git a/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/error_checker_max_norm.cpp b/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/error_checker_max_norm.cpp deleted file mode 100644 index 08b3b4fb..00000000 --- a/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/error_checker_max_norm.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * is_pair.cpp - * - * Created on: Feb 12, 2011 - * Author: karsten - */ - -#define BOOST_TEST_MODULE odeint_error_checker_max_norm - -#include - -#include -#include - -#include -#include -#include - -#include - -using namespace boost::numeric::odeint; - - - -BOOST_AUTO_TEST_SUITE( error_checker_max_norm_test ) - -BOOST_AUTO_TEST_CASE( test_version1 ) -{ - // computes err = max( x_err / ( eps_abs + eps_rel * max( x , x_old ) ) ); - - range_algebra algebra; - error_checker_max_norm< double , range_algebra , default_operations > error_checker( algebra , 1.0e-3 , 1.0e-4 ); - - double dt , err; - boost::array< double , 2 > x , x_old , x_err; - - x[0] = 1.0 ; x[1] = 2.0; - x_old[0] = 0.5 ; x_old[1] = 1.5; - x_err[0] = 0.01 ; x_err[1] = 0.02; - - // err1 = 0.01 / ( 0.001 + 0.0001 * max( 1.0 , 0.5 ) ) - // err1 = 0.01 / ( 0.0011 ) - // err1 = 9.090909090 - // err2 = 0.02 / ( 0.001 + 0.0001 * max( 2.0 , 1.5 ) ) - // err2 = 0.02 / ( 0.0012 ) - // err2 = 16.6666666666666666 - // err = max( err1 , err2 ) - - - err = error_checker.error( x_old , x , x_err , dt ); - BOOST_CHECK_CLOSE( err , 16.66666666666 , 1.0e-10 ); - - x_err[1] = 0.00002; - err = error_checker.error( x_old , x , x_err , dt ); - BOOST_CHECK_CLOSE( err , 9.0909090909091 , 1.0e-10 ); - - x_err[0] *= -1.0; - err = error_checker.error( x_old , x , x_err , dt ); - BOOST_CHECK_CLOSE( err , 9.0909090909091 , 1.0e-10 ); - - x[0] *= -1.0; - err = error_checker.error( x_old , x , x_err , dt ); - BOOST_CHECK_CLOSE( err , 9.0909090909091 , 1.0e-10 ); - - x_old[0] *= -1.0; - err = error_checker.error( x_old , x , x_err , dt ); - BOOST_CHECK_CLOSE( err , 9.0909090909091 , 1.0e-10 ); -} - -BOOST_AUTO_TEST_CASE( test_version2 ) -{ - range_algebra algebra; - error_checker_max_norm< double , range_algebra , default_operations > error_checker( algebra , 1.0e-3 , 1.0e-4 , 0.5 , 1.5 ); - - double dt = 0.02 , err; - boost::array< double , 2 > x , x_old , x_err , dxdt_old , dxdt; - - x[0] = 1.0 ; x[1] = 2.0; - x_old[0] = 0.5 ; x_old[1] = 1.5; - x_err[0] = 0.01 ; x_err[1] = 0.02; - dxdt_old[0] = 2.0 ; dxdt_old[1] = 4.0; - dxdt[0] = 1000.0 , dxdt[1] = 255555.0; - - // err1 = 0.01 / ( 0.001 + 0.0001 * ( 0.5 * 0.5 + 0.02 * 1.5 * 2.0 ) ) - // err1 = 0.01 / ( 0.001 + 0.0001 * ( 0.25 + 0.06 ) ) - // err1 = 0.01 / ( 0.001031 - // err1 = 9.699321048 - // err2 = 0.02 / ( 0.001 + 0.0001 * ( 0.5 * 1.5 + 0.02 * 1.5 * 4.0 ) ) - // err2 = 0.02 / ( 0.001 + 0.0001 * ( 0.75 + 0.12 ) ) - // err2 = 0.02 / ( 0.001087 ) - // err2 = 18.399264029 - - err = error_checker.error( x_old , x , dxdt_old , x_err , dt ); - BOOST_CHECK_CLOSE( err , 18.399264029 , 1.0e-8 ); - - err = error_checker.error( x_old , x , dxdt_old , dxdt , x_err , dt ); -// BOOST_CHECK_CLOSE( err , 18.399264029 , 1.0e-8 ); - - x_err[1] = 0.00002; - err = error_checker.error( x_old , x , dxdt_old , x_err , dt ); - BOOST_CHECK_CLOSE( err , 9.699321048 , 1.0e-8 ); - - x_err[0] *= -1.0; - err = error_checker.error( x_old , x , dxdt_old , x_err , dt ); - BOOST_CHECK_CLOSE( err , 9.699321048 , 1.0e-8 ); - - x_old[0] *= -1.0; - err = error_checker.error( x_old , x , dxdt_old , x_err , dt ); - BOOST_CHECK_CLOSE( err , 9.699321048 , 1.0e-8 ); - - dxdt_old[0] *= 1.0; - err = error_checker.error( x_old , x , dxdt_old , x_err , dt ); - BOOST_CHECK_CLOSE( err , 9.699321048 , 1.0e-8 ); -} - - - -BOOST_AUTO_TEST_SUITE_END() diff --git a/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/number_of_elements.cpp b/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/number_of_elements.cpp deleted file mode 100644 index b05cc250..00000000 --- a/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/number_of_elements.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * number_of_elements.cpp - * - * Created on: Feb 12, 2011 - * Author: karsten - */ - -#define BOOST_TEST_MODULE odeint_number_of_elements - -#include -#include -#include -#include - -#include - -#include - - - -using namespace boost::numeric::odeint; - - - -BOOST_AUTO_TEST_SUITE( number_of_elements_test ) - -BOOST_AUTO_TEST_CASE( test_number_of_elements_vector ) -{ - typedef std::vector< double > state_type; - state_type v( 10 ); - BOOST_CHECK_EQUAL( size_t( 10 ) , number_of_elements( v ) ); -} - -BOOST_AUTO_TEST_CASE( test_number_of_elements_boost_array ) -{ - typedef boost::array< double , 5 > state_type; - state_type v; - BOOST_CHECK_EQUAL( size_t( 5 ) , number_of_elements( v ) ); - -} - -BOOST_AUTO_TEST_CASE( test_number_of_elements_list ) -{ - typedef std::list< double > state_type; - state_type v( 10 ); - BOOST_CHECK_EQUAL( size_t( 10 ) , number_of_elements( v ) ); -} - -BOOST_AUTO_TEST_CASE( test_number_of_elements_ublas_vector ) -{ - typedef boost::numeric::ublas::vector< double > state_type; - state_type v( 10 ); - BOOST_CHECK_EQUAL( size_t( 10 ) , number_of_elements( v ) ); - -} - -BOOST_AUTO_TEST_SUITE_END() diff --git a/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/ref_or_value_holder.cpp b/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/ref_or_value_holder.cpp deleted file mode 100644 index 56e36b79..00000000 --- a/libs/numeric/odeint/ideas/controller/libs/numeric/odeint/test/ref_or_value_holder.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * is_pair.cpp - * - * Created on: Feb 12, 2011 - * Author: karsten - */ - -#define BOOST_TEST_MODULE odeint_ref_or_value - -#include - -#include -#include - -#include - - - -using namespace boost::numeric::odeint; - - - -BOOST_AUTO_TEST_SUITE( ref_or_value_holder_test ) - -BOOST_AUTO_TEST_CASE( test_value_holder ) -{ - int a = 1; - ref_or_value_holder< int , false > value( a ); - value.get() = 2; - - BOOST_CHECK_EQUAL( 1 , a ); - BOOST_CHECK_EQUAL( 2 , value.get() ); -} - -BOOST_AUTO_TEST_CASE( test_ref_holder ) -{ - int a = 1; - ref_or_value_holder< int , true > value( a ); - value.get() = 2; - - BOOST_CHECK_EQUAL( 2 , a ); - BOOST_CHECK_EQUAL( 2 , value.get() ); -} - - - -BOOST_AUTO_TEST_CASE( test_const_value_holder ) -{ - int a = 1; - ref_or_value_holder< const int , false > value( a ); - - BOOST_CHECK_EQUAL( 1 , a ); - BOOST_CHECK_EQUAL( 1 , value.get() ); -} - -BOOST_AUTO_TEST_CASE( test_const_ref_holder ) -{ - int a = 1; - ref_or_value_holder< const int , true > value( a ); - - BOOST_CHECK_EQUAL( 1 , a ); - BOOST_CHECK_EQUAL( 1 , value.get() ); -} - -BOOST_AUTO_TEST_SUITE_END() diff --git a/libs/numeric/odeint/ideas/controller/rb_controller.cpp b/libs/numeric/odeint/ideas/controller/rb_controller.cpp deleted file mode 100644 index e29ae51a..00000000 --- a/libs/numeric/odeint/ideas/controller/rb_controller.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* - * TODO: - * - * * implement rosenbrock_error_checker - * * implement rosenbrock_controller - * * implement generic_controlled_stepper - */ - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - - -#define tab "\t" - -namespace boost { -namespace numeric { -namespace odeint { - - -template< class Value , class Algebra , class Operations > -class error_checker -{ -public: - - typedef Value value_type; - typedef Algebra algebra_type; - typedef Operations operations_type; - - - error_checker( - const value_type eps_abs = static_cast< value_type >( 1.0e-6 ) , - const value_type eps_rel = static_cast< value_type >( 1.0e-6 ) - ) - : m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) - { } - - template< class State1 , class State2 , class Err , class Time > - value_type error( const State1 &x_old , const State2 &x , Err &x_err , const Time &dt ) - { - // this overwrites x_err ! - algebra.for_each3( x_err , x_old , x , - typename operations_type::template default_rel_error< value_type >( m_eps_abs , m_eps_rel ) ); - - value_type res = algebra.reduce( x_err , - typename operations_type::template maximum< value_type >() , static_cast< value_type >( 0.0 ) ); - return res; - } - -private: - - value_type m_eps_abs; - value_type m_eps_rel; - algebra_type algebra; -}; - - - -template< class Value > -class rosenbrock_error_checker -{ -public: - - typedef Value value_type; - - - rosenbrock_error_checker( - const value_type eps_abs = static_cast< value_type >( 1.0e-6 ) , - const value_type eps_rel = static_cast< value_type >( 1.0e-6 ) - ) - : m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) - { } - - template< class State1 , class State2 , class Err , class Time > - value_type error( const State1 &x_old , const State2 &x , Err &x_err , const Time &dt ) - { - value_type res = 0.0 , sk = 0.0; - for( size_t i=0 ; i -class rosenbrock4_controller_tmp : public generic_controlled_stepper< - rosenbrock4< double > , - rosenbrock_error_checker< double > , - stiff_controller< double > , - initially_resizer , - error_stepper_tag > -{ -}; - - - - - - - -} -} -} - - - -typedef boost::numeric::odeint::rosenbrock4< double > stepper_type; -typedef stepper_type::state_type state_type; -typedef stepper_type::matrix_type matrix_type; - -const double mu = 1000.0; - - -struct vdp_stiff -{ - template< class State , class Deriv > - void operator()( const State &x , Deriv &dxdt , double t ) - { - dxdt[0] = x[1]; - dxdt[1] = -x[0] - mu * x[1] * (x[0]*x[0]-1.0); - } -}; - -struct vdp_stiff_jacobi -{ - void operator()( const state_type &x , matrix_type &J , const double &t , state_type &dfdt ) - { - J(0, 0) = 0.0; - J(0, 1) = 1.0; - J(1, 0) = -1.0 - 2.0*mu * x[0] * x[1]; - J(1, 1) = -mu * ( x[0] * x[0] - 1.0); - - dfdt[0] = 0.0; - dfdt[1] = 0.0; - } -}; - -struct streaming_observer -{ - std::ostream& m_out; - - streaming_observer( std::ostream &out ) : m_out( out ) { } - - template< class State > - void operator()( const State &x , double t ) const - { - m_out << t; - for( size_t i=0 ; i stepper2_type; - - state_type x1( 2 ); - x1[ 0 ] = 1.0 ; x1[ 1 ] = 1.0; - state_type x2 = x1; - state_type x3 = x1; - state_type x4 = x1; - - boost::timer timer; - const double t_max = 100000.0; - - ofstream fout1( "vdp_rb_1.dat" ); - timer.restart(); - size_t steps1 = integrate_adaptive( make_controlled( 1.0e-6 , 1.0e-6 , stepper1 ) , - make_pair( vdp_stiff() , vdp_stiff_jacobi() ) , x1 , 0.0 , t_max , 0.1 , streaming_observer( fout1 ) ); - double t1 = timer.elapsed(); - cout << steps1 << tab << t1 << tab << x1[0] << tab << x1[1] << endl; - - - ofstream fout2( "vdp_rb_2.dat" ); - timer.restart(); - size_t steps2 = integrate_adaptive( stepper2_type() , - make_pair( vdp_stiff() , vdp_stiff_jacobi() ) , x2 , 0.0 , t_max , 0.1 , streaming_observer( fout2 ) ); - double t2 = timer.elapsed(); - cout << steps2 << tab << t2 << tab << x2[0] << tab << x2[1] << endl; - - - - - - - return 0; -} diff --git a/libs/numeric/odeint/ideas/controller/rb_dense_output.cpp b/libs/numeric/odeint/ideas/controller/rb_dense_output.cpp deleted file mode 100644 index 43e864c4..00000000 --- a/libs/numeric/odeint/ideas/controller/rb_dense_output.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include - -#include - -#include -#include -#include -#include - -#define tab "\t" - -typedef boost::numeric::odeint::rosenbrock4< double > stepper_type; -typedef stepper_type::state_type state_type; -typedef stepper_type::matrix_type matrix_type; - -const double mu = 1000.0; - - -struct vdp_stiff -{ - template< class State , class Deriv > - void operator()( const State &x , Deriv &dxdt , double t ) - { - dxdt[0] = x[1]; - dxdt[1] = -x[0] - mu * x[1] * (x[0]*x[0]-1.0); - } -}; - -struct vdp_stiff_jacobi -{ - void operator()( const state_type &x , matrix_type &J , const double &t , state_type &dfdt ) - { - J(0, 0) = 0.0; - J(0, 1) = 1.0; - J(1, 0) = -1.0 - 2.0*mu * x[0] * x[1]; - J(1, 1) = -mu * ( x[0] * x[0] - 1.0); - - dfdt[0] = 0.0; - dfdt[1] = 0.0; - } -}; - - -int main( int argc , char **argv ) -{ - using namespace std; - using namespace boost::numeric::odeint; - - stepper_type stepper1; - - state_type x1( 2 ); - x1[ 0 ] = 1.0 ; x1[ 1 ] = 1.0; - state_type x2 = x1; - state_type x3 = x1; - state_type x4 = x1; - - boost::timer timer; - const double t_max = 10000000.0; - - timer.restart(); - size_t steps1 = integrate_adaptive( make_dense_output( 1.0e-6 , 1.0e-6 , stepper1 ) , - make_pair( vdp_stiff() , vdp_stiff_jacobi() ) , x1 , 0.0 , t_max , 0.1 ); - double t1 = timer.elapsed(); - cout << steps1 << tab << t1 << tab << x1[0] << tab << x1[1] << endl; - - generic_dense_output_stepper< rosenbrock4_controller< rosenbrock4< double > > > stepper2; - timer.restart(); - size_t steps2 = integrate_adaptive( stepper2 , make_pair( vdp_stiff() , vdp_stiff_jacobi() ) , x2 , 0.0 , t_max , 0.1 ); - double t2 = timer.elapsed(); - cout << steps2 << tab << t2 << tab << x2[0] << tab << x2[1] << endl; - - - - return 0; -} - diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/Jamfile b/libs/numeric/odeint/ideas/fusion_runge_kutta/Jamfile deleted file mode 100644 index 44548491..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/Jamfile +++ /dev/null @@ -1,17 +0,0 @@ -# (C) Copyright 2010 : Karsten Ahnert, 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) - -import os ; -import modules ; -import path ; - -project - : requirements - BOOST_ALL_NO_LIB=1 - ../../../../.. - ; - -exe test_explicit_rk - : test_explicit_rk.cpp - ; \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_algebra.hpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_algebra.hpp deleted file mode 100644 index 938c3af6..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_algebra.hpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - * fusion_algebra.hpp - * - * Created on: Apr 26, 2011 - * Author: mario - */ - -#ifndef FUSION_ALGEBRA_HPP_ -#define FUSION_ALGEBRA_HPP_ - -#include - -#include - - -template< size_t n > -struct fusion_algebra -{ - template< typename T , size_t dim > - inline static void foreach( boost::array< T , dim > &x_tmp , const boost::array< T , dim > &x , - const boost::array< double , n > &a , - const boost::array< T , dim > k_vector[n] , const double dt ) - { - for( size_t i=0 ; i - inline static void foreach( boost::array< T , dim > &x_tmp , - const boost::array< double , n > &a , - const boost::array< T , dim > k_vector[n] , const double dt ) - { - for( size_t i=0 ; i -struct fusion_algebra< 1 > -{ - template< typename T , size_t dim > - inline static void foreach( boost::array< T , dim > &x_tmp , const boost::array< T , dim > &x , - const boost::array< double , 1 > &a , - const boost::array< T , dim > *k_vector , const double dt ) - { - for( size_t i=0 ; i -struct fusion_algebra< 2 > -{ - - template< typename T , size_t dim > - inline static void foreach( boost::array< T , dim > &x_tmp , const boost::array< T , dim > &x , - const boost::array< double , 2 > &a , - const boost::array< T , dim > *k_vector , const double dt ) - { - for( size_t i=0 ; i -struct fusion_algebra< 3 > -{ - - template< typename T , size_t dim > - inline static void foreach( boost::array< T , dim > &x_tmp , const boost::array< T , dim > &x , - const boost::array< double , 3 > &a , - const boost::array< T , dim > *k_vector , const double dt ) - { - for( size_t i=0 ; i -struct fusion_algebra< 4 > -{ - - template< typename T , size_t dim > - inline static void foreach( boost::array< T , dim > &x_tmp , const boost::array< T , dim > &x , - const boost::array< double , 4 > &a , - const boost::array< T , dim > *k_vector , const double dt ) - { - for( size_t i=0 ; i -struct fusion_algebra< 5 > -{ - - template< typename T , size_t dim > - inline static void foreach( boost::array< T , dim > &x_tmp , const boost::array< T , dim > &x , - const boost::array< double , 5 > &a , - const boost::array< T , dim > *k_vector , const double dt ) - { - for( size_t i=0 ; i -struct fusion_algebra< 6 > -{ - - template< typename T , size_t dim > - inline static void foreach( boost::array< T , dim > &x_tmp , const boost::array< T , dim > &x , - const boost::array< double , 6 > &a , - const boost::array< T , dim > *k_vector , const double dt ) - { - for( size_t i=0 ; i - inline static void foreach(boost::array &x_tmp , - const boost::array &a , - const boost::array *k_vector , const double dt) - { - for (size_t i = 0 ; i < dim ; ++i) - { - x_tmp[i] = a[0] * dt * k_vector[0][i] + a[1] * dt * k_vector[1][i] - + a[2] * dt * k_vector[2][i] + a[3] * dt * k_vector[3][i] - + a[4] * dt * k_vector[4][i] + a[5] * dt * k_vector[5][i]; - } - } - -}; - -//#endif /* BOOST_MSVC */ - -#endif /* FUSION_ALGEBRA_HPP_ */ diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_explicit_error_rk.hpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_explicit_error_rk.hpp deleted file mode 100644 index b466bb09..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_explicit_error_rk.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * fusion_explicit_error_rk.hpp - * - * Created on: Apr 29, 2011 - * Author: mario - */ - -#ifndef FUSION_EXPLICIT_ERROR_RK_HPP_ -#define FUSION_EXPLICIT_ERROR_RK_HPP_ - -#include "fusion_explicit_rk_new.hpp" -#include "fusion_algebra.hpp" - -namespace mpl = boost::mpl; -namespace fusion = boost::fusion; - -using namespace std; - -template< class StateType , size_t stage_count > -class explicit_error_rk : public explicit_rk< StateType , stage_count > -{ - -public: - - typedef explicit_rk< StateType , stage_count > base; - - typedef StateType state_type; - - typedef typename base::stage_indices stage_indices; - - typedef typename base::coef_a_type coef_a_type; - - typedef typename base::coef_b_type coef_b_type; - typedef typename base::coef_c_type coef_c_type; - - public: - - explicit_error_rk( const coef_a_type &a , - const coef_b_type &b , - const coef_b_type &b2 , - const coef_c_type &c ) - : base( a , b , c ) , m_b2( b2 ) - { } - - template< class System > - void inline do_step( System system , state_type &x , const double t , const double dt , state_type &x_err ) - { - base::do_step( system , x , t , dt ); - // compute error estimate - fusion_algebra< stage_count >::foreach( x_err , m_b2 , base::m_F , dt ); - } - -private: - - const coef_b_type m_b2; -}; - -#endif /* FUSION_EXPLICIT_ERROR_RK_HPP_ */ diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_explicit_rk.hpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_explicit_rk.hpp deleted file mode 100644 index 01bb4518..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_explicit_rk.hpp +++ /dev/null @@ -1,211 +0,0 @@ -/* - * fusion_runge_kutta.hpp - * - * Created on: Apr 26, 2011 - * Author: mario - */ - -#ifndef FUSION_EXPLICIT_RK_HPP_ -#define FUSION_EXPLICIT_RK_HPP_ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - - -#include -#include -#include - -#include -#include - -#include "fusion_algebra.hpp" - -namespace mpl = boost::mpl; -namespace fusion = boost::fusion; - -using namespace std; - -struct intermediate_stage {}; -struct last_stage {}; - - - -template< class T , class Constant > -struct array_wrapper -{ - typedef typename boost::array< T , Constant::value > type; -}; - -template< class T , class Constant , class StageCategory > -struct stage_fusion_wrapper -{ - typedef typename fusion::vector< size_t , T , boost::array< T , Constant::value > , StageCategory > type; -}; - - -template< class StateType , size_t stage_count > -class explicit_rk -{ - -public: - - typedef StateType state_type; - - typedef mpl::range_c< size_t , 1 , stage_count > stage_indices; - - typedef typename fusion::result_of::as_vector - < - typename mpl::copy - < - stage_indices , - mpl::inserter - < - mpl::vector0< > , - mpl::push_back< mpl::_1 , array_wrapper< double , mpl::_2 > > - > - >::type - >::type coef_a_type; - - typedef boost::array< double , stage_count > coef_b_type; - typedef boost::array< double , stage_count > coef_c_type; - - typedef typename fusion::result_of::as_vector - < - typename mpl::push_back - < - typename mpl::copy - < - stage_indices, - mpl::inserter - < - mpl::vector0<> , - mpl::push_back< mpl::_1 , stage_fusion_wrapper< double , mpl::_2 , intermediate_stage > > - > - >::type , - typename stage_fusion_wrapper< double , mpl::size_t< stage_count > , last_stage >::type - >::type - >::type stage_vector_base; - - - struct stage_vector : public stage_vector_base - { - struct do_insertion - { - stage_vector_base &m_base; - const coef_a_type &m_a; - const coef_c_type &m_c; - - do_insertion( stage_vector_base &base , const coef_a_type &a , const coef_c_type &c ) - : m_base( base ) , m_a( a ) , m_c( c ) { } - - template< class Index > - void operator()( Index ) const - { - fusion::at_c< 0 >( fusion::at< Index >( m_base ) ) = Index::value; - fusion::at_c< 1 >( fusion::at< Index >( m_base ) ) = m_c[ Index::value ]; - fusion::at_c< 2 >( fusion::at< Index >( m_base ) ) = fusion::at< Index >( m_a ); - } - }; - - stage_vector( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c ) - { - typedef mpl::range_c< size_t , 0 , stage_count - 1 > indices; - mpl::for_each< indices >( do_insertion( *this , a , c ) ); - fusion::at_c< 0 >( fusion::at_c< stage_count - 1 >( *this ) ) = stage_count - 1 ; - fusion::at_c< 1 >( fusion::at_c< stage_count - 1 >( *this ) ) = c[ stage_count - 1 ]; - fusion::at_c< 2 >( fusion::at_c< stage_count - 1 >( *this ) ) = b; - } - }; - - - - template< class System > - struct calculate_stage - { - System &system; - state_type &x , &x_tmp; - state_type *k_vector; - const double t; - const double dt; - - calculate_stage( System &_system , state_type &_x , state_type &_x_tmp , state_type *_k_vector , - const double _t , const double _dt ) - : system( _system ) , x( _x ) , x_tmp( _x_tmp ) , k_vector( _k_vector ) , t( _t ) , dt( _dt ) - {} - - - template< typename T , size_t stage_number > - void operator()( fusion::vector< size_t , T , boost::array< T , stage_number > , intermediate_stage > const &stage ) const - //typename stage_fusion_wrapper< T , mpl::size_t< stage_number > , intermediate_stage >::type const &stage ) const - { - double c = fusion::at_c< 1 >( stage ); - - if( stage_number == 1 ) - system( x , k_vector[stage_number-1] , t + c * dt ); - else - system( x_tmp , k_vector[stage_number-1] , t + c * dt ); - - fusion_algebra::foreach( x_tmp , x , fusion::at_c< 2 >( stage ) , k_vector , dt); - } - - - template< typename T , size_t stage_number > - void operator()( fusion::vector< size_t , T , boost::array< T , stage_number > , last_stage > const &stage ) const - //void operator()( typename stage_fusion_wrapper< T , mpl::size_t< stage_number > , last_stage >::type const &stage ) const - { - double c = fusion::at_c< 1 >( stage ); - - if( stage_number == 1 ) - system( x , k_vector[stage_number-1] , t + c * dt ); - else - system( x_tmp , k_vector[stage_number-1] , t + c * dt ); - - fusion_algebra::foreach( x , x , fusion::at_c< 2 >( stage ) , k_vector , dt); - } - - - }; - - - - -public: - - explicit_rk( const coef_a_type &a , - const coef_b_type &b , - const coef_c_type &c ) - : m_a( a ) , m_b( b ) , m_c( c ) , - m_stages( a , b , c ) - - { } - - - template< class System > - void do_step( System &system , state_type &x , double t , const double dt ) - { - fusion::for_each( m_stages , calculate_stage< System >( system , x , m_x_tmp , m_k_vector , t , dt ) ); - } - - -private: - - const coef_a_type m_a; - const coef_b_type m_b; - const coef_c_type m_c; - const stage_vector m_stages; - state_type m_x_tmp; - state_type m_k_vector[stage_count]; -}; - - -#endif /* FUSION_EXPLICIT_RK_HPP_ */ diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_explicit_rk_new.hpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_explicit_rk_new.hpp deleted file mode 100644 index 553acd79..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_explicit_rk_new.hpp +++ /dev/null @@ -1,212 +0,0 @@ -/* - * fusion_runge_kutta.hpp - * - * Created on: Apr 26, 2011 - * Author: mario - */ - -#ifndef FUSION_EXPLICIT_RK_HPP_ -#define FUSION_EXPLICIT_RK_HPP_ - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include "fusion_algebra.hpp" -//#include "fusion_foreach_performance.hpp" - -namespace mpl = boost::mpl; -namespace fusion = boost::fusion; - -using namespace std; - -struct intermediate_stage {}; -struct last_stage {}; - - - -template< class T , class Constant > -struct array_wrapper -{ - typedef const typename boost::array< T , Constant::value > type; -}; - -template< class T , size_t i , class StageCategory > -struct stage -{ - T c; - boost::array< T , i > a; - typedef StageCategory category; -}; - -template< class T , size_t i> -struct stage< T , i , last_stage > -{ - T c; - boost::array< T , i > b; - typedef last_stage category; -}; - - - -template< class T , class Constant , class StageCategory > -struct stage_wrapper -{ - typedef stage< T , Constant::value , StageCategory > type; -}; - - -template< class StateType , size_t stage_count > -class explicit_rk -{ - -public: - - typedef StateType state_type; - - typedef mpl::range_c< size_t , 1 , stage_count > stage_indices; - - typedef typename fusion::result_of::as_vector - < - typename mpl::copy - < - stage_indices , - mpl::inserter - < - mpl::vector0< > , - mpl::push_back< mpl::_1 , array_wrapper< double , mpl::_2 > > - > - >::type - >::type coef_a_type; - - typedef boost::array< double , stage_count > coef_b_type; - typedef boost::array< double , stage_count > coef_c_type; - - typedef typename fusion::result_of::as_vector - < - typename mpl::push_back - < - typename mpl::copy - < - stage_indices, - mpl::inserter - < - mpl::vector0<> , - mpl::push_back< mpl::_1 , stage_wrapper< double , mpl::_2 , intermediate_stage > > - > - >::type , - stage< double , stage_count , last_stage > - >::type - >::type stage_vector_base; - - - struct stage_vector : public stage_vector_base - { - struct do_insertion - { - stage_vector_base &m_base; - const coef_a_type &m_a; - const coef_c_type &m_c; - - do_insertion( stage_vector_base &base , const coef_a_type &a , const coef_c_type &c ) - : m_base( base ) , m_a( a ) , m_c( c ) { } - - template< class Index > - void operator()( Index ) const - { - //fusion::at< Index >( m_base ) = stage< double , Index::value+1 , intermediate_stage >( m_c[ Index::value ] , fusion::at< Index >( m_a ) ); - fusion::at< Index >( m_base ).c = m_c[ Index::value ]; - fusion::at< Index >( m_base ).a = fusion::at< Index >( m_a ); - } - }; - - stage_vector( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c ) - { - typedef mpl::range_c< size_t , 0 , stage_count - 1 > indices; - mpl::for_each< indices >( do_insertion( *this , a , c ) ); - //fusion::at_c< 0 >( fusion::at_c< stage_count - 1 >( *this ) ) = stage_count - 1 ; - fusion::at_c< stage_count - 1 >( *this ).c = c[ stage_count - 1 ]; - fusion::at_c< stage_count - 1 >( *this ).b = b; - } - }; - - - - template< class System > - struct calculate_stage - { - System &system; - state_type &x , &x_tmp; - state_type *F; - const double t; - const double dt; - - calculate_stage( System &_system , state_type &_x , state_type &_x_tmp , state_type *_F , - const double _t , const double _dt ) - : system( _system ) , x( _x ) , x_tmp( _x_tmp ) , F( _F ) , t( _t ) , dt( _dt ) - {} - - - template< typename T , size_t stage_number > - void inline operator()( stage< T , stage_number , intermediate_stage > const &stage ) const - //typename stage_fusion_wrapper< T , mpl::size_t< stage_number > , intermediate_stage >::type const &stage ) const - { - if( stage_number == 1 ) - system( x , F[stage_number-1] , t + stage.c * dt ); - else - system( x_tmp , F[stage_number-1] , t + stage.c * dt ); - - fusion_algebra::foreach( x_tmp , x , stage.a , F , dt); - } - - - template< typename T , size_t stage_number > - void inline operator()( stage< T , stage_number , last_stage > const &stage ) const - //void operator()( typename stage_fusion_wrapper< T , mpl::size_t< stage_number > , last_stage >::type const &stage ) const - { - if( stage_number == 1 ) - system( x , F[stage_number-1] , t + stage.c * dt ); - else - system( x_tmp , F[stage_number-1] , t + stage.c * dt ); - - fusion_algebra::foreach( x , x , stage.b , F , dt); - } - - - }; - -public: - - explicit_rk( const coef_a_type &a , - const coef_b_type &b , - const coef_c_type &c ) - : m_stages( a , b , c ) - - { } - - - template< class System > - void inline do_step( System system , state_type &x , const double t , const double dt ) - { - fusion::for_each( m_stages , calculate_stage< System >( system , x , m_x_tmp , m_F , t , dt ) ); - } - -private: - - stage_vector m_stages; - state_type m_x_tmp; - -protected: - state_type m_F[stage_count]; - -}; - -#endif /* FUSION_EXPLICIT_RK_HPP_ */ diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_foreach_performance.hpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_foreach_performance.hpp deleted file mode 100644 index 2a3d0ee6..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_foreach_performance.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace boost { namespace fusion { -namespace detail -{ - template<> - struct for_each_unrolled<6> - { - template - static void inline call(I0 const& i0, F const& f) - { - f(*i0); - typedef typename result_of::next::type I1; - I1 i1(fusion::next(i0)); - f(*i1); - typedef typename result_of::next::type I2; - I2 i2(fusion::next(i1)); - f(*i2); - typedef typename result_of::next::type I3; - I3 i3(fusion::next(i2)); - f(*i3); - typedef typename result_of::next::type I4; - I4 i4(fusion::next(i3)); - f(*i4); - typedef typename result_of::next::type I5; - I5 i5(fusion::next(i4)); - f(*i5); - } - }; -} -} } diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/Jamfile b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/Jamfile deleted file mode 100644 index b77ef4ad..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/Jamfile +++ /dev/null @@ -1,131 +0,0 @@ -# (C) Copyright 2010 : Karsten Ahnert, 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) - -import os ; -import modules ; -import path ; - -project - : requirements - BOOST_ALL_NO_LIB=1 - ../../../../../.. - : default-build release - ; - - -lib libgsl : : gsl ; -lib libgslcblas : : gslcblas ; - -#exe generic_rk4 -# : generic_rk4.cpp -# : intel:-inline-forceinline -# ; - -exe generic_rk4_lorenz - : generic_rk4_lorenz.cpp - : intel:-inline-forceinline - ; - -exe generic_odeint_rk4_lorenz - : generic_odeint_rk4_lorenz.cpp - : intel:-inline-forceinline - ; - -#exe odeint_rk4 -# : odeint_rk4.cpp -# : -Winline -# ; - -exe odeint_rk4_lorenz - : odeint_rk4_lorenz.cpp - ; - -exe odeint_rk4_lorenz_def_alg - : odeint_rk4_lorenz_def_alg.cpp - ; - -#exe nr_rk4 -# : nr_rk4.cpp -# ; - -exe nr_rk4_lorenz - : nr_rk4_lorenz.cpp - ; - - -#exe rt_generic_rk4 -# : rt_generic_rk4.cpp -# ; - -exe rt_generic_rk4_lorenz - : rt_generic_rk4_lorenz.cpp - ; - - -#exe gsl_rk4 -# : gsl_rk4.cpp libgsl libgslcblas -# ; - -exe gsl_rk4_lorenz - : gsl_rk4_lorenz.cpp libgsl libgslcblas - ; - -exe generic_rk54ck - : generic_rk54ck.cpp - : intel:-inline-forceinline - ; - -exe generic_rk54ck_lorenz - : generic_rk54ck_lorenz.cpp - : intel:-inline-forceinline - ; - -exe odeint_rk54ck - : odeint_rk54ck.cpp - ; - -exe odeint_rk54ck_lorenz - : odeint_rk54ck_lorenz.cpp - ; - -exe odeint_rk54ck_def_alg - : odeint_rk54ck_def_alg.cpp - ; - -exe odeint_rk54ck_lorenz_def_alg - : odeint_rk54ck_lorenz_def_alg.cpp - ; - -exe nr_rk54ck - : nr_rk54ck.cpp - ; - -exe nr_rk54ck_lorenz - : nr_rk54ck_lorenz.cpp - ; - -exe gsl_rk54ck - : gsl_rk54ck.cpp libgsl libgslcblas - ; - -exe gsl_rk54ck_lorenz - : gsl_rk54ck_lorenz.cpp libgsl libgslcblas - ; - -exe generic_rk4_phase_lattice - : generic_rk4_phase_lattice.cpp - : intel:-inline-forceinline - ; - -exe odeint_rk4_phase_lattice - : odeint_rk4_phase_lattice.cpp - ; - -exe nr_rk4_phase_lattice - : nr_rk4_phase_lattice.cpp - ; - -exe rt_generic_rk4_phase_lattice - : rt_generic_rk4_phase_lattice.cpp - ; \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_odeint_rk4_lorenz.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_odeint_rk4_lorenz.cpp deleted file mode 100644 index c61f6366..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_odeint_rk4_lorenz.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include - -//#include -#include -#include - -#include "rk_performance_test_case.hpp" - -#include "lorenz.hpp" - -using namespace boost::numeric::odeint; - -typedef boost::array< double , 3 > state_type; -/*typedef explicit_generic_rk< 4 , 4 , state_type , double , state_type , double , array_algebra > rk4_type; - -typedef rk4_type::coef_a_type coef_a_type; -typedef rk4_type::coef_b_type coef_b_type; -typedef rk4_type::coef_c_type coef_c_type; - -const boost::array< double , 1 > a1 = {{ 0.5 }}; -const boost::array< double , 2 > a2 = {{ 0.0 , 0.5 }}; -const boost::array< double , 3 > a3 = {{ 0.0 , 0.0 , 1.0 }}; - -const coef_a_type a = fusion::make_vector( a1 , a2 , a3 ); -const coef_b_type b = {{ 1.0/6 , 1.0/3 , 1.0/3 , 1.0/6 }}; -const coef_c_type c = {{ 0.0 , 0.5 , 0.5 , 1.0 }}; -*/ - -typedef runge_kutta4< state_type , double , state_type , double , array_algebra > rk4_type; - - -class rk4_wrapper -{ - -public: - - rk4_wrapper() - { } - - void reset_init_cond() - { - m_x[0] = 10.0 * rand() / RAND_MAX; - m_x[1] = 10.0 * rand() / RAND_MAX; - m_x[2] = 10.0 * rand() / RAND_MAX; - m_t = 0.0; - } - - inline void do_step( const double dt ) - { - m_stepper.do_step( lorenz(), m_x , m_t , dt ); - } - - double state( const size_t i ) const - { return m_x[i]; } - -private: - state_type m_x; - double m_t; - rk4_type m_stepper; -}; - - - -int main() -{ - srand( 12312354 ); - - rk4_wrapper stepper; - - run( stepper ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk4_lorenz.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk4_lorenz.cpp deleted file mode 100644 index 9f74f02f..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk4_lorenz.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include - -#include "../fusion_explicit_rk_new.hpp" - -#include "rk_performance_test_case.hpp" - -#include "lorenz.hpp" - -typedef boost::array< double , 3 > state_type; -typedef explicit_rk< state_type , 4 > rk4_fusion_type; - -typedef rk4_fusion_type::coef_a_type coef_a_type; -typedef rk4_fusion_type::coef_b_type coef_b_type; -typedef rk4_fusion_type::coef_c_type coef_c_type; - -const boost::array< double , 1 > a1 = {{ 0.5 }}; -const boost::array< double , 2 > a2 = {{ 0.0 , 0.5 }}; -const boost::array< double , 3 > a3 = {{ 0.0 , 0.0 , 1.0 }}; - -const coef_a_type a = fusion::make_vector( a1 , a2 , a3 ); -const coef_b_type b = {{ 1.0/6 , 1.0/3 , 1.0/3 , 1.0/6 }}; -const coef_c_type c = {{ 0.0 , 0.5 , 0.5 , 1.0 }}; - -class fusion_wrapper -{ - -public: - - fusion_wrapper() : m_stepper( a , b , c ) - { } - - void reset_init_cond() - { - m_x[0] = 10.0 * rand() / RAND_MAX; - m_x[1] = 10.0 * rand() / RAND_MAX; - m_x[2] = 10.0 * rand() / RAND_MAX; - m_t = 0.0; - } - - inline void do_step( const double dt ) - { - m_stepper.do_step( lorenz(), m_x , m_t , dt ); - } - - double state( const size_t i ) const - { return m_x[i]; } - -private: - state_type m_x; - double m_t; - rk4_fusion_type m_stepper; -}; - - - -int main() -{ - srand( 12312354 ); - - fusion_wrapper stepper; - - run( stepper ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk4_phase_lattice.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk4_phase_lattice.cpp deleted file mode 100644 index 4e916ada..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk4_phase_lattice.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * generic_rk4_phase_lattice.cpp - * - * Created on: May 15, 2011 - * Author: mario - */ - -#include - -#include "../fusion_explicit_rk_new.hpp" - -#include "rk_performance_test_case.hpp" - -#include "phase_lattice.hpp" - -const size_t N = 1024; - -typedef boost::array< double , N > state_type; -typedef explicit_rk< state_type , 4 > rk4_fusion_type; - -typedef rk4_fusion_type::coef_a_type coef_a_type; -typedef rk4_fusion_type::coef_b_type coef_b_type; -typedef rk4_fusion_type::coef_c_type coef_c_type; - -const boost::array< double , 1 > a1 = {{ 0.5 }}; -const boost::array< double , 2 > a2 = {{ 0.0 , 0.5 }}; -const boost::array< double , 3 > a3 = {{ 0.0 , 0.0 , 1.0 }}; - -const coef_a_type a = fusion::make_vector( a1 , a2 , a3 ); -const coef_b_type b = {{ 1.0/6 , 1.0/3 , 1.0/3 , 1.0/6 }}; -const coef_c_type c = {{ 0.0 , 0.5 , 0.5 , 1.0 }}; - -class fusion_wrapper -{ - -public: - - fusion_wrapper() : m_stepper( a , b , c ) - { } - - void reset_init_cond() - { - for( size_t i = 0 ; i(), m_x , m_t , dt ); - } - - double state( const size_t i ) const - { return m_x[i]; } - -private: - state_type m_x; - double m_t; - rk4_fusion_type m_stepper; -}; - - - -int main() -{ - srand( 12312354 ); - - fusion_wrapper stepper; - - run( stepper , 10000 , 1E-6 ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk54ck.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk54ck.cpp deleted file mode 100644 index 1809f195..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_rk54ck.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * generic_rk78.cpp - * - * Created on: Apr 29, 2011 - * Author: mario - */ - -#include -#include - -#include - -#include -#include -#include - -#include "../fusion_explicit_error_rk.hpp" - -#include "lorenz.hpp" - -#define tab "\t" - -using namespace std; -using namespace boost::accumulators; - -typedef accumulator_set< - double , stats< tag::mean , tag::variance > - > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - -typedef boost::timer timer_type; - - -typedef boost::array< double , 3 > state_type; -typedef explicit_error_rk< state_type , 6 > rk54ck_fusion_type; -//typedef explicit_rk< state_type , 6 > rk54ck_fusion_type; - -const size_t loops = 20; - -int main( int argc , char **argv ) -{ - typedef rk54ck_fusion_type::coef_a_type coef_a_type; - typedef rk54ck_fusion_type::coef_b_type coef_b_type; - typedef rk54ck_fusion_type::coef_c_type coef_c_type; - - const boost::array< double , 1 > a1 = {{ 0.2 }}; - const boost::array< double , 2 > a2 = {{ 3.0/40.0 , 9.0/40 }}; - const boost::array< double , 3 > a3 = {{ 0.3 , -0.9 , 1.2 }}; - const boost::array< double , 4 > a4 = {{ -11.0/54.0 , 2.5 , -70.0/27.0 , 35.0/27.0 }}; - const boost::array< double , 5 > a5 = {{ 1631.0/55296.0 , 175.0/512.0 , 575.0/13824.0 , 44275.0/110592.0 , 253.0/4096.0 }}; - - const coef_a_type a = fusion::make_vector( a1 , a2 , a3 , a4 , a5 ); - const coef_b_type b = {{ 37.0/378.0 , 0.0 , 250.0/621.0 , 125.0/594.0 , 0.0 , 512.0/1771.0 }}; - const coef_b_type b2 = {{ b[0]-2825.0/27648.0 , b[1]-0.0 , b[2]-18575.0/48384.0 , b[3]-13525.0/55296.0 , b[4]-277.0/14336.0 , b[5]-0.25 }}; - //const coef_b_type b = {{ 2825.0/27648 , 0.0 , 18575.0/48384 , 13525.0/55296 , 277.0/14336 , 1.0/4 }}; - //const coef_b_type b2 = {{ b[0]-37.0/378 , b[1]-0.0 , b[2]-250.0/621 , b[3]-125.0/594 , b[4]-0.0 , b[5]-512.0/1771 }}; - const coef_c_type c = {{ 0.0 , 0.2 , 0.3 , 0.6 , 1.0 , 7.0/8 }}; - - rk54ck_fusion_type rk54ck( a , b , b2 , c ); - //rk54ck_fusion_type rk54ck( a , b , c ); - - const size_t num_of_steps = 20000000; - double dt = 1E-10; - - accumulator_type acc; - timer_type timer; - - srand( 12312354 ); - - for( size_t n=0 ; n - -#include "../fusion_explicit_error_rk.hpp" - -#include "rk_performance_test_case.hpp" - -#include "lorenz.hpp" - -typedef boost::array< double , 3 > state_type; -typedef explicit_error_rk< state_type , 6 > rk54ck_fusion_type; - - -typedef rk54ck_fusion_type::coef_a_type coef_a_type; -typedef rk54ck_fusion_type::coef_b_type coef_b_type; -typedef rk54ck_fusion_type::coef_c_type coef_c_type; - -const boost::array< double , 1 > a1 = {{ 0.2 }}; -const boost::array< double , 2 > a2 = {{ 3.0/40.0 , 9.0/40 }}; -const boost::array< double , 3 > a3 = {{ 0.3 , -0.9 , 1.2 }}; -const boost::array< double , 4 > a4 = {{ -11.0/54.0 , 2.5 , -70.0/27.0 , 35.0/27.0 }}; -const boost::array< double , 5 > a5 = {{ 1631.0/55296.0 , 175.0/512.0 , 575.0/13824.0 , 44275.0/110592.0 , 253.0/4096.0 }}; - -const coef_a_type a = fusion::make_vector( a1 , a2 , a3 , a4 , a5 ); -const coef_b_type b = {{ 37.0/378.0 , 0.0 , 250.0/621.0 , 125.0/594.0 , 0.0 , 512.0/1771.0 }}; -const coef_b_type b2 = {{ b[0]-2825.0/27648.0 , b[1]-0.0 , b[2]-18575.0/48384.0 , b[3]-13525.0/55296.0 , b[4]-277.0/14336.0 , b[5]-0.25 }}; - -const coef_c_type c = {{ 0.0 , 0.2 , 0.3 , 0.6 , 1.0 , 7.0/8 }}; - -class fusion_wrapper -{ -public: - - fusion_wrapper() : m_stepper( a , b , b2 , c ) - { } - - void reset_init_cond() - { - m_x[0] = 10.0 * rand() / RAND_MAX; - m_x[1] = 10.0 * rand() / RAND_MAX; - m_x[2] = 10.0 * rand() / RAND_MAX; - m_t = 0.0; - } - - inline void do_step( const double dt ) - { - m_stepper.do_step( lorenz() , m_x , m_t , dt , m_x_err ); - //m_t += dt; - } - - double state( const size_t i ) const - { return m_x[i]; } - -private: - state_type m_x; - state_type m_x_err; - double m_t; - rk54ck_fusion_type m_stepper; -}; - - - -int main() -{ - srand( 12312354 ); - - fusion_wrapper stepper; - - run( stepper ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/gsl_rk4_lorenz.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/gsl_rk4_lorenz.cpp deleted file mode 100644 index caacd9a4..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/gsl_rk4_lorenz.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * gsl_rk4_lorenz.cpp - * - * Created on: May 11, 2011 - * Author: mario - */ - -#include - -#include "rk_performance_test_case.hpp" - -#include "lorenz_gsl.hpp" - -const size_t dim = 3; - -class gsl_wrapper -{ -public: - - gsl_wrapper() - { - m_s = gsl_odeiv_step_alloc( gsl_odeiv_step_rk4 , dim); - m_sys.function = lorenz_gsl; - m_sys.jacobian = 0; - m_sys.dimension = dim; - m_sys.params = 0; - } - - void reset_init_cond() - { - m_x[0] = 10.0 * rand() / RAND_MAX; - m_x[1] = 10.0 * rand() / RAND_MAX; - m_x[2] = 10.0 * rand() / RAND_MAX; - m_t = 0.0; - } - - inline void do_step( const double dt ) - { - gsl_odeiv_step_apply ( m_s , m_t , dt , m_x , m_x_err , 0 , 0 , &m_sys ); - //m_t += dt; - } - - double state( const size_t i ) const - { return m_x[i]; } - - ~gsl_wrapper() - { - gsl_odeiv_step_free( m_s ); - } - -private: - double m_x[dim]; - double m_x_err[dim]; - double m_t; - gsl_odeiv_step *m_s; - gsl_odeiv_system m_sys; -}; - - - -int main() -{ - gsl_wrapper stepper; - - run( stepper , 20000000 / 3 , 1E-10 * 3); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/gsl_rk54ck.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/gsl_rk54ck.cpp deleted file mode 100644 index 89a50160..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/gsl_rk54ck.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * gsl_rk54ck.cpp - * - * Created on: Apr 29, 2011 - * Author: mario - */ - -#include - -#include -#include -#include - -#include -#include - -#include "lorenz_gsl.hpp" - -#define tab "\t" - -using namespace std; -using namespace boost::accumulators; - -typedef accumulator_set< - double , stats< tag::mean , tag::variance > - > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - -typedef boost::timer timer_type; - -const size_t loops = 20; - -int main() -{ - const size_t num_of_steps = 20000000; - double dt = 1E-10; - - accumulator_type acc; - timer_type timer; - - srand( 12312354 ); - - gsl_odeiv_step *s = gsl_odeiv_step_alloc( gsl_odeiv_step_rkck , 3); - gsl_odeiv_system sys = { lorenz_gsl , 0 , 3 , 0 }; - - for( size_t n=0 ; n - -#include "rk_performance_test_case.hpp" - -#include "lorenz_gsl.hpp" - -const size_t dim = 3; - -class gsl_wrapper -{ -public: - - gsl_wrapper() - { - m_s = gsl_odeiv_step_alloc( gsl_odeiv_step_rkck , dim); - m_sys.function = lorenz_gsl; - m_sys.jacobian = 0; - m_sys.dimension = dim; - m_sys.params = 0; - } - - void reset_init_cond() - { - m_x[0] = 10.0 * rand() / RAND_MAX; - m_x[1] = 10.0 * rand() / RAND_MAX; - m_x[2] = 10.0 * rand() / RAND_MAX; - m_t = 0.0; - } - - inline void do_step( const double dt ) - { - gsl_odeiv_step_apply ( m_s , m_t , dt , m_x , m_x_err , 0 , 0 , &m_sys ); - //m_t += dt; - } - - double state( const size_t i ) const - { return m_x[i]; } - - ~gsl_wrapper() - { - gsl_odeiv_step_free( m_s ); - } - -private: - double m_x[dim]; - double m_x_err[dim]; - double m_t; - gsl_odeiv_step *m_s; - gsl_odeiv_system m_sys; -}; - - - -int main() -{ - gsl_wrapper stepper; - - run( stepper ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/java/rk4.java b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/java/rk4.java deleted file mode 100644 index fb143e7a..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/java/rk4.java +++ /dev/null @@ -1,62 +0,0 @@ -//package org.apache.commons.math.ode; -//package org.apache.commons.math.ode.nonstiff; - -import org.apache.commons.math.ode.FirstOrderDifferentialEquations; -import org.apache.commons.math.ode.FirstOrderIntegrator; -import org.apache.commons.math.ode.nonstiff.ClassicalRungeKuttaIntegrator; -import org.apache.commons.math.ode.DerivativeException; -import org.apache.commons.math.ode.IntegratorException; - -public class rk4 { - - - private static class Lorenz implements FirstOrderDifferentialEquations - { - private static double sigma = 10.0; - private static double R = 28.0; - private static double b = 8.0/3.0; - - public int getDimension() - { - return 3; - } - - public void computeDerivatives( double t , double[] y , double[] yDot ) - { - yDot[0] = sigma * ( y[1] - y[0] ); - yDot[1] = R * y[0] - y[1] - y[0] * y[2]; - yDot[2] = y[0]*y[1] - b * y[2]; - } - } - - - public static void main( String[] args ) - { - final int loops = 20; - final double dt = 1E-10; - final int steps = 20000000; - double mean = 0.0; - - FirstOrderIntegrator rk4 = new ClassicalRungeKuttaIntegrator( dt ); - final FirstOrderDifferentialEquations ode = new Lorenz(); - - for( int n=0 ; n 2 ) - mean += end - start; - } - System.out.println("Average run time: " + (mean/loops) + " ms" ); - } - -} \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/lorenz.hpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/lorenz.hpp deleted file mode 100644 index c9748b68..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/lorenz.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * lorenz.hpp - * - * Created on: May 12, 2011 - * Author: mario - */ - -#ifndef LORENZ_HPP_ -#define LORENZ_HPP_ - -#include - -struct lorenz -{ - template< class state_type > - void inline operator()( const state_type &x , state_type &dxdt , const double t ) const - { - const double sigma = 10.0; - const double R = 28.0; - const double 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] = x[0]*x[1] - b * x[2]; - } -}; - - -typedef boost::array< double , 3 > state_type; - - -inline void lorenz_func( const state_type &x , state_type &dxdt , const double t ) -{ - const double sigma = 10.0; - const double R = 28.0; - const double 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] = x[0]*x[1] - b * x[2]; -} - -#endif /* LORENZ_HPP_ */ diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/lorenz_gsl.hpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/lorenz_gsl.hpp deleted file mode 100644 index 6b295ecc..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/lorenz_gsl.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * lorenz_gsl.hpp - * - * Created on: May 12, 2011 - * Author: mario - */ - -#ifndef LORENZ_GSL_HPP_ -#define LORENZ_GSL_HPP_ - -#include - -int lorenz_gsl( const double t , const double y[] , double f[] , void *params) -{ - const double sigma = 10.0; - const double R = 28.0; - const double b = 8.0 / 3.0; - - f[0] = sigma * ( y[1] - y[0] ); - f[1] = R * y[0] - y[1] - y[0] * y[2]; - f[2] = y[0]*y[1] - b * y[2]; - return GSL_SUCCESS; -} - -#endif \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/nr_rk4_lorenz.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/nr_rk4_lorenz.cpp deleted file mode 100644 index 71a178fb..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/nr_rk4_lorenz.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * nr_rk4_lorenz.cpp - * - * Created on: May 11, 2011 - * Author: mario - */ - -#include - -#include "rk_performance_test_case.hpp" - -#include "lorenz.hpp" - -const size_t dim = 3; - -typedef boost::array< double , dim > state_type; - - -template< class System , typename T , size_t dim > -void rk4_step( const System sys , boost::array< T , dim > &x , const double t , const double dt ) -{ // fast rk4 implementation adapted from the book 'Numerical Recipes' - size_t i; - const double hh = dt*0.5; - const double h6 = dt/6.0; - const double th = t+hh; - boost::array< T , dim > dydx , dym , dyt , yt; - - sys( x , dydx , t ); - - for( i=0 ; i - -#include "rk_performance_test_case.hpp" - -#include "phase_lattice.hpp" - -const size_t dim = 1024; - -typedef boost::array< double , dim > state_type; - - -template< class System , typename T , size_t dim > -void rk4_step( const System sys , boost::array< T , dim > &x , const double t , const double dt ) -{ // fast rk4 implementation adapted from the book 'Numerical Recipes' - size_t i; - const double hh = dt*0.5; - const double h6 = dt/6.0; - const double th = t+hh; - boost::array< T , dim > dydx , dym , dyt , yt; - - sys( x , dydx , t ); - - for( i=0 ; i() , m_x , m_t , dt ); - } - - double state( const size_t i ) const - { return m_x[i]; } - -private: - state_type m_x; - double m_t; -}; - - - -int main() -{ - srand( 12312354 ); - - nr_wrapper stepper; - - run( stepper , 10000 , 1E-6 ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/nr_rk54ck.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/nr_rk54ck.cpp deleted file mode 100644 index 6f8caf87..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/nr_rk54ck.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * nr_rk4.cpp - * - * Created on: Apr 28, 2011 - * Author: mario - */ - -#include -#include - -#include - -#include -#include -#include -#include - -#include "lorenz.hpp" - -#define tab "\t" - -using namespace std; -using namespace boost::accumulators; - -typedef accumulator_set< - double , stats< tag::mean , tag::variance > - > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - -typedef boost::timer timer_type; - -typedef boost::array< double , 3 > state_type; - - -template< class System , typename T , size_t dim > -void rk54ck_step( System sys , boost::array< T , dim > &x , const double t , const double dt , boost::array< T , dim > &xerr ) -{ // fast rk54ck implementation adapted from the book 'Numerical Recipes' - size_t i; - static const double a2 = 0.2 , a3 = 0.3 , a4 = 0.6 , a5 = 1.0 , a6 = 0.875 , - b21 = 0.2 , b31 = 3.0 / 40.0 , b32 = 9.0 / 40.0 , b41 = 0.3 , b42 = - -0.9 , b43 = 1.2 , b51 = -11.0 / 54.0 , b52 = 2.5 , b53 = - -70.0 / 27.0 , b54 = 35.0 / 27.0 , b61 = 1631.0 / 55296.0 , - b62 = 175.0 / 512.0 , b63 = 575.0 / 13824.0 , b64 = 44275.0 - / 110592.0 , b65 = 253.0 / 4096.0 , c1 = 37.0 / 378.0 , c3 = - 250.0 / 621.0 , c4 = 125.0 / 594.0 , c6 = 512.0 / 1771.0 , - dc1 = c1 - 2825.0 / 27648.0 , dc3 = c3 - 18575.0 / 48384.0 , dc4 = - c4 - 13525.0 / 55296.0 , dc5 = -277.00 / 14336.0 , dc6 = c6 - - 0.25; - const size_t n = dim; - boost::array< T , dim > dydx , ak2 , ak3 , ak4 , ak5 , ak6 , ytemp; - - sys( x , dydx , t ); - for (i=0;i - -#include "rk_performance_test_case.hpp" - -#include "lorenz.hpp" - -const size_t dim = 3; - -typedef boost::array< double , dim > state_type; - - -template< class System , typename T , size_t dim > -void rk54ck_step( System sys , boost::array< T , dim > &x , const double t , const double dt , boost::array< T , dim > &xerr ) -{ // fast rk54ck implementation adapted from the book 'Numerical Recipes' - size_t i; - static const double a2 = 0.2 , a3 = 0.3 , a4 = 0.6 , a5 = 1.0 , a6 = 0.875 , - b21 = 0.2 , b31 = 3.0 / 40.0 , b32 = 9.0 / 40.0 , b41 = 0.3 , b42 = - -0.9 , b43 = 1.2 , b51 = -11.0 / 54.0 , b52 = 2.5 , b53 = - -70.0 / 27.0 , b54 = 35.0 / 27.0 , b61 = 1631.0 / 55296.0 , - b62 = 175.0 / 512.0 , b63 = 575.0 / 13824.0 , b64 = 44275.0 - / 110592.0 , b65 = 253.0 / 4096.0 , c1 = 37.0 / 378.0 , c3 = - 250.0 / 621.0 , c4 = 125.0 / 594.0 , c6 = 512.0 / 1771.0 , - dc1 = c1 - 2825.0 / 27648.0 , dc3 = c3 - 18575.0 / 48384.0 , dc4 = - c4 - 13525.0 / 55296.0 , dc5 = -277.00 / 14336.0 , dc6 = c6 - - 0.25; - const size_t n = dim; - boost::array< T , dim > dydx , ak2 , ak3 , ak4 , ak5 , ak6 , ytemp; - - sys( x , dydx , t ); - for (i=0;i - -#include -#include - -#include "rk_performance_test_case.hpp" - -#include "lorenz.hpp" - -typedef boost::array< double , 3 > state_type; -typedef boost::numeric::odeint::runge_kutta4_classic< state_type , double , state_type , double , - boost::numeric::odeint::array_algebra > rk4_odeint_type; - - -class odeint_wrapper -{ -public: - void reset_init_cond() - { - m_x[0] = 10.0 * rand() / RAND_MAX; - m_x[1] = 10.0 * rand() / RAND_MAX; - m_x[2] = 10.0 * rand() / RAND_MAX; - m_t = 0.0; - } - - inline void do_step( const double dt ) - { - m_stepper.do_step( lorenz() , m_x , m_t , dt ); - //m_t += dt; - } - - double state( const size_t i ) const - { return m_x[i]; } - -private: - state_type m_x; - double m_t; - rk4_odeint_type m_stepper; -}; - - - -int main() -{ - srand( 12312354 ); - - odeint_wrapper stepper; - - run( stepper ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk4_lorenz_def_alg.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk4_lorenz_def_alg.cpp deleted file mode 100644 index ae8ddb17..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk4_lorenz_def_alg.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * odeint_rk4_lorenz_def_alg.cpp - * - * Created on: Apr 28, 2011 - * Author: mario - */ - -#include - -#include -#include - -#include "rk_performance_test_case.hpp" - -#include "lorenz.hpp" - -typedef boost::array< double , 3 > state_type; -typedef boost::numeric::odeint::runge_kutta4_classic< state_type > rk4_odeint_type; - - -class odeint_wrapper -{ -public: - void reset_init_cond() - { - m_x[0] = 10.0 * rand() / RAND_MAX; - m_x[1] = 10.0 * rand() / RAND_MAX; - m_x[2] = 10.0 * rand() / RAND_MAX; - m_t = 0.0; - } - - inline void do_step( const double dt ) - { - m_stepper.do_step( lorenz() , m_x , m_t , dt ); - //m_t += dt; - } - - double state( const size_t i ) const - { return m_x[i]; } - -private: - state_type m_x; - double m_t; - rk4_odeint_type m_stepper; -}; - - - -int main() -{ - odeint_wrapper stepper; - - run( stepper ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk4_phase_lattice.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk4_phase_lattice.cpp deleted file mode 100644 index 84eb4325..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk4_phase_lattice.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * odeint_rk4_phase_lattice.cpp - * - * Created on: May 15, 2011 - * Author: mario - */ - -#include - -#include - -#include -#include - -#include "rk_performance_test_case.hpp" - -#include "phase_lattice.hpp" - -const size_t N = 1024; - -typedef boost::array< double , N > state_type; -typedef boost::numeric::odeint::runge_kutta4_classic< state_type , double , state_type , double , - boost::numeric::odeint::array_algebra > rk4_odeint_type; - - -class odeint_wrapper -{ -public: - void reset_init_cond() - { - for( size_t i = 0 ; i() , m_x , m_t , dt ); - //m_t += dt; - } - - double state( const size_t i ) const - { return m_x[i]; } - -private: - state_type m_x; - double m_t; - rk4_odeint_type m_stepper; -}; - - - -int main() -{ - srand( 12312354 ); - - odeint_wrapper stepper; - - run( stepper , 10000 , 1E-6 ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk54ck.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk54ck.cpp deleted file mode 100644 index fd846361..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk54ck.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * odeint_rk54ck.cpp - * - * Created on: Apr 29, 2011 - * Author: mario - */ - -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include "lorenz.hpp" - -#define tab "\t" - -using namespace std; -using namespace boost::accumulators; - -typedef accumulator_set< - double , stats< tag::mean , tag::variance > - > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - -typedef boost::timer timer_type; - - -typedef boost::array< double , 3 > state_type; -//typedef boost::numeric::odeint::explicit_error_rk54_ck< state_type > rk54_ck_odeint_type; -typedef boost::numeric::odeint::runge_kutta_cash_karp54_classic< state_type , double , state_type , double , - boost::numeric::odeint::array_algebra > rk54_ck_odeint_type; - - -const size_t loops = 20; - -int main( int argc , char **argv ) -{ - rk54_ck_odeint_type rk54_ck_odeint; - - const size_t num_of_steps = 20000000; - double dt = 1E-10; - - accumulator_type acc; - timer_type timer; - - srand( 12312354 ); - - for( size_t n=0 ; n -#include - -#include - -#include -#include -#include -#include -#include - -#include "lorenz.hpp" - -#define tab "\t" - -using namespace std; -using namespace boost::accumulators; - -typedef accumulator_set< - double , stats< tag::mean , tag::variance > - > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - -typedef boost::timer timer_type; - - -typedef boost::array< double , 3 > state_type; -typedef boost::numeric::odeint::runge_kutta_cash_karp54_classic< state_type > rk54_ck_odeint_type; - - -const size_t loops = 20; - -int main( int argc , char **argv ) -{ - rk54_ck_odeint_type rk54_ck_odeint; - - const size_t num_of_steps = 20000000; - double dt = 1E-10; - - accumulator_type acc; - timer_type timer; - - srand( 12312354 ); - - for( size_t n=0 ; n - -#include -#include - -#include "rk_performance_test_case.hpp" - -#include "lorenz.hpp" - -typedef boost::array< double , 3 > state_type; -typedef boost::numeric::odeint::runge_kutta_cash_karp54_classic< state_type , double , state_type , double , - boost::numeric::odeint::array_algebra > rk54_odeint_type; - -class odeint_wrapper -{ -public: - void reset_init_cond() - { - m_x[0] = 10.0 * rand() / RAND_MAX; - m_x[1] = 10.0 * rand() / RAND_MAX; - m_x[2] = 10.0 * rand() / RAND_MAX; - m_t = 0.0; - } - - inline void do_step( const double dt ) - { - m_stepper.do_step( lorenz() , m_x , m_t , dt , m_x_err ); - //m_t += dt; - } - - double state( const size_t i ) const - { return m_x[i]; } - -private: - state_type m_x; - state_type m_x_err; - double m_t; - rk54_odeint_type m_stepper; -}; - - - -int main() -{ - srand( 12312354 ); - - odeint_wrapper stepper; - - run( stepper ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk54ck_lorenz_def_alg.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk54ck_lorenz_def_alg.cpp deleted file mode 100644 index 90c3bc37..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/odeint_rk54ck_lorenz_def_alg.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * odeint_rk54ck_lorenz.cpp - * - * Created on: May 12, 2011 - * Author: mario - */ - -#include - -#include -#include - -#include "rk_performance_test_case.hpp" - -#include "lorenz.hpp" - -typedef boost::array< double , 3 > state_type; -typedef boost::numeric::odeint::runge_kutta_cash_karp54_classic< state_type > rk54_odeint_type; - -class odeint_wrapper -{ -public: - void reset_init_cond() - { - m_x[0] = 10.0 * rand() / RAND_MAX; - m_x[1] = 10.0 * rand() / RAND_MAX; - m_x[2] = 10.0 * rand() / RAND_MAX; - m_t = 0.0; - } - - inline void do_step( const double dt ) - { - m_stepper.do_step( lorenz() , m_x , m_t , dt , m_x_err ); - //m_t += dt; - } - - double state( const size_t i ) const - { return m_x[i]; } - -private: - state_type m_x; - state_type m_x_err; - double m_t; - rk54_odeint_type m_stepper; -}; - - - -int main() -{ - srand( 12312354 ); - - odeint_wrapper stepper; - - run( stepper ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/perf_analysis.py b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/perf_analysis.py deleted file mode 100644 index aec361b3..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/perf_analysis.py +++ /dev/null @@ -1,51 +0,0 @@ -from pylab import * - -rcParams.update( { 'xtick.labelsize': 20 , 'ytick.labelsize': 20 }) - - -results_rk4 = array( -[[ 0.82 , 0.59 , 0.60 , 0.60 , 0.54 , 0.54 , 0.81 , 0.98 , 1.14 ] , #odeint - [ 0.64 , 0.56 , 0.54 , 0.60 , 0.77 , 0.65 , 0.85 , 0.98 , 1.09 ] , #generic - [ 0.96 , 0.64 , 0.62 , 0.60 , 0.80 , 0.47 , 1.05 , 0.63 , 0.76 ] , #nr - [ 1.52 , 1.61 , 1.35 , 1.77 , 1.07 , 1.06 , 1.07 , 1.28 , 1.62 ] , #gsl - [ 1.85 , 1.85 , 1.47 , 2.08 , 1.08 , 1.08 , 1.57 , 1.70 , 2.10 ]]) #rt gen - -results_rk54ck = array( -[[ 1.34 , 1.14 , 1.38 , 1.00 , 0.95 , 1.53 , 1.91 ] , #odeint - [ 1.26 , 1.13 , 1.43 , 1.28 , 1.02 , 1.63 , 1.84 ] , #generic - [ 2.04 , 1.32 , 1.34 , 1.48 , 1.10 , 1.82 , 1.15 ] , #nr - [ 2.80 , 2.34 , 2.79 , 1.80 , 1.94 , 1.99 , 2.16 ]]) #gsl - -means_rk4 = 100*ones( 5 ) -error_rk4 = zeros( 5 ) - -for i in arange(1,5): - tmp = results_rk4[0] / results_rk4[i] - means_rk4[i] = 100*mean( tmp ) - error_rk4[i] = 100*sqrt(var( tmp )) - -means_rk54ck = 100*ones( 4 ) -error_rk54ck = zeros( 4 ) - -for i in arange(1,4): - tmp = results_rk54ck[0] / results_rk54ck[i] - means_rk54ck[i] = 100*mean( tmp ) - error_rk54ck[i] = 100*sqrt(var( tmp )) - -bar_width = 0.6 - -figure(1) -title("Runge-Kutta 4" , fontsize=20) -bar( arange(5) , means_rk4 , bar_width , color='blue' , linewidth=4 , edgecolor='blue' , yerr = error_rk4 , ecolor='red') #, elinewidth=2, ecolor='red' ) -xlim( -0.5 , 4.5+bar_width ) -xticks( arange(5)+bar_width/2 , ('odeint' , 'generic' , 'NR' , 'GSL' , 'rt gen' ) ) -ylabel('Performance in %' , fontsize=20) - -figure(2) -title("Runge-Kutta 5(4) Cash-Karp" , fontsize=20) -bar( arange(4) , means_rk54ck , bar_width , color='blue' , linewidth=4 , edgecolor='blue' , yerr = error_rk54ck , ecolor='red' ) -xlim( -0.5 , 3.5+bar_width ) -xticks( arange(4)+bar_width/2 , ('odeint' , 'generic' , 'NR' , 'GSL' ) ) -ylabel('Performance in %' , fontsize=20) - -show() diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/perf_tests.py b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/perf_tests.py deleted file mode 100644 index 1e9791c2..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/perf_tests.py +++ /dev/null @@ -1,39 +0,0 @@ -from os import popen -from os import system -from os.path import isfile - -#toolset = "gcc-4.4" -#toolset = "intel" -#toolset = "msvc" -toolset = "msvc-9.0express" - -#bin_path = "bin/gcc-4.4/release/" -#bin_path = "bin/intel-linux/release/" -bin_path = "bin\\msvc-9.0express\\release\\threading-multi\\" -extension = ".exe" -#extension = "" - -bins = [ "odeint_rk4_lorenz" , "odeint_rk4_lorenz_def_alg" , "generic_odeint_rk4_lorenz" , "generic_rk4_lorenz" , "nr_rk4_lorenz" , "gsl_rk4_lorenz" , "rt_generic_rk4_lorenz" , - "odeint_rk54ck_lorenz" , "odeint_rk54ck_lorenz_def_alg" , "generic_rk54ck_lorenz" , "nr_rk54ck_lorenz" , "gsl_rk54ck_lorenz" ] - -results = [] - -print "Performance tests for " , bin_path -print - -for bin in bins: - system( "bjam toolset=" + toolset + " -a " + bin ); - if isfile( bin_path + bin + extension): - print "Running" , bin - res = popen( bin_path+bin+extension ).read() - print bin , res - results.append( res ) - else: - print "no executable found:" , bin_path + bin + extension - results.append( " -- " ) - -print "Results from" , bin_path -print - -for i in range(len(bins)): - print bins[i] , results[i] diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/phase_lattice.hpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/phase_lattice.hpp deleted file mode 100644 index 07b00251..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/phase_lattice.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* -*/ - -#include - -#include - -template< size_t N > -struct phase_lattice -{ - typedef double value_type; - typedef boost::array< value_type , N > state_type; - - value_type m_epsilon; - state_type m_omega; - - phase_lattice() : m_epsilon( 6.0/(N*N) ) // should be < 8/N^2 to see phase locking - { - for( size_t i=1 ; i -#include -#include -#include - -#define tab "\t" - -using namespace std; -using namespace boost::accumulators; - -typedef accumulator_set< - double , stats< tag::mean , tag::variance > - > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - -typedef boost::timer timer_type; - - -template< class Stepper > -void run( Stepper &stepper , const size_t num_of_steps = 20000000 , const double dt = 1E-10 ) -{ - const size_t loops = 20; - - accumulator_type acc; - timer_type timer; - - srand( 12312354 ); - - for( size_t n=0 ; n - -#include "../rt_explicit_rk.hpp" - -#include "rk_performance_test_case.hpp" - -#include "lorenz.hpp" - -typedef boost::array< double , 3 > state_type; - -typedef rt_explicit_rk< state_type > rk_stepper_type; - -const size_t stage_count = 4; - - -class rt_generic_wrapper -{ -public: - - rt_generic_wrapper() : m_stepper( stage_count ) - { - rk_stepper_type::coeff_a_type a( stage_count-1 ); - a[0].resize(1); a[0][0] = 0.5; - a[1].resize(2); a[1][0] = 0.0; a[1][1] = 0.5; - a[2].resize(3); a[2][0] = 0.0; a[2][1] = 0.0; a[2][2] = 1.0; - - rk_stepper_type::coeff_b_type b( stage_count ); - b[0] = 1.0/6; b[1] = 1.0/3; b[2] = 1.0/3; b[3] = 1.0/6; - - rk_stepper_type::coeff_c_type c( stage_count ); - c[0] = 0.0; c[1] = 0.5; c[2] = 0.5; c[3] = 1.0; - - m_stepper.set_params( a , b , c ); - } - - void reset_init_cond() - { - m_x[0] = 10.0 * rand() / RAND_MAX; - m_x[1] = 10.0 * rand() / RAND_MAX; - m_x[2] = 10.0 * rand() / RAND_MAX; - m_t = 0.0; - } - - inline void do_step( const double dt ) - { - m_stepper.do_step( lorenz() , m_x , m_t , dt ); - //m_t += dt; - } - - double state( const size_t i ) const - { return m_x[i]; } - -private: - state_type m_x; - double m_t; - rk_stepper_type m_stepper; -}; - - - -int main() -{ - rt_generic_wrapper stepper; - - run( stepper ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/rt_generic_rk4_phase_lattice.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/rt_generic_rk4_phase_lattice.cpp deleted file mode 100644 index 22bfc113..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/rt_generic_rk4_phase_lattice.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * rt_generic_rk4_phase_lattice.cpp - * - * Created on: May 15, 2011 - * Author: mario - */ - -#include - -#include "../rt_explicit_rk.hpp" - -#include "rk_performance_test_case.hpp" - -#include "phase_lattice.hpp" - -const size_t N = 1024; - -typedef boost::array< double , N > state_type; - -typedef rt_explicit_rk< state_type > rk_stepper_type; - -const size_t stage_count = 4; - - -class rt_generic_wrapper -{ -public: - - rt_generic_wrapper() : m_stepper( stage_count ) - { - rk_stepper_type::coeff_a_type a( stage_count-1 ); - a[0].resize(1); a[0][0] = 0.5; - a[1].resize(2); a[1][0] = 0.0; a[1][1] = 0.5; - a[2].resize(3); a[2][0] = 0.0; a[2][1] = 0.0; a[2][2] = 1.0; - - rk_stepper_type::coeff_b_type b( stage_count ); - b[0] = 1.0/6; b[1] = 1.0/3; b[2] = 1.0/3; b[3] = 1.0/6; - - rk_stepper_type::coeff_c_type c( stage_count ); - c[0] = 0.0; c[1] = 0.5; c[2] = 0.5; c[3] = 1.0; - - m_stepper.set_params( a , b , c ); - } - - void reset_init_cond() - { - for( size_t i = 0 ; i() , m_x , m_t , dt ); - //m_t += dt; - } - - double state( const size_t i ) const - { return m_x[i]; } - -private: - state_type m_x; - double m_t; - rk_stepper_type m_stepper; -}; - - - -int main() -{ - srand( 12312354 ); - - rt_generic_wrapper stepper; - - run( stepper , 10000 , 1E-6 ); -} diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/rt_algebra.hpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/rt_algebra.hpp deleted file mode 100644 index 0418c6bb..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/rt_algebra.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#include - -using namespace std; - -struct rt_algebra -{ - template< typename T , size_t dim > - inline static void foreach( boost::array< T , dim > & x_tmp , const boost::array< T , dim > &x , - const vector< double > &a , - const boost::array< T , dim > *k_vector , const double dt ) - { - for( size_t i=0 ; i - -#include "rt_algebra.hpp" - -using namespace std; - -template< class StateType > -class rt_explicit_rk -{ -public: - typedef StateType state_type; - typedef vector< vector< double > > coeff_a_type; - typedef vector< double > coeff_b_type; - typedef vector< double > coeff_c_type; - - rt_explicit_rk( size_t stage_count ) : m_s( stage_count ) - { - m_F = new state_type[ m_s ]; - } - - rt_explicit_rk( size_t stage_count , coeff_a_type &a , coeff_b_type &b , coeff_c_type &c ) - : m_s( stage_count ) , m_a( a ) , m_b( b ) , m_c( c ) - { - m_F = new state_type[ m_s ]; - } - - ~rt_explicit_rk() - { - delete[] m_F; - } - - void set_params( coeff_a_type &a , coeff_b_type &b , coeff_c_type &c ) - { - m_a = a; - m_b = b; - m_c = c; - } - - template< class System > - void do_step( System sys , state_type &x , const double t , const double dt ) - { - // first stage separately - sys( x , m_F[0] , t + m_c[0]*t ); - if( m_s == 1 ) - rt_algebra::foreach( x , x , m_b , m_F , dt ); - else - rt_algebra::foreach( m_x_tmp , x , m_a[0] , m_F , dt ); - - for( size_t stage = 2 ; stage <= m_s ; ++stage ) - { - sys( m_x_tmp , m_F[stage-1] , t + m_c[stage-1]*dt ); - if( stage == m_s ) - rt_algebra::foreach( x , x , m_b , m_F , dt ); - else - rt_algebra::foreach( m_x_tmp , x , m_a[stage-1] , m_F , dt ); - } - } - - -private: - size_t m_s; - vector< vector< double > > m_a; - vector< double > m_b; - vector< double > m_c; - - state_type m_x_tmp; - state_type *m_F; -}; - -#endif /* RT_EXPLICIT_RK_HPP_ */ diff --git a/libs/numeric/odeint/ideas/fusion_runge_kutta/test_explicit_rk.cpp b/libs/numeric/odeint/ideas/fusion_runge_kutta/test_explicit_rk.cpp deleted file mode 100644 index cdeee465..00000000 --- a/libs/numeric/odeint/ideas/fusion_runge_kutta/test_explicit_rk.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * test_explicit_rk.cpp - * - * Created on: Apr 26, 2011 - * Author: mario - */ - -#include -#include - -#include - -#include -#include -#include - -//#include "fusion_explicit_rk.hpp" -#include "fusion_explicit_rk_new.hpp" - -#define tab "\t" - -using namespace std; -using namespace boost::accumulators; - -typedef accumulator_set< - double , stats< tag::mean , tag::variance > - > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - -typedef boost::timer timer_type; - - -typedef boost::array< double , 3 > state_type; -typedef explicit_rk< state_type , 4 > rk4_fusion_type; - - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - const double sigma = 10.0; - const double R = 28.0; - const double 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] = x[0]*x[1] - b * x[2]; -} - - - - -int main( int argc , char **argv ) -{ - typedef rk4_fusion_type::coef_a_type coef_a_type; - typedef rk4_fusion_type::coef_b_type coef_b_type; - typedef rk4_fusion_type::coef_c_type coef_c_type; - - const boost::array< double , 1 > a1 = {{ 0.5 }}; - const boost::array< double , 2 > a2 = {{ 0.0 , 0.5 }}; - const boost::array< double , 3 > a3 = {{ 0.0 , 0.0 , 1.0 }}; - - const coef_a_type a = fusion::make_vector( a1 , a2 , a3 ); - const coef_b_type b = {{ 1.0/6 , 1.0/3 , 1.0/3 , 1.0/6 }}; - const coef_c_type c = {{ 0.0 , 0.5 , 0.5 , 1.0 }}; - - rk4_fusion_type rk4_fusion( a , b , c ); - - const size_t num_of_steps = 20000000; - const double dt = 0.01; - - accumulator_type acc; - timer_type timer; - - srand( 12312354 ); - - while( true ) - { - state_type x = {{ 10.0 * rand()/RAND_MAX , 10.0 * rand()/RAND_MAX , 10.0 * rand()/RAND_MAX }}; - //state_type x = {{ 10.0 , 1.0 , 5.0 }}; - double t = 0.0; - - timer.restart(); - for( size_t i=0 ; iBOOST_ALL_NO_LIB=1 - ../../../../.. - ../butcher - $(CHRONO_ROOT) - ; - -#exe test -# : test.cpp -# ; - -exe rk_test - : rk_test.cpp - ; - -exe performance - : performance.cpp - ; - -exe performance_fusion - : performance_fusion.cpp runge_kutta_stepper_fast.hpp - ; - -exe performance_mpl - : performance_mpl.cpp - ; - -exe performance_odeint - : performance_odeint.cpp - ; \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/generic_stepper/fusion_algebra.hpp b/libs/numeric/odeint/ideas/generic_stepper/fusion_algebra.hpp deleted file mode 100644 index 0b75c2dc..00000000 --- a/libs/numeric/odeint/ideas/generic_stepper/fusion_algebra.hpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * fusion_algebra.hpp - * - * Created on: Nov 13, 2010 - * Author: mario - */ - -#ifndef FUSION_ALGEBRA_HPP_ -#define FUSION_ALGEBRA_HPP_ - -#include - -#include - -#include -#include - -template< size_t n > -struct fusion_algebra -{ - - typedef boost::numeric::odeint::range_algebra std_algebra; - typedef boost::numeric::odeint::default_operations std_op; - - template< class state_type > - inline static void foreach( state_type &x_tmp , const state_type &x , const boost::array< double , n > &a , - const state_type *k_vector , const double dt ) - {} - -}; - - -template<> -struct fusion_algebra< 1 > -{ - - typedef boost::numeric::odeint::range_algebra std_algebra; - typedef boost::numeric::odeint::default_operations std_op; - - template< class state_type > - inline static void foreach( state_type &x_tmp , const state_type &x , const boost::array< double , 1 > &a , - const state_type *k_vector , const double dt ) - { - std_algebra::for_each3( x_tmp , x , k_vector[0] , std_op::scale_sum2<>( 1.0 , a[0]*dt ) ); - } - -}; - - -template<> -struct fusion_algebra< 2 > -{ - - typedef boost::numeric::odeint::range_algebra std_algebra; - typedef boost::numeric::odeint::default_operations std_op; - - template< class state_type > - inline static void foreach( state_type &x_tmp , const state_type &x , const boost::array< double , 2 > &a , - const state_type *k_vector , const double dt ) - { - std_algebra::for_each4( x_tmp , x , k_vector[0] , k_vector[1] , - std_op::scale_sum3<>( 1.0 , a[0]*dt , a[1]*dt ) ); - } - -}; - - -template<> -struct fusion_algebra< 3 > -{ - - typedef boost::numeric::odeint::range_algebra std_algebra; - typedef boost::numeric::odeint::default_operations std_op; - - template< class state_type > - inline static void foreach( state_type &x_tmp , const state_type &x , const boost::array< double , 3 > &a , - const state_type *k_vector , const double dt ) - { - std_algebra::for_each5( x_tmp , x , k_vector[0] , k_vector[1] , k_vector[2] , - std_op::scale_sum4<>( 1.0 , a[0]*dt , a[1]*dt , a[2]*dt) ); - } - -}; - - - -template<> -struct fusion_algebra< 4 > -{ - - typedef boost::numeric::odeint::range_algebra std_algebra; - typedef boost::numeric::odeint::default_operations std_op; - - template< class state_type > - inline static void foreach( state_type &x_tmp , const state_type &x , const boost::array< double , 4 > &a , - const state_type *k_vector , const double dt ) - { - std_algebra::for_each6( x_tmp , x , k_vector[0] , k_vector[1] , k_vector[2] , k_vector[3] , - std_op::scale_sum5<>( 1.0 , a[0]*dt , a[1]*dt , a[2]*dt , a[3]*dt ) ); - } - -}; - - -#endif /* FUSION_ALGEBRA_HPP_ */ diff --git a/libs/numeric/odeint/ideas/generic_stepper/fusion_array.cpp b/libs/numeric/odeint/ideas/generic_stepper/fusion_array.cpp deleted file mode 100644 index b3a3a98d..00000000 --- a/libs/numeric/odeint/ideas/generic_stepper/fusion_array.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * main.cpp - * - * Created on: Oct 16, 2010 - * Author: karsten - */ - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -//#include -//#include -//#include - - -#define tab "\t" - -using namespace std; -namespace fusion = boost::fusion; -namespace mpl = boost::mpl; - -//template< class T , class Constant > -//struct array_wrapper : std::tr1::array< T , Constant::value > -//{ -//}; - -template< class T , class Constant > -struct array_wrapper -{ - typedef typename std::tr1::array< T , Constant::value > type; -}; - - -struct print_xml -{ - template - void operator()(T const& x) const - { - std::cout - << '<' << typeid(x).name() << '>' -// << x - << "' - << endl; - } -}; - - -template< size_t N > -class test_class -{ -public: - - typedef typename fusion::result_of::as_vector - < - typename mpl::copy - < - mpl::range_c< size_t , 1 , N > , - mpl::inserter - < - mpl::vector0<> , - mpl::push_back< mpl::_1 , array_wrapper< double , mpl::_2 > > - > - >::type - >::type coef_a_type; - - typedef std::tr1::array< double , N > coef_c_type; - - const coef_a_type coef_a; - const coef_c_type coef_c; - - test_class( const coef_a_type &a , const coef_c_type &c ) : coef_a( a ) , coef_c( c ) { } -}; - - - -int main( int argc , char **argv ) -{ - typedef test_class< 3 > class_type; - const std::tr1::array< double , 1 > a_1 = {{ 0.5 }}; - const std::tr1::array< double , 2 > a_2 = {{ 2.2 , 3.3 }}; - const class_type::coef_a_type coef_a = fusion::make_vector( a_1 , a_2 ); - - test_class< 3 >::coef_a_type coef_a_new; - fusion::for_each( coef_a_new , print_xml() ); - - - const class_type::coef_c_type coef_c = {{ 1.0 , 2.0 }}; - - class_type my_class( coef_a , coef_c ); - - cout << my_class.coef_c[0] << endl; - cout << my_class.coef_c[1] << endl; - - cout << fusion::at_c< 0 >( my_class.coef_a )[0] << endl; - cout << fusion::at_c< 1 >( my_class.coef_a )[0] << endl; - cout << fusion::at_c< 1 >( my_class.coef_a )[1] << endl; - - return 0; -} diff --git a/libs/numeric/odeint/ideas/generic_stepper/fusion_stepper.hpp b/libs/numeric/odeint/ideas/generic_stepper/fusion_stepper.hpp deleted file mode 100644 index c6ca9277..00000000 --- a/libs/numeric/odeint/ideas/generic_stepper/fusion_stepper.hpp +++ /dev/null @@ -1,294 +0,0 @@ -/* - * fusion_stepper.hpp - * - * Created on: Nov 21, 2010 - * Author: mario - */ - -#ifndef FUSION_STEPPER_HPP_ -#define FUSION_STEPPER_HPP_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include - -#include - - -#include "algebra.hpp" - -namespace mpl = boost::mpl; -namespace fusion = boost::fusion; - -using namespace std; - -template< typename State , size_t stage > -class stepper_stage -{ - -public: - - typedef double value_type; - typedef State state_type; - typedef vector< vector< double > > parameter_array_type2D; - typedef vector< double > parameter_array_type1D; - - - void init( const parameter_array_type2D &a , const parameter_array_type1D &c ) - { - copy( a[stage-1].begin() , a[stage-1].end() , &m_a_row[0] ); - m_c = c[stage-1]; - } - - template< typename System > - void operator() ( System &system , state_type &x_tmp , const state_type &x , state_type *k_vector , - double t , const double dt ) const - { - system( x_tmp , k_vector[stage-1] , t + m_c * dt ); - algebra::foreach< stage >( x_tmp , x , m_a_row , k_vector , dt); - } - -private: - - boost::array< value_type , stage > m_a_row; - value_type m_c; - -}; - -template< typename State > -class stepper_stage< State , 1 > -{ - -public: - - typedef double value_type; - typedef State state_type; - typedef vector< vector< double > > parameter_array_type2D; - typedef vector< double > parameter_array_type1D; - - - void init( const parameter_array_type2D &a , const parameter_array_type1D &c ) - { - copy( a[0].begin() , a[0].end() , &m_a_row[0] ); - m_c = c[0]; - } - - template< typename System > - void operator() ( System &system , state_type &x_tmp , const state_type &x , state_type *k_vector , - double t , const double dt ) const - { - system( x , k_vector[0] , t + m_c * dt ); - algebra::foreach( x_tmp , x , m_a_row , k_vector , dt); - } - -private: - - boost::array< value_type , 1 > m_a_row; - value_type m_c; - -}; - - -template< typename State , size_t stage > -class stepper_last_stage -{ - -public: - - typedef double value_type; - typedef State state_type; - typedef vector< vector< double > > parameter_array_type2D; - typedef vector< double > parameter_array_type1D; - - - void init( const parameter_array_type1D &b , const parameter_array_type1D &c ) - { - copy( b.begin() , b.end() , &m_b[0] ); - m_c = c[stage-1]; - } - - template< typename System > - void operator() ( System &system , state_type &x_tmp , state_type &x , state_type *k_vector , - double t , const double dt ) const - { - system( x_tmp , k_vector[stage-1] , t + m_c * dt ); - algebra::foreach( x , x , m_b , k_vector , dt); - } - -private: - - boost::array< value_type , stage > m_b; - value_type m_c; - -}; - - -template< typename State > -class stepper_last_stage< State , 1 > -{ - -public: - - typedef double value_type; - typedef State state_type; - typedef vector< vector< double > > parameter_array_type2D; - typedef vector< double > parameter_array_type1D; - - - void init( const parameter_array_type1D &b , const parameter_array_type1D &c ) - { - copy( b.begin() , b.end() , &m_b[0] ); - m_c = c[0]; - } - - template< typename System > - void operator() ( System &system , state_type &x_tmp , state_type &x , state_type k_vector[1] , - double t , const double dt ) const - { - system( x , k_vector[0] , t + m_c * dt ); - algebra::foreach( x , x , m_b , k_vector , dt); - } - -private: - - boost::array< value_type , 1 > m_b; - value_type m_c; - -}; - - - - - - - - -template< class T , class Constant > -struct stepper_stage_wrapper -{ - typedef stepper_stage< T , Constant::value > type; -}; - - - - -/* Runge Kutta Stepper - consisting of several stages */ - -template< typename State , size_t stage_count > -class runge_kutta_stepper -{ - - typedef State state_type; - - - typedef typename fusion::result_of::as_vector - < - typename mpl::copy - < - mpl::range_c< size_t , 1 , N > , - mpl::inserter - < - mpl::vector0<> , - mpl::push_back< mpl::_1 , array_wrapper< double , mpl::_2 > > - > - >::type - >::type coef_a_type; - typedef boost::array< double , N > coef_b_type; - typedef boost::array< double , N > coef_c_type; - - - template< class System > - struct calculate_stage - { - System &system; - state_type &x , &x_tmp; - state_type *k_vector; - const double t; - const double dt; - - calculate_stage( System &_system , state_type &_x , state_type &_x_tmp , state_type *_k_vector , - const double _t , const double _dt ) - : system( _system ) , x( _x ) , x_tmp( _x_tmp ) , k_vector( _k_vector ) , t( _t ) , dt( _dt ) - {} - - template< class Stage > - void operator()( Stage const &stage ) const - { - stage( system , x_tmp , x , k_vector , t , dt ); - } - - }; - - struct init_stage { - - const parameter_array_type2D &m_a; - const parameter_array_type1D &m_c; - - init_stage( const parameter_array_type2D &a , const parameter_array_type1D &c ) - : m_a( a ) , m_c( c ) - { } - - template< typename Stage > - void operator() ( Stage &stage ) const - { - stage.init( m_a , m_c ); - } - }; - -public: - - typedef mpl::range_c< size_t , 1 , stage_count > indices; - typedef typename fusion::result_of::as_vector < - typename mpl::copy // create mpl::vector< stepper_stage< 0 >, stepper_stage< 1 > , .. stepper_stage< stage_count-1 > > - < - indices , - mpl::inserter - < - mpl::vector0<> , - mpl::push_back< mpl::_1 , stepper_stage_wrapper< State , mpl::_2 > > - > - >::type - >::type stage_vector; - typedef stepper_last_stage< State , stage_count > last_stage_type; - - runge_kutta_stepper( const coef_a_type &a , - const coef_b_type &b , - const coef_c_type &c ) - { - fusion::for_each( m_stages , init_stage( a , c ) ); - m_last_stage.init( b , c ); - } - - template< class System > - void do_step( System &system , state_type &x , double t , const double dt ) - { - fusion::for_each( m_stages , calculate_stage< System >( system , x , m_x_tmp , m_k_vector , t , dt ) ); - m_last_stage( system , m_x_tmp , x , m_k_vector , t , dt ); - } - - -private: - - state_type m_k_vector[stage_count]; - state_type m_x_tmp; - stage_vector m_stages; - last_stage_type m_last_stage; -}; - -#endif /* FUSION_STEPPER_HPP_ */ diff --git a/libs/numeric/odeint/ideas/generic_stepper/generic_stepper.hpp b/libs/numeric/odeint/ideas/generic_stepper/generic_stepper.hpp deleted file mode 100644 index efe26723..00000000 --- a/libs/numeric/odeint/ideas/generic_stepper/generic_stepper.hpp +++ /dev/null @@ -1,259 +0,0 @@ -/* - * generic_stepper.hpp - * - * Created on: Nov 12, 2010 - * Author: mario - */ - -#ifndef GENERIC_STEPPER_HPP_ -#define GENERIC_STEPPER_HPP_ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "algebra.hpp" - -namespace mpl = boost::mpl; - -using namespace std; - - -/* - * c_1 | - * c_2 | a_{2,1} - * c_3 | a_{3,1} a_{3,2} - * ... - * c_s | a_{s,1} a_{s,2} ... a_{s,s-1} - * ----------------------------------- - * | b_1 b_2 b_{s-1} b_s - */ - - -/* Runge Kutta Stages */ - - -template< typename State , size_t stage > -class stepper_stage -{ - -public: - - typedef double value_type; - typedef State state_type; - typedef vector< vector< double > > parameter_array_type2D; - typedef vector< double > parameter_array_type1D; - - - void init( parameter_array_type2D &a , parameter_array_type1D &c ) - { - m_a_row = a[stage-1]; - m_c = c[stage-1]; - } - - template< typename System > - void operator() ( System &system , state_type &x_tmp , const state_type &x , const state_type *k_vector , double t , const double dt ) - { - system( x_tmp , k_vector[stage-1] , t + m_c * dt ); - algebra::foreach< stage >( x_tmp , x , m_a_row , k_vector , dt); - } - -private: - - vector< value_type > m_a_row; - value_type m_c; - -}; - - -template< typename State > -class stepper_stage< State , 1 > -{ - -public: - - typedef double value_type; - typedef State state_type; - typedef vector< vector< double > > parameter_array_type2D; - typedef vector< double > parameter_array_type1D; - - - void init( parameter_array_type2D &a , parameter_array_type1D &c ) - { - m_a_row = a[0]; - m_c = c[0]; - } - - template< typename System > - void operator() ( System &system , state_type &x_tmp , const state_type &x , const state_type *k_vector , double t , const double dt ) - { - system( x , k_vector[0] , t + m_c * dt ); - algebra::foreach( x_tmp , x , m_a_row , k_vector , dt); - } - -private: - - vector< value_type > m_a_row; - value_type m_c; - -}; - - -template< typename State , size_t stage > -class stepper_last_stage -{ - -public: - - typedef double value_type; - typedef State state_type; - typedef vector< vector< double > > parameter_array_type2D; - typedef vector< double > parameter_array_type1D; - - - void init( const parameter_array_type1D &b , const parameter_array_type1D &c ) - { - m_b = b; - m_c = c[stage-1]; - } - - template< typename System > - void operator() ( System &system , state_type &x_tmp , state_type &x , state_type *k_vector , double t , const double dt ) - { - system( x_tmp , k_vector[stage-1] , t + m_c * dt ); - algebra::foreach( x , x , m_b , k_vector , dt); - } - -private: - - vector< value_type > m_b; - value_type m_c; - -}; - - -template< typename State > -class stepper_last_stage< State , 1 > -{ - -public: - - typedef double value_type; - typedef State state_type; - typedef vector< vector< double > > parameter_array_type2D; - typedef vector< double > parameter_array_type1D; - - - void init( const parameter_array_type1D &b , const parameter_array_type1D &c ) - { - m_b = b; - m_c = c[0]; - } - - template< typename System > - void do_step( System &system , state_type &x_tmp , state_type &x , state_type k_vector[1] , double t , const double dt ) - { - system( x , k_vector[0] , t + m_c * dt ); - algebra::foreach( x , x , m_b , k_vector , dt); - } - -private: - - vector< value_type > m_b; - value_type m_c; - -}; - - -/* Runge Kutta Stepper - consisting of several stages */ - -template< typename State , size_t stage_count > -class runge_kutta_stepper -{ - - typedef State state_type; - typedef vector< vector< double > > parameter_array_type2D; - typedef vector< double > parameter_array_type1D; - - template< class System > - struct calculate_stage - { - System &system; - state_type &x , &x_tmp; - state_type *k_vector; - const double t; - const double dt; - const parameter_array_type2D &m_a; - const parameter_array_type1D &m_b; - const parameter_array_type1D &m_c; - - calculate_stage( System &_system , state_type &_x , state_type &_x_tmp , state_type *_k_vector , - const double _t , const double _dt , - const parameter_array_type2D &a , - const parameter_array_type1D &b , - const parameter_array_type1D &c ) - : system( _system ) , x( _x ) , x_tmp( _x_tmp ) , k_vector( _k_vector ) , t( _t ) , dt( _dt ), - m_a( a ) , m_b( b ) , m_c( c ) - {} - - template< class Stage > - void operator()( Stage &s ) - { - s.init( m_a , m_b , m_c ); - s( x_tmp , x , k_vector , t , dt ); - } - - }; - -public: - - typedef mpl::range_c< size_t , 1 , stage_count > indices; - typedef typename mpl::copy // create mpl::vector< stepper_stage< 0 >, stepper_stage< 1 > , .. stepper_stage< stage_count-1 > > - < - indices , - mpl::inserter - < - mpl::vector0<> , - stepper_stage< State , mpl::_2::value > - > - >::type stage_vector; - typedef stepper_last_stage< State , stage_count > last_stage_type; - - runge_kutta_stepper( const parameter_array_type2D &a , - const parameter_array_type1D &b , - const parameter_array_type1D &c ) - : m_a( a ) , m_b( b ) , m_c( c ) - { - last_stage.init( b , c ); - } - - template< class System > - void do_step( System &system , state_type &x , double t , const double dt ) - { - mpl::for_each< stage_vector >( calculate_stage< System >( system , x , m_x_tmp , m_k_vector , t , dt , - m_a , m_b , m_c ) ); - last_stage.do_step( system , m_x_tmp , x , m_k_vector , t , dt ); - } - -private: - - state_type m_k_vector[stage_count]; - state_type m_x_tmp; - last_stage_type last_stage; - const parameter_array_type2D &m_a; - const parameter_array_type1D &m_b; - const parameter_array_type1D &m_c; -}; - - -#endif /* GENERIC_STEPPER_HPP_ */ diff --git a/libs/numeric/odeint/ideas/generic_stepper/performance.cpp b/libs/numeric/odeint/ideas/generic_stepper/performance.cpp deleted file mode 100644 index 841ec08e..00000000 --- a/libs/numeric/odeint/ideas/generic_stepper/performance.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * performance.cpp - * - * Created on: Dec 1, 2010 - * Author: mario - */ - -/* - * butcher_test.cpp - * - * Created on: Nov 5, 2010 - * Author: karsten - */ - -#include -#include - -#include - -#include -#include -#include -#include - -#include "predefined_steppers.hpp" -#include "runge_kutta_stepper_fast.hpp" - -#define tab "\t" - -using namespace std; -using namespace boost::accumulators; - -typedef accumulator_set< - double , stats< tag::mean , tag::variance > - > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - -typedef boost::timer timer_type; - - -typedef boost::array< double , 3 > state_type; -typedef boost::numeric::odeint::explicit_rk4< state_type > rk4_odeint_type; -typedef mpl_rk4_stepper< state_type > rk4_mpl_type; -typedef runge_kutta_stepper< state_type , 4 > rk4_fusion_type; - - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - const double sigma = 10.0; - const double R = 28.0; - const double 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] = x[0]*x[1] - b * x[2]; -} - - - - -int main( int argc , char **argv ) -{ - rk4_odeint_type rk4_odeint; - rk4_mpl_type rk4_mpl; - - typedef rk4_fusion_type::coef_a_type coef_a_type; - typedef rk4_fusion_type::coef_b_type coef_b_type; - typedef rk4_fusion_type::coef_c_type coef_c_type; - - const boost::array< double , 1 > a1 = {{ 0.5 }}; - const boost::array< double , 2 > a2 = {{ 0.0 , 0.5 }}; - const boost::array< double , 3 > a3 = {{ 0.0 , 0.0 , 1.0 }}; - - const coef_a_type a = fusion::make_vector( a1 , a2 , a3 ); - const coef_b_type b = {{ 1.0/6 , 1.0/3 , 1.0/3 , 1.0/6 }}; - const coef_c_type c = {{ 0.0 , 0.5 , 0.5 , 1.0 }}; - - rk4_fusion_type rk4_fusion( a , b , c ); - - const size_t num_of_steps = 20000000; - const double dt = 0.01; - - accumulator_type acc1 , acc2 , acc3; - timer_type timer; - - srand48( 12312354 ); - - while( true ) - { - state_type x1 = {{ 10.0 * drand48() , 10.0 * drand48() , 10.0 * drand48() }}; - state_type x2 = x1; - state_type x3 = x1; - double t1 = 0.0 ; - double t2 = 0.0; - double t3 = 0.0; - - timer.restart(); - for( size_t i=0 ; i -#include - -#include - -#include -#include -#include - -#include "runge_kutta_stepper.hpp" - -#define tab "\t" - -using namespace std; -using namespace boost::accumulators; - -typedef accumulator_set< - double , stats< tag::mean , tag::variance > - > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - -typedef boost::timer timer_type; - - -typedef boost::array< double , 3 > state_type; -typedef runge_kutta_stepper< state_type , 4 > rk4_fusion_type; - - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - const double sigma = 10.0; - const double R = 28.0; - const double 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] = x[0]*x[1] - b * x[2]; -} - - - -int main( int argc , char **argv ) -{ - typedef rk4_fusion_type::coef_a_type coef_a_type; - typedef rk4_fusion_type::coef_b_type coef_b_type; - typedef rk4_fusion_type::coef_c_type coef_c_type; - - const boost::array< double , 1 > a1 = {{ 0.5 }}; - const boost::array< double , 2 > a2 = {{ 0.0 , 0.5 }}; - const boost::array< double , 3 > a3 = {{ 0.0 , 0.0 , 1.0 }}; - - const coef_a_type a = fusion::make_vector( a1 , a2 , a3 ); - const coef_b_type b = {{ 1.0/6 , 1.0/3 , 1.0/3 , 1.0/6 }}; - const coef_c_type c = {{ 0.0 , 0.5 , 0.5 , 1.0 }}; - - rk4_fusion_type rk4_fusion( a , b , c ); - - const size_t num_of_steps = 20000000; - const double dt = 0.01; - - accumulator_type acc; - timer_type timer; - - srand( 12312354 ); - - while( true ) - { - state_type x = {{ 10.0 * rand()/RAND_MAX , - 10.0 * rand()/RAND_MAX , - 10.0 * rand()/RAND_MAX }}; - double t = 0.0; - - timer.restart(); - for( size_t i=0 ; i -#include - -#include - -#include -#include -#include - -#include "predefined_steppers.hpp" - -#define tab "\t" - -using namespace std; -using namespace boost::accumulators; - -typedef accumulator_set< - double , stats< tag::mean , tag::variance > - > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - -typedef boost::timer timer_type; - - -typedef boost::array< double , 3 > state_type; -typedef mpl_rk4_stepper< state_type > rk4_mpl_type; - - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - const double sigma = 10.0; - const double R = 28.0; - const double 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] = x[0]*x[1] - b * x[2]; -} - - - - -int main( int argc , char **argv ) -{ - rk4_mpl_type rk4_mpl; - - const size_t num_of_steps = 20000000; - const double dt = 0.01; - - accumulator_type acc; - timer_type timer; - - srand48( 12312354 ); - - while( true ) - { - state_type x = {{ 10.0 * drand48() , 10.0 * drand48() , 10.0 * drand48() }}; - double t = 0.0; - - timer.restart(); - for( size_t i=0 ; i -#include - -#include - -#include -#include -#include -#include - -#define tab "\t" - -using namespace std; -using namespace boost::accumulators; - -typedef accumulator_set< - double , stats< tag::mean , tag::variance > - > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - -typedef boost::timer timer_type; - - -typedef boost::array< double , 3 > state_type; -typedef boost::numeric::odeint::explicit_rk4< state_type > rk4_odeint_type; - - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - const double sigma = 10.0; - const double R = 28.0; - const double 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] = x[0]*x[1] - b * x[2]; -} - - - - -int main( int argc , char **argv ) -{ - rk4_odeint_type rk4_odeint; - - const size_t num_of_steps = 20000000; - const double dt = 0.01; - - accumulator_type acc; - timer_type timer; - - srand( 12312354 ); - - while( true ) - { - state_type x = {{ 10.0 * rand()/RAND_MAX , - 10.0 * rand()/RAND_MAX , - 10.0 * rand()/RAND_MAX }}; - double t = 0.0; - - timer.restart(); - for( size_t i=0 ; i -#include - -#include - -#include "runge_kutta_stepper.hpp" - -using namespace std; - -namespace odeint = boost::numeric::odeint; - -typedef boost::array< double , 3 > state_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - -int main( int argc , char **argv ) -{ - typedef runge_kutta_stepper< state_type , 4 > rk_type; - typedef rk_type::coef_a_type coef_a_type; - typedef rk_type::coef_b_type coef_b_type; - typedef rk_type::coef_c_type coef_c_type; - - const boost::array< double , 1 > a1 = {{ 0.5 }}; - const boost::array< double , 2 > a2 = {{ 0.0 , 0.5 }}; - const boost::array< double , 3 > a3 = {{ 0.0 , 0.0 , 1.0 }}; - - const coef_a_type a = fusion::make_vector( a1 , a2 , a3 ); - const coef_b_type b = {{ 1.0/6 , 1.0/3 , 1.0/3 , 1.0/6 }}; - const coef_c_type c = {{ 0.0 , 0.5 , 0.5 , 1.0 }}; - - rk_type rk( a , b , c ); - rk.print_vals(); - - state_type x = {{ 1.0 , 1.0 , 2.0 }}; - double t = 0.0; - rk.do_step( lorenz , x , t , 0.1 ); - - cout.precision(16); - - cout << x[0] << " , " << x[1] << " , " << x[2] << endl; - - - odeint::explicit_rk4< state_type > rk4; - state_type x2 = {{ 1.0 , 1.0 , 2.0 }}; - rk4.do_step( lorenz , x2 , t , 0.1 ); - cout << x2[0] << " , " << x2[1] << " , " << x2[2] << endl; -} diff --git a/libs/numeric/odeint/ideas/generic_stepper/runge_kutta_stepper.hpp b/libs/numeric/odeint/ideas/generic_stepper/runge_kutta_stepper.hpp deleted file mode 100644 index c079b0fe..00000000 --- a/libs/numeric/odeint/ideas/generic_stepper/runge_kutta_stepper.hpp +++ /dev/null @@ -1,296 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - - -#include -#include -#include - -#include -#include - - -#include "fusion_algebra.hpp" - -namespace mpl = boost::mpl; -namespace fusion = boost::fusion; - -using namespace std; - - -struct first_stage {}; -struct intermediate_stage {}; -struct last_stage {}; - -ostream& operator<<( ostream& out , const first_stage& ) -{ - out << "first stage"; - return out; -} - -ostream& operator<<( ostream& out , const intermediate_stage& ) -{ - out << "intermediate stage"; - return out; -} - -ostream& operator<<( ostream& out , const last_stage& ) -{ - out << "last stage"; - return out; -} - - - -template< class T , class Constant > -struct array_wrapper -{ - typedef typename boost::array< T , Constant::value > type; -}; - -template< class T , class Constant , class StageCategory > -struct stage_fusion_wrapper -{ - typedef typename fusion::vector< size_t , T , boost::array< T , Constant::value > , StageCategory > type; -}; - -struct print_stage -{ - template< typename Stage > - void operator() ( const Stage &stage ) const - { - std::cout<< "stage: " << fusion::at_c<0>( stage ) << " c:" << fusion::at_c<1>( stage ) << " "; - for( size_t i=0 ; i < fusion::at_c<2>( stage ).size() ; ++i ) - std::cout << "a["<( stage )[i] << " "; - std::cout << std::endl; - } -}; - -struct print_sequence -{ - size_t m_indent; - - print_sequence( size_t indent = 0 ) - : m_indent( indent ) { } - - template< typename T > - void operator()( T ) const - { - string in; - for( size_t i=0 ; i - void operator()( const T &t ) const - { - typedef typename fusion::traits::is_sequence< T >::type seq_type; - print_val( t , seq_type() ); - } - - template< class R > - void print_val( const R &r , mpl::false_ ) const - { - string in; - for( size_t i=0 ; i - void print_val( const S &s , mpl::true_ ) const - { - fusion::for_each( s , print_values( m_indent + 1 ) ); - } -}; - - -template< class StateType , size_t stage_count > -class runge_kutta_stepper -{ - -public: - - typedef StateType state_type; - - typedef mpl::range_c< size_t , 1 , stage_count > stage_indices; - - typedef typename fusion::result_of::as_vector - < - typename mpl::copy - < - stage_indices , - mpl::inserter - < - mpl::vector0< > , - mpl::push_back< mpl::_1 , array_wrapper< double , mpl::_2 > > - > - >::type - >::type coef_a_type; - - typedef boost::array< double , stage_count > coef_b_type; - typedef boost::array< double , stage_count > coef_c_type; - - typedef typename fusion::result_of::as_vector - < - typename mpl::push_back - < - typename mpl::copy - < - stage_indices, - mpl::inserter - < - mpl::vector0<> , - mpl::push_back< mpl::_1 , stage_fusion_wrapper< double , mpl::_2 , intermediate_stage > > - > - >::type , - typename stage_fusion_wrapper< double , mpl::size_t< stage_count > , last_stage >::type - >::type - >::type stage_vector_base; - - - struct stage_vector : public stage_vector_base - { - struct do_insertion - { - stage_vector_base &m_base; - const coef_a_type &m_a; - const coef_c_type &m_c; - - do_insertion( stage_vector_base &base , const coef_a_type &a , const coef_c_type &c ) - : m_base( base ) , m_a( a ) , m_c( c ) { } - - template< class Index > - void operator()( Index ) const - { - fusion::at_c< 0 >( fusion::at< Index >( m_base ) ) = Index::value; - fusion::at_c< 1 >( fusion::at< Index >( m_base ) ) = m_c[ Index::value ]; - fusion::at_c< 2 >( fusion::at< Index >( m_base ) ) = fusion::at< Index >( m_a ); - } - }; - - stage_vector( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c ) - { - typedef mpl::range_c< size_t , 0 , stage_count - 1 > indices; - mpl::for_each< indices >( do_insertion( *this , a , c ) ); - fusion::at_c< 0 >( fusion::at_c< stage_count - 1 >( *this ) ) = stage_count - 1 ; - fusion::at_c< 1 >( fusion::at_c< stage_count - 1 >( *this ) ) = c[ stage_count - 1 ]; - fusion::at_c< 2 >( fusion::at_c< stage_count - 1 >( *this ) ) = b; - } - }; - - - - template< class System > - struct calculate_stage - { - System &system; - state_type &x , &x_tmp; - state_type *k_vector; - const double t; - const double dt; - - calculate_stage( System &_system , state_type &_x , state_type &_x_tmp , state_type *_k_vector , - const double _t , const double _dt ) - : system( _system ) , x( _x ) , x_tmp( _x_tmp ) , k_vector( _k_vector ) , t( _t ) , dt( _dt ) - {} - - - template< typename T , size_t stage_number > - void operator()( fusion::vector< size_t , T , boost::array< T , stage_number > , intermediate_stage > const &stage ) const - //typename stage_fusion_wrapper< T , mpl::size_t< stage_number > , intermediate_stage >::type const &stage ) const - { - double c = fusion::at_c< 1 >( stage ); - - if( stage_number == 1 ) - system( x , k_vector[stage_number-1] , t + c * dt ); - else - system( x_tmp , k_vector[stage_number-1] , t + c * dt ); - - fusion_algebra::foreach( x_tmp , x , fusion::at_c< 2 >( stage ) , k_vector , dt); - } - - - template< typename T , size_t stage_number > - void operator()( fusion::vector< size_t , T , boost::array< T , stage_number > , last_stage > const &stage ) const - //void operator()( typename stage_fusion_wrapper< T , mpl::size_t< stage_number > , last_stage >::type const &stage ) const - { - double c = fusion::at_c< 1 >( stage ); - - if( stage_number == 1 ) - system( x , k_vector[stage_number-1] , t + c * dt ); - else - system( x_tmp , k_vector[stage_number-1] , t + c * dt ); - - fusion_algebra::foreach( x , x , fusion::at_c< 2 >( stage ) , k_vector , dt); - } - - - }; - - - - -public: - - runge_kutta_stepper( const coef_a_type &a , - const coef_b_type &b , - const coef_c_type &c ) - : m_a( a ) , m_b( b ) , m_c( c ) , - m_stages( a , b , c ) - - { } - - - template< class System > - void do_step( System &system , state_type &x , double t , const double dt ) - { - fusion::for_each( m_stages , calculate_stage< System >( system , x , m_x_tmp , m_k_vector , t , dt ) ); - } - - - void print_vals() - { - cout << "Typeof state_vector_base : " << endl; - mpl::for_each< stage_vector_base >( print_sequence( 1 ) ); - - cout << "m_a : " << endl; - fusion::for_each( m_a , print_values( 1 ) ); - - cout << "m_b : " << endl; - fusion::for_each( m_b , print_values( 1 ) ); - - cout << "m_c : " << endl; - fusion::for_each( m_c , print_values( 1 ) ); - - cout << "m_stages : " << endl; - fusion::for_each( m_stages , print_values( 1 ) ); - } - - - -private: - - const coef_a_type m_a; - const coef_b_type m_b; - const coef_c_type m_c; - const stage_vector m_stages; - state_type m_x_tmp; - state_type m_k_vector[stage_count]; -}; diff --git a/libs/numeric/odeint/ideas/generic_stepper/runge_kutta_stepper_fast.hpp b/libs/numeric/odeint/ideas/generic_stepper/runge_kutta_stepper_fast.hpp deleted file mode 100644 index 32879c7f..00000000 --- a/libs/numeric/odeint/ideas/generic_stepper/runge_kutta_stepper_fast.hpp +++ /dev/null @@ -1,201 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - - -#include -#include -#include - -#include -#include - - -#include "fusion_algebra.hpp" - -namespace mpl = boost::mpl; -namespace fusion = boost::fusion; - -using namespace std; - - -struct first_stage {}; -struct intermediate_stage {}; -struct last_stage {}; - - -template< class T , class Constant > -struct array_wrapper -{ - typedef typename boost::array< T , Constant::value > type; -}; - -template< class T , class Constant , class StageCategory > -struct stage_fusion_wrapper -{ - typedef typename fusion::vector< size_t , T , boost::array< T , Constant::value > , StageCategory > type; -}; - -template< class StateType , size_t stage_count > -class runge_kutta_stepper -{ - -public: - - typedef StateType state_type; - - typedef mpl::range_c< size_t , 1 , stage_count > stage_indices; - - typedef typename fusion::result_of::as_vector - < - typename mpl::copy - < - stage_indices , - mpl::inserter - < - mpl::vector0< > , - mpl::push_back< mpl::_1 , array_wrapper< double , mpl::_2 > > - > - >::type - >::type coef_a_type; - - typedef boost::array< double , stage_count > coef_b_type; - typedef boost::array< double , stage_count > coef_c_type; - - typedef typename fusion::result_of::as_vector - < - typename mpl::push_back - < - typename mpl::copy - < - stage_indices, - mpl::inserter - < - mpl::vector0<> , - mpl::push_back< mpl::_1 , stage_fusion_wrapper< double , mpl::_2 , intermediate_stage > > - > - >::type , - typename stage_fusion_wrapper< double , mpl::size_t< stage_count > , last_stage >::type - >::type - >::type stage_vector_base; - - - struct stage_vector : public stage_vector_base - { - struct do_insertion - { - stage_vector_base &m_base; - const coef_a_type &m_a; - const coef_c_type &m_c; - - do_insertion( stage_vector_base &base , const coef_a_type &a , const coef_c_type &c ) - : m_base( base ) , m_a( a ) , m_c( c ) { } - - template< class Index > - void operator()( Index ) const - { - fusion::at_c< 0 >( fusion::at< Index >( m_base ) ) = Index::value; - fusion::at_c< 1 >( fusion::at< Index >( m_base ) ) = m_c[ Index::value ]; - fusion::at_c< 2 >( fusion::at< Index >( m_base ) ) = fusion::at< Index >( m_a ); - } - }; - - stage_vector( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c ) - { - typedef mpl::range_c< size_t , 0 , stage_count - 1 > indices; - mpl::for_each< indices >( do_insertion( *this , a , c ) ); - fusion::at_c< 0 >( fusion::at_c< stage_count - 1 >( *this ) ) = stage_count - 1 ; - fusion::at_c< 1 >( fusion::at_c< stage_count - 1 >( *this ) ) = c[ stage_count - 1 ]; - fusion::at_c< 2 >( fusion::at_c< stage_count - 1 >( *this ) ) = b; - } - }; - - - - template< class System > - struct calculate_stage - { - System &system; - state_type &x , &x_tmp; - state_type *k_vector; - const double t; - const double dt; - - calculate_stage( System &_system , state_type &_x , state_type &_x_tmp , state_type *_k_vector , - const double _t , const double _dt ) - : system( _system ) , x( _x ) , x_tmp( _x_tmp ) , k_vector( _k_vector ) , t( _t ) , dt( _dt ) - {} - - - template< typename T , const size_t stage_number > - inline void operator()( fusion::vector< size_t , T , boost::array< T , stage_number > , intermediate_stage > const &stage ) const - //typename stage_fusion_wrapper< T , mpl::size_t< stage_number > , intermediate_stage >::type const &stage ) const - { - const double c = fusion::at_c< 1 >( stage ); - - if( stage_number == 1 ) - system( x , k_vector[stage_number-1] , t + c * dt ); - else - system( x_tmp , k_vector[stage_number-1] , t + c * dt ); - - fusion_algebra::foreach( x_tmp , x , fusion::at_c< 2 >( stage ) , k_vector , dt); - } - - - template< typename T , const size_t stage_number > - inline void operator()( fusion::vector< size_t , T , boost::array< T , stage_number > , last_stage > const &stage ) const - //void operator()( typename stage_fusion_wrapper< T , mpl::size_t< stage_number > , last_stage >::type const &stage ) const - { - const double c = fusion::at_c< 1 >( stage ); - - if( stage_number == 1 ) - system( x , k_vector[stage_number-1] , t + c * dt ); - else - system( x_tmp , k_vector[stage_number-1] , t + c * dt ); - - fusion_algebra::foreach( x , x , fusion::at_c< 2 >( stage ) , k_vector , dt); - } - - - }; - - - - -public: - - runge_kutta_stepper( const coef_a_type &a , - const coef_b_type &b , - const coef_c_type &c ) - : m_a( a ) , m_b( b ) , m_c( c ) , - m_stages( a , b , c ) - - { } - - - template< class System > - inline void do_step( System &system , state_type &x , double t , const double dt ) - { - fusion::for_each( m_stages , calculate_stage< System >( system , x , m_x_tmp , m_k_vector , t , dt ) ); - } - - - - -private: - - const coef_a_type m_a; - const coef_b_type m_b; - const coef_c_type m_c; - const stage_vector m_stages; - state_type m_x_tmp; - state_type m_k_vector[stage_count]; -}; diff --git a/libs/numeric/odeint/ideas/generic_stepper/test.cpp b/libs/numeric/odeint/ideas/generic_stepper/test.cpp deleted file mode 100644 index b23231e3..00000000 --- a/libs/numeric/odeint/ideas/generic_stepper/test.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * test.cpp - * - * Created on: Nov 13, 2010 - * Author: mario - */ - -#include -#include -#include - -#include "fusion_stepper.hpp" - -using namespace std; - -typedef tr1::array< double , 3 > state_type; -typedef runge_kutta_stepper< state_type , 1 > euler_stepper; -typedef runge_kutta_stepper< state_type , 2 > midpoint_stepper; - - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - -const double dt = 0.001; - -int main( void ) -{ - vector< vector > a( 0, vector( 0 ) ); - vector< double > b( 1 , 1.0 ); - vector< double > c( 1 , 0.0 ); - euler_stepper euler( a , b , c ); - - vector< vector< double > > a2( 1 , vector( 1 , 0.5 ) ); - vector< double > b2( 2 , 0.0 ); b2[1] = 0.5; - vector< double > c2( 1 , 0.0 ); c2[1] = 1.0; - midpoint_stepper midpoint( a2 , b2 , c2 ); - - state_type x = {{ 1.0 , 1.0 , 2.0 }}; - state_type x2 = {{ 1.0 , 1.0 , 2.0 }}; - double t = 0.0; - euler.do_step( lorenz , x , t , dt ); - midpoint.do_step( lorenz , x2 , t , dt ); - - cout << x[0] << " , " << x[1] << " , " << x[2] << endl; - cout << x2[0] << " , " << x2[1] << " , " << x2[2] << endl; -} diff --git a/libs/numeric/odeint/ideas/odeint_ref_problem.cpp b/libs/numeric/odeint/ideas/odeint_ref_problem.cpp deleted file mode 100644 index 13c286a9..00000000 --- a/libs/numeric/odeint/ideas/odeint_ref_problem.cpp +++ /dev/null @@ -1,227 +0,0 @@ -//============================================================================ -// Name : odeint_ref_problem.cpp -// Author : Karsten Ahnert -// Version : -// Copyright : Your copyright notice -// Description : Hello World in C++, Ansi-style -//============================================================================ - -#include -#include -#include - -#include -#include - -#include -#include - -#include - -#include -//#include -//#include - - -#define tab "\t" - -using namespace std; - -typedef boost::accumulators::accumulator_set< - double , boost::accumulators::stats< - boost::accumulators::tag::mean , - boost::accumulators::tag::variance - > - > accumulator_type; - -typedef boost::timer timer_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << tab; -// out << boost::accumulators::variance( acc ) << tab; - return out; -} - - - - -class explicit_euler -{ -public: - - typedef double value_type; - typedef std::tr1::array< double , 3 > state_type; - typedef boost::function3< void , const state_type& , state_type& , value_type > func_type; - - void do_step( func_type system , state_type &x , value_type t , value_type dt ) - { - system( x , m_dxdt , t ); - for( size_t i=0 ; i state_type; - typedef boost::numeric::odeint::container_traits< state_type > traits_type; - - template< class System > - void do_step( System system , state_type &x , value_type t , value_type dt ) - { - typename boost::unwrap_reference< System >::type &sys = system; - sys( x , m_dxdt , t ); - // x = x + dt*dxdt - boost::numeric::odeint::detail::it_algebra::increment( - traits_type::begin(x) , - traits_type::end(x) , - traits_type::begin(m_dxdt) , - dt ); - }; - -private: - - state_type m_dxdt; -}; - - -typedef explicit_euler::value_type value_type; -typedef explicit_euler::state_type state_type; - -ostream& operator<<( ostream& out , const state_type &x ) -{ - out << x[0] << tab << x[1] << tab << x[2]; - return out; -} - -const value_type sigma = 10.0; -const value_type R = 28.0; -const value_type b = 8.0 / 3.0; - - -void lorenz( const state_type &x , state_type &dxdt , value_type t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - -struct lorenz_class -{ - void operator()( const state_type &x , state_type &dxdt , value_type t ) - { - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; - } -}; - - -int main() -{ - explicit_euler euler1; - boost::numeric::odeint::stepper_euler< state_type > euler2; - explicit_euler_2 euler3; - const value_type dt = 0.01; - lorenz_class lorenz_c; - - timer_type timer; - accumulator_type acc1 , acc2 , acc3 , acc4 , acc5 , acc6 , acc7 , acc8 , acc9 , acc10; - double elapsed; - const size_t num_of_steps = 1024 * 1024 * 32; - - while( true ) - { - state_type x = {{ drand48() , drand48() , drand48() }}; - state_type x1( x ) , x2( x ) , x3( x ) , x4( x ) , x5( x ) , x6( x ) , x7( x ) , x8( x ) , x9( x ) , x10( x ); - - timer.restart(); - for( size_t i = 0 ; i -struct operations_dispatcher -{ - typedef default_operations< Time > type; -}; - - -} // odeint -} // numeric -} // boost - - -#endif //BOOST_BOOST_NUMERIC_ODEINT_OPERATIONS_DISPATCHER_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/rosenbrock4/Jamfile b/libs/numeric/odeint/ideas/rosenbrock4/Jamfile deleted file mode 100644 index aec5a023..00000000 --- a/libs/numeric/odeint/ideas/rosenbrock4/Jamfile +++ /dev/null @@ -1,24 +0,0 @@ -# (C) Copyright 2010 : Karsten Ahnert, 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) - -import os ; -import modules ; -import path ; - -path-constant HOME : [ os.environ HOME ] ; -#path-constant CHRONO_ROOT : [ os.environ CHRONO_ROOT ] ; - -project - : requirements - BOOST_ALL_NO_LIB=1 - ../../../../.. - ; - -exe rosenbrock4 - : rosenbrock4.cpp - ; - -exe rosenbrock4_stepper - : rosenbrock4_stepper.cpp - ; \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/rosenbrock4/rosenbrock4.cpp b/libs/numeric/odeint/ideas/rosenbrock4/rosenbrock4.cpp deleted file mode 100644 index 0a9a4cd7..00000000 --- a/libs/numeric/odeint/ideas/rosenbrock4/rosenbrock4.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - * rosenbrock4.cpp - * - * Created on: Jan 9, 2011 - * Author: karsten - */ - -#include -#include -#include -#include - -#include "rosenbrock4.hpp" -#include -#include - -using namespace std; -using namespace boost::numeric::odeint; - -const static size_t dim = 3; -typedef double time_type; -typedef rosenbrock4< time_type > stepper_type; -typedef stepper_type::state_type state_type; -typedef stepper_type::matrix_type matrix_type; -typedef rosenbrock4_controller< time_type > controlled_stepper_type; - -//template< class StateType > -//void system( const StateType &x , StateType &dxdt , time_type t ) -//{ -// dxdt[0] = -0.013 * x[0] - 1000.0 * x[0] * x[2]; -// dxdt[1] = -2500.0 * x[1] * x[2]; -// dxdt[2] = -0.013 * x[0] - 1000.0 * x[0] * x[2] - 2500.0 * x[1] * x[2]; -//} -// -//void jacobi( const state_type &x , matrix_type &J , time_type t , state_type &dfdt ) -//{ -// J( 0 , 0 ) = -0.013 - 1000.0 * x[2]; -// J( 0 , 1 ) = 0.0; -// J( 0 , 2 ) = -1000.0 * x[0]; -// J( 1 , 0 ) = 0.0; -// J( 1 , 1 ) = -2500.0 * x[2]; -// J( 1 , 2 ) = -2500.0 * x[1]; -// J( 2 , 0 ) = -0.013 - 1000.0 * x[2]; -// J( 2 , 1 ) = -2500.0 * x[2]; -// J( 2 , 2 ) = -1000.0 * x[0] - 2500.0 * x[1]; -// -// dfdt[0] = 0.0; -// dfdt[1] = 0.0; -// dfdt[2] = 0.0; -//} - -const time_type sigma = 10.0; -const time_type R = 28.0; -const time_type b = 8.0 / 3.0; - -struct lorenz -{ - template< class StateType > - void operator()( const StateType &x , StateType &dxdt , time_type t ) - { - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0] * x[1] - b * x[2]; - } -}; - -struct jacobi -{ - void operator()( const state_type &x , matrix_type &J , time_type t , state_type &dfdt ) - { - J( 0 , 0 ) = -sigma; - J( 0 , 1 ) = sigma; - J( 0 , 2 ) = 0.0; - J( 1 , 0 ) = R - x[2]; - J( 1 , 1 ) = -1.0; - J( 1 , 2 ) = -x[0]; - J( 2 , 0 ) = x[1]; - J( 2 , 1 ) = x[0]; - J( 2 , 2 ) = -b; - - dfdt[0] = 0.0; - dfdt[1] = 0.0; - dfdt[2] = 0.0; - } -}; - - - -int main( int argc , char **argv ) -{ - if( true ) - { - state_type x( dim ) , xerr( dim ); - time_type t = 0.0 , dt = 0.00001; - - stepper_type stepper; - stepper.do_step( make_pair( lorenz() , jacobi() ) , x , t , dt , xerr ); - controlled_stepper_type controlled_stepper; - - x[0] = 1.0 ; x[1] = 1.0 ; x[2] = 0.0; - - ofstream fout( "dat/ross.dat" ); - size_t count = 0; - while( t < 50.0 ) - { -// clog << t << "\t" << dt << "\t" << controlled_stepper.last_error() << "\n"; - fout << t << "\t" << dt << "\t" << controlled_stepper.last_error() << "\t"; - fout << x[0] << "\t" << x[1] << "\t" << x[2] << "\t"; -// fout << xerr[0] << "\t" << xerr[1] << "\t" << xerr[2] << "\t"; - fout < state_type2; - typedef runge_kutta_cash_karp54_classic< state_type2 > stepper_type2; - typedef controlled_runge_kutta< stepper_type2 > controlled_stepper_type2; - stepper_type2 rk_stepper; - controlled_stepper_type2 stepper( rk_stepper ); - - state_type2 x = {{ 1.0 , 1.0 , 0.0 }}; - time_type t = 0.0 , dt = 0.00001; - ofstream fout( "dat/rk.dat" ); - size_t count = 0; - while( t < 50.0 ) - { - fout << t << "\t" << dt << "\t" << stepper.last_error() << "\t"; - fout << x[0] << "\t" << x[1] << "\t" << x[2] << "\t"; - fout < - -#include -#include -#include - -#include - - -namespace boost { -namespace numeric { -namespace odeint { - - -/* - * ToDo: - * - * 1. roll out parameters - * 2. how to call, with jacobi and system? - * 3. Introduce adjust size - * 4. Interfacing for odeint, check if controlled_error_stepper can be used - * 5. dense output - */ - -template< class Value > -class rosenbrock4 -{ -public: - - typedef Value value_type; - typedef boost::numeric::ublas::vector< value_type > state_type; - typedef state_type deriv_type; - typedef value_type time_type; - typedef boost::numeric::ublas::matrix< time_type > matrix_type; - typedef boost::numeric::ublas::permutation_matrix< size_t > pmatrix_type; - - rosenbrock4( void ) - { - } - - template< class System > - void do_step( System system , const state_type &x , time_type t , state_type &xout , time_type dt , state_type &xerr ) - { - const value_type gamma = 0.25; - const value_type d1 = 0.25 , d2 = -0.1043 , d3 = 0.1035 , d4 = 0.3620000000000023e-01; - const value_type c2 = 0.386 , c3 = 0.21 , c4 = 0.63; - const value_type c21 = -0.5668800000000000e+01; - const value_type a21 = 0.1544000000000000e+01; - const value_type c31 = -0.2430093356833875e+01 , c32 = -0.2063599157091915e+00; - const value_type a31 = 0.9466785280815826e+00 , a32 = 0.2557011698983284e+00; - const value_type c41 = -0.1073529058151375e+00 , c42 = -0.9594562251023355e+01 , c43 = -0.2047028614809616e+02; - const value_type a41 = 0.3314825187068521e+01 , a42 = 0.2896124015972201e+01 , a43 = 0.9986419139977817e+00; - const value_type c51 = 0.7496443313967647e+01 , c52 = -0.1024680431464352e+02 , c53 = -0.3399990352819905e+02 , c54 = 0.1170890893206160e+02; - const value_type a51 = 0.1221224509226641e+01 , a52 = 0.6019134481288629e+01 , a53 = 0.1253708332932087e+02 , a54 = -0.6878860361058950e+00 ; - const value_type c61 = 0.8083246795921522e+01 , c62 = -0.7981132988064893e+01 , c63 = -0.3152159432874371e+02 , c64 = 0.1631930543123136e+02 , c65 = -0.6058818238834054e+01; - - typedef typename boost::unwrap_reference< System >::type system_type; - typedef typename boost::unwrap_reference< typename system_type::first_type >::type deriv_func_type; - typedef typename boost::unwrap_reference< typename system_type::second_type >::type jacobi_func_type; - system_type &sys = system; - deriv_func_type &deriv_func = sys.first; - jacobi_func_type &jacobi_func = sys.second; - - - const size_t n = x.size(); - matrix_type jac( n , n ); - pmatrix_type pm( n ); - state_type dfdt( n ) , dxdt( n ); - deriv_func( x , dxdt , t ); - jacobi_func( x , jac , t , dfdt ); - - state_type g1( n ) , g2( n ) , g3( n ) , g4( n ) , g5( n ); - state_type xtmp( n ) , dxdtnew( n ); - - - jac *= -1.0; - jac += 1.0 / gamma / dt * boost::numeric::ublas::identity_matrix< time_type >( n ); - boost::numeric::ublas::lu_factorize( jac , pm ); - - for( size_t i=0 ; i - void do_step( System system , state_type &x , time_type t , time_type dt , state_type &xerr ) - { - do_step( system , x , t , x , dt , xerr ); - } - - -private: - -}; - - - -template< class Value > -class rosenbrock4_controller -{ -public: - - typedef Value time_type; - typedef boost::numeric::ublas::vector< time_type > state_type; - typedef boost::numeric::ublas::matrix< time_type > matrix_type; - typedef boost::numeric::ublas::permutation_matrix< size_t > pmatrix_type; - - rosenbrock4_controller( time_type atol = 1.0e-6 , time_type rtol = 1.0e-6 ) - : m_rb4() , m_atol( atol ) , m_rtol( rtol ) , - m_first_step( true ) , m_err_old( 0.0 ) , m_dt_old( 0.0 ) , - m_last_rejected( false ) - { - } - - time_type error( const state_type &x , const state_type &xold , const state_type &xerr ) - { - const size_t n = x.size(); - time_type err = 0.0 , sk = 0.0; - for( size_t i=0 ; i - boost::numeric::odeint::controlled_step_result - try_step( System sys , state_type &x , time_type &t , time_type &dt ) - { - static const time_type safe = 0.9 , fac1 = 5.0 , fac2 = 1.0 / 6.0; - - const size_t n = x.size(); - state_type xnew( n ) , xerr( n ); - m_rb4.do_step( sys , x , t , xnew , dt , xerr ); - time_type err = error( xnew , x , xerr ); - - time_type fac = std::max( fac2 ,std::min( fac1 , std::pow( err , 0.25 ) / safe ) ); - time_type dt_new = dt / fac; - if ( err <= 1.0 ) - { - if( m_first_step ) - { - m_first_step = false; - } - else - { - time_type fac_pred = ( m_dt_old / dt ) * pow( err * err / m_err_old , 0.25 ) / safe; - fac_pred = std::max( fac2 , std::min( fac1 , fac_pred ) ); - fac = std::max( fac , fac_pred ); - dt_new = dt / fac; - } - - m_dt_old = dt; - m_err_old = std::max( 0.01 , err ); - if( m_last_rejected ) - dt_new = ( dt >= 0.0 ? std::min( dt_new , dt ) : std::max( dt_new , dt ) ); - t += dt; - dt = dt_new; - m_last_rejected = false; - x = xnew; - return success_step_size_increased; - } - else - { - dt = dt_new; - m_last_rejected = true; - return step_size_decreased; - } - } - - - -private: - - rosenbrock4< time_type > m_rb4; - time_type m_atol , m_rtol; - bool m_first_step; - time_type m_err_old , m_dt_old; - bool m_last_rejected; -}; - - -} -} -} - - -#endif /* ROSENBROCK4_HPP_ */ diff --git a/libs/numeric/odeint/ideas/rosenbrock4/rosenbrock4_stepper.cpp b/libs/numeric/odeint/ideas/rosenbrock4/rosenbrock4_stepper.cpp deleted file mode 100644 index 6f4f961e..00000000 --- a/libs/numeric/odeint/ideas/rosenbrock4/rosenbrock4_stepper.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * rosenbrock4_stepper.cpp - * - * Created on: Jan 9, 2011 - * Author: karsten - */ - -#include -#include -#include -#include - -#include "rosenbrock4.hpp" -#include - -using namespace std; -using namespace boost::numeric::odeint; - -const static size_t dim = 3; -typedef double time_type; -typedef rosenbrock4< time_type > stepper_type; -typedef stepper_type::state_type state_type; -typedef stepper_type::matrix_type matrix_type; -typedef rosenbrock4_controller< time_type > controlled_stepper_type; - -//template< class StateType > -//void system( const StateType &x , StateType &dxdt , time_type t ) -//{ -// dxdt[0] = -0.013 * x[0] - 1000.0 * x[0] * x[2]; -// dxdt[1] = -2500.0 * x[1] * x[2]; -// dxdt[2] = -0.013 * x[0] - 1000.0 * x[0] * x[2] - 2500.0 * x[1] * x[2]; -//} -// -//void jacobi( const state_type &x , matrix_type &J , time_type t , state_type &dfdt ) -//{ -// J( 0 , 0 ) = -0.013 - 1000.0 * x[2]; -// J( 0 , 1 ) = 0.0; -// J( 0 , 2 ) = -1000.0 * x[0]; -// J( 1 , 0 ) = 0.0; -// J( 1 , 1 ) = -2500.0 * x[2]; -// J( 1 , 2 ) = -2500.0 * x[1]; -// J( 2 , 0 ) = -0.013 - 1000.0 * x[2]; -// J( 2 , 1 ) = -2500.0 * x[2]; -// J( 2 , 2 ) = -1000.0 * x[0] - 2500.0 * x[1]; -// -// dfdt[0] = 0.0; -// dfdt[1] = 0.0; -// dfdt[2] = 0.0; -//} - - -const time_type sigma = 10.0; -const time_type R = 28.0; -const time_type b = 8.0 / 3.0; - -struct lorenz -{ - template< class StateType > - void operator()( const StateType &x , StateType &dxdt , time_type t ) - { - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0] * x[1] - b * x[2]; - } -}; - -void jacobi( const state_type &x , matrix_type &J , time_type t , state_type &dfdt ) -{ - J( 0 , 0 ) = -sigma; - J( 0 , 1 ) = sigma; - J( 0 , 2 ) = 0.0; - J( 1 , 0 ) = R - x[2]; - J( 1 , 1 ) = -1.0; - J( 1 , 2 ) = -x[0]; - J( 2 , 0 ) = x[1]; - J( 2 , 1 ) = x[0]; - J( 2 , 2 ) = -b; - - dfdt[0] = 0.0; - dfdt[1] = 0.0; - dfdt[2] = 0.0; -} - - - -int main( int argc , char **argv ) -{ - const double dt = 0.01; - size_t steps = 1000; - double x0 = -12.0 , y0 = -12.0 , z0 = 20.0; - if( true ) - { - state_type x( dim ) , xerr( dim ); - time_type t = 0.0; - - stepper_type stepper; - x[0] = x0 ; x[1] = y0 ; x[2] = z0; - - ofstream fout( "dat/ross.dat" ); - fout.precision( 14 ); - size_t count = 0; - while( count < steps ) - { - fout << t << "\t"; - fout << x[0] << "\t" << x[1] << "\t" << x[2] << "\t"; - fout << xerr[0] << "\t" << xerr[1] << "\t" << xerr[2] << "\t"; - fout < state_type2; - typedef runge_kutta_cash_karp54_classic< state_type2 > stepper_type2; - stepper_type2 rk_stepper; - state_type2 x = {{ x0 , y0 , z0 }} , xerr = {{ 0.0 , 0.0 , 0.0 }}; - time_type t = 0.0; - - ofstream fout( "dat/rk.dat" ); - fout.precision( 14 ); - size_t count = 0; - while( count < steps ) - { - fout << t << "\t"; - fout << x[0] << "\t" << x[1] << "\t" << x[2] << "\t"; - fout << xerr[0] << "\t" << xerr[1] << "\t" << xerr[2] << "\t"; - fout <../../../../.. - ; - -lib libgsl : : gsl ; -lib libgslcblas : : gslcblas ; - -exe test_vector - : test_vector.cpp - ; - -exe test_gsl_vector - : test_gsl_vector.cpp libgsl libgslcblas - ; - -exe test_array - : test_array.cpp - ; \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp b/libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp deleted file mode 100644 index 5adc2237..00000000 --- a/libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp +++ /dev/null @@ -1,90 +0,0 @@ -#include - -#include - -#include -#include -#include -#include - - -template< class V , typename resizeable = typename boost::numeric::odeint::is_resizeable< V >::type> -struct state_wrapper; - -//two standard implementations, with and without resizing depending on is_resizeable< StateType > - -template< class V > -struct state_wrapper< V , boost::true_type > // with resizing -{ - typedef typename V::value_type value_type; - - V m_v; - - state_wrapper() : m_v() { } - - template< class StateIn > - bool same_size( const StateIn &x ) const - { - return ( boost::size( m_v ) == boost::size( x ) ); - } - - template< class StateIn > - void resize( const StateIn &x ) - { - m_v.resize( x.size() ); - } -}; - - -template< class V > -struct state_wrapper< V , boost::false_type > // without resizing -{ - typedef typename V::value_type value_type; - - V m_v; - - state_wrapper() : m_v() { } - - //no resize method -}; - - -template< typename StateType , class Resizer > -class explicit_euler { - -public: - - typedef double value_type; - typedef double time_type; - typedef StateType state_type; - typedef state_wrapper< state_type > wrapped_state_type; - typedef Resizer resizer_type; - - explicit_euler() : m_dxdt() , m_resizer() - { } - - template< class System , class StateInOut > - void do_step( System system , StateInOut &inout , const time_type &t , const time_type &dt ) - { - m_resizer.adjust_size( *this , inout ); - - system( inout , m_dxdt.m_v , t ); - - boost::numeric::odeint::range_algebra::for_each3( inout , inout , m_dxdt.m_v , typename boost::numeric::odeint::default_operations::template scale_sum2< value_type , time_type >( 1.0 , dt ) ); - } - - template< class State > - bool adjust_size( const State &x ) - { - if( m_dxdt.same_size( x ) ) - { - m_dxdt.resize( x ); - return true; - } else - return false; - } - -private: - wrapped_state_type m_dxdt; - resizer_type m_resizer; -}; diff --git a/libs/numeric/odeint/ideas/state_wrapper/size_adjuster.hpp b/libs/numeric/odeint/ideas/state_wrapper/size_adjuster.hpp deleted file mode 100644 index 4ffd8a3f..00000000 --- a/libs/numeric/odeint/ideas/state_wrapper/size_adjuster.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#include - - -template< class Stepper , class State > -bool adjust_size_by_resizeability( Stepper &stepper , const State &x , boost::true_type ) -{ - return stepper.adjust_size( x ); -} - -template< class Stepper , class State> -bool adjust_size_by_resizeability( Stepper &stepper , const State &x , boost::false_type ) -{ - return false; -} - -struct always_resizer -{ - - template< class Stepper , class State > - bool adjust_size( Stepper& stepper, const State &x ) - { - return adjust_size_by_resizeability( stepper , x , typename boost::numeric::odeint::is_resizeable< State >::type() ); - stepper.resize( x ); - } - -}; - - -struct initially_resizer -{ - bool m_initialized; - - initially_resizer(): m_initialized( false ) - { } - - template< class Stepper , class State > - bool adjust_size( Stepper& stepper, const State &x ) - { - if( !m_initialized ) - { - m_initialized = true; - return adjust_size_by_resizeability( stepper , x , typename boost::numeric::odeint::is_resizeable< State >::type() ); - } - return false; - } -}; - - -struct never_resizer -{ - template< class Stepper , class State > - void adjust_size( Stepper& stepper, const State &x ) - { } -}; diff --git a/libs/numeric/odeint/ideas/state_wrapper/test_array.cpp b/libs/numeric/odeint/ideas/state_wrapper/test_array.cpp deleted file mode 100644 index 5950d599..00000000 --- a/libs/numeric/odeint/ideas/state_wrapper/test_array.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include - -#include "euler.hpp" -#include "size_adjuster.hpp" - -using namespace std; - -typedef boost::array< double , 3 > state_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - -int main() -{ - explicit_euler< state_type , initially_resizer > euler; - //you would use never_resizer for arrays, but just to show that no resizing is called - //even with initially_resizer I use this one here. - - state_type x; - x[0] = 1.0; x[1] = 1.0; x[2] = 2.0; - - euler.do_step( lorenz , x , 0.0 , 0.1 ); - - cout << x[0] << " " << x[1] << " " << x[2] << endl; -} diff --git a/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp b/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp deleted file mode 100644 index a8cae2db..00000000 --- a/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include - -#include "euler.hpp" -#include "size_adjuster.hpp" - -using namespace std; - -typedef gsl_vector* state_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type x , state_type dxdt , double t ) -{ - gsl_vector_set( dxdt , 0 , sigma * ( gsl_vector_get(x , 1 ) - gsl_vector_get( x , 0 ) ) ); - gsl_vector_set( dxdt , 1 , R * gsl_vector_get( x , 0 ) - gsl_vector_get( x , 1 ) - gsl_vector_get( x , 0 ) * gsl_vector_get( x , 2) ); - gsl_vector_set( dxdt , 2 , gsl_vector_get( x , 0 ) * gsl_vector_get( x , 1 ) - b * gsl_vector_get( x , 2) ); -} - -template<> -struct state_wrapper< state_type > -{ - typedef double value_type; - - state_type m_v; - - state_wrapper( ) - { - m_v = gsl_vector_alloc( 1 ); - } - - ~state_wrapper() - { - gsl_vector_free( m_v ); - } - - bool same_size( const gsl_vector *x ) - { - return ( m_v->size == x->size ); - } - - void resize( const gsl_vector *x ) - { - if( x->size == 0 ) return; - - gsl_vector_free( m_v ); - m_v = gsl_vector_alloc( x->size ); - } - -}; - -int main() { - - explicit_euler< state_type , initially_resizer > euler; - - state_type x = gsl_vector_alloc( 3 ); - gsl_vector_set( x , 0 , 1.0); - gsl_vector_set( x , 1 , 1.0); - gsl_vector_set( x , 2 , 2.0); - - euler.do_step( lorenz , x , 0.0 , 0.1 ); - - cout << gsl_vector_get( x , 0 ) << " " << gsl_vector_get( x , 1 ) << " " << gsl_vector_get( x , 2 ) << endl; - - gsl_vector_free( x ); -} diff --git a/libs/numeric/odeint/ideas/state_wrapper/test_vector.cpp b/libs/numeric/odeint/ideas/state_wrapper/test_vector.cpp deleted file mode 100644 index 9a085dae..00000000 --- a/libs/numeric/odeint/ideas/state_wrapper/test_vector.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include - -#include "euler.hpp" -#include "size_adjuster.hpp" - -using namespace std; - -typedef vector< double > state_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - -int main() -{ - explicit_euler< state_type , initially_resizer > euler; - - state_type x(3); - x[0] = 1.0; x[1] = 1.0; x[2] = 2.0; - - euler.do_step( lorenz , x , 0.0 , 0.1 ); - - cout << x[0] << " " << x[1] << " " << x[2] << endl; -} diff --git a/libs/numeric/odeint/ideas/taylor/Notes b/libs/numeric/odeint/ideas/taylor/Notes deleted file mode 100644 index f754df6e..00000000 --- a/libs/numeric/odeint/ideas/taylor/Notes +++ /dev/null @@ -1,36 +0,0 @@ -Version 1: - -* Done -* Use contexts - - -Version 2: - -* Done -* Requiremnts: - * Solve Lorenz with help of transforms and compare performance with Version 1 - -Version 3: - -* Requirements: - * Optimize a * x - * Optimize a + x - - -Version 4: - - * Optimize x * y - * Optimize g(x) - -* Ansatz : - * mult< terminal< double >( a ) , expr > to mult_scalar< expr )( a ) - * plus< terminal< double >( a ) , expr > to shift_scalar< expr )( a ) - * mult< expr1 , expr2 > to mult_leibnitz< expr1 , expr2 > - * unary_op< expr > to unary_op_faa_di_bruno_bruno< expr > - -* Possible solutions : - * Proto transform to create - deriv[which] = deriv_transform()( expr , x , derivs , which ); - * custom eval context to create - deriv[which] = proto::eval( expr , my_context( x , derivs , which ) ); - * start with 1D Odes \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/taylor/lorenz.nb b/libs/numeric/odeint/ideas/taylor/lorenz.nb deleted file mode 100644 index 4da277a3..00000000 --- a/libs/numeric/odeint/ideas/taylor/lorenz.nb +++ /dev/null @@ -1,474 +0,0 @@ -(* Content-type: application/mathematica *) - -(*** Wolfram Notebook File ***) -(* http://www.wolfram.com/nb *) - -(* CreatedBy='Mathematica 7.0' *) - -(*CacheID: 234*) -(* Internal cache information: -NotebookFileLineBreakTest -NotebookFileLineBreakTest -NotebookDataPosition[ 145, 7] -NotebookDataLength[ 14490, 465] -NotebookOptionsPosition[ 13070, 414] -NotebookOutlinePosition[ 13407, 429] -CellTagsIndexPosition[ 13364, 426] -WindowFrame->Normal*) - -(* Beginning of Notebook Content *) -Notebook[{ -Cell[BoxData[{ - RowBox[{ - RowBox[{"\[Sigma]", "=", "10"}], ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"R", "=", "28"}], ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"b", "=", - RowBox[{"8", "/", "3"}]}], ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"fx", "[", "t_", "]"}], ":=", - RowBox[{"\[Sigma]", - RowBox[{"(", - RowBox[{ - RowBox[{"y", "[", "t", "]"}], "-", - RowBox[{"x", "[", "t", "]"}]}], ")"}]}]}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"fy", "[", "t_", "]"}], ":=", - RowBox[{ - RowBox[{"R", " ", - RowBox[{"x", "[", "t", "]"}]}], "-", - RowBox[{"y", "[", "t", "]"}], "-", - RowBox[{ - RowBox[{"x", "[", "t", "]"}], " ", - RowBox[{"z", "[", "t", "]"}]}]}]}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"fz", "[", "t_", "]"}], ":=", - RowBox[{ - RowBox[{ - RowBox[{"x", "[", "t", "]"}], - RowBox[{"y", "[", "t", "]"}]}], "-", - RowBox[{"b", " ", - RowBox[{"z", "[", "t", "]"}]}]}]}]}], "Input", - CellChangeTimes->{{3.510824673195559*^9, 3.5108246955668364`*^9}, { - 3.510824728655014*^9, 3.510824774844098*^9}}], - -Cell[BoxData[ - RowBox[{ - RowBox[{"vec", "=", - RowBox[{"{", - RowBox[{ - RowBox[{"fx", "[", "t", "]"}], ",", - RowBox[{"fy", "[", "t", "]"}], ",", - RowBox[{"fz", "[", "t", "]"}]}], "}"}]}], ";"}]], "Input", - CellChangeTimes->{{3.5108247955762157`*^9, 3.510824808339299*^9}}], - -Cell[CellGroupData[{ - -Cell[BoxData[ - RowBox[{"dx", "=", - RowBox[{ - RowBox[{ - RowBox[{"vec", "/.", - RowBox[{ - RowBox[{"x", "[", "t", "]"}], "\[Rule]", "10"}]}], "/.", - RowBox[{ - RowBox[{"y", "[", "t", "]"}], "\[Rule]", "10"}]}], "/.", - RowBox[{ - RowBox[{"z", "[", "t", "]"}], "\[Rule]", "10"}]}]}]], "Input", - CellChangeTimes->{{3.5108248103120823`*^9, 3.510824843576672*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{"0", ",", "170", ",", - FractionBox["220", "3"]}], "}"}]], "Output", - CellChangeTimes->{3.510824811744413*^9, 3.510824844343238*^9, - 3.513935237148198*^9}] -}, Open ]], - -Cell[CellGroupData[{ - -Cell[BoxData[ - RowBox[{"ddx", "=", - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{"D", "[", - RowBox[{"vec", ",", "t"}], "]"}], "/.", - RowBox[{ - RowBox[{"x", "[", "t", "]"}], "\[Rule]", "10"}]}], "/.", - RowBox[{ - RowBox[{"y", "[", "t", "]"}], "\[Rule]", "10"}]}], "/.", - RowBox[{ - RowBox[{"z", "[", "t", "]"}], "\[Rule]", "10"}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"x", "'"}], "[", "t", "]"}], "\[Rule]", "0"}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"y", "'"}], "[", "t", "]"}], "\[Rule]", "170"}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"z", "'"}], "[", "t", "]"}], "\[Rule]", - RowBox[{"220", "/", "3"}]}]}]}]], "Input", - CellChangeTimes->{{3.510824847695149*^9, 3.510824889430078*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{"1700", ",", - RowBox[{"-", - FractionBox["2710", "3"]}], ",", - FractionBox["13540", "9"]}], "}"}]], "Output", - CellChangeTimes->{{3.510824862798667*^9, 3.510824892253048*^9}, - 3.513935237968691*^9}] -}, Open ]], - -Cell[CellGroupData[{ - -Cell[BoxData[ - RowBox[{"dddx", "=", - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{"D", "[", - RowBox[{"vec", ",", - RowBox[{"{", - RowBox[{"t", ",", "2"}], "}"}]}], "]"}], "/.", - RowBox[{ - RowBox[{"x", "[", "t", "]"}], "\[Rule]", "10"}]}], "/.", - RowBox[{ - RowBox[{"y", "[", "t", "]"}], "\[Rule]", "10"}]}], "/.", - RowBox[{ - RowBox[{"z", "[", "t", "]"}], "\[Rule]", "10"}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"x", "'"}], "[", "t", "]"}], "\[Rule]", "0"}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"y", "'"}], "[", "t", "]"}], "\[Rule]", "170"}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"z", "'"}], "[", "t", "]"}], "\[Rule]", - RowBox[{"220", "/", "3"}]}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"x", "''"}], "[", "t", "]"}], "\[Rule]", "1700"}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"y", "''"}], "[", "t", "]"}], "\[Rule]", - RowBox[{ - RowBox[{"-", "2710"}], "/", "3"}]}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"z", "''"}], "[", "t", "]"}], "\[Rule]", - RowBox[{"13540", "/", "9"}]}]}]}]], "Input", - CellChangeTimes->{{3.5108248942284517`*^9, 3.510824926935175*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{ - RowBox[{"-", - FractionBox["78100", "3"]}], ",", - FractionBox["148130", "9"], ",", - FractionBox["106780", "27"]}], "}"}]], "Output", - CellChangeTimes->{3.510824928988983*^9, 3.513935238940962*^9}] -}, Open ]], - -Cell[CellGroupData[{ - -Cell[BoxData[ - RowBox[{"ddddx", "=", - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{"D", "[", - RowBox[{"vec", ",", - RowBox[{"{", - RowBox[{"t", ",", "3"}], "}"}]}], "]"}], "/.", - RowBox[{ - RowBox[{"x", "[", "t", "]"}], "\[Rule]", "10"}]}], "/.", - RowBox[{ - RowBox[{"y", "[", "t", "]"}], "\[Rule]", "10"}]}], "/.", - RowBox[{ - RowBox[{"z", "[", "t", "]"}], "\[Rule]", "10"}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"x", "'"}], "[", "t", "]"}], "\[Rule]", "0"}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"y", "'"}], "[", "t", "]"}], "\[Rule]", "170"}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"z", "'"}], "[", "t", "]"}], "\[Rule]", - RowBox[{"220", "/", "3"}]}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"x", "''"}], "[", "t", "]"}], "\[Rule]", "1700"}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"y", "''"}], "[", "t", "]"}], "\[Rule]", - RowBox[{ - RowBox[{"-", "2710"}], "/", "3"}]}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"z", "''"}], "[", "t", "]"}], "\[Rule]", - RowBox[{"13540", "/", "9"}]}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"x", "'''"}], "[", "t", "]"}], "\[Rule]", - RowBox[{ - RowBox[{"-", "78100"}], "/", "3"}]}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"y", "'''"}], "[", "t", "]"}], "\[Rule]", - RowBox[{"148130", "/", "9"}]}]}], "/.", - RowBox[{ - RowBox[{ - RowBox[{"z", "'''"}], "[", "t", "]"}], "\[Rule]", - RowBox[{"106780", "/", "27"}]}]}]}]], "Input", - CellChangeTimes->{{3.513935187550949*^9, 3.513935230954701*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{ - FractionBox["3824300", "9"], ",", - RowBox[{"-", - FractionBox["24262390", "27"]}], ",", - FractionBox["61617460", "81"]}], "}"}]], "Output", - CellChangeTimes->{{3.513935233233439*^9, 3.513935239844738*^9}}] -}, Open ]], - -Cell[CellGroupData[{ - -Cell[BoxData[{ - RowBox[{"N", "[", "dx", "]"}], "\[IndentingNewLine]", - RowBox[{"N", "[", "ddx", "]"}], "\[IndentingNewLine]", - RowBox[{"N", "[", "dddx", "]"}], "\[IndentingNewLine]", - RowBox[{"N", "[", "ddddx", "]"}]}], "Input", - CellChangeTimes->{{3.510824932150373*^9, 3.510824938416258*^9}, { - 3.513935242881462*^9, 3.513935243956193*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{"0.`", ",", "170.`", ",", "73.33333333333333`"}], "}"}]], "Output", - CellChangeTimes->{3.510824939061275*^9, 3.5139352446122847`*^9}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{"1700.`", ",", - RowBox[{"-", "903.3333333333334`"}], ",", "1504.4444444444443`"}], - "}"}]], "Output", - CellChangeTimes->{3.510824939061275*^9, 3.513935244616696*^9}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{ - RowBox[{"-", "26033.333333333332`"}], ",", "16458.88888888889`", ",", - "3954.814814814815`"}], "}"}]], "Output", - CellChangeTimes->{3.510824939061275*^9, 3.513935244620942*^9}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{"424922.22222222225`", ",", - RowBox[{"-", "898607.0370370371`"}], ",", "760709.3827160494`"}], - "}"}]], "Output", - CellChangeTimes->{3.510824939061275*^9, 3.513935244625566*^9}] -}, Open ]], - -Cell[CellGroupData[{ - -Cell[BoxData[{ - RowBox[{ - RowBox[{"dt", "=", "1"}], ";"}], "\[IndentingNewLine]", - RowBox[{"dx1", "=", - RowBox[{"dt", " ", "dx"}]}], "\[IndentingNewLine]", - RowBox[{"ddx1", "=", - RowBox[{ - RowBox[{ - RowBox[{"dt", "^", "2"}], "/", "2"}], "ddx"}]}], "\[IndentingNewLine]", - RowBox[{"dddx1", "=", - RowBox[{ - RowBox[{ - RowBox[{"dt", "^", "3"}], "/", - RowBox[{"3", "!"}]}], "dddx"}]}], "\[IndentingNewLine]", - RowBox[{"ddddx1", "=", - RowBox[{ - RowBox[{ - RowBox[{"dt", "^", "4"}], "/", - RowBox[{"4", "!"}]}], "ddddx"}]}]}], "Input", - CellChangeTimes->{{3.5108251832490597`*^9, 3.510825322790757*^9}, { - 3.510825737885933*^9, 3.510825758949971*^9}, {3.510825802567717*^9, - 3.510825805399754*^9}, {3.5139352586584597`*^9, 3.513935304517981*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{"0", ",", "170", ",", - FractionBox["220", "3"]}], "}"}]], "Output", - CellChangeTimes->{{3.510825209963582*^9, 3.5108252877049*^9}, - 3.510825323504698*^9, 3.510825760025854*^9, 3.510825805994877*^9, { - 3.5139352825257673`*^9, 3.5139353051164513`*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{"850", ",", - RowBox[{"-", - FractionBox["1355", "3"]}], ",", - FractionBox["6770", "9"]}], "}"}]], "Output", - CellChangeTimes->{{3.510825209963582*^9, 3.5108252877049*^9}, - 3.510825323504698*^9, 3.510825760025854*^9, 3.510825805994877*^9, { - 3.5139352825257673`*^9, 3.513935305122323*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{ - RowBox[{"-", - FractionBox["39050", "9"]}], ",", - FractionBox["74065", "27"], ",", - FractionBox["53390", "81"]}], "}"}]], "Output", - CellChangeTimes->{{3.510825209963582*^9, 3.5108252877049*^9}, - 3.510825323504698*^9, 3.510825760025854*^9, 3.510825805994877*^9, { - 3.5139352825257673`*^9, 3.5139353051274033`*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{ - FractionBox["956075", "54"], ",", - RowBox[{"-", - FractionBox["12131195", "324"]}], ",", - FractionBox["15404365", "486"]}], "}"}]], "Output", - CellChangeTimes->{{3.510825209963582*^9, 3.5108252877049*^9}, - 3.510825323504698*^9, 3.510825760025854*^9, 3.510825805994877*^9, { - 3.5139352825257673`*^9, 3.5139353051323833`*^9}}] -}, Open ]], - -Cell[CellGroupData[{ - -Cell[BoxData[{ - RowBox[{"N", "[", - RowBox[{"dx1", ",", "20"}], "]"}], "\[IndentingNewLine]", - RowBox[{"N", "[", - RowBox[{"ddx1", ",", "20"}], "]"}], "\[IndentingNewLine]", - RowBox[{"N", "[", - RowBox[{"dddx1", ",", "20"}], "]"}], "\[IndentingNewLine]", - RowBox[{"N", "[", - RowBox[{"ddddx1", ",", "20"}], "]"}]}], "Input", - CellChangeTimes->{{3.5108252915121098`*^9, 3.510825294371749*^9}, { - 3.510825326753573*^9, 3.5108253314518747`*^9}, {3.513935286019421*^9, - 3.513935289521921*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{ - "0", ",", "170.`20.", ",", - "73.33333333333333333333333333333333333333`20."}], "}"}]], "Output", - CellChangeTimes->{ - 3.510825295082189*^9, 3.510825332149527*^9, 3.510825761579811*^9, - 3.510825806943115*^9, {3.513935290210574*^9, 3.513935306844468*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{"850.`20.", ",", - RowBox[{"-", "451.66666666666666666666666666666666666667`20."}], ",", - "752.22222222222222222222222222222222222222`20."}], "}"}]], "Output", - CellChangeTimes->{ - 3.510825295082189*^9, 3.510825332149527*^9, 3.510825761579811*^9, - 3.510825806943115*^9, {3.513935290210574*^9, 3.513935306849414*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{ - RowBox[{"-", "4338.88888888888888888888888888888888888889`20."}], ",", - "2743.14814814814814814814814814814814814815`20.", ",", - "659.13580246913580246913580246913580246914`20."}], "}"}]], "Output", - CellChangeTimes->{ - 3.510825295082189*^9, 3.510825332149527*^9, 3.510825761579811*^9, - 3.510825806943115*^9, {3.513935290210574*^9, 3.513935306853644*^9}}], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{"17705.09259259259259259259259259259259259259`20.", ",", - RowBox[{"-", "37441.95987654320987654320987654320987654321`20."}], ",", - "31696.22427983539094650205761316872427983539`20."}], "}"}]], "Output", - CellChangeTimes->{ - 3.510825295082189*^9, 3.510825332149527*^9, 3.510825761579811*^9, - 3.510825806943115*^9, {3.513935290210574*^9, 3.513935306892515*^9}}] -}, Open ]] -}, -WindowSize->{640, 750}, -WindowMargins->{{146, Automatic}, {Automatic, 2}}, -FrontEndVersion->"7.0 for Linux x86 (64-bit) (November 11, 2008)", -StyleDefinitions->"Default.nb" -] -(* End of Notebook Content *) - -(* Internal cache information *) -(*CellTagsOutline -CellTagsIndex->{} -*) -(*CellTagsIndex -CellTagsIndex->{} -*) -(*NotebookFileOutline -Notebook[{ -Cell[545, 20, 1090, 33, 143, "Input"], -Cell[1638, 55, 292, 8, 32, "Input"], -Cell[CellGroupData[{ -Cell[1955, 67, 384, 11, 32, "Input"], -Cell[2342, 80, 198, 5, 46, "Output"] -}, Open ]], -Cell[CellGroupData[{ -Cell[2577, 90, 830, 26, 32, "Input"], -Cell[3410, 118, 249, 7, 46, "Output"] -}, Open ]], -Cell[CellGroupData[{ -Cell[3696, 130, 1387, 43, 32, "Input"], -Cell[5086, 175, 248, 7, 46, "Output"] -}, Open ]], -Cell[CellGroupData[{ -Cell[5371, 187, 1958, 59, 143, "Input"], -Cell[7332, 248, 257, 7, 46, "Output"] -}, Open ]], -Cell[CellGroupData[{ -Cell[7626, 260, 346, 6, 99, "Input"], -Cell[7975, 268, 172, 3, 31, "Output"], -Cell[8150, 273, 209, 5, 31, "Output"], -Cell[8362, 280, 222, 5, 31, "Output"], -Cell[8587, 287, 221, 5, 31, "Output"] -}, Open ]], -Cell[CellGroupData[{ -Cell[8845, 297, 777, 21, 121, "Input"], -Cell[9625, 320, 297, 6, 46, "Output"], -Cell[9925, 328, 341, 8, 46, "Output"], -Cell[10269, 338, 371, 9, 46, "Output"], -Cell[10643, 349, 381, 9, 46, "Output"] -}, Open ]], -Cell[CellGroupData[{ -Cell[11061, 363, 499, 11, 99, "Input"], -Cell[11563, 376, 302, 7, 31, "Output"], -Cell[11868, 385, 364, 7, 52, "Output"], -Cell[12235, 394, 408, 8, 31, "Output"], -Cell[12646, 404, 408, 7, 31, "Output"] -}, Open ]] -} -] -*) - -(* End of internal cache information *) diff --git a/libs/numeric/odeint/ideas/taylor/lorenz_special/lorenz_original.f b/libs/numeric/odeint/ideas/taylor/lorenz_special/lorenz_original.f deleted file mode 100644 index c3a9c58c..00000000 --- a/libs/numeric/odeint/ideas/taylor/lorenz_special/lorenz_original.f +++ /dev/null @@ -1,140 +0,0 @@ - IMPLICIT REAL*8 (A-H,O-Z) - call sections - stop - end - - Subroutine SECTIONS - IMPLICIT REAL*8 (A-H,O-Z) - real*8 AX(77777),AY(77777),AZ(77777),AT(77777) - DIMENSION DX(0:40),DY(0:40),DZ(0:40) -C This subroutine provides the values of consecutive -c intersection coordinates of the solution of the Lorenz equations -c with the plane Z=const -c (keeping them in the arrays AX and AY). Array DT contains the -c time values at the moments of intersections. -c These data are written into the file 'lorsec.dat' - - COMMON /ST/ DX,DY,DZ,Q,NO - open(9,file='lorsec.dat',status='unknown',access='sequential', - : form='formatted') -C Introduce the parameters: - P=10.d0 - B=8.d0/3.d0 - R=28.d0 -C Insert the initial point: - write(*,"(' Initial X ? '$)") - read*,x - write(*,"(' Initial Y ? '$)") - read*,y - write(*,"(' Initial Z ? '$)") - read*,z - t=0 -C Insert the desired number of the Poincare sections - write(*,"(' How many section points to find ? '$)") - read*,JSECT - isect=0 -C Insert the coordinate Z of the section plane - write(*,"(' Coordinate Z of the secant plane = ? '$)") - read*,zsect - 10 xp=x - yp=y - zp=z - call step (P,R,B,X,Y,Z,DT) - jjj=jjj+1 - T=T+DT - IF(z.lt.zsect.and.zp.ge.zsect)then -C computation of the section coordinates - td=0 - tu=DT/q - 12 tt=td+0.5d0*(tu-td) - QZ=0. - DO I=0,NO-1 - QZ=(QZ+DZ(NO-I))*tt - ENDDO - if(zp+QZ.gt.zsect)td=tt - if(zp+QZ.le.zsect)tU=tt - if(tu-td.Gt.1.d-10*DT/Q)goto 12 - QX=0. - QY=0. - DO I=0,NO-1 - QX=(QX+DX(NO-I))*tt - QY=(QY+DY(NO-I))*tt - ENDDO - isect=isect+1 - ax(isect)=xp+qx - ay(isect)=yp+qy - at(isect)=T-DT+tt*Q - write(9,'(i10,3f20.11)') isect,ax(isect),ay(isect),at(isect) - if(jsect/20*(20*isect/jsect).eq.isect) - : write(*,"(i3,'%'$)")100*isect/jsect - ENDIF - if(isect.lt.jsect)goto 10 - print*,'ready' - close(9) - return - end - - subroutine step (P,R,B,X,Y,Z,DT) -c This subroutine performs one integration step for the Lorenz -c equations by integrating them with the method of order NO, -c and relative error TO. Here P,R and B are the usual parameters -c of the Lorenz equations. The input values of X,Y,Z are the current -c values of the respective variables; as the output values they -c contain the new values. The neccesary stepsize is computed -c automatically and can be recovered from the output value DT. - IMPLICIT REAL*8 (A-H,O-Z) - DIMENSION DX(0:40),DY(0:40),DZ(0:40) - COMMON /ST/ DX,DY,DZ,Q,NO - DATA Q/1.d0/ - TO=1.D-17 - NO=25 - DX(0)=X - DY(0)=Y - DZ(0)=Z - Q1=1. - DO 19 ND=1,NO - DXY=0 - DXZ=0 - ND1=ND-1 - QQ=Q/ND - DO I=0,ND1 - DXY=DXY+DX(I)*DY(ND1-I) - DXZ=DXZ+DX(I)*DZ(ND1-I) - enddo - DX(ND)=P*(DY(ND1)-DX(ND1))*QQ - DY(ND)=(R*DX(ND1)-DY(ND1)-DXZ)*QQ - DZ(ND)=(DXY-B*DZ(ND1))*QQ - 13 Q1=1. - Q2=DABS(DX(ND))+DABS(DY(ND))+DABS(DZ(ND)) - IF(Q2.LT.1.D-19)Q1=1.5 - IF(Q2.GT.1.D19)Q1=0.6 - IF(Q1.LT.0.95.OR.Q1.GT.1.05)THEN - Q2=Q1 - DO M=1,ND - DX(M)=DX(M)*Q2 - DY(M)=DY(M)*Q2 - DZ(M)=DZ(M)*Q2 - Q2=Q2*Q1 - enddo - Q=Q*Q1 - GOTO 13 - ENDIF - 19 CONTINUE - EX=DABS(DX(NO))/(DABS(X)+1.D-35) - EY=DABS(DY(NO))/(DABS(Y)+1.D-35) - EZ=DABS(DZ(NO))/(DABS(Z)+1.D-35) - DT=(TO/DMAX1(EX,EY,EZ))**(1.d0/NO) - QZ=0. - QY=0. - QX=0. - DO I=0,NO-1 - QX=(QX+DX(NO-I))*DT - QY=(QY+DY(NO-I))*DT - QZ=(QZ+DZ(NO-I))*DT - ENDDO - X=X+QX - Y=Y+QY - Z=Z+QZ - DT=DT*Q - return - END diff --git a/libs/numeric/odeint/ideas/taylor/lorenz_special/lorenz_special.f b/libs/numeric/odeint/ideas/taylor/lorenz_special/lorenz_special.f deleted file mode 100644 index 18a39533..00000000 --- a/libs/numeric/odeint/ideas/taylor/lorenz_special/lorenz_special.f +++ /dev/null @@ -1,106 +0,0 @@ - IMPLICIT REAL*8 (A-H,O-Z) - call integration - stop - end - - - - Subroutine INTEGRATION - IMPLICIT REAL*8 (A-H,O-Z) - real*8 AX(77777),AY(77777),AZ(77777),AT(77777) - DIMENSION DX(0:40),DY(0:40),DZ(0:40) -C This subroutine provides the values of consecutive -c intersection coordinates of the solution of the Lorenz equations -c with the plane Z=const -c (keeping them in the arrays AX and AY). Array DT contains the -c time values at the moments of intersections. -c These data are written into the file 'lorsec.dat' - - COMMON /ST/ DX,DY,DZ,Q,NO - INTEGER counter -C open(9,file='lorenz.dat',status='unknown',access='sequential', -C : form='formatted') -C Introduce the parameters: - P=10.d0 - B=8.d0/3.d0 - R=28.d0 -C Insert the initial point: - x=10.d0 - y=10.d0 - z=10.d0 - t=0.d0 - tend=100000.d0 - counter=0 -10 call step (P,R,B,X,Y,Z,DT) - T=T+DT -C write(9,'(4f20.11)') t,x,y,z - counter = counter + 1 - if(t.lt.tend) goto 10 - write(*,"(i8)")counter - return - end - - subroutine step (P,R,B,X,Y,Z,DT) -c This subroutine performs one integration step for the Lorenz -c equations by integrating them with the method of order NO, -c and relative error TO. Here P,R and B are the usual parameters -c of the Lorenz equations. The input values of X,Y,Z are the current -c values of the respective variables; as the output values they -c contain the new values. The neccesary stepsize is computed -c automatically and can be recovered from the output value DT. - IMPLICIT REAL*8 (A-H,O-Z) - DIMENSION DX(0:40),DY(0:40),DZ(0:40) - COMMON /ST/ DX,DY,DZ,Q,NO - DATA Q/1.d0/ - TO=1.D-17 - NO=25 - DX(0)=X - DY(0)=Y - DZ(0)=Z - Q1=1. - DO 19 ND=1,NO - DXY=0 - DXZ=0 - ND1=ND-1 - QQ=Q/ND - DO I=0,ND1 - DXY=DXY+DX(I)*DY(ND1-I) - DXZ=DXZ+DX(I)*DZ(ND1-I) - enddo - DX(ND)=P*(DY(ND1)-DX(ND1))*QQ - DY(ND)=(R*DX(ND1)-DY(ND1)-DXZ)*QQ - DZ(ND)=(DXY-B*DZ(ND1))*QQ - 13 Q1=1. - Q2=DABS(DX(ND))+DABS(DY(ND))+DABS(DZ(ND)) - IF(Q2.LT.1.D-19)Q1=1.5 - IF(Q2.GT.1.D19)Q1=0.6 - IF(Q1.LT.0.95.OR.Q1.GT.1.05)THEN - Q2=Q1 - DO M=1,ND - DX(M)=DX(M)*Q2 - DY(M)=DY(M)*Q2 - DZ(M)=DZ(M)*Q2 - Q2=Q2*Q1 - enddo - Q=Q*Q1 - GOTO 13 - ENDIF - 19 CONTINUE - EX=DABS(DX(NO))/(DABS(X)+1.D-35) - EY=DABS(DY(NO))/(DABS(Y)+1.D-35) - EZ=DABS(DZ(NO))/(DABS(Z)+1.D-35) - DT=(TO/DMAX1(EX,EY,EZ))**(1.d0/NO) - QZ=0. - QY=0. - QX=0. - DO I=0,NO-1 - QX=(QX+DX(NO-I))*DT - QY=(QY+DY(NO-I))*DT - QZ=(QZ+DZ(NO-I))*DT - ENDDO - X=X+QX - Y=Y+QY - Z=Z+QZ - DT=DT*Q - return - END diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v1/Jamfile b/libs/numeric/odeint/ideas/taylor/taylor_v1/Jamfile deleted file mode 100644 index e7ae7551..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v1/Jamfile +++ /dev/null @@ -1,16 +0,0 @@ -# (C) Copyright 2010 : Karsten Ahnert, 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) - - - -project - : requirements - BOOST_ALL_NO_LIB=1 - ../../../../../.. - ; - -exe taylor_main : taylor_main.cpp ; -exe taylor_lorenz_evol_direct : taylor_lorenz_evol_direct.cpp ; -exe taylor_lorenz_evol_adaptive : taylor_lorenz_evol_adaptive.cpp ; -exe taylor_lorenz_evol_adaptive_statistics : taylor_lorenz_evol_adaptive_statistics.cpp ; diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor.hpp b/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor.hpp deleted file mode 100644 index 9815fb4f..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor.hpp +++ /dev/null @@ -1,372 +0,0 @@ -/* - * taylor.hpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#ifndef BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_HPP_ -#define BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_HPP_ - -#include - -// general boost includes -#include -#include -#include - -// fusion includes -#include -#include -#include - -// mpl includes -#include -#include - -// proto includes -#include - - - - -namespace boost { -namespace numeric { -namespace odeint { - - -namespace taylor_adf -{ - - namespace proto = boost::proto; - - template struct placeholder {}; - - proto::terminal< placeholder< 0 > >::type const arg1 = {{}}; - proto::terminal< placeholder< 1 > >::type const arg2 = {{}}; - proto::terminal< placeholder< 2 > >::type const arg3 = {{}}; - - - - template< class State , size_t Order > - struct context_derivs : proto::callable_context< context_derivs< State , Order > const > - { - typedef double result_type; - - const State &m_x; - std::tr1::array< State , Order > &m_derivs; - size_t m_which; - - context_derivs( const State &x , std::tr1::array< State , Order > &derivs , size_t which ) - : m_x( x ) , m_derivs( derivs ) , m_which( which ) { } - - - - template< int I > - double operator()( proto::tag::terminal , placeholder ) const - { - return ( m_which == 0 ) ? m_x[I] : m_derivs[m_which-1][I]; - } - - double operator()( proto::tag::terminal , double x ) const - { - return ( m_which == 0 ) ? x : 0.0; - } - - - template< typename L , typename R > - double operator ()( proto::tag::plus , L const &l , R const &r ) const - { - return proto::eval( l , context_derivs< State , Order >( m_x , m_derivs , m_which ) ) + - proto::eval( r , context_derivs< State , Order >( m_x , m_derivs , m_which ) ); - } - - - template< typename L , typename R > - double operator ()( proto::tag::minus , L const &l , R const &r ) const - { - return proto::eval( l , context_derivs< State , Order >( m_x , m_derivs , m_which ) ) - - proto::eval( r , context_derivs< State , Order >( m_x , m_derivs , m_which ) ); - } - - - template< typename L , typename R > - double operator ()( proto::tag::multiplies , L const &l , R const &r ) const - { - double tmp = 0.0; - for( size_t k=0 ; k<=m_which ; ++k ) - { - tmp += boost::math::binomial_coefficient< double >( m_which , k ) - * proto::eval( l , context_derivs< State , Order >( m_x , m_derivs , k ) ) - * proto::eval( r , context_derivs< State , Order >( m_x , m_derivs , m_which - k ) ); - } - return tmp; - } - - - template< typename L , typename R > - double operator ()( proto::tag::divides , L const &l , R const &r ) const - { - return 0.0; - } - - }; - - template< class System , class State , size_t Order > - struct eval_derivs - { - typedef std::tr1::array< State , Order > derivs_type; - - System m_sys; - const State &m_x; - derivs_type &m_derivs; - size_t m_which; - double m_dt; - - eval_derivs( System sys , const State &x , derivs_type &derivs , size_t which , double dt ) - : m_sys( sys ) , m_x( x ) , m_derivs( derivs ) , m_which( which ) , m_dt( dt ) { } - - template< class Index > - void operator()( Index ) - { - m_derivs[m_which][ Index::value ] = m_dt / double( m_which + 1 ) * boost::proto::eval( - boost::fusion::at< Index >( m_sys ) , - taylor_adf::context_derivs< State , Order >( m_x , m_derivs , m_which ) ); - } - }; - - template< class System , class State , size_t Order > - eval_derivs< System , State , Order > make_eval_derivs( System sys , const State &x , std::tr1::array< State , Order > &derivs , size_t i , double dt ) - { - return eval_derivs< System , State , Order >( sys , x , derivs , i , dt ); - } - - - -} - -template< size_t N , size_t Order > -class taylor -{ -public: - - static const size_t dim = N; - static const size_t order_value = Order; - typedef double value_type; - typedef value_type time_type; - typedef unsigned short order_type; - - typedef std::tr1::array< value_type , dim > state_type; - typedef state_type deriv_type; - typedef std::tr1::array< state_type , order_value > derivs_type; - - order_type order( void ) const - { - return order_value; - } - - order_type stepper_order( void ) const - { - return order_value; - } - - order_type error_order( void ) const - { - return order_value - 1; - } - - - - - template< class System > - void do_step( System sys , state_type &x , time_type t , time_type dt ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - - do_step( sys , x , t , x , dt ); - } - - template< class System > - void do_step( System sys , const state_type &in , time_type t , state_type &out , time_type dt ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - - for( size_t i=0 ; i >( make_eval_derivs( sys , in , m_derivs , i , dt ) ); - } - - for( size_t i=0 ; i - void do_step( System sys , state_type &x , time_type t , time_type dt , state_type &xerr ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - BOOST_STATIC_ASSERT(( order_value > 1 )); - - do_step( sys , x , t , x , dt , xerr ); - } - - template< class System > - void do_step( System sys , const state_type &in , time_type t , state_type &out , time_type dt , state_type &xerr ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - BOOST_STATIC_ASSERT(( order_value > 1 )); - - for( size_t i=0 ; i >( make_eval_derivs( sys , in , m_derivs , i , dt ) ); - } - - for( size_t i=0 ; i struct placeholder {}; - - proto::terminal< placeholder< 0 > >::type const arg1 = {{}}; - proto::terminal< placeholder< 1 > >::type const arg2 = {{}}; - proto::terminal< placeholder< 2 > >::type const arg3 = {{}}; - - - - template< class State , size_t Order > - struct context_derivs : proto::callable_context< context_derivs< State , Order > const > - { - typedef double result_type; - - const State &m_x; - std::tr1::array< State , Order > &m_derivs; - size_t m_which; - - context_derivs( const State &x , std::tr1::array< State , Order > &derivs , size_t which ) - : m_x( x ) , m_derivs( derivs ) , m_which( which ) { } - - - - template< int I > - double operator()( proto::tag::terminal , placeholder ) const - { - return ( m_which == 0 ) ? m_x[I] : m_derivs[m_which-1][I]; - } - - double operator()( proto::tag::terminal , double x ) const - { - return ( m_which == 0 ) ? x : 0.0; - } - - - template< typename L , typename R > - double operator ()( proto::tag::plus , L const &l , R const &r ) const - { - return proto::eval( l , context_derivs< State , Order >( m_x , m_derivs , m_which ) ) + - proto::eval( r , context_derivs< State , Order >( m_x , m_derivs , m_which ) ); - } - - - template< typename L , typename R > - double operator ()( proto::tag::minus , L const &l , R const &r ) const - { - return proto::eval( l , context_derivs< State , Order >( m_x , m_derivs , m_which ) ) - - proto::eval( r , context_derivs< State , Order >( m_x , m_derivs , m_which ) ); - } - - - template< typename L , typename R > - double operator ()( proto::tag::multiplies , L const &l , R const &r ) const - { - double tmp = 0.0; - for( size_t k=0 ; k<=m_which ; ++k ) - { - tmp += boost::math::binomial_coefficient< double >( m_which , k ) - * proto::eval( l , context_derivs< State , Order >( m_x , m_derivs , k ) ) - * proto::eval( r , context_derivs< State , Order >( m_x , m_derivs , m_which - k ) ); - } - return tmp; - } - - - template< typename L , typename R > - double operator ()( proto::tag::divides , L const &l , R const &r ) const - { - return 0.0; - } - - }; - - template< class System , class State , size_t Order > - struct eval_derivs - { - typedef std::tr1::array< State , Order > derivs_type; - - System m_sys; - const State &m_x; - derivs_type &m_derivs; - size_t m_which; - - eval_derivs( System sys , const State &x , derivs_type &derivs , size_t which ) - : m_sys( sys ) , m_x( x ) , m_derivs( derivs ) , m_which( which ) { } - - template< class Index > - void operator()( Index ) - { - m_derivs[m_which][ Index::value ] = boost::proto::eval( - boost::fusion::at< Index >( m_sys ) , - taylor_adf::context_derivs< State , Order >( m_x , m_derivs , m_which ) ); - } - }; - - template< class System , class State , size_t Order > - eval_derivs< System , State , Order > make_eval_derivs( System sys , const State &x , std::tr1::array< State , Order > &derivs , size_t i ) - { - return eval_derivs< System , State , Order >( sys , x , derivs , i ); - } - - - -} - - - - -} // namespace odeint -} // namespace numeric -} // namespace boost - - -#endif /* BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_HPP_ */ diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_controller.hpp b/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_controller.hpp deleted file mode 100644 index c1f7157f..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_controller.hpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - boost header: NUMERIC_ODEINT_STEPPER/controlled_runge_kutta.hpp - - Copyright 2009 Karsten Ahnert - Copyright 2009 Mario Mulansky - Copyright 2009 Andre Bergner - - 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_STEPPER_TAYLOR_CONTROLLER_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_CONTROLLER_HPP_INCLUDED - -#include - -#include -#include -#include -#include - - - - -namespace boost { -namespace numeric { -namespace odeint { - - -/* - * explicit stepper version - */ -template -< - class TaylorStepper -> -class taylor_controller -{ - -public: - - typedef TaylorStepper stepper_type; - typedef typename stepper_type::state_type state_type; - typedef typename stepper_type::value_type value_type; - typedef typename stepper_type::deriv_type deriv_type; - typedef typename stepper_type::time_type time_type; - typedef typename stepper_type::order_type order_type; - typedef default_error_checker< value_type > error_checker_type; - typedef controlled_stepper_tag stepper_category; - - - taylor_controller( - value_type eps_abs = static_cast< value_type >( 1.0e-6 ) , - value_type eps_rel = static_cast< value_type >( 1.0e-6 ) , - value_type a_x = static_cast< value_type >( 1.0 ) , - value_type a_dxdt = static_cast< value_type >( 1.0 ) , - const stepper_type &stepper = stepper_type() - ) - : m_stepper( stepper ) , - m_error_checker( eps_abs , eps_rel , a_x , a_dxdt ) , - m_xerr() , m_xnew() - { - } - - - template< class System > - controlled_step_result try_step( System system , state_type &x , time_type &t , time_type &dt ) - { - controlled_step_result res = try_step( system , x , t , m_xnew , dt ); - if( ( res == success_step_size_increased ) || ( res == success_step_size_unchanged ) ) - { - x = m_xnew; - } - return res; - } - - - template< class System > - controlled_step_result try_step( System system , state_type &in , time_type &t , state_type &out , time_type &dt ) - { - using std::max; - using std::min; - using std::pow; - - // do one step with error calculation - m_stepper.do_step( system , in , t , out , dt , m_xerr ); - - value_type max_rel_error = m_error_checker.error( in , m_stepper.get_last_derivs()[0] , m_xerr , dt ); - - if( max_rel_error > 1.1 ) - { - // error too large - decrease dt ,limit scaling factor to 0.2 and reset state - dt *= max( 0.9 * pow( max_rel_error , -1.0 / ( m_stepper.error_order() - 1.0 ) ) , 0.2 ); - return step_size_decreased; - } - else - { - if( max_rel_error < 0.5 ) - { - //error too small - increase dt and keep the evolution and limit scaling factor to 5.0 - t += dt; - dt *= min( 0.9 * pow( max_rel_error , -1.0 / m_stepper.stepper_order() ) , 5.0 ); - return success_step_size_increased; - } - else - { - t += dt; - return success_step_size_unchanged; - } - } - } - - - stepper_type& stepper( void ) - { - return m_stepper; - } - - const stepper_type& stepper( void ) const - { - return m_stepper; - } - - -private: - - - - stepper_type m_stepper; - error_checker_type m_error_checker; - state_type m_xerr; - state_type m_xnew; -}; - - - - - - - - -} // odeint -} // numeric -} // boost - - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_CONTROLLER_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_lorenz_evol_adaptive.cpp b/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_lorenz_evol_adaptive.cpp deleted file mode 100644 index f2376f17..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_lorenz_evol_adaptive.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * main.cpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#include -#include - -#include "taylor.hpp" -#include "taylor_controller.hpp" - -#include -#include -#include - -#include -#include - -template< typename T , size_t N > -std::ostream& operator<<( std::ostream& out , const std::tr1::array< T , N > &x ) -{ - if( !x.empty() ) out << x[0]; - for( size_t i=1 ; i taylor_type; -typedef taylor_type::state_type state_type; -typedef boost::numeric::odeint::explicit_error_rk54_ck< state_type > rk54_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - - - - - -namespace fusion = boost::fusion; -namespace phoenix = boost::phoenix; - -using namespace std; -using namespace boost::numeric::odeint; - -using boost::numeric::odeint::taylor_adf::arg1; -using boost::numeric::odeint::taylor_adf::arg2; -using boost::numeric::odeint::taylor_adf::arg3; - -struct streaming_observer -{ - std::ostream& m_out; - - streaming_observer( std::ostream &out ) : m_out( out ) { } - - template< class State > - void operator()( const State &x , double t ) const - { - m_out << t; - for( size_t i=0 ; i 2 ) - { - eps_abs = atof( argv[1] ); - eps_rel = atof( argv[2] ); - } - - - rk54_type rk54_plain; - controlled_runge_kutta< rk54_type > rk54( rk54_plain , default_error_checker< double >( eps_abs , eps_rel ) ); - taylor_controller< taylor_type > taylor_controller( eps_abs , eps_rel ); - - state_type x1 = {{ 10.0 , 10.0 , 10.0 }} , x2 = x1; - - ofstream fout( "lorenz_rk54.dat" ); - size_t steps_rk54 = integrate_adaptive( rk54 , lorenz , x1 , 0.0 , 50.0 , 0.1 , streaming_observer( fout ) ); - clog << "Steps RK 54 : " << steps_rk54 << endl;; - - ofstream fout2( "lorenz_taylor.dat" ); - size_t steps_taylor = integrate_adaptive( taylor_controller , - fusion::make_vector - ( - sigma * ( arg2 - arg1 ) , - R * arg1 - arg2 - arg1 * arg3 , - arg1 * arg2 - b * arg3 - ) , x2 , 0.0 , 50.0 , 0.1 , streaming_observer( fout2 ) ); - clog << "Steps Taylor : " << steps_taylor << endl; - - return 0; -} diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_lorenz_evol_adaptive_statistics.cpp b/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_lorenz_evol_adaptive_statistics.cpp deleted file mode 100644 index c5e8b687..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_lorenz_evol_adaptive_statistics.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * main.cpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#include -#include - -#include "taylor.hpp" -#include "taylor_controller.hpp" - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#define tab "\t" - -template< typename T , size_t N > -std::ostream& operator<<( std::ostream& out , const std::tr1::array< T , N > &x ) -{ - if( !x.empty() ) out << x[0]; - for( size_t i=1 ; i state_type; - -typedef boost::numeric::odeint::explicit_error_rk54_ck< state_type > rk54_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - - -namespace fusion = boost::fusion; -namespace phoenix = boost::phoenix; -namespace mpl = boost::mpl; - -using namespace std; -using namespace boost::numeric::odeint; -using namespace boost::assign; - -using boost::numeric::odeint::taylor_adf::arg1; -using boost::numeric::odeint::taylor_adf::arg2; -using boost::numeric::odeint::taylor_adf::arg3; - -struct run -{ - vector< double > m_eps_abs_values; - vector< double > m_eps_rel_values; - double m_t_end; - - run( const vector< double > &eps_abs_values , const vector< double > &eps_rel_values , double t_end ) - : m_eps_abs_values( eps_abs_values ) , m_eps_rel_values( eps_rel_values ) , m_t_end( t_end ){ } - - template< class Order > - void operator()( Order ) const - { - static const size_t order = Order::value; - typedef boost::numeric::odeint::taylor< 3 , order > taylor_type; - - boost::timer timer; - - char str[512] = ""; - sprintf( str , "dat/lorenz_taylor_%02d.dat" , int( order ) ); - ofstream fout( str ); - - for( size_t i=0 ; i taylor_controller( eps_abs , eps_rel ); - - state_type x = {{ 10.0 , 10.0 , 10.0 }}; - - timer.restart(); - size_t steps_taylor = integrate_adaptive( taylor_controller , - fusion::make_vector - ( - sigma * ( arg2 - arg1 ) , - R * arg1 - arg2 - arg1 * arg3 , - arg1 * arg2 - b * arg3 - ) , x , 0.0 , m_t_end , 0.1 ); - double time_taylor = timer.elapsed(); - - fout << i << tab << j << tab << eps_abs << tab << eps_rel << tab; - fout << steps_taylor << tab << time_taylor; - fout << endl; - } - fout << endl; - } - - - } -}; - - - - -int main( int argc , char **argv ) -{ - if( argc != 2 ) - { - cerr << "usage taylor_lorenz_eval_adaptive_statistics t_end" << endl; - return -1; - } - double t_end = atof( argv[1] ); - - vector< double > eps_abs_values; - vector< double > eps_rel_values; - - eps_abs_values += 1.0e1 , 1.0 , 1.0e-1 , 1.0e-2 , 1.0e-3 , 1.0e-4 , 1.0e-5 , 1.0e-6 , 1.0e-7 , 1.0e-8 , 1.0e-9 , 1.0e-10 , 1.0e-11 , 1.0e-12 , 1.0e-13 , 1.0e-14; - eps_rel_values += 1.0e-1 , 1.0e-2 , 1.0e-3 , 1.0e-4 , 1.0e-5 , 1.0e-6 , 1.0e-7 , 1.0e-8 , 1.0e-9 , 1.0e-10 , 1.0e-11 , 1.0e-12 , 1.0e-13 , 1.0e-14; - - - typedef mpl::range_c< size_t , 5 , 30 > order_values; - mpl::for_each< order_values >( run( eps_abs_values , eps_rel_values , t_end ) ); - - - boost::timer timer; - ofstream fout( "dat/lorenz_rk54.dat" ); - for( size_t i=0 ; i rk54( rk54_plain , default_error_checker< double >( eps_abs , eps_rel ) ); - - state_type x = {{ 10.0 , 10.0 , 10.0 }}; - - timer.restart(); - size_t steps_rk54 = integrate_adaptive( rk54 , lorenz , x , 0.0 , t_end , 0.1 ); - double time_rk54 = timer.elapsed(); - - fout << i << tab << j << tab << eps_abs << tab << eps_rel << tab; - fout << steps_rk54 << tab << time_rk54 << tab; - fout << endl; - } - fout << endl; - } - - return 0; -} diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_lorenz_evol_direct.cpp b/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_lorenz_evol_direct.cpp deleted file mode 100644 index 0019e1cd..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_lorenz_evol_direct.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * main.cpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#include - -#include "taylor.hpp" - -#include - -#include - -template< typename T , size_t N > -std::ostream& operator<<( std::ostream& out , const std::tr1::array< T , N > &x ) -{ - if( !x.empty() ) out << x[0]; - for( size_t i=1 ; i taylor_type; -typedef taylor_type::state_type state_type; -typedef boost::numeric::odeint::explicit_rk4< state_type > rk4_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - - - - - -namespace fusion = boost::fusion; - -using namespace std; -using namespace boost::numeric::odeint; - -using boost::numeric::odeint::taylor_adf::arg1; -using boost::numeric::odeint::taylor_adf::arg2; -using boost::numeric::odeint::taylor_adf::arg3; - -int main( int argc , char **argv ) -{ - taylor_type tay; - rk4_type rk4; - - - state_type x1 = {{ 10.0 , 10.0 , 10.0 }} , x2 = x1; - - const double dt = 0.1; - double t = 0.0; - for( size_t i=0 ; i<10000 ; ++i , t += dt ) - { - tay.do_step( - fusion::make_vector - ( - sigma * ( arg2 - arg1 ) , - R * arg1 - arg2 - arg1 * arg3 , - arg1 * arg2 - b * arg3 - ) , - x1 , t , dt ); - - rk4.do_step( lorenz , x2 , t , dt ); - - cout << t << "\t" << x1 << "\t" << x2 << "\n"; - } - - - return 0; -} diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_main.cpp b/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_main.cpp deleted file mode 100644 index c7f86ec7..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v1/taylor_main.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * main.cpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#include - -#include "taylor.hpp" - -#include - -template< typename T , size_t N > -std::ostream& operator<<( std::ostream& out , const std::tr1::array< T , N > &x ) -{ - if( !x.empty() ) out << x[0]; - for( size_t i=1 ; i taylor_type; -typedef taylor_type::state_type state_type; -typedef taylor_type::derivs_type derivs_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - - - - - -namespace fusion = boost::fusion; - -using namespace std; -using namespace boost::numeric::odeint; - -using boost::numeric::odeint::taylor_adf::arg1; -using boost::numeric::odeint::taylor_adf::arg2; -using boost::numeric::odeint::taylor_adf::arg3; - -int main( int argc , char **argv ) -{ - cout.precision( 14 ); - - taylor_type t; - - state_type in = {{ 10.0 , 10.0 , 10.0 }} , dxdt = {{ 0.0 , 0.0 , 0.0 }} , xerr = {{ 0.0 , 0.0 , 0.0 }} , out = {{ 0.0 ,0.0 , 0.0 }}; - - lorenz( in , dxdt , 0.0 ); - - cout << in << endl; - cout << dxdt << endl << endl; - - t.do_step( - fusion::make_vector - ( - sigma * ( arg2 - arg1 ) , - R * arg1 - arg2 - arg1 * arg3 , - arg1 * arg2 - b * arg3 - ) , - in , 0.0 , out , 0.1 , xerr ); - - - - cout << in << endl; - cout << dxdt << endl; - cout << xerr << endl; - cout << out << endl << endl; - const derivs_type &derivs = t.get_last_derivs(); - for( size_t i=0 ; iBOOST_ALL_NO_LIB=1 - ../../../../../.. - ; - -exe taylor_main : taylor_main.cpp ; -exe taylor_lorenz_evol_direct : taylor_lorenz_evol_direct.cpp ; -exe taylor_lorenz_evol_adaptive_statistics : taylor_lorenz_evol_adaptive_statistics.cpp ; diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v2/taylor.hpp b/libs/numeric/odeint/ideas/taylor/taylor_v2/taylor.hpp deleted file mode 100644 index 43884e2a..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v2/taylor.hpp +++ /dev/null @@ -1,378 +0,0 @@ -/* - * taylor.hpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#ifndef BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_HPP_ -#define BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_HPP_ - -#include - -#include -using namespace std; - -// general boost includes -#include -#include -#include - -// fusion includes -#include -#include -#include -#include - -// mpl includes -#include -#include - -// proto includes -#include - - - - -namespace boost { -namespace numeric { -namespace odeint { - - -namespace taylor_adf -{ - - namespace proto = boost::proto; - namespace fusion = boost::fusion; - namespace proto = boost::proto; - - template< typename I > struct placeholder : I {}; - - proto::terminal< placeholder< mpl::size_t< 0 > > >::type const arg1 = {}; - proto::terminal< placeholder< mpl::size_t< 1 > > >::type const arg2 = {}; - proto::terminal< placeholder< mpl::size_t< 2 > > >::type const arg3 = {}; - - template< typename I > - std::ostream& operator<<( std::ostream &s , const placeholder< I > &p ) - { - s << "placeholder<" << I::value << ">"; - return s; - } - - - /* - * eventuel array< double , n > dt mit potenzen anlegen - */ - template< class State , size_t MaxOrder > - struct taylor_context - { - typedef State state_type; - typedef std::tr1::array< state_type , MaxOrder > deriv_type; - - size_t which; - double dt; - const state_type &x; - deriv_type &derivs; - - taylor_context( size_t _which , double _dt , const state_type &_x , deriv_type &_derivs ) - : which( _which ) , dt( _dt ) , x( _x ) , derivs( _derivs ) { } - }; - - - template< typename Grammar > - struct plus_transform : proto::transform< plus_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { - return Grammar()( proto::left( expr ) , state , data ) - + Grammar()( proto::right( expr ) , state , data ); - } - }; - }; - - - template< typename Grammar > - struct minus_transform : proto::transform< minus_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { - return Grammar()( proto::left( expr ) , state , data ) - - Grammar()( proto::right( expr ) , state , data ); - } - }; - }; - - - - template< typename Grammar > - struct multiplies_transform : proto::transform< multiplies_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { - typedef typename impl::data data_type; - - double tmp = 0.0; - for( size_t k=0 ; k<=data.which ; ++k ) - { - data_type data1( k , data.dt , data.x , data.derivs ); - data_type data2( data.which - k , data.dt , data.x , data.derivs ); - - tmp += boost::math::binomial_coefficient< double >( data.which , k ) - * Grammar()( proto::left( expr ) , state , data1 ) - * Grammar()( proto::right( expr ) , state , data2 ); - } - - return tmp; - } - }; - }; - - - struct terminal_double_transform : proto::transform< terminal_double_transform > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { - return ( data.which == 0 ) ? proto::value( expr ) : 0.0; - } - }; - }; - - - template< typename Index > - struct terminal_placeholder_transform : proto::transform< terminal_placeholder_transform< Index > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { - typedef typename impl::expr expr_type; - typedef typename expr_type::proto_args args_type; - typedef typename args_type::child0 index_type; - const size_t index = index_type::value; - - return ( data.which == 0 ) ? data.x[ index ] : data.derivs[ data.which - 1 ][ index ]; - } - }; - }; - - - struct taylor_double_terminal : proto::when< proto::terminal< double > , terminal_double_transform > { }; - - template< typename Which > - struct taylor_placeholder_terminal : proto::when< proto::terminal< placeholder< Which > > , terminal_placeholder_transform< Which > > { }; - - template< typename Grammar > - struct taylor_plus : proto::when< proto::plus< Grammar , Grammar > , plus_transform< Grammar > > { }; - - template< typename Grammar > - struct taylor_minus : proto::when< proto::minus< Grammar , Grammar > , minus_transform< Grammar > > { }; - - template< typename Grammar > - struct taylor_multiplies : proto::when< proto::multiplies< Grammar , Grammar > , multiplies_transform< Grammar > > { }; - - - - struct taylor_transform : - proto::or_ - < - taylor_double_terminal , - taylor_placeholder_terminal< proto::_ > , - taylor_plus< taylor_transform > , - taylor_minus< taylor_transform > , - taylor_multiplies< taylor_transform > - > - { }; - - - - template< class System , class State , size_t Order > - struct eval_derivs - { - typedef State state_type; - typedef taylor_context< state_type , Order > taylor_context_type; - typedef typename taylor_context_type::deriv_type deriv_type; - - System m_sys; - taylor_context_type m_data; - - eval_derivs( System sys , const State &x , deriv_type &derivs , size_t which , double dt ) - : m_sys( sys ) , m_data( which , dt , x , derivs ) { } - - template< class Index > - void operator()( Index ) - { - typedef typename fusion::result_of::at< System , Index >::type expr_type; - const expr_type &expr = boost::fusion::at< Index >( m_sys ); - - double deriv = taylor_transform()( expr , 0.0 , m_data ); - m_data.derivs[ m_data.which ][ Index::value ] = m_data.dt / double( m_data.which + 1 ) * deriv; - } - }; - - template< class System , class State , size_t Order > - eval_derivs< System , State , Order > make_eval_derivs( System sys , const State &x , std::tr1::array< State , Order > &derivs , size_t i , double dt ) - { - return eval_derivs< System , State , Order >( sys , x , derivs , i , dt ); - } - - - struct optimize_tree : proto::or_< proto::_ > { }; -} - -template< size_t N , size_t Order > -class taylor -{ -public: - - static const size_t dim = N; - static const size_t order_value = Order; - typedef double value_type; - typedef value_type time_type; - typedef unsigned short order_type; - - typedef std::tr1::array< value_type , dim > state_type; - typedef state_type deriv_type; - typedef std::tr1::array< state_type , order_value > derivs_type; - - order_type order( void ) const - { - return order_value; - } - - order_type stepper_order( void ) const - { - return order_value; - } - - order_type error_order( void ) const - { - return order_value - 1; - } - - - - - template< class System > - void do_step( System sys , state_type &x , time_type t , time_type dt ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - - do_step( sys , x , t , x , dt ); - } - - template< class System > - void do_step( System sys , const state_type &in , time_type t , state_type &out , time_type dt ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - - typedef typename boost::fusion::result_of::transform< System , taylor_adf::optimize_tree >::type optimized_system_type; - - optimized_system_type optimized_system = boost::fusion::transform( sys , taylor_adf::optimize_tree() ); - - for( size_t i=0 ; i >( make_eval_derivs( optimized_system , in , m_derivs , i , dt ) ); - } - - for( size_t i=0 ; i - void do_step( System sys , state_type &x , time_type t , time_type dt , state_type &xerr ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - BOOST_STATIC_ASSERT(( order_value > 1 )); - - do_step( sys , x , t , x , dt , xerr ); - } - - template< class System > - void do_step( System sys , const state_type &in , time_type t , state_type &out , time_type dt , state_type &xerr ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - BOOST_STATIC_ASSERT(( order_value > 1 )); - - for( size_t i=0 ; i >( make_eval_derivs( sys , in , m_derivs , i , dt ) ); - } - - for( size_t i=0 ; i - -#include -#include -#include -#include - - - - -namespace boost { -namespace numeric { -namespace odeint { - - -/* - * explicit stepper version - */ -template -< - class TaylorStepper -> -class taylor_controller -{ - -public: - - typedef TaylorStepper stepper_type; - typedef typename stepper_type::state_type state_type; - typedef typename stepper_type::value_type value_type; - typedef typename stepper_type::deriv_type deriv_type; - typedef typename stepper_type::time_type time_type; - typedef typename stepper_type::order_type order_type; - typedef default_error_checker< value_type > error_checker_type; - typedef controlled_stepper_tag stepper_category; - - - taylor_controller( - value_type eps_abs = static_cast< value_type >( 1.0e-6 ) , - value_type eps_rel = static_cast< value_type >( 1.0e-6 ) , - value_type a_x = static_cast< value_type >( 1.0 ) , - value_type a_dxdt = static_cast< value_type >( 1.0 ) , - const stepper_type &stepper = stepper_type() - ) - : m_stepper( stepper ) , - m_error_checker( eps_abs , eps_rel , a_x , a_dxdt ) , - m_xerr() , m_xnew() - { - } - - - template< class System > - controlled_step_result try_step( System system , state_type &x , time_type &t , time_type &dt ) - { - controlled_step_result res = try_step( system , x , t , m_xnew , dt ); - if( ( res == success_step_size_increased ) || ( res == success_step_size_unchanged ) ) - { - x = m_xnew; - } - return res; - } - - - template< class System > - controlled_step_result try_step( System system , state_type &in , time_type &t , state_type &out , time_type &dt ) - { - using std::max; - using std::min; - using std::pow; - - // do one step with error calculation - m_stepper.do_step( system , in , t , out , dt , m_xerr ); - - value_type max_rel_error = m_error_checker.error( in , m_stepper.get_last_derivs()[0] , m_xerr , dt ); - - if( max_rel_error > 1.1 ) - { - // error too large - decrease dt ,limit scaling factor to 0.2 and reset state - dt *= max( 0.9 * pow( max_rel_error , -1.0 / ( m_stepper.error_order() - 1.0 ) ) , 0.2 ); - return step_size_decreased; - } - else - { - if( max_rel_error < 0.5 ) - { - //error too small - increase dt and keep the evolution and limit scaling factor to 5.0 - t += dt; - dt *= min( 0.9 * pow( max_rel_error , -1.0 / m_stepper.stepper_order() ) , 5.0 ); - return success_step_size_increased; - } - else - { - t += dt; - return success_step_size_unchanged; - } - } - } - - - stepper_type& stepper( void ) - { - return m_stepper; - } - - const stepper_type& stepper( void ) const - { - return m_stepper; - } - - -private: - - - - stepper_type m_stepper; - error_checker_type m_error_checker; - state_type m_xerr; - state_type m_xnew; -}; - - - - - - - - -} // odeint -} // numeric -} // boost - - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_CONTROLLER_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_lorenz_evol_adaptive_statistics.cpp b/libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_lorenz_evol_adaptive_statistics.cpp deleted file mode 100644 index c5e8b687..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_lorenz_evol_adaptive_statistics.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * main.cpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#include -#include - -#include "taylor.hpp" -#include "taylor_controller.hpp" - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#define tab "\t" - -template< typename T , size_t N > -std::ostream& operator<<( std::ostream& out , const std::tr1::array< T , N > &x ) -{ - if( !x.empty() ) out << x[0]; - for( size_t i=1 ; i state_type; - -typedef boost::numeric::odeint::explicit_error_rk54_ck< state_type > rk54_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - - -namespace fusion = boost::fusion; -namespace phoenix = boost::phoenix; -namespace mpl = boost::mpl; - -using namespace std; -using namespace boost::numeric::odeint; -using namespace boost::assign; - -using boost::numeric::odeint::taylor_adf::arg1; -using boost::numeric::odeint::taylor_adf::arg2; -using boost::numeric::odeint::taylor_adf::arg3; - -struct run -{ - vector< double > m_eps_abs_values; - vector< double > m_eps_rel_values; - double m_t_end; - - run( const vector< double > &eps_abs_values , const vector< double > &eps_rel_values , double t_end ) - : m_eps_abs_values( eps_abs_values ) , m_eps_rel_values( eps_rel_values ) , m_t_end( t_end ){ } - - template< class Order > - void operator()( Order ) const - { - static const size_t order = Order::value; - typedef boost::numeric::odeint::taylor< 3 , order > taylor_type; - - boost::timer timer; - - char str[512] = ""; - sprintf( str , "dat/lorenz_taylor_%02d.dat" , int( order ) ); - ofstream fout( str ); - - for( size_t i=0 ; i taylor_controller( eps_abs , eps_rel ); - - state_type x = {{ 10.0 , 10.0 , 10.0 }}; - - timer.restart(); - size_t steps_taylor = integrate_adaptive( taylor_controller , - fusion::make_vector - ( - sigma * ( arg2 - arg1 ) , - R * arg1 - arg2 - arg1 * arg3 , - arg1 * arg2 - b * arg3 - ) , x , 0.0 , m_t_end , 0.1 ); - double time_taylor = timer.elapsed(); - - fout << i << tab << j << tab << eps_abs << tab << eps_rel << tab; - fout << steps_taylor << tab << time_taylor; - fout << endl; - } - fout << endl; - } - - - } -}; - - - - -int main( int argc , char **argv ) -{ - if( argc != 2 ) - { - cerr << "usage taylor_lorenz_eval_adaptive_statistics t_end" << endl; - return -1; - } - double t_end = atof( argv[1] ); - - vector< double > eps_abs_values; - vector< double > eps_rel_values; - - eps_abs_values += 1.0e1 , 1.0 , 1.0e-1 , 1.0e-2 , 1.0e-3 , 1.0e-4 , 1.0e-5 , 1.0e-6 , 1.0e-7 , 1.0e-8 , 1.0e-9 , 1.0e-10 , 1.0e-11 , 1.0e-12 , 1.0e-13 , 1.0e-14; - eps_rel_values += 1.0e-1 , 1.0e-2 , 1.0e-3 , 1.0e-4 , 1.0e-5 , 1.0e-6 , 1.0e-7 , 1.0e-8 , 1.0e-9 , 1.0e-10 , 1.0e-11 , 1.0e-12 , 1.0e-13 , 1.0e-14; - - - typedef mpl::range_c< size_t , 5 , 30 > order_values; - mpl::for_each< order_values >( run( eps_abs_values , eps_rel_values , t_end ) ); - - - boost::timer timer; - ofstream fout( "dat/lorenz_rk54.dat" ); - for( size_t i=0 ; i rk54( rk54_plain , default_error_checker< double >( eps_abs , eps_rel ) ); - - state_type x = {{ 10.0 , 10.0 , 10.0 }}; - - timer.restart(); - size_t steps_rk54 = integrate_adaptive( rk54 , lorenz , x , 0.0 , t_end , 0.1 ); - double time_rk54 = timer.elapsed(); - - fout << i << tab << j << tab << eps_abs << tab << eps_rel << tab; - fout << steps_rk54 << tab << time_rk54 << tab; - fout << endl; - } - fout << endl; - } - - return 0; -} diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_lorenz_evol_direct.cpp b/libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_lorenz_evol_direct.cpp deleted file mode 100644 index 94902c10..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_lorenz_evol_direct.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * main.cpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#include - -#include "taylor.hpp" - -#include - -#include - -template< typename T , size_t N > -std::ostream& operator<<( std::ostream& out , const std::tr1::array< T , N > &x ) -{ - if( !x.empty() ) out << x[0]; - for( size_t i=1 ; i taylor_type; -typedef taylor_type::state_type state_type; -typedef boost::numeric::odeint::explicit_rk4< state_type > rk4_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - - - - - -namespace fusion = boost::fusion; - -using namespace std; -using namespace boost::numeric::odeint; - -using boost::numeric::odeint::taylor_adf::arg1; -using boost::numeric::odeint::taylor_adf::arg2; -using boost::numeric::odeint::taylor_adf::arg3; - -int main( int argc , char **argv ) -{ - taylor_type tay; - rk4_type rk4; - - - state_type x1 = {{ 10.0 , 10.0 , 10.0 }} , x2 = x1 , xerr = x1; - - const double dt = 0.01; - double t = 0.0; - for( size_t i=0 ; i<10000 ; ++i , t += dt ) - { - tay.do_step( - fusion::make_vector - ( - sigma * ( arg2 - arg1 ) , - R * arg1 - arg2 - arg1 * arg3 , - arg1 * arg2 - b * arg3 - ) , - x1 , t , dt , xerr ); - - rk4.do_step( lorenz , x2 , t , dt ); - - cout << t << "\t" << x1 << "\t" << x2 << "\n"; - } - - - return 0; -} diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_main.cpp b/libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_main.cpp deleted file mode 100644 index 38e42047..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v2/taylor_main.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * main.cpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#include - -#include "taylor.hpp" - -#include - -template< typename T , size_t N > -std::ostream& operator<<( std::ostream& out , const std::tr1::array< T , N > &x ) -{ - if( !x.empty() ) out << x[0]; - for( size_t i=1 ; i taylor_type; -typedef taylor_type::state_type state_type; -typedef taylor_type::derivs_type derivs_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - - - - - -namespace fusion = boost::fusion; - -using namespace std; -using namespace boost::numeric::odeint; - -using boost::numeric::odeint::taylor_adf::arg1; -using boost::numeric::odeint::taylor_adf::arg2; -using boost::numeric::odeint::taylor_adf::arg3; - -int main( int argc , char **argv ) -{ - cout.precision( 14 ); - - taylor_type t; - - state_type in = {{ 10.0 , 10.0 , 10.0 }} , dxdt = {{ 0.0 , 0.0 , 0.0 }} , xerr = {{ 0.0 , 0.0 , 0.0 }} , out = {{ 0.0 ,0.0 , 0.0 }}; - - lorenz( in , dxdt , 0.0 ); - - cout << in << endl; - cout << dxdt << endl << endl; - - t.do_step( - fusion::make_vector - ( - sigma * ( arg2 - arg1 ) , - R * arg1 - arg2 - arg1 * arg3 , - arg1 * arg2 - b * arg3 - ) , - in , 0.0 , out , 0.1 , xerr ); - - - - cout << endl; - cout << in << endl; - cout << xerr << endl; - cout << out << endl << endl; - const derivs_type &derivs = t.get_last_derivs(); - for( size_t i=0 ; iBOOST_ALL_NO_LIB=1 - ../../../../../.. - ; - -exe taylor_main : taylor_main.cpp ; -exe taylor_lorenz_evol_direct : taylor_lorenz_evol_direct.cpp ; -exe taylor_lorenz_evol_adaptive_statistics : taylor_lorenz_evol_adaptive_statistics.cpp ; diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v3/taylor.hpp b/libs/numeric/odeint/ideas/taylor/taylor_v3/taylor.hpp deleted file mode 100644 index d99e075b..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v3/taylor.hpp +++ /dev/null @@ -1,482 +0,0 @@ -/* - * taylor.hpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#ifndef BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_HPP_ -#define BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_HPP_ - -#include - -#include -using namespace std; - -// general boost includes -#include -#include -#include - -// fusion includes -#include -#include -#include -#include - -// mpl includes -#include -#include - -// proto includes -#include - - - - -namespace boost { -namespace numeric { -namespace odeint { - - -namespace taylor_adf -{ - - namespace proto = boost::proto; - namespace fusion = boost::fusion; - namespace proto = boost::proto; - - template< typename I > struct placeholder : I {}; - - proto::terminal< placeholder< mpl::size_t< 0 > > >::type const arg1 = {}; - proto::terminal< placeholder< mpl::size_t< 1 > > >::type const arg2 = {}; - proto::terminal< placeholder< mpl::size_t< 2 > > >::type const arg3 = {}; - - template< typename I > - std::ostream& operator<<( std::ostream &s , const placeholder< I > &p ) - { - s << "placeholder<" << I::value << ">"; - return s; - } - - - /* - * eventuel array< double , n > dt mit potenzen anlegen - */ - template< class State , size_t MaxOrder > - struct taylor_context - { - typedef State state_type; - typedef std::tr1::array< state_type , MaxOrder > deriv_type; - - size_t which; - double dt; - const state_type &x; - deriv_type &derivs; - - taylor_context( size_t _which , double _dt , const state_type &_x , deriv_type &_derivs ) - : which( _which ) , dt( _dt ) , x( _x ) , derivs( _derivs ) { } - }; - - - template< typename Grammar > - struct plus_transform : proto::transform< plus_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Plus transform" << endl; - return Grammar()( proto::left( expr ) , state , data ) - + Grammar()( proto::right( expr ) , state , data ); - } - }; - }; - - - template< typename Grammar > - struct minus_transform : proto::transform< minus_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Minus transform" << endl; - return Grammar()( proto::left( expr ) , state , data ) - - Grammar()( proto::right( expr ) , state , data ); - } - }; - }; - - - - template< typename Grammar > - struct multiplies_transform : proto::transform< multiplies_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Multiplies transform" << endl; - typedef typename impl::data data_type; - - double tmp = 0.0; - for( size_t k=0 ; k<=data.which ; ++k ) - { - data_type data1( k , data.dt , data.x , data.derivs ); - data_type data2( data.which - k , data.dt , data.x , data.derivs ); - - tmp += boost::math::binomial_coefficient< double >( data.which , k ) - * Grammar()( proto::left( expr ) , state , data1 ) - * Grammar()( proto::right( expr ) , state , data2 ); - } - - return tmp; - } - }; - }; - - - struct terminal_double_transform : proto::transform< terminal_double_transform > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Terminal double transform" << endl; - return ( data.which == 0 ) ? proto::value( expr ) : 0.0; - } - }; - }; - - - template< typename Index > - struct terminal_placeholder_transform : proto::transform< terminal_placeholder_transform< Index > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Terminal placeholder transform" << endl; - typedef typename impl::expr expr_type; - typedef typename expr_type::proto_args args_type; - typedef typename args_type::child0 index_type; - const size_t index = index_type::value; - - return ( data.which == 0 ) ? data.x[ index ] : data.derivs[ data.which - 1 ][ index ]; - } - }; - }; - - template< typename Grammar > - struct right_shift_transform : proto::transform< right_shift_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Right shift transform" << endl; - return Grammar()( proto::left( expr ) , state , data ) - + ( data.which == 0 ) ? proto::value( proto::right( expr ) ) : 0.0; - } - }; - }; - - template< typename Grammar > - struct left_shift_transform : proto::transform< left_shift_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Right shift transform" << endl; - return Grammar()( proto::right( expr ) , state , data ) - + ( data.which == 0 ) ? proto::value( proto::left( expr ) ) : 0.0; - } - }; - }; - - - template< typename Grammar > - struct right_scalar_multiplies_transform : proto::transform< right_scalar_multiplies_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Right scalar multiplies transform" << endl; - return Grammar()( proto::left( expr ) , state , data ) * proto::value( proto::right( expr ) ); - } - }; - }; - - template< typename Grammar > - struct left_scalar_multiplies_transform : proto::transform< left_scalar_multiplies_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Left scalar multiplies transform" << endl; - return Grammar()( proto::right( expr ) , state , data ) * proto::value( proto::left( expr ) ); - } - }; - }; - - - - - - struct taylor_double_terminal : proto::when< proto::terminal< double > , terminal_double_transform > { }; - - template< typename Which > - struct taylor_placeholder_terminal : proto::when< proto::terminal< placeholder< Which > > , terminal_placeholder_transform< Which > > { }; - - template< typename Grammar > - struct taylor_plus : proto::when< proto::plus< Grammar , Grammar > , plus_transform< Grammar > > { }; - - template< typename Grammar > - struct taylor_minus : proto::when< proto::minus< Grammar , Grammar > , minus_transform< Grammar > > { }; - - template< typename Grammar > - struct taylor_multiplies : proto::when< proto::multiplies< Grammar , Grammar > , multiplies_transform< Grammar > > { }; - - template< typename Grammar > - struct taylor_shift : - proto::or_< - proto::when< proto::plus< Grammar , proto::terminal< double > > , right_shift_transform< Grammar > > , - proto::when< proto::plus< proto::terminal< double > , Grammar > , left_shift_transform< Grammar > > - > { }; - - template< typename Grammar > - struct taylor_scalar_multiplies : - proto::or_< - proto::when< proto::multiplies< Grammar , proto::terminal< double > > , right_scalar_multiplies_transform< Grammar > > , - proto::when< proto::multiplies< proto::terminal< double > , Grammar > , left_scalar_multiplies_transform< Grammar > > - > { }; - - - - - - struct taylor_transform : - proto::or_ - < - taylor_shift< taylor_transform > , - taylor_scalar_multiplies< taylor_transform > , - taylor_double_terminal , - taylor_placeholder_terminal< proto::_ > , - taylor_plus< taylor_transform > , - taylor_minus< taylor_transform > , - taylor_multiplies< taylor_transform > - > - { }; - - - template< class System , class State , size_t Order > - struct eval_derivs - { - typedef State state_type; - typedef taylor_context< state_type , Order > taylor_context_type; - typedef typename taylor_context_type::deriv_type deriv_type; - - System m_sys; - taylor_context_type m_data; - - eval_derivs( System sys , const State &x , deriv_type &derivs , size_t which , double dt ) - : m_sys( sys ) , m_data( which , dt , x , derivs ) { } - - template< class Index > - void operator()( Index ) - { - typedef typename fusion::result_of::at< System , Index >::type expr_type; - const expr_type &expr = boost::fusion::at< Index >( m_sys ); - - double deriv = taylor_transform()( expr , 0.0 , m_data ); - m_data.derivs[ m_data.which ][ Index::value ] = m_data.dt / double( m_data.which + 1 ) * deriv; - } - }; - - template< class System , class State , size_t Order > - eval_derivs< System , State , Order > make_eval_derivs( System sys , const State &x , std::tr1::array< State , Order > &derivs , size_t i , double dt ) - { - return eval_derivs< System , State , Order >( sys , x , derivs , i , dt ); - } - - - struct optimize_tree : proto::or_< proto::_ > { }; -} - -template< size_t N , size_t Order > -class taylor -{ -public: - - static const size_t dim = N; - static const size_t order_value = Order; - typedef double value_type; - typedef value_type time_type; - typedef unsigned short order_type; - - typedef std::tr1::array< value_type , dim > state_type; - typedef state_type deriv_type; - typedef std::tr1::array< state_type , order_value > derivs_type; - - order_type order( void ) const - { - return order_value; - } - - order_type stepper_order( void ) const - { - return order_value; - } - - order_type error_order( void ) const - { - return order_value - 1; - } - - - - - template< class System > - void do_step( System sys , state_type &x , time_type t , time_type dt ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - - do_step( sys , x , t , x , dt ); - } - - template< class System > - void do_step( System sys , const state_type &in , time_type t , state_type &out , time_type dt ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - - typedef typename boost::fusion::result_of::transform< System , taylor_adf::optimize_tree >::type optimized_system_type; - - optimized_system_type optimized_system = boost::fusion::transform( sys , taylor_adf::optimize_tree() ); - - for( size_t i=0 ; i >( make_eval_derivs( optimized_system , in , m_derivs , i , dt ) ); - } - - for( size_t i=0 ; i - void do_step( System sys , state_type &x , time_type t , time_type dt , state_type &xerr ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - BOOST_STATIC_ASSERT(( order_value > 1 )); - - do_step( sys , x , t , x , dt , xerr ); - } - - template< class System > - void do_step( System sys , const state_type &in , time_type t , state_type &out , time_type dt , state_type &xerr ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - BOOST_STATIC_ASSERT(( order_value > 1 )); - - for( size_t i=0 ; i >( make_eval_derivs( sys , in , m_derivs , i , dt ) ); - } - - for( size_t i=0 ; i - -#include -#include -#include -#include - - - - -namespace boost { -namespace numeric { -namespace odeint { - - -/* - * explicit stepper version - */ -template -< - class TaylorStepper -> -class taylor_controller -{ - -public: - - typedef TaylorStepper stepper_type; - typedef typename stepper_type::state_type state_type; - typedef typename stepper_type::value_type value_type; - typedef typename stepper_type::deriv_type deriv_type; - typedef typename stepper_type::time_type time_type; - typedef typename stepper_type::order_type order_type; - typedef default_error_checker< value_type > error_checker_type; - typedef controlled_stepper_tag stepper_category; - - - taylor_controller( - value_type eps_abs = static_cast< value_type >( 1.0e-6 ) , - value_type eps_rel = static_cast< value_type >( 1.0e-6 ) , - value_type a_x = static_cast< value_type >( 1.0 ) , - value_type a_dxdt = static_cast< value_type >( 1.0 ) , - const stepper_type &stepper = stepper_type() - ) - : m_stepper( stepper ) , - m_error_checker( eps_abs , eps_rel , a_x , a_dxdt ) , - m_xerr() , m_xnew() - { - } - - - template< class System > - controlled_step_result try_step( System system , state_type &x , time_type &t , time_type &dt ) - { - controlled_step_result res = try_step( system , x , t , m_xnew , dt ); - if( ( res == success_step_size_increased ) || ( res == success_step_size_unchanged ) ) - { - x = m_xnew; - } - return res; - } - - - template< class System > - controlled_step_result try_step( System system , state_type &in , time_type &t , state_type &out , time_type &dt ) - { - using std::max; - using std::min; - using std::pow; - - // do one step with error calculation - m_stepper.do_step( system , in , t , out , dt , m_xerr ); - - value_type max_rel_error = m_error_checker.error( in , m_stepper.get_last_derivs()[0] , m_xerr , dt ); - - if( max_rel_error > 1.1 ) - { - // error too large - decrease dt ,limit scaling factor to 0.2 and reset state - dt *= max( 0.9 * pow( max_rel_error , -1.0 / ( m_stepper.error_order() - 1.0 ) ) , 0.2 ); - return step_size_decreased; - } - else - { - if( max_rel_error < 0.5 ) - { - //error too small - increase dt and keep the evolution and limit scaling factor to 5.0 - t += dt; - dt *= min( 0.9 * pow( max_rel_error , -1.0 / m_stepper.stepper_order() ) , 5.0 ); - return success_step_size_increased; - } - else - { - t += dt; - return success_step_size_unchanged; - } - } - } - - - stepper_type& stepper( void ) - { - return m_stepper; - } - - const stepper_type& stepper( void ) const - { - return m_stepper; - } - - -private: - - - - stepper_type m_stepper; - error_checker_type m_error_checker; - state_type m_xerr; - state_type m_xnew; -}; - - - - - - - - -} // odeint -} // numeric -} // boost - - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_CONTROLLER_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_lorenz_evol_adaptive_statistics.cpp b/libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_lorenz_evol_adaptive_statistics.cpp deleted file mode 100644 index c5e8b687..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_lorenz_evol_adaptive_statistics.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * main.cpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#include -#include - -#include "taylor.hpp" -#include "taylor_controller.hpp" - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#define tab "\t" - -template< typename T , size_t N > -std::ostream& operator<<( std::ostream& out , const std::tr1::array< T , N > &x ) -{ - if( !x.empty() ) out << x[0]; - for( size_t i=1 ; i state_type; - -typedef boost::numeric::odeint::explicit_error_rk54_ck< state_type > rk54_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - - -namespace fusion = boost::fusion; -namespace phoenix = boost::phoenix; -namespace mpl = boost::mpl; - -using namespace std; -using namespace boost::numeric::odeint; -using namespace boost::assign; - -using boost::numeric::odeint::taylor_adf::arg1; -using boost::numeric::odeint::taylor_adf::arg2; -using boost::numeric::odeint::taylor_adf::arg3; - -struct run -{ - vector< double > m_eps_abs_values; - vector< double > m_eps_rel_values; - double m_t_end; - - run( const vector< double > &eps_abs_values , const vector< double > &eps_rel_values , double t_end ) - : m_eps_abs_values( eps_abs_values ) , m_eps_rel_values( eps_rel_values ) , m_t_end( t_end ){ } - - template< class Order > - void operator()( Order ) const - { - static const size_t order = Order::value; - typedef boost::numeric::odeint::taylor< 3 , order > taylor_type; - - boost::timer timer; - - char str[512] = ""; - sprintf( str , "dat/lorenz_taylor_%02d.dat" , int( order ) ); - ofstream fout( str ); - - for( size_t i=0 ; i taylor_controller( eps_abs , eps_rel ); - - state_type x = {{ 10.0 , 10.0 , 10.0 }}; - - timer.restart(); - size_t steps_taylor = integrate_adaptive( taylor_controller , - fusion::make_vector - ( - sigma * ( arg2 - arg1 ) , - R * arg1 - arg2 - arg1 * arg3 , - arg1 * arg2 - b * arg3 - ) , x , 0.0 , m_t_end , 0.1 ); - double time_taylor = timer.elapsed(); - - fout << i << tab << j << tab << eps_abs << tab << eps_rel << tab; - fout << steps_taylor << tab << time_taylor; - fout << endl; - } - fout << endl; - } - - - } -}; - - - - -int main( int argc , char **argv ) -{ - if( argc != 2 ) - { - cerr << "usage taylor_lorenz_eval_adaptive_statistics t_end" << endl; - return -1; - } - double t_end = atof( argv[1] ); - - vector< double > eps_abs_values; - vector< double > eps_rel_values; - - eps_abs_values += 1.0e1 , 1.0 , 1.0e-1 , 1.0e-2 , 1.0e-3 , 1.0e-4 , 1.0e-5 , 1.0e-6 , 1.0e-7 , 1.0e-8 , 1.0e-9 , 1.0e-10 , 1.0e-11 , 1.0e-12 , 1.0e-13 , 1.0e-14; - eps_rel_values += 1.0e-1 , 1.0e-2 , 1.0e-3 , 1.0e-4 , 1.0e-5 , 1.0e-6 , 1.0e-7 , 1.0e-8 , 1.0e-9 , 1.0e-10 , 1.0e-11 , 1.0e-12 , 1.0e-13 , 1.0e-14; - - - typedef mpl::range_c< size_t , 5 , 30 > order_values; - mpl::for_each< order_values >( run( eps_abs_values , eps_rel_values , t_end ) ); - - - boost::timer timer; - ofstream fout( "dat/lorenz_rk54.dat" ); - for( size_t i=0 ; i rk54( rk54_plain , default_error_checker< double >( eps_abs , eps_rel ) ); - - state_type x = {{ 10.0 , 10.0 , 10.0 }}; - - timer.restart(); - size_t steps_rk54 = integrate_adaptive( rk54 , lorenz , x , 0.0 , t_end , 0.1 ); - double time_rk54 = timer.elapsed(); - - fout << i << tab << j << tab << eps_abs << tab << eps_rel << tab; - fout << steps_rk54 << tab << time_rk54 << tab; - fout << endl; - } - fout << endl; - } - - return 0; -} diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_lorenz_evol_direct.cpp b/libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_lorenz_evol_direct.cpp deleted file mode 100644 index db7e3c1f..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_lorenz_evol_direct.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * main.cpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#include - -#include "taylor.hpp" - -// #include - -#include - -template< typename T , size_t N > -std::ostream& operator<<( std::ostream& out , const std::tr1::array< T , N > &x ) -{ - if( !x.empty() ) out << x[0]; - for( size_t i=1 ; i taylor_type; -typedef taylor_type::state_type state_type; -// typedef boost::numeric::odeint::explicit_rk4< state_type > rk4_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -//void lorenz( const state_type &x , state_type &dxdt , double t ) -//{ -// dxdt[0] = sigma * ( x[1] - x[0] ); -// dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; -// dxdt[2] = x[0]*x[1] - b * x[2]; -//} - - - - - -namespace fusion = boost::fusion; - -using namespace std; -using namespace boost::numeric::odeint; - -using boost::numeric::odeint::taylor_adf::arg1; -using boost::numeric::odeint::taylor_adf::arg2; -using boost::numeric::odeint::taylor_adf::arg3; - -int main( int argc , char **argv ) -{ - taylor_type tay; -// rk4_type rk4; - - - state_type x1 = {{ 10.0 , 10.0 , 10.0 }} , x2 = x1 , xerr = x1; - - const double dt = 0.01; - double t = 0.0; - for( size_t i=0 ; i<100000 ; ++i , t += dt ) - { - tay.do_step( - fusion::make_vector - ( - sigma * ( arg2 - arg1 ) , - R * arg1 - arg2 - arg1 * arg3 , - arg1 * arg2 - b * arg3 - ) , - x1 , t , dt , xerr ); - -// rk4.do_step( lorenz , x2 , t , dt ); -// -// cout << t << "\t" << x1 << "\t" << x2 << "\n"; - } - - - return 0; -} diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_main.cpp b/libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_main.cpp deleted file mode 100644 index 38e42047..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v3/taylor_main.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * main.cpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#include - -#include "taylor.hpp" - -#include - -template< typename T , size_t N > -std::ostream& operator<<( std::ostream& out , const std::tr1::array< T , N > &x ) -{ - if( !x.empty() ) out << x[0]; - for( size_t i=1 ; i taylor_type; -typedef taylor_type::state_type state_type; -typedef taylor_type::derivs_type derivs_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - - - - - -namespace fusion = boost::fusion; - -using namespace std; -using namespace boost::numeric::odeint; - -using boost::numeric::odeint::taylor_adf::arg1; -using boost::numeric::odeint::taylor_adf::arg2; -using boost::numeric::odeint::taylor_adf::arg3; - -int main( int argc , char **argv ) -{ - cout.precision( 14 ); - - taylor_type t; - - state_type in = {{ 10.0 , 10.0 , 10.0 }} , dxdt = {{ 0.0 , 0.0 , 0.0 }} , xerr = {{ 0.0 , 0.0 , 0.0 }} , out = {{ 0.0 ,0.0 , 0.0 }}; - - lorenz( in , dxdt , 0.0 ); - - cout << in << endl; - cout << dxdt << endl << endl; - - t.do_step( - fusion::make_vector - ( - sigma * ( arg2 - arg1 ) , - R * arg1 - arg2 - arg1 * arg3 , - arg1 * arg2 - b * arg3 - ) , - in , 0.0 , out , 0.1 , xerr ); - - - - cout << endl; - cout << in << endl; - cout << xerr << endl; - cout << out << endl << endl; - const derivs_type &derivs = t.get_last_derivs(); - for( size_t i=0 ; iBOOST_ALL_NO_LIB=1 - ../../../../../.. - ; - -exe taylor_main : taylor_main.cpp ; -exe taylor_lorenz_evol_adaptive_statistics : taylor_lorenz_evol_adaptive_statistics.cpp ; \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/taylor/taylor_v4/taylor.hpp b/libs/numeric/odeint/ideas/taylor/taylor_v4/taylor.hpp deleted file mode 100644 index 768bb4e4..00000000 --- a/libs/numeric/odeint/ideas/taylor/taylor_v4/taylor.hpp +++ /dev/null @@ -1,565 +0,0 @@ -/* - * taylor.hpp - * - * Created on: Apr 2, 2011 - * Author: karsten - */ - -#ifndef BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_HPP_ -#define BOOST_NUMERIC_ODEINT_STEPPER_TAYLOR_HPP_ - -#include -#include -#include - -#include -using namespace std; -#define tab "\t" - -// general boost includes -#include -#include -#include - -// fusion includes -#include -#include -#include -#include - -// mpl includes -#include -#include - -// proto includes -#include - -/* - * OK # dt entfernen aus context - * OK # do_step zu try_step - * OK # Skalierung - * OK -- dt_fac # Namen für Skalierungsfaktor finden - * OK # Faktor einschleusen in context - * OK # Nach jedem Durchgang einer Ordnung Skalierungsfaktor neu berechnen und schon - * berechnete Ableitungen skalieren - * # Fehler als Member parameter - * # Fehler anhand der hoechsten Ableitung berechnen - * # Schrittweite bestimmen - * # Schritt ausfuehren - */ - - -namespace boost { -namespace numeric { -namespace odeint { - - -namespace taylor_adf -{ - - namespace proto = boost::proto; - namespace fusion = boost::fusion; - namespace proto = boost::proto; - - template< typename I > struct placeholder : I {}; - - proto::terminal< placeholder< mpl::size_t< 0 > > >::type const arg1 = {}; - proto::terminal< placeholder< mpl::size_t< 1 > > >::type const arg2 = {}; - proto::terminal< placeholder< mpl::size_t< 2 > > >::type const arg3 = {}; - - template< typename I > - std::ostream& operator<<( std::ostream &s , const placeholder< I > &p ) - { - s << "placeholder<" << I::value << ">"; - return s; - } - - - /* - * eventuel array< double , n > dt mit potenzen anlegen - */ - template< class State , size_t MaxOrder > - struct taylor_context - { - typedef State state_type; - typedef boost::array< state_type , MaxOrder > deriv_type; - - size_t which; - const state_type &x; - deriv_type &derivs; - double &dt_fac; - - taylor_context( size_t _which , const state_type &_x , deriv_type &_derivs , double &_dt_fac ) - : which( _which ) , x( _x ) , derivs( _derivs ) , dt_fac( _dt_fac ) { } - }; - - - template< typename Grammar > - struct plus_transform : proto::transform< plus_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Plus transform" << endl; - return Grammar()( proto::left( expr ) , state , data ) - + Grammar()( proto::right( expr ) , state , data ); - } - }; - }; - - - template< typename Grammar > - struct minus_transform : proto::transform< minus_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Minus transform" << endl; - return Grammar()( proto::left( expr ) , state , data ) - - Grammar()( proto::right( expr ) , state , data ); - } - }; - }; - - - - template< typename Grammar > - struct multiplies_transform : proto::transform< multiplies_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Multiplies transform" << endl; - typedef typename impl::data data_type; - - double tmp = 0.0; - for( size_t k=0 ; k<=data.which ; ++k ) - { - data_type data1( k , data.x , data.derivs , data.dt_fac ); - data_type data2( data.which - k , data.x , data.derivs , data.dt_fac ); - -// tmp += boost::math::binomial_coefficient< double >( data.which , k ) -// * Grammar()( proto::left( expr ) , state , data1 ) -// * Grammar()( proto::right( expr ) , state , data2 ); - - tmp += Grammar()( proto::left( expr ) , state , data1 ) - * Grammar()( proto::right( expr ) , state , data2 ); - - } - - return tmp; - } - }; - }; - - - struct terminal_double_transform : proto::transform< terminal_double_transform > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Terminal double transform" << endl; - return ( data.which == 0 ) ? proto::value( expr ) : 0.0; - } - }; - }; - - - template< typename Index > - struct terminal_placeholder_transform : proto::transform< terminal_placeholder_transform< Index > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Terminal placeholder transform" << endl; - typedef typename impl::expr expr_type; - typedef typename expr_type::proto_args args_type; - typedef typename args_type::child0 index_type; - const size_t index = index_type::value; - - return ( data.which == 0 ) ? data.x[ index ] : data.derivs[ data.which - 1 ][ index ]; - } - }; - }; - - template< typename Grammar > - struct right_shift_transform : proto::transform< right_shift_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Right shift transform" << endl; - return Grammar()( proto::left( expr ) , state , data ) - + ( data.which == 0 ) ? proto::value( proto::right( expr ) ) : 0.0; - } - }; - }; - - template< typename Grammar > - struct left_shift_transform : proto::transform< left_shift_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Right shift transform" << endl; - return Grammar()( proto::right( expr ) , state , data ) - + ( data.which == 0 ) ? proto::value( proto::left( expr ) ) : 0.0; - } - }; - }; - - - template< typename Grammar > - struct right_scalar_multiplies_transform : proto::transform< right_scalar_multiplies_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Right scalar multiplies transform" << endl; - return Grammar()( proto::left( expr ) , state , data ) * proto::value( proto::right( expr ) ); - } - }; - }; - - template< typename Grammar > - struct left_scalar_multiplies_transform : proto::transform< left_scalar_multiplies_transform< Grammar > > - { - template< typename Expr , typename State , typename Data > - struct impl : proto::transform_impl< Expr , State , Data > - { - typedef double result_type; - - result_type operator ()( - typename impl::expr_param expr , - typename impl::state_param state , - typename impl::data_param data ) const - { -// cout << "Left scalar multiplies transform" << endl; - return Grammar()( proto::right( expr ) , state , data ) * proto::value( proto::left( expr ) ); - } - }; - }; - - - - - - struct taylor_double_terminal : proto::when< proto::terminal< double > , terminal_double_transform > { }; - - template< typename Which > - struct taylor_placeholder_terminal : proto::when< proto::terminal< placeholder< Which > > , terminal_placeholder_transform< Which > > { }; - - template< typename Grammar > - struct taylor_plus : proto::when< proto::plus< Grammar , Grammar > , plus_transform< Grammar > > { }; - - template< typename Grammar > - struct taylor_minus : proto::when< proto::minus< Grammar , Grammar > , minus_transform< Grammar > > { }; - - template< typename Grammar > - struct taylor_multiplies : proto::when< proto::multiplies< Grammar , Grammar > , multiplies_transform< Grammar > > { }; - - template< typename Grammar > - struct taylor_shift : - proto::or_< - proto::when< proto::plus< Grammar , proto::terminal< double > > , right_shift_transform< Grammar > > , - proto::when< proto::plus< proto::terminal< double > , Grammar > , left_shift_transform< Grammar > > - > { }; - - template< typename Grammar > - struct taylor_scalar_multiplies : - proto::or_< - proto::when< proto::multiplies< Grammar , proto::terminal< double > > , right_scalar_multiplies_transform< Grammar > > , - proto::when< proto::multiplies< proto::terminal< double > , Grammar > , left_scalar_multiplies_transform< Grammar > > - > { }; - - - - - - struct taylor_transform : - proto::or_ - < - taylor_shift< taylor_transform > , - taylor_scalar_multiplies< taylor_transform > , - taylor_double_terminal , - taylor_placeholder_terminal< proto::_ > , - taylor_plus< taylor_transform > , - taylor_minus< taylor_transform > , - taylor_multiplies< taylor_transform > - > - { }; - - - template< class System , class State , size_t Order > - struct eval_derivs - { - typedef State state_type; - typedef taylor_context< state_type , Order > taylor_context_type; - typedef typename taylor_context_type::deriv_type deriv_type; - - System m_sys; - taylor_context_type m_data; - - eval_derivs( System sys , const State &x , deriv_type &derivs , double &dt_fac , size_t which ) - : m_sys( sys ) , m_data( which , x , derivs , dt_fac ) { } - - template< class Index > - void operator()( Index ) - { - typedef typename fusion::result_of::at< System , Index >::type expr_type; - - /* Mario: changed to make it compile with msvc 9.0 - * error: invalid type: reference to reference - */ -// const expr_type &expr = boost::fusion::at< Index >( m_sys ); - expr_type expr = boost::fusion::at< Index >( m_sys ); - /* end changes */ - - double deriv = taylor_transform()( expr , 0.0 , m_data ); - m_data.derivs[ m_data.which ][ Index::value ] = m_data.dt_fac / double( m_data.which + 1 ) * deriv; - } - }; - - template< class System , class State , size_t Order > - eval_derivs< System , State , Order > make_eval_derivs( System sys , const State &x , boost::array< State , Order > &derivs , double &dt_fac , size_t i ) - { - return eval_derivs< System , State , Order >( sys , x , derivs , dt_fac , i ); - } -} - -template< size_t N , size_t Order > -class taylor -{ -public: - - static const size_t dim = N; - static const size_t order_value = Order; - typedef double value_type; - typedef value_type time_type; - typedef unsigned short order_type; - - typedef boost::array< value_type , dim > state_type; - typedef state_type deriv_type; - typedef boost::array< state_type , order_value > derivs_type; - - taylor( value_type rel_error = 1.0e-14 , value_type abs_error = 1.0e-14 ) - : m_derivs() , m_dt_fac( 1.0 ) , m_rel_error( rel_error ) , m_abs_error( abs_error ) { } - - order_type order( void ) const - { - return order_value; - } - - order_type stepper_order( void ) const - { - return order_value; - } - - order_type error_order( void ) const - { - return order_value - 1; - } - - - - - template< class System > - void try_step( System sys , state_type &x , time_type &t , time_type &dt ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - - try_step( sys , x , t , x , dt ); - } - - template< class System > - void try_step( System sys , const state_type &in , time_type &t , state_type &out , time_type &dt ) - { - BOOST_STATIC_ASSERT(( boost::fusion::traits::is_sequence< System >::value )); - BOOST_STATIC_ASSERT(( size_t( boost::fusion::result_of::size< System >::value ) == dim )); - - eval_derivs( sys , in , m_derivs , m_dt_fac ); - - double max_error = 0.0; - for( size_t i=0 ; i - void eval_derivs( System sys , const state_type &in , derivs_type &der , double &dt_fac ) const - { - const double min_error = 1.0e-19; - const double max_error = 1.0e19; - const double min_fac = 1.5; - const double max_fac = 0.6; - - for( size_t i=0 ; i >( make_eval_derivs( sys , in , der , dt_fac , i ) ); - -// clog << i << tab << "Deriv : "; -// for( size_t j=0 ; j max_error ) - { -// clog << i << tab << "max_error : " << err << tab << dt_fac << endl; - scale_derivs( der , i , max_fac ); - dt_fac *= max_fac; - continue; - } - break; - } - - } - - } - - void scale_derivs( derivs_type &der , size_t order , double fac ) const - { - double scale = 1.0; - for( size_t i=0 ; i<=order ; ++i ) - { - scale *= fac; - for( size_t j=0 ; j -#include - -#include -#include -#include -#include -#include -#include -#include -#include - - -#include -#include -#include -#include - -#include -#include - -#include "taylor.hpp" - -#define tab "\t" - -template< typename T , size_t N > -std::ostream& operator<<( std::ostream& out , const boost::array< T , N > &x ) -{ - if( !x.empty() ) out << x[0]; - for( size_t i=1 ; i state_type; - -typedef boost::numeric::odeint::runge_kutta_cash_karp54< state_type > rk54_type; -typedef boost::numeric::odeint::runge_kutta_dopri5< state_type > dopri5_type; -typedef boost::numeric::odeint::runge_kutta_fehlberg78< state_type > fehlberg_type; -typedef boost::numeric::odeint::bulirsch_stoer< state_type > bulirsch_stoer_type; - - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -void lorenz( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0]*x[1] - b * x[2]; -} - -struct print { - ofstream &m_out; - print( ofstream &out ) - : m_out( out ) - { } - - void operator()( const state_type &x , const double t ) - { - m_out << x[0] << tab << x[1] << tab << x[2] << endl; - } -}; - -namespace fusion = boost::fusion; -namespace phoenix = boost::phoenix; -namespace mpl = boost::mpl; - -using namespace std; -using namespace boost::numeric::odeint; -using namespace boost::assign; - -using boost::numeric::odeint::taylor_adf::arg1; -using boost::numeric::odeint::taylor_adf::arg2; -using boost::numeric::odeint::taylor_adf::arg3; - -struct run -{ - vector< double > m_eps_abs_values; - vector< double > m_eps_rel_values; - double m_t_end; - - run( const vector< double > &eps_abs_values , const vector< double > &eps_rel_values , double t_end ) - : m_eps_abs_values( eps_abs_values ) , m_eps_rel_values( eps_rel_values ) , m_t_end( t_end ){ } - - template< class Order > - void operator()( Order ) const - { - static const size_t order = Order::value; - typedef boost::numeric::odeint::taylor< 3 , order > taylor_type; - - boost::timer timer; - - char str[512] = ""; - sprintf( str , "dat/lorenz_taylor_%02d.dat" , int( order ) ); - ofstream fout( str ); - - for( size_t i=0 ; i eps_abs_values; - vector< double > eps_rel_values; - - eps_abs_values += 1.0e1 , 1.0 , 1.0e-1 , 1.0e-2 , 1.0e-3 , 1.0e-4 , 1.0e-5 , 1.0e-6 , 1.0e-7 , 1.0e-8 , 1.0e-9 , 1.0e-10 , 1.0e-11 , 1.0e-12 , 1.0e-13 , 1.0e-14; - eps_rel_values += 1.0e-1 , 1.0e-2 , 1.0e-3 , 1.0e-4 , 1.0e-5 , 1.0e-6 , 1.0e-7 , 1.0e-8 , 1.0e-9 , 1.0e-10 , 1.0e-11 , 1.0e-12 , 1.0e-13 , 1.0e-14; - - - typedef mpl::range_c< size_t , 5 , 30 > order_values; - mpl::for_each< order_values >( run( eps_abs_values , eps_rel_values , t_end ) ); - - - boost::timer timer; - ofstream fout1( "dat/lorenz_rk54.dat" ); - ofstream fout2( "dat/lorenz_dopri5.dat" ); - ofstream fout3( "dat/lorenz_fehlberg.dat" ); - ofstream fout4( "dat/lorenz_bs.dat" ); - - ofstream wf_out( "dat/bs.dat" ); - - for( size_t i=0 ; i -#include - -#include "taylor.hpp" - -#include - -//template< typename T , size_t N > -//std::ostream& operator<<( std::ostream& out , const boost::array< T , N > &x ) -//{ -// if( !x.empty() ) out << x[0]; -// for( size_t i=1 ; i taylor_type; -typedef taylor_type::state_type state_type; -typedef taylor_type::derivs_type derivs_type; - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - - - - - - -namespace fusion = boost::fusion; - -using namespace std; -using namespace boost::numeric::odeint; - -using boost::numeric::odeint::taylor_adf::arg1; -using boost::numeric::odeint::taylor_adf::arg2; -using boost::numeric::odeint::taylor_adf::arg3; - -int main( int argc , char **argv ) -{ -// cout.precision( 14 ); - - taylor_type stepper( 1.0e-17 , 1.0e-35 ); - - - state_type x = {{ 10.0 , 10.0 , 10.0 }} ; - - double t = 0.0; - double dt = 1.0; -// for( size_t i=0 ; i<10000 ; ++i ) -// { -// stepper.try_step( -// fusion::make_vector -// ( -// sigma * ( arg2 - arg1 ) , -// R * arg1 - arg2 - arg1 * arg3 , -// arg1 * arg2 - b * arg3 -// ) , -// x , t , dt ); -// cout << i << "\t" << t << "\t" << x << "\n"; -// } - -// ofstream fout( "lorenz.dat" ); - size_t count = 0; - while( t < 100000.0 ) - { - stepper.try_step( - fusion::make_vector - ( - sigma * ( arg2 - arg1 ) , - R * arg1 - arg2 - arg1 * arg3 , - arg1 * arg2 - b * arg3 - ) , - x , t , dt ); - -// fout << t << "\t" << x << endl; - ++count; - } - clog << count << endl; - - return 0; -} diff --git a/libs/numeric/odeint/ideas/units/Jamfile b/libs/numeric/odeint/ideas/units/Jamfile deleted file mode 100644 index 29f1910d..00000000 --- a/libs/numeric/odeint/ideas/units/Jamfile +++ /dev/null @@ -1,24 +0,0 @@ -# (C) Copyright 2010 : Karsten Ahnert, 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) - -import os ; -import modules ; -import path ; - -path-constant HOME : [ os.environ HOME ] ; -#path-constant CHRONO_ROOT : [ os.environ CHRONO_ROOT ] ; - -project - : requirements - BOOST_ALL_NO_LIB=1 - ../../../../.. - ; - -exe test_units - : test_units.cpp - ; - -# exe test_ranges -# : test_ranges.cpp -# ; \ No newline at end of file diff --git a/libs/numeric/odeint/ideas/units/adjust_size_units.hpp b/libs/numeric/odeint/ideas/units/adjust_size_units.hpp deleted file mode 100644 index bf4b4532..00000000 --- a/libs/numeric/odeint/ideas/units/adjust_size_units.hpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - boost header: NUMERIC_ODEINT/adjust_size.hpp - - Copyright 2009 Karsten Ahnert - Copyright 2009 Mario Mulansky - Copyright 2009 Andre Bergner - - 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_ADJUST_SIZE_UNITS_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_ADJUST_SIZE_UNITS_HPP_INCLUDED - -#include - -#include -#include - -#include - - -namespace boost { -namespace numeric { -namespace odeint { - - - - - - - - -/* - * Adjust size functionality with policies and resizeability - */ -template< class Deriv , size_t Dim > -class size_adjuster_units : boost::noncopyable -{ -public: - - size_adjuster_units() : m_is_initialized( false ) , m_states() - { - std::fill( m_states.begin() , m_states.end() , static_cast< Deriv* >( 0 ) ); - } - - template< class State > - bool adjust_size( const State &x ) - { - return adjust_size_by_resizeability( x , typename is_resizeable< Deriv >::type() ); - } - - template< class State > - bool adjust_size_by_policy( const State &x , adjust_size_manually_tag ) - { - return false; - } - - template< class State > - bool adjust_size_by_policy( const State &x , adjust_size_initially_tag ) - { - if( !m_is_initialized ) - { - m_is_initialized = true; - return adjust_size_by_resizeability( x , typename is_resizeable< Deriv >::type() ); - } - else - { - return false; - } - } - - template< class State > - bool adjust_size_by_policy( const State &x , adjust_size_always_tag ) - { - return adjust_size_by_resizeability( x , typename is_resizeable< Deriv >::type() ); - } - - void register_state( size_t idx , Deriv &x ) - { - m_states[idx] = &x; - } - - -private: - - template< class State > - bool adjust_size_by_resizeability( const State &x , boost::true_type ) - { - for( size_t i=0 ; i 0 ); - } - - template< class State > - bool adjust_size_by_resizeability( const State &x , boost::false_type ) - { - return false; - } - - -private : - - bool m_is_initialized; - boost::array< Deriv* , Dim > m_states; -}; - - -} // odeint -} // numeric -} // boost - - -#endif //BOOST_NUMERIC_ODEINT_ADJUST_SIZE_UNITS_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/units/explicit_euler_units.hpp b/libs/numeric/odeint/ideas/units/explicit_euler_units.hpp deleted file mode 100644 index faef49a9..00000000 --- a/libs/numeric/odeint/ideas/units/explicit_euler_units.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - boost header: BOOST_NUMERIC_ODEINT/euler.hpp - - Copyright 2009 Karsten Ahnert - Copyright 2009 Mario Mulansky - Copyright 2009 Andre Bergner - - 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_BOOST_NUMERIC_ODEINT_EXPLICIT_EULER_UNITS_HPP_INCLUDED -#define BOOST_BOOST_NUMERIC_ODEINT_EXPLICIT_EULER_UNITS_HPP_INCLUDED - -#include - -#include "explicit_stepper_base_units.hpp" -#include "standard_operations_units.hpp" - -namespace boost { -namespace numeric { -namespace odeint { - -template< - class Deriv , - class Value = double , - class Time = double , - class Algebra = range_algebra , - class Operations = standard_operations_units , - class AdjustSizePolicy = adjust_size_initially_tag - > -class explicit_euler_units -: public explicit_stepper_base_units< - explicit_euler_units< Deriv , Value , Time , Algebra , Operations , AdjustSizePolicy > , - 1 , Deriv , Value , Time , Algebra , Operations , AdjustSizePolicy > -{ -public : - - typedef explicit_stepper_base_units< - explicit_euler_units< Deriv , Value , Time , Algebra , Operations , AdjustSizePolicy > , - 1 , Deriv , Value , Time , Algebra , Operations , AdjustSizePolicy > stepper_base_type; - typedef typename stepper_base_type::deriv_type deriv_type; - typedef typename stepper_base_type::value_type value_type; - typedef typename stepper_base_type::time_type time_type; - typedef typename stepper_base_type::algebra_type algebra_type; - typedef typename stepper_base_type::operations_type operations_type; - typedef typename stepper_base_type::adjust_size_policy adjust_size_policy; - typedef typename stepper_base_type::stepper_type stepper_type; - - - template< class System , class State > - void do_step_impl( System system , const State &in , const deriv_type &dxdt , const time_type t , State & out , const time_type dt ) - { - algebra_type::for_each3( out , in , dxdt , operations_type::make_scale_sum2( static_cast< value_type >( 1.0 ) , dt ) ); - } -}; - - - - -} // odeint -} // numeric -} // boost - - -#endif //BOOST_BOOST_NUMERIC_ODEINT_EXPLICIT_EULER_UNITS_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/units/explicit_stepper_base_units.hpp b/libs/numeric/odeint/ideas/units/explicit_stepper_base_units.hpp deleted file mode 100644 index 9fab975a..00000000 --- a/libs/numeric/odeint/ideas/units/explicit_stepper_base_units.hpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - boost header: numeric/odeint/explicit_stepper_base.hpp - - Copyright 2009 Karsten Ahnert - Copyright 2009 Mario Mulansky - Copyright 2009 Andre Bergner - - 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_EXPLICIT_STEPPER_BASE_UNITS_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_EXPLICIT_STEPPER_BASE_UNITS_HPP_INCLUDED - -#include -#include - -#include -#include -#include -#include - - -#include "adjust_size_units.hpp" - - -namespace boost { -namespace numeric { -namespace odeint { - -/* - * base class for explicit steppers - * models the stepper concept - */ -template< - class Stepper , - unsigned short Order , - class Deriv , - class Value , - class Time , - class Algebra , - class Operations , - class AdjustSizePolicy -> -class explicit_stepper_base_units : boost::noncopyable -{ -public: - - - typedef Deriv deriv_type; - typedef Value value_type; - typedef Time time_type; - typedef Algebra algebra_type; - typedef Operations operations_type; - typedef AdjustSizePolicy adjust_size_policy; - typedef Stepper stepper_type; - - typedef explicit_stepper_base_units< Stepper , Order , Deriv , Value , Time , Algebra , Operations , AdjustSizePolicy > internal_stepper_base_type; - - typedef unsigned short order_type; - static const order_type order_value = Order; - - - order_type order( void ) const - { - return order_value; - } - - - explicit_stepper_base_units( void ) : m_size_adjuster() , m_dxdt() - { - boost::numeric::odeint::construct( m_dxdt ); - m_size_adjuster.register_state( 0 , m_dxdt ); - } - - ~explicit_stepper_base_units( void ) - { - boost::numeric::odeint::destruct( m_dxdt ); - } - - - - - // do_step( sys , x , t , dt ) - template< class System , class State > - void do_step( System system , State &x , const time_type &t , const time_type &dt ) - { - typename boost::unwrap_reference< System >::type &sys = system; - m_size_adjuster.adjust_size_by_policy( x , adjust_size_policy() ); - sys( x , m_dxdt ,t ); - this->stepper().do_step_impl( system , x , m_dxdt , t , x , dt ); - } - - // do_step( sys , x , dxdt , t , dt ) - template< class System , class State > - void do_step( System system , State &x , const deriv_type dxdt , const time_type &t , const time_type &dt ) - { - this->stepper().do_step_impl( system , x , dxdt , t , x , dt ); - } - - // do_step( sys , in , t , out , dt ) - template< class System , class State > - void do_step( System system , const State &in , const time_type &t , State &out , const time_type &dt ) - { - typename boost::unwrap_reference< System >::type &sys = system; - m_size_adjuster.adjust_size_by_policy( in , adjust_size_policy() ); - sys( in , m_dxdt ,t ); - this->stepper().do_step_impl( system , in , m_dxdt , t , out , dt ); - } - - // do_step( sys , in , dxdt , t , out , dt ) - template< class System , class State > - void do_step( System system , const State &in , const deriv_type &dxdt , const time_type &t , State &out , const time_type &dt ) - { - this->stepper().do_step_impl( system , in , dxdt , t , out , dt ); - } - - - - template< class State > - void adjust_size( const State &x ) - { - m_size_adjuster.adjust_size( x ); - } - - -protected: - - stepper_type& stepper( void ) - { - return *static_cast< stepper_type* >( this ); - } - - const stepper_type& stepper( void ) const - { - return *static_cast< const stepper_type* >( this ); - } - - - size_adjuster_units< deriv_type , 1 > m_size_adjuster; - deriv_type m_dxdt; -}; - - -} // odeint -} // numeric -} // boost - -#endif //BOOST_NUMERIC_ODEINT_EXPLICIT_STEPPER_BASE_UNITS_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/units/standard_operations_units.hpp b/libs/numeric/odeint/ideas/units/standard_operations_units.hpp deleted file mode 100644 index 1423f7d0..00000000 --- a/libs/numeric/odeint/ideas/units/standard_operations_units.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - boost header: BOOST_NUMERIC_ODEINT/standard_operations.hpp - - Copyright 2009 Karsten Ahnert - Copyright 2009 Mario Mulansky - Copyright 2009 Andre Bergner - - 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_BOOST_NUMERIC_ODEINT_STANDARD_OPERATIONS_UNITS_HPP_INCLUDED -#define BOOST_BOOST_NUMERIC_ODEINT_STANDARD_OPERATIONS_UNITS_HPP_INCLUDED - -#include // for std::max - -namespace boost { -namespace numeric { -namespace odeint { - - - -struct standard_operations_units -{ - template< class Fac1 , class Fac2 > - struct scale_sum2 - { - const Fac1 m_alpha1; - const Fac2 m_alpha2; - - scale_sum2( const Fac1 &alpha1 , const Fac2 &alpha2 ) : m_alpha1( alpha1 ) , m_alpha2( alpha2 ) { } - - template< class T1 , class T2 , class T3 > - void operator()( T1 &t1 , const T2 &t2 , const T3 &t3) const - { - t1 = m_alpha1 * t2 + m_alpha2 * t3; - } - }; - - template< class Fac1 , class Fac2 > - static scale_sum2< Fac1 , Fac2 > make_scale_sum2( const Fac1 &alpha1 , const Fac2 &alpha2 ) - { - return scale_sum2< Fac1 , Fac2 >( alpha1 , alpha2 ); - } - -}; - - -} // odeint -} // numeric -} // boost - - -#endif //BOOST_BOOST_NUMERIC_ODEINT_STANDARD_OPERATIONS_UNITS_HPP_INCLUDED diff --git a/libs/numeric/odeint/ideas/units/test_ranges.cpp b/libs/numeric/odeint/ideas/units/test_ranges.cpp deleted file mode 100644 index df45dacd..00000000 --- a/libs/numeric/odeint/ideas/units/test_ranges.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * test_ranges.cpp - * - * Created on: Jan 18, 2011 - * Author: karsten - */ - -#include -#include -#include - -#include "explicit_euler_units.hpp" - -typedef std::vector< double > deriv_type; - -typedef boost::numeric::odeint::explicit_euler_units< deriv_type > stepper_type; - -struct harm_osc -{ - template< class State , class Deriv > - void operator()( const State &x , Deriv &dxdt , double t ) - { - dxdt[0] = x[1]; - dxdt[1] = -x[0]; - } -}; - -int main( int argc , char **argv ) -{ - stepper_type stepper; - std::tr1::array< double , 2 > x = {{ 1.0 , 0.0 }}; - stepper.do_step( harm_osc() , x , 0.0 , 0.1 ); -} diff --git a/libs/numeric/odeint/ideas/units/test_units.cpp b/libs/numeric/odeint/ideas/units/test_units.cpp deleted file mode 100644 index 2ed29003..00000000 --- a/libs/numeric/odeint/ideas/units/test_units.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * test.cpp - * - * Created on: Jan 18, 2011 - * Author: karsten - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "explicit_euler_units.hpp" - -namespace units = boost::units; -namespace si = boost::units::si; - -using std::cout; -using std::endl; - -typedef units::quantity< si::length > length_type; -typedef units::quantity< si::velocity > vel_type; -typedef units::quantity< si::time > time_type; - -typedef std::tr1::array< length_type , 2 > state_type; -typedef std::tr1::array< vel_type , 2 > deriv_type; - - -typedef boost::numeric::odeint::explicit_euler_units< deriv_type , double , time_type > stepper_type; - -struct lorenz -{ - template< class State , class Deriv , class Time > - void operator()( const State &x , Deriv &dxdt , const Time &t ) - { - dxdt[0] = ( x[0] / Time( 1.0 * si::second ) ); - dxdt[1] = ( x[1] / Time( 1.0 * si::second ) ); - } -}; - - - -int main( int argc , char **argv ) -{ - state_type x = {{ 1.0 * si::meter , 1.0 * si::meter }}; - time_type t( 0.0 * si::seconds ) , dt( 0.0 * si::seconds ); - stepper_type stepper; - stepper.do_step( lorenz() , x , t , dt ); - - vel_type a( 1.0 * si::meter / si::seconds ); - -// units::quantity< si::length > x( 2.0 * si::meter ); -// units::quantity< si::time > t( 1.0 * si::second ); -// cout << x * t << endl; - - return 0; -} diff --git a/libs/numeric/odeint/regression_test/Jamfile b/libs/numeric/odeint/regression_test/Jamfile deleted file mode 100644 index b6985ea6..00000000 --- a/libs/numeric/odeint/regression_test/Jamfile +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright 2009 Karsten Ahnert and 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) - - -project - : requirements - ../../../.. - ../../../../../.. - ; - -exe controlled_stepper_evolution - : controlled_stepper_evolution.cpp - ; - -exe dense_output_stepper_evolution - : dense_output_stepper_evolution.cpp - ; - -exe dense_output_explicit - : dense_output_explicit.cpp - ; - -exe dense_output_controlled_explicit - : dense_output_controlled_explicit.cpp - ; - -exe rosenbrock4 - : rosenbrock4.cpp - ; - -exe integrate_functions - : integrate_functions.cpp - ; - -exe hamiltonian_steppers - : hamiltonian_steppers.cpp - ; - -exe adams_bashforth - : adams_bashforth.cpp - ; - -exe adams_bashforth_moulton - : adams_bashforth_moulton.cpp - ; - \ No newline at end of file diff --git a/libs/numeric/odeint/regression_test/adams_bashforth.cpp b/libs/numeric/odeint/regression_test/adams_bashforth.cpp deleted file mode 100644 index b1da0db3..00000000 --- a/libs/numeric/odeint/regression_test/adams_bashforth.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * adams_bashforth.cpp - * - * Created on: May 18, 2011 - * Author: karsten - */ - -#include -#include - -#include -#include -#include -#include - -using namespace std; -using namespace boost::numeric::odeint; - -typedef double value_type; -typedef boost::array< value_type , 3 > state_type; - -struct lorenz -{ - template< class State , class Deriv , class Value > - void operator()( const State &_x , Deriv &_dxdt , const Value &dt ) const - { - const value_type sigma = 10.0; - const value_type R = 28.0; - const value_type b = 8.0 / 3.0; - - 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] = x[0]*x[1] - b * x[2]; - } -}; - -struct writing_observer -{ - std::ostream &m_out; - writing_observer( std::ostream &out ) : m_out( out ) { } - - template< class State , class Value > - void operator()( const State &x , const Value &t ) - { - m_out << t << "\t" << x[0] << "\t" << x[1] << "\t" << x[2] << "\n"; - } -}; - - -int main( int argc , char **argv ) -{ - state_type x = {{ 10.0 , 10.0 , 10.0 }}; - - const double dt = 0.01; - double t = 0.0; - - adams_bashforth< 3 , state_type > stepper; - euler< state_type > euler; - stepper.initialize( euler , lorenz() , x , t , dt ); - - integrate_n_steps( stepper , lorenz() , x , 0.0 , 0.01 , 10000 , writing_observer( cout ) ); -} diff --git a/libs/numeric/odeint/regression_test/adams_bashforth_moulton.cpp b/libs/numeric/odeint/regression_test/adams_bashforth_moulton.cpp deleted file mode 100644 index f7324d0f..00000000 --- a/libs/numeric/odeint/regression_test/adams_bashforth_moulton.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * adams_bashforth.cpp - * - * Created on: May 18, 2011 - * Author: karsten - */ - -#include -#include - -#include -#include -#include - -using namespace std; -using namespace boost::numeric::odeint; - -typedef double value_type; -typedef boost::array< value_type , 3 > state_type; - -struct lorenz -{ - template< class State , class Deriv , class Value > - void operator()( const State &_x , Deriv &_dxdt , const Value &dt ) const - { - const value_type sigma = 10.0; - const value_type R = 28.0; - const value_type b = 8.0 / 3.0; - - 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] = x[0]*x[1] - b * x[2]; - } -}; - -struct writing_observer -{ - std::ostream &m_out; - writing_observer( std::ostream &out ) : m_out( out ) { } - - template< class State , class Value > - void operator()( const State &x , const Value &t ) - { - m_out << t << "\t" << x[0] << "\t" << x[1] << "\t" << x[2] << "\n"; - } -}; - - -int main( int argc , char **argv ) -{ - state_type x = {{ 10.0 , 10.0 , 10.0 }}; - - const double dt = 0.01; - double t = 0.0; - - adams_bashforth_moulton< 5 , state_type > stepper; - stepper.initialize( lorenz() , x , t , dt ); - - integrate_n_steps( stepper , lorenz() , x , t , dt , 10000 , writing_observer( cout ) ); -} diff --git a/libs/numeric/odeint/regression_test/controlled_stepper_evolution.cpp b/libs/numeric/odeint/regression_test/controlled_stepper_evolution.cpp deleted file mode 100644 index 977f6fab..00000000 --- a/libs/numeric/odeint/regression_test/controlled_stepper_evolution.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * controlled_stepper_evolution.cpp - * - * Created on: Nov 2, 2010 - * Author: karsten - */ - -#include -#include -#include -#include - -#include -#include -#include - -#define tab "\t" - -using namespace std; -using namespace boost::numeric::odeint; - - -typedef boost::array< double , 2 > state_type; - -ostream& operator<<( ostream &out , const state_type &x ) -{ - out << x[0] << tab << x[1]; - return out; -} - -void sys( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = x[1]; - dxdt[1] = -x[0]; -} - -state_type sys_solution( double t , const state_type &x0 ) -{ - state_type sol = {{ 0.0 , 0.0 }}; - sol[0] = x0[0] * cos( t ) + x0[1] * sin( t ); - sol[1] = -x0[0] * sin( t ) + x0[1] * cos( t ); - return sol; -} - - - -template< class Stepper > -void evolution( Stepper &stepper , double t_end , const state_type &x0 , const string &filename ) -{ - ofstream fout( filename.c_str() ); - state_type x = x0; - double t = 0.0 , dt = 0.01; - while( t < t_end ) - { - state_type orig = sys_solution( t , x0 ); - state_type diff = {{ orig[0] - x[0] , orig[1] - x[1] }}; - double diff_abs = sqrt( diff[0] * diff[0] + diff[1] * diff[1] ); - fout << t << tab << orig << tab << x << tab << diff << tab << diff_abs << endl; - stepper.try_step( sys , x , t , dt ); - } -} - - -int main( int argc , char **argv ) -{ - typedef runge_kutta_cash_karp54_classic< state_type > rk54_type; - typedef runge_kutta_dopri5< state_type > dopri5_type; - - controlled_runge_kutta< rk54_type > rk54_controlled; - controlled_runge_kutta< dopri5_type > dopri5_controlled; - - state_type x0 = {{ 1.25 , 0.43 }}; - evolution( rk54_controlled , 100.0 , x0 , "rk54.dat" ); - evolution( dopri5_controlled , 100.0 , x0 , "dopri5.dat" ); - - return 0; -} diff --git a/libs/numeric/odeint/regression_test/dense_output_controlled_explicit.cpp b/libs/numeric/odeint/regression_test/dense_output_controlled_explicit.cpp deleted file mode 100644 index 0cc30508..00000000 --- a/libs/numeric/odeint/regression_test/dense_output_controlled_explicit.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * dense_output_explicit_controlled_fsal.cpp - * - * Created on: Jan 28, 2011 - * Author: karsten - */ - -#include -#include -#include - -#include -#include -#include - -using namespace std; -using namespace boost::numeric::odeint; - -typedef vector< double > state_type; -typedef runge_kutta_dopri5< state_type > dopri5_type; -typedef controlled_runge_kutta< dopri5_type > controlled_error_stepper_type; -typedef dense_output_runge_kutta< controlled_error_stepper_type > stepper_type; - - -struct lorenz -{ - template< class State , class Deriv > - void operator()( const State &x , Deriv &dxdt , double t ) - { - const double sigma = 10.0; - const double R = 28.0; - const double 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] = x[0]*x[1] - b * x[2]; - } -}; - - - -int main( int argc , char **argv ) -{ - stepper_type stepper; - - state_type x_start( 3 ); - x_start[0] = 10.0 , x_start[1] = 10.0 ; x_start[2] = 20.0; - - const double dt1 = 0.025 , dt2 = 0.01; - stepper.initialize( x_start , 0.0 , dt1 ); - - ofstream fout( "test.dat" ); - ofstream fout2( "test2.dat" ); - state_type x( 3 ); - double t = 0.0; - while( stepper.current_time() < 10.0 ) - { - while( t < stepper.current_time() ) - { - stepper.calc_state( t , x ); - fout << t << " " << x[0] << " " << x[1] << " " << x[2] << endl; - t += dt2; - } - stepper.do_step( lorenz() ); - const state_type ¤t = stepper.current_state(); - fout2 << stepper.current_time() << " " << stepper.current_time_step() << " " << current[0] << " " << current[1] << " " << current[2] << " " << endl; - } - - - // compare with the controlled dopri5 - { - controlled_error_stepper_type controlled_stepper; - ofstream fout3( "test3.dat" ); - double t = 0.0 , dt = 0.025; - while( t < 10.0 ) - { - controlled_step_result res = controlled_stepper.try_step( lorenz() , x_start , t , dt ); - size_t count = 0; - while( ( res == fail ) && ( count < 1000 ) ) - { - res = controlled_stepper.try_step( lorenz() , x_start , t , dt ); - } - if( count == 1000 ) - throw std::runtime_error( "Maximal iterations reached!" ); - - fout3 << t << " " << dt << " " << x_start[0] << " " << x_start[1] << " " << x_start[2] << endl; - } - } - - //return 0;*/ -} diff --git a/libs/numeric/odeint/regression_test/dense_output_explicit.cpp b/libs/numeric/odeint/regression_test/dense_output_explicit.cpp deleted file mode 100644 index 9c7bed97..00000000 --- a/libs/numeric/odeint/regression_test/dense_output_explicit.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * dense_output_explicit.cpp - * - * Created on: Jan 28, 2011 - * Author: karsten - */ - -#include -#include -#include - -#include -#include - -using namespace std; -using namespace boost::numeric::odeint; - -typedef std::vector< double > state_type; -typedef euler< state_type > explicit_stepper_type; -typedef dense_output_runge_kutta< explicit_stepper_type > stepper_type; - -struct lorenz -{ - template< class State , class Deriv > - void operator()( const State &x , Deriv &dxdt , double t ) - { - const double sigma = 10.0; - const double R = 28.0; - const double 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] = x[0]*x[1] - b * x[2]; - } -}; - -int main( int argc , char **argv ) -{ - stepper_type stepper; - - state_type x_start( 3 ); - x_start[0] = 10.0 , x_start[1] = 10.0 ; x_start[2] = 20.0; - - const double dt1 = 0.025 , dt2 = 0.01; - stepper.initialize( x_start , 0.0 , dt1 ); - - ofstream fout( "test.dat" ); - ofstream fout2( "test2.dat" ); - state_type x( 3 ); - double t = 0.0; - while( stepper.current_time() < 10.0 ) - { - while( t < stepper.current_time() ) - { - stepper.calc_state( t , x ); - fout << t << " " << x[0] << " " << x[1] << " " << x[2] << endl; - t += dt2; - } - stepper.do_step( lorenz() ); - const state_type ¤t = stepper.current_state(); - fout2 << stepper.current_time() << " " << current[0] << " " << current[1] << " " << current[2] << " " << endl; - } - - - return 0; -} diff --git a/libs/numeric/odeint/regression_test/dense_output_stepper_evolution.cpp b/libs/numeric/odeint/regression_test/dense_output_stepper_evolution.cpp deleted file mode 100644 index 2d177c6b..00000000 --- a/libs/numeric/odeint/regression_test/dense_output_stepper_evolution.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * dense_output_stepper_evolution.cpp - * - * Created on: Nov 2, 2010 - * Author: karsten - */ - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#define tab "\t" - -using namespace std; -using namespace boost::numeric::odeint; - -typedef boost::array< double , 2 > state_type; -typedef boost::timer timer_type; - -ostream& operator<<( ostream &out , const state_type &x ) -{ - out << x[0] << tab << x[1]; - return out; -} - -void sys( const state_type &x , state_type &dxdt , double t ) -{ - dxdt[0] = x[1]; - dxdt[1] = -x[0]; -} - -state_type sys_solution( double t , const state_type &x0 ) -{ - state_type sol = {{ 0.0 , 0.0 }}; - sol[0] = x0[0] * cos( t ) + x0[1] * sin( t ); - sol[1] = -x0[0] * sin( t ) + x0[1] * cos( t ); - return sol; -} - - - -template< class Stepper > -void evolution( Stepper &stepper , double t_end , const state_type &x0 , const string &stepper_filename , const string &state_filename ) -{ - ofstream state_out( state_filename.c_str() ); - ofstream stepper_out( stepper_filename.c_str() ); - - stepper.initialize( x0 , 0.0 , 0.01 ); - - state_type x = x0; - double t = 0.0; - double dt = 0.001; - while( t < t_end ) - { - if( t < stepper.current_time() ) - { - stepper.calc_state( t , x ); - state_type orig = sys_solution( t , x0 ); - state_type diff = {{ orig[0] - x[0] , orig[1] - x[1] }}; - double diff_abs = sqrt( diff[0] * diff[0] + diff[1] * diff[1] ); - state_out << t << tab << x << tab << orig << tab << diff << tab << diff_abs << endl; - } - else - { - stepper.do_step( sys ); - state_type orig = sys_solution( stepper.current_time() , x0 ); - const state_type &xx = stepper.current_state(); - state_type diff = {{ orig[0] - xx[0] , orig[1] - xx[1] }}; - double diff_abs = sqrt( diff[0] * diff[0] + diff[1] * diff[1] ); - stepper_out << stepper.current_time() << "\t" << xx << tab << orig << tab << diff << tab << diff_abs << std::endl; - continue; - } - t += dt; - - } -} - - -int main( int argc , char **argv ) -{ - typedef runge_kutta_dopri5< state_type > dopri5_type; - typedef controlled_runge_kutta< dopri5_type > controlled_dopri5_type; - - dense_output_runge_kutta< euler< state_type > > dense_euler; - dense_output_runge_kutta< controlled_dopri5_type > dense_dopri5; - - state_type x0 = {{ 1.25 , 0.43 }}; - - timer_type timer; - const double t_max = 100.0; - - timer.restart(); - evolution( dense_euler , t_max , x0 , "dense_euler_stepper.dat" , "dense_euler_state.dat" ); - clog << timer.elapsed() << endl; - - timer.restart(); - evolution( dense_dopri5 , t_max , x0 , "dense_dopri5_stepper.dat" , "dense_dopri5_state.dat" ); - clog << timer.elapsed() << endl; - -} diff --git a/libs/numeric/odeint/regression_test/hamiltonian_steppers.cpp b/libs/numeric/odeint/regression_test/hamiltonian_steppers.cpp deleted file mode 100644 index e2f17e59..00000000 --- a/libs/numeric/odeint/regression_test/hamiltonian_steppers.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/* - * hamiltonian_steppers.cpp - * - * Created on: Feb 12, 2011 - * Author: karsten - */ - -#include -#include - -#include -#include -#include - -#include - -#include -#include - -//#include -//#include - - -using namespace std; -using namespace boost::accumulators; - - -typedef accumulator_set< double , stats< tag::mean > > accumulator_type; - -ostream& operator<<( ostream& out , accumulator_type &acc ) -{ - out << boost::accumulators::mean( acc ) << "\t"; - return out; -} - -typedef boost::timer timer_type; - - - - - - -typedef boost::array< double , 1 > container_type; -typedef std::pair< container_type , container_type > state_type; - - - -struct harm_osc -{ - const double m_omega_sq; - - harm_osc( double omega_sq ) : m_omega_sq( omega_sq ) { } - - template< class Coor , class MomentumDeriv > - void operator()( const Coor &coor , MomentumDeriv &deriv ) - { - deriv[0] = -m_omega_sq * coor[0]; - } -}; - - -void test_euler( void ) -{ - typedef boost::numeric::odeint::symplectic_euler< container_type > stepper_type; - stepper_type stepper; - stepper_type stepper2( stepper ); - stepper_type stepper3; - stepper3 = stepper; - - state_type state; - state.first[0] = 1.0; - state.second[0] = 0.0; - - double t = 0.0; - const double dt = 0.1; - const double omega_sq = 4.0; - - container_type q = { { 0.0 } } , p = { { 1.0 } }; - - stepper.do_step( harm_osc( omega_sq ) , state , t , dt ); - stepper.do_step( harm_osc( omega_sq ) , q , p , t , dt ); - stepper.do_step( harm_osc( omega_sq ) , std::make_pair( boost::ref( q ) , boost::ref( p ) ) , t , dt ); -} - -void test_rkn_sb3a_mclachlan( void ) -{ - typedef boost::numeric::odeint::symplectic_rkn_sb3a_mclachlan< container_type > stepper_type; - stepper_type stepper; - stepper_type stepper2( stepper ); - stepper_type stepper3; - //stepper3 = stepper; //impossible because of const member - - state_type state; - state.first[0] = 1.0; - state.second[0] = 0.0; - - double t = 0.0; - const double dt = 0.1; - const double omega_sq = 4.0; - - stepper.do_step( harm_osc( omega_sq ) , state , t , dt ); -} - -void compare_euler_rkn( void ) -{ - typedef boost::numeric::odeint::symplectic_euler< container_type > stepper_type1; - typedef boost::numeric::odeint::symplectic_rkn_sb3a_mclachlan< container_type > stepper_type2; - - stepper_type1 stepper1; - stepper_type2 stepper2; - - state_type state1; - state1.first[0] = 1.0; - state1.second[0] = 0.0; - state_type state2 = state1; - - double t = 0.0; - const double dt = 0.1; - const double omega_sq = 4.0; - - const size_t ilen = 100; - for( size_t i=0 ; i<10000 ; ++i ) - { - double q1 = state1.first[0] , p1 = state1.second[0] , q2 = state2.first[0] , p2 = state2.second[0] ; - double energy1 = 0.5 * p1 * p1 + 0.5 * omega_sq * q1 * q1; - double energy2 = 0.5 * p2 * p2 + 0.5 * omega_sq * q2 * q2; - cout << t << "\t" << q1 << "\t" << p1 << "\t" << q2 << "\t" << p2 << "\t" << energy1 << "\t" << energy2 << "\n"; - for( size_t ii=0 ; ii stepper_type1; - typedef boost::numeric::odeint::symplectic_rkn_sb3a_mclachlan< container_type > stepper_type2; - - state_type state1; - state1.first[0] = 1.0; - state1.second[0] = 1.0; - state_type state2 = state1; - - const size_t steps = 100000000; - - timer_type timer; - accumulator_type acc1 , acc2; - harm_osc osc( 4.0 ); - const double dt = 0.01; - - for( size_t count=0 ; count<10000 ; ++count ) - { - timer.restart(); - stepper_type1 stepper1; - for( size_t i=0 ; i -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - - -const double sigma = 10.0; -const double R = 28.0; -const double b = 8.0 / 3.0; - -struct lorenz -{ - template< class StateType > - void operator()( const StateType &x , StateType &dxdt , const double &t ) - { - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0] * x[1] - b * x[2]; - } -}; - -struct lorenz_jacobi -{ - template< class State , class Matrix > - void operator()( const State &x , Matrix &J , const double &t , State &dfdt ) - { - J( 0 , 0 ) = -sigma; - J( 0 , 1 ) = sigma; - J( 0 , 2 ) = 0.0; - J( 1 , 0 ) = R - x[2]; - J( 1 , 1 ) = -1.0; - J( 1 , 2 ) = -x[0]; - J( 2 , 0 ) = x[1]; - J( 2 , 1 ) = x[0]; - J( 2 , 2 ) = -b; - - dfdt[0] = 0.0; - dfdt[1] = 0.0; - dfdt[2] = 0.0; - } -}; - -typedef boost::numeric::ublas::vector< double > vector_type; -typedef boost::array< double , 3 > state_type; - -std::ostream& operator<<( std::ostream &out , const vector_type &x ) -{ - if( x.size() != 0 ) out << x[0]; - for( size_t i=1 ; i - void operator()( const T1 &t1 , const T2 &t2 ) const - { - m_out << t2 << " " << t1 << "\n"; - } -}; - -int main( int argc , char **argv ) -{ - using namespace std; - - state_type x1 = { { 10.0 , 10.0 , 10.0 } }; - vector_type x2( 3 , 10.0 ); - -// integrate( implicit_euler< double >() , make_pair( lorenz() , lorenz_jacobi() ) , x2 , 0.0 , 10.0 , 0.1 , do_nothing_observer() ); -// integrate_n_steps( implicit_euler< double >() , make_pair( lorenz() , lorenz_jacobi() ) , x2 , 0.0 , 1000 , 0.1 ); -// integrate_adaptive( implicit_euler< double >() , make_pair( lorenz() , lorenz_jacobi() ) , x2 , 0.0 , 10.0 , 0.1 ); - -// integrate( rosenbrock4< double >() , make_pair( lorenz() , lorenz_jacobi() ) , x2 , 0.0 , 10.0 , 0.1 ); -// integrate_n_steps( rosenbrock4< double >() , make_pair( lorenz() , lorenz_jacobi() ) , x2 , 0.0 , 1000 , 0.1 ); -// integrate_adaptive( rosenbrock4< double >() , make_pair( lorenz() , lorenz_jacobi() ) , x2 , 0.0 , 10.0 , 0.1 ); -// -// integrate( rosenbrock4_controller< rosenbrock4< double > >() , make_pair( lorenz() , lorenz_jacobi() ) , x2 , 0.0 , 10.0 , 0.1 ); -// integrate_n_steps( rosenbrock4_controller< rosenbrock4< double > >() , make_pair( lorenz() , lorenz_jacobi() ) , x2 , 0.0 , 1000 , 0.1 ); -// integrate_adaptive( rosenbrock4_controller< rosenbrock4< double > >() , make_pair( lorenz() , lorenz_jacobi() ) , x2 , 0.0 , 10.0 , 0.1 ); - - - integrate_const( euler< state_type >() , lorenz() , x1 , 0.0 , 0.1001 , 0.01 , tmp_func( cout ) ); -// integrate_n_steps( explicit_euler< state_type >() , lorenz() , x1 , 0.0 , 0.1 , 100 , cout << _1 << "\n" ); -// integrate_adaptive( explicit_euler< state_type >() , lorenz() , x1 , 0.0 , 10.0 , 0.1 , cout << _1 << "\n" ); - - - - - - { - // works - ofstream fout( "integrate_controlled_rk54.dat" ); - size_t num_of_steps = integrate_const( - controlled_runge_kutta< runge_kutta_cash_karp54< state_type > >() , - lorenz() , x1 , 0.0 , 50.0 , 0.1 , tmp_func( fout ) ); - clog << "Integrate controlled error stepper rk54 " << num_of_steps << endl; - } - - - - { - // seem to work, check - typedef runge_kutta_dopri5< state_type > dopri5_type; - typedef controlled_runge_kutta< dopri5_type > controlled_error_stepper_type; - typedef dense_output_runge_kutta< controlled_error_stepper_type > stepper_type; - - controlled_error_stepper_type controlled_stepper( default_error_checker< double >( 1.0e-1 , 0.1 ) ); - - ofstream fout( "integrate_controlled_dopri5.dat" ); - size_t num_of_steps = integrate_const( - stepper_type( controlled_stepper ) , lorenz() , x1 , 0.0 , 50.0 , 0.001 , tmp_func( fout ) ); - clog << "Integrate denseoutput controlled dopri5 " << num_of_steps << endl; - } - - { - // seem to work, check - typedef runge_kutta_dopri5< state_type > dopri5_type; - typedef controlled_runge_kutta< dopri5_type > controlled_error_stepper_type; - typedef dense_output_runge_kutta< controlled_error_stepper_type > stepper_type; - - controlled_error_stepper_type controlled_stepper( default_error_checker< double >( 1.0e-1 , 0.1 ) ); - - ofstream fout( "integrate_adpative_controlled_dopri5.dat" ); - size_t num_of_steps = integrate_adaptive( - stepper_type( controlled_stepper ) , lorenz() , x1 , 0.0 , 50.0 , 0.001 , tmp_func( fout ) ); - clog << "Integrate adaptive denseoutput controlled dopri5 " << num_of_steps << endl; - } - - - - - return true; -} diff --git a/libs/numeric/odeint/regression_test/rosenbrock4.cpp b/libs/numeric/odeint/regression_test/rosenbrock4.cpp deleted file mode 100644 index deda2da0..00000000 --- a/libs/numeric/odeint/regression_test/rosenbrock4.cpp +++ /dev/null @@ -1,278 +0,0 @@ -/* - * rosenbrock4.cpp - * - * Created on: Jan 9, 2011 - * Author: karsten - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -using namespace std; -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 StateType > - void operator()( const StateType &x , StateType &dxdt , const double &t ) - { - - dxdt[0] = sigma * ( x[1] - x[0] ); - dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; - dxdt[2] = x[0] * x[1] - b * x[2]; - } -}; - -struct lorenz_jacobi -{ - template< class State , class Matrix > - void operator()( const State &x , Matrix &J , const double &t , State &dfdt ) - { - J( 0 , 0 ) = -sigma; - J( 0 , 1 ) = sigma; - J( 0 , 2 ) = 0.0; - J( 1 , 0 ) = R - x[2]; - J( 1 , 1 ) = -1.0; - J( 1 , 2 ) = -x[0]; - J( 2 , 0 ) = x[1]; - J( 2 , 1 ) = x[0]; - J( 2 , 2 ) = -b; - - dfdt[0] = 0.0; - dfdt[1] = 0.0; - dfdt[2] = 0.0; - } -}; - - -struct stiff_system -{ - template< class State > - void operator()( const State &x , State &dxdt , double t ) - { - dxdt[ 0 ] = -101.0 * x[ 0 ] - 100.0 * x[ 1 ]; - dxdt[ 1 ] = x[ 0 ]; - } -}; - -struct stiff_system_jacobi -{ - template< class State , class Matrix > - void operator()( const State &x , Matrix &J , const double &t , State &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; - } -}; - - - - - -void test_rosenbrock_stepper_with_lorenz( void ) -{ - const static size_t dim = 3; - typedef rosenbrock4< double > stepper_type; - typedef stepper_type::state_type state_type; - typedef stepper_type::matrix_type matrix_type; - - const double dt = 0.01; - size_t steps = 1000; - double x0 = -12.0 , y0 = -12.0 , z0 = 20.0; - state_type x( dim ) , xerr( dim ); - double t = 0.0; - - stepper_type stepper; - x[0] = x0 ; x[1] = y0 ; x[2] = z0; - - ofstream fout( "rosenbrock_stepper_lorenz.dat" ); - fout.precision( 14 ); - size_t count = 0; - while( count < steps ) - { - fout << t << " "; - fout << x[0] << " " << x[1] << " " << x[2] << " "; - fout << xerr[0] << " " << xerr[1] << " " << xerr[2] << " "; - fout < state_type2; - typedef runge_kutta_cash_karp54_classic< state_type2 > stepper_type2; - stepper_type2 rk_stepper; - - double x0 = -12.0 , y0 = -12.0 , z0 = 20.0; - state_type2 x = {{ x0 , y0 , z0 }} , xerr = {{ 0.0 , 0.0 , 0.0 }}; - double t = 0.0; - - ofstream fout( "rk54_ck_stepper_with_lorenz.dat" ); - fout.precision( 14 ); - size_t count = 0; - size_t steps = 1000; - const double dt = 0.01; - while( count < steps ) - { - fout << t << "\t"; - fout << x[0] << "\t" << x[1] << "\t" << x[2] << "\t"; - fout << xerr[0] << "\t" << xerr[1] << "\t" << xerr[2] << "\t"; - fout < stepper_type; - typedef stepper_type::state_type state_type; - typedef stepper_type::matrix_type matrix_type; - typedef rosenbrock4_controller< stepper_type > controlled_stepper_type; - - state_type x( dim ) , xerr( dim ); - double t = 0.0 , dt = 0.00001; - - controlled_stepper_type controlled_stepper; - - x[0] = 1.0 ; x[1] = 1.0 ; - - ofstream fout( "rosenbrock_controller_stiff.dat" ); - size_t count = 0; - while( t < 50.0 ) - { - fout << t << "\t" << dt << "\t" << controlled_stepper.last_error() << "\t"; - fout << x[0] << "\t" << x[1] << "\t"; - fout < stepper_type; - typedef stepper_type::state_type state_type; - typedef stepper_type::matrix_type matrix_type; - typedef rosenbrock4_controller< stepper_type > controlled_stepper_type; - typedef rosenbrock4_dense_output< controlled_stepper_type > dense_output_stepper_type; - - state_type x( dim ); - double t = 0.0 , dt = 1.0; - - dense_output_stepper_type dense_output_stepper; - x[0] = 1.0 ; x[1] = 1.0 ; - dense_output_stepper.initialize( x , t , 0.00001 ); - - ofstream stepper_out( "rosenbrock_dense_output_stiff_stepper.dat" ); - ofstream res_out( "rosenbrock_dense_output_stiff.dat" ); - size_t count = 0; - - while( t < 50.0 ) - { - if( t < dense_output_stepper.current_time() ) - { - dense_output_stepper.calc_state( t , x ); - res_out << t << "\t" << x[0] << "\t" << x[1] << endl; - } - else - { - dense_output_stepper.do_step( make_pair( stiff_system() , stiff_system_jacobi() ) ); - const state_type &xx = dense_output_stepper.current_state(); - stepper_out << dense_output_stepper.current_time() << "\t" << xx[0] << "\t" << xx[1] << std::endl; - ++count; - continue; - } - t += dt; - } - clog << "Rosenbrock dense out : " << count << endl; - -} - -void rk54_ck_controlled_with_stiff_system( void ) -{ - typedef boost::array< double , 2 > state_type2; - typedef runge_kutta_cash_karp54_classic< state_type2 > stepper_type2; - typedef controlled_runge_kutta< stepper_type2 > controlled_stepper_type2; - controlled_stepper_type2 stepper; - - state_type2 x = {{ 1.0 , 1.0 }}; - double t = 0.0 , dt = 0.00001; - ofstream fout( "rk54_ck_controller_stiff.dat" ); - size_t count = 0; - while( t < 50.0 ) - { - fout << t << "\t" << dt << "\t" << stepper.last_error() << "\t"; - fout << x[0] << "\t" << x[1] << "\t"; - fout <+. -This class provides basic assignment and random access methods, but does not support iterators. -Furthermore, the routines for ODEs are restricted to the \lstinline+NRVec< double >+ specializations of the vectors. -The Numerical Recipes provide several standard routines for solving ODEs, like the classical Runge-Kutta-4 scheme, the RK54 Cash-Karp method with error estimates, the controlled Burlish-Stoer scheme and many others. -These routines execute one step with constant or adjusted step-size of a given system. -The system, namely the right hand side of the ODE, is providede to these routines in terms of a function pointer \lstinline+void rhs(const DP, Vec_I_DP &, Vec_O_DP &)+. -Additionally, a driver is provided in terms of a function which integrates an ODE from some start- to some end-point by successively calling the single step functions and adjusting the step size according to some desired error levels. - -This design exhibits several disadvantages. -Most of these points are due to the fact that the code relies on its own, fixed vector type and these apply to all of the libraries that are presented here. -\begin{itemize} - \item Connection with other libraries, like STL, requires mapping of the \lstinline+NRVec+ to other vector types. - \item Impossible to solve ODEs with complex valued date types or multi-precision data types. - \item Impossible to solve ODEs on resizing lattices. - \item Impossible to solve ODEs on nontrivial state types like complex networks. - \item Impossible to represent the ODE as a class due to restriction to function pointers. -\end{itemize} - -\section{GNU Scientfic Library} -The GNU Scientfic Library (GSL) provides many numerical algorithms as a precompiled library. -In terms of functionality its ODE routines are comparable with the Numerical Recipes. -It includes standard Runge-Kutta as well as several implicit schemes. -The interface use plain C which results in cumbersume usage, especially within an otherwise modern C++ environment. -As for the Numerical Recipes, the GSL also brings its own vector type, \lstinline+gsl_vector+, that is extremely uncomfortable to use as its element access is realized by global functions. -Moreover, stepper and driver routines require the call of allocation functions and so the programmer must also take care for deallocation. -Additionally, the GSL shows rather poor performance simply because it is pre-compiled which prevents the compiler from employing optimized function inlining. -And just like for the Numerical Recipes the right hand side of the ODE has to be provided in terms of a function pointer which rules out the possibility to represent the ODE as a class. - -To summarize, the GSL suffers from the same disadvantages as the Numerical Recipes because it also uses its own vector type and requires functions pointers. -Additionally, it shows worse performance due to its pre-compiled nature. -Finally, its C interfaces are unacceptable from a modern point of view. - -\section{Apache Math} -The Apache Commons Math Library is mathematical component written in Java. -Besides many other subjects it also addresses solving of ODEs. -The library is well designed making heavy use of object-orientation techniques. -The ODE is defined as a class implementing a certain interface and the solver algorithm is also represented by a class providing an integrate function which does integration steps by successive iteration of single steps with (possibly) step size control. - -However, we again have the disadvantage that the whole library works only with a fixed vector type, namely array of doubles \lstinline+double[]+. -So there is no chance to use it with complex valued data types, resizing states or on self written state types like complex networks. -Additionally, the performance of this Java library is about ten times worse than a good C or C++ approach. -However, the library is well designed in terms of OO principles and it is easy to add new solver algorithms, for example. - -\section{Python SciPy} -The Python.SciPy package contains a function for solving ODEs, called scipy.integrate.odeint. -This function is highly convenient and very easy to use. -In its simplest form the programmer just provides any callable object representing the right hand side of the ODE, a starting condition and an array of times at which the solution should be evaluated. -This easy-to-use method automatically chooses integration routine and step size and provides a convenient way to solve ODEs quick-n-dirty. - -However, it is impossible to choose the actual algorithm used by this routine which makes it not suitable for real scientific work. -Furthermore, the performance is by no means comparable to a C/C++ library. -But in terms of convenivence this function is what we want to reach with \odeint, without loosing the possibility to configure the algorithm and the details of the integration. - -\section*{Summary} -To our knowledge, all libraries dealing with ODEs are implemented in a way that nails down the vector type to some sort of array of doubles. -This is, in our opinion, a major disadvantage that can be solved by using modern template techniques in C++. -So our aim with \odeint\ is to provide standard integration routines for ODEs, but completely separate the algorithms from the vector types. -We currently don't know of any comparable approach towards numerical libraries but we do believe that with this separation we are able to overcome the downfalls of the existing libraries presented before. - -\end{document} \ No newline at end of file From c2cf7005ecdec6d20676605e8b8bb8f36a82e7da Mon Sep 17 00:00:00 2001 From: Karsten Ahnert Date: Fri, 29 Jun 2012 08:15:31 +0200 Subject: [PATCH 04/12] changed by hand --- .../odeint/iterator/const_step_iterator.hpp | 108 ------------------ libs/numeric/odeint/test/Jamfile | 1 - .../odeint/test/const_step_iterator.cpp | 88 -------------- 3 files changed, 197 deletions(-) delete mode 100644 boost/numeric/odeint/iterator/const_step_iterator.hpp delete mode 100644 libs/numeric/odeint/test/const_step_iterator.cpp diff --git a/boost/numeric/odeint/iterator/const_step_iterator.hpp b/boost/numeric/odeint/iterator/const_step_iterator.hpp deleted file mode 100644 index 45284d30..00000000 --- a/boost/numeric/odeint/iterator/const_step_iterator.hpp +++ /dev/null @@ -1,108 +0,0 @@ - -/* - [auto_generated] - boost/numeric/odeint/iterator/const_step_ode_iterator.hpp - - [begin_description] - Iterator for iterating throught the solution of an ODE with constant step size. - [end_description] - - Copyright 2009-2011 Karsten Ahnert - Copyright 2009-2011 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_ITERATOR_CONST_STEP_ODE_ITERATOR_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_ITERATOR_CONST_STEP_ODE_ITERATOR_HPP_INCLUDED - -# include - - -namespace boost { -namespace numeric { -namespace odeint { - - template< class Stepper , class System > - class const_step_iterator : public boost::iterator_facade - < - const_step_iterator< Stepper , System > , - typename Stepper::state_type , - boost::incrementable_traversal_tag - > - { - private: - - typedef Stepper stepper_type; - typedef System system_type; - typedef typename stepper_type::state_type state_type; - typedef typename stepper_type::time_type time_type; - - public: - - const_step_iterator( stepper_type stepper , system_type sys , state_type &s , time_type t , time_type dt ) - : m_stepper( stepper ) , m_system( sys ) , m_state( s ) , m_t( t ) , m_dt( dt ) {} - - private: - - - - friend class boost::iterator_core_access; - - void increment() - { - m_stepper.do_step( m_system , m_state , m_t , m_dt ); - m_t += m_dt; - } - - bool equal( const_step_iterator const& other ) const - { - return m_t > other.m_t; - } - - state_type& dereference() const - { - return m_state; - } - - stepper_type m_stepper; - system_type m_system; - state_type &m_state; - time_type m_t; - time_type m_dt; - - }; - - - template< class Stepper , class System > - const_step_iterator< Stepper , System > make_const_step_iterator( - Stepper stepper , - System system , - typename Stepper::state_type &x , - typename Stepper::time_type t , - typename Stepper::time_type dt ) - { - return const_step_iterator< Stepper , System >( stepper , system , x , t , dt ); - } - - - - - - - -// make_const_step_ode_iterator - - - - -} // namespace odeint -} // namespace numeric -} // namespace boost - - - -#endif // BOOST_NUMERIC_ODEINT_ITERATOR_CONST_STEP_ODE_ITERATOR_HPP_INCLUDED diff --git a/libs/numeric/odeint/test/Jamfile b/libs/numeric/odeint/test/Jamfile index 74e25b96..a8d576bf 100644 --- a/libs/numeric/odeint/test/Jamfile +++ b/libs/numeric/odeint/test/Jamfile @@ -45,6 +45,5 @@ test-suite "odeint" [ run integrate_implicit.cpp ] [ run generation.cpp ] [ run trivial_state.cpp ] - [ run const_step_iterator.cpp ] : valgrind ; diff --git a/libs/numeric/odeint/test/const_step_iterator.cpp b/libs/numeric/odeint/test/const_step_iterator.cpp deleted file mode 100644 index 8873675d..00000000 --- a/libs/numeric/odeint/test/const_step_iterator.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * const_step_ode_iterator.cpp - * - * Created on: Jun 26, 2012 - * Author: karsten - */ - -#define BOOST_TEST_MODULE odeint_const_step_iterator - -#include -#include -#include - -#include -#include -#include - -#include -#include - - -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() From 78ee9fb6749ed23faa045c3cb76fd60f31a6590f Mon Sep 17 00:00:00 2001 From: Mario Mulansky Date: Fri, 29 Jun 2012 15:11:47 +0200 Subject: [PATCH 05/12] +inv_time_vector --- boost/numeric/odeint/stepper/bulirsch_stoer.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/boost/numeric/odeint/stepper/bulirsch_stoer.hpp b/boost/numeric/odeint/stepper/bulirsch_stoer.hpp index bd5c35c5..43a9b1c2 100644 --- a/boost/numeric/odeint/stepper/bulirsch_stoer.hpp +++ b/boost/numeric/odeint/stepper/bulirsch_stoer.hpp @@ -73,6 +73,7 @@ public: typedef std::vector< value_type > value_vector; typedef std::vector< time_type > time_vector; + typedef std::vector< time_type > inv_time_vector; //should be 1/time_type for boost.units typedef std::vector< value_vector > value_matrix; typedef std::vector< size_t > int_vector; typedef std::vector< wrapped_state_type > state_table_type; @@ -190,7 +191,7 @@ public: bool reject( true ); time_vector h_opt( m_k_max+1 ); - value_vector work( m_k_max+1 ); + inv_time_vector work( m_k_max+1 ); //std::cout << "t=" << t <<", dt=" << dt << "(" << m_dt_last << ")" << ", k_opt=" << m_current_k_opt << std::endl; @@ -401,7 +402,7 @@ private: return h*fac; } - controlled_step_result set_k_opt( size_t k , const value_vector &work , const time_vector &h_opt , time_type &dt ) + controlled_step_result set_k_opt( size_t k , const inv_time_vector &work , const time_vector &h_opt , time_type &dt ) { //std::cout << "finding k_opt..." << std::endl; if( k == 1 ) From bd481d8343240ed19a7e8f5a5dfb1559ff92473e Mon Sep 17 00:00:00 2001 From: Mario Mulansky Date: Fri, 29 Jun 2012 15:12:53 +0200 Subject: [PATCH 06/12] just one more cast to make expression templates work in min/max functions --- boost/numeric/odeint/stepper/controlled_runge_kutta.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boost/numeric/odeint/stepper/controlled_runge_kutta.hpp b/boost/numeric/odeint/stepper/controlled_runge_kutta.hpp index 3d08fc28..4bfe0bed 100644 --- a/boost/numeric/odeint/stepper/controlled_runge_kutta.hpp +++ b/boost/numeric/odeint/stepper/controlled_runge_kutta.hpp @@ -475,7 +475,7 @@ public: if( max_rel_err > 1.0 ) { // error too large - decrease dt ,limit scaling factor to 0.2 and reset state - dt *= max( static_cast(9)/static_cast(10) * pow( max_rel_err , static_cast(-1) / ( m_stepper.error_order() - 1 ) ) , static_cast(1)/static_cast (5) ); + dt *= max( static_cast( static_cast(9)/static_cast(10) * pow( max_rel_err , static_cast(-1) / ( m_stepper.error_order() - 1 ) ) ) , static_cast( static_cast(1)/static_cast (5)) ); return fail; } else @@ -483,7 +483,7 @@ public: if( max_rel_err < 0.5 ) { //error too small - increase dt and keep the evolution and limit scaling factor to 5.0 t += dt; - dt *= min( static_cast(9)/static_cast(10) * pow( max_rel_err , static_cast(-1) / m_stepper.stepper_order() ) , static_cast(5) ); + dt *= min( static_cast( static_cast(9)/static_cast(10) * pow( max_rel_err , static_cast(-1) / m_stepper.stepper_order() ) ) , static_cast(5) ); return success; } else From f46f2eab48368ca56c967c8998bae741e5511317 Mon Sep 17 00:00:00 2001 From: Karsten Ahnert Date: Fri, 29 Jun 2012 20:37:12 +0200 Subject: [PATCH 07/12] applied patch from slayoo and removed iterator branch stuff --- Jamroot | 9 --- .../external/thrust/thrust_operations.hpp | 19 ++++++ libs/numeric/odeint/examples/Jamfile | 2 +- .../odeint/examples/const_step_iterator.cpp | 60 ------------------- 4 files changed, 20 insertions(+), 70 deletions(-) delete mode 100644 libs/numeric/odeint/examples/const_step_iterator.cpp diff --git a/Jamroot b/Jamroot index e7b92234..882251e2 100644 --- a/Jamroot +++ b/Jamroot @@ -19,7 +19,6 @@ project # tests, regression tests and examples build-project libs/numeric/odeint/test ; build-project libs/numeric/odeint/examples ; -build-project libs/numeric/odeint/regression_test ; # additional tests with external libraries : @@ -28,14 +27,6 @@ build-project libs/numeric/odeint/regression_test ; # build-project libs/numeric/odeint/test_external/gsl ; -# ideas -# build-project libs/numeric/odeint/ideas/butcher ; -# build-project libs/numeric/odeint/ideas/generic_stepper ; -#build-project libs/numeric/odeint/ideas/rosenbrock4 ; -#build-project libs/numeric/odeint/ideas/units ; -#build-project libs/numeric/odeint/ideas/algebra ; - - # docs: # build-project libs/numeric/odeint/doc ; diff --git a/boost/numeric/odeint/external/thrust/thrust_operations.hpp b/boost/numeric/odeint/external/thrust/thrust_operations.hpp index be79f17a..710657ae 100644 --- a/boost/numeric/odeint/external/thrust/thrust_operations.hpp +++ b/boost/numeric/odeint/external/thrust/thrust_operations.hpp @@ -46,6 +46,25 @@ struct thrust_operations } }; + template< class Fac1 = double , class Fac2 = Fac1 > + struct scale_sum_swap2 + { + const Fac1 m_alpha1; + const Fac2 m_alpha2; + + scale_sum_swap2( const Fac1 alpha1 , const Fac2 alpha2 ) + : m_alpha1( alpha1 ) , m_alpha2( alpha2 ) { } + + template< class Tuple > + __host__ __device__ + void operator()( Tuple t ) const + { + typename thrust::tuple_element<0,Tuple>::type tmp = thrust::get<0>(t); + thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) + m_alpha2 * thrust::get<2>(t); + thrust::get<1>(t) = tmp; + } + }; + template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 > struct scale_sum3 { diff --git a/libs/numeric/odeint/examples/Jamfile b/libs/numeric/odeint/examples/Jamfile index 64f1ae5f..0d051a71 100644 --- a/libs/numeric/odeint/examples/Jamfile +++ b/libs/numeric/odeint/examples/Jamfile @@ -34,7 +34,7 @@ exe simple1d : simple1d.cpp ; exe stochastic_euler : stochastic_euler.cpp : : -std=c++0x ; exe generation_functions : generation_functions.cpp : : -std=c++0x ; exe heun : heun.cpp : : -std=c++0x ; -exe const_step_iterator : const_step_iterator.cpp ; + # build-project mtl ; # build-project ublas ; diff --git a/libs/numeric/odeint/examples/const_step_iterator.cpp b/libs/numeric/odeint/examples/const_step_iterator.cpp deleted file mode 100644 index fe235267..00000000 --- a/libs/numeric/odeint/examples/const_step_iterator.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * const_step_ode_iterator.cpp - * - * Created on: Jun 26, 2012 - * Author: karsten - */ - -#include -#include -#include - -#include - -#include -#include - - -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; -} From ca1f5389cba47b0530511d27e1c1035074808885 Mon Sep 17 00:00:00 2001 From: Karsten Ahnert Date: Sat, 30 Jun 2012 11:04:37 +0200 Subject: [PATCH 08/12] all examples do now work with c++03 --- libs/numeric/odeint/examples/Jamfile | 6 +++--- .../odeint/examples/generation_functions.cpp | 10 +++++++-- libs/numeric/odeint/examples/heun.cpp | 21 ++++++++++++++----- .../odeint/examples/stochastic_euler.cpp | 18 ++++++++-------- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/libs/numeric/odeint/examples/Jamfile b/libs/numeric/odeint/examples/Jamfile index 0d051a71..ca984f38 100644 --- a/libs/numeric/odeint/examples/Jamfile +++ b/libs/numeric/odeint/examples/Jamfile @@ -31,9 +31,9 @@ exe lorenz_point : lorenz_point.cpp ; exe bs_bug : bs_bug.cpp ; exe van_der_pol_stiff : van_der_pol_stiff.cpp ; exe simple1d : simple1d.cpp ; -exe stochastic_euler : stochastic_euler.cpp : : -std=c++0x ; -exe generation_functions : generation_functions.cpp : : -std=c++0x ; -exe heun : heun.cpp : : -std=c++0x ; +exe stochastic_euler : stochastic_euler.cpp ; +exe generation_functions : generation_functions.cpp ; +exe heun : heun.cpp ; # build-project mtl ; diff --git a/libs/numeric/odeint/examples/generation_functions.cpp b/libs/numeric/odeint/examples/generation_functions.cpp index 34fa6c56..825d258a 100644 --- a/libs/numeric/odeint/examples/generation_functions.cpp +++ b/libs/numeric/odeint/examples/generation_functions.cpp @@ -11,11 +11,11 @@ copy at http://www.boost.org/LICENSE_1_0.txt) */ -#include +#include #include -typedef std::array< double , 1 > state_type; +typedef boost::array< double , 1 > state_type; using namespace boost::numeric::odeint; @@ -73,10 +73,12 @@ int main( int argc , char **argv ) { typedef runge_kutta_dopri5< state_type > stepper_type; + /* //[ generation_functions_syntax_auto auto stepper1 = make_controlled( 1.0e-6 , 1.0e-6 , stepper_type() ); auto stepper2 = make_dense_output( 1.0e-6 , 1.0e-6 , stepper_type() ); //] + */ //[ generation_functions_syntax_result_of result_of::make_controlled< stepper_type >::type stepper3 = make_controlled( 1.0e-6 , 1.0e-6 , stepper_type() ); @@ -85,9 +87,13 @@ int main( int argc , char **argv ) } { + /* //[ generation_functions_example_custom_controller auto stepper5 = make_controlled( 1.0e-6 , 1.0e-6 , custom_stepper() ); //] + */ + + result_of::make_controlled< custom_stepper >::type stepper5 = make_controlled( 1.0e-6 , 1.0e-6 , custom_stepper() ); } return 0; } diff --git a/libs/numeric/odeint/examples/heun.cpp b/libs/numeric/odeint/examples/heun.cpp index 2be70115..98da9994 100644 --- a/libs/numeric/odeint/examples/heun.cpp +++ b/libs/numeric/odeint/examples/heun.cpp @@ -15,7 +15,6 @@ */ #include -#include #include #include @@ -133,6 +132,19 @@ struct lorenz } }; +struct streaming_observer +{ + std::ostream &m_out; + streaming_observer( std::ostream &out ) : m_out( out ) { } + template< typename State , typename Value > + void operator()( const State &x , Value t ) const + { + m_out << t; + for( size_t i=0 ; i state_type; + typedef boost::array< double , 3 > state_type; heun< state_type > h; state_type x = {{ 10.0 , 10.0 , 10.0 }}; integrate_const( h , lorenz() , x , 0.0 , 100.0 , 0.01 , - []( const state_type &_x , double _t ) { - std::cout << _t << "\t" << _x[0] << "\t" << _x[1] << "\t" << _x[2] << "\n"; - }); + streaming_observer( std::cout ) ); + //] return 0; diff --git a/libs/numeric/odeint/examples/stochastic_euler.cpp b/libs/numeric/odeint/examples/stochastic_euler.cpp index 02980c02..06d51934 100644 --- a/libs/numeric/odeint/examples/stochastic_euler.cpp +++ b/libs/numeric/odeint/examples/stochastic_euler.cpp @@ -14,8 +14,8 @@ #include #include -#include -#include +#include +#include #include @@ -26,8 +26,8 @@ template< size_t N > class stochastic_euler { public: - typedef std::array< double , N > state_type; - typedef std::array< double , N > deriv_type; + typedef boost::array< double , N > state_type; + typedef boost::array< double , N > deriv_type; typedef double value_type; typedef double time_type; typedef unsigned short order_type; @@ -71,8 +71,8 @@ class stochastic_euler { public: - typedef std::array< double , N > state_type; - typedef std::array< double , N > deriv_type; + typedef boost::array< double , N > state_type; + typedef boost::array< double , N > deriv_type; typedef double value_type; typedef double time_type; typedef unsigned short order_type; @@ -97,7 +97,7 @@ public: //[ stochastic_euler_ornstein_uhlenbeck_def const static size_t N = 1; -typedef std::array< double , N > state_type; +typedef boost::array< double , N > state_type; struct ornstein_det { @@ -109,8 +109,8 @@ struct ornstein_det struct ornstein_stoch { - std::mt19937 m_rng; - std::normal_distribution<> m_dist; + boost::mt19937 m_rng; + boost::normal_distribution<> m_dist; ornstein_stoch( double sigma ) : m_rng() , m_dist( 0.0 , sigma ) { } From 68fdb78a1b2d2474e6f08a5a41fe9d73397ed09c Mon Sep 17 00:00:00 2001 From: Karsten Ahnert Date: Sat, 30 Jun 2012 12:48:32 +0200 Subject: [PATCH 09/12] added inverse time meta function --- .../numeric/odeint/stepper/bulirsch_stoer.hpp | 10 ++++++- boost/numeric/odeint/util/unit_helper.hpp | 28 +++++++++++++++++++ .../odeint/test/stepper_with_units.cpp | 4 +-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/boost/numeric/odeint/stepper/bulirsch_stoer.hpp b/boost/numeric/odeint/stepper/bulirsch_stoer.hpp index 43a9b1c2..facac3a5 100644 --- a/boost/numeric/odeint/stepper/bulirsch_stoer.hpp +++ b/boost/numeric/odeint/stepper/bulirsch_stoer.hpp @@ -38,13 +38,19 @@ #include #include #include +#include + namespace boost { namespace numeric { namespace odeint { + + /** ToDo try_step stepsize changed return values doesn't make too much sense here as we have order control as well */ + + template< class State , class Value = double , @@ -71,9 +77,11 @@ public: typedef bulirsch_stoer< State , Value , Deriv , Time , Algebra , Operations , Resizer > controlled_error_bs_type; + typedef typename inverse_time< time_type >::type inv_time_type; + typedef std::vector< value_type > value_vector; typedef std::vector< time_type > time_vector; - typedef std::vector< time_type > inv_time_vector; //should be 1/time_type for boost.units + typedef std::vector< inv_time_type > inv_time_vector; //should be 1/time_type for boost.units typedef std::vector< value_vector > value_matrix; typedef std::vector< size_t > int_vector; typedef std::vector< wrapped_state_type > state_table_type; diff --git a/boost/numeric/odeint/util/unit_helper.hpp b/boost/numeric/odeint/util/unit_helper.hpp index 78223e15..f13910e9 100644 --- a/boost/numeric/odeint/util/unit_helper.hpp +++ b/boost/numeric/odeint/util/unit_helper.hpp @@ -21,6 +21,8 @@ #ifndef __CUDACC__ #include +#include +#include #endif @@ -115,6 +117,32 @@ namespace detail { + + + + + + + + template< typename Time > + struct inverse_time + { + typedef Time type; + }; + + template< typename Unit , typename Value > + struct inverse_time< boost::units::quantity< Unit , Value > > + { + typedef boost::units::quantity< Unit , Value > time_type; + typedef typename boost::units::get_dimension< time_type >::type dimension; + typedef typename boost::units::get_system< time_type >::type system; + typedef typename boost::mpl::divides< boost::units::dimensionless_type , dimension >::type inv_dimension; + typedef boost::units::unit< inv_dimension , system > inv_unit; + typedef boost::units::quantity< inv_unit , Value > type; + }; + + + } // namespace odeint } // namespace numeric } // namespace boost diff --git a/libs/numeric/odeint/test/stepper_with_units.cpp b/libs/numeric/odeint/test/stepper_with_units.cpp index 2139b689..7c2fc0be 100644 --- a/libs/numeric/odeint/test/stepper_with_units.cpp +++ b/libs/numeric/odeint/test/stepper_with_units.cpp @@ -266,8 +266,8 @@ class fsal_error_stepper_types : public mpl::vector class controlled_stepper_types : public mpl::vector < controlled_runge_kutta< runge_kutta_cash_karp54_classic< state_type , value_type , deriv_type , time_type , fusion_algebra > > , - controlled_runge_kutta< runge_kutta_dopri5< state_type , value_type , deriv_type , time_type , fusion_algebra > > - //, bulirsch_stoer< state_type , value_type , deriv_type , time_type , fusion_algebra > + controlled_runge_kutta< runge_kutta_dopri5< state_type , value_type , deriv_type , time_type , fusion_algebra > > +// bulirsch_stoer< state_type , value_type , deriv_type , time_type , fusion_algebra > //, controlled_error_stepper< runge_kutta_fehlberg78< state_type , value_type , deriv_type , time_type , fusion_algebra > > > { }; From c7b17ec25dfa31fddb4c926543241664904d4884 Mon Sep 17 00:00:00 2001 From: Mario Mulansky Date: Mon, 2 Jul 2012 14:10:12 +0200 Subject: [PATCH 10/12] units support for bulirsch stoer dense out --- .../numeric/odeint/stepper/bulirsch_stoer.hpp | 4 +-- .../stepper/bulirsch_stoer_dense_out.hpp | 26 +++++++++---------- .../odeint/stepper/modified_midpoint.hpp | 8 +++--- .../odeint/test/stepper_with_units.cpp | 15 ++++++----- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/boost/numeric/odeint/stepper/bulirsch_stoer.hpp b/boost/numeric/odeint/stepper/bulirsch_stoer.hpp index facac3a5..5561df13 100644 --- a/boost/numeric/odeint/stepper/bulirsch_stoer.hpp +++ b/boost/numeric/odeint/stepper/bulirsch_stoer.hpp @@ -222,7 +222,7 @@ public: typename operations_type::template scale_sum2< value_type , value_type >( val1 , -val1 ) ); const value_type error = m_error_checker.error( m_algebra , in , dxdt , m_err.m_v , dt ); h_opt[k] = calc_h_opt( dt , error , k ); - work[k] = m_cost[k]/h_opt[k]; + work[k] = static_cast( m_cost[k] ) / h_opt[k]; //std::cout << '\t' << "h_opt=" << h_opt[k] << ", work=" << work[k] << std::endl; //std::cout << '\t' << "error: " << error << std::endl; @@ -237,7 +237,7 @@ public: // leave order as is (except we were in first round) m_current_k_opt = std::min( static_cast(m_k_max)-1 , std::max( 2 , static_cast(k)+1 ) ); new_h = h_opt[k]; - new_h *= m_cost[k+1]/m_cost[k]; + new_h *= static_cast( m_cost[k+1] ) / static_cast( m_cost[k] ); } else { m_current_k_opt = std::min( static_cast(m_k_max)-1 , std::max( 2 , static_cast(k) ) ); new_h = h_opt[k]; diff --git a/boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp b/boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp index ba5f970e..b010a37e 100644 --- a/boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp +++ b/boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -87,8 +88,11 @@ public: typedef bulirsch_stoer_dense_out< State , Value , Deriv , Time , Algebra , Operations , Resizer > controlled_error_bs_type; + typedef typename inverse_time< time_type >::type inv_time_type; + typedef std::vector< value_type > value_vector; typedef std::vector< time_type > time_vector; + typedef std::vector< inv_time_type > inv_time_vector; //should be 1/time_type for boost.units typedef std::vector< value_vector > value_matrix; typedef std::vector< size_t > int_vector; typedef std::vector< wrapped_state_type > state_vector_type; @@ -104,15 +108,9 @@ public: value_type eps_abs = 1E-6 , value_type eps_rel = 1E-6 , value_type factor_x = 1.0 , value_type factor_dxdt = 1.0 , bool control_interpolation = false ) - : m_error_checker( eps_abs , eps_rel , factor_x, factor_dxdt ) , m_midpoint() , + : m_error_checker( eps_abs , eps_rel , factor_x, factor_dxdt ) , m_control_interpolation( control_interpolation) , m_last_step_rejected( false ) , m_first( true ) , - /*m_t() , m_dt() , - m_dt_last( 1.0E30 ) , m_t_last() , - m_current_k_opt() , - m_k_final(0) , - m_algebra() , m_resizer() , - m_x1() , m_x2() , m_dxdt1() , m_dxdt2() , m_err() ,*/ m_current_state_x1( true ) , m_error( m_k_max ) , m_interval_sequence( m_k_max+1 ) , @@ -185,7 +183,7 @@ public: bool reject( true ); time_vector h_opt( m_k_max+1 ); - value_vector work( m_k_max+1 ); + inv_time_vector work( m_k_max+1 ); m_k_final = 0; time_type new_h = dt; @@ -209,7 +207,7 @@ public: typename operations_type::template scale_sum2< value_type , value_type >( val1 , -val1 ) ); const value_type error = m_error_checker.error( m_algebra , in , dxdt , m_err.m_v , dt ); h_opt[k] = calc_h_opt( dt , error , k ); - work[k] = m_cost[k]/h_opt[k]; + work[k] = static_cast( m_cost[k] ) / h_opt[k]; //std::cout << '\t' << "h_opt=" << h_opt[k] << ", work=" << work[k] << std::endl; //std::cout << '\t' << "error: " << error << std::endl; @@ -225,7 +223,7 @@ public: { // leave order as is (except we were in first round) m_current_k_opt = std::min( static_cast(m_k_max)-1 , std::max( 2 , static_cast(k)+1 ) ); - new_h = h_opt[k] * m_cost[k+1]/m_cost[k]; + new_h = h_opt[k] * static_cast( m_cost[k+1] ) / static_cast( m_cost[k] ); } else { m_current_k_opt = std::min( static_cast(m_k_max)-1 , std::max( 2 , static_cast(k) ) ); new_h = h_opt[k]; @@ -253,7 +251,7 @@ public: else if( (work[k] < KFAC2*work[k-1]) && !m_last_step_rejected ) { m_current_k_opt = std::min( static_cast(m_k_max)-1 , static_cast(m_current_k_opt)+1 ); - new_h = h_opt[k]*m_cost[m_current_k_opt]/m_cost[k]; + new_h = h_opt[k]*static_cast( m_cost[m_current_k_opt] ) / static_cast( m_cost[k] ); } else new_h = h_opt[m_current_k_opt]; break; @@ -502,7 +500,7 @@ private: for( int j = 0 ; j<=k ; j++ ) { /* not working with boost units... */ - const value_type d = m_interval_sequence[j] / ( 2*dt ); + const value_type d = m_interval_sequence[j] / ( static_cast(2) * dt ); value_type f = 1.0; //factor 1/2 here because our interpolation interval has length 2 !!! for( int kappa = 0 ; kappa <= 2*j+1 ; ++kappa ) { @@ -664,7 +662,7 @@ private: { // interpolation polynomial is defined for theta = -1 ... 1 // m_k_final is the number of order-iterations done for the last step - it governs the order of the interpolation polynomial - const time_type theta = 2*(t - m_t_last)/(m_t - m_t_last) - 1; + const value_type theta = 2 * get_unit_value( (t - m_t_last) / (m_t - m_t_last) ) - 1; //std::cout << "theta=" << theta << std::endl; //start with x = a0 + a_{2k+1} theta^{2k+1} + a_{2k+2} theta^{2k+2} + a_{2k+3} theta^{2k+3} + a_{2k+4} theta^{2k+4} //std::cout << "x = a_0 + "; @@ -809,7 +807,7 @@ private: //wrapped_state_type m_a1 , m_a2 , m_a3 , m_a4; - const time_type STEPFAC1 , STEPFAC2 , STEPFAC3 , STEPFAC4 , KFAC1 , KFAC2; + const value_type STEPFAC1 , STEPFAC2 , STEPFAC3 , STEPFAC4 , KFAC1 , KFAC2; }; } diff --git a/boost/numeric/odeint/stepper/modified_midpoint.hpp b/boost/numeric/odeint/stepper/modified_midpoint.hpp index 27749143..37abcac0 100644 --- a/boost/numeric/odeint/stepper/modified_midpoint.hpp +++ b/boost/numeric/odeint/stepper/modified_midpoint.hpp @@ -76,8 +76,8 @@ public : m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) ); - const time_type h = dt / m_steps ; - const time_type h2 = 2 * h; + const time_type h = dt / static_cast( m_steps ); + const time_type h2 = static_cast(2) * h; typename odeint::unwrap_reference< System >::type &sys = system; @@ -200,8 +200,8 @@ public : m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize< StateIn > , detail::ref( *this ) , detail::_1 ) ); - const time_type h = dt / static_cast( m_steps ); - const time_type h2 = static_cast( 2 ) * h; + const time_type h = dt / static_cast( m_steps ); + const time_type h2 = static_cast( 2 ) * h; typename odeint::unwrap_reference< System >::type &sys = system; diff --git a/libs/numeric/odeint/test/stepper_with_units.cpp b/libs/numeric/odeint/test/stepper_with_units.cpp index 7c2fc0be..f151f8dc 100644 --- a/libs/numeric/odeint/test/stepper_with_units.cpp +++ b/libs/numeric/odeint/test/stepper_with_units.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -266,16 +267,18 @@ class fsal_error_stepper_types : public mpl::vector class controlled_stepper_types : public mpl::vector < controlled_runge_kutta< runge_kutta_cash_karp54_classic< state_type , value_type , deriv_type , time_type , fusion_algebra > > , - controlled_runge_kutta< runge_kutta_dopri5< state_type , value_type , deriv_type , time_type , fusion_algebra > > -// bulirsch_stoer< state_type , value_type , deriv_type , time_type , fusion_algebra > - //, controlled_error_stepper< runge_kutta_fehlberg78< state_type , value_type , deriv_type , time_type , fusion_algebra > > + controlled_runge_kutta< runge_kutta_dopri5< state_type , value_type , deriv_type , time_type , fusion_algebra > > + , bulirsch_stoer< state_type , value_type , deriv_type , time_type , fusion_algebra > + // rk78 with units needs up to 3GB memory to compile - disable testing... + //, controlled_runge_kutta< runge_kutta_fehlberg78< state_type , value_type , deriv_type , time_type , fusion_algebra > > > { }; class dense_output_stepper_types : public mpl::vector < - dense_output_runge_kutta< euler< state_type , value_type , deriv_type , time_type , fusion_algebra > > , - dense_output_runge_kutta< - controlled_runge_kutta< runge_kutta_dopri5< state_type , value_type , deriv_type , time_type , fusion_algebra > > > + dense_output_runge_kutta< euler< state_type , value_type , deriv_type , time_type , fusion_algebra > > , + dense_output_runge_kutta< + controlled_runge_kutta< runge_kutta_dopri5< state_type , value_type , deriv_type , time_type , fusion_algebra > > > + //, bulirsch_stoer_dense_out< state_type , value_type , deriv_type , time_type , fusion_algebra > > { }; From 3e94027eea22a7ab8d0e33bb01f886488a6271e6 Mon Sep 17 00:00:00 2001 From: Karsten Ahnert Date: Mon, 2 Jul 2012 23:33:56 +0200 Subject: [PATCH 11/12] added implicit euler based on mlt4 matrix types --- .../external/mtl4/implicit_euler_mtl4.hpp | 162 +++++++++ .../odeint/external/mtl4/mtl4_resize.hpp | 133 ++++++++ libs/numeric/odeint/examples/mtl/Jamfile | 5 +- .../odeint/examples/mtl/gauss_packet.cpp | 4 +- .../examples/mtl/implicit_euler_mtl.cpp | 314 ++++++++++++++++++ .../odeint/examples/mtl/mtl_bindings.hpp | 49 --- .../odeint/test_external/mtl/gauss_packet.cpp | 137 -------- .../odeint/test_external/mtl/mtl_bindings.hpp | 31 -- .../test_external/{mtl => mtl4}/Jamfile | 17 +- .../odeint/test_external/mtl4/mtl4_resize.cpp | 89 +++++ 10 files changed, 719 insertions(+), 222 deletions(-) create mode 100644 boost/numeric/odeint/external/mtl4/implicit_euler_mtl4.hpp create mode 100644 boost/numeric/odeint/external/mtl4/mtl4_resize.hpp create mode 100644 libs/numeric/odeint/examples/mtl/implicit_euler_mtl.cpp delete mode 100644 libs/numeric/odeint/examples/mtl/mtl_bindings.hpp delete mode 100644 libs/numeric/odeint/test_external/mtl/gauss_packet.cpp delete mode 100644 libs/numeric/odeint/test_external/mtl/mtl_bindings.hpp rename libs/numeric/odeint/test_external/{mtl => mtl4}/Jamfile (51%) create mode 100644 libs/numeric/odeint/test_external/mtl4/mtl4_resize.cpp diff --git a/boost/numeric/odeint/external/mtl4/implicit_euler_mtl4.hpp b/boost/numeric/odeint/external/mtl4/implicit_euler_mtl4.hpp new file mode 100644 index 00000000..3588ed20 --- /dev/null +++ b/boost/numeric/odeint/external/mtl4/implicit_euler_mtl4.hpp @@ -0,0 +1,162 @@ +/* +[begin_description] +Modification of the implicit Euler method, works with the MTL4 matrix library only. +[end_description] + +Copyright 2009-2011 Karsten Ahnert +Copyright 2009-2011 Mario Mulansky +Copyright 2012 Andreas Angelopoulos + +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_IMPLICIT_EULER_MTL4_HPP_INCLUDED +#define BOOST_NUMERIC_ODEINT_EXTERNAL_IMPLICIT_EULER_MTL4_HPP_INCLUDED + + +#include + +#include +#include +#include + +#include + +#include +#include + + + + +namespace boost { +namespace numeric { +namespace odeint { + + +template< class ValueType , class Resizer = initially_resizer > +class implicit_euler_mtl4 +{ + +public: + + typedef ValueType value_type; + typedef value_type time_type; + typedef mtl::dense_vector state_type; + + typedef state_wrapper< state_type > wrapped_state_type; + typedef state_type deriv_type; + typedef state_wrapper< deriv_type > wrapped_deriv_type; + typedef mtl::compressed2D< value_type > matrix_type; + typedef state_wrapper< matrix_type > wrapped_matrix_type; + + typedef Resizer resizer_type; + typedef stepper_tag stepper_category; + + typedef implicit_euler_mtl4< ValueType , Resizer > stepper_type; + + + implicit_euler_mtl4( const value_type epsilon = 1E-6 ) + : m_epsilon( epsilon ) , m_resizer() , + m_dxdt() , m_x() , + m_identity() , m_jacobi() + { } + + + template< class System > + void do_step( System system , state_type &x , time_type t , time_type dt ) + { + typedef typename odeint::unwrap_reference< System >::type system_type; + typedef typename odeint::unwrap_reference< typename system_type::first_type >::type deriv_func_type; + typedef typename odeint::unwrap_reference< typename system_type::second_type >::type jacobi_func_type; + system_type &sys = system; + deriv_func_type &deriv_func = sys.first; + jacobi_func_type &jacobi_func = sys.second; + + m_resizer.adjust_size( x , detail::bind( + &stepper_type::template resize_impl< state_type > , detail::ref( *this ) , detail::_1 ) ); + + m_identity.m_v = 1; + + t += dt; + m_x.m_v = x; + + deriv_func( x , m_dxdt.m_v , t ); + jacobi_func( x , m_jacobi.m_v , t ); + + + m_dxdt.m_v *= -dt; + + m_jacobi.m_v *= dt; + m_jacobi.m_v -= m_identity.m_v ; + + + + // using ilu_0 preconditioning -incomplete LU factorisation + // itl::pc::diagonal L(m_jacobi.m_v); + itl::pc::ilu_0 L( m_jacobi.m_v ); + + solve( m_jacobi.m_v , m_x.m_v , m_dxdt.m_v , L ); + x+= m_x.m_v; + + + } + + + template< class StateType > + void adjust_size( const StateType &x ) + { + resize_impl( x ); + } + + +private: + + + /* + Applying approximate iteractive linear solvers + default solver is Biconjugate gradient stabilized method + itl::bicgstab(A, x, b, L, iter); + */ + template < class LinearOperator, class HilbertSpaceX, class HilbertSpaceB, class Preconditioner> + void solve(const LinearOperator& A, HilbertSpaceX& x, const HilbertSpaceB& b, + const Preconditioner& L, int max_iteractions =500) + { + // Termination criterion: r < 1e-6 * b or N iterations + itl::basic_iteration< double > iter( b , max_iteractions , 1e-6 ); + itl::bicgstab( A , x , b , L , iter ); + + } + + + template< class StateIn > + bool resize_impl( const StateIn &x ) + { + bool resized = false; + resized |= adjust_size_by_resizeability( m_dxdt , x , typename is_resizeable::type() ); + resized |= adjust_size_by_resizeability( m_x , x , typename is_resizeable::type() ); + resized |= adjust_size_by_resizeability( m_identity , x , typename is_resizeable::type() ); + resized |= adjust_size_by_resizeability( m_jacobi , x , typename is_resizeable::type() ); + return resized; + } + + +private: + + value_type m_epsilon; + resizer_type m_resizer; + wrapped_deriv_type m_dxdt; + wrapped_state_type m_x; + wrapped_matrix_type m_identity; + wrapped_matrix_type m_jacobi; +}; + + +} // odeint +} // numeric +} // boost + + +#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_IMPLICIT_EULER_MTL4_HPP_INCLUDED diff --git a/boost/numeric/odeint/external/mtl4/mtl4_resize.hpp b/boost/numeric/odeint/external/mtl4/mtl4_resize.hpp new file mode 100644 index 00000000..93569747 --- /dev/null +++ b/boost/numeric/odeint/external/mtl4/mtl4_resize.hpp @@ -0,0 +1,133 @@ +/* +[begin_description] +Modification of the implicit Euler method, works with the MTL4 matrix library only. +[end_description] + +Copyright 2009-2011 Karsten Ahnert +Copyright 2009-2011 Mario Mulansky +Copyright 2012 Andreas Angelopoulos + +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_MTL4_RESIZE_HPP_INCLUDED +#define BOOST_NUMERIC_ODEINT_EXTERNAL_MTL4_RESIZE_HPP_INCLUDED + +#include +#include +#include + +#include +#include +#include + + +namespace boost { +namespace numeric { +namespace odeint { + + +template< class Value , class Parameters > +struct is_resizeable< mtl::dense_vector< Value , Parameters > > +{ + typedef boost::true_type type; + const static bool value = type::value; +}; + +template< class Value , class Parameters > +struct is_resizeable< mtl::dense2D< Value , Parameters > > +{ + typedef boost::true_type type; + const static bool value = type::value; +}; + +template< class Value , class Parameters > +struct is_resizeable< mtl::compressed2D< Value , Parameters > > +{ + typedef boost::true_type type; + const static bool value = type::value; +}; + + + + +template< class Value , class Parameters > +struct same_size_impl< mtl::dense_vector< Value , Parameters > , mtl::dense_vector< Value , Parameters > > +{ + static bool same_size( const mtl::dense_vector< Value , Parameters > &v1 , + const mtl::dense_vector< Value , Parameters > &v2 ) + { + return mtl::size( v1 ) == mtl::size( v2 ); + } +}; + +template< class Value , class Parameters > +struct resize_impl< mtl::dense_vector< Value , Parameters > , mtl::dense_vector< Value , Parameters > > +{ + static void resize( mtl::dense_vector< Value , Parameters > &v1 , + const mtl::dense_vector< Value , Parameters > &v2 ) + { + v1.change_dim( mtl::size( v2 ) ); + } +}; + + + +template< class Value , class MatrixParameters , class VectorParameters > +struct same_size_impl< mtl::dense2D< Value , MatrixParameters > , mtl::dense_vector< Value , VectorParameters > > +{ + static bool same_size( const mtl::dense2D< Value , MatrixParameters > &m , + const mtl::dense_vector< Value , VectorParameters > &v ) + { + return ( ( mtl::size( v ) == m.num_cols() ) && ( mtl::size( v ) == m.num_rows() ) ); + } +}; + +template< class Value , class MatrixParameters , class VectorParameters > +struct resize_impl< mtl::dense2D< Value , MatrixParameters > , mtl::dense_vector< Value , VectorParameters > > +{ + static void resize( mtl::dense2D< Value , MatrixParameters > &m , + const mtl::dense_vector< Value , VectorParameters > &v ) + { + m.change_dim( mtl::size( v ) , mtl::size( v ) , false ); + } +}; + + + + +template< class Value , class MatrixParameters , class VectorParameters > +struct same_size_impl< mtl::compressed2D< Value , MatrixParameters > , mtl::dense_vector< Value , VectorParameters > > +{ + static bool same_size( const mtl::compressed2D< Value , MatrixParameters > &m , + const mtl::dense_vector< Value , VectorParameters > &v ) + { + return ( ( mtl::size( v ) == m.num_cols() ) && ( mtl::size( v ) == m.num_rows() ) ); + } +}; + +template< class Value , class MatrixParameters , class VectorParameters > +struct resize_impl< mtl::compressed2D< Value , MatrixParameters > , mtl::dense_vector< Value , VectorParameters > > +{ + static void resize( mtl::compressed2D< Value , MatrixParameters > &m , + const mtl::dense_vector< Value , VectorParameters > &v ) + { + m.change_dim( mtl::size( v ) , mtl::size( v ) ); + } +}; + + + + + + + + +} // namespace odeint +} // namesapce numeric +} // namespace boost + +#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_MTL4_RESIZE_HPP_INCLUDED diff --git a/libs/numeric/odeint/examples/mtl/Jamfile b/libs/numeric/odeint/examples/mtl/Jamfile index 403a369e..aa61fb1a 100644 --- a/libs/numeric/odeint/examples/mtl/Jamfile +++ b/libs/numeric/odeint/examples/mtl/Jamfile @@ -3,13 +3,16 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +MTL4_INCLUDE = /home/karsten/boost/MTL-4.0.8862-Linux/usr/include ; project : requirements ../../../../.. + $(MTL4_INCLUDE) BOOST_ALL_NO_LIB=1 : build-dir . : default-build release ; -exe gauss_packet : gauss_packet.cpp ; \ No newline at end of file +exe gauss_packet : gauss_packet.cpp ; +exe implicit_euler_mtl : implicit_euler_mtl.cpp ; \ No newline at end of file diff --git a/libs/numeric/odeint/examples/mtl/gauss_packet.cpp b/libs/numeric/odeint/examples/mtl/gauss_packet.cpp index 7daf2189..cfd6ed8d 100644 --- a/libs/numeric/odeint/examples/mtl/gauss_packet.cpp +++ b/libs/numeric/odeint/examples/mtl/gauss_packet.cpp @@ -16,9 +16,9 @@ #include #include -#include "mtl_bindings.hpp" - +#include +#include using namespace std; diff --git a/libs/numeric/odeint/examples/mtl/implicit_euler_mtl.cpp b/libs/numeric/odeint/examples/mtl/implicit_euler_mtl.cpp new file mode 100644 index 00000000..eb1bd58d --- /dev/null +++ b/libs/numeric/odeint/examples/mtl/implicit_euler_mtl.cpp @@ -0,0 +1,314 @@ +#include +#include +#include +#include "time.h" + +#include +#include +#include + +#include + +using namespace std; +using namespace boost::numeric::odeint; + +namespace phoenix = boost::phoenix; + + + +typedef mtl::dense_vector< double > vec_mtl4; +typedef mtl::compressed2D< double > mat_mtl4; + +typedef boost::numeric::ublas::vector< double > vec_ublas; +typedef boost::numeric::ublas::matrix< double > mat_ublas; + + +// two systems defined 1 & 2 both are mostly sparse with the number of element variable +struct system1_mtl4 +{ + + void operator()( const vec_mtl4 &x , vec_mtl4 &dxdt , double t ) + { + int size = mtl::size(x); + + dxdt[ 0 ] = -0.06*x[0]; + + for (int i =1; i< size ; ++i){ + + dxdt[ i ] = 4.2*x[i-1]-2.2*x[i]*x[i]; + } + + } +}; + +struct jacobi1_mtl4 +{ + void operator()( const vec_mtl4 &x , mat_mtl4 &J , const double &t ) + { + int size = mtl::size(x); + mtl::matrix::inserter ins(J); + + ins[0][0]=-0.06; + + for (int i =1; i< size ; ++i) + { + ins[i][i-1] = + 4.2; + ins[i][i] = -4.2*x[i]; + } + } +}; + + + +struct system1_ublas +{ + + void operator()( const vec_ublas &x , vec_ublas &dxdt , double t ) + { + int size = x.size(); + + dxdt[ 0 ] = -0.06*x[0]; + + for (int i =1; i< size ; ++i){ + + dxdt[ i ] = 4.2*x[i-1]-2.2*x[i]*x[i]; + } + + } +}; + +struct jacobi1_ublas +{ + void operator()( const vec_ublas &x , mat_ublas &J , const double &t ) + { + int size = x.size(); +// mtl::matrix::inserter ins(J); + + J(0,0)=-0.06; + + for (int i =1; i< size ; ++i){ +//ins[i][0]=120.0*x[i]; + J(i,i-1) = + 4.2; + J(i,i) = -4.2*x[i]; + + } + } +}; + +struct system2_mtl4 +{ + + void operator()( const vec_mtl4 &x , vec_mtl4 &dxdt , double t ) + { + int size = mtl::size(x); + + + for (int i =0; i< size/5 ; i+=5){ + + dxdt[ i ] = -0.5*x[i]; + dxdt[i+1]= +25*x[i+1]*x[i+2]-740*x[i+3]*x[i+3]+4.2e-2*x[i]; + dxdt[i+2]= +25*x[i]*x[i]-740*x[i+3]*x[i+3]; + dxdt[i+3]= -25*x[i+1]*x[i+2]+740*x[i+3]*x[i+3]; + dxdt[i+4] = 0.250*x[i]*x[i+1]-44.5*x[i+3]; + + } + + } +}; + +struct jacobi2_mtl4 +{ + void operator()( const vec_mtl4 &x , mat_mtl4 &J , const double &t ) + { + int size = mtl::size(x); + mtl::matrix::inserter ins(J); + + for (int i =0; i< size/5 ; i+=5){ + + ins[ i ][i] = -0.5; + ins[i+1][i+1]=25*x[i+2]; + ins[i+1][i+2] = 25*x[i+1]; + ins[i+1][i+3] = -740*2*x[i+3]; + ins[i+1][i] =+4.2e-2; + + ins[i+2][i]= 50*x[i]; + ins[i+2][i+3]= -740*2*x[i+3]; + ins[i+3][i+1] = -25*x[i+2]; + ins[i+3][i+2] = -25*x[i+1]; + ins[i+3][i+3] = +740*2*x[i+3]; + ins[i+4][i] = 0.25*x[i+1]; + ins[i+4][i+1] =0.25*x[i]; + ins[i+4][i+3]=-44.5; + + + + } + } +}; + + + +struct system2_ublas +{ + + void operator()( const vec_ublas &x , vec_ublas &dxdt , double t ) + { + int size = x.size(); + for (int i =0; i< size/5 ; i+=5){ + + dxdt[ i ] = -4.2e-2*x[i]; + dxdt[i+1]= +25*x[i+1]*x[i+2]-740*x[i+3]*x[i+3]+4.2e-2*x[i]; + dxdt[i+2]= +25*x[i]*x[i]-740*x[i+3]*x[i+3]; + dxdt[i+3]= -25*x[i+1]*x[i+2]+740*x[i+3]*x[i+3]; + dxdt[i+4] = 0.250*x[i]*x[i+1]-44.5*x[i+3]; + + } + + } +}; + +struct jacobi2_ublas +{ + void operator()( const vec_ublas &x , mat_ublas &J , const double &t ) + { + int size = x.size(); + + for (int i =0; i< size/5 ; i+=5){ + + J(i ,i) = -4.2e-2; + J(i+1,i+1)=25*x[i+2]; + J(i+1,i+2) = 25*x[i+1]; + J(i+1,i+3) = -740*2*x[i+3]; + J(i+1,i) =+4.2e-2; + + J(i+2,i)= 50*x[i]; + J(i+2,i+3)= -740*2*x[i+3]; + J(i+3,i+1) = -25*x[i+2]; + J(i+3,i+2) = -25*x[i+1]; + J(i+3,i+3) = +740*2*x[i+3]; + J(i+4,i) = 0.25*x[i+1]; + J(i+4,i+1) =0.25*x[i]; + J(i+4,i+3)=-44.5; + + + + } + + + } +}; + + + + +void testRidiculouslyMassiveArray( int size ) +{ + typedef boost::numeric::odeint::implicit_euler_mtl4 < double > mtl4stepper; + typedef boost::numeric::odeint::implicit_euler< double > booststepper; + + vec_mtl4 x(size , 0.0); + x[0]=1; + + + double dt = 0.02; + double endtime = 10.0; + + clock_t tstart_mtl4 = clock(); + size_t num_of_steps_mtl4 = integrate_const( + mtl4stepper() , + make_pair( system1_mtl4() , jacobi1_mtl4() ) , + x , 0.0 , endtime , dt ); + clock_t tend_mtl4 = clock() ; + + clog << x[0] << endl; + clog << num_of_steps_mtl4 << " time elapsed: " << (double)(tend_mtl4-tstart_mtl4 )/CLOCKS_PER_SEC << endl; + + vec_ublas x_ublas(size , 0.0); + x_ublas[0]=1; + + clock_t tstart_boost = clock(); + size_t num_of_steps_ublas = integrate_const( + booststepper() , + make_pair( system1_ublas() , jacobi1_ublas() ) , + x_ublas , 0.0 , endtime , dt ); + clock_t tend_boost = clock() ; + + clog << x_ublas[0] << endl; + clog << num_of_steps_ublas << " time elapsed: " << (double)(tend_boost-tstart_boost)/CLOCKS_PER_SEC<< endl; + + clog << "dt_ublas/dt_mtl4 = " << (double)( tend_boost-tstart_boost )/( tend_mtl4-tstart_mtl4 ) << endl << endl; + return ; +} + + + +void testRidiculouslyMassiveArray2( int size ) +{ + typedef boost::numeric::odeint::implicit_euler_mtl4 < double > mtl4stepper; + typedef boost::numeric::odeint::implicit_euler< double > booststepper; + + + vec_mtl4 x(size , 0.0); + x[0]=100; + + + double dt = 0.01; + double endtime = 10.0; + + clock_t tstart_mtl4 = clock(); + size_t num_of_steps_mtl4 = integrate_const( + mtl4stepper() , + make_pair( system1_mtl4() , jacobi1_mtl4() ) , + x , 0.0 , endtime , dt ); + + + clock_t tend_mtl4 = clock() ; + + clog << x[0] << endl; + clog << num_of_steps_mtl4 << " time elapsed: " << (double)(tend_mtl4-tstart_mtl4 )/CLOCKS_PER_SEC << endl; + + vec_ublas x_ublas(size , 0.0); + x_ublas[0]=100; + + clock_t tstart_boost = clock(); + size_t num_of_steps_ublas = integrate_const( + booststepper() , + make_pair( system1_ublas() , jacobi1_ublas() ) , + x_ublas , 0.0 , endtime , dt ); + + + clock_t tend_boost = clock() ; + + clog << x_ublas[0] << endl; + clog << num_of_steps_ublas << " time elapsed: " << (double)(tend_boost-tstart_boost)/CLOCKS_PER_SEC<< endl; + + clog << "dt_ublas/dt_mtl4 = " << (double)( tend_boost-tstart_boost )/( tend_mtl4-tstart_mtl4 ) << endl << endl; + return ; +} + + + + +int main( int argc , char **argv ) +{ + std::vector< size_t > length; + length.push_back( 8 ); + length.push_back( 16 ); + length.push_back( 32 ); + length.push_back( 64 ); + length.push_back( 128 ); + length.push_back( 256 ); + + for( size_t i=0 ; i -#include - -namespace boost { namespace numeric { namespace odeint { - -template< class Value , class Parameters > -struct is_resizeable< mtl::dense_vector< Value , Parameters > > -{ // declare resizeablility - typedef boost::true_type type; - const static bool value = type::value; -}; - -template< class Value , class Parameters > //, class Value2 , class Parameters2 > -struct same_size_impl< mtl::dense_vector< Value , Parameters > , mtl::dense_vector< Value , Parameters > > -{ // define how to check size - static bool same_size( const mtl::dense_vector< Value , Parameters > &v1 , - const mtl::dense_vector< Value , Parameters > &v2 ) - { - return mtl::size( v1 ) == mtl::size( v2 ); - } -}; - -template< class Value , class Parameters > -struct resize_impl< mtl::dense_vector< Value , Parameters > , mtl::dense_vector< Value , Parameters > > -{ // define how to resize - static void resize( mtl::dense_vector< Value , Parameters > &v1 , - const mtl::dense_vector< Value , Parameters > &v2 ) - { - v1.change_dim( mtl::size( v2 ) ); - } -}; - -} } } - -//] - -#endif /* MTL_BINDINGS_HPP_ */ diff --git a/libs/numeric/odeint/test_external/mtl/gauss_packet.cpp b/libs/numeric/odeint/test_external/mtl/gauss_packet.cpp deleted file mode 100644 index 6b15d3c0..00000000 --- a/libs/numeric/odeint/test_external/mtl/gauss_packet.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * gauss_packet.cpp - * - * Schroedinger equation with potential barrier and periodic boundary conditions - * Initial Gauss packet moving to the right - * - * pipe output into gnuplot to see animation - * - * Implementation of Hamilton operator via MTL library - * - * Created on: Oct 26, 2011 - * Author: mario - */ - -#include -#include - -#include "mtl_bindings.hpp" - -#include -#include - -#include - -using namespace std; -using namespace boost::numeric::odeint; - -typedef mtl::dense_vector< complex< double > > state_type; - -struct hamiltonian { - - typedef mtl::compressed2D< complex< double > > matrix_type; - matrix_type m_H; - - hamiltonian( const int N ) : m_H( N , N ) - { - // constructor with zero potential - m_H = 0.0; - initialize_kinetic_term(); - } - - //template< mtl::compressed2D< double > > - hamiltonian( mtl::compressed2D< double > &V ) : m_H( num_rows( V ) , num_cols( V ) ) - { - // use potential V in hamiltonian - m_H = complex( 0.0 , -1.0 ) * V; - initialize_kinetic_term(); - } - - void initialize_kinetic_term( ) - { - const int N = num_rows( m_H ); - mtl::matrix::inserter< matrix_type , mtl::update_plus< complex > > ins( m_H ); - const double z = 1.0; - // fill diagonal and upper and lower diagonal - for( int i = 0 ; i( 0.0 , -z ); - ins[ i ][ i ] << complex< double >( 0.0 , z ); - ins[ (i+1) % N ][ i ] << complex< double >( 0.0 , -z ); - } - } - - void operator()( const state_type &psi , state_type &dpsidt , const double t ) - { - dpsidt = m_H * psi; - } - -}; - -struct write_for_gnuplot -{ - size_t m_every , m_count; - - write_for_gnuplot( size_t every = 10 ) - : m_every( every ) , m_count( 0 ) { } - - void operator()( const state_type &x , double t ) - { - if( ( m_count % m_every ) == 0 ) - { - //clog << t << endl; - cout << "p [0:" << mtl::size(x) << "][0:0.02] '-'" << endl; - for( size_t i=0 ; i( 0.0 , k0*i ) ); - //x[i] += 2.0*exp( -(i+N0-N)*(i+N0-N) / ( 4.0*sigma0*sigma0 ) ) * exp( complex< double >( 0.0 , -k0*i ) ); - } - x /= mtl::two_norm( x ); - - typedef runge_kutta4< state_type , double , state_type , double , vector_space_algebra > stepper; - - // create potential barrier - mtl::compressed2D< double > V( N , N ); - V = 0.0; - { - mtl::matrix::inserter< mtl::compressed2D< double > > ins( V ); - for( int i=0 ; i - -namespace boost { namespace numeric { namespace odeint { - -template< class Value1 , class Parameters1 , class Value2 , class Parameters2 > -bool same_size( mtl::dense_vector< Value1 , Parameters1 > &v1 , - const mtl::dense_vector< Value2 , Parameters2 > &v2 ) -{ - return mtl::size( v1 ) == mtl::size( v2 ); -} - -template< class Value1 , class Parameters1 , class Value2 , class Parameters2 > -void resize( mtl::dense_vector< Value1 , Parameters1 > &v1 , - const mtl::dense_vector< Value2 , Parameters2 > &v2 ) -{ - v1.change_dim( mtl::size( v2 ) ); -} - -} } } - -#endif /* MTL_BINDINGS_HPP_ */ diff --git a/libs/numeric/odeint/test_external/mtl/Jamfile b/libs/numeric/odeint/test_external/mtl4/Jamfile similarity index 51% rename from libs/numeric/odeint/test_external/mtl/Jamfile rename to libs/numeric/odeint/test_external/mtl4/Jamfile index 403a369e..1e72934d 100644 --- a/libs/numeric/odeint/test_external/mtl/Jamfile +++ b/libs/numeric/odeint/test_external/mtl4/Jamfile @@ -3,13 +3,26 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +import testing ; +import boost ; + +boost.use-project ; + +MTL4_INCLUDE = /home/karsten/boost/MTL-4.0.8862-Linux/usr/include ; project : requirements + /boost/test//boost_unit_test_framework ../../../../.. + $(MTL4_INCLUDE) BOOST_ALL_NO_LIB=1 - : build-dir . + static + : : default-build release ; -exe gauss_packet : gauss_packet.cpp ; \ No newline at end of file +test-suite "odeint-mtl4" + : + [ run mtl4_resize.cpp ] + : valgrind + ; diff --git a/libs/numeric/odeint/test_external/mtl4/mtl4_resize.cpp b/libs/numeric/odeint/test_external/mtl4/mtl4_resize.cpp new file mode 100644 index 00000000..7c65d289 --- /dev/null +++ b/libs/numeric/odeint/test_external/mtl4/mtl4_resize.cpp @@ -0,0 +1,89 @@ +/* Boost mtl4_resize.cpp test file + + Copyright 2009 Karsten Ahnert + Copyright 2009 Mario Mulansky + + This file tests the odeint library with the mtl4 routines. + + 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 test_mtl4_resize + +#include + +#include +#include + +namespace odeint = boost::numeric::odeint; + + +BOOST_AUTO_TEST_CASE( test_dense_vector_resizeability ) +{ + BOOST_CHECK( odeint::is_resizeable< mtl::dense_vector< double > >::value ); +} + +BOOST_AUTO_TEST_CASE( test_dense2D_resizeability ) +{ + BOOST_CHECK( odeint::is_resizeable< mtl::dense2D< double > >::value ); +} + +BOOST_AUTO_TEST_CASE( test_compressed2D_resizeability ) +{ + BOOST_CHECK( odeint::is_resizeable< mtl::compressed2D< double > >::value ); +} + + + +BOOST_AUTO_TEST_CASE( test_dense_vector_vector_same_size ) +{ + mtl::dense_vector< double > v1( 10 ) , v2( 10 ); + BOOST_CHECK( odeint::same_size( v2 , v1 ) ); +} + +BOOST_AUTO_TEST_CASE( test_dense_vector_dense2D_same_size ) +{ + mtl::dense_vector< double > v( 10 ); + mtl::dense2D< double > m( 10 , 10 ); + BOOST_CHECK( odeint::same_size( m , v ) ); +} + +BOOST_AUTO_TEST_CASE( test_dense_vector_compressed2D_same_size ) +{ + mtl::dense_vector< double > v( 10 ); + mtl::compressed2D< double > m( 10 , 10 ); + BOOST_CHECK( odeint::same_size( m , v ) ); +} + + + + +BOOST_AUTO_TEST_CASE( test_dense_vector_vector_resize ) +{ + mtl::dense_vector< double > v1( 10 ); + mtl::dense_vector< double > v2; + odeint::resize( v2 , v1 ); + BOOST_CHECK( mtl::size( v2 ) == mtl::size( v1 ) ); +} + +BOOST_AUTO_TEST_CASE( test_dense_vector_dense2D_resize ) +{ + mtl::dense_vector< double > v( 10 ); + mtl::dense2D< double > m; + + odeint::resize( m , v ); + BOOST_CHECK( m.num_cols() == mtl::size( v ) ); + BOOST_CHECK( m.num_rows() == mtl::size( v ) ); +} + +BOOST_AUTO_TEST_CASE( test_dense_vector_compressed2D_resize ) +{ + mtl::dense_vector< double > v( 10 ); + mtl::compressed2D< double > m; + + odeint::resize( m , v ); + BOOST_CHECK( m.num_cols() == mtl::size( v ) ); + BOOST_CHECK( m.num_rows() == mtl::size( v ) ); +} From f1fa4bfb7811ced833b200e7a160e9882fb447c9 Mon Sep 17 00:00:00 2001 From: Mario Mulansky Date: Tue, 3 Jul 2012 12:15:55 +0200 Subject: [PATCH 12/12] changed integrate_const implementation --- .../integrate/detail/integrate_const.hpp | 159 ++++++++++++++++++ .../integrate/detail/integrate_n_steps.hpp | 1 + .../odeint/integrate/integrate_const.hpp | 17 +- libs/numeric/odeint/test/integrate.cpp | 12 +- 4 files changed, 176 insertions(+), 13 deletions(-) create mode 100644 boost/numeric/odeint/integrate/detail/integrate_const.hpp diff --git a/boost/numeric/odeint/integrate/detail/integrate_const.hpp b/boost/numeric/odeint/integrate/detail/integrate_const.hpp new file mode 100644 index 00000000..2eb7ae0a --- /dev/null +++ b/boost/numeric/odeint/integrate/detail/integrate_const.hpp @@ -0,0 +1,159 @@ +/* + [auto_generated] + boost/numeric/odeint/integrate/detail/integrate_const.hpp + + [begin_description] + integrate const implementation + [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_INTEGRATE_DETAIL_INTEGRATE_CONST_HPP_INCLUDED +#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_CONST_HPP_INCLUDED + +#include +#include +#include +#include + +#include + +namespace boost { +namespace numeric { +namespace odeint { +namespace detail { + +// forward declaration +template< class Stepper , class System , class State , class Time , class Observer > +size_t integrate_adaptive( + Stepper stepper , System system , State &start_state , + Time &start_time , Time end_time , Time &dt , + Observer observer , controlled_stepper_tag +); + + +template< class Stepper , class System , class State , class Time , class Observer > +size_t integrate_const( + Stepper stepper , System system , State &start_state , + Time start_time , Time end_time , Time dt , + Observer observer , stepper_tag +) +{ + typename odeint::unwrap_reference< Observer >::type &obs = observer; + + Time time = start_time; + int step = 0; + + while( less_eq_with_sign( time+dt , end_time , dt ) ) + { + obs( start_state , time ); + stepper.do_step( system , start_state , time , dt ); + // direct computation of the time avoids error propagation happening when using time += dt + // we need clumsy type analysis to get boost units working here + ++step; + time = start_time + static_cast< typename unit_value_type