Stan Math Library  2.9.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 
10  namespace math {
11 
25  template <typename F, typename T1, typename T2>
27  };
28 
29 
40  template <typename F>
41  struct coupled_ode_system<F, double, double> {
42  const F& f_;
43  const std::vector<double>& y0_dbl_;
44  const std::vector<double>& theta_dbl_;
45  const std::vector<double>& x_;
46  const std::vector<int>& x_int_;
47  const int N_;
48  const int M_;
49  const int size_;
50  std::ostream* msgs_;
51 
64  coupled_ode_system(const F& f,
65  const std::vector<double>& y0,
66  const std::vector<double>& theta,
67  const std::vector<double>& x,
68  const std::vector<int>& x_int,
69  std::ostream* msgs)
70  : f_(f),
71  y0_dbl_(y0),
72  theta_dbl_(theta),
73  x_(x),
74  x_int_(x_int),
75  N_(y0.size()),
76  M_(theta.size()),
77  size_(N_),
78  msgs_(msgs) {
79  }
80 
96  void operator()(const std::vector<double>& y,
97  std::vector<double>& dy_dt,
98  double t) {
99  dy_dt = f_(t, y, theta_dbl_, x_, x_int_, msgs_);
100  stan::math::check_matching_sizes("coupled_ode_system",
101  "y", y,
102  "dy_dt", dy_dt);
103  }
104 
110  int size() const {
111  return size_;
112  }
113 
126  std::vector<double> initial_state() {
127  std::vector<double> state(size_, 0.0);
128  for (int n = 0; n < N_; n++)
129  state[n] = y0_dbl_[n];
130  return state;
131  }
132 
143  std::vector<std::vector<double> >
144  decouple_states(const std::vector<std::vector<double> >& y) {
145  return y;
146  }
147  };
148 
149  }
150 
151 }
152 
153 #endif
void operator()(const std::vector< double > &y, std::vector< double > &dy_dt, double t)
Calculates the derivative of the coupled ode system with respect to the specified state at the specif...
std::vector< double > initial_state()
Returns the initial state of the coupled system, which is identical to the base ODE original state in...
size_t size_
Definition: dot_self.hpp:18
int size() const
Returns the size of the coupled system.
bool check_matching_sizes(const char *function, const char *name1, const T_y1 &y1, const char *name2, const T_y2 &y2)
Return true if two structures at the same size.
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, parameters, data and a stream for messages.
std::vector< std::vector< double > > decouple_states(const std::vector< std::vector< double > > &y)
Returns the base portion of the coupled state.
int size(const std::vector< T > &x)
Return the size of the specified standard vector.
Definition: size.hpp:17
Base template class for a coupled ordinary differential equation system, which adds sensitivities to ...
int N_

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