MUQ  0.4.3
ODEData.cpp
Go to the documentation of this file.
1 #include "MUQ/Modeling/ODEData.h"
2 
3 #include "boost/none.hpp"
4 
5 using namespace muq::Modeling;
6 
7 // construct basic ode data
8 ODEData::ODEData(std::shared_ptr<ModPiece> const& rhs,
9  ref_vector<Eigen::VectorXd> const& refinputs,
10  bool const autoIn,
11  int const wrtIn,
12  Eigen::VectorXd const& actionVecIn) : rhs(rhs),
13  autonomous(autoIn),
14  wrtIn(wrtIn),
15  actionVec(actionVecIn),
16  isAction(actionVecIn.size()>0)
17 {
18  inputs.reserve(refinputs.size() + (autonomous ? 0 : 1));
19  if(!autonomous)
20  inputs.push_back(std::cref(time));
21 
22  for( unsigned int i=0; i<refinputs.size(); ++i )
23  inputs.push_back(refinputs[i]);
24 }
25 
26 // construct with root function
27 ODEData::ODEData(std::shared_ptr<ModPiece> const& rhs,
28  std::shared_ptr<ModPiece> const& root,
29  ref_vector<Eigen::VectorXd> const& refinputs,
30  bool const autoIn,
31  int const wrtIn,
32  Eigen::VectorXd const& actionVecIn) : rhs(rhs),
33  root(root),
34  autonomous(autoIn),
35  wrtIn(wrtIn),
36  actionVec(actionVecIn),
37  isAction(actionVecIn.size()>0)
38 {
39  inputs.reserve(refinputs.size() + (autonomous ? 0 : 1));
40  if(!autonomous)
41  inputs.push_back(std::cref(state));
42 
43  for( unsigned int i=0; i<refinputs.size(); ++i )
44  inputs.push_back(refinputs[i]);
45 }
46 
47 void ODEData::UpdateInputs(Eigen::Ref<const Eigen::VectorXd> const& newState, double const newTime)
48 {
49 
50  state = newState;
51 
52  if( autonomous ) {
53  inputs.at(0) = std::cref(state);
54  }else{
55  time = Eigen::VectorXd::Constant(1, newTime);
56  inputs.at(0) = std::cref(time);
57  inputs.at(1) = std::cref(state);
58  }
59 
60 }
Eigen::VectorXd time
The inputs to the rhs — the first is the state, the rest are constant in time.
Definition: ODEData.h:62
const bool autonomous
Is the RHS autonomous?
Definition: ODEData.h:67
ref_vector< Eigen::VectorXd > inputs
Definition: ODEData.h:64
ODEData(std::shared_ptr< ModPiece > const &rhs, ref_vector< Eigen::VectorXd > const &refinputs, bool const autonomous, int const wrtIn, Eigen::VectorXd const &actionVec=Eigen::VectorXd())
Construct basic ode data.
Definition: ODEData.cpp:8
void UpdateInputs(Eigen::Ref< const Eigen::VectorXd > const &newState, double const time)
Update the time and state inputs.
Definition: ODEData.cpp:47
Eigen::VectorXd state
Definition: ODEData.h:63
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...
Definition: WorkPiece.h:37