Reference documentation for deal.II version 9.6.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_snes.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 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#ifndef dealii_petsc_snes_h
16#define dealii_petsc_snes_h
17
18#include <deal.II/base/config.h>
19
20#ifdef DEAL_II_WITH_PETSC
21# include <deal.II/base/mpi.h>
24
28
29# include <petscsnes.h>
30
31# include <exception>
32
33# if defined(DEAL_II_HAVE_CXX20)
34# include <concepts>
35# endif
36
37
39
40namespace PETScWrappers
41{
157
257 template <typename VectorType = PETScWrappers::VectorBase,
258 typename PMatrixType = PETScWrappers::MatrixBase,
259 typename AMatrixType = PMatrixType>
262 std::constructible_from<
263 VectorType,
265 std::constructible_from<
266 PMatrixType,
268 std::constructible_from<AMatrixType, Mat>))
270 {
271 public:
277 using real_type = PetscReal;
278
283 const MPI_Comm mpi_comm = PETSC_COMM_WORLD);
284
289
295 operator SNES() const;
296
300 SNES
302
308
312 void
314
319 void
321
333 void
334 set_matrix(PMatrixType &P);
335
341 void
342 set_matrices(AMatrixType &A, PMatrixType &P);
343
351 unsigned int
352 solve(VectorType &x);
353
363 unsigned int
364 solve(VectorType &x, PMatrixType &P);
365
376 unsigned int
377 solve(VectorType &x, AMatrixType &A, PMatrixType &P);
378
387 std::function<void(const VectorType &x, VectorType &res)> residual;
388
398 std::function<void(const VectorType &x, AMatrixType &A, PMatrixType &P)>
400
413 std::function<void(const VectorType &x,
414 const unsigned int step_number,
415 const real_type f_norm)>
417
431 std::function<void(const VectorType &x)> setup_jacobian;
432
444 std::function<void(const VectorType &src, VectorType &dst)>
446
464 std::function<void(const VectorType &x, real_type &energy_value)> energy;
465
466 private:
470 SNES snes;
471
477
482
488 mutable std::exception_ptr pending_exception;
489 };
490
491} // namespace PETScWrappers
492
494
495#endif // DEAL_II_WITH_PETSC
496
497#endif
void add_parameters(ParameterHandler &prm)
std::function< void(const VectorType &src, VectorType &dst)> solve_with_jacobian
Definition petsc_snes.h:445
void set_matrices(AMatrixType &A, PMatrixType &P)
std::function< void(const VectorType &x, real_type &energy_value)> energy
Definition petsc_snes.h:464
SmartPointer< PMatrixType, NonlinearSolver > P
Definition petsc_snes.h:476
unsigned int solve(VectorType &x, AMatrixType &A, PMatrixType &P)
std::function< void(const VectorType &x, VectorType &res)> residual
Definition petsc_snes.h:387
unsigned int solve(VectorType &x)
std::exception_ptr pending_exception
Definition petsc_snes.h:488
NonlinearSolver(const NonlinearSolverData &data=NonlinearSolverData(), const MPI_Comm mpi_comm=PETSC_COMM_WORLD)
MPI_Comm get_mpi_communicator() const
void set_matrix(PMatrixType &P)
unsigned int solve(VectorType &x, PMatrixType &P)
std::function< void(const VectorType &x, AMatrixType &A, PMatrixType &P)> jacobian
Definition petsc_snes.h:399
std::function< void(const VectorType &x)> setup_jacobian
Definition petsc_snes.h:431
SmartPointer< AMatrixType, NonlinearSolver > A
Definition petsc_snes.h:475
std::function< void(const VectorType &x, const unsigned int step_number, const real_type f_norm)> monitor
Definition petsc_snes.h:416
void reinit(const NonlinearSolverData &data)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:177
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
NonlinearSolverData(const std::string &options_prefix="", const std::string &snes_type="", const std::string &snes_linesearch_type="", const real_type absolute_tolerance=0, const real_type relative_tolerance=0, const real_type step_tolerance=0, const int maximum_non_linear_iterations=-1, const int max_n_function_evaluations=-1)
Definition petsc_snes.h:74