Reference documentation for deal.II version Git 7026f387cc 2019-10-15 14:19:01 -0400
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
petsc_solver.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2018 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_petsc_solver_h
17 # define dealii_petsc_solver_h
18 
19 
20 # include <deal.II/base/config.h>
21 
22 # ifdef DEAL_II_WITH_PETSC
23 
24 # include <deal.II/lac/exceptions.h>
25 # include <deal.II/lac/solver_control.h>
26 
27 # include <petscksp.h>
28 
29 # include <memory>
30 
31 # ifdef DEAL_II_WITH_SLEPC
32 # include <deal.II/lac/slepc_spectral_transformation.h>
33 # endif
34 
35 DEAL_II_NAMESPACE_OPEN
36 
37 // Forward declarations
38 # ifndef DOXYGEN
39 # ifdef DEAL_II_WITH_SLEPC
40 namespace SLEPcWrappers
41 {
42  // forward declarations
43  class TransformationBase;
44 } // namespace SLEPcWrappers
45 # endif
46 # endif
47 
48 namespace PETScWrappers
49 {
50  // forward declarations
51 # ifndef DOXYGEN
52  class MatrixBase;
53  class VectorBase;
54  class PreconditionerBase;
55 # endif
56 
57 
114  {
115  public:
125  SolverBase(SolverControl &cn, const MPI_Comm &mpi_communicator);
126 
130  virtual ~SolverBase() = default;
131 
139  void
140  solve(const MatrixBase & A,
141  VectorBase & x,
142  const VectorBase & b,
143  const PreconditionerBase &preconditioner);
144 
145 
150  virtual void
151  reset();
152 
153 
158  void
159  set_prefix(const std::string &prefix);
160 
161 
165  SolverControl &
166  control() const;
167 
172  void
173  initialize(const PreconditionerBase &preconditioner);
174 
175  protected:
183 
187  const MPI_Comm mpi_communicator;
188 
193  virtual void
194  set_solver_type(KSP &ksp) const = 0;
195 
202  std::string prefix_name;
203 
204  private:
211  static PetscErrorCode
212  convergence_test(KSP ksp,
213  const PetscInt iteration,
214  const PetscReal residual_norm,
215  KSPConvergedReason *reason,
216  void * solver_control);
217 
235  struct SolverData
236  {
240  ~SolverData();
241 
245  KSP ksp;
246  };
247 
252  std::unique_ptr<SolverData> solver_data;
253 
254 # ifdef DEAL_II_WITH_SLEPC
255  // Make the transformation class a friend, since it needs to set the KSP
256  // solver.
258 # endif
259  };
260 
261 
262 
271  {
272  public:
277  {
281  explicit AdditionalData(const double omega = 1);
282 
286  double omega;
287  };
288 
306  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
307  const AdditionalData &data = AdditionalData());
308 
309  protected:
314 
319  virtual void
320  set_solver_type(KSP &ksp) const override;
321  };
322 
323 
324 
333  {
334  public:
339  {};
340 
358  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
359  const AdditionalData &data = AdditionalData());
360 
361  protected:
366 
371  virtual void
372  set_solver_type(KSP &ksp) const override;
373  };
374 
375 
376 
383  class SolverCG : public SolverBase
384  {
385  public:
390  {};
391 
408  SolverCG(SolverControl & cn,
409  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
410  const AdditionalData &data = AdditionalData());
411 
412  protected:
417 
422  virtual void
423  set_solver_type(KSP &ksp) const override;
424  };
425 
426 
427 
434  class SolverBiCG : public SolverBase
435  {
436  public:
441  {};
442 
460  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
461  const AdditionalData &data = AdditionalData());
462 
463  protected:
468 
473  virtual void
474  set_solver_type(KSP &ksp) const override;
475  };
476 
477 
478 
485  class SolverGMRES : public SolverBase
486  {
487  public:
492  {
497  AdditionalData(const unsigned int restart_parameter = 30,
498  const bool right_preconditioning = false);
499 
503  unsigned int restart_parameter;
504 
509  };
510 
528  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
529  const AdditionalData &data = AdditionalData());
530 
531  protected:
536 
541  virtual void
542  set_solver_type(KSP &ksp) const override;
543  };
544 
545 
546 
554  class SolverBicgstab : public SolverBase
555  {
556  public:
561  {};
562 
580  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
581  const AdditionalData &data = AdditionalData());
582 
583  protected:
588 
593  virtual void
594  set_solver_type(KSP &ksp) const override;
595  };
596 
604  class SolverCGS : public SolverBase
605  {
606  public:
611  {};
612 
630  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
631  const AdditionalData &data = AdditionalData());
632 
633  protected:
638 
643  virtual void
644  set_solver_type(KSP &ksp) const override;
645  };
646 
647 
648 
655  class SolverTFQMR : public SolverBase
656  {
657  public:
662  {};
663 
681  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
682  const AdditionalData &data = AdditionalData());
683 
684  protected:
689 
694  virtual void
695  set_solver_type(KSP &ksp) const override;
696  };
697 
698 
699 
711  class SolverTCQMR : public SolverBase
712  {
713  public:
718  {};
719 
737  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
738  const AdditionalData &data = AdditionalData());
739 
740  protected:
745 
750  virtual void
751  set_solver_type(KSP &ksp) const override;
752  };
753 
754 
755 
762  class SolverCR : public SolverBase
763  {
764  public:
769  {};
770 
787  SolverCR(SolverControl & cn,
788  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
789  const AdditionalData &data = AdditionalData());
790 
791  protected:
796 
801  virtual void
802  set_solver_type(KSP &ksp) const override;
803  };
804 
805 
806 
814  class SolverLSQR : public SolverBase
815  {
816  public:
821  {};
822 
840  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
841  const AdditionalData &data = AdditionalData());
842 
843  protected:
848 
853  virtual void
854  set_solver_type(KSP &ksp) const override;
855  };
856 
857 
870  class SolverPreOnly : public SolverBase
871  {
872  public:
877  {};
878 
896  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
897  const AdditionalData &data = AdditionalData());
898 
899  protected:
904 
909  virtual void
910  set_solver_type(KSP &ksp) const override;
911  };
912 
938  {
939  public:
944  {};
949  const MPI_Comm & mpi_communicator = PETSC_COMM_SELF,
950  const AdditionalData &data = AdditionalData());
951 
955  void
956  solve(const MatrixBase &A, VectorBase &x, const VectorBase &b);
957 
963  void
964  set_symmetric_mode(const bool flag);
965 
966  protected:
971 
972  virtual void
973  set_solver_type(KSP &ksp) const override;
974 
975  private:
982  static PetscErrorCode
983  convergence_test(KSP ksp,
984  const PetscInt iteration,
985  const PetscReal residual_norm,
986  KSPConvergedReason *reason,
987  void * solver_control);
988 
995  {
999  ~SolverDataMUMPS();
1000 
1001  KSP ksp;
1002  PC pc;
1003  };
1004 
1005  std::unique_ptr<SolverDataMUMPS> solver_data;
1006 
1012  };
1013 } // namespace PETScWrappers
1014 
1015 DEAL_II_NAMESPACE_CLOSE
1016 
1017 # endif // DEAL_II_WITH_PETSC
1018 
1019 /*---------------------------- petsc_solver.h ---------------------------*/
1020 
1021 #endif
1022 /*---------------------------- petsc_solver.h ---------------------------*/
const AdditionalData additional_data
Definition: petsc_solver.h:416
const AdditionalData additional_data
Definition: petsc_solver.h:847
const AdditionalData additional_data
Definition: petsc_solver.h:313
const AdditionalData additional_data
Definition: petsc_solver.h:365
const AdditionalData additional_data
Definition: petsc_solver.h:744
const AdditionalData additional_data
Definition: petsc_solver.h:535
const MPI_Comm mpi_communicator
Definition: petsc_solver.h:187
std::unique_ptr< SolverData > solver_data
Definition: petsc_solver.h:252
const AdditionalData additional_data
Definition: petsc_solver.h:903
SolverControl & solver_control
Definition: petsc_solver.h:182
const AdditionalData additional_data
Definition: petsc_solver.h:467
const AdditionalData additional_data
Definition: petsc_solver.h:587
const AdditionalData additional_data
Definition: petsc_solver.h:970
const AdditionalData additional_data
Definition: petsc_solver.h:637
const AdditionalData additional_data
Definition: petsc_solver.h:795
const AdditionalData additional_data
Definition: petsc_solver.h:688