libMesh
eigen_system.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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 
32 namespace libMesh
33 {
34 
35 // Forward Declarations
36 template <typename T> class SparseMatrix;
37 template <typename T> class ShellMatrix;
38 
39 
55 class EigenSystem : public System
56 {
57 public:
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;
74  EigenSystem & operator= (EigenSystem &&) = delete;
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 
161  bool use_shell_matrices() const { return _use_shell_matrices; }
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 
232  const ShellMatrix<Number> & get_shell_matrix_A() const;
233 
241 
248  const ShellMatrix<Number> & get_shell_matrix_B() const;
249 
257 
262 
267 
271  const EigenSolver<Number> & get_eigen_solver() const;
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 
365 protected:
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 
392 private:
393 
398 
402  unsigned int _n_iterations;
403 
408 
413 
418 };
419 
420 } // namespace libMesh
421 
422 #endif // LIBMESH_HAVE_SLEPC
423 
424 #endif // LIBMESH_EIGEN_SYSTEM_H
virtual void reinit() override
Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be use...
Definition: eigen_system.C:182
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i)
Definition: eigen_system.C:286
void use_shell_matrices(bool use_shell_matrices)
Set a flag to use shell matrices.
Definition: eigen_system.h:166
bool generalized() const
Definition: eigen_system.C:303
const SparseMatrix< Number > & get_precond_matrix() const
Definition: eigen_system.C:349
This is the EquationSystems class.
EigenSystem sys_type
The type of system.
Definition: eigen_system.h:80
SparseMatrix< Number > * matrix_B
A second system matrix for generalized eigenvalue problems.
Definition: eigen_system.h:321
unsigned int _n_converged_eigenpairs
The number of converged eigenpairs.
Definition: eigen_system.h:397
const SparseMatrix< Number > & get_matrix_A() const
Definition: eigen_system.C:311
sys_type & system()
Definition: eigen_system.h:90
std::unique_ptr< ShellMatrix< Number > > shell_precond_matrix
A preconditioning shell matrix.
Definition: eigen_system.h:353
const SparseMatrix< Number > & get_matrix_B() const
Definition: eigen_system.C:329
bool has_matrix_A() const
Definition: eigen_system.C:421
bool has_shell_matrix_A() const
Definition: eigen_system.C:442
EigenProblemType
Defines an enum for eigenproblem types.
virtual void init_matrices() override
Initializes the matrices associated with the system.
Definition: eigen_system.C:158
bool use_shell_precond_matrix() const
Definition: eigen_system.h:171
virtual std::string system_type() const override
Definition: eigen_system.h:125
EigenSystem & operator=(const EigenSystem &)=delete
void set_initial_space(NumericVector< Number > &initial_space_in)
Sets an initial eigen vector.
Definition: eigen_system.C:297
The libMesh namespace provides an interface to certain functionality in the library.
const EigenSolver< Number > & get_eigen_solver() const
Definition: eigen_system.C:460
const ShellMatrix< Number > & get_shell_matrix_A() const
Definition: eigen_system.C:369
System Parent
The type of the parent.
Definition: eigen_system.h:85
unsigned int _n_iterations
The number of iterations of the eigen solver algorithm.
Definition: eigen_system.h:402
std::unique_ptr< ShellMatrix< Number > > shell_matrix_A
The system shell matrix for standard eigenvalue problems.
Definition: eigen_system.h:329
SparseMatrix< Number > * precond_matrix
A preconditioning matrix.
Definition: eigen_system.h:345
void use_shell_precond_matrix(bool use_shell_precond_matrix)
Set a flag to use a shell preconditioning matrix.
Definition: eigen_system.h:176
bool use_shell_matrices() const
Definition: eigen_system.h:161
void set_n_iterations(unsigned int its)
Set the _n_iterations member, useful for subclasses of EigenSystem.
Definition: eigen_system.h:388
bool has_matrix_B() const
Definition: eigen_system.C:428
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
bool has_precond_matrix() const
Definition: eigen_system.C:435
EigenProblemType get_eigenproblem_type() const
Definition: eigen_system.h:145
bool _use_shell_precond_matrix
A boolean flag to indicate whether or not to use a shell preconditioning matrix.
Definition: eigen_system.h:417
std::unique_ptr< ShellMatrix< Number > > shell_matrix_B
A second system shell matrix for generalized eigenvalue problems.
Definition: eigen_system.h:337
SparseMatrix< Number > * matrix_A
The system matrix for standard eigenvalue problems.
Definition: eigen_system.h:313
bool has_shell_matrix_B() const
Definition: eigen_system.C:448
void set_n_converged(unsigned int nconv)
Set the _n_converged_eigenpairs member, useful for subclasses of EigenSystem.
Definition: eigen_system.h:381
const ShellMatrix< Number > & get_shell_precond_matrix() const
Definition: eigen_system.C:403
bool has_shell_precond_matrix() const
Definition: eigen_system.C:454
virtual std::pair< Real, Real > get_eigenvalue(dof_id_type i)
Definition: eigen_system.C:292
virtual void solve() override
Assembles & solves the eigen system.
Definition: eigen_system.C:209
EigenSystem(EquationSystems &es, const std::string &name_in, const unsigned int number_in)
Constructor.
Definition: eigen_system.C:39
bool _use_shell_matrices
A boolean flag to indicate whether or not to use shell matrices.
Definition: eigen_system.h:412
std::unique_ptr< EigenSolver< Number > > eigen_solver
The EigenSolver, defining which interface, i.e solver package to use.
Definition: eigen_system.h:362
const ShellMatrix< Number > & get_shell_matrix_B() const
Definition: eigen_system.C:385
virtual void add_matrices() override
Adds the necessary matrices and shell matrices.
Definition: eigen_system.C:126
EigenProblemType _eigen_problem_type
The type of the eigenvalue problem.
Definition: eigen_system.h:407
void set_eigenproblem_type(EigenProblemType ept)
Sets the type of the current eigen problem.
Definition: eigen_system.C:85
unsigned int get_n_converged() const
Definition: eigen_system.h:130
virtual void clear() override
Clear all the data structures associated with the system.
Definition: eigen_system.C:62
Manages consistently variables, degrees of freedom, and coefficient vectors for eigenvalue problems...
Definition: eigen_system.h:55
uint8_t dof_id_type
Definition: id_types.h:67
unsigned int get_n_iterations() const
Definition: eigen_system.h:135
This class provides an interface to solvers for eigenvalue problems.
Definition: eigen_solver.h:58