deal.II version GIT relicensing-2167-g9622207b8f 2024-11-21 12:40:00+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\}}\)
Loading...
Searching...
No Matches
petsc_compatibility.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2016 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15/*
16 * Rather than using ifdefs everywhere, try to wrap older versions of PETSc
17 * functions in one place.
18 *
19 * Functions that are not inlined are:
20 * - Functions returning PetscErrorCode that are supposed to be called within
21 * PETSc callbacks.
22 * - Functions that need access to internal PETSc headers that we don't want
23 * to expose to deal.II users
24 */
25#ifndef dealii_petsc_compatibility_h
26#define dealii_petsc_compatibility_h
27
28#include <deal.II/base/config.h>
29
31
32#ifdef DEAL_II_WITH_PETSC
33
34# include <petscksp.h>
35# include <petscmat.h>
36# include <petscpc.h>
37# include <petscsnes.h>
38# include <petscts.h>
39# if DEAL_II_PETSC_VERSION_LT(3, 19, 0)
40# define PETSC_SUCCESS 0
41# endif
42
43# include <string>
44
46
47namespace PETScWrappers
48{
53 inline void
54 set_option_value(const std::string &name, const std::string &value)
55 {
56 const PetscErrorCode ierr =
57 PetscOptionsSetValue(nullptr, name.c_str(), value.c_str());
58 AssertThrow(ierr == 0, ExcPETScError(ierr));
59 }
60
61
62
70 inline void
71 set_matrix_option(Mat &matrix,
72 const MatOption option_name,
73 const PetscBool option_value = PETSC_FALSE)
74 {
75 const PetscErrorCode ierr = MatSetOption(matrix, option_name, option_value);
76 AssertThrow(ierr == 0, ExcPETScError(ierr));
77 }
78
79
80
85 inline void
86 close_matrix(Mat &matrix)
87 {
88# ifdef DEBUG
89 set_matrix_option(matrix, MAT_NEW_NONZERO_LOCATION_ERR, PETSC_TRUE);
90# else
91 set_matrix_option(matrix, MAT_NEW_NONZERO_LOCATIONS, PETSC_FALSE);
92# endif
93 }
94
95
96
102 inline void
104 {
105 set_matrix_option(matrix, MAT_KEEP_NONZERO_PATTERN, PETSC_TRUE);
106 }
107
108
109
113 void
115
116
117
121 void
123
124
128 PetscErrorCode
129 pc_set_failed_reason(PC pc, PCFailedReason reason);
130
131
132
136 void
137 snes_reset_domain_flags(SNES snes);
138
139
140
144 void
146
147
148
158 void
159 set_use_matrix_free(SNES snes, const bool mf_operator, const bool mf);
160
161
162
172 void
173 set_use_matrix_free(TS ts, const bool mf_operator, const bool mf);
174
175
176
180 void
181 ts_reset_dm(TS ts);
182
183
184
188 void
189 ts_set_max_time(TS ts, const PetscReal maxtime);
190
191
192
196 void
197 ts_set_max_steps(TS ts, const PetscInt maxsteps);
198
199
200
204 unsigned int
205 ts_get_step_number(TS ts);
206
207
208
212 bool
213 ts_has_snes(TS ts);
214
215} // namespace PETScWrappers
216
218
219#endif // DEAL_II_WITH_PETSC
220#endif // dealii_petsc_compatibility_h
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
#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)