Reference documentation for deal.II version 8.4.2
sparse_direct.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2001 - 2016 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__sparse_direct_h
17 #define dealii__sparse_direct_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/exceptions.h>
22 #include <deal.II/base/subscriptor.h>
23 #include <deal.II/base/thread_management.h>
24 #include <deal.II/lac/vector.h>
25 #include <deal.II/lac/sparse_matrix.h>
26 #include <deal.II/lac/sparse_matrix_ez.h>
27 #include <deal.II/lac/block_sparse_matrix.h>
28 
29 #ifdef DEAL_II_WITH_UMFPACK
30 # include <umfpack.h>
31 #endif
32 #ifndef SuiteSparse_long
33 # define SuiteSparse_long long int
34 #endif
35 
36 DEAL_II_NAMESPACE_OPEN
37 
81 {
82 public:
87 
93  {};
94 
95 
101 
106 
118  void initialize (const SparsityPattern &sparsity_pattern);
119 
137  template <class Matrix>
138  void factorize (const Matrix &matrix);
139 
143  template <class Matrix>
144  void initialize(const Matrix &matrix,
145  const AdditionalData additional_data = AdditionalData());
146 
167  void vmult (Vector<double> &dst,
168  const Vector<double> &src) const;
169 
173  void vmult (BlockVector<double> &dst,
174  const BlockVector<double> &src) const;
175 
180  void Tvmult (Vector<double> &dst,
181  const Vector<double> &src) const;
182 
186  void Tvmult (BlockVector<double> &dst,
187  const BlockVector<double> &src) const;
188 
193  size_type m () const;
194 
199  size_type n () const;
200 
227  void solve (Vector<double> &rhs_and_solution, bool transpose = false) const;
228 
232  void solve (BlockVector<double> &rhs_and_solution, bool transpose = false) const;
233 
240  template <class Matrix>
241  void solve (const Matrix &matrix,
242  Vector<double> &rhs_and_solution,
243  bool transpose = false);
244 
248  template <class Matrix>
249  void solve (const Matrix &matrix,
250  BlockVector<double> &rhs_and_solution,
251  bool transpose = false);
252 
262  DeclException2 (ExcUMFPACKError, char *, int,
263  << "UMFPACK routine " << arg1
264  << " returned error status " << arg2 << "."
265  << "\n\n"
266  << ("A complete list of error codes can be found in the file "
267  "<bundled/umfpack/UMFPACK/Include/umfpack.h>."
268  "\n\n"
269  "That said, the two most common errors that can happen are "
270  "that your matrix cannot be factorized because it is "
271  "rank deficient, and that UMFPACK runs out of memory "
272  "because your problem is too large."
273  "\n\n"
274  "The first of these cases most often happens if you "
275  "forget terms in your bilinear form necessary to ensure "
276  "that the matrix has full rank, or if your equation has a "
277  "spatially variable coefficient (or nonlinearity) that is "
278  "supposed to be strictly positive but, for whatever "
279  "reasons, is negative or zero. In either case, you probably "
280  "want to check your assembly procedure. Similarly, a "
281  "matrix can be rank deficient if you forgot to apply the "
282  "appropriate boundary conditions. For example, the "
283  "Laplace equation without boundary conditions has a "
284  "single zero eigenvalue and its rank is therefore "
285  "deficient by one."
286  "\n\n"
287  "The other common situation is that you run out of memory."
288  "On a typical laptop or desktop, it should easily be possible "
289  "to solve problems with 100,000 unknowns in 2d. If you are "
290  "solving problems with many more unknowns than that, in "
291  "particular if you are in 3d, then you may be running out "
292  "of memory and you will need to consider iterative "
293  "solvers instead of the direct solver employed by "
294  "UMFPACK."));
295 
296 private:
300  size_type _m;
301 
305  size_type _n;
306 
313  void *numeric_decomposition;
314 
318  void clear ();
319 
326  template <typename number>
327  void sort_arrays (const SparseMatrixEZ<number> &);
328 
329  template <typename number>
330  void sort_arrays (const SparseMatrix<number> &);
331 
332  template <typename number>
333  void sort_arrays (const BlockSparseMatrix<number> &);
334 
340  std::vector<SuiteSparse_long> Ap;
341  std::vector<SuiteSparse_long> Ai;
342  std::vector<double> Ax;
343 
347  std::vector<double> control;
348 };
349 
350 DEAL_II_NAMESPACE_CLOSE
351 
352 #endif // dealii__sparse_direct_h
size_type n() const
size_type m() const
types::global_dof_index size_type
Definition: sparse_direct.h:86
void Tvmult(Vector< double > &dst, const Vector< double > &src) const
void factorize(const Matrix &matrix)
DeclException2(ExcUMFPACKError, char *, int,<< "UMFPACK routine "<< arg1<< " returned error status "<< arg2<< "."<< "\n\n"<< ("A complete list of error codes can be found in the file ""<bundled/umfpack/UMFPACK/Include/umfpack.h>.""\n\n""That said, the two most common errors that can happen are ""that your matrix cannot be factorized because it is ""rank deficient, and that UMFPACK runs out of memory ""because your problem is too large.""\n\n""The first of these cases most often happens if you ""forget terms in your bilinear form necessary to ensure ""that the matrix has full rank, or if your equation has a ""spatially variable coefficient (or nonlinearity) that is ""supposed to be strictly positive but, for whatever ""reasons, is negative or zero. In either case, you probably ""want to check your assembly procedure. Similarly, a ""matrix can be rank deficient if you forgot to apply the ""appropriate boundary conditions. For example, the ""Laplace equation without boundary conditions has a ""single zero eigenvalue and its rank is therefore ""deficient by one.""\n\n""The other common situation is that you run out of memory.""On a typical laptop or desktop, it should easily be possible ""to solve problems with 100,000 unknowns in 2d. If you are ""solving problems with many more unknowns than that, in ""particular if you are in 3d, then you may be running out ""of memory and you will need to consider iterative ""solvers instead of the direct solver employed by ""UMFPACK."))
unsigned int global_dof_index
Definition: types.h:88
void solve(Vector< double > &rhs_and_solution, bool transpose=false) const
std::vector< SuiteSparse_long > Ap
std::vector< double > control
void initialize(const SparsityPattern &sparsity_pattern)
void sort_arrays(const SparseMatrixEZ< number > &)
void vmult(Vector< double > &dst, const Vector< double > &src) const