libMesh
laspack_linear_solver.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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_LASPACK_LINEAR_SOLVER_H
21 #define LIBMESH_LASPACK_LINEAR_SOLVER_H
22 
23 #include "libmesh/libmesh_common.h"
24 
25 #if defined(LIBMESH_HAVE_LASPACK)
26 //#if defined(LIBMESH_HAVE_LASPACK) && !defined(LIBMESH_USE_COMPLEX_NUMBERS)
27 
28 // Laspack includes
29 #include <itersolv.h>
30 #include <rtc.h>
31 #include <errhandl.h>
32 
33 // Local includes
34 #include "libmesh/linear_solver.h"
35 #include "libmesh/laspack_vector.h"
36 #include "libmesh/laspack_matrix.h"
37 
38 // C++ includes
39 
40 namespace libMesh
41 {
42 
51 template <typename T>
52 class LaspackLinearSolver : public LinearSolver<T>
53 {
54 public:
59  LIBMESH_CAN_DEFAULT_TO_COMMWORLD);
60 
65 
69  virtual void clear () libmesh_override;
70 
74  virtual void init (const char * name = libmesh_nullptr) libmesh_override;
75 
79  virtual std::pair<unsigned int, Real>
80  solve (SparseMatrix<T> & matrix,
81  NumericVector<T> & solution,
82  NumericVector<T> & rhs,
83  const double tol,
84  const unsigned int m_its) libmesh_override;
85 
89  virtual std::pair<unsigned int, Real>
90  adjoint_solve (SparseMatrix<T> & matrix,
91  NumericVector<T> & solution,
92  NumericVector<T> & rhs,
93  const double tol,
94  const unsigned int m_its) libmesh_override;
95 
99  virtual std::pair<unsigned int, Real>
100  solve (SparseMatrix<T> & matrix,
101  SparseMatrix<T> & pc,
102  NumericVector<T> & solution,
103  NumericVector<T> & rhs,
104  const double tol,
105  const unsigned int m_its) libmesh_override;
106 
110  virtual std::pair<unsigned int, Real>
111  solve (const ShellMatrix<T> & shell_matrix,
112  NumericVector<T> & solution_in,
113  NumericVector<T> & rhs_in,
114  const double tol,
115  const unsigned int m_its) libmesh_override;
116 
122  virtual std::pair<unsigned int, Real>
123  solve (const ShellMatrix<T> & shell_matrix,
124  const SparseMatrix<T> & precond_matrix,
125  NumericVector<T> & solution_in,
126  NumericVector<T> & rhs_in,
127  const double tol,
128  const unsigned int m_its) libmesh_override;
129 
134  virtual void print_converged_reason() const libmesh_override;
135 
139  virtual LinearConvergenceReason get_converged_reason() const libmesh_override;
140 
141 private:
142 
148 
152  PrecondProcType _precond_type;
153 };
154 
155 
156 /*----------------------- functions ----------------------------------*/
157 template <typename T>
158 inline
159 LaspackLinearSolver<T>::LaspackLinearSolver (const libMesh::Parallel::Communicator & comm) :
160  LinearSolver<T>(comm),
161  _precond_type (ILUPrecond)
162 {
163 }
164 
165 
166 
167 template <typename T>
168 inline
170 {
171  this->clear ();
172 }
173 
174 
175 
176 template <typename T>
177 inline
178 std::pair<unsigned int, Real>
180  SparseMatrix<T> &,
183  const double,
184  const unsigned int)
185 {
186  libmesh_error_msg("ERROR: LASPACK does not support a user-supplied preconditioner!");
187 
188  std::pair<unsigned int, Real> p;
189  return p;
190 }
191 
192 } // namespace libMesh
193 
194 #endif // #ifdef LIBMESH_HAVE_LASPACK
195 #endif // LIBMESH_LASPACK_LINEAR_SOLVER_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
Encapsulates the MPI_Comm object.
Definition: parallel.h:657
void set_laspack_preconditioner_type()
Tells LASPACK to use the user-specified preconditioner stored in _preconditioner_type.
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &matrix, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its) libmesh_override
Call the Laspack solver.
const class libmesh_nullptr_t libmesh_nullptr
Numeric vector.
Definition: dof_map.h:66
The libMesh namespace provides an interface to certain functionality in the library.
PetscErrorCode Vec Mat Mat pc
virtual void init(const char *name=libmesh_nullptr) libmesh_override
Initialize data structures if not done so already.
virtual LinearConvergenceReason get_converged_reason() const libmesh_override
Generic sparse matrix.
Definition: dof_map.h:65
This class provides an interface to Laspack iterative solvers that is compatible with the libMesh Lin...
This base class can be inherited from to provide interfaces to linear solvers from different packages...
Definition: linear_solver.h:58
PrecondProcType _precond_type
Preconditioner type.
LaspackLinearSolver(const libMesh::Parallel::Communicator &comm LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
Constructor.
virtual void print_converged_reason() const libmesh_override
Prints a useful message about why the latest linear solve con(di)verged.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Parallel::Communicator & comm() const
virtual void clear() libmesh_override
Release all memory and clear data structures.
LinearConvergenceReason
Linear solver convergence flags (taken from the PETSc flags)
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) libmesh_override
Call the Laspack solver to solve A^T x = b.