deal.II version GIT relicensing-1989-gd7a2c90e4e 2024-10-14 01:50:00+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
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members

#include <deal.II/lac/sparse_direct.h>

Inheritance diagram for SparseDirectUMFPACK:
Inheritance graph
[legend]

Classes

class  AdditionalData
 

Public Types

using size_type = types::global_dof_index
 

Public Member Functions

 SparseDirectUMFPACK ()
 
 ~SparseDirectUMFPACK () override
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 
Setting up a sparse factorization
void initialize (const SparsityPattern &sparsity_pattern)
 
template<class Matrix >
void factorize (const Matrix &matrix)
 
template<class Matrix >
void initialize (const Matrix &matrix, const AdditionalData additional_data=AdditionalData())
 
Functions that represent the inverse of a matrix
void vmult (Vector< double > &dst, const Vector< double > &src) const
 
void vmult (BlockVector< double > &dst, const BlockVector< double > &src) const
 
void Tvmult (Vector< double > &dst, const Vector< double > &src) const
 
void Tvmult (BlockVector< double > &dst, const BlockVector< double > &src) const
 
size_type m () const
 
size_type n () const
 
Functions that solve linear systems
void solve (Vector< double > &rhs_and_solution, const bool transpose=false) const
 
void solve (Vector< std::complex< double > > &rhs_and_solution, const bool transpose=false) const
 
void solve (BlockVector< double > &rhs_and_solution, const bool transpose=false) const
 
void solve (BlockVector< std::complex< double > > &rhs_and_solution, const bool transpose=false) const
 
template<class Matrix >
void solve (const Matrix &matrix, Vector< double > &rhs_and_solution, const bool transpose=false)
 
template<class Matrix >
void solve (const Matrix &matrix, Vector< std::complex< double > > &rhs_and_solution, const bool transpose=false)
 
template<class Matrix >
void solve (const Matrix &matrix, BlockVector< double > &rhs_and_solution, const bool transpose=false)
 
template<class Matrix >
void solve (const Matrix &matrix, BlockVector< std::complex< double > > &rhs_and_solution, const bool transpose=false)
 
EnableObserverPointer functionality

Classes derived from EnableObserverPointer provide a facility to subscribe to this object. This is mostly used by the ObserverPointer class.

void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
template<typename StreamType >
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 

Static Public Member Functions

static ::ExceptionBaseExcUMFPACKError (std::string arg1, int arg2)
 
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 

Private Types

using map_value_type = decltype(counter_map)::value_type
 
using map_iterator = decltype(counter_map)::iterator
 

Private Member Functions

void clear ()
 
template<typename number >
void sort_arrays (const SparseMatrixEZ< number > &)
 
template<typename number >
void sort_arrays (const SparseMatrix< number > &)
 
template<typename number >
void sort_arrays (const BlockSparseMatrix< number > &)
 
void check_no_subscribers () const noexcept
 

Private Attributes

size_type n_rows
 
size_type n_cols
 
void * symbolic_decomposition
 
void * numeric_decomposition
 
std::vector< types::suitesparse_indexAp
 
std::vector< types::suitesparse_indexAi
 
std::vector< double > Ax
 
std::vector< double > Az
 
std::vector< double > control
 
std::atomic< unsigned intcounter
 
std::map< std::string, unsigned intcounter_map
 
std::vector< std::atomic< bool > * > validity_pointers
 
const std::type_info * object_info
 

Static Private Attributes

static std::mutex mutex
 

Detailed Description

This class provides an interface to the sparse direct solver UMFPACK, which is part of the SuiteSparse library (see this link). UMFPACK is a set of routines for solving non-symmetric sparse linear systems, Ax=b, using the Unsymmetric-pattern MultiFrontal method and direct sparse LU factorization. Matrices may have symmetric or unsymmetric sparsity patterns, and may have unsymmetric entries. The use of this class is explained in the step-22 and step-29 tutorial programs.

