slepc_eigen_solver.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_SLEPC_EIGEN_SOLVER_H
21 #define LIBMESH_SLEPC_EIGEN_SOLVER_H
22 
23 #include "libmesh/libmesh_config.h"
24 
25 #ifdef LIBMESH_HAVE_SLEPC
26 
27 // Local includes
28 #include "libmesh/eigen_solver.h"
29 #include "libmesh/slepc_macro.h"
30 
31 // SLEPc include files.
32 EXTERN_C_FOR_SLEPC_BEGIN
33 # include "libmesh/ignore_warnings.h"
34 # include <slepceps.h>
36 EXTERN_C_FOR_SLEPC_END
37 
38 namespace libMesh
39 {
40 
49 template <typename T>
50 class SlepcEigenSolver : public EigenSolver<T>
51 {
52 
53 public:
54 
59 
60 
65 
66 
70  virtual void clear() override;
71 
72 
76  virtual void init() override;
77 
78 
89  virtual std::pair<unsigned int, unsigned int>
90  solve_standard (SparseMatrix<T> & matrix_A,
91  int nev,
92  int ncv,
93  const double tol,
94  const unsigned int m_its) override;
95 
100  virtual std::pair<unsigned int, unsigned int>
101  solve_standard (ShellMatrix<T> & shell_matrix,
102  int nev,
103  int ncv,
104  const double tol,
105  const unsigned int m_its) override;
106 
107 
120  virtual std::pair<unsigned int, unsigned int>
122  SparseMatrix<T> & matrix_B,
123  int nev,
124  int ncv,
125  const double tol,
126  const unsigned int m_its) override;
127 
132  virtual std::pair<unsigned int, unsigned int>
134  SparseMatrix<T> & matrix_B,
135  int nev,
136  int ncv,
137  const double tol,
138  const unsigned int m_its) override;
139 
150  virtual std::pair<unsigned int, unsigned int>
152  ShellMatrix<T> & matrix_B,
153  int nev,
154  int ncv,
155  const double tol,
156  const unsigned int m_its) override;
157 
168  virtual std::pair<unsigned int, unsigned int>
170  ShellMatrix<T> & matrix_B,
171  int nev,
172  int ncv,
173  const double tol,
174  const unsigned int m_its) override;
175 
176 
177 
184  virtual std::pair<Real, Real>
186  NumericVector<T> & solution_in) override;
187 
191  virtual std::pair<Real, Real>
192  get_eigenvalue (dof_id_type i) override;
193 
198  Real get_relative_error (unsigned int i);
199 
203  virtual void attach_deflation_space(NumericVector<T> & deflation_vector) override;
204 
208  virtual void
209  set_initial_space(NumericVector<T> & initial_space_in) override;
210 
214  EPS eps() { this->init(); return _eps; }
215 
216 private:
217 
221  std::pair<unsigned int, unsigned int> _solve_standard_helper (Mat mat,
222  int nev,
223  int ncv,
224  const double tol,
225  const unsigned int m_its);
226 
230  std::pair<unsigned int, unsigned int> _solve_generalized_helper (Mat mat_A,
231  Mat mat_B,
232  int nev,
233  int ncv,
234  const double tol,
235  const unsigned int m_its);
236 
241  void set_slepc_solver_type ();
242 
247  void set_slepc_problem_type ();
248 
254 
260  static PetscErrorCode _petsc_shell_matrix_mult(Mat mat, Vec arg, Vec dest);
261 
267  static PetscErrorCode _petsc_shell_matrix_get_diagonal(Mat mat, Vec dest);
268 
272  EPS _eps;
273 
274 };
275 
276 } // namespace libMesh
277 
278 
279 #endif // #ifdef LIBMESH_HAVE_SLEPC
280 #endif // LIBMESH_SLEPC_EIGEN_SOLVER_H
std::pair< unsigned int, unsigned int > _solve_generalized_helper(Mat mat_A, Mat mat_B, int nev, int ncv, const double tol, const unsigned int m_its)
Real get_relative_error(unsigned int i)
EigenSolver implementation based on SLEPc.
virtual std::pair< Real, Real > get_eigenvalue(dof_id_type i) override
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: diff_context.h:40
static PetscErrorCode _petsc_shell_matrix_get_diagonal(Mat mat, Vec dest)
virtual void set_initial_space(NumericVector< T > &initial_space_in) override
virtual void clear() override
virtual std::pair< unsigned int, unsigned int > solve_standard(SparseMatrix< T > &matrix_A, int nev, int ncv, const double tol, const unsigned int m_its) override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static PetscErrorCode _petsc_shell_matrix_mult(Mat mat, Vec arg, Vec dest)
std::pair< unsigned int, unsigned int > _solve_standard_helper(Mat mat, int nev, int ncv, const double tol, const unsigned int m_its)
SlepcEigenSolver(const Parallel::Communicator &comm_in)
virtual void init() override
virtual std::pair< unsigned int, unsigned int > solve_generalized(SparseMatrix< T > &matrix_A, SparseMatrix< T > &matrix_B, int nev, int ncv, const double tol, const unsigned int m_its) override
virtual void attach_deflation_space(NumericVector< T > &deflation_vector) override
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i, NumericVector< T > &solution_in) override
uint8_t dof_id_type
Definition: id_types.h:64
Base class which defines the interface for solving eigenproblems.
Definition: eigen_solver.h:68