Reference documentation for deal.II version GIT 0980a66d4b 2023-03-23 20:20:03+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\}}\)
petsc_compatibility.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2016 - 2020 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 /*
17  * Rather than using ifdefs everywhere, try to wrap older versions of PETSc
18  * functions in one place.
19  */
20 #ifndef dealii_petsc_compatibility_h
21 #define dealii_petsc_compatibility_h
22 
23 #include <deal.II/base/config.h>
24 
25 #include <deal.II/lac/exceptions.h>
26 
27 #ifdef DEAL_II_WITH_PETSC
28 
29 # include <petscconf.h>
30 # include <petscksp.h>
31 # include <petscmat.h>
32 # include <petscpc.h>
33 
34 # include <string>
35 
37 
38 namespace PETScWrappers
39 {
45  inline void
46  set_option_value(const std::string &name, const std::string &value)
47  {
48 # if DEAL_II_PETSC_VERSION_LT(3, 7, 0)
49  const PetscErrorCode ierr =
50  PetscOptionsSetValue(name.c_str(), value.c_str());
51 # else
52  const PetscErrorCode ierr =
53  PetscOptionsSetValue(nullptr, name.c_str(), value.c_str());
54 # endif
55  AssertThrow(ierr == 0, ExcPETScError(ierr));
56  }
57 
58 
59 
69  inline PetscErrorCode
71  {
72  // PETSc will check whether or not matrix is nullptr.
73  return MatDestroy(&matrix);
74  }
75 
76 
77 
88  inline PetscErrorCode
89  destroy_krylov_solver(KSP &krylov_solver)
90  {
91  // PETSc will check whether or not matrix is nullptr.
92  return KSPDestroy(&krylov_solver);
93  }
94 
95 
96 
104  inline void
106  const MatOption option_name,
107  const PetscBool option_value = PETSC_FALSE)
108  {
109  const PetscErrorCode ierr = MatSetOption(matrix, option_name, option_value);
110  AssertThrow(ierr == 0, ExcPETScError(ierr));
111  }
112 
113 
114 
119  inline void
121  {
122 # ifdef DEBUG
123  set_matrix_option(matrix, MAT_NEW_NONZERO_LOCATION_ERR, PETSC_TRUE);
124 # else
125  set_matrix_option(matrix, MAT_NEW_NONZERO_LOCATIONS, PETSC_FALSE);
126 # endif
127  }
128 
129 
130 
136  inline void
138  {
139  set_matrix_option(matrix, MAT_KEEP_NONZERO_PATTERN, PETSC_TRUE);
140  }
141 } // namespace PETScWrappers
142 
144 
145 #endif // DEAL_II_WITH_PETSC
146 #endif // dealii_petsc_compatibility_h
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:474
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:475
#define AssertThrow(cond, exc)
Definition: exceptions.h:1675
@ matrix
Contents is actually a matrix.
void set_option_value(const std::string &name, const std::string &value)
void set_keep_zero_rows(Mat &matrix)
void set_matrix_option(Mat &matrix, const MatOption option_name, const PetscBool option_value=PETSC_FALSE)
PetscErrorCode destroy_krylov_solver(KSP &krylov_solver)
PetscErrorCode destroy_matrix(Mat &matrix)
void close_matrix(Mat &matrix)