libMesh
eigen_system.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 #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 
64  const std::string & name_in,
65  const unsigned int number_in);
66 
70  virtual ~EigenSystem ();
71 
76 
80  typedef System Parent;
81 
85  sys_type & system () { return *this; }
86 
91  virtual void clear () override;
92 
97  virtual void reinit () override;
98 
102  virtual void solve () override;
103 
107  virtual void assemble () override;
108 
113  virtual std::pair<Real, Real> get_eigenpair (dof_id_type i);
114 
119  virtual std::string system_type () const override { return "Eigen"; }
120 
124  virtual unsigned int n_matrices () const override;
125 
129  unsigned int get_n_converged () const {return _n_converged_eigenpairs;}
130 
134  unsigned int get_n_iterations () const {return _n_iterations;}
135 
140 
145 
150  bool generalized () const { return _is_generalized_eigenproblem; }
151 
155  bool use_shell_matrices() const { return _use_shell_matrices; }
156 
161 
165  std::unique_ptr<SparseMatrix<Number>> matrix_A;
166 
170  std::unique_ptr<SparseMatrix<Number>> matrix_B;
171 
175  std::unique_ptr<ShellMatrix<Number>> shell_matrix_A;
176 
180  std::unique_ptr<ShellMatrix<Number>> shell_matrix_B;
181 
185  std::unique_ptr<SparseMatrix<Number>> precond_matrix;
186 
191  std::unique_ptr<EigenSolver<Number>> eigen_solver;
192 
193 
194 protected:
195 
196 
201  virtual void init_data () override;
202 
206  virtual void init_matrices ();
207 
212  void set_n_converged (unsigned int nconv)
213  { _n_converged_eigenpairs = nconv; }
214 
219  void set_n_iterations (unsigned int its)
220  { _n_iterations = its;}
221 
222 
223 private:
224 
229 
233  unsigned int _n_iterations;
234 
240 
245 
250 };
251 
252 
253 
254 // ------------------------------------------------------------
255 // EigenSystem inline methods
256 inline
257 unsigned int EigenSystem::n_matrices () const
258 {
260  return 2;
261 
262  return 1;
263 }
264 
265 } // namespace libMesh
266 
267 #endif // LIBMESH_HAVE_SLEPC
268 
269 #endif // LIBMESH_EIGEN_SYSTEM_H
libMesh::System
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:100
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::EigenSystem::set_n_converged
void set_n_converged(unsigned int nconv)
Set the _n_converged_eigenpairs member, useful for subclasses of EigenSystem.
Definition: eigen_system.h:212
libMesh::EigenSystem::matrix_A
std::unique_ptr< SparseMatrix< Number > > matrix_A
The system matrix for standard eigenvalue problems.
Definition: eigen_system.h:165
libMesh::EigenSystem::_is_generalized_eigenproblem
bool _is_generalized_eigenproblem
A boolean flag to indicate whether we are dealing with a generalized eigenvalue problem.
Definition: eigen_system.h:239
libMesh::EigenSystem::shell_matrix_B
std::unique_ptr< ShellMatrix< Number > > shell_matrix_B
A second system shell matrix for generalized eigenvalue problems.
Definition: eigen_system.h:180
libMesh::EigenProblemType
EigenProblemType
Defines an enum for eigenproblem types.
Definition: enum_eigen_solver_type.h:54
libMesh::EigenSystem::init_matrices
virtual void init_matrices()
Initializes the matrices associated with the system.
Definition: eigen_system.C:139
libMesh::EigenSystem::get_eigenproblem_type
EigenProblemType get_eigenproblem_type() const
Definition: eigen_system.h:144
libMesh::EigenSystem::~EigenSystem
virtual ~EigenSystem()
Destructor.
Definition: eigen_system.C:57
libMesh::EigenSystem::solve
virtual void solve() override
Assembles & solves the eigen system.
Definition: eigen_system.C:259
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::EigenSystem::EigenSystem
EigenSystem(EquationSystems &es, const std::string &name_in, const unsigned int number_in)
Constructor.
Definition: eigen_system.C:41
libMesh::EigenSystem::eigen_solver
std::unique_ptr< EigenSolver< Number > > eigen_solver
The EigenSolver, defining which interface, i.e solver package to use.
Definition: eigen_system.h:191
libMesh::EigenSystem::set_eigenproblem_type
void set_eigenproblem_type(EigenProblemType ept)
Sets the type of the current eigen problem.
Definition: eigen_system.C:84
libMesh::EigenSystem::clear
virtual void clear() override
Clear all the data structures associated with the system.
Definition: eigen_system.C:65
libMesh::EigenSystem::_eigen_problem_type
EigenProblemType _eigen_problem_type
The type of the eigenvalue problem.
Definition: eigen_system.h:244
libMesh::EigenSystem::_use_shell_matrices
bool _use_shell_matrices
A boolean flag to indicate whether or not to use shell matrices.
Definition: eigen_system.h:249
libMesh::EigenSystem::precond_matrix
std::unique_ptr< SparseMatrix< Number > > precond_matrix
A preconditioning matrix.
Definition: eigen_system.h:185
libMesh::EigenSystem::get_n_converged
unsigned int get_n_converged() const
Definition: eigen_system.h:129
libMesh::EigenSystem::matrix_B
std::unique_ptr< SparseMatrix< Number > > matrix_B
A second system matrix for generalized eigenvalue problems.
Definition: eigen_system.h:170
libMesh::EigenSystem::generalized
bool generalized() const
Definition: eigen_system.h:150
libMesh::EigenSystem::get_n_iterations
unsigned int get_n_iterations() const
Definition: eigen_system.h:134
libMesh::EigenSystem::init_data
virtual void init_data() override
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used.
Definition: eigen_system.C:123
libMesh::EigenSystem::use_shell_matrices
void use_shell_matrices(bool use_shell_matrices)
Set a flag to use shell matrices.
Definition: eigen_system.h:160
libMesh::EigenSystem::get_eigenpair
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i)
Definition: eigen_system.C:333
libMesh::EigenSystem::sys_type
EigenSystem sys_type
The type of system.
Definition: eigen_system.h:75
libMesh::EigenSystem::reinit
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:202
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::EigenSystem
Manages consistently variables, degrees of freedom, and coefficient vectors for eigenvalue problems.
Definition: eigen_system.h:55
libMesh::EigenSystem::_n_converged_eigenpairs
unsigned int _n_converged_eigenpairs
The number of converged eigenpairs.
Definition: eigen_system.h:228
libMesh::EigenSystem::system
sys_type & system()
Definition: eigen_system.h:85
libMesh::EigenSystem::shell_matrix_A
std::unique_ptr< ShellMatrix< Number > > shell_matrix_A
The system shell matrix for standard eigenvalue problems.
Definition: eigen_system.h:175
libMesh::EigenSystem::_n_iterations
unsigned int _n_iterations
The number of iterations of the eigen solver algorithm.
Definition: eigen_system.h:233
libMesh::EigenSystem::n_matrices
virtual unsigned int n_matrices() const override
Definition: eigen_system.h:257
libMesh::EigenSystem::system_type
virtual std::string system_type() const override
Definition: eigen_system.h:119
libMesh::EigenSystem::set_n_iterations
void set_n_iterations(unsigned int its)
Set the _n_iterations member, useful for subclasses of EigenSystem.
Definition: eigen_system.h:219
libMesh::EigenSystem::use_shell_matrices
bool use_shell_matrices() const
Definition: eigen_system.h:155
libMesh::EigenSystem::Parent
System Parent
The type of the parent.
Definition: eigen_system.h:80
libMesh::EigenSystem::assemble
virtual void assemble() override
Assembles the system matrix.
Definition: eigen_system.C:324