deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+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
sparse_direct.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) 2001 - 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_sparse_direct_h
14#define dealii_sparse_direct_h
15
16
17
18#include <deal.II/base/config.h>
19
22
26#include <deal.II/lac/vector.h>
27
28#ifdef DEAL_II_WITH_UMFPACK
29# include <umfpack.h>
30#endif
31
32#ifdef DEAL_II_WITH_MUMPS
33# include <dmumps_c.h>
34#endif
35
36#ifdef DEAL_II_WITH_TRILINOS
39#endif
40
41#ifdef DEAL_II_WITH_PETSC
44#endif
45
46#include <complex>
47
49
50namespace types
51{
56#ifdef SuiteSparse_long
57 using suitesparse_index = SuiteSparse_long;
58#else
59 using suitesparse_index = long int;
60#endif
61
62#ifdef DEAL_II_WITH_MUMPS
63 using mumps_index = MUMPS_INT;
64 using mumps_nnz = MUMPS_INT8;
65#else
66 using mumps_index = int;
67 using mumps_nnz = std::size_t;
68#endif
69
70
71} // namespace types
72
117{
118public:
123
129 {};
130
131
137
141 ~SparseDirectUMFPACK() override;
142
154 void
155 initialize(const SparsityPattern &sparsity_pattern);
156
174 template <class Matrix>
175 void
176 factorize(const Matrix &matrix);
177
181 template <class Matrix>
182 void
183 initialize(const Matrix &matrix,
184 const AdditionalData additional_data = AdditionalData());
185
206 void
207 vmult(Vector<double> &dst, const Vector<double> &src) const;
208
212 void
213 vmult(BlockVector<double> &dst, const BlockVector<double> &src) const;
214
219 void
220 Tvmult(Vector<double> &dst, const Vector<double> &src) const;
221
225 void
226 Tvmult(BlockVector<double> &dst, const BlockVector<double> &src) const;
227
233 m() const;
234
240 n() const;
241
270 void
271 solve(Vector<double> &rhs_and_solution, const bool transpose = false) const;
272
284 void
285 solve(Vector<std::complex<double>> &rhs_and_solution,
286 const bool transpose = false) const;
287
291 void
292 solve(BlockVector<double> &rhs_and_solution,
293 const bool transpose = false) const;
294
298 void
299 solve(BlockVector<std::complex<double>> &rhs_and_solution,
300 const bool transpose = false) const;
301
308 template <class Matrix>
309 void
310 solve(const Matrix &matrix,
311 Vector<double> &rhs_and_solution,
312 const bool transpose = false);
313
317 template <class Matrix>
318 void
319 solve(const Matrix &matrix,
320 Vector<std::complex<double>> &rhs_and_solution,
321 const bool transpose = false);
322
326 template <class Matrix>
327 void
328 solve(const Matrix &matrix,
329 BlockVector<double> &rhs_and_solution,
330 const bool transpose = false);
331
335 template <class Matrix>
336 void
337 solve(const Matrix &matrix,
338 BlockVector<std::complex<double>> &rhs_and_solution,
339 const bool transpose = false);
340
352 std::string,
353 int,
354 << "UMFPACK routine " << arg1 << " returned error status " << arg2 << '.'
355 << "\n\n"
356 << ("A complete list of error codes can be found in the file "
357 "<bundled/umfpack/UMFPACK/Include/umfpack.h>."
358 "\n\n"
359 "That said, the two most common errors that can happen are "
360 "that your matrix cannot be factorized because it is "
361 "rank deficient, and that UMFPACK runs out of memory "
362 "because your problem is too large."
363 "\n\n"
364 "The first of these cases most often happens if you "
365 "forget terms in your bilinear form necessary to ensure "
366 "that the matrix has full rank, or if your equation has a "
367 "spatially variable coefficient (or nonlinearity) that is "
368 "supposed to be strictly positive but, for whatever "
369 "reasons, is negative or zero. In either case, you probably "
370 "want to check your assembly procedure. Similarly, a "
371 "matrix can be rank deficient if you forgot to apply the "
372 "appropriate boundary conditions. For example, the "
373 "Laplace equation for a problem where only Neumann boundary "
374 "conditions are posed (or where you forget to apply Dirichlet "
375 "boundary conditions) has exactly one eigenvalue equal to zero "
376 "and its rank is therefore deficient by one. Finally, the matrix "
377 "may be rank deficient because you are using a quadrature "
378 "formula with too few quadrature points."
379 "\n\n"
380 "The other common situation is that you run out of memory. "
381 "On a typical laptop or desktop, it should easily be possible "
382 "to solve problems with 100,000 unknowns in 2d. If you are "
383 "solving problems with many more unknowns than that, in "
384 "particular if you are in 3d, then you may be running out "
385 "of memory and you will need to consider iterative "
386 "solvers instead of the direct solver employed by "
387 "UMFPACK."));
388
389private:
394
400
408
412 void
413 clear();
414
421 template <typename number>
422 void
424
425 template <typename number>
426 void
428
429 template <typename number>
430 void
432
444 std::vector<types::suitesparse_index> Ap;
445 std::vector<types::suitesparse_index> Ai;
446 std::vector<double> Ax;
447 std::vector<double> Az;
448
452 std::vector<double> control;
453};
454
455
456
480{
481public:
486
491 {
496 {
497 BlockLowRank(const bool blr_ucfs = false,
498 const double lowrank_threshold = 1e-8)
501 {}
502
503
509
514 };
515
519 AdditionalData(const bool output_details = false,
520 const bool error_statistics = false,
521 const bool symmetric = false,
522 const bool posdef = false,
523 const bool blr_factorization = false,
524 const BlockLowRank &blr = BlockLowRank())
528 , posdef(posdef)
530 , blr(blr)
531 {}
532
537
542
552
561 bool posdef;
562
567
572 };
573
579 const MPI_Comm &communicator = MPI_COMM_WORLD);
580
585
590
596 template <class Matrix>
597 void
598 initialize(const Matrix &matrix);
599
604 template <typename VectorType>
605 void
606 vmult(VectorType &dst, const VectorType &src) const;
607
608
613 template <typename VectorType>
614 void
615 Tvmult(VectorType &, const VectorType &src) const;
616
631 int *
632 get_icntl();
633
634private:
635#ifdef DEAL_II_WITH_MUMPS
636 mutable DMUMPS_STRUC_C id;
637
638#endif // DEAL_II_WITH_MUMPS
639
645 std::unique_ptr<double[]> a;
646
650 mutable std::vector<double> rhs;
651
655 mutable std::vector<types::mumps_index> irhs_loc;
656
660 std::unique_ptr<types::mumps_index[]> irn;
661
665 std::unique_ptr<types::mumps_index[]> jcn;
666
671
676
681
686 template <class Matrix>
687 void
688 initialize_matrix(const Matrix &matrix);
689
693 void
694 copy_solution(Vector<double> &vector) const;
695
699 void
701
706
711};
712
714
715#endif // dealii_sparse_direct_h
void copy_solution(Vector< double > &vector) const
void initialize_matrix(const Matrix &matrix)
void initialize(const Matrix &matrix)
std::vector< double > rhs
std::unique_ptr< double[]> a
void copy_rhs_to_mumps(const Vector< double > &rhs) const
types::global_dof_index n
const MPI_Comm mpi_communicator
DMUMPS_STRUC_C id
std::unique_ptr< types::mumps_index[]> irn
std::unique_ptr< types::mumps_index[]> jcn
std::vector< types::mumps_index > irhs_loc
void vmult(VectorType &dst, const VectorType &src) const
types::mumps_nnz nnz
IndexSet locally_owned_rows
AdditionalData additional_data
void Tvmult(VectorType &, const VectorType &src) const
std::vector< double > Az
~SparseDirectUMFPACK() override
void initialize(const SparsityPattern &sparsity_pattern)
void Tvmult(Vector< double > &dst, const Vector< double > &src) const
size_type m() const
void solve(Vector< double > &rhs_and_solution, const bool transpose=false) const
std::vector< double > Ax
void sort_arrays(const SparseMatrixEZ< number > &)
size_type n() const
void factorize(const Matrix &matrix)
std::vector< double > control
void vmult(Vector< double > &dst, const Vector< double > &src) const
std::vector< types::suitesparse_index > Ap
std::vector< types::suitesparse_index > Ai
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
#define DeclException0(Exception0)
static ::ExceptionBase & ExcUMFPACKError(std::string arg1, int arg2)
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcInitializeAlreadyCalled()
Definition types.h:30
MUMPS_INT mumps_index
unsigned int global_dof_index
Definition types.h:92
long int suitesparse_index
MUMPS_INT8 mumps_nnz
BlockLowRank(const bool blr_ucfs=false, const double lowrank_threshold=1e-8)
AdditionalData(const bool output_details=false, const bool error_statistics=false, const bool symmetric=false, const bool posdef=false, const bool blr_factorization=false, const BlockLowRank &blr=BlockLowRank())