Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:58:37

0001 /*
0002  [auto_generated]
0003  boost/numeric/odeint/integrate/max_step_checker.hpp
0004 
0005  [begin_description]
0006  Throws exception if too many steps are performed.
0007  [end_description]
0008 
0009  Copyright 2015 Mario Mulansky
0010 
0011  Distributed under the Boost Software License, Version 1.0.
0012  (See accompanying file LICENSE_1_0.txt or
0013  copy at http://www.boost.org/LICENSE_1_0.txt)
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  * \brief A class for performing overflow checks on the step count in integrate functions.
0033  *
0034  * Provide an instance of this class to integrate functions if you want to throw a runtime error if
0035  * too many steps are performed without progress during the integrate routine.
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      * \brief Construct the max_step_checker.
0048      * max_steps is the maximal number of iterations allowed before runtime_error is thrown.
0049      */
0050     max_step_checker(const int max_steps = 500)
0051         : m_max_steps(max_steps)
0052     {
0053         reset();
0054     }
0055 
0056     /**
0057      * \brief Resets the max_step_checker by setting the internal counter to 0.
0058      */
0059     void reset()
0060     {
0061         m_steps = 0;
0062     }
0063 
0064     /**
0065      * \brief Increases the counter and performs the iteration check
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  * \brief A class for performing overflow checks on the failed step count in step size adjustments.
0081  *
0082  * Used internally within the dense output stepper and integrate routines.
0083  */
0084 class failed_step_checker : public max_step_checker
0085 {
0086 
0087 public:
0088     /**
0089      * \brief Construct the failed_step_checker.
0090      * max_steps is the maximal number of iterations allowed before runtime_error is thrown.
0091      */
0092     failed_step_checker(const int max_steps = 500)
0093             : max_step_checker(max_steps)
0094     {}
0095 
0096     /**
0097      * \brief Increases the counter and performs the iteration check
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 } // namespace odeint
0111 } // namespace numeric
0112 } // namespace boost
0113 
0114 #endif