libMesh
eigen_solver.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 // C++ includes
35 #include <memory>
36 
37 namespace libMesh
38 {
39 
40 // forward declarations
41 template <typename T> class SparseMatrix;
42 template <typename T> class ShellMatrix;
43 template <typename T> class NumericVector;
44 class SolverConfiguration;
45 enum EigenSolverType : int;
46 enum EigenProblemType : int;
47 enum PositionOfSpectrum : int;
48 
57 template <typename T>
58 class EigenSolver : public ReferenceCountedObject<EigenSolver<T>>,
59  public ParallelObject
60 {
61 public:
62 
66  EigenSolver (const Parallel::Communicator & comm_in);
67 
71  virtual ~EigenSolver ();
72 
77  static std::unique_ptr<EigenSolver<T>> build(const Parallel::Communicator & comm_in,
78  const SolverPackage solver_package = SLEPC_SOLVERS);
79 
84  bool initialized () const { return _is_initialized; }
85 
92  {
93  libmesh_experimental();
95  }
96 
102  {
103  libmesh_experimental();
105  }
106 
110  virtual void clear () {}
111 
115  virtual void init () = 0;
116 
121 
126 
131  { return _position_of_spectrum;}
132 
137  { _eigen_solver_type = est; }
138 
143  {_eigen_problem_type = ept;}
144 
149  {_position_of_spectrum= pos;}
150 
151  void set_position_of_spectrum (Real pos);
153 
160  virtual std::pair<unsigned int, unsigned int> solve_standard (SparseMatrix<T> & matrix_A,
161  int nev,
162  int ncv,
163  const double tol,
164  const unsigned int m_its) = 0;
165 
172  virtual std::pair<unsigned int, unsigned int> solve_standard (ShellMatrix<T> & matrix_A,
173  int nev,
174  int ncv,
175  const double tol,
176  const unsigned int m_its) = 0;
177 
185  virtual std::pair<unsigned int, unsigned int> solve_standard (ShellMatrix<T> & matrix_A,
186  SparseMatrix<T> & precond,
187  int nev,
188  int ncv,
189  const double tol,
190  const unsigned int m_its) = 0;
191 
199  virtual std::pair<unsigned int, unsigned int> solve_standard (ShellMatrix<T> & matrix_A,
200  ShellMatrix<T> & precond,
201  int nev,
202  int ncv,
203  const double tol,
204  const unsigned int m_its) = 0;
205 
213  virtual std::pair<unsigned int, unsigned int> solve_generalized (SparseMatrix<T> & matrix_A,
214  SparseMatrix<T> & matrix_B,
215  int nev,
216  int ncv,
217  const double tol,
218  const unsigned int m_its) = 0;
219 
227  virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> & matrix_A,
228  SparseMatrix<T> & matrix_B,
229  int nev,
230  int ncv,
231  const double tol,
232  const unsigned int m_its) = 0;
233 
241  virtual std::pair<unsigned int, unsigned int> solve_generalized (SparseMatrix<T> & matrix_A,
242  ShellMatrix<T> & matrix_B,
243  int nev,
244  int ncv,
245  const double tol,
246  const unsigned int m_its) = 0;
247 
255  virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> & matrix_A,
256  ShellMatrix<T> & matrix_B,
257  int nev,
258  int ncv,
259  const double tol,
260  const unsigned int m_its) = 0;
261 
269  virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> & matrix_A,
270  ShellMatrix<T> & matrix_B,
271  SparseMatrix<T> & precond,
272  int nev,
273  int ncv,
274  const double tol,
275  const unsigned int m_its) = 0;
276 
284  virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> & matrix_A,
285  ShellMatrix<T> & matrix_B,
286  ShellMatrix<T> & precond,
287  int nev,
288  int ncv,
289  const double tol,
290  const unsigned int m_its) = 0;
291 
292 
297  virtual std::pair<Real, Real> get_eigenpair (dof_id_type i,
298  NumericVector<T> & solution) = 0;
299 
305  virtual std::pair<Real, Real> get_eigenvalue (dof_id_type i) = 0;
306 
310  virtual void attach_deflation_space(NumericVector<T> & deflation_vector) = 0;
311 
315  virtual void set_initial_space(NumericVector<T> & initial_space_in) = 0;
316 
320  void set_solver_configuration(SolverConfiguration & solver_configuration);
321 
322 protected:
323 
328 
333 
338 
343 
349 
351 
353 };
354 
355 } // namespace libMesh
356 
357 #endif // LIBMESH_HAVE_SLEPC
358 
359 #endif // LIBMESH_EIGEN_SOLVER_H
void set_eigensolver_type(const EigenSolverType est)
Sets the type of eigensolver to use.
Definition: eigen_solver.h:136
SolverConfiguration * _solver_configuration
Optionally store a SolverOptions object that can be used to set parameters like solver type...
Definition: eigen_solver.h:348
virtual void set_initial_space(NumericVector< T > &initial_space_in)=0
Provide one basis vector for the initial guess.
bool _is_initialized
Flag indicating if the data structures have been initialized.
Definition: eigen_solver.h:342
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: vector_fe_ex5.C:44
EigenProblemType
Defines an enum for eigenproblem types.
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i, NumericVector< T > &solution)=0
The libMesh namespace provides an interface to certain functionality in the library.
virtual void attach_deflation_space(NumericVector< T > &deflation_vector)=0
Attach a deflation space defined by a single vector.
PositionOfSpectrum _position_of_spectrum
Enum stating where to evaluate the spectrum.
Definition: eigen_solver.h:337
Generic sparse matrix.
Definition: vector_fe_ex5.C:46
bool initialized() const
Definition: eigen_solver.h:84
PositionOfSpectrum position_of_spectrum() const
Definition: eigen_solver.h:130
EigenProblemType eigen_problem_type() const
Definition: eigen_solver.h:125
virtual std::pair< Real, Real > get_eigenvalue(dof_id_type i)=0
This class stores solver configuration data, e.g.
PositionOfSpectrum
Defines an enum for the position of the spectrum, i.e.
EigenSolver(const Parallel::Communicator &comm_in)
Constructor.
Definition: eigen_solver.C:38
void set_eigenproblem_type(EigenProblemType ept)
Sets the type of the eigenproblem.
Definition: eigen_solver.h:142
This class implements reference counting.
An object whose state is distributed along a set of processors.
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.
virtual ~EigenSolver()
Destructor.
bool get_close_matrix_before_solve() const
Definition: eigen_solver.h:91
virtual void init()=0
Initialize data structures if not done so already.
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:58
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void set_position_of_spectrum(PositionOfSpectrum pos)
Sets the position of the spectrum.
Definition: eigen_solver.h:148
EigenSolverType
Defines an enum for iterative eigenproblem solver types.
EigenSolverType _eigen_solver_type
Enum stating which type of eigensolver to use.
Definition: eigen_solver.h:327
SolverPackage
Defines an enum for various linear solver packages.
EigenProblemType _eigen_problem_type
Enum stating which type of eigen problem we deal with.
Definition: eigen_solver.h:332
void set_solver_configuration(SolverConfiguration &solver_configuration)
Set the solver configuration object.
Definition: eigen_solver.C:79
Generic shell matrix, i.e.
EigenSolverType eigen_solver_type() const
Definition: eigen_solver.h:120
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:101
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.
virtual void clear()
Release all memory and clear data structures.
Definition: eigen_solver.h:110
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
uint8_t dof_id_type
Definition: id_types.h:67
This class provides an interface to solvers for eigenvalue problems.
Definition: eigen_solver.h:58