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.cc
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 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. This file contains functions that need access to
19 * internal PETSc headers that we don't want to expose to deal.II users
20 */
22
23#ifdef DEAL_II_WITH_PETSC
24
25# include <petsc/private/pcimpl.h>
26# include <petsc/private/petscimpl.h>
27# include <petsc/private/snesimpl.h>
28# include <petsc/private/tsimpl.h>
29
30// Shorthand notation for PETSc error codes.
31# define AssertPETSc(code) \
32 do \
33 { \
34 PetscErrorCode ierr = (code); \
35 AssertThrow(ierr == 0, ExcPETScError(ierr)); \
36 } \
37 while (0)
38
40
41
42namespace PETScWrappers
43{
44 void
46 {
47 AssertPETSc(PetscObjectStateIncrease(reinterpret_cast<PetscObject>(v)));
48 }
49
50 void
52 {
53 AssertPETSc(PetscObjectStateIncrease(reinterpret_cast<PetscObject>(A)));
54 }
55
56 PetscErrorCode
57 pc_set_failed_reason(PC pc, PCFailedReason reason)
58 {
59# if DEAL_II_PETSC_VERSION_GTE(3, 14, 0)
60 return PCSetFailedReason(pc, reason);
61# else
62 pc->failedreason = reason;
63 return 0;
64# endif
65 }
66
67 void
69 {
70# if DEAL_II_PETSC_VERSION_GTE(3, 11, 0)
71 snes->jacobiandomainerror = PETSC_FALSE;
72# endif
73 snes->domainerror = PETSC_FALSE;
74 }
75
76 void
78 {
79# if DEAL_II_PETSC_VERSION_GTE(3, 11, 0)
80 snes->jacobiandomainerror = PETSC_TRUE;
81# else
82 // There is no equivalent, and since this used to stop
83 // computations, we opt to set the converged reason
84 snes->reason = SNES_DIVERGED_FUNCTION_DOMAIN;
85# endif
86 }
87
88 void
89 set_use_matrix_free(SNES snes, bool mf_operator, bool mf)
90 {
91# if DEAL_II_PETSC_VERSION_LT(3, 13, 1)
92 snes->mf = mf ? PETSC_TRUE : PETSC_FALSE;
93 snes->mf_operator = mf_operator ? PETSC_TRUE : PETSC_FALSE;
94# else
95 AssertPETSc(SNESSetUseMatrixFree(snes,
96 mf_operator ? PETSC_TRUE : PETSC_FALSE,
97 mf ? PETSC_TRUE : PETSC_FALSE));
98# endif
99 }
100
101 void
102 set_use_matrix_free(TS ts, const bool mf_operator, const bool mf)
103 {
104 SNES snes;
105 AssertPETSc(TSGetSNES(ts, &snes));
106 set_use_matrix_free(snes, mf_operator, mf);
107 }
108
109 void
110 ts_set_max_steps(TS ts, const PetscInt maxsteps)
111 {
112# if DEAL_II_PETSC_VERSION_LT(3, 8, 0)
113 if (maxsteps >= 0)
114 ts->max_steps = maxsteps;
115# else
116 AssertPETSc(TSSetMaxSteps(ts, maxsteps));
117# endif
118 }
119
120 void
121 ts_set_max_time(TS ts, const PetscReal maxtime)
122 {
123# if DEAL_II_PETSC_VERSION_LT(3, 8, 0)
124 if (maxtime != PETSC_DEFAULT)
125 ts->max_time = maxtime;
126# else
127 AssertPETSc(TSSetMaxTime(ts, maxtime));
128# endif
129 }
130
131 unsigned int
133 {
134 PetscInt step;
135# if DEAL_II_PETSC_VERSION_LT(3, 8, 0)
136 step = ts->steps;
137# else
138 AssertPETSc(TSGetStepNumber(ts, &step));
139# endif
140 return static_cast<unsigned int>(step);
141 }
142
143 bool
145 {
146 return ts->snes ? true : false;
147 }
148
149} // namespace PETScWrappers
150
152
153#endif // DEAL_II_WITH_PETSC
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
void set_use_matrix_free(SNES snes, const bool mf_operator, const bool mf)
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 snes_set_jacobian_domain_error(SNES snes)
void ts_set_max_steps(TS ts, const PetscInt maxsteps)
void petsc_increment_state_counter(Vec v)
unsigned int ts_get_step_number(TS ts)
#define AssertPETSc(code)