$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_EIGEN_SPARSE_LINEAR_SOLVER_H 00021 #define LIBMESH_EIGEN_SPARSE_LINEAR_SOLVER_H 00022 00023 #include "libmesh/libmesh_common.h" 00024 00025 #ifdef LIBMESH_HAVE_EIGEN 00026 00027 // Eigen includes 00028 00029 // Local includes 00030 #include "libmesh/linear_solver.h" 00031 #include "libmesh/eigen_sparse_vector.h" 00032 #include "libmesh/eigen_sparse_matrix.h" 00033 00034 // C++ includes 00035 00036 namespace libMesh 00037 { 00038 00039 00040 00048 template <typename T> 00049 class EigenSparseLinearSolver : public LinearSolver<T> 00050 { 00051 public: 00055 EigenSparseLinearSolver (const libMesh::Parallel::Communicator &comm_in 00056 LIBMESH_CAN_DEFAULT_TO_COMMWORLD); 00057 00061 ~EigenSparseLinearSolver (); 00062 00066 void clear (); 00067 00071 void init (const char* name=NULL); 00072 00076 std::pair<unsigned int, Real> 00077 solve (SparseMatrix<T> &matrix, 00078 NumericVector<T> &solution, 00079 NumericVector<T> &rhs, 00080 const double tol, 00081 const unsigned int m_its); 00082 00086 std::pair<unsigned int, Real> 00087 adjoint_solve (SparseMatrix<T> &matrix, 00088 NumericVector<T> &solution, 00089 NumericVector<T> &rhs, 00090 const double tol, 00091 const unsigned int m_its); 00092 00096 std::pair<unsigned int, Real> 00097 solve (SparseMatrix<T> &matrix, 00098 SparseMatrix<T> &pc, 00099 NumericVector<T> &solution, 00100 NumericVector<T> &rhs, 00101 const double tol, 00102 const unsigned int m_its); 00103 00107 std::pair<unsigned int, Real> 00108 solve (const ShellMatrix<T>& shell_matrix, 00109 NumericVector<T>& solution_in, 00110 NumericVector<T>& rhs_in, 00111 const double tol, 00112 const unsigned int m_its); 00113 00119 virtual std::pair<unsigned int, Real> 00120 solve (const ShellMatrix<T>& shell_matrix, 00121 const SparseMatrix<T>& precond_matrix, 00122 NumericVector<T>& solution_in, 00123 NumericVector<T>& rhs_in, 00124 const double tol, 00125 const unsigned int m_its); 00126 00131 virtual void print_converged_reason() const; 00132 00136 virtual LinearConvergenceReason get_converged_reason() const; 00137 00138 private: 00139 00144 void set_eigen_preconditioner_type (); 00145 00146 }; 00147 00148 00149 /*----------------------- functions ----------------------------------*/ 00150 template <typename T> 00151 inline 00152 EigenSparseLinearSolver<T>::EigenSparseLinearSolver(const libMesh::Parallel::Communicator &comm_in) : 00153 LinearSolver<T>(comm_in) 00154 { 00155 // The GMRES iterative solver isn't supported by Eigen, so use BICGSTAB instead 00156 this->_solver_type = BICGSTAB; 00157 } 00158 00159 00160 00161 template <typename T> 00162 inline 00163 EigenSparseLinearSolver<T>::~EigenSparseLinearSolver () 00164 { 00165 this->clear (); 00166 } 00167 00168 00169 00170 template <typename T> 00171 inline 00172 std::pair<unsigned int, Real> 00173 EigenSparseLinearSolver<T>::solve (SparseMatrix<T>&, 00174 SparseMatrix<T>&, 00175 NumericVector<T>&, 00176 NumericVector<T>&, 00177 const double, 00178 const unsigned int) 00179 { 00180 libmesh_error_msg("ERROR: Eigen does not support a user-supplied preconditioner!"); 00181 00182 std::pair<unsigned int, Real> p; 00183 return p; 00184 } 00185 00186 } // namespace libMesh 00187 00188 #endif // #ifdef LIBMESH_HAVE_EIGEN 00189 #endif // LIBMESH_EIGEN_SPARSE_LINEAR_SOLVER_H