| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

cvodes_utils.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_MAT_FUNCTOR_CVODES_UTILS_HPP
2 #define STAN_MATH_REV_MAT_FUNCTOR_CVODES_UTILS_HPP
3
4 #include <cvodes/cvodes.h>
5 #include <cvodes/cvodes_band.h>
6 #include <cvodes/cvodes_dense.h>
7 #include <nvector/nvector_serial.h>
8 #include <sstream>
9 #include <string>
10
11 namespace stan {
12 namespace math {
13
14 // no-op error handler to silence CVodes error output; errors handled
15 // directly by Stan
16 extern "C"
17 inline void cvodes_silent_err_handler(int error_code, const char *module,
18 const char *function, char *msg,
19 void *eh_data) {
20 }
21
22 inline void cvodes_check_flag(int flag, const std::string& func_name) {
23 if (flag < 0) {
24 std::ostringstream ss;
25 ss << func_name << " failed with error flag " << flag;
26 throw std::runtime_error(ss.str());
27 }
28 }
29
30 inline void cvodes_set_options(void* cvodes_mem,
31 double rel_tol, double abs_tol,
32 // NOLINTNEXTLINE(runtime/int)
33 long int max_num_steps) {
34 // forward CVode errors to noop error handler
35 CVodeSetErrHandlerFn(cvodes_mem, cvodes_silent_err_handler, 0);
36
37 // Initialize solver parameters
38 cvodes_check_flag(CVodeSStolerances(cvodes_mem, rel_tol, abs_tol),
39 "CVodeSStolerances");
40
41 cvodes_check_flag(CVodeSetMaxNumSteps(cvodes_mem, max_num_steps),
42 "CVodeSetMaxNumSteps");
43
44 double init_step = 0;
45 cvodes_check_flag(CVodeSetInitStep(cvodes_mem, init_step),
46 "CVodeSetInitStep");
47
48 long int max_err_test_fails = 20; // NOLINT(runtime/int)
49 cvodes_check_flag(CVodeSetMaxErrTestFails(cvodes_mem, max_err_test_fails),
50 "CVodeSetMaxErrTestFails");
51
52 long int max_conv_fails = 50; // NOLINT(runtime/int)
53 cvodes_check_flag(CVodeSetMaxConvFails(cvodes_mem, max_conv_fails),
54 "CVodeSetMaxConvFails");
55 }
56
57 }
58 }
59 #endif
stan::math::cvodes_set_options
void cvodes_set_options(void *cvodes_mem, double rel_tol, double abs_tol, long int max_num_steps)
Definition: cvodes_utils.hpp:30
stan
Definition: log_sum_exp.hpp:8
stan::math::cvodes_check_flag
void cvodes_check_flag(int flag, const std::string &func_name)
Definition: cvodes_utils.hpp:22
stan::math::cvodes_silent_err_handler
void cvodes_silent_err_handler(int error_code, const char *module, const char *function, char *msg, void *eh_data)
Definition: cvodes_utils.hpp:17

[ Stan Home Page ] © 2011–2016, Stan Development Team.