Stan Math Library  2.14.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 
24  template <typename F, typename T1, typename T2>
26  };
27 
38  template <typename F>
39  class coupled_ode_system<F, double, double> {
40  public:
41  const F& f_;
42  const std::vector<double>& y0_dbl_;
43  const std::vector<double>& theta_dbl_;
44  const std::vector<double>& x_;
45  const std::vector<int>& x_int_;
46  const size_t N_;
47  const size_t M_;
48  const size_t size_;
49  std::ostream* msgs_;
50 
63  coupled_ode_system(const F& f,
64  const std::vector<double>& y0,
65  const std::vector<double>& theta,
66  const std::vector<double>& x,
67  const std::vector<int>& x_int,
68  std::ostream* msgs)
69  : f_(f),
70  y0_dbl_(y0),
71  theta_dbl_(theta),
72  x_(x),
73  x_int_(x_int),
74  N_(y0.size()),
75  M_(theta.size()),
76  size_(N_),
77  msgs_(msgs) {
78  }
79 
95  void operator()(const std::vector<double>& y,
96  std::vector<double>& dy_dt,
97  double t) {
98  dy_dt = f_(t, y, theta_dbl_, x_, x_int_, msgs_);
99  check_size_match("coupled_ode_system",
100  "y", y.size(),
101  "dy_dt", dy_dt.size());
102  }
103 
109  int size() const {
110  return size_;
111  }
112 
125  std::vector<double> initial_state() {
126  std::vector<double> state(size_, 0.0);
127  for (size_t n = 0; n < N_; n++)
128  state[n] = y0_dbl_[n];
129  return state;
130  }
131 
142  std::vector<std::vector<double> >
143  decouple_states(const std::vector<std::vector<double> >& y) {
144  return y;
145  }
146  };
147 
148  }
149 }
150 #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...
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.
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.
size_t size_
Definition: dot_self.hpp:18
std::vector< double > initial_state()
Returns the initial state of the coupled system, which is identical to the base ODE original state in...
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–2016, Stan Development Team.