libMesh
Loading...
Searching...
No Matches
laspack_linear_solver.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
38namespace libMesh
39{
40
49template <typename T>
51{
52public:
57
62
66 virtual void clear () override;
67
71 virtual void init (const char * name = nullptr) override;
72
76 virtual std::pair<unsigned int, Real>
77 solve (SparseMatrix<T> & matrix,
78 NumericVector<T> & solution,
79 NumericVector<T> & rhs,
80 const std::optional<double> tol = std::nullopt,
81 const std::optional<unsigned int> m_its = std::nullopt) override;
82
86 virtual std::pair<unsigned int, Real>
88 NumericVector<T> & solution,
89 NumericVector<T> & rhs,
90 const std::optional<double> tol = std::nullopt,
91 const std::optional<unsigned int> m_its = std::nullopt) override;
92
96 virtual std::pair<unsigned int, Real>
97 solve (SparseMatrix<T> & matrix,
98 SparseMatrix<T> & pc,
99 NumericVector<T> & solution,
100 NumericVector<T> & rhs,
101 const std::optional<double> tol = std::nullopt,
102 const std::optional<unsigned int> m_its = std::nullopt) override;
103
107 virtual std::pair<unsigned int, Real>
108 solve (const ShellMatrix<T> & shell_matrix,
109 NumericVector<T> & solution_in,
110 NumericVector<T> & rhs_in,
111 const std::optional<double> tol = std::nullopt,
112 const std::optional<unsigned int> m_its = std::nullopt) override;
113
119 virtual std::pair<unsigned int, Real>
120 solve (const ShellMatrix<T> & shell_matrix,
121 const SparseMatrix<T> & precond_matrix,
122 NumericVector<T> & solution_in,
123 NumericVector<T> & rhs_in,
124 const std::optional<double> tol = std::nullopt,
125 const std::optional<unsigned int> m_its = std::nullopt) override;
126
131 virtual void print_converged_reason() const override;
132
136 virtual LinearConvergenceReason get_converged_reason() const override;
137
138private:
139
145
149 PrecondProcType _precond_type;
150};
151
152
153/*----------------------- functions ----------------------------------*/
154template <typename T>
155inline
157 LinearSolver<T>(comm),
158 _precond_type (ILUPrecond)
159{
160}
161
162
163
164template <typename T>
165inline
167{
168 this->clear ();
169}
170
171
172
173template <typename T>
174inline
175std::pair<unsigned int, Real>
180 const std::optional<double>,
181 const std::optional<unsigned int>)
182{
183 libmesh_error_msg("ERROR: LASPACK does not support a user-supplied preconditioner!");
184
185 std::pair<unsigned int, Real> p;
186 return p;
187}
188
189} // namespace libMesh
190
191#endif // #ifdef LIBMESH_HAVE_LASPACK
192#endif // LIBMESH_LASPACK_LINEAR_SOLVER_H
This class provides an interface to Laspack iterative solvers that is compatible with the libMesh Lin...
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &matrix, NumericVector< T > &solution, NumericVector< T > &rhs, const std::optional< double > tol=std::nullopt, const std::optional< unsigned int > m_its=std::nullopt) override
Call the Laspack solver.
void set_laspack_preconditioner_type()
Tells LASPACK to use the user-specified preconditioner stored in _preconditioner_type.
virtual std::pair< unsigned int, Real > adjoint_solve(SparseMatrix< T > &matrix, NumericVector< T > &solution, NumericVector< T > &rhs, const std::optional< double > tol=std::nullopt, const std::optional< unsigned int > m_its=std::nullopt) override
Call the Laspack solver to solve A^T x = b.
virtual void clear() override
Release all memory and clear data structures.
virtual LinearConvergenceReason get_converged_reason() const override
virtual void init(const char *name=nullptr) override
Initialize data structures if not done so already.
PrecondProcType _precond_type
Preconditioner type.
virtual void print_converged_reason() const override
Prints a useful message about why the latest linear solve con(di)verged.
LaspackLinearSolver(const libMesh::Parallel::Communicator &comm)
Constructor.
This base class can be inherited from to provide interfaces to linear solvers from different packages...
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
const Parallel::Communicator & comm() const
Generic shell matrix, i.e.
Generic sparse matrix.
The libMesh namespace provides an interface to certain functionality in the library.
LinearConvergenceReason
Linear solver convergence flags (taken from the PETSc flags).