4#include <deal.II/base/config.h>
10#if defined(DEAL_II_WITH_PETSC) && defined(DEAL_II_PETSC_WITH_MUMPS)
12#include <deal.II/lac/petsc_solver.h>
13#include <deal.II/lac/solver_control.h>
43 template <
typename SparseMatrixType,
typename VectorType>
44 class PETScDirect :
public AbstractLinearSolver<SparseMatrixType, VectorType>
47 static constexpr bool performs_factorization =
false;
49 PETScDirect() : matrix(nullptr) {}
51 void init(
const SparseMatrixType &matrix)
53 this->matrix = &matrix;
59 bool invert() {
return false; }
61 int solve(
const VectorType &src, VectorType &dst,
const double tol)
63 if (!matrix)
throw std::runtime_error(
"PETScDirect::solve: matrix not initialized");
68 control = std::make_unique<dealii::SolverControl>(1, tol);
69 solver = std::make_unique<dealii::PETScWrappers::SparseDirectMUMPS>(*control);
71 control->set_tolerance(tol);
75 solver->solve(*matrix, dst, src);
76 }
catch (std::exception &e) {
77 std::cerr <<
"PETSc MUMPS direct solver failed: " << e.what() << std::endl;
81 return control->last_step();
85 const SparseMatrixType *matrix;
88 std::unique_ptr<dealii::SolverControl> control;
89 std::unique_ptr<dealii::PETScWrappers::SparseDirectMUMPS> solver;
Definition complex_math.hh:10