This matrix class implements the usual interface of preconditioners, that is a function initialize(const SparseMatrix<double>&matrix,const AdditionalData) for initializing and the whole set of vmult() functions common to all matrices. Implemented here are only vmult() and vmult_add(), which perform multiplication with the inverse matrix. Furthermore, this class provides an older interface, consisting of the functions factorize() and solve(). Both interfaces are interchangeable.

Note
This class exists if the UMFPACK interface was not explicitly disabled during configuration.
UMFPACK has its own license, independent of that of deal.II. If you want to use the UMFPACK you have to accept that license. It is linked to from the deal.II ReadMe file. UMFPACK is included courtesy of its author, Timothy A. Davis.

Instantiations

There are instantiations of this class for SparseMatrix<double>, SparseMatrix<float>, SparseMatrixEZ<float>, SparseMatrixEZ<double>, BlockSparseMatrix<double>, and BlockSparseMatrix<float>.

This class is not instantiated for the matrix types in namespace PETScWrappers or TrilinosWrappers. However, PETScWrappers::SparseDirectMUMPS can be used for PETSc matrices, and in fact even works for parallel computations.

Definition at line 91 of file sparse_direct.h.

Member Typedef Documentation

◆ size_type

Declare type for container size.

Definition at line 97 of file sparse_direct.h.

◆ map_value_type

using EnableObserverPointer::map_value_type = decltype(counter_map)::value_type
privateinherited

The data type used in counter_map.

Definition at line 231 of file enable_ref_counting_by_observer_pointer.h.

◆ map_iterator

using EnableObserverPointer::map_iterator = decltype(counter_map)::iterator
privateinherited

The iterator type used in counter_map.

Definition at line 236 of file enable_ref_counting_by_observer_pointer.h.

Constructor & Destructor Documentation

◆ SparseDirectUMFPACK()

SparseDirectUMFPACK::SparseDirectUMFPACK ( )

Constructor. See the documentation of this class for the meaning of the parameters to this function.

Definition at line 73 of file sparse_direct.cc.

◆ ~SparseDirectUMFPACK()

SparseDirectUMFPACK::~SparseDirectUMFPACK ( )
override

Destructor.

Definition at line 60 of file sparse_direct.cc.

Member Function Documentation

◆ initialize() [1/2]

void SparseDirectUMFPACK::initialize ( const SparsityPattern sparsity_pattern)

This function does nothing. It is only here to provide a interface consistent with other sparse direct solvers.

Definition at line 67 of file sparse_direct.cc.

◆ factorize()

template<class Matrix >
void SparseDirectUMFPACK::factorize ( const Matrix &  matrix)

Factorize the matrix. This function may be called multiple times for different matrices, after the object of this class has been initialized for a certain sparsity pattern. You may therefore save some computing time if you want to invert several matrices with the same sparsity pattern. However, note that the bulk of the computing time is actually spent in the factorization, so this functionality may not always be of large benefit.

In contrast to the other direct solver classes, the initialization method does nothing. Therefore initialize is not automatically called by this method, when the initialization step has not been performed yet.

This function copies the contents of the matrix into its own storage; the matrix can therefore be deleted after this operation, even if subsequent solves are required.

Definition at line 252 of file sparse_direct.cc.

◆ initialize() [2/2]

template<class Matrix >
void SparseDirectUMFPACK::initialize ( const Matrix &  matrix,
const AdditionalData  additional_data = AdditionalData() 
)

Initialize memory and call SparseDirectUMFPACK::factorize.

Definition at line 788 of file sparse_direct.cc.

◆ vmult() [1/2]

void SparseDirectUMFPACK::vmult ( Vector< double > &  dst,
const Vector< double > &  src 
) const

Preconditioner interface function. Usually, given the source vector, this method returns an approximate solution of Ax = b. As this class provides a wrapper to a direct solver, here it is actually the exact solution (exact within the range of numerical accuracy of course).

In other words, this function actually multiplies with the exact inverse of the matrix, \(A^{-1}\).

Definition at line 795 of file sparse_direct.cc.

◆ vmult() [2/2]

void SparseDirectUMFPACK::vmult ( BlockVector< double > &  dst,
const BlockVector< double > &  src 
) const

