/* boost/numeric/odeint/stepper/detail/adaptive_adams_coefficients.hpp [begin_description] Calculation of the coefficients for the adaptive adams stepper. [end_description] Copyright 2017 Valentin Noah Hartmann 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_DETAIL_ADAPTIVE_ADAMS_COEFFICIENTS_HPP_INCLUDED #define BOOST_NUMERIC_ODEINT_STEPPER_DETAIL_ADAPTIVE_ADAMS_COEFFICIENTS_HPP_INCLUDED #include #include #include #include #include #include #include #include #include namespace boost { namespace numeric { namespace odeint { namespace detail { template< size_t Steps, class Deriv, class Value = double, class Time = double, class Algebra = typename algebra_dispatcher< Deriv >::algebra_type, class Operations = typename operations_dispatcher< Deriv >::operations_type, class Resizer = initially_resizer > class adaptive_adams_coefficients { public: static const size_t steps = Steps; typedef unsigned short order_type; static const order_type order_value = steps; typedef Value value_type; typedef Deriv deriv_type; typedef Time time_type; typedef state_wrapper< deriv_type > wrapped_deriv_type; typedef rotating_buffer< time_type , steps+1 > time_storage_type; typedef Algebra algebra_type; typedef Operations operations_type; typedef Resizer resizer_type; typedef adaptive_adams_coefficients< Steps , Deriv , Value , Time , Algebra , Operations , Resizer > aac_type; adaptive_adams_coefficients( const algebra_type &algebra = algebra_type()) :m_eo(1), m_steps_init(1), beta(), phi(), m_ns(0), m_time_storage(), m_algebra(algebra), m_phi_resizer() { for (size_t i=0; i 1e-16 || m_eo >= m_ns) { m_ns = 0; } else if (m_ns < order_value + 2) { m_ns++; } for(size_t i=1+m_ns; i , detail::ref( *this ) , detail::_1 ) ); phi[o][0].m_v = dxdt; for(size_t i=1; im_algebra.for_each3(phi[o][i].m_v, phi[o][i-1].m_v, phi[o+1][i-1].m_v, typename Operations::template scale_sum2(1.0, -beta[o][i-1])); } else { this->m_algebra.for_each2(phi[o][i].m_v, phi[o][i-1].m_v, typename Operations::template scale_sum1(1.0)); } } }; void confirm() { beta.rotate(); phi.rotate(); m_time_storage.rotate(); if(m_steps_init < order_value+1) { ++m_steps_init; } }; void reset() { m_eo = 1; m_steps_init = 1; }; size_t m_eo; size_t m_steps_init; rotating_buffer, 2> beta; // beta[0] = beta(n) rotating_buffer, 3> phi; // phi[0] = phi(n+1) boost::array g; boost::array gs; private: template< class StateType > bool resize_phi_impl( const StateType &x ) { bool resized( false ); for(size_t i=0; i<(order_value + 2); ++i) { resized |= adjust_size_by_resizeability( phi[0][i], x, typename is_resizeable::type() ); resized |= adjust_size_by_resizeability( phi[1][i], x, typename is_resizeable::type() ); resized |= adjust_size_by_resizeability( phi[2][i], x, typename is_resizeable::type() ); } return resized; }; size_t m_ns; time_storage_type m_time_storage; static const size_t c_size = order_value + 2; boost::array c; algebra_type m_algebra; resizer_type m_phi_resizer; }; } // detail } // odeint } // numeric } // boost #endif