eigen_solver.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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"
30 #include "libmesh/libmesh.h"
32 #include "libmesh/auto_ptr.h" // deprecated
33 #include "libmesh/enum_solver_package.h" // SLEPC_SOLVERS
34 
35 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
36 namespace libMesh
37 {
38 enum EigenSolverType : int;
39 enum EigenProblemType : int;
40 enum PositionOfSpectrum : int;
41 }
42 #else
45 #endif
46 
47 // C++ includes
48 #include <memory>
49 
50 namespace libMesh
51 {
52 
53 // forward declarations
54 template <typename T> class SparseMatrix;
55 template <typename T> class ShellMatrix;
56 template <typename T> class NumericVector;
57 class SolverConfiguration;
58 
67 template <typename T>
68 class EigenSolver : public ReferenceCountedObject<EigenSolver<T>>,
69  public ParallelObject
70 {
71 public:
72 
76  EigenSolver (const Parallel::Communicator & comm_in);
77 
81  virtual ~EigenSolver ();
82 
87  static std::unique_ptr<EigenSolver<T>> build(const Parallel::Communicator & comm_in,
88  const SolverPackage solver_package = SLEPC_SOLVERS);
89 
94  bool initialized () const { return _is_initialized; }
95 
102  {
103  libmesh_experimental();
105  }
106 
112  {
113  libmesh_experimental();
115  }
116 
120  virtual void clear () {}
121 
125  virtual void init () = 0;
126 
131 
136 
141  { return _position_of_spectrum;}
142 
147  { _eigen_solver_type = est; }
148 
153  {_eigen_problem_type = ept;}
154 
159  {_position_of_spectrum= pos;}
160 
161  void set_position_of_spectrum (Real pos);
163 
170  virtual std::pair<unsigned int, unsigned int> solve_standard (SparseMatrix<T> & matrix_A,
171  int nev,
172  int ncv,
173  const double tol,
174  const unsigned int m_its) = 0;
175 
182  virtual std::pair<unsigned int, unsigned int> solve_standard (ShellMatrix<T> & matrix_A,
183  int nev,
184  int ncv,
185  const double tol,
186  const unsigned int m_its) = 0;
187 
188 
196  virtual std::pair<unsigned int, unsigned int> solve_generalized (SparseMatrix<T> & matrix_A,
197  SparseMatrix<T> & matrix_B,
198  int nev,
199  int ncv,
200  const double tol,
201  const unsigned int m_its) = 0;
202 
210  virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> & matrix_A,
211  SparseMatrix<T> & matrix_B,
212  int nev,
213  int ncv,
214  const double tol,
215  const unsigned int m_its) = 0;
216 
224  virtual std::pair<unsigned int, unsigned int> solve_generalized (SparseMatrix<T> & matrix_A,
225  ShellMatrix<T> & matrix_B,
226  int nev,
227  int ncv,
228  const double tol,
229  const unsigned int m_its) = 0;
230 
238  virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> & matrix_A,
239  ShellMatrix<T> & matrix_B,
240  int nev,
241  int ncv,
242  const double tol,
243  const unsigned int m_its) = 0;
244 
245 
250  virtual std::pair<Real, Real> get_eigenpair (dof_id_type i,
251  NumericVector<T> & solution) = 0;
252 
258  virtual std::pair<Real, Real> get_eigenvalue (dof_id_type i) = 0;
259 
263  virtual void attach_deflation_space(NumericVector<T> & deflation_vector) = 0;
264 
268  virtual void set_initial_space(NumericVector<T> & initial_space_in) = 0;
269 
273  void set_solver_configuration(SolverConfiguration & solver_configuration);
274 
275 protected:
276 
281 
286 
291 
296 
302 
304 
306 };
307 
308 } // namespace libMesh
309 
310 #endif // LIBMESH_HAVE_SLEPC
311 
312 #endif // LIBMESH_EIGEN_SOLVER_H
void set_eigensolver_type(const EigenSolverType est)
Definition: eigen_solver.h:146
SolverConfiguration * _solver_configuration
Definition: eigen_solver.h:301
virtual void set_initial_space(NumericVector< T > &initial_space_in)=0
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: diff_context.h:40
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i, NumericVector< T > &solution)=0
virtual void attach_deflation_space(NumericVector< T > &deflation_vector)=0
PositionOfSpectrum _position_of_spectrum
Definition: eigen_solver.h:290
bool initialized() const
Definition: eigen_solver.h:94
PositionOfSpectrum position_of_spectrum() const
Definition: eigen_solver.h:140
EigenProblemType eigen_problem_type() const
Definition: eigen_solver.h:135
virtual std::pair< Real, Real > get_eigenvalue(dof_id_type i)=0
EigenSolver(const Parallel::Communicator &comm_in)
Definition: eigen_solver.C:36
void set_eigenproblem_type(EigenProblemType ept)
Definition: eigen_solver.h:152
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
virtual ~EigenSolver()
Definition: eigen_solver.C:50
bool get_close_matrix_before_solve() const
Definition: eigen_solver.h:101
virtual void init()=0
static std::unique_ptr< EigenSolver< T > > build(const Parallel::Communicator &comm_in, const SolverPackage solver_package=SLEPC_SOLVERS)
Definition: eigen_solver.C:59
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void set_position_of_spectrum(PositionOfSpectrum pos)
Definition: eigen_solver.h:158
EigenSolverType _eigen_solver_type
Definition: eigen_solver.h:280
EigenProblemType _eigen_problem_type
Definition: eigen_solver.h:285
void set_solver_configuration(SolverConfiguration &solver_configuration)
Definition: eigen_solver.C:80
EigenSolverType eigen_solver_type() const
Definition: eigen_solver.h:130
void set_close_matrix_before_solve(bool val)
Definition: eigen_solver.h:111
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
virtual void clear()
Definition: eigen_solver.h:120
uint8_t dof_id_type
Definition: id_types.h:64
Base class which defines the interface for solving eigenproblems.
Definition: eigen_solver.h:68