deal.II version 9.7.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
sparse_direct.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2001 - 2025 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_sparse_direct_h
16#define dealii_sparse_direct_h
17
18
19
20#include <deal.II/base/config.h>
21
24
28#include <deal.II/lac/vector.h>
29
30#ifdef DEAL_II_WITH_UMFPACK
31# include <umfpack.h>
32#endif
33
34#ifdef DEAL_II_WITH_MUMPS
35# include <dmumps_c.h>
36#endif
37
38#ifdef DEAL_II_WITH_TRILINOS
41#endif
42
43#ifdef DEAL_II_WITH_PETSC
46#endif
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
149
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
189
196
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
245
252
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
344
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
477{
478public:
483
488 {
493 {
494 BlockLowRank(const bool blr_ucfs = false,
495 const double lowrank_threshold = 1e-8)
498 {}
499
500
506
511 };
512
516 AdditionalData(const bool output_details = false,
517 const bool error_statistics = false,
518 const bool symmetric = false,
519 const bool posdef = false,
520 const bool blr_factorization = false,
521 const BlockLowRank &blr = BlockLowRank())
525 , posdef(posdef)
527 , blr(blr)
528 {}
529
534
539
549
558 bool posdef;
559
564
569 };
570
576 const MPI_Comm &communicator = MPI_COMM_WORLD);
577
582
587
593 template <class Matrix>
594 void
595 initialize(const Matrix &matrix);
596
601 template <typename VectorType>
602 void
603 vmult(VectorType &dst, const VectorType &src) const;
604
605
610 template <typename VectorType>
611 void
612 Tvmult(VectorType &, const VectorType &src) const;
613
628 int *
629 get_icntl();
630
631private:
632#ifdef DEAL_II_WITH_MUMPS
633 mutable DMUMPS_STRUC_C id;
634
635#endif // DEAL_II_WITH_MUMPS
636
642 std::unique_ptr<double[]> a;
643
647 mutable std::vector<double> rhs;
648
652 mutable std::vector<types::mumps_index> irhs_loc;
653
657 std::unique_ptr<types::mumps_index[]> irn;
658
662 std::unique_ptr<types::mumps_index[]> jcn;
663
668
673
678
683 template <class Matrix>
684 void
685 initialize_matrix(const Matrix &matrix);
686
690 void
691 copy_solution(Vector<double> &vector) const;
692
696 void
698
703
708};
709
711
712#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
SparseDirectMUMPS(const AdditionalData &additional_data=AdditionalData(), const MPI_Comm &communicator=MPI_COMM_WORLD)
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
types::global_dof_index size_type
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
types::global_dof_index size_type
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:40
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:41
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:32
MUMPS_INT8 mumps_nnz
unsigned int global_dof_index
Definition types.h:94
long int suitesparse_index
MUMPS_INT mumps_index
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())