Automatic Differentiation
 
Loading...
Searching...
No Matches
dae.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUNCTOR_DAE_HPP
2#define STAN_MATH_REV_FUNCTOR_DAE_HPP
3
8#include <ostream>
9#include <vector>
10
11namespace stan {
12namespace math {
13
50template <typename F, typename T_yy, typename T_yp, typename... T_Args,
51 require_all_eigen_col_vector_t<T_yy, T_yp>* = nullptr>
52inline std::vector<
53 Eigen::Matrix<stan::return_type_t<T_yy, T_yp, T_Args...>, -1, 1>>
54dae_tol_impl(const char* func, const F& f, const T_yy& yy0, const T_yp& yp0,
55 double t0, const std::vector<double>& ts, double rtol, double atol,
56 int64_t max_num_steps, std::ostream* msgs, const T_Args&... args) {
57 check_finite(func, "initial state", yy0);
58 check_finite(func, "initial state derivative", yp0);
59 check_nonzero_size(func, "initial state", yy0);
60 check_nonzero_size(func, "initial state derivative", yp0);
61 check_finite(func, "initial time", t0);
62 check_finite(func, "times", ts);
63 check_nonzero_size(func, "times", ts);
64 check_sorted(func, "times", ts);
65 check_less(func, "initial time", t0, ts[0]);
66 check_positive_finite(func, "relative_tolerance", rtol);
67 check_positive_finite(func, "absolute_tolerance", atol);
68 check_positive(func, "max_num_steps", max_num_steps);
69
70 const auto& args_ref_tuple = std::make_tuple(to_ref(args)...);
72 [&](auto&&... args) {
73 std::vector<int> unused_temp{
74 0, (check_finite("dae", "DAE parameters and data", args), 0)...};
75 },
76 args_ref_tuple);
77
78 return math::apply(
79 [&](const auto&... args_refs) {
81 args_refs...);
82 idas_integrator integ(rtol, atol, max_num_steps);
83 return integ(func, dae, t0, ts);
84 },
85 args_ref_tuple);
86}
87
123template <typename F, typename T_yy, typename T_yp, typename... T_Args,
125inline std::vector<
126 Eigen::Matrix<stan::return_type_t<T_yy, T_yp, T_Args...>, -1, 1>>
127dae_tol(const F& f, const T_yy& yy0, const T_yp& yp0, double t0,
128 const std::vector<double>& ts, double rtol, double atol,
129 int64_t max_num_steps, std::ostream* msgs, const T_Args&... args) {
130 return dae_tol_impl("dae_tol", f, yy0, yp0, t0, ts, rtol, atol, max_num_steps,
131 msgs, args...);
132}
133
166template <typename F, typename T_yy, typename T_yp, typename... T_Args,
168inline std::vector<
169 Eigen::Matrix<stan::return_type_t<T_yy, T_yp, T_Args...>, -1, 1>>
170dae(const F& f, const T_yy& yy0, const T_yp& yp0, double t0,
171 const std::vector<double>& ts, std::ostream* msgs, const T_Args&... args) {
172 return dae_tol_impl("dae", f, yy0, yp0, t0, ts, 1.e-10, 1.e-10, 1e8, msgs,
173 args...);
174}
175
176} // namespace math
177} // namespace stan
178
179#endif
IDAS DAE system that contains information on residual equation functor, sensitivity residual equation...
require_all_t< is_eigen_col_vector< std::decay_t< Types > >... > require_all_eigen_col_vector_t
Require all of the types satisfy is_eigen_col_vector.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
std::vector< Eigen::Matrix< stan::return_type_t< T_yy, T_yp, T_Args... >, -1, 1 > > dae_tol(const F &f, const T_yy &yy0, const T_yp &yp0, double t0, const std::vector< double > &ts, double rtol, double atol, int64_t max_num_steps, std::ostream *msgs, const T_Args &... args)
Solve the DAE initial value problem f(t, y, y')=0, y(t0) = yy0, y'(t0)=yp0 at a set of times,...
Definition dae.hpp:127
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
std::vector< Eigen::Matrix< stan::return_type_t< T_yy, T_yp, T_Args... >, -1, 1 > > dae_tol_impl(const char *func, const F &f, const T_yy &yy0, const T_yp &yp0, double t0, const std::vector< double > &ts, double rtol, double atol, int64_t max_num_steps, std::ostream *msgs, const T_Args &... args)
Solve the DAE initial value problem f(t, y, y')=0, y(t0) = yy0, y'(t0)=yp0 at a set of times,...
Definition dae.hpp:54
std::vector< Eigen::Matrix< stan::return_type_t< T_yy, T_yp, T_Args... >, -1, 1 > > dae(const F &f, const T_yy &yy0, const T_yp &yp0, double t0, const std::vector< double > &ts, std::ostream *msgs, const T_Args &... args)
Solve the DAE initial value problem f(t, y, y')=0, y(t0) = yy0, y'(t0)=yp0 at a set of times,...
Definition dae.hpp:170
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
void check_sorted(const char *function, const char *name, const EigVec &y)
Check if the specified vector is sorted into increasing order (repeated values are okay).
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:18
void check_less(const char *function, const char *name, const T_y &y, const T_high &high, Idxs... idxs)
Throw an exception if y is not strictly less than high.
constexpr decltype(auto) apply(F &&f, Tuple &&t, PreArgs &&... pre_args)
Definition apply.hpp:51
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...