Reference documentation for deal.II version GIT relicensing-437-g81ec864850 2024-04-19 07:30:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
solver_selector.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 1999 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_solver_selector_h
16#define dealii_solver_selector_h
17
18
19#include <deal.II/base/config.h>
20
22
24#include <deal.II/lac/solver.h>
31#include <deal.II/lac/vector.h>
32
34
35
89template <typename VectorType = Vector<double>>
91{
92public:
96 using vector_type = VectorType;
97
101 SolverSelector() = default;
102
107 SolverSelector(const std::string &name, SolverControl &control);
108
112 virtual ~SolverSelector() override = default;
113
118 template <class Matrix, class Preconditioner>
119 void
120 solve(const Matrix &A,
121 VectorType &x,
122 const VectorType &b,
123 const Preconditioner &precond) const;
124
129 void
130 select(const std::string &name);
131
135 void
137
141 void
143
147 void
149
153 void
155
159 void
161
165 void
167
171 void
173
186 static std::string
188
193 std::string,
194 << "Solver " << arg1 << " does not exist. Use one of "
195 << std::endl
197
198
199
200protected:
206
210 std::string solver_name;
211
212private:
217
222
227
232
237
242};
243
245/* --------------------- Inline and template functions ------------------- */
246
247
248template <typename VectorType>
250 SolverControl &solver_control)
251 : solver_name(name)
252 , control(&solver_control)
253{}
254
255
256
257template <typename VectorType>
258void
260{
261 solver_name = name;
262}
263
264
265
266template <typename VectorType>
267template <class Matrix, class Preconditioner>
268void
270 VectorType &x,
271 const VectorType &b,
272 const Preconditioner &precond) const
273{
274 if (solver_name == "richardson")
275 {
276 SolverRichardson<VectorType> solver(*control, richardson_data);
277 solver.solve(A, x, b, precond);
278 }
279 else if (solver_name == "cg")
280 {
281 SolverCG<VectorType> solver(*control, cg_data);
282 solver.solve(A, x, b, precond);
283 }
284 else if (solver_name == "minres")
285 {
286 SolverMinRes<VectorType> solver(*control, minres_data);
287 solver.solve(A, x, b, precond);
288 }
289 else if (solver_name == "bicgstab")
290 {
291 SolverBicgstab<VectorType> solver(*control, bicgstab_data);
292 solver.solve(A, x, b, precond);
293 }
294 else if (solver_name == "gmres")
295 {
296 SolverGMRES<VectorType> solver(*control, gmres_data);
297 solver.solve(A, x, b, precond);
298 }
299 else if (solver_name == "fgmres")
300 {
301 SolverFGMRES<VectorType> solver(*control, fgmres_data);
302 solver.solve(A, x, b, precond);
303 }
304 else
305 Assert(false, ExcSolverDoesNotExist(solver_name));
306}
307
308
309
310template <typename VectorType>
311void
313{
314 control = &ctrl;
315}
316
317
318
319template <typename VectorType>
320std::string
322{
323 return "richardson|cg|bicgstab|gmres|fgmres|minres";
324}
325
326
327
328template <typename VectorType>
329void
331 const typename SolverGMRES<VectorType>::AdditionalData &data)
332{
333 gmres_data = data;
334}
335
336
337
338template <typename VectorType>
339void
341 const typename SolverFGMRES<VectorType>::AdditionalData &data)
342{
343 fgmres_data = data;
344}
345
346
347
348template <typename VectorType>
349void
352{
353 richardson_data = data;
354}
355
356
357
358template <typename VectorType>
359void
361 const typename SolverCG<VectorType>::AdditionalData &data)
362{
363 cg_data = data;
364}
365
366
367
368template <typename VectorType>
369void
371 const typename SolverMinRes<VectorType>::AdditionalData &data)
372{
373 minres_data = data;
374}
375
376
377
378template <typename VectorType>
379void
382{
383 bicgstab_data = data;
384}
385
387
388#endif
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const PreconditionerType &preconditioner)
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const PreconditionerType &preconditioner)
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const PreconditionerType &preconditioner)
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const PreconditionerType &preconditioner)
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const PreconditionerType &preconditioner)
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const PreconditionerType &preconditioner)
SolverGMRES< VectorType >::AdditionalData gmres_data
VectorType vector_type
virtual ~SolverSelector() override=default
SolverBicgstab< VectorType >::AdditionalData bicgstab_data
void select(const std::string &name)
static std::string get_solver_names()
void set_control(SolverControl &ctrl)
SolverFGMRES< VectorType >::AdditionalData fgmres_data
SolverMinRes< VectorType >::AdditionalData minres_data
void solve(const Matrix &A, VectorType &x, const VectorType &b, const Preconditioner &precond) const
void set_data(const typename SolverRichardson< VectorType >::AdditionalData &data)
SmartPointer< SolverControl, SolverSelector< VectorType > > control
std::string solver_name
SolverSelector()=default
SolverCG< VectorType >::AdditionalData cg_data
SolverRichardson< VectorType >::AdditionalData richardson_data
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
static ::ExceptionBase & ExcSolverDoesNotExist(std::string arg1)
#define Assert(cond, exc)
#define DeclException1(Exception1, type1, outsequence)
Definition exceptions.h:516