123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_MAX_STEP_CHECKER_HPP_INCLUDED
- #define BOOST_NUMERIC_ODEINT_INTEGRATE_MAX_STEP_CHECKER_HPP_INCLUDED
- #include <stdexcept>
- #include <cstdio>
- #include <boost/throw_exception.hpp>
- #include <boost/numeric/odeint/util/odeint_error.hpp>
- namespace boost {
- namespace numeric {
- namespace odeint {
- class max_step_checker
- {
- public:
- protected:
- const int m_max_steps;
- int m_steps;
- public:
-
- max_step_checker(const int max_steps = 500)
- : m_max_steps(max_steps)
- {
- reset();
- }
-
- void reset()
- {
- m_steps = 0;
- }
-
- void operator()(void)
- {
- if( m_steps++ >= m_max_steps )
- {
- char error_msg[200];
- std::snprintf(error_msg, 200, "Max number of iterations exceeded (%d).", m_max_steps);
- BOOST_THROW_EXCEPTION( no_progress_error(error_msg) );
- }
- }
- };
- class failed_step_checker : public max_step_checker
- {
- public:
-
- failed_step_checker(const int max_steps = 500)
- : max_step_checker(max_steps)
- {}
-
- void operator()(void)
- {
- if( m_steps++ >= m_max_steps )
- {
- char error_msg[200];
- std::snprintf(error_msg, 200, "Max number of iterations exceeded (%d). A new step size was not found.", m_max_steps);
- BOOST_THROW_EXCEPTION( step_adjustment_error(error_msg) );
- }
- }
- };
- }
- }
- }
- #endif
|