Line data Source code
1 : // The libMesh Finite Element Library.
2 : // Copyright (C) 2002-2025 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 : namespace libMesh
39 : {
40 :
41 : /**
42 : * This class provides an interface to Laspack
43 : * iterative solvers that is compatible with the \p libMesh
44 : * \p LinearSolver<>
45 : *
46 : * \author Benjamin Kirk
47 : * \date 2002-2007
48 : */
49 : template <typename T>
50 : class LaspackLinearSolver : public LinearSolver<T>
51 : {
52 : public:
53 : /**
54 : * Constructor. Initializes Laspack data structures
55 : */
56 : LaspackLinearSolver (const libMesh::Parallel::Communicator & comm);
57 :
58 : /**
59 : * Destructor.
60 : */
61 : ~LaspackLinearSolver ();
62 :
63 : /**
64 : * Release all memory and clear data structures.
65 : */
66 : virtual void clear () override;
67 :
68 : /**
69 : * Initialize data structures if not done so already.
70 : */
71 : virtual void init (const char * name = nullptr) override;
72 :
73 : /**
74 : * Call the Laspack solver
75 : */
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 :
83 : /**
84 : * Call the Laspack solver to solve A^T x = b
85 : */
86 : virtual std::pair<unsigned int, Real>
87 : adjoint_solve (SparseMatrix<T> & matrix,
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 :
93 : /**
94 : * Call the Laspack solver
95 : */
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 :
104 : /**
105 : * This function solves a system whose matrix is a shell matrix.
106 : */
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 :
114 : /**
115 : * This function solves a system whose matrix is a shell matrix, but
116 : * a sparse matrix is used as preconditioning matrix, this allowing
117 : * other preconditioners than JACOBI.
118 : */
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 :
127 : /**
128 : * Prints a useful message about why the latest linear solve
129 : * con(di)verged.
130 : */
131 : virtual void print_converged_reason() const override;
132 :
133 : /**
134 : * \returns The solver's convergence flag.
135 : */
136 : virtual LinearConvergenceReason get_converged_reason() const override;
137 :
138 : private:
139 :
140 : /**
141 : * Tells LASPACK to use the user-specified preconditioner stored in
142 : * \p _preconditioner_type
143 : */
144 : void set_laspack_preconditioner_type ();
145 :
146 : /**
147 : * Preconditioner type
148 : */
149 : PrecondProcType _precond_type;
150 : };
151 :
152 :
153 : /*----------------------- functions ----------------------------------*/
154 : template <typename T>
155 : inline
156 0 : LaspackLinearSolver<T>::LaspackLinearSolver (const libMesh::Parallel::Communicator & comm) :
157 : LinearSolver<T>(comm),
158 0 : _precond_type (ILUPrecond)
159 : {
160 0 : }
161 :
162 :
163 :
164 : template <typename T>
165 : inline
166 0 : LaspackLinearSolver<T>::~LaspackLinearSolver ()
167 : {
168 0 : this->clear ();
169 0 : }
170 :
171 :
172 :
173 : template <typename T>
174 : inline
175 : std::pair<unsigned int, Real>
176 0 : LaspackLinearSolver<T>::solve (SparseMatrix<T> &,
177 : SparseMatrix<T> &,
178 : NumericVector<T> &,
179 : NumericVector<T> &,
180 : const std::optional<double>,
181 : const std::optional<unsigned int>)
182 : {
183 0 : 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
|