slepc_eigen_solver.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 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(); 00060 00061 00065 ~SlepcEigenSolver(); 00066 00067 00071 void clear(); 00072 00073 00077 void init(); 00078 00079 00090 std::pair<unsigned int, unsigned int> solve_standard (SparseMatrix<T> &matrix_A, 00091 int nev, 00092 int ncv, 00093 const double tol, 00094 const unsigned int m_its); 00095 00100 std::pair<unsigned int, unsigned int> solve_standard (ShellMatrix<T> &shell_matrix, 00101 int nev, 00102 int ncv, 00103 const double tol, 00104 const unsigned int m_its); 00105 00106 00119 std::pair<unsigned int, unsigned int> solve_generalized(SparseMatrix<T> &matrix_A, 00120 SparseMatrix<T> &matrix_B, 00121 int nev, 00122 int ncv, 00123 const double tol, 00124 const unsigned int m_its); 00125 00130 std::pair<unsigned int, unsigned int> solve_generalized(ShellMatrix<T> &matrix_A, 00131 SparseMatrix<T> &matrix_B, 00132 int nev, 00133 int ncv, 00134 const double tol, 00135 const unsigned int m_its); 00136 00147 std::pair<unsigned int, unsigned int> solve_generalized(SparseMatrix<T> &matrix_A, 00148 ShellMatrix<T> &matrix_B, 00149 int nev, 00150 int ncv, 00151 const double tol, 00152 const unsigned int m_its); 00153 00164 std::pair<unsigned int, unsigned int> solve_generalized(ShellMatrix<T> &matrix_A, 00165 ShellMatrix<T> &matrix_B, 00166 int nev, 00167 int ncv, 00168 const double tol, 00169 const unsigned int m_its); 00170 00171 00172 00179 std::pair<Real, Real> get_eigenpair (unsigned int i, 00180 NumericVector<T> &solution_in); 00181 00185 std::pair<Real, Real> get_eigenvalue (unsigned int i); 00186 00191 Real get_relative_error (unsigned int i); 00192 00196 void attach_deflation_space(NumericVector<T>& deflation_vector); 00197 00198 private: 00199 00203 std::pair<unsigned int, unsigned int> _solve_standard_helper (Mat mat, 00204 int nev, 00205 int ncv, 00206 const double tol, 00207 const unsigned int m_its); 00208 00212 std::pair<unsigned int, unsigned int> _solve_generalized_helper (Mat mat_A, 00213 Mat mat_B, 00214 int nev, 00215 int ncv, 00216 const double tol, 00217 const unsigned int m_its); 00218 00223 void set_slepc_solver_type (); 00224 00229 void set_slepc_problem_type (); 00230 00235 void set_slepc_position_of_spectrum(); 00236 00242 static PetscErrorCode _petsc_shell_matrix_mult(Mat mat, Vec arg, Vec dest); 00243 00249 static PetscErrorCode _petsc_shell_matrix_get_diagonal(Mat mat, Vec dest); 00250 00254 EPS _eps; 00255 00256 }; 00257 00258 00259 /*----------------------- inline functions ----------------------------------*/ 00260 template <typename T> 00261 inline 00262 SlepcEigenSolver<T>::SlepcEigenSolver () 00263 { 00264 this->_eigen_solver_type = ARNOLDI; 00265 this->_eigen_problem_type = NHEP; 00266 } 00267 00268 00269 00270 template <typename T> 00271 inline 00272 SlepcEigenSolver<T>::~SlepcEigenSolver () 00273 { 00274 this->clear (); 00275 } 00276 00277 } // namespace libMesh 00278 00279 00280 #endif // #ifdef LIBMESH_HAVE_SLEPC 00281 #endif // LIBMESH_SLEPC_EIGEN_SOLVER_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:48 UTC
Hosted By: