libMesh
slepc_eigen_solver.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 <slepceps.h>
34 EXTERN_C_FOR_SLEPC_END
35 
36 namespace libMesh
37 {
38 
47 template <typename T>
48 class SlepcEigenSolver : public EigenSolver<T>
49 {
50 
51 public:
52 
57  LIBMESH_CAN_DEFAULT_TO_COMMWORLD);
58 
59 
64 
65 
69  virtual void clear() libmesh_override;
70 
71 
75  virtual void init() libmesh_override;
76 
77 
88  virtual std::pair<unsigned int, unsigned int>
89  solve_standard (SparseMatrix<T> & matrix_A,
90  int nev,
91  int ncv,
92  const double tol,
93  const unsigned int m_its) libmesh_override;
94 
99  virtual std::pair<unsigned int, unsigned int>
100  solve_standard (ShellMatrix<T> & shell_matrix,
101  int nev,
102  int ncv,
103  const double tol,
104  const unsigned int m_its) libmesh_override;
105 
106 
119  virtual std::pair<unsigned int, unsigned int>
121  SparseMatrix<T> & matrix_B,
122  int nev,
123  int ncv,
124  const double tol,
125  const unsigned int m_its) libmesh_override;
126 
131  virtual std::pair<unsigned int, unsigned int>
133  SparseMatrix<T> & matrix_B,
134  int nev,
135  int ncv,
136  const double tol,
137  const unsigned int m_its) libmesh_override;
138 
149  virtual std::pair<unsigned int, unsigned int>
151  ShellMatrix<T> & matrix_B,
152  int nev,
153  int ncv,
154  const double tol,
155  const unsigned int m_its) libmesh_override;
156 
167  virtual std::pair<unsigned int, unsigned int>
169  ShellMatrix<T> & matrix_B,
170  int nev,
171  int ncv,
172  const double tol,
173  const unsigned int m_its) libmesh_override;
174 
175 
176 
183  virtual std::pair<Real, Real>
185  NumericVector<T> & solution_in) libmesh_override;
186 
190  virtual std::pair<Real, Real>
191  get_eigenvalue (dof_id_type i) libmesh_override;
192 
197  Real get_relative_error (unsigned int i);
198 
202  virtual void attach_deflation_space(NumericVector<T> & deflation_vector) libmesh_override;
203 
207  virtual void
208  set_initial_space(NumericVector<T> & initial_space_in) libmesh_override;
209 
213  EPS eps() { this->init(); return _eps; }
214 
215 private:
216 
220  std::pair<unsigned int, unsigned int> _solve_standard_helper (Mat mat,
221  int nev,
222  int ncv,
223  const double tol,
224  const unsigned int m_its);
225 
229  std::pair<unsigned int, unsigned int> _solve_generalized_helper (Mat mat_A,
230  Mat mat_B,
231  int nev,
232  int ncv,
233  const double tol,
234  const unsigned int m_its);
235 
240  void set_slepc_solver_type ();
241 
246  void set_slepc_problem_type ();
247 
253 
259  static PetscErrorCode _petsc_shell_matrix_mult(Mat mat, Vec arg, Vec dest);
260 
266  static PetscErrorCode _petsc_shell_matrix_get_diagonal(Mat mat, Vec dest);
267 
271  EPS _eps;
272 
273 };
274 
275 
276 /*----------------------- inline functions ----------------------------------*/
277 template <typename T>
278 inline
280  EigenSolver<T>(comm_in)
281 {
282  this->_eigen_solver_type = ARNOLDI;
283  this->_eigen_problem_type = NHEP;
284 }
285 
286 
287 
288 template <typename T>
289 inline
291 {
292  this->clear ();
293 }
294 
295 } // namespace libMesh
296 
297 
298 #endif // #ifdef LIBMESH_HAVE_SLEPC
299 #endif // LIBMESH_SLEPC_EIGEN_SOLVER_H
virtual void clear() libmesh_override
Release all memory and clear data structures.
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)
Helper function that actually performs the generalized eigensolve.
Encapsulates the MPI_Comm object.
Definition: parallel.h:657
Real get_relative_error(unsigned int i)
This class provides an interface to the SLEPc eigenvalue solver library from http://slepc.upv.es/.
Numeric vector.
Definition: dof_map.h:66
static PetscErrorCode _petsc_shell_matrix_get_diagonal(Mat mat, Vec dest)
Internal function if shell matrix mode is used, this just calls the shell matrix&#39;s get_diagonal funct...
The libMesh namespace provides an interface to certain functionality in the library.
SlepcEigenSolver(const Parallel::Communicator &comm_in LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
Constructor.
void set_slepc_solver_type()
Tells Slepc to use the user-specified solver stored in _eigen_solver_type.
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i, NumericVector< T > &solution_in) libmesh_override
Generic sparse matrix.
Definition: dof_map.h:65
void set_slepc_problem_type()
Tells Slepc to deal with the type of problem stored in _eigen_problem_type.
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) libmesh_override
This function calls the SLEPc solver to compute the eigenpairs of the SparseMatrix matrix_A...
EPS _eps
Eigenproblem solver context.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void attach_deflation_space(NumericVector< T > &deflation_vector) libmesh_override
Attach a deflation space defined by a single vector.
virtual std::pair< Real, Real > get_eigenvalue(dof_id_type i) libmesh_override
Same as above, but does not copy the eigenvector.
static PetscErrorCode _petsc_shell_matrix_mult(Mat mat, Vec arg, Vec dest)
Internal function if shell matrix mode is used, this just calls the shell matrix&#39;s matrix multiplicat...
virtual void set_initial_space(NumericVector< T > &initial_space_in) libmesh_override
Use initial_space_in as the initial guess.
std::pair< unsigned int, unsigned int > _solve_standard_helper(Mat mat, int nev, int ncv, const double tol, const unsigned int m_its)
Helper function that actually performs the standard eigensolve.
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) libmesh_override
This function calls the SLEPc solver to compute the eigenpairs for the generalized eigenproblem defin...
EigenSolverType _eigen_solver_type
Enum stating which type of eigensolver to use.
Definition: eigen_solver.h:268
void set_slepc_position_of_spectrum()
Tells Slepc to compute the spectrum at the position stored in _position_of_spectrum.
EigenProblemType _eigen_problem_type
Enum stating which type of eigen problem we deal with.
Definition: eigen_solver.h:273
Generic shell matrix, i.e.
virtual void init() libmesh_override
Initialize data structures if not done so already.
uint8_t dof_id_type
Definition: id_types.h:64
This class provides an interface to solvers for eigenvalue problems.
Definition: eigen_solver.h:54