Reference documentation for deal.II version 9.5.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\}}\)
Loading...
Searching...
No Matches
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
32
33#ifdef DEAL_II_WITH_PETSC
34
35# include <petscconf.h>
36# include <petscksp.h>
37# include <petscmat.h>
38# include <petscpc.h>
39# include <petscsnes.h>
40# include <petscts.h>
41
42# include <string>
43
45
46namespace PETScWrappers
47{
52 inline void
53 set_option_value(const std::string &name, const std::string &value)
54 {
55 const PetscErrorCode ierr =
56 PetscOptionsSetValue(nullptr, name.c_str(), value.c_str());
57 AssertThrow(ierr == 0, ExcPETScError(ierr));
58 }
59
60
61
69 inline void
70 set_matrix_option(Mat & matrix,
71 const MatOption option_name,
72 const PetscBool option_value = PETSC_FALSE)
73 {
74 const PetscErrorCode ierr = MatSetOption(matrix, option_name, option_value);
75 AssertThrow(ierr == 0, ExcPETScError(ierr));
76 }
77
78
79
84 inline void
85 close_matrix(Mat &matrix)
86 {
87# ifdef DEBUG
88 set_matrix_option(matrix, MAT_NEW_NONZERO_LOCATION_ERR, PETSC_TRUE);
89# else
90 set_matrix_option(matrix, MAT_NEW_NONZERO_LOCATIONS, PETSC_FALSE);
91# endif
92 }
93
94
95
101 inline void
103 {
104 set_matrix_option(matrix, MAT_KEEP_NONZERO_PATTERN, PETSC_TRUE);
105 }
106
107
108
112 void
114
115
116
120 void
122
123
127 PetscErrorCode
128 pc_set_failed_reason(PC pc, PCFailedReason reason);
129
130
131
135 void
136 snes_reset_domain_flags(SNES snes);
137
138
139
143 void
145
146
147
157 void
158 set_use_matrix_free(SNES snes, const bool mf_operator, const bool mf);
159
160
161
171 void
172 set_use_matrix_free(TS ts, const bool mf_operator, const bool mf);
173
174
175
179 void
180 ts_set_max_time(TS ts, const PetscReal maxtime);
181
182
183
187 void
188 ts_set_max_steps(TS ts, const PetscInt maxsteps);
189
190
191
195 unsigned int
196 ts_get_step_number(TS ts);
197
198
199
203 bool
204 ts_has_snes(TS ts);
205
206} // namespace PETScWrappers
207
209
210#endif // DEAL_II_WITH_PETSC
211#endif // dealii_petsc_compatibility_h
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#define AssertThrow(cond, exc)
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 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)
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)