Flow123d  last_with_con_2.0.0-4-g42e6930
linear_ode_solver.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file linear_ode_solver.hh
15  * @brief
16  */
17 
18 #ifndef LINEAR_ODE_SOLVER_H_
19 #define LINEAR_ODE_SOLVER_H_
20 
21 #include "armadillo"
22 #include "input/accessors.hh"
23 
24 
25 /// @brief Base class for linear ODE solver.
26 /** This class represents an interface to a solver of a system of linear ordinary differential
27  * equations with constant coefficients.
28  */
30 {
31 public:
32  /**
33  * Abstract record for the linear ODE solver.
34  */
36 
38  virtual ~LinearODESolverBase();
39 
40  void set_system_matrix(const arma::mat &matrix); ///< Sets the matrix of ODE system.
41  void set_step(double step); ///< Sets the step of the numerical method.
42 
43  /// Updates solution of the ODEs system.
44  /**
45  * @param init_vec is the column initial vector
46  * @param output_vec is the column output vector containing the result
47  */
48  virtual void update_solution(arma::vec &init_vec, arma::vec &output_vec) = 0;
49 
50  /// Updates solution of the system with different initial vectors.
51  /**
52  * Column initial @p init_vecs and output @p output_vecs vectors are grouped in the matrices.
53  * Parameter @p mask can be used to skip some of the vectors.
54  */
55  virtual void update_solution(arma::mat &init_vecs, arma::mat &output_vecs,
57 
58  /// Estimate upper bound for time step. Return true if constraint was set.
59  virtual bool evaluate_time_constraint(double &time_constraint) = 0;
60 
61 protected:
62  arma::mat system_matrix_; ///< the square matrix of ODE system
63  arma::vec rhs_; ///< the column vector of RHS values (not used currently)
64  double step_; ///< the step of the numerical method
65  bool step_changed_; ///< flag is true if the step has been changed
66  bool system_matrix_changed_; ///< Indicates that the system_matrix_ was recently updated.
67 };
68 
69 
70 /** @brief Template class of the linear ODE solver.
71  *
72  * It provides a common method @p update_solution which can compute the same system of ODEs with
73  * different initial vectors at once.
74  *
75  * This class represents the Curiously Recurring Template Pattern (CRTP). Therefore, the method update_solution
76  * of the template called inside @p update_solution using static_cast is not a virtual one.
77  *
78  */
79 template<class Method>
81 {
82 public:
84  virtual ~LinearODESolver(){};
85 
86  /// Updates solution of the system with different initial vectors.
87  /**
88  * See the base class member documentation.
89  */
90  virtual void update_solution(arma::mat &init_vecs, arma::mat &output_vecs,
91  const std::vector<unsigned int> &mask = std::vector<unsigned int>(0)) override;
92 
93 private:
94 };
95 
96 template<class Method>
97 void LinearODESolver<Method>::update_solution(arma::mat& init_vecs, arma::mat& output_vecs, const std::vector< unsigned int > &mask)
98 {
99  OLD_ASSERT(0,"Not implemented yet.");
100  OLD_ASSERT_EQUAL(init_vecs.n_cols, output_vecs.n_cols);
101  OLD_ASSERT_EQUAL(init_vecs.n_rows, output_vecs.n_rows);
102 
103  for(unsigned int j=0; j < init_vecs.n_cols; j++)
104  {
105  //static_cast<Method*>(this)->update_solution(init_vecs.col(j), output_vecs.col(j));
106  }
107 }
108 
109 #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)
virtual bool evaluate_time_constraint(double &time_constraint)=0
Estimate upper bound for time step. Return true if constraint was set.
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.
#define OLD_ASSERT(...)
Definition: global_defs.h:131
Base class for linear ODE solver.
bool system_matrix_changed_
Indicates that the system_matrix_ was recently updated.
static Input::Type::Abstract & get_input_type()
bool step_changed_
flag is true if the step has been changed
Class for declaration of polymorphic Record.
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
#define OLD_ASSERT_EQUAL(a, b)
Definition: global_defs.h:133