整理
This commit is contained in:
@@ -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,121 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp
|
||||
|
||||
[begin_description]
|
||||
Default Integrate adaptive implementation.
|
||||
[end_description]
|
||||
|
||||
Copyright 2009-2011 Karsten Ahnert
|
||||
Copyright 2009-2011 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_INTEGRATE_ADAPTIVE_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
|
||||
#include <boost/numeric/odeint/stepper/controlled_step_result.hpp>
|
||||
#include <boost/numeric/odeint/iterator/integrate/detail/integrate_const.hpp>
|
||||
#include <boost/numeric/odeint/iterator/adaptive_time_iterator.hpp>
|
||||
#include <boost/numeric/odeint/iterator/integrate/detail/functors.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>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* classical integrate adaptive
|
||||
*/
|
||||
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
|
||||
)
|
||||
{
|
||||
size_t obs_calls = 0;
|
||||
|
||||
boost::for_each( make_adaptive_time_range( stepper , system , start_state ,
|
||||
start_time , end_time , dt ) ,
|
||||
obs_caller< Observer >( obs_calls , observer ) );
|
||||
|
||||
return obs_calls-1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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 )
|
||||
{
|
||||
size_t obs_calls = 0;
|
||||
|
||||
boost::for_each( make_adaptive_time_range( stepper , system , start_state ,
|
||||
start_time , end_time , dt ) ,
|
||||
obs_caller< Observer >( obs_calls , observer ) );
|
||||
|
||||
return obs_calls-1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace detail
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/detail/integrate_const.hpp
|
||||
|
||||
[begin_description]
|
||||
integrate const implementation
|
||||
[end_description]
|
||||
|
||||
Copyright 2009-2012 Karsten Ahnert
|
||||
Copyright 2009-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_DETAIL_INTEGRATE_CONST_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_CONST_HPP_INCLUDED
|
||||
|
||||
#include <boost/range/algorithm/for_each.hpp>
|
||||
|
||||
#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/iterator/const_step_time_iterator.hpp>
|
||||
#include <boost/numeric/odeint/iterator/integrate/detail/integrate_adaptive.hpp>
|
||||
#include <boost/numeric/odeint/iterator/integrate/detail/functors.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
|
||||
)
|
||||
{
|
||||
size_t obs_calls = 0;
|
||||
|
||||
boost::for_each( make_const_step_time_range( stepper , system , start_state ,
|
||||
start_time , end_time , dt ) ,
|
||||
// should we use traits<Stepper>::state_type here instead of State? NO!
|
||||
obs_caller< Observer >( obs_calls , observer ) );
|
||||
|
||||
// step integration steps gives step+1 observer calls
|
||||
return obs_calls-1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 step = 0;
|
||||
|
||||
while( less_eq_with_sign( static_cast<Time>(time+time_step) , end_time , dt ) )
|
||||
{
|
||||
obs( start_state , time );
|
||||
detail::integrate_adaptive( stepper , system , start_state , 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 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 , dense_output_stepper_tag
|
||||
)
|
||||
{
|
||||
size_t obs_calls = 0;
|
||||
|
||||
boost::for_each( make_const_step_time_range( stepper , system , start_state ,
|
||||
start_time , end_time , dt ) ,
|
||||
obs_caller< Observer >( obs_calls , observer ) );
|
||||
return obs_calls-1;
|
||||
}
|
||||
|
||||
|
||||
} } } }
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/detail/integrate_n_steps.hpp
|
||||
|
||||
[begin_description]
|
||||
integrate steps implementation
|
||||
[end_description]
|
||||
|
||||
Copyright 2009-2012 Karsten Ahnert
|
||||
Copyright 2009-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_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/iterator/integrate/detail/integrate_adaptive.hpp>
|
||||
#include <boost/numeric/odeint/iterator/integrate/detail/functors.hpp>
|
||||
#include <boost/numeric/odeint/iterator/n_step_time_iterator.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(
|
||||
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 )
|
||||
{
|
||||
// ToDo: is there a better way to extract the final time?
|
||||
Time t = start_time; // Assignment is only here to avoid warnings.
|
||||
boost::for_each( make_n_step_time_range( stepper , system , start_state ,
|
||||
start_time , dt , num_of_steps ) ,
|
||||
obs_caller_time< Observer , Time >( t , observer ) );
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
/* 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 );
|
||||
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 )
|
||||
{
|
||||
// ToDo: is there a better way to extract the final time?
|
||||
Time t = start_time; // Assignment is only here to avoid warnings.
|
||||
boost::for_each( make_n_step_time_range( stepper , system , start_state ,
|
||||
start_time , dt , num_of_steps ) ,
|
||||
obs_caller_time< Observer , Time >( t , observer ) );
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED */
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/detail/integrate_times.hpp
|
||||
|
||||
[begin_description]
|
||||
Default integrate times implementation.
|
||||
[end_description]
|
||||
|
||||
Copyright 2009-2012 Karsten Ahnert
|
||||
Copyright 2009-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_DETAIL_INTEGRATE_TIMES_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_TIMES_HPP_INCLUDED
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/algorithm/for_each.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/iterator/times_time_iterator.hpp>
|
||||
#include <boost/numeric/odeint/iterator/integrate/detail/functors.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
namespace detail {
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* integrate_times for all steppers
|
||||
*/
|
||||
template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer , class StepperTag >
|
||||
size_t integrate_times(
|
||||
Stepper stepper , System system , State &start_state ,
|
||||
TimeIterator start_time , TimeIterator end_time , Time dt ,
|
||||
Observer observer , StepperTag
|
||||
)
|
||||
{
|
||||
size_t obs_calls = 0;
|
||||
|
||||
boost::for_each( make_times_time_range( stepper , system , start_state ,
|
||||
start_time , end_time , dt ) ,
|
||||
// should we use traits<Stepper>::state_type here instead of State? NO!
|
||||
obs_caller< Observer >( obs_calls , observer ) );
|
||||
|
||||
// step integration steps gives step+1 observer calls
|
||||
return obs_calls-1;
|
||||
}
|
||||
|
||||
|
||||
} // namespace detail
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED
|
||||
Reference in New Issue
Block a user