我odeint
要从c++ boost
图书馆了解,我需要知道哪个部分做什么。在boost/numeric/odeint/integrate/integrate_adaptive.hpp
中,有一个名为 的函数integrate_adaptive
。这个函数有一些重载。我的一些操作的简化文件如下:
集成自适应最小.hpp
#define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_ADAPTIVE_HPP_INCLUDED
#include <boost/type_traits/is_same.hpp>
#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>
using namespace std;
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 )
{
cout<<"type one"<<endl; //added by me ***************************************
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 )
{
cout<<"type two"<<endl; //added by me ***************************************
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() );
}
} // namespace odeint
} // namespace numeric
} // namespace boost
这两个函数的区别与参数有关start_state
。在第二个函数中,它包含一个const
关键字。我想知道调用了哪个重载。因此,我在每个函数中添加了一个 cout。然后我从这个测试文件中调用它们:
最小的.cpp
#include "integrate_adaptive_minimal.hpp"
#include <boost/numeric/odeint.hpp>
#include <armadillo>
using namespace arma;
using namespace boost::numeric::odeint;
typedef vec::fixed<2> state_type;
void sys( const state_type &x , state_type &dxdt , const double t)
{
mat A;
A<<-1<<0<<endr<<0<<-1;
mat B;
B<<1<<endr<<1;
dxdt=A*x+B*(t>0?1:0);
}
void observer( const state_type &x , const double t )
{
}
typedef runge_kutta_dopri5<state_type> stepper_type;
int main()
{
state_type x;
x(0) = 0.0;
x(1) = 0.0;
integrate_adaptive(make_controlled(1E-10,1E-10,stepper_type()),
sys,x,0.0,11.0,0.1,observer);
return 0;
}
当我编译并运行时:
g++ -std=c++11 minimal.cpp -larmadillo -lboost_thread -lboost_filesystem -lboost_system -Wfatal-errors
./a.out
结果显示integrate_adaptive
调用了第一个没有的函数const
。现在,我想知道调用第二个函数的正确方法是什么?对象 x 不能是const
!
如果有人甚至了解boost
库的机制,请告诉我第二个功能的优势。
更新: