Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
ginkgo_solver.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2018 - 2019 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_ginkgo_solver_h
17 # define dealii_ginkgo_solver_h
18 
19 
20 # include <deal.II/base/config.h>
21 
22 # ifdef DEAL_II_WITH_GINKGO
23 
24 # include <deal.II/lac/block_sparse_matrix.h>
25 # include <deal.II/lac/exceptions.h>
26 # include <deal.II/lac/solver_control.h>
27 # include <deal.II/lac/sparse_matrix.h>
28 # include <deal.II/lac/vector.h>
29 
30 # include <ginkgo/ginkgo.hpp>
31 
32 # include <memory>
33 
34 DEAL_II_NAMESPACE_OPEN
35 
36 namespace GinkgoWrappers
37 {
49  template <typename ValueType, typename IndexType>
50  class SolverBase
51  {
52  public:
105  SolverBase(SolverControl &solver_control, const std::string &exec_type);
106 
110  virtual ~SolverBase() = default;
111 
115  void
116  initialize(const SparseMatrix<ValueType> &matrix);
117 
123  void
124  apply(Vector<ValueType> &solution, const Vector<ValueType> &rhs);
125 
131  void
132  solve(const SparseMatrix<ValueType> &matrix,
133  Vector<ValueType> & solution,
134  const Vector<ValueType> & rhs);
135 
139  SolverControl &
140  control() const;
141 
142 
143  protected:
148  SolverControl &solver_control;
149 
153  std::shared_ptr<gko::LinOpFactory> solver_gen;
154 
159  std::shared_ptr<gko::stop::ResidualNormReduction<>::Factory>
160  residual_criterion;
161 
166  std::shared_ptr<gko::log::Convergence<>> convergence_logger;
167 
172  std::shared_ptr<gko::stop::Combined::Factory> combined_factory;
173 
179  std::shared_ptr<gko::Executor> executor;
180 
181  private:
188  void
189  initialize_ginkgo_log();
190 
198  std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>> system_matrix;
199 
205  const std::string exec_type;
206  };
207 
208 
214  template <typename ValueType = double, typename IndexType = int32_t>
215  class SolverCG : public SolverBase<ValueType, IndexType>
216  {
217  public:
221  struct AdditionalData
222  {};
223 
235  SolverCG(SolverControl & solver_control,
236  const std::string & exec_type,
237  const AdditionalData &data = AdditionalData());
238 
252  SolverCG(SolverControl & solver_control,
253  const std::string & exec_type,
254  const std::shared_ptr<gko::LinOpFactory> &preconditioner,
255  const AdditionalData & data = AdditionalData());
256 
257  protected:
261  const AdditionalData additional_data;
262  };
263 
264 
270  template <typename ValueType = double, typename IndexType = int32_t>
271  class SolverBicgstab : public SolverBase<ValueType, IndexType>
272  {
273  public:
277  struct AdditionalData
278  {};
279 
291  SolverBicgstab(SolverControl & solver_control,
292  const std::string & exec_type,
293  const AdditionalData &data = AdditionalData());
294 
308  SolverBicgstab(SolverControl & solver_control,
309  const std::string & exec_type,
310  const std::shared_ptr<gko::LinOpFactory> &preconditioner,
311  const AdditionalData &data = AdditionalData());
312 
313  protected:
317  const AdditionalData additional_data;
318  };
319 
328  template <typename ValueType = double, typename IndexType = int32_t>
329  class SolverCGS : public SolverBase<ValueType, IndexType>
330  {
331  public:
335  struct AdditionalData
336  {};
337 
349  SolverCGS(SolverControl & solver_control,
350  const std::string & exec_type,
351  const AdditionalData &data = AdditionalData());
352 
366  SolverCGS(SolverControl & solver_control,
367  const std::string & exec_type,
368  const std::shared_ptr<gko::LinOpFactory> &preconditioner,
369  const AdditionalData &data = AdditionalData());
370 
371  protected:
375  const AdditionalData additional_data;
376  };
377 
395  template <typename ValueType = double, typename IndexType = int32_t>
396  class SolverFCG : public SolverBase<ValueType, IndexType>
397  {
398  public:
402  struct AdditionalData
403  {};
404 
416  SolverFCG(SolverControl & solver_control,
417  const std::string & exec_type,
418  const AdditionalData &data = AdditionalData());
419 
433  SolverFCG(SolverControl & solver_control,
434  const std::string & exec_type,
435  const std::shared_ptr<gko::LinOpFactory> &preconditioner,
436  const AdditionalData &data = AdditionalData());
437 
438  protected:
442  const AdditionalData additional_data;
443  };
444 
450  template <typename ValueType = double, typename IndexType = int32_t>
451  class SolverGMRES : public SolverBase<ValueType, IndexType>
452  {
453  public:
457  struct AdditionalData
458  {
463  AdditionalData(const unsigned int restart_parameter = 30);
464 
468  unsigned int restart_parameter;
469  };
470 
482  SolverGMRES(SolverControl & solver_control,
483  const std::string & exec_type,
484  const AdditionalData &data = AdditionalData());
485 
499  SolverGMRES(SolverControl & solver_control,
500  const std::string & exec_type,
501  const std::shared_ptr<gko::LinOpFactory> &preconditioner,
502  const AdditionalData &data = AdditionalData());
503 
504  protected:
508  const AdditionalData additional_data;
509  };
510 
520  template <typename ValueType = double, typename IndexType = int32_t>
521  class SolverIR : public SolverBase<ValueType, IndexType>
522  {
523  public:
527  struct AdditionalData
528  {};
529 
541  SolverIR(SolverControl & solver_control,
542  const std::string & exec_type,
543  const AdditionalData &data = AdditionalData());
544 
558  SolverIR(SolverControl & solver_control,
559  const std::string & exec_type,
560  const std::shared_ptr<gko::LinOpFactory> &inner_solver,
561  const AdditionalData & data = AdditionalData());
562 
563  protected:
567  const AdditionalData additional_data;
568  };
569 
570 
571 } // namespace GinkgoWrappers
572 
573 DEAL_II_NAMESPACE_CLOSE
574 
575 # endif // DEAL_II_WITH_GINKGO
576 
577 #endif
578 /*---------------------------- ginkgo_solver.h ---------------------------*/
SolverCG
Definition: solver_cg.h:96
SparseMatrix
Definition: mpi.h:94
SolverBase
Definition: solver.h:328
SolverGMRES
Definition: solver_gmres.h:178
SolverBicgstab
Definition: solver_bicgstab.h:124
SolverControl
Definition: solver_control.h:65