Flow123d  release_2.2.0-22-g936454a
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 #include "system/global_defs.h"
24 #include "system/asserts.hh"
25 
26 
27 /// @brief Base class for linear ODE solver.
28 /** This class represents an interface to a solver of a system of linear ordinary differential
29  * equations with constant coefficients.
30  */
32 {
33 public:
34  /**
35  * Abstract record for the linear ODE solver.
36  */
38 
40  virtual ~LinearODESolverBase();
41 
42  void set_system_matrix(const arma::mat &matrix); ///< Sets the matrix of ODE system.
43  void set_step(double step); ///< Sets the step of the numerical method.
44 
45  /// Updates solution of the ODEs system.
46  /**
47  * @param init_vec is the column initial vector
48  * @param output_vec is the column output vector containing the result
49  */
50  virtual void update_solution(arma::vec &init_vec, arma::vec &output_vec) = 0;
51 
52  /// Updates solution of the system with different initial vectors.
53  /**
54  * Column initial @p init_vecs and output @p output_vecs vectors are grouped in the matrices.
55  * Parameter @p mask can be used to skip some of the vectors.
56  */
57  virtual void update_solution(arma::mat &init_vecs, arma::mat &output_vecs,
59 
60  /// Estimate upper bound for time step. Return true if constraint was set.
61  virtual bool evaluate_time_constraint(double &time_constraint) = 0;
62 
63 protected:
64  arma::mat system_matrix_; ///< the square matrix of ODE system
65  arma::vec rhs_; ///< the column vector of RHS values (not used currently)
66  double step_; ///< the step of the numerical method
67  bool step_changed_; ///< flag is true if the step has been changed
68  bool system_matrix_changed_; ///< Indicates that the system_matrix_ was recently updated.
69 };
70 
71 
72 /** @brief Template class of the linear ODE solver.
73  *
74  * It provides a common method @p update_solution which can compute the same system of ODEs with
75  * different initial vectors at once.
76  *
77  * This class represents the Curiously Recurring Template Pattern (CRTP). Therefore, the method update_solution
78  * of the template called inside @p update_solution using static_cast is not a virtual one.
79  *
80  */
81 template<class Method>
83 {
84 public:
86  virtual ~LinearODESolver(){};
87 
88  /// Updates solution of the system with different initial vectors.
89  /**
90  * See the base class member documentation.
91  */
92  virtual void update_solution(arma::mat &init_vecs, arma::mat &output_vecs,
93  const std::vector<unsigned int> &mask = std::vector<unsigned int>(0)) override;
94 
95 private:
96 };
97 
98 template<class Method>
99 void LinearODESolver<Method>::update_solution(arma::mat& init_vecs, arma::mat& output_vecs, const std::vector< unsigned int > &mask)
100 {
101  OLD_ASSERT(0,"Not implemented yet.");
102  OLD_ASSERT_EQUAL(init_vecs.n_cols, output_vecs.n_cols);
103  OLD_ASSERT_EQUAL(init_vecs.n_rows, output_vecs.n_rows);
104 
105  for(unsigned int j=0; j < init_vecs.n_cols; j++)
106  {
107  //static_cast<Method*>(this)->update_solution(init_vecs.col(j), output_vecs.col(j));
108  }
109 }
110 
111 #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.
Definitions of ASSERTS.
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
Global macros to enhance readability and debugging, general constants.
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