整理
This commit is contained in:
222
include/boost/numeric/odeint/integrate/check_adapter.hpp
Normal file
222
include/boost/numeric/odeint/integrate/check_adapter.hpp
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/check_adapter.hpp
|
||||
|
||||
[begin_description]
|
||||
Adapters to add checking facility to stepper and observer
|
||||
[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_CHECK_ADAPTER_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_CHECK_ADAPTER_HPP_INCLUDED
|
||||
|
||||
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
|
||||
#include <boost/numeric/odeint/stepper/controlled_step_result.hpp>
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
template<class Stepper, class Checker,
|
||||
class StepperCategory = typename base_tag<typename Stepper::stepper_category>::type>
|
||||
class checked_stepper;
|
||||
|
||||
|
||||
/**
|
||||
* \brief Adapter to combine basic stepper and checker.
|
||||
*/
|
||||
template<class Stepper, class Checker>
|
||||
class checked_stepper<Stepper, Checker, stepper_tag>
|
||||
{
|
||||
|
||||
public:
|
||||
typedef Stepper stepper_type;
|
||||
typedef Checker checker_type;
|
||||
// forward stepper typedefs
|
||||
typedef typename stepper_type::state_type state_type;
|
||||
typedef typename stepper_type::value_type value_type;
|
||||
typedef typename stepper_type::deriv_type deriv_type;
|
||||
typedef typename stepper_type::time_type time_type;
|
||||
|
||||
private:
|
||||
stepper_type &m_stepper;
|
||||
checker_type &m_checker;
|
||||
|
||||
public:
|
||||
/**
|
||||
* \brief Construct the checked_stepper.
|
||||
*/
|
||||
checked_stepper(stepper_type &stepper, checker_type &checker)
|
||||
: m_stepper(stepper), m_checker(checker) { }
|
||||
|
||||
/**
|
||||
* \brief forward of the do_step method
|
||||
*/
|
||||
template<class System, class StateInOut>
|
||||
void do_step(System system, StateInOut &state, const time_type t, const time_type dt)
|
||||
{
|
||||
// do the step
|
||||
m_stepper.do_step(system, state, t, dt);
|
||||
// call the checker
|
||||
m_checker();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Adapter to combine controlled stepper and checker.
|
||||
*/
|
||||
template<class ControlledStepper, class Checker>
|
||||
class checked_stepper<ControlledStepper, Checker, controlled_stepper_tag>
|
||||
{
|
||||
|
||||
public:
|
||||
typedef ControlledStepper stepper_type;
|
||||
typedef Checker checker_type;
|
||||
// forward stepper typedefs
|
||||
typedef typename stepper_type::state_type state_type;
|
||||
typedef typename stepper_type::value_type value_type;
|
||||
typedef typename stepper_type::deriv_type deriv_type;
|
||||
typedef typename stepper_type::time_type time_type;
|
||||
|
||||
private:
|
||||
stepper_type &m_stepper;
|
||||
checker_type &m_checker;
|
||||
|
||||
public:
|
||||
/**
|
||||
* \brief Construct the checked_stepper.
|
||||
*/
|
||||
checked_stepper(stepper_type &stepper, checker_type &checker)
|
||||
: m_stepper(stepper), m_checker(checker) { }
|
||||
|
||||
/**
|
||||
* \brief forward of the do_step method
|
||||
*/
|
||||
template< class System , class StateInOut >
|
||||
controlled_step_result try_step( System system , StateInOut &state , time_type &t , time_type &dt )
|
||||
{
|
||||
// do the step
|
||||
if( m_stepper.try_step(system, state, t, dt) == success )
|
||||
{
|
||||
// call the checker if step was successful
|
||||
m_checker();
|
||||
return success;
|
||||
} else
|
||||
{
|
||||
// step failed -> return fail
|
||||
return fail;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Adapter to combine dense out stepper and checker.
|
||||
*/
|
||||
template<class DenseOutStepper, class Checker>
|
||||
class checked_stepper<DenseOutStepper, Checker, dense_output_stepper_tag>
|
||||
{
|
||||
|
||||
public:
|
||||
typedef DenseOutStepper stepper_type;
|
||||
typedef Checker checker_type;
|
||||
// forward stepper typedefs
|
||||
typedef typename stepper_type::state_type state_type;
|
||||
typedef typename stepper_type::value_type value_type;
|
||||
typedef typename stepper_type::deriv_type deriv_type;
|
||||
typedef typename stepper_type::time_type time_type;
|
||||
|
||||
private:
|
||||
stepper_type &m_stepper;
|
||||
checker_type &m_checker;
|
||||
|
||||
public:
|
||||
/**
|
||||
* \brief Construct the checked_stepper.
|
||||
*/
|
||||
checked_stepper(stepper_type &stepper, checker_type &checker)
|
||||
: m_stepper(stepper), m_checker(checker) { }
|
||||
|
||||
|
||||
template< class System >
|
||||
std::pair< time_type , time_type > do_step( System system )
|
||||
{
|
||||
m_checker();
|
||||
return m_stepper.do_step(system);
|
||||
}
|
||||
|
||||
/* provide the remaining dense out stepper interface */
|
||||
template< class StateType >
|
||||
void initialize( const StateType &x0 , time_type t0 , time_type dt0 )
|
||||
{ m_stepper.initialize(x0, t0, dt0); }
|
||||
|
||||
|
||||
template< class StateOut >
|
||||
void calc_state( time_type t , StateOut &x ) const
|
||||
{ m_stepper.calc_state(t, x); }
|
||||
|
||||
template< class StateOut >
|
||||
void calc_state( time_type t , const StateOut &x ) const
|
||||
{ m_stepper.calc_state(t, x); }
|
||||
|
||||
const state_type& current_state( void ) const
|
||||
{ return m_stepper.current_state(); }
|
||||
|
||||
time_type current_time( void ) const
|
||||
{ return m_stepper.current_time(); }
|
||||
|
||||
const state_type& previous_state( void ) const
|
||||
{ return m_stepper.previous_state(); }
|
||||
|
||||
time_type previous_time( void ) const
|
||||
{ return m_stepper.previous_time(); }
|
||||
|
||||
time_type current_time_step( void ) const
|
||||
{ return m_stepper.current_time_step(); }
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Adapter to combine observer and checker.
|
||||
*/
|
||||
template<class Observer, class Checker>
|
||||
class checked_observer
|
||||
{
|
||||
public:
|
||||
typedef Observer observer_type;
|
||||
typedef Checker checker_type;
|
||||
|
||||
private:
|
||||
observer_type &m_observer;
|
||||
checker_type &m_checker;
|
||||
|
||||
public:
|
||||
checked_observer(observer_type &observer, checker_type &checker)
|
||||
: m_observer(observer), m_checker(checker)
|
||||
{}
|
||||
|
||||
template< class State , class Time >
|
||||
void operator()(const State& state, Time t) const
|
||||
{
|
||||
// call the observer
|
||||
m_observer(state, t);
|
||||
// reset the checker
|
||||
m_checker.reset();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
70
include/boost/numeric/odeint/integrate/detail/functors.hpp
Normal file
70
include/boost/numeric/odeint/integrate/detail/functors.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/detail/functors.hpp
|
||||
|
||||
[begin_description]
|
||||
some functors for the iterator based integrate routines
|
||||
[end_description]
|
||||
|
||||
Copyright 2009-2013 Karsten Ahnert
|
||||
Copyright 2009-2013 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_DETAIL_FUNCTORS_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_FUNCTORS_HPP_INCLUDED
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
namespace detail {
|
||||
|
||||
|
||||
template< class Observer >
|
||||
struct obs_caller {
|
||||
|
||||
size_t &m_n;
|
||||
Observer m_obs;
|
||||
|
||||
obs_caller( size_t &m , Observer &obs ) : m_n(m) , m_obs( obs ) {}
|
||||
|
||||
template< class State , class Time >
|
||||
void operator()( std::pair< const State & , const Time & > x )
|
||||
{
|
||||
typedef typename odeint::unwrap_reference< Observer >::type observer_type;
|
||||
observer_type &obs = m_obs;
|
||||
obs( x.first , x.second );
|
||||
m_n++;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Observer , class Time >
|
||||
struct obs_caller_time {
|
||||
|
||||
Time &m_t;
|
||||
Observer m_obs;
|
||||
|
||||
obs_caller_time( Time &t , Observer &obs ) : m_t(t) , m_obs( obs ) {}
|
||||
|
||||
template< class State >
|
||||
void operator()( std::pair< const State & , const Time & > x )
|
||||
{
|
||||
typedef typename odeint::unwrap_reference< Observer >::type observer_type;
|
||||
observer_type &obs = m_obs;
|
||||
obs( x.first , x.second );
|
||||
m_t = x.second;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_FUNCTORS_HPP_INCLUDED
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp
|
||||
|
||||
[begin_description]
|
||||
Default Integrate adaptive implementation.
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2013 Karsten Ahnert
|
||||
Copyright 2011-2015 Mario Mulansky
|
||||
Copyright 2012 Christoph Koke
|
||||
|
||||
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_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
|
||||
#include <boost/numeric/odeint/stepper/controlled_step_result.hpp>
|
||||
#include <boost/numeric/odeint/integrate/max_step_checker.hpp>
|
||||
#include <boost/numeric/odeint/integrate/detail/integrate_const.hpp>
|
||||
#include <boost/numeric/odeint/util/bind.hpp>
|
||||
#include <boost/numeric/odeint/util/unwrap_reference.hpp>
|
||||
#include <boost/numeric/odeint/util/copy.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
namespace detail {
|
||||
|
||||
// forward declaration
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
size_t integrate_const(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time end_time , Time dt ,
|
||||
Observer observer , stepper_tag );
|
||||
|
||||
/*
|
||||
* integrate_adaptive for simple stepper is basically an integrate_const + some last step
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
size_t integrate_adaptive(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time end_time , Time dt ,
|
||||
Observer observer , stepper_tag
|
||||
)
|
||||
{
|
||||
size_t steps = detail::integrate_const( stepper , system , start_state , start_time ,
|
||||
end_time , dt , observer , stepper_tag() );
|
||||
typename odeint::unwrap_reference< Observer >::type &obs = observer;
|
||||
typename odeint::unwrap_reference< Stepper >::type &st = stepper;
|
||||
|
||||
Time end = start_time + dt*steps;
|
||||
if( less_with_sign( end , end_time , dt ) )
|
||||
{ //make a last step to end exactly at end_time
|
||||
st.do_step( system , start_state , end , end_time - end );
|
||||
steps++;
|
||||
obs( start_state , end_time );
|
||||
}
|
||||
return steps;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* integrate adaptive for controlled stepper
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
size_t integrate_adaptive(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time &start_time , Time end_time , Time &dt ,
|
||||
Observer observer , controlled_stepper_tag
|
||||
)
|
||||
{
|
||||
typename odeint::unwrap_reference< Observer >::type &obs = observer;
|
||||
typename odeint::unwrap_reference< Stepper >::type &st = stepper;
|
||||
|
||||
failed_step_checker fail_checker; // to throw a runtime_error if step size adjustment fails
|
||||
size_t count = 0;
|
||||
while( less_with_sign( start_time , end_time , dt ) )
|
||||
{
|
||||
obs( start_state , start_time );
|
||||
if( less_with_sign( end_time , static_cast<Time>(start_time + dt) , dt ) )
|
||||
{
|
||||
dt = end_time - start_time;
|
||||
}
|
||||
|
||||
controlled_step_result res;
|
||||
do
|
||||
{
|
||||
res = st.try_step( system , start_state , start_time , dt );
|
||||
fail_checker(); // check number of failed steps
|
||||
}
|
||||
while( res == fail );
|
||||
fail_checker.reset(); // if we reach here, the step was successful -> reset fail checker
|
||||
|
||||
++count;
|
||||
}
|
||||
obs( start_state , start_time );
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* integrate adaptive for dense output steppers
|
||||
*
|
||||
* step size control is used if the stepper supports it
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
size_t integrate_adaptive(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time end_time , Time dt ,
|
||||
Observer observer , dense_output_stepper_tag )
|
||||
{
|
||||
typename odeint::unwrap_reference< Observer >::type &obs = observer;
|
||||
typename odeint::unwrap_reference< Stepper >::type &st = stepper;
|
||||
|
||||
size_t count = 0;
|
||||
st.initialize( start_state , start_time , dt );
|
||||
|
||||
while( less_with_sign( st.current_time() , end_time , st.current_time_step() ) )
|
||||
{
|
||||
while( less_eq_with_sign( static_cast<Time>(st.current_time() + st.current_time_step()) ,
|
||||
end_time ,
|
||||
st.current_time_step() ) )
|
||||
{ //make sure we don't go beyond the end_time
|
||||
obs( st.current_state() , st.current_time() );
|
||||
st.do_step( system );
|
||||
++count;
|
||||
}
|
||||
// calculate time step to arrive exactly at end time
|
||||
st.initialize( st.current_state() , st.current_time() , static_cast<Time>(end_time - st.current_time()) );
|
||||
}
|
||||
obs( st.current_state() , st.current_time() );
|
||||
// overwrite start_state with the final point
|
||||
boost::numeric::odeint::copy( st.current_state() , start_state );
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace detail
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/detail/integrate_const.hpp
|
||||
|
||||
[begin_description]
|
||||
integrate const implementation
|
||||
[end_description]
|
||||
|
||||
Copyright 2012-2015 Mario Mulansky
|
||||
Copyright 2012 Christoph Koke
|
||||
Copyright 2012 Karsten Ahnert
|
||||
|
||||
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_DETAIL_INTEGRATE_CONST_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_CONST_HPP_INCLUDED
|
||||
|
||||
#include <boost/numeric/odeint/util/unwrap_reference.hpp>
|
||||
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
|
||||
#include <boost/numeric/odeint/util/unit_helper.hpp>
|
||||
#include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
namespace detail {
|
||||
|
||||
// forward declaration
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
size_t integrate_adaptive(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time &start_time , Time end_time , Time &dt ,
|
||||
Observer observer , controlled_stepper_tag
|
||||
);
|
||||
|
||||
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
size_t integrate_const(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time end_time , Time dt ,
|
||||
Observer observer , stepper_tag
|
||||
)
|
||||
{
|
||||
|
||||
typename odeint::unwrap_reference< Observer >::type &obs = observer;
|
||||
typename odeint::unwrap_reference< Stepper >::type &st = stepper;
|
||||
|
||||
Time time = start_time;
|
||||
int step = 0;
|
||||
// cast time+dt explicitely in case of expression templates (e.g. multiprecision)
|
||||
while( less_eq_with_sign( static_cast<Time>(time+dt) , end_time , dt ) )
|
||||
{
|
||||
obs( start_state , time );
|
||||
st.do_step( system , start_state , time , dt );
|
||||
// direct computation of the time avoids error propagation happening when using time += dt
|
||||
// we need clumsy type analysis to get boost units working here
|
||||
++step;
|
||||
time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * dt;
|
||||
}
|
||||
obs( start_state , time );
|
||||
|
||||
return step;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
size_t integrate_const(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time end_time , Time dt ,
|
||||
Observer observer , controlled_stepper_tag
|
||||
)
|
||||
{
|
||||
typename odeint::unwrap_reference< Observer >::type &obs = observer;
|
||||
|
||||
Time time = start_time;
|
||||
const Time time_step = dt;
|
||||
int real_steps = 0;
|
||||
int step = 0;
|
||||
|
||||
while( less_eq_with_sign( static_cast<Time>(time+time_step) , end_time , dt ) )
|
||||
{
|
||||
obs( start_state , time );
|
||||
// integrate_adaptive_checked uses the given checker to throw if an overflow occurs
|
||||
real_steps += detail::integrate_adaptive(stepper, system, start_state, time,
|
||||
static_cast<Time>(time + time_step), dt,
|
||||
null_observer(), controlled_stepper_tag());
|
||||
// direct computation of the time avoids error propagation happening when using time += dt
|
||||
// we need clumsy type analysis to get boost units working here
|
||||
step++;
|
||||
time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * time_step;
|
||||
}
|
||||
obs( start_state , time );
|
||||
|
||||
return real_steps;
|
||||
}
|
||||
|
||||
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
size_t integrate_const(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time end_time , Time dt ,
|
||||
Observer observer , dense_output_stepper_tag
|
||||
)
|
||||
{
|
||||
typename odeint::unwrap_reference< Observer >::type &obs = observer;
|
||||
typename odeint::unwrap_reference< Stepper >::type &st = stepper;
|
||||
|
||||
Time time = start_time;
|
||||
|
||||
st.initialize( start_state , time , dt );
|
||||
obs( start_state , time );
|
||||
time += dt;
|
||||
|
||||
int obs_step( 1 );
|
||||
int real_step( 0 );
|
||||
|
||||
while( less_eq_with_sign( static_cast<Time>(time+dt) , end_time , dt ) )
|
||||
{
|
||||
while( less_eq_with_sign( time , st.current_time() , dt ) )
|
||||
{
|
||||
st.calc_state( time , start_state );
|
||||
obs( start_state , time );
|
||||
++obs_step;
|
||||
// direct computation of the time avoids error propagation happening when using time += dt
|
||||
// we need clumsy type analysis to get boost units working here
|
||||
time = start_time + static_cast< typename unit_value_type<Time>::type >(obs_step) * dt;
|
||||
}
|
||||
// we have not reached the end, do another real step
|
||||
if( less_with_sign( static_cast<Time>(st.current_time()+st.current_time_step()) ,
|
||||
end_time ,
|
||||
st.current_time_step() ) )
|
||||
{
|
||||
while( less_eq_with_sign( st.current_time() , time , dt ) )
|
||||
{
|
||||
st.do_step( system );
|
||||
++real_step;
|
||||
}
|
||||
}
|
||||
else if( less_with_sign( st.current_time() , end_time , st.current_time_step() ) )
|
||||
{ // do the last step ending exactly on the end point
|
||||
st.initialize( st.current_state() , st.current_time() , end_time - st.current_time() );
|
||||
st.do_step( system );
|
||||
++real_step;
|
||||
}
|
||||
|
||||
}
|
||||
// last observation, if we are still in observation interval
|
||||
// might happen due to finite precision problems when computing the the time
|
||||
if( less_eq_with_sign( time , end_time , dt ) )
|
||||
{
|
||||
st.calc_state( time , start_state );
|
||||
obs( start_state , time );
|
||||
}
|
||||
|
||||
return real_step;
|
||||
}
|
||||
|
||||
|
||||
} } } }
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/detail/integrate_n_steps.hpp
|
||||
|
||||
[begin_description]
|
||||
integrate steps implementation
|
||||
[end_description]
|
||||
|
||||
Copyright 2012-2015 Mario Mulansky
|
||||
Copyright 2012 Christoph Koke
|
||||
Copyright 2012 Karsten Ahnert
|
||||
|
||||
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_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED
|
||||
|
||||
#include <boost/numeric/odeint/util/unwrap_reference.hpp>
|
||||
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
|
||||
#include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
|
||||
#include <boost/numeric/odeint/util/unit_helper.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
namespace detail {
|
||||
|
||||
// forward declaration
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
size_t integrate_adaptive_checked(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time &start_time , Time end_time , Time &dt ,
|
||||
Observer observer, controlled_stepper_tag
|
||||
);
|
||||
|
||||
|
||||
/* basic version */
|
||||
template< class Stepper , class System , class State , class Time , class Observer>
|
||||
Time integrate_n_steps(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time dt , size_t num_of_steps ,
|
||||
Observer observer , stepper_tag )
|
||||
{
|
||||
typename odeint::unwrap_reference< Observer >::type &obs = observer;
|
||||
typename odeint::unwrap_reference< Stepper >::type &st = stepper;
|
||||
|
||||
Time time = start_time;
|
||||
|
||||
for( size_t step = 0; step < num_of_steps ; ++step )
|
||||
{
|
||||
obs( start_state , time );
|
||||
st.do_step( system , start_state , time , dt );
|
||||
// direct computation of the time avoids error propagation happening when using time += dt
|
||||
// we need clumsy type analysis to get boost units working here
|
||||
time = start_time + static_cast< typename unit_value_type<Time>::type >( step+1 ) * dt;
|
||||
}
|
||||
obs( start_state , time );
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
/* controlled version */
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
Time integrate_n_steps(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time dt , size_t num_of_steps ,
|
||||
Observer observer , controlled_stepper_tag )
|
||||
{
|
||||
typename odeint::unwrap_reference< Observer >::type &obs = observer;
|
||||
|
||||
Time time = start_time;
|
||||
Time time_step = dt;
|
||||
|
||||
for( size_t step = 0; step < num_of_steps ; ++step )
|
||||
{
|
||||
obs( start_state , time );
|
||||
// integrate_adaptive_checked uses the given checker to throw if an overflow occurs
|
||||
detail::integrate_adaptive(stepper, system, start_state, time, static_cast<Time>(time + time_step), dt,
|
||||
null_observer(), controlled_stepper_tag());
|
||||
// direct computation of the time avoids error propagation happening when using time += dt
|
||||
// we need clumsy type analysis to get boost units working here
|
||||
time = start_time + static_cast< typename unit_value_type<Time>::type >(step+1) * time_step;
|
||||
}
|
||||
obs( start_state , time );
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
/* dense output version */
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
Time integrate_n_steps(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time dt , size_t num_of_steps ,
|
||||
Observer observer , dense_output_stepper_tag )
|
||||
{
|
||||
typename odeint::unwrap_reference< Observer >::type &obs = observer;
|
||||
typename odeint::unwrap_reference< Stepper >::type &st = stepper;
|
||||
|
||||
Time time = start_time;
|
||||
const Time end_time = start_time + static_cast< typename unit_value_type<Time>::type >(num_of_steps) * dt;
|
||||
|
||||
st.initialize( start_state , time , dt );
|
||||
|
||||
size_t step = 0;
|
||||
|
||||
while( step < num_of_steps )
|
||||
{
|
||||
while( less_with_sign( time , st.current_time() , st.current_time_step() ) )
|
||||
{
|
||||
st.calc_state( time , start_state );
|
||||
obs( start_state , time );
|
||||
++step;
|
||||
// direct computation of the time avoids error propagation happening when using time += dt
|
||||
// we need clumsy type analysis to get boost units working here
|
||||
time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * dt;
|
||||
}
|
||||
|
||||
// we have not reached the end, do another real step
|
||||
if( less_with_sign( static_cast<Time>(st.current_time()+st.current_time_step()) ,
|
||||
end_time ,
|
||||
st.current_time_step() ) )
|
||||
{
|
||||
st.do_step( system );
|
||||
}
|
||||
else if( less_with_sign( st.current_time() , end_time , st.current_time_step() ) )
|
||||
{ // do the last step ending exactly on the end point
|
||||
st.initialize( st.current_state() , st.current_time() , static_cast<Time>(end_time - st.current_time()) );
|
||||
st.do_step( system );
|
||||
}
|
||||
}
|
||||
|
||||
// make sure we really end exactly where we should end
|
||||
while( st.current_time() < end_time )
|
||||
{
|
||||
if( less_with_sign( end_time ,
|
||||
static_cast<Time>(st.current_time()+st.current_time_step()) ,
|
||||
st.current_time_step() ) )
|
||||
st.initialize( st.current_state() , st.current_time() , static_cast<Time>(end_time - st.current_time()) );
|
||||
st.do_step( system );
|
||||
}
|
||||
|
||||
// observation at final point
|
||||
obs( st.current_state() , end_time );
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED */
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/detail/integrate_times.hpp
|
||||
|
||||
[begin_description]
|
||||
Default integrate times implementation.
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2015 Mario Mulansky
|
||||
Copyright 2012 Karsten Ahnert
|
||||
Copyright 2012 Christoph Koke
|
||||
|
||||
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_DETAIL_INTEGRATE_TIMES_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_TIMES_HPP_INCLUDED
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/numeric/odeint/util/unwrap_reference.hpp>
|
||||
#include <boost/numeric/odeint/stepper/controlled_step_result.hpp>
|
||||
#include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
|
||||
#include <boost/numeric/odeint/integrate/max_step_checker.hpp>
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
namespace detail {
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* integrate_times for simple stepper
|
||||
*/
|
||||
template<class Stepper, class System, class State, class TimeIterator, class Time, class Observer>
|
||||
size_t integrate_times(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
TimeIterator start_time , TimeIterator end_time , Time dt ,
|
||||
Observer observer , stepper_tag
|
||||
)
|
||||
{
|
||||
typedef typename odeint::unwrap_reference< Stepper >::type stepper_type;
|
||||
typedef typename odeint::unwrap_reference< Observer >::type observer_type;
|
||||
|
||||
stepper_type &st = stepper;
|
||||
observer_type &obs = observer;
|
||||
typedef typename unit_value_type<Time>::type time_type;
|
||||
|
||||
size_t steps = 0;
|
||||
Time current_dt = dt;
|
||||
while( true )
|
||||
{
|
||||
Time current_time = *start_time++;
|
||||
obs( start_state , current_time );
|
||||
if( start_time == end_time )
|
||||
break;
|
||||
while( less_with_sign( current_time , static_cast<time_type>(*start_time) , current_dt ) )
|
||||
{
|
||||
current_dt = min_abs( dt , *start_time - current_time );
|
||||
st.do_step( system , start_state , current_time , current_dt );
|
||||
current_time += current_dt;
|
||||
steps++;
|
||||
}
|
||||
}
|
||||
return steps;
|
||||
}
|
||||
|
||||
/*
|
||||
* integrate_times for controlled stepper
|
||||
*/
|
||||
template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer >
|
||||
size_t integrate_times(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
TimeIterator start_time , TimeIterator end_time , Time dt ,
|
||||
Observer observer , controlled_stepper_tag
|
||||
)
|
||||
{
|
||||
typename odeint::unwrap_reference< Observer >::type &obs = observer;
|
||||
typename odeint::unwrap_reference< Stepper >::type &st = stepper;
|
||||
typedef typename unit_value_type<Time>::type time_type;
|
||||
|
||||
failed_step_checker fail_checker; // to throw a runtime_error if step size adjustment fails
|
||||
size_t steps = 0;
|
||||
while( true )
|
||||
{
|
||||
Time current_time = *start_time++;
|
||||
obs( start_state , current_time );
|
||||
if( start_time == end_time )
|
||||
break;
|
||||
while( less_with_sign( current_time , static_cast<time_type>(*start_time) , dt ) )
|
||||
{
|
||||
// adjust stepsize to end up exactly at the observation point
|
||||
Time current_dt = min_abs( dt , *start_time - current_time );
|
||||
if( st.try_step( system , start_state , current_time , current_dt ) == success )
|
||||
{
|
||||
++steps;
|
||||
// successful step -> reset the fail counter, see #173
|
||||
fail_checker.reset();
|
||||
// continue with the original step size if dt was reduced due to observation
|
||||
dt = max_abs( dt , current_dt );
|
||||
}
|
||||
else
|
||||
{
|
||||
fail_checker(); // check for possible overflow of failed steps in step size adjustment
|
||||
dt = current_dt;
|
||||
}
|
||||
}
|
||||
}
|
||||
return steps;
|
||||
}
|
||||
|
||||
/*
|
||||
* integrate_times for dense output stepper
|
||||
*/
|
||||
template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer >
|
||||
size_t integrate_times(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
TimeIterator start_time , TimeIterator end_time , Time dt ,
|
||||
Observer observer , dense_output_stepper_tag
|
||||
)
|
||||
{
|
||||
typename odeint::unwrap_reference< Observer >::type &obs = observer;
|
||||
typename odeint::unwrap_reference< Stepper >::type &st = stepper;
|
||||
|
||||
typedef typename unit_value_type<Time>::type time_type;
|
||||
|
||||
if( start_time == end_time )
|
||||
return 0;
|
||||
|
||||
TimeIterator last_time_iterator = end_time;
|
||||
--last_time_iterator;
|
||||
Time last_time_point = static_cast<time_type>(*last_time_iterator);
|
||||
|
||||
st.initialize( start_state , *start_time , dt );
|
||||
obs( start_state , *start_time++ );
|
||||
|
||||
size_t count = 0;
|
||||
while( start_time != end_time )
|
||||
{
|
||||
while( ( start_time != end_time ) && less_eq_with_sign( static_cast<time_type>(*start_time) , st.current_time() , st.current_time_step() ) )
|
||||
{
|
||||
st.calc_state( *start_time , start_state );
|
||||
obs( start_state , *start_time );
|
||||
start_time++;
|
||||
}
|
||||
|
||||
// we have not reached the end, do another real step
|
||||
if( less_eq_with_sign( st.current_time() + st.current_time_step() ,
|
||||
last_time_point ,
|
||||
st.current_time_step() ) )
|
||||
{
|
||||
st.do_step( system );
|
||||
++count;
|
||||
}
|
||||
else if( start_time != end_time )
|
||||
{ // do the last step ending exactly on the end point
|
||||
st.initialize( st.current_state() , st.current_time() , last_time_point - st.current_time() );
|
||||
st.do_step( system );
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
} // namespace detail
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED
|
||||
133
include/boost/numeric/odeint/integrate/integrate.hpp
Normal file
133
include/boost/numeric/odeint/integrate/integrate.hpp
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/integrate.hpp
|
||||
|
||||
[begin_description]
|
||||
Convenience methods which choose the stepper for the current ODE.
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2013 Karsten Ahnert
|
||||
Copyright 2011-2012 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_INTEGRATE_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_HPP_INCLUDED
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp>
|
||||
#include <boost/numeric/odeint/stepper/controlled_runge_kutta.hpp>
|
||||
#include <boost/numeric/odeint/integrate/null_observer.hpp>
|
||||
#include <boost/numeric/odeint/integrate/integrate_adaptive.hpp>
|
||||
|
||||
// for has_value_type trait
|
||||
#include <boost/numeric/odeint/algebra/detail/extract_value_type.hpp>
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
|
||||
/*
|
||||
* ToDo :
|
||||
*
|
||||
* determine type of dxdt for units
|
||||
*
|
||||
*/
|
||||
template< class System , class State , class Time , class Observer >
|
||||
typename boost::enable_if< typename has_value_type<State>::type , size_t >::type
|
||||
integrate( System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer )
|
||||
{
|
||||
typedef controlled_runge_kutta< runge_kutta_dopri5< State , typename State::value_type , State , Time > > stepper_type;
|
||||
return integrate_adaptive( stepper_type() , system , start_state , start_time , end_time , dt , observer );
|
||||
}
|
||||
|
||||
template< class Value , class System , class State , class Time , class Observer >
|
||||
size_t
|
||||
integrate( System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer )
|
||||
{
|
||||
typedef controlled_runge_kutta< runge_kutta_dopri5< State , Value , State , Time > > stepper_type;
|
||||
return integrate_adaptive( stepper_type() , system , start_state , start_time , end_time , dt , observer );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* the two overloads are needed in order to solve the forwarding problem
|
||||
*/
|
||||
template< class System , class State , class Time >
|
||||
size_t integrate( System system , State &start_state , Time start_time , Time end_time , Time dt )
|
||||
{
|
||||
return integrate( system , start_state , start_time , end_time , dt , null_observer() );
|
||||
}
|
||||
|
||||
template< class Value , class System , class State , class Time >
|
||||
size_t integrate( System system , State &start_state , Time start_time , Time end_time , Time dt )
|
||||
{
|
||||
return integrate< Value >( system , start_state , start_time , end_time , dt , null_observer() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \fn integrate( System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer )
|
||||
* \brief Integrates the ODE.
|
||||
*
|
||||
* Integrates the ODE given by system from start_time to end_time starting
|
||||
* with start_state as initial condition and dt as initial time step.
|
||||
* This function uses a dense output dopri5 stepper and performs an adaptive
|
||||
* integration with step size control, thus dt changes during the integration.
|
||||
* This method uses standard error bounds of 1E-6.
|
||||
* After each step, the observer is called.
|
||||
*
|
||||
* \attention A second version of this function template exists which explicitly
|
||||
* expects the value type as template parameter, i.e. integrate< double >( sys , x , t0 , t1 , dt , obs );
|
||||
*
|
||||
* \param system The system function to solve, hence the r.h.s. of the
|
||||
* ordinary differential equation.
|
||||
* \param start_state The initial state.
|
||||
* \param start_time Start time of the integration.
|
||||
* \param end_time End time of the integration.
|
||||
* \param dt Initial step size, will be adjusted during the integration.
|
||||
* \param observer Observer that will be called after each time step.
|
||||
* \return The number of steps performed.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \fn integrate( System system , State &start_state , Time start_time , Time end_time , Time dt )
|
||||
* \brief Integrates the ODE without observer calls.
|
||||
*
|
||||
* Integrates the ODE given by system from start_time to end_time starting
|
||||
* with start_state as initial condition and dt as initial time step.
|
||||
* This function uses a dense output dopri5 stepper and performs an adaptive
|
||||
* integration with step size control, thus dt changes during the integration.
|
||||
* This method uses standard error bounds of 1E-6.
|
||||
* No observer is called.
|
||||
*
|
||||
* \attention A second version of this function template exists which explicitly
|
||||
* expects the value type as template parameter, i.e. integrate< double >( sys , x , t0 , t1 , dt );
|
||||
*
|
||||
* \param system The system function to solve, hence the r.h.s. of the
|
||||
* ordinary differential equation.
|
||||
* \param start_state The initial state.
|
||||
* \param start_time Start time of the integration.
|
||||
* \param end_time End time of the integration.
|
||||
* \param dt Initial step size, will be adjusted during the integration.
|
||||
* \return The number of steps performed.
|
||||
*/
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_HPP_INCLUDED
|
||||
127
include/boost/numeric/odeint/integrate/integrate_adaptive.hpp
Normal file
127
include/boost/numeric/odeint/integrate/integrate_adaptive.hpp
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/integrate_adaptive.hpp
|
||||
|
||||
[begin_description]
|
||||
Adaptive integration of ODEs.
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2013 Karsten Ahnert
|
||||
Copyright 2011-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_INTEGRATE_ADAPTIVE_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_ADAPTIVE_HPP_INCLUDED
|
||||
|
||||
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
|
||||
#include <boost/numeric/odeint/integrate/null_observer.hpp>
|
||||
#include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
|
||||
/*
|
||||
* the two overloads are needed in order to solve the forwarding problem
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
size_t integrate_adaptive(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time end_time , Time dt ,
|
||||
Observer observer )
|
||||
{
|
||||
typedef typename odeint::unwrap_reference< Stepper >::type::stepper_category stepper_category;
|
||||
return detail::integrate_adaptive(
|
||||
stepper , system , start_state ,
|
||||
start_time , end_time , dt ,
|
||||
observer , stepper_category() );
|
||||
|
||||
/*
|
||||
* Suggestion for a new extendable version:
|
||||
*
|
||||
* integrator_adaptive< Stepper , System, State , Time , Observer , typename Stepper::stepper_category > integrator;
|
||||
* return integrator.run( stepper , system , start_state , start_time , end_time , dt , observer );
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Second version to solve the forwarding problem,
|
||||
* can be called with Boost.Range as start_state.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
size_t integrate_adaptive(
|
||||
Stepper stepper , System system , const State &start_state ,
|
||||
Time start_time , Time end_time , Time dt ,
|
||||
Observer observer )
|
||||
{
|
||||
typedef typename odeint::unwrap_reference< Stepper >::type::stepper_category stepper_category;
|
||||
return detail::integrate_adaptive(
|
||||
stepper , system , start_state ,
|
||||
start_time , end_time , dt ,
|
||||
observer , stepper_category() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief integrate_adaptive without an observer.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time >
|
||||
size_t integrate_adaptive(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time end_time , Time dt )
|
||||
{
|
||||
return integrate_adaptive( stepper , system , start_state , start_time , end_time , dt , null_observer() );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Second version to solve the forwarding problem,
|
||||
* can be called with Boost.Range as start_state.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time >
|
||||
size_t integrate_adaptive(
|
||||
Stepper stepper , System system , const State &start_state ,
|
||||
Time start_time , Time end_time , Time dt )
|
||||
{
|
||||
return integrate_adaptive( stepper , system , start_state , start_time , end_time , dt , null_observer() );
|
||||
}
|
||||
|
||||
|
||||
/************* DOXYGEN ************/
|
||||
|
||||
/**
|
||||
* \fn integrate_adaptive( Stepper stepper , System system , State &start_state , Time start_time , Time end_time , Time dt , Observer observer )
|
||||
* \brief Integrates the ODE with adaptive step size.
|
||||
*
|
||||
* This function integrates the ODE given by system with the given stepper.
|
||||
* The observer is called after each step. If the stepper has no error
|
||||
* control, the step size remains constant and the observer is called at
|
||||
* equidistant time points t0+n*dt. If the stepper is a ControlledStepper,
|
||||
* the step size is adjusted and the observer is called in non-equidistant
|
||||
* intervals.
|
||||
*
|
||||
* \param stepper The stepper to be used for numerical integration.
|
||||
* \param system Function/Functor defining the rhs of the ODE.
|
||||
* \param start_state The initial condition x0.
|
||||
* \param start_time The initial time t0.
|
||||
* \param end_time The final integration time tend.
|
||||
* \param dt The time step between observer calls, _not_ necessarily the
|
||||
* time step of the integration.
|
||||
* \param observer Function/Functor called at equidistant time intervals.
|
||||
* \return The number of steps performed.
|
||||
*/
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_ADAPTIVE_HPP_INCLUDED
|
||||
195
include/boost/numeric/odeint/integrate/integrate_const.hpp
Normal file
195
include/boost/numeric/odeint/integrate/integrate_const.hpp
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/integrate_const.hpp
|
||||
|
||||
[begin_description]
|
||||
Constant integration of ODEs, meaning that the state of the ODE is observed on constant time intervals.
|
||||
The routines makes full use of adaptive and dense-output methods.
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2013 Karsten Ahnert
|
||||
Copyright 2011-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_INTEGRATE_CONST_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_CONST_HPP_INCLUDED
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
|
||||
#include <boost/numeric/odeint/integrate/null_observer.hpp>
|
||||
#include <boost/numeric/odeint/integrate/check_adapter.hpp>
|
||||
#include <boost/numeric/odeint/integrate/detail/integrate_const.hpp>
|
||||
#include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
|
||||
/*
|
||||
* Integrates with constant time step dt.
|
||||
*/
|
||||
template<class Stepper, class System, class State, class Time, class Observer, class StepOverflowChecker>
|
||||
size_t integrate_const(
|
||||
Stepper stepper, System system, State &start_state,
|
||||
Time start_time, Time end_time, Time dt,
|
||||
Observer observer, StepOverflowChecker checker
|
||||
) {
|
||||
typedef typename odeint::unwrap_reference<Stepper>::type::stepper_category stepper_category;
|
||||
// we want to get as fast as possible to the end
|
||||
// no overflow checks needed
|
||||
BOOST_IF_CONSTEXPR (std::is_same<null_observer, Observer>::value) {
|
||||
return detail::integrate_adaptive(
|
||||
stepper, system, start_state,
|
||||
start_time, end_time, dt,
|
||||
observer, stepper_category());
|
||||
}
|
||||
else {
|
||||
// unwrap references
|
||||
typedef typename odeint::unwrap_reference< Stepper >::type stepper_type;
|
||||
typedef typename odeint::unwrap_reference< Observer >::type observer_type;
|
||||
typedef typename odeint::unwrap_reference< StepOverflowChecker >::type checker_type;
|
||||
|
||||
return detail::integrate_const(checked_stepper<stepper_type, checker_type>(stepper, checker),
|
||||
system, start_state,
|
||||
start_time, end_time, dt,
|
||||
checked_observer<observer_type, checker_type>(observer, checker),
|
||||
stepper_category());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Second version to solve the forwarding problem,
|
||||
* can be called with Boost.Range as start_state.
|
||||
*/
|
||||
template<class Stepper, class System, class State, class Time, class Observer, class StepOverflowChecker >
|
||||
size_t integrate_const(
|
||||
Stepper stepper, System system, const State &start_state,
|
||||
Time start_time, Time end_time, Time dt,
|
||||
Observer observer, StepOverflowChecker checker
|
||||
) {
|
||||
typedef typename odeint::unwrap_reference<Stepper>::type::stepper_category stepper_category;
|
||||
// we want to get as fast as possible to the end
|
||||
|
||||
BOOST_IF_CONSTEXPR (std::is_same<null_observer, Observer>::value) {
|
||||
return detail::integrate_adaptive(
|
||||
stepper, system, start_state,
|
||||
start_time, end_time, dt,
|
||||
observer, stepper_category());
|
||||
}
|
||||
else {
|
||||
typedef typename odeint::unwrap_reference< Stepper >::type stepper_type;
|
||||
typedef typename odeint::unwrap_reference< Observer >::type observer_type;
|
||||
typedef typename odeint::unwrap_reference< StepOverflowChecker >::type checker_type;
|
||||
|
||||
return detail::integrate_const(checked_stepper<stepper_type, checker_type>(stepper, checker),
|
||||
system, start_state,
|
||||
start_time, end_time, dt,
|
||||
checked_observer<observer_type, checker_type>(observer, checker),
|
||||
stepper_category());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief integrate_const without step overflow checker
|
||||
*/
|
||||
template<class Stepper, class System, class State, class Time, class Observer>
|
||||
size_t integrate_const(
|
||||
Stepper stepper, System system, State &start_state,
|
||||
Time start_time, Time end_time, Time dt, Observer observer)
|
||||
{
|
||||
typedef typename odeint::unwrap_reference<Stepper>::type::stepper_category stepper_category;
|
||||
return detail::integrate_const(stepper, system, start_state,
|
||||
start_time, end_time, dt, observer, stepper_category());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Second version to solve the forwarding problem,
|
||||
* can be called with Boost.Range as start_state.
|
||||
*/
|
||||
template<class Stepper, class System, class State, class Time, class Observer>
|
||||
size_t integrate_const(
|
||||
Stepper stepper, System system, const State &start_state,
|
||||
Time start_time, Time end_time, Time dt, Observer observer
|
||||
) {
|
||||
typedef typename odeint::unwrap_reference<Stepper>::type::stepper_category stepper_category;
|
||||
return detail::integrate_const(stepper, system, start_state,
|
||||
start_time, end_time, dt, observer, stepper_category());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief integrate_const without observer calls
|
||||
*/
|
||||
template<class Stepper, class System, class State, class Time>
|
||||
size_t integrate_const(
|
||||
Stepper stepper, System system, State &start_state,
|
||||
Time start_time, Time end_time, Time dt
|
||||
) {
|
||||
return integrate_const(stepper, system, start_state, start_time, end_time, dt, null_observer());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Second version to solve the forwarding problem,
|
||||
* can be called with Boost.Range as start_state.
|
||||
*/
|
||||
template<class Stepper, class System, class State, class Time>
|
||||
size_t integrate_const(
|
||||
Stepper stepper, System system, const State &start_state,
|
||||
Time start_time, Time end_time, Time dt
|
||||
) {
|
||||
return integrate_const(stepper, system, start_state, start_time, end_time, dt, null_observer());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/********* DOXYGEN *********/
|
||||
/**
|
||||
* \fn integrate_const( Stepper stepper , System system , State &start_state , Time start_time ,
|
||||
* Time end_time , Time dt , Observer observer , StepOverflowChecker checker )
|
||||
* \brief Integrates the ODE with constant step size.
|
||||
*
|
||||
* Integrates the ODE defined by system using the given stepper.
|
||||
* This method ensures that the observer is called at constant intervals dt.
|
||||
* If the Stepper is a normal stepper without step size control, dt is also
|
||||
* used for the numerical scheme. If a ControlledStepper is provided, the
|
||||
* algorithm might reduce the step size to meet the error bounds, but it is
|
||||
* ensured that the observer is always called at equidistant time points
|
||||
* t0 + n*dt. If a DenseOutputStepper is used, the step size also may vary
|
||||
* and the dense output is used to call the observer at equidistant time
|
||||
* points.
|
||||
* If a max_step_checker is provided as StepOverflowChecker, a
|
||||
* no_progress_error is thrown if too many steps (default: 500) are performed
|
||||
* without progress, i.e. in between observer calls. If no checker is provided,
|
||||
* no such overflow check is performed.
|
||||
*
|
||||
* \param stepper The stepper to be used for numerical integration.
|
||||
* \param system Function/Functor defining the rhs of the ODE.
|
||||
* \param start_state The initial condition x0.
|
||||
* \param start_time The initial time t0.
|
||||
* \param end_time The final integration time tend.
|
||||
* \param dt The time step between observer calls, _not_ necessarily the
|
||||
* time step of the integration.
|
||||
* \param observer [optional] Function/Functor called at equidistant time intervals.
|
||||
* \param checker [optional] Functor to check for step count overflows, if no
|
||||
* checker is provided, no exception is thrown.
|
||||
* \return The number of steps performed.
|
||||
*/
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_CONST_HPP_INCLUDED
|
||||
178
include/boost/numeric/odeint/integrate/integrate_n_steps.hpp
Normal file
178
include/boost/numeric/odeint/integrate/integrate_n_steps.hpp
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/integrate_n_steps.hpp
|
||||
|
||||
[begin_description]
|
||||
Integration of n steps with constant time size. Adaptive and dense-output methods are fully supported.
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2013 Karsten Ahnert
|
||||
Copyright 2011-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_INTEGRATE_N_STEPS_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_N_STEPS_HPP_INCLUDED
|
||||
|
||||
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
|
||||
#include <boost/numeric/odeint/integrate/null_observer.hpp>
|
||||
#include <boost/numeric/odeint/integrate/detail/integrate_n_steps.hpp>
|
||||
#include <boost/numeric/odeint/integrate/check_adapter.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
|
||||
/*
|
||||
* Integrates n steps
|
||||
*
|
||||
* the two overloads are needed in order to solve the forwarding problem
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time , class Observer , class StepOverflowChecker >
|
||||
Time integrate_n_steps(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time dt , size_t num_of_steps ,
|
||||
Observer observer , StepOverflowChecker checker )
|
||||
{
|
||||
// unwrap references
|
||||
typedef typename odeint::unwrap_reference< Stepper >::type stepper_type;
|
||||
typedef typename odeint::unwrap_reference< Observer >::type observer_type;
|
||||
typedef typename odeint::unwrap_reference< StepOverflowChecker >::type checker_type;
|
||||
typedef typename stepper_type::stepper_category stepper_category;
|
||||
|
||||
return detail::integrate_n_steps(
|
||||
checked_stepper<stepper_type, checker_type>(stepper, checker),
|
||||
system , start_state ,
|
||||
start_time , dt , num_of_steps ,
|
||||
checked_observer<observer_type, checker_type>(observer, checker),
|
||||
stepper_category() );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time , class Observer , class StepOverflowChecker >
|
||||
Time integrate_n_steps(
|
||||
Stepper stepper , System system , const State &start_state ,
|
||||
Time start_time , Time dt , size_t num_of_steps ,
|
||||
Observer observer , StepOverflowChecker checker )
|
||||
{
|
||||
typedef typename odeint::unwrap_reference< Stepper >::type stepper_type;
|
||||
typedef typename odeint::unwrap_reference< Observer >::type observer_type;
|
||||
typedef typename odeint::unwrap_reference< StepOverflowChecker >::type checker_type;
|
||||
typedef typename stepper_type::stepper_category stepper_category;
|
||||
|
||||
return detail::integrate_n_steps(
|
||||
checked_stepper<stepper_type, checker_type>(stepper, checker),
|
||||
system , start_state ,
|
||||
start_time , dt , num_of_steps ,
|
||||
checked_observer<observer_type, checker_type>(observer, checker),
|
||||
stepper_category() );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief The same function as above, but without checker.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
Time integrate_n_steps(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time dt , size_t num_of_steps , Observer observer )
|
||||
{
|
||||
typedef typename odeint::unwrap_reference<Stepper>::type::stepper_category stepper_category;
|
||||
|
||||
return detail::integrate_n_steps(
|
||||
stepper , system , start_state ,
|
||||
start_time , dt , num_of_steps ,
|
||||
observer , stepper_category() );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time , class Observer >
|
||||
Time integrate_n_steps(
|
||||
Stepper stepper , System system , const State &start_state ,
|
||||
Time start_time , Time dt , size_t num_of_steps , Observer observer )
|
||||
{
|
||||
typedef typename odeint::unwrap_reference<Stepper>::type::stepper_category stepper_category;
|
||||
|
||||
return detail::integrate_n_steps(
|
||||
stepper , system , start_state ,
|
||||
start_time , dt , num_of_steps ,
|
||||
observer , stepper_category() );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The same function as above, but without observer calls.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time >
|
||||
Time integrate_n_steps(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
Time start_time , Time dt , size_t num_of_steps )
|
||||
{
|
||||
return integrate_n_steps(stepper, system, start_state, start_time,
|
||||
dt, num_of_steps, null_observer());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class Time >
|
||||
Time integrate_n_steps(
|
||||
Stepper stepper , System system , const State &start_state ,
|
||||
Time start_time , Time dt , size_t num_of_steps )
|
||||
{
|
||||
return integrate_n_steps(stepper, system, start_state, start_time,
|
||||
dt, num_of_steps, null_observer());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/************* DOXYGEN *************/
|
||||
/**
|
||||
* \fn Time integrate_n_steps( Stepper stepper , System system , State &start_state , Time start_time , Time dt , size_t num_of_steps , Observer observer )
|
||||
* \brief Integrates the ODE with constant step size.
|
||||
*
|
||||
* This function is similar to integrate_const. The observer is called at
|
||||
* equidistant time intervals t0 + n*dt.
|
||||
* If the Stepper is a normal stepper without step size control, dt is also
|
||||
* used for the numerical scheme. If a ControlledStepper is provided, the
|
||||
* algorithm might reduce the step size to meet the error bounds, but it is
|
||||
* ensured that the observer is always called at equidistant time points
|
||||
* t0 + n*dt. If a DenseOutputStepper is used, the step size also may vary
|
||||
* and the dense output is used to call the observer at equidistant time
|
||||
* points. The final integration time is always t0 + num_of_steps*dt.
|
||||
* If a max_step_checker is provided as StepOverflowChecker, a
|
||||
* no_progress_errror is thrown if too many steps (default: 500) are
|
||||
* performed without progress, i.e. in between observer calls. If no
|
||||
* checker is provided, no such overflow check is performed.
|
||||
|
||||
*
|
||||
* \param stepper The stepper to be used for numerical integration.
|
||||
* \param system Function/Functor defining the rhs of the ODE.
|
||||
* \param start_state The initial condition x0.
|
||||
* \param start_time The initial time t0.
|
||||
* \param dt The time step between observer calls, _not_ necessarily the
|
||||
* time step of the integration.
|
||||
* \param num_of_steps Number of steps to be performed
|
||||
* \param observer Function/Functor called at equidistant time intervals.
|
||||
* \param checker [optional] Functor to check for step count overflows, if no
|
||||
* checker is provided, no exception is thrown.
|
||||
* \return The number of steps performed.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_N_STEPS_HPP_INCLUDED
|
||||
220
include/boost/numeric/odeint/integrate/integrate_times.hpp
Normal file
220
include/boost/numeric/odeint/integrate/integrate_times.hpp
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/integrate_times.hpp
|
||||
|
||||
[begin_description]
|
||||
Integration of ODEs with observation at user defined points
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2013 Karsten Ahnert
|
||||
Copyright 2011-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_INTEGRATE_TIMES_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_TIMES_HPP_INCLUDED
|
||||
|
||||
#include <boost/range.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
|
||||
#include <boost/numeric/odeint/integrate/null_observer.hpp>
|
||||
#include <boost/numeric/odeint/integrate/check_adapter.hpp>
|
||||
#include <boost/numeric/odeint/integrate/detail/integrate_times.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
|
||||
/*
|
||||
* \brief Integrates while calling the observer at the time points given by sequence [times_start, time_end)
|
||||
* the two overloads are needed in order to solve the forwarding problem
|
||||
*/
|
||||
template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer , class StepOverflowChecker >
|
||||
size_t integrate_times(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
TimeIterator times_start , TimeIterator times_end , Time dt ,
|
||||
Observer observer , StepOverflowChecker checker )
|
||||
{
|
||||
// unwrap references
|
||||
typedef typename odeint::unwrap_reference< Stepper >::type stepper_type;
|
||||
typedef typename odeint::unwrap_reference< Observer >::type observer_type;
|
||||
typedef typename odeint::unwrap_reference< StepOverflowChecker >::type checker_type;
|
||||
typedef typename stepper_type::stepper_category stepper_category;
|
||||
|
||||
// pass on checked stepper and observer
|
||||
// checked_stepper/observer use references internally, so passing by value is fine
|
||||
return detail::integrate_times(
|
||||
checked_stepper<stepper_type, checker_type>(stepper, checker) ,
|
||||
system , start_state ,
|
||||
times_start , times_end , dt ,
|
||||
checked_observer<observer_type, checker_type>(observer, checker),
|
||||
stepper_category() );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer , class StepOverflowChecker >
|
||||
size_t integrate_times(
|
||||
Stepper stepper , System system , const State &start_state ,
|
||||
TimeIterator times_start , TimeIterator times_end , Time dt ,
|
||||
Observer observer , StepOverflowChecker checker )
|
||||
{
|
||||
typedef typename odeint::unwrap_reference< Stepper >::type stepper_type;
|
||||
typedef typename odeint::unwrap_reference< Observer >::type observer_type;
|
||||
typedef typename odeint::unwrap_reference< StepOverflowChecker >::type checker_type;
|
||||
typedef typename stepper_type::stepper_category stepper_category;
|
||||
|
||||
stepper_type &st = stepper;
|
||||
observer_type &obs = observer;
|
||||
checker_type &chk = checker;
|
||||
|
||||
return detail::integrate_times(
|
||||
checked_stepper<stepper_type, checker_type>(stepper, checker) ,
|
||||
system , start_state ,
|
||||
times_start , times_end , dt ,
|
||||
checked_observer<observer_type, checker_type>(observer, checker),
|
||||
stepper_category() );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The same function as above, but with the observation times given as range.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class TimeRange , class Time , class Observer , class StepOverflowChecker >
|
||||
size_t integrate_times(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
const TimeRange × , Time dt ,
|
||||
Observer observer , StepOverflowChecker checker )
|
||||
{
|
||||
return integrate_times(
|
||||
stepper , system , start_state ,
|
||||
boost::begin( times ) , boost::end( times ) , dt , observer , checker );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class TimeRange , class Time , class Observer , class StepOverflowChecker >
|
||||
size_t integrate_times(
|
||||
Stepper stepper , System system , const State &start_state ,
|
||||
const TimeRange × , Time dt ,
|
||||
Observer observer , StepOverflowChecker checker )
|
||||
{
|
||||
return integrate_times(
|
||||
stepper , system , start_state ,
|
||||
boost::begin( times ) , boost::end( times ) , dt , observer , checker );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* The same functions as above, but without a StepOverflowChecker
|
||||
*/
|
||||
template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer >
|
||||
size_t integrate_times(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
TimeIterator times_start , TimeIterator times_end , Time dt ,
|
||||
Observer observer )
|
||||
{
|
||||
typedef typename odeint::unwrap_reference< Stepper >::type::stepper_category stepper_category;
|
||||
// simply don't use checked_* adapters
|
||||
return detail::integrate_times(
|
||||
stepper , system , start_state ,
|
||||
times_start , times_end , dt ,
|
||||
observer , stepper_category() );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer >
|
||||
size_t integrate_times(
|
||||
Stepper stepper , System system , const State &start_state ,
|
||||
TimeIterator times_start , TimeIterator times_end , Time dt ,
|
||||
Observer observer )
|
||||
{
|
||||
typedef typename odeint::unwrap_reference< Stepper >::type::stepper_category stepper_category;
|
||||
return detail::integrate_times(
|
||||
stepper , system , start_state ,
|
||||
times_start , times_end , dt ,
|
||||
observer , stepper_category() );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The same function as above, but with the observation times given as range.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class TimeRange , class Time , class Observer >
|
||||
size_t integrate_times(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
const TimeRange × , Time dt ,
|
||||
Observer observer )
|
||||
{
|
||||
return integrate_times(
|
||||
stepper , system , start_state ,
|
||||
boost::begin( times ) , boost::end( times ) , dt , observer );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
|
||||
*/
|
||||
template< class Stepper , class System , class State , class TimeRange , class Time , class Observer >
|
||||
size_t integrate_times(
|
||||
Stepper stepper , System system , const State &start_state ,
|
||||
const TimeRange × , Time dt ,
|
||||
Observer observer )
|
||||
{
|
||||
return integrate_times(
|
||||
stepper , system , start_state ,
|
||||
boost::begin( times ) , boost::end( times ) , dt , observer);
|
||||
}
|
||||
|
||||
|
||||
/********* DOXYGEN ***********/
|
||||
|
||||
/**
|
||||
* \fn size_t integrate_times( Stepper stepper , System system , State &start_state , TimeIterator times_start , TimeIterator times_end , Time dt , Observer observer )
|
||||
* \brief Integrates the ODE with observer calls at given time points.
|
||||
*
|
||||
* Integrates the ODE given by system using the given stepper. This function
|
||||
* does observer calls at the subsequent time points given by the range
|
||||
* times_start, times_end. If the stepper has not step size control, the
|
||||
* step size might be reduced occasionally to ensure observer calls exactly
|
||||
* at the time points from the given sequence. If the stepper is a
|
||||
* ControlledStepper, the step size is adjusted to meet the error bounds,
|
||||
* but also might be reduced occasionally to ensure correct observer calls.
|
||||
* If a DenseOutputStepper is provided, the dense output functionality is
|
||||
* used to call the observer at the given times. The end time of the
|
||||
* integration is always *(end_time-1).
|
||||
* If a max_step_checker is provided as StepOverflowChecker, a
|
||||
* no_progress_error is thrown if too many steps (default: 500) are
|
||||
* performed without progress, i.e. in between observer calls. If no
|
||||
* checker is provided, no such overflow check is performed.
|
||||
*
|
||||
* \param stepper The stepper to be used for numerical integration.
|
||||
* \param system Function/Functor defining the rhs of the ODE.
|
||||
* \param start_state The initial condition x0.
|
||||
* \param times_start Iterator to the start time
|
||||
* \param times_end Iterator to the end time
|
||||
* \param dt The time step between observer calls, _not_ necessarily the
|
||||
* time step of the integration.
|
||||
* \param observer Function/Functor called at equidistant time intervals.
|
||||
* \param checker [optional] Functor to check for step count overflows, if no
|
||||
* checker is provided, no exception is thrown.
|
||||
* \return The number of steps performed.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_TIMES_HPP_INCLUDED
|
||||
114
include/boost/numeric/odeint/integrate/max_step_checker.hpp
Normal file
114
include/boost/numeric/odeint/integrate/max_step_checker.hpp
Normal file
@@ -0,0 +1,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];
|
||||
std::snprintf(error_msg, 200, "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];
|
||||
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) );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
38
include/boost/numeric/odeint/integrate/null_observer.hpp
Normal file
38
include/boost/numeric/odeint/integrate/null_observer.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/null_observer.hpp
|
||||
|
||||
[begin_description]
|
||||
null_observer
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2012 Karsten Ahnert
|
||||
Copyright 2011-2012 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_NULL_OBSERVER_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_NULL_OBSERVER_HPP_INCLUDED
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
struct null_observer
|
||||
{
|
||||
template< class State , class Time >
|
||||
void operator()( const State& /* x */ , Time /* t */ ) const
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_NULL_OBSERVER_HPP_INCLUDED
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/observer_collection.hpp
|
||||
|
||||
[begin_description]
|
||||
Collection of observers, which are all called during the evolution of the ODE.
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2012 Karsten Ahnert
|
||||
Copyright 2011-2012 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_OBSERVER_COLLECTION_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_OBSERVER_COLLECTION_HPP_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
template< class State , class Time >
|
||||
class observer_collection
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::function< void( const State& , const Time& ) > observer_type;
|
||||
typedef std::vector< observer_type > collection_type;
|
||||
|
||||
void operator()( const State& x , Time t )
|
||||
{
|
||||
for( size_t i=0 ; i<m_observers.size() ; ++i )
|
||||
m_observers[i]( x , t );
|
||||
}
|
||||
|
||||
collection_type& observers( void ) { return m_observers; }
|
||||
const collection_type& observers( void ) const { return m_observers; }
|
||||
|
||||
private:
|
||||
|
||||
collection_type m_observers;
|
||||
};
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_OBSERVER_COLLECTION_HPP_INCLUDED
|
||||
Reference in New Issue
Block a user