Flow123d  jenkins-Flow123d-linux-release-multijob-282
pade_approximant.hh
Go to the documentation of this file.
1 /*
2  * pade_approximant.h
3  *
4  * Author: PavelExner
5  */
6 
7 #ifndef PADE_APPROXIMANT_H_
8 #define PADE_APPROXIMANT_H_
9 
10 #include "input/accessors.hh"
12 #include "armadillo"
13 
14 /** @brief This class implements the Pade approximation of exponential function.
15  *
16  * The exponential function is considered in the form \f$ e^{At} \f$ where \f$ A \f$ is a constant matrix.
17  * It is then approximated by a fraction of polynomials
18  * \f[ e^{At} = \frac{P(t)}{Q(t)},\f]
19  * where the degrees of polynomials in nominator and denominator, \f$ P(t) \f$ and \f$ Q(t) \f$, are
20  * set from the input record.
21  *
22  */
23 class PadeApproximant : public LinearODESolver<PadeApproximant>
24 {
25 public:
26  /**
27  * Input record for class PadeApproximant.
28  */
30 
31  /// Constructor from input record.
33 
34  /// Constructor.
35  PadeApproximant(unsigned int nominator_degree, unsigned int denominator_degree);
36 
37  /// Destructor.
38  ~PadeApproximant(void);
39 
40  void update_solution(arma::vec &init_vector, arma::vec &output_vec) override;
41 
42 protected:
43  ///Hide default constructor.
45 
46  /**
47  * Approximate the matrix function.
48  */
49  void approximate_matrix(arma::mat &matrix);
50 
51  /// Evaluates nominator and denominator coeficients of PadeApproximant for exponencial function.
52  /** @param nominator_degree is the degree of polynomial in the nominator
53  * @param denominator_degree is the degree of polynomial in the denominator
54  * @param nominator_coefs is the vector of coeficients of the polynomial in the nominator
55  * @param denominator_coefs is the vector of coeficients of the polynomial in the denominator
56  */
57  void compute_exp_coefs(unsigned int nominator_degree, unsigned int denominator_degree,
58  std::vector<double> &nominator_coefs, std::vector<double> &denominator_coefs);
59 
60  /// Evaluates the matrix polynomial by Horner scheme.
61  /** @param polynomial_matrix is the output matrix
62  * @param input_matrix is the input matrix (with elements -kt)
63  * @param coefs is the vector of coeficients of the polynomial
64  */
65  void evaluate_matrix_polynomial(arma::mat &polynomial_matrix,
66  const arma::mat &input_matrix,
67  const std::vector<double> &coefs);
68 
69  int nominator_degree_; ///< Degree of the polynomial in the nominator.
70  int denominator_degree_; ///< Degree of the polynomial in the denominator.
71 
72  arma::mat solution_matrix_; ///< Solution matrix \f$ e^{At} \f$.
73 };
74 
75 #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...
static Input::Type::Record input_type
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.
PadeApproximant()
Hide default constructor.
Accessor to the data with type Type::Record.
Definition: accessors.hh:327
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.
arma::mat solution_matrix_
Solution matrix .
Record type proxy class.
Definition: type_record.hh:169