1 #ifndef STAN_MATH_PRIM_ARR_FUNCTOR_INTEGRATE_ODE_RK45_HPP 2 #define STAN_MATH_PRIM_ARR_FUNCTOR_INTEGRATE_ODE_RK45_HPP 13 #include <boost/version.hpp> 14 #if BOOST_VERSION == 106400 15 #include <boost/serialization/array_wrapper.hpp> 17 #include <boost/numeric/odeint.hpp> 68 template <
typename F,
typename T1,
typename T2>
71 const std::vector<double>& ts,
const std::vector<T2>&
theta,
72 const std::vector<double>&
x,
const std::vector<int>& x_int,
73 std::ostream*
msgs =
nullptr,
74 double relative_tolerance = 1
e-6,
75 double absolute_tolerance = 1
e-6,
int max_num_steps = 1E6) {
76 using boost::numeric::odeint::integrate_times;
77 using boost::numeric::odeint::make_dense_output;
78 using boost::numeric::odeint::max_step_checker;
79 using boost::numeric::odeint::runge_kutta_dopri5;
84 check_finite(
"integrate_ode_rk45",
"parameter vector", theta);
85 check_finite(
"integrate_ode_rk45",
"continuous data", x);
90 check_less(
"integrate_ode_rk45",
"initial time", t0, ts[0]);
92 if (relative_tolerance <= 0)
94 relative_tolerance,
"",
", must be greater than 0");
95 if (absolute_tolerance <= 0)
97 absolute_tolerance,
"",
", must be greater than 0");
98 if (max_num_steps <= 0)
100 ", must be greater than 0");
106 std::vector<double> ts_vec(ts.size() + 1);
108 for (
size_t n = 0;
n < ts.size();
n++)
109 ts_vec[
n + 1] = ts[
n];
111 std::vector<std::vector<double> > y_coupled(ts_vec.size());
115 std::vector<double> initial_coupled_state = coupled_system.initial_state();
117 const double step_size = 0.1;
119 make_dense_output(absolute_tolerance, relative_tolerance,
120 runge_kutta_dopri5<std::vector<double>,
double,
121 std::vector<double>,
double>()),
122 boost::ref(coupled_system), initial_coupled_state, boost::begin(ts_vec),
123 boost::end(ts_vec), step_size, observer, max_step_checker(max_num_steps));
126 y_coupled.erase(y_coupled.begin());
129 return coupled_system.decouple_states(y_coupled);
void check_finite(const char *function, const char *name, const T_y &y)
void check_nonzero_size(const char *function, const char *name, const T_y &y)
void check_ordered(const char *function, const char *name, const std::vector< T_y > &y)
std::vector< std::vector< typename stan::return_type< T1, T2 >::type > > integrate_ode_rk45(const F &f, const std::vector< T1 > &y0, double t0, const std::vector< double > &ts, const std::vector< T2 > &theta, const std::vector< double > &x, const std::vector< int > &x_int, std::ostream *msgs=nullptr, double relative_tolerance=1e-6, double absolute_tolerance=1e-6, int max_num_steps=1E6)
void invalid_argument(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
void check_less(const char *function, const char *name, const T_y &y, const T_high &high)