libMesh
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_EIGEN_SOLVER_H
21 #define LIBMESH_EIGEN_SOLVER_H
22 
23 
24 #include "libmesh/libmesh_config.h"
25 #ifdef LIBMESH_HAVE_SLEPC
26 
27 // Local includes
28 #include "libmesh/libmesh_common.h"
29 #include "libmesh/reference_counted_object.h"
30 #include "libmesh/libmesh.h"
31 #include "libmesh/parallel_object.h"
32 #include "libmesh/enum_solver_package.h" // SLEPC_SOLVERS
33 
34 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
35 namespace libMesh
36 {
37 enum EigenSolverType : int;
38 enum EigenProblemType : int;
39 enum PositionOfSpectrum : int;
40 }
41 #else
42 #include "libmesh/enum_solver_package.h"
43 #include "libmesh/enum_eigen_solver_type.h"
44 #endif
45 
46 // C++ includes
47 #include <memory>
48 
49 namespace libMesh
50 {
51 
52 // forward declarations
53 template <typename T> class SparseMatrix;
54 template <typename T> class ShellMatrix;
55 template <typename T> class NumericVector;
56 class SolverConfiguration;
57 
66 template <typename T>
67 class EigenSolver : public ReferenceCountedObject<EigenSolver<T>>,
68  public ParallelObject
69 {
70 public:
71 
75  EigenSolver (const Parallel::Communicator & comm_in);
76 
80  virtual ~EigenSolver ();
81 
86  static std::unique_ptr<EigenSolver<T>> build(const Parallel::Communicator & comm_in,
87  const SolverPackage solver_package = SLEPC_SOLVERS);
88 
93  bool initialized () const { return _is_initialized; }
94 
101  {
102  libmesh_experimental();
104  }
105 
111  {
112  libmesh_experimental();
114  }
115 
119  virtual void clear () {}
120 
124  virtual void init () = 0;
125 
130 
135 
140  { return _position_of_spectrum;}
141 
146  { _eigen_solver_type = est; }
147 
152  {_eigen_problem_type = ept;}
153 
158  {_position_of_spectrum= pos;}
159 
160  void set_position_of_spectrum (Real pos);
162 
169  virtual std::pair<unsigned int, unsigned int> solve_standard (SparseMatrix<T> & matrix_A,
170  int nev,
171  int ncv,
172  const double tol,
173  const unsigned int m_its) = 0;
174 
181  virtual std::pair<unsigned int, unsigned int> solve_standard (ShellMatrix<T> & matrix_A,
182  int nev,
183  int ncv,
184  const double tol,
185  const unsigned int m_its) = 0;
186 
194  virtual std::pair<unsigned int, unsigned int> solve_standard (ShellMatrix<T> & matrix_A,
195  SparseMatrix<T> & precond,
196  int nev,
197  int ncv,
198  const double tol,
199  const unsigned int m_its) = 0;
200 
201 
209  virtual std::pair<unsigned int, unsigned int> solve_generalized (SparseMatrix<T> & matrix_A,
210  SparseMatrix<T> & matrix_B,
211  int nev,
212  int ncv,
213  const double tol,
214  const unsigned int m_its) = 0;
215 
223  virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> & matrix_A,
224  SparseMatrix<T> & matrix_B,
225  int nev,
226  int ncv,
227  const double tol,
228  const unsigned int m_its) = 0;
229 
237  virtual std::pair<unsigned int, unsigned int> solve_generalized (SparseMatrix<T> & matrix_A,
238  ShellMatrix<T> & matrix_B,
239  int nev,
240  int ncv,
241  const double tol,
242  const unsigned int m_its) = 0;
243 
251  virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> & matrix_A,
252  ShellMatrix<T> & matrix_B,
253  int nev,
254  int ncv,
255  const double tol,
256  const unsigned int m_its) = 0;
257 
265  virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> & matrix_A,
266  ShellMatrix<T> & matrix_B,
267  SparseMatrix<T> & precond,
268  int nev,
269  int ncv,
270  const double tol,
271  const unsigned int m_its) = 0;
272 
273 
278  virtual std::pair<Real, Real> get_eigenpair (dof_id_type i,
279  NumericVector<T> & solution) = 0;
280 
286  virtual std::pair<Real, Real> get_eigenvalue (dof_id_type i) = 0;
287 
291  virtual void attach_deflation_space(NumericVector<T> & deflation_vector) = 0;
292 
296  virtual void set_initial_space(NumericVector<T> & initial_space_in) = 0;
297 
301  void set_solver_configuration(SolverConfiguration & solver_configuration);
302 
303 protected:
304 
309 
314 
319 
324 
330 
332 
334 };
335 
336 } // namespace libMesh
337 
338 #endif // LIBMESH_HAVE_SLEPC
339 
340 #endif // LIBMESH_EIGEN_SOLVER_H
libMesh::EigenSolver::initialized
bool initialized() const
Definition: eigen_solver.h:93
libMesh::EigenSolver::attach_deflation_space
virtual void attach_deflation_space(NumericVector< T > &deflation_vector)=0
Attach a deflation space defined by a single vector.
libMesh::ShellMatrix
Generic shell matrix, i.e.
Definition: eigen_preconditioner.h:36
libMesh::EigenSolver::get_eigenpair
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i, NumericVector< T > &solution)=0
libMesh::SolverPackage
SolverPackage
Defines an enum for various linear solver packages.
Definition: enum_solver_package.h:34
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::EigenSolver::eigen_solver_type
EigenSolverType eigen_solver_type() const
Definition: eigen_solver.h:129
libMesh::EigenSolver::eigen_problem_type
EigenProblemType eigen_problem_type() const
Definition: eigen_solver.h:134
libMesh::EigenProblemType
EigenProblemType
Defines an enum for eigenproblem types.
Definition: enum_eigen_solver_type.h:54
libMesh::EigenSolver::set_eigenproblem_type
void set_eigenproblem_type(EigenProblemType ept)
Sets the type of the eigenproblem.
Definition: eigen_solver.h:151
libMesh::ReferenceCountedObject
This class implements reference counting.
Definition: reference_counted_object.h:65
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::EigenSolver::get_close_matrix_before_solve
bool get_close_matrix_before_solve() const
Definition: eigen_solver.h:100
libMesh::EigenSolver::_solver_configuration
SolverConfiguration * _solver_configuration
Optionally store a SolverOptions object that can be used to set parameters like solver type,...
Definition: eigen_solver.h:329
libMesh::EigenSolver::set_eigensolver_type
void set_eigensolver_type(const EigenSolverType est)
Sets the type of eigensolver to use.
Definition: eigen_solver.h:145
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::EigenSolver::EigenSolver
EigenSolver(const Parallel::Communicator &comm_in)
Constructor.
Definition: eigen_solver.C:36
libMesh::EigenSolver::_position_of_spectrum
PositionOfSpectrum _position_of_spectrum
Enum stating where to evaluate the spectrum.
Definition: eigen_solver.h:318
libMesh::EigenSolver::get_eigenvalue
virtual std::pair< Real, Real > get_eigenvalue(dof_id_type i)=0
libMesh::EigenSolver::_is_initialized
bool _is_initialized
Flag indicating if the data structures have been initialized.
Definition: eigen_solver.h:323
libMesh::EigenSolver::set_close_matrix_before_solve
void set_close_matrix_before_solve(bool val)
Set the flag which controls whether libmesh closes the eigenproblem matrices before solving.
Definition: eigen_solver.h:110
libMesh::EigenSolver::set_solver_configuration
void set_solver_configuration(SolverConfiguration &solver_configuration)
Set the solver configuration object.
Definition: eigen_solver.C:80
libMesh::EigenSolver::init
virtual void init()=0
Initialize data structures if not done so already.
libMesh::EigenSolverType
EigenSolverType
Defines an enum for iterative eigenproblem solver types.
Definition: enum_eigen_solver_type.h:33
libMesh::EigenSolver::~EigenSolver
virtual ~EigenSolver()
Destructor.
Definition: eigen_solver.C:50
libMesh::EigenSolver::set_position_of_spectrum
void set_position_of_spectrum(PositionOfSpectrum pos)
Sets the position of the spectrum.
Definition: eigen_solver.h:157
libMesh::EigenSolver::_eigen_problem_type
EigenProblemType _eigen_problem_type
Enum stating which type of eigen problem we deal with.
Definition: eigen_solver.h:313
libMesh::EigenSolver::_eigen_solver_type
EigenSolverType _eigen_solver_type
Enum stating which type of eigensolver to use.
Definition: eigen_solver.h:308
libMesh::EigenSolver::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)=0
Solves the generalized eigenproblem involving SparseMatrices matrix_A and matrix_B.
libMesh::EigenSolver::set_initial_space
virtual void set_initial_space(NumericVector< T > &initial_space_in)=0
Provide one basis vector for the initial guess.
libMesh::PositionOfSpectrum
PositionOfSpectrum
Defines an enum for the position of the spectrum, i.e.
Definition: enum_eigen_solver_type.h:74
libMesh::EigenSolver::position_of_spectrum
PositionOfSpectrum position_of_spectrum() const
Definition: eigen_solver.h:139
libMesh::EigenSolver
This class provides an interface to solvers for eigenvalue problems.
Definition: eigen_solver.h:67
libMesh::EigenSolver::clear
virtual void clear()
Release all memory and clear data structures.
Definition: eigen_solver.h:119
libMesh::SLEPC_SOLVERS
Definition: enum_solver_package.h:39
libMesh::SolverConfiguration
This class stores solver configuration data, e.g.
Definition: solver_configuration.h:39
libMesh::EigenSolver::_target_val
Real _target_val
Definition: eigen_solver.h:331
libMesh::EigenSolver::_close_matrix_before_solve
bool _close_matrix_before_solve
Definition: eigen_solver.h:333
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::EigenSolver::build
static std::unique_ptr< EigenSolver< T > > build(const Parallel::Communicator &comm_in, const SolverPackage solver_package=SLEPC_SOLVERS)
Builds an EigenSolver using the linear solver package specified by solver_package.
Definition: eigen_solver.C:59
libMesh::ParallelObject
An object whose state is distributed along a set of processors.
Definition: parallel_object.h:55
int
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
libMesh::EigenSolver::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)=0
Solves the standard eigenproblem involving the SparseMatrix matrix_A.