Same as before, but for block vectors.

Definition at line 804 of file sparse_direct.cc.

◆ Tvmult() [1/2]

void SparseDirectUMFPACK::Tvmult ( Vector< double > &  dst,
const Vector< double > &  src 
) const

Same as before, but uses the transpose of the matrix, i.e. this function multiplies with \(A^{-T}\).

Definition at line 813 of file sparse_direct.cc.

◆ Tvmult() [2/2]

void SparseDirectUMFPACK::Tvmult ( BlockVector< double > &  dst,
const BlockVector< double > &  src 
) const

Same as before, but for block vectors

Definition at line 823 of file sparse_direct.cc.

◆ m()

SparseDirectUMFPACK::size_type SparseDirectUMFPACK::m ( ) const

Return the dimension of the codomain (or range) space. Note that the matrix is of dimension \(m \times n\).

Definition at line 831 of file sparse_direct.cc.

◆ n()

SparseDirectUMFPACK::size_type SparseDirectUMFPACK::n ( ) const

Return the dimension of the domain space. Note that the matrix is of dimension \(m \times n\).

Definition at line 838 of file sparse_direct.cc.

◆ solve() [1/8]

void SparseDirectUMFPACK::solve ( Vector< double > &  rhs_and_solution,
const bool  transpose = false 
) const

Solve for a certain right hand side vector. This function may be called multiple times for different right hand side vectors after the matrix has been factorized. This yields substantial savings in computing time, since the actual solution is fast, compared to the factorization of the matrix.

The solution will be returned in place of the right hand side vector.

Parameters
[in,out]rhs_and_solutionA vector that contains the right hand side \(b\) of a linear system \(Ax=b\) upon calling this function, and that contains the solution \(x\) of the linear system after calling this function.
[in]transposeIf set to true, this function solves the linear \(A^T x = b\) instead of \(Ax=b\).
Precondition
You need to call factorize() before this function can be called.

Definition at line 377 of file sparse_direct.cc.

◆ solve() [2/8]

void SparseDirectUMFPACK::solve ( Vector< std::complex< double > > &  rhs_and_solution,
const bool  transpose = false 
) const

Like the previous function, but for a complex-valued right hand side and solution vector.

If the matrix that was previously factorized had complex-valued entries, then the rhs_and_solution vector will, upon return from this function, simply contain the solution of the linear system \(Ax=b\). If the matrix was real-valued, then this is also true, but the solution will simply be computed by applying the factorized \(A^{-1}\) to both the real and imaginary parts of the right hand side vector.

Definition at line 417 of file sparse_direct.cc.

◆ solve() [3/8]

void SparseDirectUMFPACK::solve ( BlockVector< double > &  rhs_and_solution,
const bool  transpose = false 
) const

Same as before, but for block vectors.

Definition at line 532 of file sparse_direct.cc.

◆ solve() [4/8]

void SparseDirectUMFPACK::solve ( BlockVector< std::complex< double > > &  rhs_and_solution,
const bool  transpose = false 
) const

Same as before, but for complex-valued block vectors.

Definition at line 547 of file sparse_direct.cc.

◆ solve() [5/8]

template<class Matrix >
void SparseDirectUMFPACK::solve ( const Matrix &  matrix,
Vector< double > &  rhs_and_solution,
const bool  transpose = false 
)

Call the two functions factorize() and solve() in that order, i.e. perform the whole solution process for the given right hand side vector.

The solution will be returned in place of the right hand side vector.

Definition at line 573 of file sparse_direct.cc.

◆ solve() [6/8]

template<class Matrix >
void SparseDirectUMFPACK::solve ( const Matrix &  matrix,
Vector< std::complex< double > > &  rhs_and_solution,
const bool  transpose = false 
)

Same as before, but for complex-valued solution vectors.

Definition at line 585 of file sparse_direct.cc.

◆ solve() [7/8]

template<class Matrix >
void SparseDirectUMFPACK::solve ( const Matrix &  matrix,
BlockVector< double > &  rhs_and_solution,
const bool  transpose = false 
)

