1#ifndef STAN_MATH_REV_FUNCTOR_IDAS_SERVICE_HPP
2#define STAN_MATH_REV_FUNCTOR_IDAS_SERVICE_HPP
9#include <nvector/nvector_serial.h>
10#include <sunmatrix/sunmatrix_dense.h>
11#include <sunlinsol/sunlinsol_dense.h>
12#include <sundials/sundials_context.h>
31template <
typename dae_type>
60 for (
auto i = 0; i < n; ++i) {
78 if (dae_type::use_fwd_sens) {
84 template <
typename dae_t = dae_type,
85 std::enable_if_t<!dae_t::use_fwd_sens>* =
nullptr>
88 template <
typename dae_t = dae_type,
89 std::enable_if_t<dae_t::use_fwd_sens>* =
nullptr>
91 yys = N_VCloneVectorArray(
ns,
nv_yy);
92 yps = N_VCloneVectorArray(
ns,
nv_yp);
93 for (
size_t is = 0; is <
ns; ++is) {
94 N_VConst(RCONST(0.0), yys[is]);
95 N_VConst(RCONST(0.0), yps[is]);
99 IDASensInit(
mem,
ns, IDA_STAGGERED, dae_type::idas_sens_res, yys, yps));
102 template <
typename dae_t = dae_type,
103 std::enable_if_t<dae_t::is_var_yy0 && dae_t::is_var_yp0>* =
nullptr>
105 for (
size_t i = 0; i < n; ++i) {
106 NV_Ith_S(yys[i], i) = 1.0;
108 for (
size_t i = 0; i < n; ++i) {
109 NV_Ith_S(yps[i + n], i) = 1.0;
114 typename dae_t = dae_type,
115 std::enable_if_t<dae_t::is_var_yy0 && (!dae_t::is_var_yp0)>* =
nullptr>
117 for (
size_t i = 0; i < n; ++i) {
118 NV_Ith_S(yys[i], i) = 1.0;
123 typename dae_t = dae_type,
124 std::enable_if_t<(!dae_t::is_var_yy0) && dae_t::is_var_yp0>* =
nullptr>
126 for (
size_t i = 0; i < n; ++i) {
127 NV_Ith_S(yps[i], i) = 1.0;
132 typename dae_t = dae_type,
133 std::enable_if_t<(!dae_t::is_var_yy0) && (!dae_t::is_var_yp0)>* =
nullptr>
#define CHECK_IDAS_CALL(call)
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,...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
void idas_sens_init(N_Vector *yys, N_Vector *yps, int ns, int n)
void set_init_sens(N_Vector *&yys, N_Vector *&yps, int n)
sundials::Context sundials_context_
void idas_sens_init(N_Vector *&yys, N_Vector *&yps, int ns, int n)
idas_service(double t0, dae_type &dae)
Construct IDAS ODE mem & workspace.
For each type of Ode(with different rhs functor F and senstivity parameters), we allocate mem and wor...