Flow123d  jenkins-Flow123d-linux-release-multijob-282
linear_ode_solver.hh
Go to the documentation of this file.
1 #ifndef LINEAR_ODE_SOLVER_H_
2 #define LINEAR_ODE_SOLVER_H_
3 
4 #include "armadillo"
5 #include "input/accessors.hh"
6 
7 
8 /// @brief Base class for linear ODE solver.
9 /** This class represents an interface to a solver of a system of linear ordinary differential
10  * equations with constant coefficients.
11  */
13 {
14 public:
15  /**
16  * Abstract record for the linear ODE solver.
17  */
19 
21  virtual ~LinearODESolverBase();
22 
23  void set_system_matrix(const arma::mat &matrix); ///< Sets the matrix of ODE system.
24  void set_step(double step); ///< Sets the step of the numerical method.
25 
26  /// Updates solution of the ODEs system.
27  /**
28  * @param init_vec is the column initial vector
29  * @param output_vec is the column output vector containing the result
30  */
31  virtual void update_solution(arma::vec &init_vec, arma::vec &output_vec) = 0;
32 
33  /// Updates solution of the system with different initial vectors.
34  /**
35  * Column initial @p init_vecs and output @p output_vecs vectors are grouped in the matrices.
36  * Parameter @p mask can be used to skip some of the vectors.
37  */
38  virtual void update_solution(arma::mat &init_vecs, arma::mat &output_vecs,
40 
41 protected:
42  arma::mat system_matrix_; ///< the square matrix of ODE system
43  arma::vec rhs_; ///< the column vector of RHS values (not used currently)
44  double step_; ///< the step of the numerical method
45  bool step_changed_; ///< flag is true if the step has been changed
46 };
47 
48 
49 /** @brief Template class of the linear ODE solver.
50  *
51  * It provides a common method @p update_solution which can compute the same system of ODEs with
52  * different initial vectors at once.
53  *
54  * This class represents the Curiously Recurring Template Pattern (CRTP). Therefore, the method update_solution
55  * of the template called inside @p update_solution using static_cast is not a virtual one.
56  *
57  */
58 template<class Method>
60 {
61 public:
63  virtual ~LinearODESolver(){};
64 
65  /// Updates solution of the system with different initial vectors.
66  /**
67  * See the base class member documentation.
68  */
69  virtual void update_solution(arma::mat &init_vecs, arma::mat &output_vecs,
70  const std::vector<unsigned int> &mask = std::vector<unsigned int>(0)) override;
71 
72 private:
73 };
74 
75 template<class Method>
76 void LinearODESolver<Method>::update_solution(arma::mat& init_vecs, arma::mat& output_vecs, const std::vector< unsigned int > &mask)
77 {
78  ASSERT(0,"Not implemented yet.");
79  ASSERT_EQUAL(init_vecs.n_cols, output_vecs.n_cols);
80  ASSERT_EQUAL(init_vecs.n_rows, output_vecs.n_rows);
81 
82  for(unsigned int j=0; j < init_vecs.n_cols; j++)
83  {
84  //static_cast<Method*>(this)->update_solution(init_vecs.col(j), output_vecs.col(j));
85  }
86 }
87 
88 #endif // LINEAR_ODE_SOLVER_H_
arma::mat system_matrix_
the square matrix of ODE system
virtual ~LinearODESolver()
arma::vec rhs_
the column vector of RHS values (not used currently)
static Input::Type::AbstractRecord input_type
Template class of the linear ODE solver.
virtual void update_solution(arma::mat &init_vecs, arma::mat &output_vecs, const std::vector< unsigned int > &mask=std::vector< unsigned int >(0)) override
Updates solution of the system with different initial vectors.
void set_step(double step)
Sets the step of the numerical method.
Base class for linear ODE solver.
#define ASSERT(...)
Definition: global_defs.h:121
#define ASSERT_EQUAL(a, b)
Definition: global_defs.h:136
Class for declaration of polymorphic Record.
Definition: type_record.hh:487
bool step_changed_
flag is true if the step has been changed
virtual void update_solution(arma::vec &init_vec, arma::vec &output_vec)=0
Updates solution of the ODEs system.
void set_system_matrix(const arma::mat &matrix)
Sets the matrix of ODE system.
double step_
the step of the numerical method