libMesh
Loading...
Searching...
No Matches
eigen_system.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#ifndef LIBMESH_EIGEN_SYSTEM_H
20#define LIBMESH_EIGEN_SYSTEM_H
21
22#include "libmesh/libmesh_config.h"
23
24// Currently, the EigenSystem should only be available
25// if SLEPc support is enabled.
26#if defined(LIBMESH_HAVE_SLEPC)
27
28// Local Includes
29#include "libmesh/system.h"
30#include "libmesh/eigen_solver.h"
31
32namespace libMesh
33{
34
35// Forward Declarations
36template <typename T> class SparseMatrix;
37template <typename T> class ShellMatrix;
38
39
55class EigenSystem : public System
56{
57public:
58
63 const std::string & name_in,
64 const unsigned int number_in);
65
71 EigenSystem (const EigenSystem &) = delete;
72 EigenSystem & operator= (const EigenSystem &) = delete;
73 EigenSystem (EigenSystem &&) = default;
75 virtual ~EigenSystem ();
76
81
85 typedef System Parent;
86
90 sys_type & system () { return *this; }
91
96 virtual void clear () override;
97
102 virtual void reinit () override;
103
107 virtual void solve () override;
108
113 virtual std::pair<Real, Real> get_eigenpair (dof_id_type i);
114
119 virtual std::pair<Real, Real> get_eigenvalue (dof_id_type i);
120
125 virtual std::string system_type () const override { return "Eigen"; }
126
130 unsigned int get_n_converged () const {return _n_converged_eigenpairs;}
131
135 unsigned int get_n_iterations () const {return _n_iterations;}
136
141
146
150 void set_initial_space(NumericVector<Number> & initial_space_in);
151
156 bool generalized () const;
157
162
167
172
177
184 const SparseMatrix<Number> & get_matrix_A() const;
185
193
200 const SparseMatrix<Number> & get_matrix_B() const;
201
209
217
225
233
241
249
257
262
267
276
280 bool has_matrix_A() const;
281
285 bool has_matrix_B() const;
286
290 bool has_precond_matrix() const;
291
295 bool has_shell_matrix_A() const;
296
300 bool has_shell_matrix_B() const;
301
305 bool has_shell_precond_matrix() const;
306
314
322
329 std::unique_ptr<ShellMatrix<Number>> shell_matrix_A;
330
337 std::unique_ptr<ShellMatrix<Number>> shell_matrix_B;
338
346
353 std::unique_ptr<ShellMatrix<Number>> shell_precond_matrix;
354
362 std::unique_ptr<EigenSolver<Number>> eigen_solver;
363
364
365protected:
366
370 virtual void add_matrices () override;
371
375 virtual void init_matrices () override;
376
381 void set_n_converged (unsigned int nconv)
382 { _n_converged_eigenpairs = nconv; }
383
388 void set_n_iterations (unsigned int its)
389 { _n_iterations = its;}
390
391 void solve_helper(SparseMatrix<Number> * const A,
392 SparseMatrix<Number> * const B,
393 SparseMatrix<Number> * const P);
394
395private:
400
404 unsigned int _n_iterations;
405
410
415
420};
421
422} // namespace libMesh
423
424#endif // LIBMESH_HAVE_SLEPC
425
426#endif // LIBMESH_EIGEN_SYSTEM_H
This class provides an interface to solvers for eigenvalue problems.
Manages consistently variables, degrees of freedom, and coefficient vectors for eigenvalue problems.
SparseMatrix< Number > * matrix_A
The system matrix for standard eigenvalue problems.
void set_initial_space(NumericVector< Number > &initial_space_in)
Sets an initial eigen vector.
virtual std::pair< Real, Real > get_eigenvalue(dof_id_type i)
bool _use_shell_matrices
A boolean flag to indicate whether or not to use shell matrices.
virtual std::string system_type() const override
void set_eigenproblem_type(EigenProblemType ept)
Sets the type of the current eigen problem.
unsigned int _n_converged_eigenpairs
The number of converged eigenpairs.
EigenSystem(EigenSystem &&)=default
EigenProblemType _eigen_problem_type
The type of the eigenvalue problem.
SparseMatrix< Number > * matrix_B
A second system matrix for generalized eigenvalue problems.
bool use_shell_matrices() const
virtual void clear() override
Clear all the data structures associated with the system.
bool has_precond_matrix() const
bool has_matrix_A() const
std::unique_ptr< ShellMatrix< Number > > shell_matrix_A
The system shell matrix for standard eigenvalue problems.
unsigned int _n_iterations
The number of iterations of the eigen solver algorithm.
bool _use_shell_precond_matrix
A boolean flag to indicate whether or not to use a shell preconditioning matrix.
const SparseMatrix< Number > & get_matrix_B() const
void set_n_converged(unsigned int nconv)
Set the _n_converged_eigenpairs member, useful for subclasses of EigenSystem.
virtual void solve() override
Assembles & solves the eigen system.
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i)
bool generalized() const
const SparseMatrix< Number > & get_precond_matrix() const
std::unique_ptr< ShellMatrix< Number > > shell_precond_matrix
A preconditioning shell matrix.
const ShellMatrix< Number > & get_shell_matrix_A() const
unsigned int get_n_converged() const
const ShellMatrix< Number > & get_shell_precond_matrix() const
SparseMatrix< Number > * precond_matrix
A preconditioning matrix.
void use_shell_matrices(bool use_shell_matrices)
Set a flag to use shell matrices.
bool has_matrix_B() const
EigenProblemType get_eigenproblem_type() const
bool has_shell_precond_matrix() const
bool use_shell_precond_matrix() const
virtual void init_matrices() override
Initializes the matrices associated with the system.
EigenSystem & operator=(const EigenSystem &)=delete
void solve_helper(SparseMatrix< Number > *const A, SparseMatrix< Number > *const B, SparseMatrix< Number > *const P)
sys_type & system()
unsigned int get_n_iterations() const
const ShellMatrix< Number > & get_shell_matrix_B() const
System Parent
The type of the parent.
EigenSystem sys_type
The type of system.
const SparseMatrix< Number > & get_matrix_A() const
std::unique_ptr< EigenSolver< Number > > eigen_solver
The EigenSolver, defining which interface, i.e solver package to use.
bool has_shell_matrix_A() const
const EigenSolver< Number > & get_eigen_solver() const
void use_shell_precond_matrix(bool use_shell_precond_matrix)
Set a flag to use a shell preconditioning matrix.
virtual void reinit() override
Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be use...
EigenSystem(const EigenSystem &)=delete
Special functions.
virtual void add_matrices() override
Adds the necessary matrices and shell matrices.
void set_n_iterations(unsigned int its)
Set the _n_iterations member, useful for subclasses of EigenSystem.
bool has_shell_matrix_B() const
std::unique_ptr< ShellMatrix< Number > > shell_matrix_B
A second system shell matrix for generalized eigenvalue problems.
This is the EquationSystems class.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
Generic shell matrix, i.e.
Generic sparse matrix.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
The libMesh namespace provides an interface to certain functionality in the library.
uint8_t dof_id_type
Definition id_types.h:67
EigenProblemType
Defines an enum for eigenproblem types.
Definition assembly.h:39