HermesCommon  2.0
eigensolver.h
Go to the documentation of this file.
1 // This file is part of HermesCommon
2 //
3 // Copyright (c) 2009 hp-FEM group at the University of Nevada, Reno (UNR).
4 // Email: hpfem-group@unr.edu, home page: http://hpfem.org/.
5 //
6 // Hermes2D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published
8 // by the Free Software Foundation; either version 2 of the License,
9 // or (at your option) any later version.
10 //
11 // Hermes2D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with Hermes2D; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef __HERMES_EIGENSOLVER_H
23 #define __HERMES_EIGENSOLVER_H
24 
25 #include "config.h"
26 #ifdef WITH_PYTHON
27 
28 #include "matrix.h"
29 
30 #include "python_API/python_api.h"
31 
32 // RCP
33 #ifndef WITH_TRILINOS
34 #include "Teuchos_RCP.hpp"
35 #else
36 #include "Teuchos_RCP.hpp"
37 #endif
38 
39 namespace Hermes
40 {
41 
42 using Teuchos::RCP;
43 using Teuchos::Ptr;
44 using Teuchos::rcp;
45 using Teuchos::null;
46 
47 
48 template <typename Scalar>
49 class HERMES_API EigenSolver
50 {
51 public:
52  EigenSolver(const RCP<Algebra::Matrix<Scalar> > &A, const RCP<Algebra::Matrix<Scalar> > &B);
53 
54 
55  // Solves for 'n_eigs' eigenvectors, around the 'target_value'. Use
56  // 'get_eigenvalue' and 'get_eigenvector' to retrieve the
57  // eigenvalues/eigenvectors:
58  void solve(int n_eigs = 4, double target_value = -1, double tol = 1e-6,
59  int max_iter = 150);
60 
61  // Returns the number of calculated eigenvalues
62  int get_n_eigs()
63  {
64  return this->n_eigs;
65  }
66  // Returns the i-th eigenvalue
67  double get_eigenvalue(int i);
68  // Returns the i-th eigenvector. A pointer will be returned into an
69  // internal array, as well as the size of the vector. You don't own the
70  // memory and it will be deallocated once the EigenSolver() class is
71  // deleted. You need to make a copy of it if you want to store it
72  // permanently.
73  void get_eigenvector(int i, double **vec, int *n);
74 
75  void print_eigenvalues()
76  {
77  printf("Eigenvalues:\n");
78  for (int i = 0; i < this->get_n_eigs(); i++)
79  printf("%3d: %f\n", i, this->get_eigenvalue(i));
80  }
81 
82 private:
83  RCP<Algebra::Matrix<Scalar> > A, B;
84  int n_eigs;
85  Python p;
86 };
87 
88 }
89 
90 #endif
91 
92 #endif