File indexing completed on 2025-12-16 09:58:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_MAX_STEP_CHECKER_HPP_INCLUDED
0018 #define BOOST_NUMERIC_ODEINT_INTEGRATE_MAX_STEP_CHECKER_HPP_INCLUDED
0019
0020 #include <stdexcept>
0021 #include <cstdio>
0022
0023 #include <boost/throw_exception.hpp>
0024 #include <boost/numeric/odeint/util/odeint_error.hpp>
0025
0026
0027 namespace boost {
0028 namespace numeric {
0029 namespace odeint {
0030
0031
0032
0033
0034
0035
0036
0037 class max_step_checker
0038 {
0039 public:
0040
0041 protected:
0042 const int m_max_steps;
0043 int m_steps;
0044
0045 public:
0046
0047
0048
0049
0050 max_step_checker(const int max_steps = 500)
0051 : m_max_steps(max_steps)
0052 {
0053 reset();
0054 }
0055
0056
0057
0058
0059 void reset()
0060 {
0061 m_steps = 0;
0062 }
0063
0064
0065
0066
0067 void operator()(void)
0068 {
0069 if( m_steps++ >= m_max_steps )
0070 {
0071 char error_msg[200];
0072 std::snprintf(error_msg, 200, "Max number of iterations exceeded (%d).", m_max_steps);
0073 BOOST_THROW_EXCEPTION( no_progress_error(error_msg) );
0074 }
0075 }
0076 };
0077
0078
0079
0080
0081
0082
0083
0084 class failed_step_checker : public max_step_checker
0085 {
0086
0087 public:
0088
0089
0090
0091
0092 failed_step_checker(const int max_steps = 500)
0093 : max_step_checker(max_steps)
0094 {}
0095
0096
0097
0098
0099 void operator()(void)
0100 {
0101 if( m_steps++ >= m_max_steps )
0102 {
0103 char error_msg[200];
0104 std::snprintf(error_msg, 200, "Max number of iterations exceeded (%d). A new step size was not found.", m_max_steps);
0105 BOOST_THROW_EXCEPTION( step_adjustment_error(error_msg) );
0106 }
0107 }
0108 };
0109
0110 }
0111 }
0112 }
0113
0114 #endif