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>
52std::vector<Eigen::Matrix<stan::return_type_t<T_yy, T_yp, T_Args...>, -1, 1>>
53dae_tol_impl(const char* func, const F& f, const T_yy& yy0, const T_yp& yp0,
54 double t0, const std::vector<double>& ts, double rtol, double atol,
55 int64_t max_num_steps, std::ostream* msgs, const T_Args&... args) {
56 check_finite(func, "initial state", yy0);
57 check_finite(func, "initial state derivative", yp0);
58 check_nonzero_size(func, "initial state", yy0);
59 check_nonzero_size(func, "initial state derivative", yp0);
60 check_finite(func, "initial time", t0);
61 check_finite(func, "times", ts);
62 check_nonzero_size(func, "times", ts);
63 check_sorted(func, "times", ts);
64 check_less(func, "initial time", t0, ts[0]);
65 check_positive_finite(func, "relative_tolerance", rtol);
66 check_positive_finite(func, "absolute_tolerance", atol);
67 check_positive(func, "max_num_steps", max_num_steps);
68
69 const auto& args_ref_tuple = std::make_tuple(to_ref(args)...);
71 [&](auto&&... args) {
72 std::vector<int> unused_temp{
73 0, (check_finite("dae", "DAE parameters and data", args), 0)...};
74 },
75 args_ref_tuple);
76
77 return math::apply(
78 [&](const auto&... args_refs) {
80 args_refs...);
81 idas_integrator integ(rtol, atol, max_num_steps);
82 return integ(func, dae, t0, ts);
83 },
84 args_ref_tuple);
85}
86
122template <typename F, typename T_yy, typename T_yp, typename... T_Args,
124std::vector<Eigen::Matrix<stan::return_type_t<T_yy, T_yp, T_Args...>, -1, 1>>
125dae_tol(const F& f, const T_yy& yy0, const T_yp& yp0, double t0,
126 const std::vector<double>& ts, double rtol, double atol,
127 int64_t max_num_steps, std::ostream* msgs, const T_Args&... args) {
128 return dae_tol_impl("dae_tol", f, yy0, yp0, t0, ts, rtol, atol, max_num_steps,
129 msgs, args...);
130}
131
164template <typename F, typename T_yy, typename T_yp, typename... T_Args,
166std::vector<Eigen::Matrix<stan::return_type_t<T_yy, T_yp, T_Args...>, -1, 1>>
167dae(const F& f, const T_yy& yy0, const T_yp& yp0, double t0,
168 const std::vector<double>& ts, std::ostream* msgs, const T_Args&... args) {
169 return dae_tol_impl("dae", f, yy0, yp0, t0, ts, 1.e-10, 1.e-10, 1e8, msgs,
170 args...);
171}
172
173} // namespace math
174} // namespace stan
175
176#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:125
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
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:53
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:167
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).
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:52
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 ...