Reference documentation for deal.II version 9.2.0
\(\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 - 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 /*
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 
70  inline PetscErrorCode
72  {
73  // PETSc will check whether or not matrix is nullptr.
74  return MatDestroy(&matrix);
75  }
76 
77 
78 
89  inline PetscErrorCode
90  destroy_krylov_solver(KSP &krylov_solver)
91  {
92  // PETSc will check whether or not matrix is nullptr.
93  return KSPDestroy(&krylov_solver);
94  }
95 
96 
97 
105  inline void
107  const MatOption option_name,
108  const PetscBool option_value = PETSC_FALSE)
109  {
110  const PetscErrorCode ierr = MatSetOption(matrix, option_name, option_value);
111  AssertThrow(ierr == 0, ExcPETScError(ierr));
112  }
113 
114 
115 
120  inline void
122  {
123 # ifdef DEBUG
124  set_matrix_option(matrix, MAT_NEW_NONZERO_LOCATION_ERR, PETSC_TRUE);
125 # else
126  set_matrix_option(matrix, MAT_NEW_NONZERO_LOCATIONS, PETSC_FALSE);
127 # endif
128  }
129 
130 
131 
137  inline void
139  {
140  set_matrix_option(matrix, MAT_KEEP_NONZERO_PATTERN, PETSC_TRUE);
141  }
142 } // namespace PETScWrappers
143 
145 
146 #endif // DEAL_II_WITH_PETSC
147 #endif // dealii_petsc_compatibility_h
PETScWrappers::destroy_matrix
PetscErrorCode destroy_matrix(Mat &matrix)
Definition: petsc_compatibility.h:71
PETScWrappers
Definition: petsc_block_sparse_matrix.h:36
PETScWrappers::set_option_value
void set_option_value(const std::string &name, const std::string &value)
Definition: petsc_compatibility.h:46
exceptions.h
PETScWrappers::set_matrix_option
void set_matrix_option(Mat &matrix, const MatOption option_name, const PetscBool option_value=PETSC_FALSE)
Definition: petsc_compatibility.h:106
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
PETScWrappers::destroy_krylov_solver
PetscErrorCode destroy_krylov_solver(KSP &krylov_solver)
Definition: petsc_compatibility.h:90
LAPACKSupport::matrix
@ matrix
Contents is actually a matrix.
Definition: lapack_support.h:60
PETScWrappers::set_keep_zero_rows
void set_keep_zero_rows(Mat &matrix)
Definition: petsc_compatibility.h:138
value
static const bool value
Definition: dof_tools_constraints.cc:433
LACExceptions::ExcPETScError
Definition: exceptions.h:56
config.h
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
PETScWrappers::close_matrix
void close_matrix(Mat &matrix)
Definition: petsc_compatibility.h:121
AssertThrow
#define AssertThrow(cond, exc)
Definition: exceptions.h:1531