deal.II version GIT relicensing-7069-g10dda06ddc 2026-11-13 05:10:02+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_snes.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2023 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_petsc_snes_h
14#define dealii_petsc_snes_h
15
16#include <deal.II/base/config.h>
17
18#ifdef DEAL_II_WITH_PETSC
19# include <deal.II/base/mpi.h>
22
26
27# include <petscsnes.h>
28
29# include <exception>
30
31# if defined(DEAL_II_HAVE_CXX20)
32# include <concepts>
33# endif
34
35#endif // DEAL_II_WITH_PETSC
36
38
39#ifdef DEAL_II_WITH_PETSC
40namespace PETScWrappers
41{
157
257 template <typename VectorType = PETScWrappers::VectorBase,
258 typename PMatrixType = PETScWrappers::MatrixBase,
259 typename AMatrixType = PMatrixType>
261 std::constructible_from<VectorType, Vec>) &&
263 std::constructible_from<PMatrixType, Mat>) &&
265 std::constructible_from<AMatrixType, Mat>))
267 {
268 public:
274 using real_type = PetscReal;
275
280 const MPI_Comm mpi_comm = PETSC_COMM_WORLD);
281
286
292 operator SNES() const;
293
297 SNES
299
305
309 void
311
316 void
318
330 void
331 set_matrix(PMatrixType &P);
332
338 void
339 set_matrices(AMatrixType &A, PMatrixType &P);
340
348 unsigned int
349 solve(VectorType &x);
350
360 unsigned int
361 solve(VectorType &x, PMatrixType &P);
362
373 unsigned int
374 solve(VectorType &x, AMatrixType &A, PMatrixType &P);
375
384 std::function<void(const VectorType &x, VectorType &res)> residual;
385
395 std::function<void(const VectorType &x, AMatrixType &A, PMatrixType &P)>
397
410 std::function<void(const VectorType &x,
411 const unsigned int step_number,
412 const real_type f_norm)>
414
428 std::function<void(const VectorType &x)> setup_jacobian;
429
441 std::function<void(const VectorType &src, VectorType &dst)>
443
461 std::function<void(const VectorType &x, real_type &energy_value)> energy;
462
463 private:
467 SNES snes;
468
474
479
485 mutable std::exception_ptr pending_exception;
486 };
487
488} // namespace PETScWrappers
489
490#endif // DEAL_II_WITH_PETSC
491
493
494#endif
void add_parameters(ParameterHandler &prm)
std::function< void(const VectorType &src, VectorType &dst)> solve_with_jacobian
Definition petsc_snes.h:442
void set_matrices(AMatrixType &A, PMatrixType &P)
ObserverPointer< PMatrixType, NonlinearSolver > P
Definition petsc_snes.h:473
std::function< void(const VectorType &x, real_type &energy_value)> energy
Definition petsc_snes.h:461
unsigned int solve(VectorType &x, AMatrixType &A, PMatrixType &P)
std::function< void(const VectorType &x, VectorType &res)> residual
Definition petsc_snes.h:384
unsigned int solve(VectorType &x)
std::exception_ptr pending_exception
Definition petsc_snes.h:485
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:396
std::function< void(const VectorType &x)> setup_jacobian
Definition petsc_snes.h:428
ObserverPointer< AMatrixType, NonlinearSolver > A
Definition petsc_snes.h:472
std::function< void(const VectorType &x, const unsigned int step_number, const real_type f_norm)> monitor
Definition petsc_snes.h:413
void reinit(const NonlinearSolverData &data)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:249
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
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
std::vector< index_type > data
Definition mpi.cc:734