blob: 6808a57bdbf2318474b0b72395c39c4a9cda2335 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
[auto_generated]
boost/numeric/odeint/integrate/max_step_checker.hpp
[begin_description]
Throws exception if too many steps are performed.
[end_description]
Copyright 2015 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_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 {
/**
* \brief A class for performing overflow checks on the step count in integrate functions.
*
* Provide an instance of this class to integrate functions if you want to throw a runtime error if
* too many steps are performed without progress during the integrate routine.
*/
class max_step_checker
{
public:
protected:
const int m_max_steps;
int m_steps;
public:
/**
* \brief Construct the max_step_checker.
* max_steps is the maximal number of iterations allowed before runtime_error is thrown.
*/
max_step_checker(const int max_steps = 500)
: m_max_steps(max_steps)
{
reset();
}
/**
* \brief Resets the max_step_checker by setting the internal counter to 0.
*/
void reset()
{
m_steps = 0;
}
/**
* \brief Increases the counter and performs the iteration check
*/
void operator()(void)
{
if( m_steps++ >= m_max_steps )
{
char error_msg[200];
sprintf(error_msg, "Max number of iterations exceeded (%d).", m_max_steps);
BOOST_THROW_EXCEPTION( no_progress_error(error_msg) );
}
}
};
/**
* \brief A class for performing overflow checks on the failed step count in step size adjustments.
*
* Used internally within the dense output stepper and integrate routines.
*/
class failed_step_checker : public max_step_checker
{
public:
/**
* \brief Construct the failed_step_checker.
* max_steps is the maximal number of iterations allowed before runtime_error is thrown.
*/
failed_step_checker(const int max_steps = 500)
: max_step_checker(max_steps)
{}
/**
* \brief Increases the counter and performs the iteration check
*/
void operator()(void)
{
if( m_steps++ >= m_max_steps )
{
char error_msg[200];
sprintf(error_msg, "Max number of iterations exceeded (%d). A new step size was not found.", m_max_steps);
BOOST_THROW_EXCEPTION( step_adjustment_error(error_msg) );
}
}
};
} // namespace odeint
} // namespace numeric
} // namespace boost
#endif
|