Helios++
Helios software for LiDAR simulations
FixedIterativeEulerMethod.h
1 #pragma once
2 
3 #include <fluxionum/IterativeEulerMethod.h>
4 
5 #include <armadillo>
6 
7 namespace fluxionum{
8 
24 template <typename A, typename B>
26 protected:
27  // *** USING *** //
28  // *************** //
31 
32  // *** ATTRIBUTES *** //
33  // ******************** //
39  arma::Col<A> const &ta;
44  arma::Col<B> const &ya;
52  size_t i;
53 
54 public:
55  // *** CONSTRUCTION / DESTRUCTION *** //
56  // ************************************ //
68  A const &t0,
69  B const &y0,
70  arma::Col<A> const &ta,
71  arma::Col<B> const &ya,
72  size_t const i=0
73  ) :
74  IterativeEulerMethod<A, B>(dydt, t0, y0),
75  ta(ta),
76  ya(ya),
77  i(i)
78  {}
79  virtual ~FixedIterativeEulerMethod() = default;
80 
81  // *** FUNCTION METHODS *** //
82  // ************************** //
90  B eval(A const &h) override{
91  // Handle fixed frontiers (assuming time is sorted)
92  A th = t+h;
93  A tdiff = h;
94  if((i<ta.n_elem-1) && (th >= ta.at(i+1))){ // Update frontier
95  for(size_t j = ta.n_elem-1 ; j > i ; --j){
96  if(th >= ta.at(j)){
97  tdiff = h-(ta.at(j)-t);
98  t = ta.at(j);
99  y = ya.at(j);
100  i = j;
101  break;
102  }
103  }
104  }
105  // Compute iterative Euler method
106  return IterativeEulerMethod<A, B>::eval(tdiff);
107  }
108 
112  void restart() override{
115  }
116 
117  // *** GETTERs and SETTERs *** //
118  // ***************************** //
122  inline arma::Col<A> const & getTa() const {return ta;}
126  inline arma::Col<B> const & getYa() const {return ya;}
130  inline size_t getCurrentPieceIndex() const {return i;}
134  inline void setCurrentPieceIndex(size_t const i) {this->i = i;}
135 };
136 
137 }
Fixed iterative Euler method.
Definition: FixedIterativeEulerMethod.h:25
arma::Col< A > const & getTa() const
Definition: FixedIterativeEulerMethod.h:122
void setCurrentPieceIndex(size_t const i)
Definition: FixedIterativeEulerMethod.h:134
B eval(A const &h) override
Compute the iterative Euler method but considering given fixed frontiers.
Definition: FixedIterativeEulerMethod.h:90
arma::Col< A > const & ta
The frontiers such that . For the last frontier, the interval is .
Definition: FixedIterativeEulerMethod.h:39
arma::Col< B > const & ya
The value of at each of the frontiers such that .
Definition: FixedIterativeEulerMethod.h:44
arma::Col< B > const & getYa() const
Definition: FixedIterativeEulerMethod.h:126
FixedIterativeEulerMethod(Function< A, B > &dydt, A const &t0, B const &y0, arma::Col< A > const &ta, arma::Col< B > const &ya, size_t const i=0)
FixedIterativeEulerMethod default constructor.
Definition: FixedIterativeEulerMethod.h:66
size_t i
The index of the current piece.
Definition: FixedIterativeEulerMethod.h:52
void restart() override
Definition: FixedIterativeEulerMethod.h:112
size_t getCurrentPieceIndex() const
Definition: FixedIterativeEulerMethod.h:130
Abstract class representing a function.
Definition: Function.h:27
Iterative Euler method.
Definition: IterativeEulerMethod.h:26
A t
The current value of .
Definition: IterativeEulerMethod.h:49
B eval(A const &h) override
Iteratively compute the next value using Euler method.
Definition: IterativeEulerMethod.h:100
Function< A, B > & dydt
Reference to the derivative function.
Definition: IterativeEulerMethod.h:38
A t0
The initial value of , .
Definition: IterativeEulerMethod.h:43
virtual void restart()
Restart the IterativeEulerMethod so it is at its initial state again .
Definition: IterativeEulerMethod.h:110
B y0
The initial value of , .
Definition: IterativeEulerMethod.h:54
B y
The current value of .
Definition: IterativeEulerMethod.h:60