18#ifndef LIBMESH_PETSC_SOLVER_EXCEPTION_H
19#define LIBMESH_PETSC_SOLVER_EXCEPTION_H
21#include "libmesh/libmesh_common.h"
23#ifdef LIBMESH_HAVE_PETSC
25#include "libmesh/libmesh_exceptions.h"
26#include "libmesh/petsc_macro.h"
33#include "libmesh/ignore_warnings.h"
35#include "libmesh/restore_warnings.h"
45#ifdef LIBMESH_ENABLE_EXCEPTIONS
57#if PETSC_VERSION_LESS_THAN(3,25,0)
60 const char * specific;
62 auto ierr = PetscErrorMessage(cast_int<PetscErrorCode>(
error_code), &text, &specific);
81#define LIBMESH_CHKERRQ(ierr) \
84 throw libMesh::PetscSolverException(ierr); \
90#define LIBMESH_CHKERRA(comm, ierr) \
92 libmesh_ignore(comm); \
93 LIBMESH_CHKERRQ(ierr); \
100#define LIBMESH_CHKERRQ(ierr) CHKERRQ(ierr);
101#define LIBMESH_CHKERRA(comm, ierr) CHKERRABORT(comm, ierr);
105#define PETSC_BEGIN_END(Function) \
106 template<class ...Args> \
108 void Function ## BeginEnd(const Parallel::Communicator & comm, const Args&... args) \
110 PetscErrorCode ierr = LIBMESH_PETSC_SUCCESS; \
111 ierr = Function ## Begin(args...); \
112 LIBMESH_CHKERRA(comm.get(), ierr); \
113 ierr = Function ## End(args...); \
114 LIBMESH_CHKERRA(comm.get(), ierr); \
117PETSC_BEGIN_END(VecScatter)
118PETSC_BEGIN_END(MatAssembly)
119PETSC_BEGIN_END(VecAssembly)
120PETSC_BEGIN_END(VecGhostUpdate)
123#define LibmeshPetscCallQ(...) \
126 PetscErrorCode libmesh_petsc_call_ierr; \
127 libmesh_petsc_call_ierr = __VA_ARGS__; \
128 LIBMESH_CHKERRQ(libmesh_petsc_call_ierr); \
132#define LibmeshPetscCallA(comm, ...) \
135 PetscErrorCode libmesh_petsc_call_ierr; \
136 libmesh_petsc_call_ierr = __VA_ARGS__; \
137 LIBMESH_CHKERRA(comm, libmesh_petsc_call_ierr); \
142#define LibmeshPetscCall(...) \
143 LibmeshPetscCallA(this->comm().get(), __VA_ARGS__)
147#define LibmeshPetscCall2(comm, ...) \
148 LibmeshPetscCallA(comm.get(), __VA_ARGS__)
150#ifdef LIBMESH_ENABLE_EXCEPTIONS
151#define LibmeshPetscCallExternal(func, ...) \
153 const auto libmesh_petsc_call_external_ierr = cast_int<int>(func(__VA_ARGS__)); \
154 if (libmesh_petsc_call_external_ierr != 0) \
155 throw PetscSolverException(libmesh_petsc_call_external_ierr); \
158#define LibmeshPetscCallExternal(func, ...) \
160 const auto libmesh_petsc_call_external_ierr = cast_int<int>(func(__VA_ARGS__)); \
161 if (libmesh_petsc_call_external_ierr != 0) \
162 libmesh_terminate_handler(); \
A specialization of the SolverException class for PETSc.
PetscSolverException(int error_code_in)
A class representing an exception during a solve.
int error_code
The error code generated by the solver.
std::string what_message
string which holds the message built in the constructor.
The libMesh namespace provides an interface to certain functionality in the library.
void libmesh_ignore(const Args &...)