Same as before, but for block vectors.

Definition at line 609 of file sparse_direct.cc.

◆ solve() [8/8]

template<class Matrix >
void SparseDirectUMFPACK::solve ( const Matrix &  matrix,
BlockVector< std::complex< double > > &  rhs_and_solution,
const bool  transpose = false 
)

Same as before, but for complex-valued block vectors.

Definition at line 621 of file sparse_direct.cc.

◆ clear()

void SparseDirectUMFPACK::clear ( )
private

Free all memory that hasn't been freed yet.

Definition at line 86 of file sparse_direct.cc.

◆ sort_arrays() [1/3]

template<typename number >
void SparseDirectUMFPACK::sort_arrays ( const SparseMatrixEZ< number > &  matrix)
private

Make sure that the arrays Ai and Ap are sorted in each row. UMFPACK wants it this way. We need to have three versions of this function, one for the usual SparseMatrix, one for the SparseMatrixEZ, and one for the BlockSparseMatrix classes

Definition at line 174 of file sparse_direct.cc.

◆ sort_arrays() [2/3]

template<typename number >
void SparseDirectUMFPACK::sort_arrays ( const SparseMatrix< number > &  matrix)
private

Definition at line 128 of file sparse_direct.cc.

◆ sort_arrays() [3/3]

template<typename number >
void SparseDirectUMFPACK::sort_arrays ( const BlockSparseMatrix< number > &  matrix)
private

Definition at line 203 of file sparse_direct.cc.

◆ subscribe()

void EnableObserverPointer::subscribe ( std::atomic< bool > *const  validity,
const std::string &  identifier = "" 
) const
inherited

Subscribes a user of the object by storing the pointer validity. The subscriber may be identified by text supplied as identifier.

Definition at line 131 of file enable_ref_counting_by_observer.cc.

◆ unsubscribe()

void EnableObserverPointer::unsubscribe ( std::atomic< bool > *const  validity,
const std::string &  identifier = "" 
) const
inherited

Unsubscribes a user from the object.

Note
The identifier and the validity pointer must be the same as the one supplied to subscribe().

Definition at line 151 of file enable_ref_counting_by_observer.cc.

◆ n_subscriptions()

unsigned int EnableObserverPointer::n_subscriptions ( ) const
inlineinherited

Return the present number of subscriptions to this object. This allows to use this class for reference counted lifetime determination where the last one to unsubscribe also deletes the object.

Definition at line 315 of file enable_ref_counting_by_observer_pointer.h.

◆ list_subscribers() [1/2]

template<typename StreamType >
void EnableObserverPointer::list_subscribers ( StreamType &  stream) const
inlineinherited

List the subscribers to the input stream.

Definition at line 332 of file enable_ref_counting_by_observer_pointer.h.

◆ list_subscribers() [2/2]

void EnableObserverPointer::list_subscribers ( ) const
inherited

List the subscribers to deallog.

Definition at line 199 of file enable_ref_counting_by_observer.cc.

◆ serialize()

template<class Archive >
void EnableObserverPointer::serialize ( Archive &  ar,
const unsigned int  version 
)
inlineinherited

Read or write the data of this object to or from a stream for the purpose of serialization using the BOOST serialization library.

This function does not actually serialize any of the member variables of this class. The reason is that what this class stores is only who subscribes to this object, but who does so at the time of storing the contents of this object does not necessarily have anything to do with who subscribes to the object when it is restored. Consequently, we do not want to overwrite the subscribers at the time of restoring, and then there is no reason to write the subscribers out in the first place.

Definition at line 324 of file enable_ref_counting_by_observer_pointer.h.

◆ check_no_subscribers()

void EnableObserverPointer::check_no_subscribers ( ) const
privatenoexceptinherited

Check that there are no objects subscribing to this object. If this check passes then it is safe to destroy the current object. It this check fails then this function will either abort or print an error message to deallog (by using the AssertNothrow mechanism), but will not throw an exception.

Note
Since this function is just a consistency check it does nothing in release mode.
If this function is called when there is an uncaught exception then, rather than aborting, this function prints an error message to the standard error stream and returns.

