Reference documentation for deal.II version GIT 29f9da0a34 2023-12-07 10:00:01+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 - 2023 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  * Functions that are not inlined are:
21  * - Functions returning PetscErrorCode that are supposed to be called within
22  * PETSc callbacks.
23  * - Functions that need access to internal PETSc headers that we don't want
24  * to expose to deal.II users
25  */
26 #ifndef dealii_petsc_compatibility_h
27 #define dealii_petsc_compatibility_h
28 
29 #include <deal.II/base/config.h>
30 
31 #include <deal.II/lac/exceptions.h>
32 
33 #ifdef DEAL_II_WITH_PETSC
34 
35 # include <petscksp.h>
36 # include <petscmat.h>
37 # include <petscpc.h>
38 # include <petscsnes.h>
39 # include <petscts.h>
40 # if DEAL_II_PETSC_VERSION_LT(3, 19, 0)
41 # define PETSC_SUCCESS 0
42 # endif
43 
44 # include <string>
45 
47 
48 namespace PETScWrappers
49 {
54  inline void
55  set_option_value(const std::string &name, const std::string &value)
56  {
57  const PetscErrorCode ierr =
58  PetscOptionsSetValue(nullptr, name.c_str(), value.c_str());
59  AssertThrow(ierr == 0, ExcPETScError(ierr));
60  }
61 
62 
63 
71  inline void
73  const MatOption option_name,
74  const PetscBool option_value = PETSC_FALSE)
75  {
76  const PetscErrorCode ierr = MatSetOption(matrix, option_name, option_value);
77  AssertThrow(ierr == 0, ExcPETScError(ierr));
78  }
79 
80 
81 
86  inline void
88  {
89 # ifdef DEBUG
90  set_matrix_option(matrix, MAT_NEW_NONZERO_LOCATION_ERR, PETSC_TRUE);
91 # else
92  set_matrix_option(matrix, MAT_NEW_NONZERO_LOCATIONS, PETSC_FALSE);
93 # endif
94  }
95 
96 
97 
103  inline void
105  {
106  set_matrix_option(matrix, MAT_KEEP_NONZERO_PATTERN, PETSC_TRUE);
107  }
108 
109 
110 
114  void
116 
117 
118 
122  void
124 
125 
129  PetscErrorCode
130  pc_set_failed_reason(PC pc, PCFailedReason reason);
131 
132 
133 
137  void
138  snes_reset_domain_flags(SNES snes);
139 
140 
141 
145  void
147 
148 
149 
159  void
160  set_use_matrix_free(SNES snes, const bool mf_operator, const bool mf);
161 
162 
163 
173  void
174  set_use_matrix_free(TS ts, const bool mf_operator, const bool mf);
175 
176 
177 
181  void
182  ts_reset_dm(TS ts);
183 
184 
185 
189  void
190  ts_set_max_time(TS ts, const PetscReal maxtime);
191 
192 
193 
197  void
198  ts_set_max_steps(TS ts, const PetscInt maxsteps);
199 
200 
201 
205  unsigned int
206  ts_get_step_number(TS ts);
207 
208 
209 
213  bool
214  ts_has_snes(TS ts);
215 
216 } // namespace PETScWrappers
217 
219 
220 #endif // DEAL_II_WITH_PETSC
221 #endif // dealii_petsc_compatibility_h
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:477
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
#define AssertThrow(cond, exc)
Definition: exceptions.h:1732
@ matrix
Contents is actually a matrix.
static const char A
void set_use_matrix_free(SNES snes, const bool mf_operator, const bool mf)
void set_option_value(const std::string &name, const std::string &value)
void ts_reset_dm(TS ts)
void set_keep_zero_rows(Mat &matrix)
PetscErrorCode pc_set_failed_reason(PC pc, PCFailedReason reason)
void ts_set_max_time(TS ts, const PetscReal maxtime)
void snes_reset_domain_flags(SNES snes)
void set_matrix_option(Mat &matrix, const MatOption option_name, const PetscBool option_value=PETSC_FALSE)
void snes_set_jacobian_domain_error(SNES snes)
bool ts_has_snes(TS ts)
void ts_set_max_steps(TS ts, const PetscInt maxsteps)
void petsc_increment_state_counter(Vec v)
void close_matrix(Mat &matrix)
unsigned int ts_get_step_number(TS ts)