coupled_ode_system.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_ARR_FUNCTOR_COUPLED_ODE_SYSTEM_HPP
#define STAN_MATH_PRIM_ARR_FUNCTOR_COUPLED_ODE_SYSTEM_HPP
#include <stan/math/prim/scal/err/check_size_match.hpp>
#include <ostream>
#include <vector>
namespace stan {
namespace math {
template <typename F, typename T1, typename T2>
struct coupled_ode_system {
};
template <typename F>
class coupled_ode_system<F, double, double> {
public:
const F& f_;
const std::vector<double>& y0_dbl_;
const std::vector<double>& theta_dbl_;
const std::vector<double>& x_;
const std::vector<int>& x_int_;
const size_t N_;
const size_t M_;
const size_t size_;
std::ostream* msgs_;
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)
: f_(f),
y0_dbl_(y0),
theta_dbl_(theta),
x_(x),
x_int_(x_int),
N_(y0.size()),
M_(theta.size()),
size_(N_),
msgs_(msgs) {
}
void operator()(const std::vector<double>& y,
std::vector<double>& dy_dt,
double t) {
dy_dt = f_(t, y, theta_dbl_, x_, x_int_, msgs_);
check_size_match("coupled_ode_system",
"y", y.size(),
"dy_dt", dy_dt.size());
}
int size() const {
return size_;
}
std::vector<double> initial_state() {
std::vector<double> state(size_, 0.0);
for (size_t n = 0; n < N_; n++)
state[n] = y0_dbl_[n];
return state;
}
std::vector<std::vector<double> >
decouple_states(const std::vector<std::vector<double> >& y) {
return y;
}
};
}
}
#endif
stan::math::coupled_ode_system< F, double, double >::x_int_
const std::vector< int > & x_int_
Definition: coupled_ode_system.hpp:45
stan::math::coupled_ode_system< F, double, double >::operator()
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...
Definition: coupled_ode_system.hpp:95
stan::math::coupled_ode_system< F, double, double >::theta_dbl_
const std::vector< double > & theta_dbl_
Definition: coupled_ode_system.hpp:43
stan::math::coupled_ode_system< F, double, double >::coupled_ode_system
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.
Definition: coupled_ode_system.hpp:63
stan::math::coupled_ode_system< F, double, double >::msgs_
std::ostream * msgs_
Definition: coupled_ode_system.hpp:49
check_size_match.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::coupled_ode_system< F, double, double >::M_
const size_t M_
Definition: coupled_ode_system.hpp:47
stan::math::check_size_match
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.
Definition: check_size_match.hpp:29
stan::math::coupled_ode_system< F, double, double >::y0_dbl_
const std::vector< double > & y0_dbl_
Definition: coupled_ode_system.hpp:42
stan::math::coupled_ode_system< F, double, double >::size
int size() const
Returns the size of the coupled system.
Definition: coupled_ode_system.hpp:109
stan::math::coupled_ode_system< F, double, double >::N_
const size_t N_
Definition: coupled_ode_system.hpp:46
size_
size_t size_
Definition: dot_self.hpp:18
stan::math::coupled_ode_system< F, double, double >::initial_state
std::vector< double > initial_state()
Returns the initial state of the coupled system, which is identical to the base ODE original state in...
Definition: coupled_ode_system.hpp:125
stan::math::coupled_ode_system< F, double, double >::f_
const F & f_
Definition: coupled_ode_system.hpp:41
stan::math::coupled_ode_system< F, double, double >::x_
const std::vector< double > & x_
Definition: coupled_ode_system.hpp:44
stan::math::coupled_ode_system< F, double, double >::decouple_states
std::vector< std::vector< double > > decouple_states(const std::vector< std::vector< double > > &y)
Returns the base portion of the coupled state.
Definition: coupled_ode_system.hpp:143
stan::math::size
int size(const std::vector< T > &x)
Return the size of the specified standard vector.
Definition: size.hpp:17
stan::math::coupled_ode_system
Base template class for a coupled ordinary differential equation system, which adds sensitivities to ...
Definition: coupled_ode_system.hpp:25
N_
int N_
Definition: mdivide_left.hpp:20
stan::math::coupled_ode_system< F, double, double >::size_
const size_t size_
Definition: coupled_ode_system.hpp:48

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