libMesh
eigen_solver.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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/enum_solver_package.h"
30 #include "libmesh/enum_eigen_solver_type.h"
31 #include "libmesh/reference_counted_object.h"
32 #include "libmesh/libmesh.h"
33 #include "libmesh/parallel_object.h"
34 #include "libmesh/auto_ptr.h"
35 
36 namespace libMesh
37 {
38 
39 // forward declarations
40 template <typename T> class SparseMatrix;
41 template <typename T> class ShellMatrix;
42 template <typename T> class NumericVector;
43 class SolverConfiguration;
44 
53 template <typename T>
54 class EigenSolver : public ReferenceCountedObject<EigenSolver<T>>,
55  public ParallelObject
56 {
57 public:
58 
62  EigenSolver (const Parallel::Communicator & comm_in
63  LIBMESH_CAN_DEFAULT_TO_COMMWORLD);
64 
68  virtual ~EigenSolver ();
69 
75  LIBMESH_CAN_DEFAULT_TO_COMMWORLD,
76  const SolverPackage solver_package = SLEPC_SOLVERS);
77 
82  bool initialized () const { return _is_initialized; }
83 
90  {
91  libmesh_experimental();
93  }
94 
100  {
101  libmesh_experimental();
103  }
104 
108  virtual void clear () {}
109 
113  virtual void init () = 0;
114 
119 
124 
129  { return _position_of_spectrum;}
130 
135  { _eigen_solver_type = est; }
136 
141  {_eigen_problem_type = ept;}
142 
147  {_position_of_spectrum= pos;}
148 
149  void set_position_of_spectrum (Real pos);
151 
158  virtual std::pair<unsigned int, unsigned int> solve_standard (SparseMatrix<T> & matrix_A,
159  int nev,
160  int ncv,
161  const double tol,
162  const unsigned int m_its) = 0;
163 
170  virtual std::pair<unsigned int, unsigned int> solve_standard (ShellMatrix<T> & matrix_A,
171  int nev,
172  int ncv,
173  const double tol,
174  const unsigned int m_its) = 0;
175 
176 
184  virtual std::pair<unsigned int, unsigned int> solve_generalized (SparseMatrix<T> & matrix_A,
185  SparseMatrix<T> & matrix_B,
186  int nev,
187  int ncv,
188  const double tol,
189  const unsigned int m_its) = 0;
190 
198  virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> & matrix_A,
199  SparseMatrix<T> & matrix_B,
200  int nev,
201  int ncv,
202  const double tol,
203  const unsigned int m_its) = 0;
204 
212  virtual std::pair<unsigned int, unsigned int> solve_generalized (SparseMatrix<T> & matrix_A,
213  ShellMatrix<T> & matrix_B,
214  int nev,
215  int ncv,
216  const double tol,
217  const unsigned int m_its) = 0;
218 
226  virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> & matrix_A,
227  ShellMatrix<T> & matrix_B,
228  int nev,
229  int ncv,
230  const double tol,
231  const unsigned int m_its) = 0;
232 
233 
238  virtual std::pair<Real, Real> get_eigenpair (dof_id_type i,
239  NumericVector<T> & solution) = 0;
240 
246  virtual std::pair<Real, Real> get_eigenvalue (dof_id_type i) = 0;
247 
251  virtual void attach_deflation_space(NumericVector<T> & deflation_vector) = 0;
252 
256  virtual void set_initial_space(NumericVector<T> & initial_space_in) = 0;
257 
261  void set_solver_configuration(SolverConfiguration & solver_configuration);
262 
263 protected:
264 
269 
274 
279 
284 
290 
292 
294 };
295 
296 
297 
298 
299 /*----------------------- inline functions ----------------------------------*/
300 template <typename T>
301 inline
303  ParallelObject(comm_in),
307  _is_initialized (false),
310 {
311 }
312 
313 
314 
315 template <typename T>
316 inline
318 {
319  this->clear ();
320 }
321 
322 } // namespace libMesh
323 
324 #endif // LIBMESH_HAVE_SLEPC
325 
326 #endif // LIBMESH_EIGEN_SOLVER_H
void set_eigensolver_type(const EigenSolverType est)
Sets the type of eigensolver to use.
Definition: eigen_solver.h:134
EigenProblemType eigen_problem_type() const
Definition: eigen_solver.h:123
SolverConfiguration * _solver_configuration
Optionally store a SolverOptions object that can be used to set parameters like solver type...
Definition: eigen_solver.h:289
Encapsulates the MPI_Comm object.
Definition: parallel.h:657
virtual void set_initial_space(NumericVector< T > &initial_space_in)=0
Provide one basis vector for the initial guess.
EigenProblemType
Defines an enum for eigenproblem types.
PositionOfSpectrum position_of_spectrum() const
Definition: eigen_solver.h:128
SolverPackage
Defines an enum for various linear solver packages.
bool _is_initialized
Flag indicating if the data structures have been initialized.
Definition: eigen_solver.h:283
const class libmesh_nullptr_t libmesh_nullptr
Numeric vector.
Definition: dof_map.h:66
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i, NumericVector< T > &solution)=0
EigenSolverType eigen_solver_type() const
Definition: eigen_solver.h:118
The libMesh namespace provides an interface to certain functionality in the library.
virtual void attach_deflation_space(NumericVector< T > &deflation_vector)=0
Attach a deflation space defined by a single vector.
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
PositionOfSpectrum _position_of_spectrum
Enum stating where to evaluate the spectrum.
Definition: eigen_solver.h:278
Generic sparse matrix.
Definition: dof_map.h:65
bool get_close_matrix_before_solve() const
Definition: eigen_solver.h:89
virtual std::pair< Real, Real > get_eigenvalue(dof_id_type i)=0
This class stores solver configuration data, e.g.
void set_eigenproblem_type(EigenProblemType ept)
Sets the type of the eigenproblem.
Definition: eigen_solver.h:140
This class implements reference counting.
This class forms the base class for all other classes that are expected to be implemented in parallel...
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.
virtual ~EigenSolver()
Destructor.
Definition: eigen_solver.h:317
EigenSolver(const Parallel::Communicator &comm_in LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
Constructor.
Definition: eigen_solver.h:302
virtual void init()=0
Initialize data structures if not done so already.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void set_position_of_spectrum(PositionOfSpectrum pos)
Sets the position of the spectrum.
Definition: eigen_solver.h:146
PositionOfSpectrum
Defines an enum for the position of the spectrum, i.e.
bool initialized() const
Definition: eigen_solver.h:82
EigenSolverType _eigen_solver_type
Enum stating which type of eigensolver to use.
Definition: eigen_solver.h:268
EigenProblemType _eigen_problem_type
Enum stating which type of eigen problem we deal with.
Definition: eigen_solver.h:273
EigenSolverType
Defines an enum for iterative eigenproblem solver types.
void set_solver_configuration(SolverConfiguration &solver_configuration)
Set the solver configuration object.
Definition: eigen_solver.C:58
Generic shell matrix, i.e.
static UniquePtr< EigenSolver< T > > build(const Parallel::Communicator &comm_in LIBMESH_CAN_DEFAULT_TO_COMMWORLD, const SolverPackage solver_package=SLEPC_SOLVERS)
Builds an EigenSolver using the linear solver package specified by solver_package.
Definition: eigen_solver.C:37
void set_close_matrix_before_solve(bool val)
Set the flag which controls whether libmesh closes the eigenproblem matrices before solving...
Definition: eigen_solver.h:99
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 void clear()
Release all memory and clear data structures.
Definition: eigen_solver.h:108
uint8_t dof_id_type
Definition: id_types.h:64
This class provides an interface to solvers for eigenvalue problems.
Definition: eigen_solver.h:54