libMesh
Loading...
Searching...
No Matches
eigen_solver.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
37namespace libMesh
38{
39
40// forward declarations
41template <typename T> class SparseMatrix;
42template <typename T> class ShellMatrix;
43template <typename T> class NumericVector;
44class SolverConfiguration;
45enum EigenSolverType : int;
48
57template <typename T>
58class EigenSolver : public ReferenceCountedObject<EigenSolver<T>>,
59 public ParallelObject
60{
61public:
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
132
138
144
150
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
322protected:
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 ErrorVector unsigned int
This class provides an interface to solvers for eigenvalue problems.
virtual std::pair< unsigned int, unsigned int > solve_generalized(ShellMatrix< T > &matrix_A, ShellMatrix< T > &matrix_B, ShellMatrix< T > &precond, int nev, int ncv, const double tol, const unsigned int m_its)=0
Solves the generalized eigenproblem involving ShellMatrices matrix_A, matrix_B and the shell precondi...
virtual std::pair< unsigned int, unsigned int > solve_generalized(ShellMatrix< T > &matrix_A, ShellMatrix< T > &matrix_B, int nev, int ncv, const double tol, const unsigned int m_its)=0
Solves the generalized eigenproblem involving ShellMatrices matrix_A and matrix_B.
EigenProblemType eigen_problem_type() const
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.
void set_eigenproblem_type(EigenProblemType ept)
Sets the type of the eigenproblem.
virtual std::pair< unsigned int, unsigned int > solve_generalized(ShellMatrix< T > &matrix_A, SparseMatrix< T > &matrix_B, int nev, int ncv, const double tol, const unsigned int m_its)=0
Solves the generalized eigenproblem with ShellMatrix matrix_A and SparseMatrix matrix_B.
void set_position_of_spectrum(PositionOfSpectrum pos)
Sets the position of the spectrum.
virtual std::pair< unsigned int, unsigned int > solve_generalized(ShellMatrix< T > &matrix_A, ShellMatrix< T > &matrix_B, SparseMatrix< T > &precond, int nev, int ncv, const double tol, const unsigned int m_its)=0
Solves the generalized eigenproblem involving ShellMatrices matrix_A, matrix_B and the SparseMatrix p...
SolverConfiguration * _solver_configuration
Optionally store a SolverOptions object that can be used to set parameters like solver type,...
bool initialized() const
void set_eigensolver_type(const EigenSolverType est)
Sets the type of eigensolver to use.
virtual ~EigenSolver()
Destructor.
EigenSolverType _eigen_solver_type
Enum stating which type of eigensolver to use.
virtual std::pair< unsigned int, unsigned int > solve_generalized(SparseMatrix< T > &matrix_A, ShellMatrix< T > &matrix_B, int nev, int ncv, const double tol, const unsigned int m_its)=0
Solves the generalized eigenproblem with SparseMatrix matrix_A and ShellMatrix matrix_B.
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 std::pair< unsigned int, unsigned int > solve_standard(ShellMatrix< T > &matrix_A, SparseMatrix< T > &precond, int nev, int ncv, const double tol, const unsigned int m_its)=0
Solves the standard eigenproblem involving the ShellMatrix matrix_A and the preconditioning matrix pr...
bool get_close_matrix_before_solve() const
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.
PositionOfSpectrum _position_of_spectrum
Enum stating where to evaluate the spectrum.
virtual void set_initial_space(NumericVector< T > &initial_space_in)=0
Provide one basis vector for the initial guess.
virtual void clear()
Release all memory and clear data structures.
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i, NumericVector< T > &solution)=0
EigenProblemType _eigen_problem_type
Enum stating which type of eigen problem we deal with.
virtual std::pair< unsigned int, unsigned int > solve_standard(ShellMatrix< T > &matrix_A, int nev, int ncv, const double tol, const unsigned int m_its)=0
Solves the standard eigenproblem involving the ShellMatrix matrix_A.
virtual std::pair< Real, Real > get_eigenvalue(dof_id_type i)=0
bool _is_initialized
Flag indicating if the data structures have been initialized.
PositionOfSpectrum position_of_spectrum() const
virtual void init()=0
Initialize data structures if not done so already.
EigenSolverType eigen_solver_type() const
void set_close_matrix_before_solve(bool val)
Set the flag which controls whether libmesh closes the eigenproblem matrices before solving.
virtual std::pair< unsigned int, unsigned int > solve_standard(ShellMatrix< T > &matrix_A, ShellMatrix< T > &precond, int nev, int ncv, const double tol, const unsigned int m_its)=0
Solves the standard eigenproblem involving the ShellMatrix matrix_A and the shell preconditioning mat...
void set_solver_configuration(SolverConfiguration &solver_configuration)
Set the solver configuration object.
virtual void attach_deflation_space(NumericVector< T > &deflation_vector)=0
Attach a deflation space defined by a single vector.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
An object whose state is distributed along a set of processors.
This class implements reference counting.
Generic shell matrix, i.e.
This class stores solver configuration data, e.g.
Generic sparse matrix.
The libMesh namespace provides an interface to certain functionality in the library.
PositionOfSpectrum
Defines an enum for the position of the spectrum, i.e.
SolverPackage
Defines an enum for various linear solver packages.
uint8_t dof_id_type
Definition id_types.h:67
EigenProblemType
Defines an enum for eigenproblem types.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
EigenSolverType
Defines an enum for iterative eigenproblem solver types.