Stan Math Library  2.20.0
reverse mode automatic differentiation
coupled_ode_system.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_ARR_FUNCTOR_COUPLED_ODE_SYSTEM_HPP
2 #define STAN_MATH_PRIM_ARR_FUNCTOR_COUPLED_ODE_SYSTEM_HPP
3 
5 #include <ostream>
6 #include <vector>
7 
8 namespace stan {
9 namespace math {
10 
28 template <typename F, typename T1, typename T2>
30 
44 template <typename F>
45 class coupled_ode_system<F, double, double> {
46  public:
47  const F& f_;
48  const std::vector<double>& y0_dbl_;
49  const std::vector<double>& theta_dbl_;
50  const std::vector<double>& x_;
51  const std::vector<int>& x_int_;
52  const size_t N_;
53  const size_t M_;
54  const size_t size_;
55  std::ostream* msgs_;
56 
69  coupled_ode_system(const F& f, const std::vector<double>& y0,
70  const std::vector<double>& theta,
71  const std::vector<double>& x,
72  const std::vector<int>& x_int, std::ostream* msgs)
73  : f_(f),
74  y0_dbl_(y0),
75  theta_dbl_(theta),
76  x_(x),
77  x_int_(x_int),
78  N_(y0.size()),
79  M_(theta.size()),
80  size_(N_),
81  msgs_(msgs) {}
82 
95  void operator()(const std::vector<double>& y, std::vector<double>& dy_dt,
96  double t) const {
97  dy_dt = f_(t, y, theta_dbl_, x_, x_int_, msgs_);
98  check_size_match("coupled_ode_system", "y", y.size(), "dy_dt",
99  dy_dt.size());
100  }
101 
107  int size() const { return size_; }
108 
115  std::vector<double> initial_state() const {
116  std::vector<double> state(size_, 0.0);
117  for (size_t n = 0; n < N_; n++)
118  state[n] = y0_dbl_[n];
119  return state;
120  }
121 };
122 
123 } // namespace math
124 } // namespace stan
125 #endif
coupled_ode_system(const F &f, const std::vector< double > &y0, const std::vector< double > &theta, const std::vector< double > &x, const std::vector< int > &x_int, std::ostream *msgs)
Construct the coupled ode system from the base system function, initial state of the base system...
std::vector< double > initial_state() const
Returns the initial state of the coupled system.
void operator()(const std::vector< double > &y, std::vector< double > &dy_dt, double t) const
Calculates the derivative of the coupled ode system with respect to time.
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
int size() const
Returns the size of the coupled system.
int size(const std::vector< T > &x)
Return the size of the specified standard vector.
Definition: size.hpp:17
The coupled_ode_system represents the coupled ode system, which is the base ode and the sensitivities...

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