libMesh
slepc_eigen_solver.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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>
35 # include "libmesh/restore_warnings.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 
58  SlepcEigenSolver(const Parallel::Communicator & comm_in);
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 
111  virtual std::pair<unsigned int, unsigned int>
112  solve_standard (ShellMatrix<T> & shell_matrix,
113  SparseMatrix<T> & precond,
114  int nev,
115  int ncv,
116  const double tol,
117  const unsigned int m_its) override;
118 
119 
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 
144  virtual std::pair<unsigned int, unsigned int>
146  SparseMatrix<T> & matrix_B,
147  int nev,
148  int ncv,
149  const double tol,
150  const unsigned int m_its) override;
151 
162  virtual std::pair<unsigned int, unsigned int>
164  ShellMatrix<T> & matrix_B,
165  int nev,
166  int ncv,
167  const double tol,
168  const unsigned int m_its) override;
169 
180  virtual std::pair<unsigned int, unsigned int>
182  ShellMatrix<T> & matrix_B,
183  int nev,
184  int ncv,
185  const double tol,
186  const unsigned int m_its) override;
187 
188 
189  virtual std::pair<unsigned int, unsigned int>
191  ShellMatrix<T> & matrix_B,
192  SparseMatrix<T> & precond,
193  int nev,
194  int ncv,
195  const double tol,
196  const unsigned int m_its) override;
197 
198 
205  virtual std::pair<Real, Real>
207  NumericVector<T> & solution_in) override;
208 
212  virtual std::pair<Real, Real>
213  get_eigenvalue (dof_id_type i) override;
214 
219  Real get_relative_error (unsigned int i);
220 
224  virtual void attach_deflation_space(NumericVector<T> & deflation_vector) override;
225 
229  virtual void
230  set_initial_space(NumericVector<T> & initial_space_in) override;
231 
235  EPS eps() { this->init(); return _eps; }
236 
237 private:
238 
242  std::pair<unsigned int, unsigned int> _solve_standard_helper (Mat mat,
243  Mat precond,
244  int nev,
245  int ncv,
246  const double tol,
247  const unsigned int m_its);
248 
252  std::pair<unsigned int, unsigned int> _solve_generalized_helper (Mat mat_A,
253  Mat mat_B,
254  Mat precond,
255  int nev,
256  int ncv,
257  const double tol,
258  const unsigned int m_its);
259 
264  void set_slepc_solver_type ();
265 
270  void set_slepc_problem_type ();
271 
277 
283  static PetscErrorCode _petsc_shell_matrix_mult(Mat mat, Vec arg, Vec dest);
284 
290  static PetscErrorCode _petsc_shell_matrix_get_diagonal(Mat mat, Vec dest);
291 
295  EPS _eps;
296 
297 };
298 
299 } // namespace libMesh
300 
301 
302 #endif // #ifdef LIBMESH_HAVE_SLEPC
303 #endif // LIBMESH_SLEPC_EIGEN_SOLVER_H
libMesh::ShellMatrix
Generic shell matrix, i.e.
Definition: eigen_preconditioner.h:36
libMesh::SlepcEigenSolver::_solve_generalized_helper
std::pair< unsigned int, unsigned int > _solve_generalized_helper(Mat mat_A, Mat mat_B, Mat precond, int nev, int ncv, const double tol, const unsigned int m_its)
Helper function that actually performs the generalized eigensolve.
Definition: slepc_eigen_solver.C:520
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::SlepcEigenSolver::~SlepcEigenSolver
~SlepcEigenSolver()
Destructor.
Definition: slepc_eigen_solver.C:51
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::SlepcEigenSolver::get_eigenvalue
virtual std::pair< Real, Real > get_eigenvalue(dof_id_type i) override
Same as above, but does not copy the eigenvector.
Definition: slepc_eigen_solver.C:841
libMesh::SlepcEigenSolver::set_slepc_solver_type
void set_slepc_solver_type()
Tells Slepc to use the user-specified solver stored in _eigen_solver_type.
Definition: slepc_eigen_solver.C:663
libMesh::SlepcEigenSolver::_solve_standard_helper
std::pair< unsigned int, unsigned int > _solve_standard_helper(Mat mat, Mat precond, int nev, int ncv, const double tol, const unsigned int m_its)
Helper function that actually performs the standard eigensolve.
Definition: slepc_eigen_solver.C:186
libMesh::SparseMatrix
Generic sparse matrix.
Definition: vector_fe_ex5.C:45
libMesh::NumericVector
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
Definition: vector_fe_ex5.C:43
libMesh::SlepcEigenSolver::solve_standard
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
This function calls the SLEPc solver to compute the eigenpairs of the SparseMatrix matrix_A.
Definition: slepc_eigen_solver.C:101
libMesh::SlepcEigenSolver::eps
EPS eps()
Definition: slepc_eigen_solver.h:235
libMesh::SlepcEigenSolver::set_initial_space
virtual void set_initial_space(NumericVector< T > &initial_space_in) override
Use initial_space_in as the initial guess.
Definition: slepc_eigen_solver.C:908
libMesh::SlepcEigenSolver
This class provides an interface to the SLEPc eigenvalue solver library from http://slepc....
Definition: slepc_eigen_solver.h:50
libMesh::SlepcEigenSolver::solve_generalized
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
This function calls the SLEPc solver to compute the eigenpairs for the generalized eigenproblem defin...
Definition: slepc_eigen_solver.C:321
libMesh::SlepcEigenSolver::_petsc_shell_matrix_mult
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's matrix multiplicat...
Definition: slepc_eigen_solver.C:933
libMesh::EigenSolver
This class provides an interface to solvers for eigenvalue problems.
Definition: eigen_solver.h:67
libMesh::SlepcEigenSolver::_petsc_shell_matrix_get_diagonal
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's get_diagonal funct...
Definition: slepc_eigen_solver.C:958
libMesh::SlepcEigenSolver::get_eigenpair
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i, NumericVector< T > &solution_in) override
Definition: slepc_eigen_solver.C:807
libMesh::SlepcEigenSolver::set_slepc_position_of_spectrum
void set_slepc_position_of_spectrum()
Tells Slepc to compute the spectrum at the position stored in _position_of_spectrum.
Definition: slepc_eigen_solver.C:725
libMesh::SlepcEigenSolver::get_relative_error
Real get_relative_error(unsigned int i)
Definition: slepc_eigen_solver.C:866
libMesh::SlepcEigenSolver::attach_deflation_space
virtual void attach_deflation_space(NumericVector< T > &deflation_vector) override
Attach a deflation space defined by a single vector.
Definition: slepc_eigen_solver.C:883
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::SlepcEigenSolver::clear
virtual void clear() override
Release all memory and clear data structures.
Definition: slepc_eigen_solver.C:59
libMesh::SlepcEigenSolver::set_slepc_problem_type
void set_slepc_problem_type()
Tells Slepc to deal with the type of problem stored in _eigen_problem_type.
Definition: slepc_eigen_solver.C:695
libMesh::SlepcEigenSolver::SlepcEigenSolver
SlepcEigenSolver(const Parallel::Communicator &comm_in)
Constructor.
Definition: slepc_eigen_solver.C:41
libMesh::SlepcEigenSolver::init
virtual void init() override
Initialize data structures if not done so already.
Definition: slepc_eigen_solver.C:78
libMesh::SlepcEigenSolver::_eps
EPS _eps
Eigenproblem solver context.
Definition: slepc_eigen_solver.h:295