$extrastylesheet
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_SLEPC_EIGEN_SOLVER_H 00021 #define LIBMESH_SLEPC_EIGEN_SOLVER_H 00022 00023 #include "libmesh/libmesh_config.h" 00024 00025 #ifdef LIBMESH_HAVE_SLEPC 00026 00027 // Local includes 00028 #include "libmesh/eigen_solver.h" 00029 #include "libmesh/slepc_macro.h" 00030 00034 EXTERN_C_FOR_SLEPC_BEGIN 00035 # include <slepceps.h> 00036 EXTERN_C_FOR_SLEPC_END 00037 00038 // C++ includes 00039 00040 00041 namespace libMesh 00042 { 00043 00044 00050 template <typename T> 00051 class SlepcEigenSolver : public EigenSolver<T> 00052 { 00053 00054 public: 00055 00059 SlepcEigenSolver(const Parallel::Communicator &comm_in 00060 LIBMESH_CAN_DEFAULT_TO_COMMWORLD); 00061 00062 00066 ~SlepcEigenSolver(); 00067 00068 00072 void clear(); 00073 00074 00078 void init(); 00079 00080 00091 std::pair<unsigned int, unsigned int> solve_standard (SparseMatrix<T> &matrix_A, 00092 int nev, 00093 int ncv, 00094 const double tol, 00095 const unsigned int m_its); 00096 00101 std::pair<unsigned int, unsigned int> solve_standard (ShellMatrix<T> &shell_matrix, 00102 int nev, 00103 int ncv, 00104 const double tol, 00105 const unsigned int m_its); 00106 00107 00120 std::pair<unsigned int, unsigned int> solve_generalized(SparseMatrix<T> &matrix_A, 00121 SparseMatrix<T> &matrix_B, 00122 int nev, 00123 int ncv, 00124 const double tol, 00125 const unsigned int m_its); 00126 00131 std::pair<unsigned int, unsigned int> solve_generalized(ShellMatrix<T> &matrix_A, 00132 SparseMatrix<T> &matrix_B, 00133 int nev, 00134 int ncv, 00135 const double tol, 00136 const unsigned int m_its); 00137 00148 std::pair<unsigned int, unsigned int> solve_generalized(SparseMatrix<T> &matrix_A, 00149 ShellMatrix<T> &matrix_B, 00150 int nev, 00151 int ncv, 00152 const double tol, 00153 const unsigned int m_its); 00154 00165 std::pair<unsigned int, unsigned int> solve_generalized(ShellMatrix<T> &matrix_A, 00166 ShellMatrix<T> &matrix_B, 00167 int nev, 00168 int ncv, 00169 const double tol, 00170 const unsigned int m_its); 00171 00172 00173 00180 std::pair<Real, Real> get_eigenpair (unsigned int i, 00181 NumericVector<T> &solution_in); 00182 00186 std::pair<Real, Real> get_eigenvalue (unsigned int i); 00187 00192 Real get_relative_error (unsigned int i); 00193 00197 void attach_deflation_space(NumericVector<T>& deflation_vector); 00198 00199 private: 00200 00204 std::pair<unsigned int, unsigned int> _solve_standard_helper (Mat mat, 00205 int nev, 00206 int ncv, 00207 const double tol, 00208 const unsigned int m_its); 00209 00213 std::pair<unsigned int, unsigned int> _solve_generalized_helper (Mat mat_A, 00214 Mat mat_B, 00215 int nev, 00216 int ncv, 00217 const double tol, 00218 const unsigned int m_its); 00219 00224 void set_slepc_solver_type (); 00225 00230 void set_slepc_problem_type (); 00231 00236 void set_slepc_position_of_spectrum(); 00237 00243 static PetscErrorCode _petsc_shell_matrix_mult(Mat mat, Vec arg, Vec dest); 00244 00250 static PetscErrorCode _petsc_shell_matrix_get_diagonal(Mat mat, Vec dest); 00251 00255 EPS _eps; 00256 00257 }; 00258 00259 00260 /*----------------------- inline functions ----------------------------------*/ 00261 template <typename T> 00262 inline 00263 SlepcEigenSolver<T>::SlepcEigenSolver (const Parallel::Communicator &comm_in) : 00264 EigenSolver<T>(comm_in) 00265 { 00266 this->_eigen_solver_type = ARNOLDI; 00267 this->_eigen_problem_type = NHEP; 00268 } 00269 00270 00271 00272 template <typename T> 00273 inline 00274 SlepcEigenSolver<T>::~SlepcEigenSolver () 00275 { 00276 this->clear (); 00277 } 00278 00279 } // namespace libMesh 00280 00281 00282 #endif // #ifdef LIBMESH_HAVE_SLEPC 00283 #endif // LIBMESH_SLEPC_EIGEN_SOLVER_H