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/check_adapter.hpp
0004 
0005  [begin_description]
0006  Adapters to add checking facility to stepper and observer
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 #ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_CHECK_ADAPTER_HPP_INCLUDED
0017 #define BOOST_NUMERIC_ODEINT_INTEGRATE_CHECK_ADAPTER_HPP_INCLUDED
0018 
0019 #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
0020 #include <boost/numeric/odeint/stepper/controlled_step_result.hpp>
0021 
0022 
0023 namespace boost {
0024 namespace numeric {
0025 namespace odeint {
0026 
0027 template<class Stepper, class Checker,
0028          class StepperCategory = typename base_tag<typename Stepper::stepper_category>::type>
0029 class checked_stepper;
0030 
0031 
0032 /**
0033  * \brief Adapter to combine basic stepper and checker.
0034  */
0035 template<class Stepper, class Checker>
0036 class checked_stepper<Stepper, Checker, stepper_tag>
0037 {
0038 
0039 public:
0040     typedef Stepper stepper_type;
0041     typedef Checker checker_type;
0042     // forward stepper typedefs
0043     typedef typename stepper_type::state_type state_type;
0044     typedef typename stepper_type::value_type value_type;
0045     typedef typename stepper_type::deriv_type deriv_type;
0046     typedef typename stepper_type::time_type time_type;
0047 
0048 private:
0049     stepper_type &m_stepper;
0050     checker_type &m_checker;
0051 
0052 public:
0053     /**
0054      * \brief Construct the checked_stepper.
0055      */
0056     checked_stepper(stepper_type &stepper, checker_type &checker)
0057             : m_stepper(stepper), m_checker(checker) { }
0058 
0059     /**
0060      * \brief forward of the do_step method
0061      */
0062     template<class System, class StateInOut>
0063     void do_step(System system, StateInOut &state, const time_type t, const time_type dt)
0064     {
0065         // do the step
0066         m_stepper.do_step(system, state, t, dt);
0067         // call the checker
0068         m_checker();
0069     }
0070 };
0071 
0072 
0073 /**
0074  * \brief Adapter to combine controlled stepper and checker.
0075  */
0076 template<class ControlledStepper, class Checker>
0077 class checked_stepper<ControlledStepper, Checker, controlled_stepper_tag>
0078 {
0079 
0080 public:
0081     typedef ControlledStepper stepper_type;
0082     typedef Checker checker_type;
0083     // forward stepper typedefs
0084     typedef typename stepper_type::state_type state_type;
0085     typedef typename stepper_type::value_type value_type;
0086     typedef typename stepper_type::deriv_type deriv_type;
0087     typedef typename stepper_type::time_type time_type;
0088 
0089 private:
0090     stepper_type &m_stepper;
0091     checker_type &m_checker;
0092 
0093 public:
0094     /**
0095      * \brief Construct the checked_stepper.
0096      */
0097     checked_stepper(stepper_type &stepper, checker_type &checker)
0098             : m_stepper(stepper), m_checker(checker) { }
0099 
0100     /**
0101      * \brief forward of the do_step method
0102      */
0103     template< class System , class StateInOut >
0104     controlled_step_result try_step( System system , StateInOut &state , time_type &t , time_type &dt )
0105     {
0106         // do the step
0107         if( m_stepper.try_step(system, state, t, dt) == success )
0108         {
0109             // call the checker if step was successful
0110             m_checker();
0111             return success;
0112         } else
0113         {
0114             // step failed -> return fail
0115             return fail;
0116         }
0117     }
0118 };
0119 
0120 
0121 /**
0122  * \brief Adapter to combine dense out stepper and checker.
0123  */
0124 template<class DenseOutStepper, class Checker>
0125 class checked_stepper<DenseOutStepper, Checker, dense_output_stepper_tag>
0126 {
0127 
0128 public:
0129     typedef DenseOutStepper stepper_type;
0130     typedef Checker checker_type;
0131     // forward stepper typedefs
0132     typedef typename stepper_type::state_type state_type;
0133     typedef typename stepper_type::value_type value_type;
0134     typedef typename stepper_type::deriv_type deriv_type;
0135     typedef typename stepper_type::time_type time_type;
0136 
0137 private:
0138     stepper_type &m_stepper;
0139     checker_type &m_checker;
0140 
0141 public:
0142     /**
0143      * \brief Construct the checked_stepper.
0144      */
0145     checked_stepper(stepper_type &stepper, checker_type &checker)
0146             : m_stepper(stepper), m_checker(checker) { }
0147 
0148 
0149     template< class System >
0150     std::pair< time_type , time_type > do_step( System system )
0151     {
0152         m_checker();
0153         return m_stepper.do_step(system);
0154     }
0155 
0156     /* provide the remaining dense out stepper interface */
0157     template< class StateType >
0158     void initialize( const StateType &x0 , time_type t0 , time_type dt0 )
0159     { m_stepper.initialize(x0, t0, dt0); }
0160 
0161 
0162     template< class StateOut >
0163     void calc_state( time_type t , StateOut &x ) const
0164     { m_stepper.calc_state(t, x); }
0165 
0166     template< class StateOut >
0167     void calc_state( time_type t , const StateOut &x ) const
0168     { m_stepper.calc_state(t, x); }
0169 
0170     const state_type& current_state( void ) const
0171     { return m_stepper.current_state(); }
0172 
0173     time_type current_time( void ) const
0174     { return m_stepper.current_time(); }
0175 
0176     const state_type& previous_state( void ) const
0177     { return m_stepper.previous_state(); }
0178 
0179     time_type previous_time( void ) const
0180     { return m_stepper.previous_time(); }
0181 
0182     time_type current_time_step( void ) const
0183     { return m_stepper.current_time_step(); }
0184 
0185 };
0186 
0187 
0188 /**
0189  * \brief Adapter to combine observer and checker.
0190  */
0191 template<class Observer, class Checker>
0192 class checked_observer
0193 {
0194 public:
0195     typedef Observer observer_type;
0196     typedef Checker checker_type;
0197 
0198 private:
0199     observer_type &m_observer;
0200     checker_type &m_checker;
0201 
0202 public:
0203     checked_observer(observer_type &observer, checker_type &checker)
0204             : m_observer(observer), m_checker(checker)
0205     {}
0206 
0207     template< class State , class Time >
0208     void operator()(const State& state, Time t) const
0209     {
0210         // call the observer
0211         m_observer(state, t);
0212         // reset the checker
0213         m_checker.reset();
0214     }
0215 };
0216 
0217 
0218 } // namespace odeint
0219 } // namespace numeric
0220 } // namespace boost
0221 
0222 #endif