Reference documentation for deal.II version GIT 3e82abc508 2023-06-09 03:50: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 - 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 # include <petscsnes.h>
34 # include <petscts.h>
35 
36 # include <string>
37 
39 
40 namespace PETScWrappers
41 {
46  inline void
47  set_option_value(const std::string &name, const std::string &value)
48  {
49  const PetscErrorCode ierr =
50  PetscOptionsSetValue(nullptr, name.c_str(), value.c_str());
51  AssertThrow(ierr == 0, ExcPETScError(ierr));
52  }
53 
54 
55 
63  inline void
65  const MatOption option_name,
66  const PetscBool option_value = PETSC_FALSE)
67  {
68  const PetscErrorCode ierr = MatSetOption(matrix, option_name, option_value);
69  AssertThrow(ierr == 0, ExcPETScError(ierr));
70  }
71 
72 
73 
78  inline void
80  {
81 # ifdef DEBUG
82  set_matrix_option(matrix, MAT_NEW_NONZERO_LOCATION_ERR, PETSC_TRUE);
83 # else
84  set_matrix_option(matrix, MAT_NEW_NONZERO_LOCATIONS, PETSC_FALSE);
85 # endif
86  }
87 
88 
89 
95  inline void
97  {
98  set_matrix_option(matrix, MAT_KEEP_NONZERO_PATTERN, PETSC_TRUE);
99  }
100 
104  void
106 
110  void
112 
122  void
123  set_use_matrix_free(SNES snes, const bool mf_operator, const bool mf);
124 
134  void
135  set_use_matrix_free(TS ts, const bool mf_operator, const bool mf);
136 
140  void
141  ts_set_max_time(TS ts, const PetscReal maxtime);
142 
146  void
147  ts_set_max_steps(TS ts, const PetscInt maxsteps);
148 
152  unsigned int
153  ts_get_step_number(TS ts);
154 } // namespace PETScWrappers
155 
157 
158 #endif // DEAL_II_WITH_PETSC
159 #endif // dealii_petsc_compatibility_h
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:475
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:476
#define AssertThrow(cond, exc)
Definition: exceptions.h:1703
@ 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 set_keep_zero_rows(Mat &matrix)
void ts_set_max_time(TS ts, const PetscReal maxtime)
void set_matrix_option(Mat &matrix, const MatOption option_name, const PetscBool option_value=PETSC_FALSE)
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)