|
12 | 12 | namespace stan { |
13 | 13 | namespace math { |
14 | 14 |
|
15 | | -/** |
16 | | - * Solve the ODE initial value problem y' = f(t, y), y(t0) = y0 at a set of |
17 | | - * times, { t1, t2, t3, ... } using the non-stiff Runge-Kutta 45 solver in Boost |
18 | | - * with a relative tolerance of 1e-10, an absolute tolerance of 1e-10, and |
19 | | - * taking a maximum of 1e8 steps. |
20 | | - * |
21 | | - * If the system of equations is stiff, <code>ode_bdf</code> will likely be |
22 | | - * faster. |
23 | | - * |
24 | | - * \p f must define an operator() with the signature as: |
25 | | - * template<typename T_t, typename T_y, typename... T_Args> |
26 | | - * Eigen::Matrix<stan::return_type_t<T_t, T_y, T_Args...>, Eigen::Dynamic, 1> |
27 | | - * operator()(const T_t& t, const Eigen::Matrix<T_y, Eigen::Dynamic, 1>& y, |
28 | | - * std::ostream* msgs, const T_Args&... args); |
29 | | - * |
30 | | - * t is the time, y is the state, msgs is a stream for error messages, and args |
31 | | - * are optional arguments passed to the ODE solve function (which are passed |
32 | | - * through to \p f without modification). |
33 | | - * |
34 | | - * @tparam F Type of ODE right hand side |
35 | | - * @tparam T_0 Type of initial time |
36 | | - * @tparam T_ts Type of output times |
37 | | - * @tparam T_Args Types of pass-through parameters |
38 | | - * |
39 | | - * @param f Right hand side of the ODE |
40 | | - * @param y0 Initial state |
41 | | - * @param t0 Initial time |
42 | | - * @param ts Times at which to solve the ODE at. All values must be sorted and |
43 | | - * not less than t0. |
44 | | - * @param relative_tolerance Relative tolerance passed to CVODES |
45 | | - * @param absolute_tolerance Absolute tolerance passed to CVODES |
46 | | - * @param max_num_steps Upper limit on the number of integration steps to |
47 | | - * take between each output (error if exceeded) |
48 | | - * @param[in, out] msgs the print stream for warning messages |
49 | | - * @param args Extra arguments passed unmodified through to ODE right hand side |
50 | | - * @return Solution to ODE at times \p ts |
51 | | - */ |
52 | | -template <typename F, typename T_initial, typename T_t0, typename T_ts, |
53 | | - typename... Args> |
54 | | -std::vector< |
55 | | - Eigen::Matrix<stan::return_type_t<T_initial, Args...>, Eigen::Dynamic, 1>> |
56 | | -ode_rk45(const F& f, const Eigen::Matrix<T_initial, Eigen::Dynamic, 1>& y0, |
57 | | - double t0, const std::vector<double>& ts, std::ostream* msgs, |
58 | | - const Args&... args) { |
59 | | - double relative_tolerance = 1e-10; |
60 | | - double absolute_tolerance = 1e-10; |
61 | | - long int max_num_steps = 1e8; |
62 | | - |
63 | | - return ode_rk45_tol(f, y0, t0, ts, relative_tolerance, absolute_tolerance, |
64 | | - max_num_steps, msgs, args...); |
65 | | -} |
66 | | - |
67 | 15 | /** |
68 | 16 | * Solve the ODE initial value problem y' = f(t, y), y(t0) = y0 at a set of |
69 | 17 | * times, { t1, t2, t3, ... } using the non-stiff Runge-Kutta 45 solver in Boost |
@@ -192,6 +140,58 @@ ode_rk45_tol(const F& f, |
192 | 140 | return y; |
193 | 141 | } |
194 | 142 |
|
| 143 | +/** |
| 144 | + * Solve the ODE initial value problem y' = f(t, y), y(t0) = y0 at a set of |
| 145 | + * times, { t1, t2, t3, ... } using the non-stiff Runge-Kutta 45 solver in Boost |
| 146 | + * with a relative tolerance of 1e-10, an absolute tolerance of 1e-10, and |
| 147 | + * taking a maximum of 1e8 steps. |
| 148 | + * |
| 149 | + * If the system of equations is stiff, <code>ode_bdf</code> will likely be |
| 150 | + * faster. |
| 151 | + * |
| 152 | + * \p f must define an operator() with the signature as: |
| 153 | + * template<typename T_t, typename T_y, typename... T_Args> |
| 154 | + * Eigen::Matrix<stan::return_type_t<T_t, T_y, T_Args...>, Eigen::Dynamic, 1> |
| 155 | + * operator()(const T_t& t, const Eigen::Matrix<T_y, Eigen::Dynamic, 1>& y, |
| 156 | + * std::ostream* msgs, const T_Args&... args); |
| 157 | + * |
| 158 | + * t is the time, y is the state, msgs is a stream for error messages, and args |
| 159 | + * are optional arguments passed to the ODE solve function (which are passed |
| 160 | + * through to \p f without modification). |
| 161 | + * |
| 162 | + * @tparam F Type of ODE right hand side |
| 163 | + * @tparam T_0 Type of initial time |
| 164 | + * @tparam T_ts Type of output times |
| 165 | + * @tparam T_Args Types of pass-through parameters |
| 166 | + * |
| 167 | + * @param f Right hand side of the ODE |
| 168 | + * @param y0 Initial state |
| 169 | + * @param t0 Initial time |
| 170 | + * @param ts Times at which to solve the ODE at. All values must be sorted and |
| 171 | + * not less than t0. |
| 172 | + * @param relative_tolerance Relative tolerance passed to CVODES |
| 173 | + * @param absolute_tolerance Absolute tolerance passed to CVODES |
| 174 | + * @param max_num_steps Upper limit on the number of integration steps to |
| 175 | + * take between each output (error if exceeded) |
| 176 | + * @param[in, out] msgs the print stream for warning messages |
| 177 | + * @param args Extra arguments passed unmodified through to ODE right hand side |
| 178 | + * @return Solution to ODE at times \p ts |
| 179 | + */ |
| 180 | +template <typename F, typename T_initial, typename T_t0, typename T_ts, |
| 181 | + typename... Args> |
| 182 | +std::vector< |
| 183 | + Eigen::Matrix<stan::return_type_t<T_initial, Args...>, Eigen::Dynamic, 1>> |
| 184 | +ode_rk45(const F& f, const Eigen::Matrix<T_initial, Eigen::Dynamic, 1>& y0, |
| 185 | + T_t0 t0, const std::vector<T_ts>& ts, std::ostream* msgs, |
| 186 | + const Args&... args) { |
| 187 | + double relative_tolerance = 1e-10; |
| 188 | + double absolute_tolerance = 1e-10; |
| 189 | + long int max_num_steps = 1e8; |
| 190 | + |
| 191 | + return ode_rk45_tol(f, y0, t0, ts, relative_tolerance, absolute_tolerance, |
| 192 | + max_num_steps, msgs, args...); |
| 193 | +} |
| 194 | + |
195 | 195 | } // namespace math |
196 | 196 | } // namespace stan |
197 | 197 | #endif |
0 commit comments