eigen_sparse_linear_solver.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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_SPARSE_LINEAR_SOLVER_H
21 #define LIBMESH_EIGEN_SPARSE_LINEAR_SOLVER_H
22 
23 #include "libmesh/libmesh_common.h"
24 
25 #ifdef LIBMESH_HAVE_EIGEN
26 
27 // Eigen includes
28 
29 // Local includes
30 #include "libmesh/linear_solver.h"
33 #include "libmesh/enum_convergence_flags.h" // The build_map() function uses these.
34 
35 
36 namespace libMesh
37 {
38 
47 template <typename T>
49 {
50 public:
55 
60 
64  virtual void clear () override;
65 
69  virtual void init (const char * name=nullptr) override;
70 
74  virtual std::pair<unsigned int, Real>
75  solve (SparseMatrix<T> & matrix,
76  NumericVector<T> & solution,
77  NumericVector<T> & rhs,
78  const double tol,
79  const unsigned int m_its) override;
80 
84  virtual std::pair<unsigned int, Real>
86  NumericVector<T> & solution,
87  NumericVector<T> & rhs,
88  const double tol,
89  const unsigned int m_its) override;
90 
94  virtual std::pair<unsigned int, Real>
95  solve (SparseMatrix<T> & matrix,
96  SparseMatrix<T> & pc,
97  NumericVector<T> & solution,
98  NumericVector<T> & rhs,
99  const double tol,
100  const unsigned int m_its) override;
101 
105  virtual std::pair<unsigned int, Real>
106  solve (const ShellMatrix<T> & shell_matrix,
107  NumericVector<T> & solution_in,
108  NumericVector<T> & rhs_in,
109  const double tol,
110  const unsigned int m_its) override;
111 
117  virtual std::pair<unsigned int, Real>
118  solve (const ShellMatrix<T> & shell_matrix,
119  const SparseMatrix<T> & precond_matrix,
120  NumericVector<T> & solution_in,
121  NumericVector<T> & rhs_in,
122  const double tol,
123  const unsigned int m_its) override;
124 
128  virtual LinearConvergenceReason get_converged_reason() const override;
129 
130 private:
131 
137 
141  Eigen::ComputationInfo _comp_info;
142 
147  static std::map<Eigen::ComputationInfo, LinearConvergenceReason> _convergence_reasons;
148 
152  static std::map<Eigen::ComputationInfo, LinearConvergenceReason> build_map()
153  {
154  std::map<Eigen::ComputationInfo, LinearConvergenceReason> ret;
155  ret[Eigen::Success] = CONVERGED_ITS;
156  ret[Eigen::NumericalIssue] = DIVERGED_BREAKDOWN;
157  ret[Eigen::NoConvergence] = DIVERGED_ITS;
158  ret[Eigen::InvalidInput] = DIVERGED_NULL;
159  return ret;
160  }
161 };
162 
163 
164 
165 // Call the class-static function to define the class-static member.
166 // Since it's a template class, you actually do this in the header,
167 // not the source file.
168 template <typename T>
169 std::map<Eigen::ComputationInfo, LinearConvergenceReason>
171 
172 
173 
174 template <typename T>
175 inline
177 {
178  this->clear ();
179 }
180 
181 
182 
183 template <typename T>
184 inline
185 std::pair<unsigned int, Real>
187  SparseMatrix<T> &,
190  const double,
191  const unsigned int)
192 {
193  libmesh_error_msg("ERROR: Eigen does not support a user-supplied preconditioner!");
194 
195  std::pair<unsigned int, Real> p;
196  return p;
197 }
198 
199 } // namespace libMesh
200 
201 #endif // #ifdef LIBMESH_HAVE_EIGEN
202 #endif // LIBMESH_EIGEN_SPARSE_LINEAR_SOLVER_H
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &matrix, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its) override
EigenSparseLinearSolver(const libMesh::Parallel::Communicator &comm_in)
virtual std::pair< unsigned int, Real > adjoint_solve(SparseMatrix< T > &matrix, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its) override
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: diff_context.h:40
virtual void init(const char *name=nullptr) override
static std::map< Eigen::ComputationInfo, LinearConvergenceReason > build_map()
virtual LinearConvergenceReason get_converged_reason() const override
static std::map< Eigen::ComputationInfo, LinearConvergenceReason > _convergence_reasons