Helios++
Helios software for LiDAR simulations
FixedParametricIterativeEulerMethod.h
1 #pragma once
2 
3 #include <fluxionum/ParametricIterativeEulerMethod.h>
4 
5 #include <armadillo>
6 
7 namespace fluxionum{
8 
24 template <typename A, typename B>
27 {
28 protected:
29  // *** USING *** //
30  // *************** //
33 
34  // *** ATTRIBUTES *** //
35  // ******************** //
41  arma::Col<A> const &ta;
47  arma::Mat<B> const &ya;
55  size_t i;
56 
57 public:
58  // *** CONSTRUCTION / DESTRUCTION *** //
59  // ************************************ //
70  Function<A, arma::Col<B>> &dydt,
71  A const &t0,
72  arma::Col<B> const &y0,
73  arma::Col<A> const &ta,
74  arma::Mat<B> const &ya,
75  size_t const i=0
76  ) :
78  ta(ta),
79  ya(ya),
80  i(i)
81  {}
82  virtual ~FixedParametricIterativeEulerMethod() = default;
83 
84  // *** FUNCTION METHODS *** //
85  // ************************** //
93  arma::Col<B> eval(A const &h) override{
94  // Handle fixed frontiers (assuming time is sorted)
95  A th = t+h;
96  A tdiff = h;
97  if((i<ta.n_elem-1) && (th >= ta.at(i+1))){ // Update frontier
98  for(size_t j = ta.n_elem-1 ; j > i ; --j){
99  if(th >= ta.at(j)){
100  tdiff = h-(ta.at(j)-t);
101  t = ta.at(j);
102  y = ya.row(j).as_col();
103  i = j;
104  break;
105  }
106  }
107  }
108  // Compute iterative Euler method
110  }
111 
115  void restart() override{
118  }
119 
120  // *** GETTERs and SETTERs *** //
121  // ***************************** //
126  inline size_t getCurrentPieceIndex() const {return i;}
131  inline void setCurrentPieceIndex(size_t const i) {this->i = i;}
132 };
133 
134 }
Fixed parametric iterative Euler method.
Definition: FixedParametricIterativeEulerMethod.h:27
void setCurrentPieceIndex(size_t const i)
Set the index identifying the current piece.
Definition: FixedParametricIterativeEulerMethod.h:131
void restart() override
Definition: FixedParametricIterativeEulerMethod.h:115
FixedParametricIterativeEulerMethod(Function< A, arma::Col< B >> &dydt, A const &t0, arma::Col< B > const &y0, arma::Col< A > const &ta, arma::Mat< B > const &ya, size_t const i=0)
FixedParametricIterativeEulerMethod default constructor.
Definition: FixedParametricIterativeEulerMethod.h:69
arma::Col< A > const & ta
The frontiers such that . For the last frontier, the interval is .
Definition: FixedParametricIterativeEulerMethod.h:41
arma::Col< B > eval(A const &h) override
Compute the parametric iterative Euler method but considering given fixed frontiers.
Definition: FixedParametricIterativeEulerMethod.h:93
arma::Mat< B > const & ya
The value of at each of the frontiers such that .
Definition: FixedParametricIterativeEulerMethod.h:47
size_t i
The index of the current piece.
Definition: FixedParametricIterativeEulerMethod.h:55
size_t getCurrentPieceIndex() const
Obtain the index identifying the current piece.
Definition: FixedParametricIterativeEulerMethod.h:126
Abstract class representing a function.
Definition: Function.h:27
Parametric iterative Euler method.
Definition: ParametricIterativeEulerMethod.h:27
virtual void restart()
Restart the ParametricIterativeEulerMethod so it is at its initial state again .
Definition: ParametricIterativeEulerMethod.h:112
arma::Col< B > y
The current value of .
Definition: ParametricIterativeEulerMethod.h:61
arma::Col< B > y0
The initial value of , .
Definition: ParametricIterativeEulerMethod.h:55
Function< A, arma::Col< B > > & dydt
Reference to the parametric derivative function.
Definition: ParametricIterativeEulerMethod.h:39
arma::Col< B > eval(A const &h) override
Iteratively compute the next value using Euler method.
Definition: ParametricIterativeEulerMethod.h:102
A t
The current value of .
Definition: ParametricIterativeEulerMethod.h:50
A t0
The initial value of , .
Definition: ParametricIterativeEulerMethod.h:44