$extrastylesheet
eigen_solver.h
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 
00020 #ifndef LIBMESH_EIGEN_SOLVER_H
00021 #define LIBMESH_EIGEN_SOLVER_H
00022 
00023 
00024 #include "libmesh/libmesh_config.h"
00025 #ifdef LIBMESH_HAVE_SLEPC
00026 
00027 // Local includes
00028 #include "libmesh/libmesh_common.h"
00029 #include "libmesh/enum_solver_package.h"
00030 #include "libmesh/enum_eigen_solver_type.h"
00031 #include "libmesh/reference_counted_object.h"
00032 #include "libmesh/libmesh.h"
00033 #include "libmesh/parallel_object.h"
00034 #include "libmesh/auto_ptr.h"
00035 
00036 // C++ includes
00037 
00038 namespace libMesh
00039 {
00040 
00041 // forward declarations
00042 template <typename T> class SparseMatrix;
00043 template <typename T> class ShellMatrix;
00044 template <typename T> class NumericVector;
00045 
00046 
00052 template <typename T>
00053 class EigenSolver : public ReferenceCountedObject<EigenSolver<T> >,
00054                     public ParallelObject
00055 {
00056 public:
00057 
00061   EigenSolver (const Parallel::Communicator &comm_in
00062                LIBMESH_CAN_DEFAULT_TO_COMMWORLD);
00063 
00067   virtual ~EigenSolver ();
00068 
00073   static UniquePtr<EigenSolver<T> > build(const Parallel::Communicator &comm_in
00074                                           LIBMESH_CAN_DEFAULT_TO_COMMWORLD,
00075                                           const SolverPackage solver_package = SLEPC_SOLVERS);
00076 
00081   bool initialized () const { return _is_initialized; }
00082 
00083 
00087   virtual void clear () {}
00088 
00092   virtual void init () = 0;
00093 
00097   EigenSolverType eigen_solver_type () const { return _eigen_solver_type; }
00098 
00102   EigenProblemType eigen_problem_type () const { return _eigen_problem_type;}
00103 
00107   PositionOfSpectrum position_of_spectrum () const
00108   { return _position_of_spectrum;}
00109 
00113   void set_eigensolver_type (const EigenSolverType est)
00114   { _eigen_solver_type = est; }
00115 
00119   void set_eigenproblem_type ( EigenProblemType ept)
00120   {_eigen_problem_type = ept;}
00121 
00125   void set_position_of_spectrum (PositionOfSpectrum pos)
00126   {_position_of_spectrum= pos;}
00127 
00133   virtual std::pair<unsigned int, unsigned int> solve_standard (SparseMatrix<T> &matrix_A,
00134                                                                 int nev,
00135                                                                 int ncv,
00136                                                                 const double tol,
00137                                                                 const unsigned int m_its) = 0;
00138 
00144   virtual std::pair<unsigned int, unsigned int> solve_standard (ShellMatrix<T> &matrix_A,
00145                                                                 int nev,
00146                                                                 int ncv,
00147                                                                 const double tol,
00148                                                                 const unsigned int m_its) = 0;
00149 
00150 
00157   virtual std::pair<unsigned int, unsigned int> solve_generalized (SparseMatrix<T> &matrix_A,
00158                                                                    SparseMatrix<T> &matrix_B,
00159                                                                    int nev,
00160                                                                    int ncv,
00161                                                                    const double tol,
00162                                                                    const unsigned int m_its) = 0;
00163 
00168   virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> &matrix_A,
00169                                                                    SparseMatrix<T> &matrix_B,
00170                                                                    int nev,
00171                                                                    int ncv,
00172                                                                    const double tol,
00173                                                                    const unsigned int m_its) = 0;
00174 
00179   virtual std::pair<unsigned int, unsigned int> solve_generalized (SparseMatrix<T> &matrix_A,
00180                                                                    ShellMatrix<T> &matrix_B,
00181                                                                    int nev,
00182                                                                    int ncv,
00183                                                                    const double tol,
00184                                                                    const unsigned int m_its) = 0;
00185 
00190   virtual std::pair<unsigned int, unsigned int> solve_generalized (ShellMatrix<T> &matrix_A,
00191                                                                    ShellMatrix<T> &matrix_B,
00192                                                                    int nev,
00193                                                                    int ncv,
00194                                                                    const double tol,
00195                                                                    const unsigned int m_its) = 0;
00196 
00197 
00202   virtual std::pair<Real, Real> get_eigenpair (unsigned int i,
00203                                                NumericVector<T> &solution) = 0;
00204 
00209   virtual std::pair<Real, Real> get_eigenvalue (unsigned int i) = 0;
00210 
00214   virtual void attach_deflation_space(NumericVector<T> &deflation_vector) = 0;
00215 
00216 protected:
00217 
00221   EigenSolverType _eigen_solver_type;
00222 
00226   EigenProblemType _eigen_problem_type;
00227 
00231   PositionOfSpectrum _position_of_spectrum;
00232 
00236   bool _is_initialized;
00237 
00238 };
00239 
00240 
00241 
00242 
00243 /*----------------------- inline functions ----------------------------------*/
00244 template <typename T>
00245 inline
00246 EigenSolver<T>::EigenSolver (const Parallel::Communicator &comm_in) :
00247   ParallelObject(comm_in),
00248   _eigen_solver_type    (ARNOLDI),
00249   _eigen_problem_type   (NHEP),
00250   _position_of_spectrum (LARGEST_MAGNITUDE),
00251   _is_initialized       (false)
00252 {
00253 }
00254 
00255 
00256 
00257 template <typename T>
00258 inline
00259 EigenSolver<T>::~EigenSolver ()
00260 {
00261   this->clear ();
00262 }
00263 
00264 } // namespace libMesh
00265 
00266 #endif // LIBMESH_HAVE_SLEPC
00267 
00268 #endif // LIBMESH_EIGEN_SOLVER_H