3 boost/numeric/odeint/integrate/max_step_checker.hpp
6 Throws exception if too many steps are performed.
9 Copyright 2015 Mario Mulansky
11 Distributed under the Boost Software License, Version 1.0.
12 (See accompanying file LICENSE_1_0.txt or
13 copy at http://www.boost.org/LICENSE_1_0.txt)
17 #ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_MAX_STEP_CHECKER_HPP_INCLUDED
18 #define BOOST_NUMERIC_ODEINT_INTEGRATE_MAX_STEP_CHECKER_HPP_INCLUDED
23 #include <boost/throw_exception.hpp>
24 #include <boost/numeric/odeint/util/odeint_error.hpp>
32 * \brief A class for performing overflow checks on the step count in integrate functions.
34 * Provide an instance of this class to integrate functions if you want to throw a runtime error if
35 * too many steps are performed without progress during the integrate routine.
37 class max_step_checker
42 const int m_max_steps;
47 * \brief Construct the max_step_checker.
48 * max_steps is the maximal number of iterations allowed before runtime_error is thrown.
50 max_step_checker(const int max_steps = 500)
51 : m_max_steps(max_steps)
57 * \brief Resets the max_step_checker by setting the internal counter to 0.
65 * \brief Increases the counter and performs the iteration check
69 if( m_steps++ >= m_max_steps )
72 sprintf(error_msg, "Max number of iterations exceeded (%d).", m_max_steps);
73 BOOST_THROW_EXCEPTION( no_progress_error(error_msg) );
80 * \brief A class for performing overflow checks on the failed step count in step size adjustments.
82 * Used internally within the dense output stepper and integrate routines.
84 class failed_step_checker : public max_step_checker
89 * \brief Construct the failed_step_checker.
90 * max_steps is the maximal number of iterations allowed before runtime_error is thrown.
92 failed_step_checker(const int max_steps = 500)
93 : max_step_checker(max_steps)
97 * \brief Increases the counter and performs the iteration check
101 if( m_steps++ >= m_max_steps )
104 sprintf(error_msg, "Max number of iterations exceeded (%d). A new step size was not found.", m_max_steps);
105 BOOST_THROW_EXCEPTION( step_adjustment_error(error_msg) );
110 } // namespace odeint
111 } // namespace numeric