Flow123d  release_2.2.0-22-g936454a
pade_approximant.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 pade_approximant.hh
15  * @brief
16  */
17 
18 #ifndef PADE_APPROXIMANT_H_
19 #define PADE_APPROXIMANT_H_
20 
23 #include "armadillo"
24 
25 /** @brief This class implements the Pade approximation of exponential function.
26  *
27  * The exponential function is considered in the form \f$ e^{At} \f$ where \f$ A \f$ is a constant matrix.
28  * It is then approximated by a fraction of polynomials
29  * \f[ e^{At} = \frac{P(t)}{Q(t)},\f]
30  * where the degrees of polynomials in nominator and denominator, \f$ P(t) \f$ and \f$ Q(t) \f$, are
31  * set from the input record.
32  *
33  */
34 class PadeApproximant : public LinearODESolver<PadeApproximant>
35 {
36 public:
38 
39  /**
40  * Input record for class PadeApproximant.
41  */
42  static const Input::Type::Record & get_input_type();
43 
44  /// Constructor from input record.
46 
47  /// Constructor.
48  PadeApproximant(unsigned int nominator_degree, unsigned int denominator_degree);
49 
50  /// Destructor.
51  ~PadeApproximant(void);
52 
53  void update_solution(arma::vec &init_vector, arma::vec &output_vec) override;
54 
55  bool evaluate_time_constraint(double &time_constraint) override { return false; }
56 
57 protected:
58  ///Hide default constructor.
60 
61  /**
62  * Approximate the matrix function.
63  */
64  void approximate_matrix(arma::mat &matrix);
65 
66  /// Evaluates nominator and denominator coeficients of PadeApproximant for exponencial function.
67  /** @param nominator_degree is the degree of polynomial in the nominator
68  * @param denominator_degree is the degree of polynomial in the denominator
69  * @param nominator_coefs is the vector of coeficients of the polynomial in the nominator
70  * @param denominator_coefs is the vector of coeficients of the polynomial in the denominator
71  */
72  void compute_exp_coefs(unsigned int nominator_degree, unsigned int denominator_degree,
73  std::vector<double> &nominator_coefs, std::vector<double> &denominator_coefs);
74 
75  /// Evaluates the matrix polynomial by Horner scheme.
76  /** @param polynomial_matrix is the output matrix
77  * @param input_matrix is the input matrix (with elements -kt)
78  * @param coefs is the vector of coeficients of the polynomial
79  */
80  void evaluate_matrix_polynomial(arma::mat &polynomial_matrix,
81  const arma::mat &input_matrix,
82  const std::vector<double> &coefs);
83 
84  int nominator_degree_; ///< Degree of the polynomial in the nominator.
85  int denominator_degree_; ///< Degree of the polynomial in the denominator.
86 
87  arma::mat solution_matrix_; ///< Solution matrix \f$ e^{At} \f$.
88 
89 private:
90  /// Registrar of class to factory
91  static const int registrar;
92 };
93 
94 #endif // PADE_APPROXIMANT_H_
This class implements the Pade approximation of exponential function.
void approximate_matrix(arma::mat &matrix)
int nominator_degree_
Degree of the polynomial in the nominator.
void compute_exp_coefs(unsigned int nominator_degree, unsigned int denominator_degree, std::vector< double > &nominator_coefs, std::vector< double > &denominator_coefs)
Evaluates nominator and denominator coeficients of PadeApproximant for exponencial function...
Template class of the linear ODE solver.
void update_solution(arma::vec &init_vector, arma::vec &output_vec) override
Updates solution of the ODEs system.
int denominator_degree_
Degree of the polynomial in the denominator.
Base class for linear ODE solver.
PadeApproximant()
Hide default constructor.
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
static const Input::Type::Record & get_input_type()
static const int registrar
Registrar of class to factory.
void evaluate_matrix_polynomial(arma::mat &polynomial_matrix, const arma::mat &input_matrix, const std::vector< double > &coefs)
Evaluates the matrix polynomial by Horner scheme.
~PadeApproximant(void)
Destructor.
LinearODESolverBase FactoryBaseType
arma::mat solution_matrix_
Solution matrix .
Record type proxy class.
Definition: type_record.hh:182
bool evaluate_time_constraint(double &time_constraint) override
Estimate upper bound for time step. Return true if constraint was set.