Definition at line 53 of file enable_ref_counting_by_observer.cc.

Member Data Documentation

◆ n_rows

size_type SparseDirectUMFPACK::n_rows
private

The dimension of the range space, i.e., the number of rows of the matrix.

Definition at line 368 of file sparse_direct.h.

◆ n_cols

size_type SparseDirectUMFPACK::n_cols
private

The dimension of the domain space, i.e., the number of columns of the matrix.

Definition at line 374 of file sparse_direct.h.

◆ symbolic_decomposition

void* SparseDirectUMFPACK::symbolic_decomposition
private

The UMFPACK routines allocate objects in which they store information about symbolic and numeric values of the decomposition. The actual data type of these objects is opaque, and only passed around as void pointers.

Definition at line 381 of file sparse_direct.h.

◆ numeric_decomposition

void* SparseDirectUMFPACK::numeric_decomposition
private

Definition at line 382 of file sparse_direct.h.

◆ Ap

std::vector<types::suitesparse_index> SparseDirectUMFPACK::Ap
private

The arrays in which we store the data for the solver. These are documented in the descriptions of the umfpack_*_symbolic() and umfpack_*_numeric() functions, but in short:

  • Ap is the array saying which row starts where in Ai
  • Ai is the array that stores the column indices of nonzero entries
  • Ax is the array that stores the values of nonzero entries; if the matrix is complex-valued, then it stores the real parts
  • Az is the array that stores the imaginary parts of nonzero entries, and is used only if the matrix is complex-valued.

Definition at line 419 of file sparse_direct.h.

◆ Ai

std::vector<types::suitesparse_index> SparseDirectUMFPACK::Ai
private

Definition at line 420 of file sparse_direct.h.

◆ Ax

std::vector<double> SparseDirectUMFPACK::Ax
private

Definition at line 421 of file sparse_direct.h.

◆ Az

std::vector<double> SparseDirectUMFPACK::Az
private

Definition at line 422 of file sparse_direct.h.

◆ control

std::vector<double> SparseDirectUMFPACK::control
private

Control and work arrays for the solver routines.

Definition at line 427 of file sparse_direct.h.

◆ counter

std::atomic<unsigned int> EnableObserverPointer::counter
mutableprivateinherited

Store the number of objects which subscribed to this object. Initially, this number is zero, and upon destruction it shall be zero again (i.e. all objects which subscribed should have unsubscribed again).

The creator (and owner) of an object is counted in the map below if HE manages to supply identification.

We use the mutable keyword in order to allow subscription to constant objects also.

This counter may be read from and written to concurrently in multithreaded code: hence we use the std::atomic class template.

Definition at line 220 of file enable_ref_counting_by_observer_pointer.h.

◆ counter_map

std::map<std::string, unsigned int> EnableObserverPointer::counter_map
mutableprivateinherited

In this map, we count subscriptions for each different identification string supplied to subscribe().

Definition at line 226 of file enable_ref_counting_by_observer_pointer.h.

◆ validity_pointers

std::vector<std::atomic<bool> *> EnableObserverPointer::validity_pointers
mutableprivateinherited

In this vector, we store pointers to the validity bool in the ObserverPointer objects that subscribe to this class.

Definition at line 242 of file enable_ref_counting_by_observer_pointer.h.

◆ object_info

const std::type_info* EnableObserverPointer::object_info
mutableprivateinherited

Pointer to the typeinfo object of this object, from which we can later deduce the class name. Since this information on the derived class is neither available in the destructor, nor in the constructor, we obtain it in between and store it here.

Definition at line 250 of file enable_ref_counting_by_observer_pointer.h.

◆ mutex

std::mutex EnableObserverPointer::mutex
staticprivateinherited

A mutex used to ensure data consistency when accessing the mutable members of this class. This lock is used in the subscribe() and unsubscribe() functions, as well as in list_subscribers().

Definition at line 273 of file enable_ref_counting_by_observer_pointer.h.


The documentation for this class was generated from the following files: