Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/dolfinx/v0.9.0/cpp/doxygen/d5/df9/classdolfinx_1_1la_1_1SparsityPattern.html
DOLFINx  0.5.1
DOLFINx C++ interface
Public Member Functions | List of all members
SparsityPattern Class Reference

This class provides a sparsity pattern data structure that can be used to initialize sparse matrices. After assembly, column indices are always sorted in increasing order. Ghost entries are kept after assembly. More...

#include <SparsityPattern.h>

Public Member Functions

 SparsityPattern (MPI_Comm comm, const std::array< std::shared_ptr< const common::IndexMap >, 2 > &maps, const std::array< int, 2 > &bs)
 Create an empty sparsity pattern with specified dimensions. More...
 
 SparsityPattern (MPI_Comm comm, const std::vector< std::vector< const SparsityPattern * >> &patterns, const std::array< std::vector< std::pair< std::reference_wrapper< const common::IndexMap >, int >>, 2 > &maps, const std::array< std::vector< int >, 2 > &bs)
 Create a new sparsity pattern by concatenating sub-patterns, e.g. pattern =[ pattern00 ][ pattern 01] [ pattern10 ][ pattern 11]. More...
 
 SparsityPattern (const SparsityPattern &pattern)=delete
 
 SparsityPattern (SparsityPattern &&pattern)=default
 Move constructor.
 
 ~SparsityPattern ()=default
 Destructor.
 
SparsityPatternoperator= (SparsityPattern &&pattern)=default
 Move assignment.
 
void insert (const std::span< const std::int32_t > &rows, const std::span< const std::int32_t > &cols)
 Insert non-zero locations using local (process-wise) indices.
 
void insert_diagonal (const std::span< const std::int32_t > &rows)
 Insert non-zero locations on the diagonal. More...
 
void assemble ()
 Finalize sparsity pattern and communicate off-process entries.
 
std::shared_ptr< const common::IndexMapindex_map (int dim) const
 Index map for given dimension dimension. Returns the index map for rows and columns that will be set by the current MPI rank. More...
 
std::vector< std::int64_t > column_indices () const
 Global indices of non-zero columns on owned rows. More...
 
common::IndexMap column_index_map () const
 Builds the index map for columns after assembly of the sparsity pattern. More...
 
int block_size (int dim) const
 Return index map block size for dimension dim.
 
std::int64_t num_nonzeros () const
 Number of nonzeros on this rank after assembly, including ghost rows.
 
std::int32_t nnz_diag (std::int32_t row) const
 Number of non-zeros in owned columns (diagonal block) on a given row. More...
 
std::int32_t nnz_off_diag (std::int32_t row) const
 Number of non-zeros in unowned columns (off-diagonal block) on a given row. More...
 
const graph::AdjacencyList< std::int32_t > & graph () const
 Sparsity pattern graph after assembly. Uses local indices for the columns. More...
 
std::span< const int > off_diagonal_offset () const
 Row-wise start of off-diagonal (unowned columns) on each row. More...
 
MPI_Comm comm () const
 Return MPI communicator.
 

Detailed Description

This class provides a sparsity pattern data structure that can be used to initialize sparse matrices. After assembly, column indices are always sorted in increasing order. Ghost entries are kept after assembly.

Constructor & Destructor Documentation

◆ SparsityPattern() [1/2]

SparsityPattern ( MPI_Comm  comm,
const std::array< std::shared_ptr< const common::IndexMap >, 2 > &  maps,
const std::array< int, 2 > &  bs 
)

Create an empty sparsity pattern with specified dimensions.

Parameters
[in]commThe communicator that the pattenr is defined on
[in]mapsThe index maps describing the [0] row and [1] column index ranges (up to a block size)
[in]bsThe block sizes for the [0] row and [1] column maps

◆ SparsityPattern() [2/2]

SparsityPattern ( MPI_Comm  comm,
const std::vector< std::vector< const SparsityPattern * >> &  patterns,
const std::array< std::vector< std::pair< std::reference_wrapper< const common::IndexMap >, int >>, 2 > &  maps,
const std::array< std::vector< int >, 2 > &  bs 
)

Create a new sparsity pattern by concatenating sub-patterns, e.g. pattern =[ pattern00 ][ pattern 01] [ pattern10 ][ pattern 11].

Parameters
[in]commThe MPI communicator
[in]patternsRectangular array of sparsity pattern. The patterns must not be finalised. Null block are permited
[in]mapsPairs of (index map, block size) for each row block (maps[0]) and column blocks (maps[1])
[in]bsBlock sizes for the sparsity pattern entries

Member Function Documentation

◆ column_index_map()

common::IndexMap column_index_map ( ) const

Builds the index map for columns after assembly of the sparsity pattern.

Returns
Map for all non-zero columns on this process, including ghosts
Todo:
Should this be compted and stored when finalising the SparsityPattern?

◆ column_indices()

std::vector< std::int64_t > column_indices ( ) const

Global indices of non-zero columns on owned rows.

Note
The ghosts are computed only once SparsityPattern::assemble has been called
Returns
The global index non-zero columns on this process, including ghosts

◆ graph()

const graph::AdjacencyList< std::int32_t > & graph ( ) const

Sparsity pattern graph after assembly. Uses local indices for the columns.

Note
Column global indices can be obtained from SparsityPattern::column_index_map()
Includes ghost rows

◆ index_map()

std::shared_ptr< const common::IndexMap > index_map ( int  dim) const

Index map for given dimension dimension. Returns the index map for rows and columns that will be set by the current MPI rank.

Parameters
[in]dimThe requested map, row (0) or column (1)
Returns
The index map

◆ insert_diagonal()

void insert_diagonal ( const std::span< const std::int32_t > &  rows)

Insert non-zero locations on the diagonal.

Parameters
[in]rowsThe rows in local (process-wise) indices. The indices must exist in the row IndexMap.

◆ nnz_diag()

std::int32_t nnz_diag ( std::int32_t  row) const

Number of non-zeros in owned columns (diagonal block) on a given row.

Note
Can also be used on ghost rows

◆ nnz_off_diag()

std::int32_t nnz_off_diag ( std::int32_t  row) const

Number of non-zeros in unowned columns (off-diagonal block) on a given row.

Note
Can also be used on ghost rows

◆ off_diagonal_offset()

std::span< const int > off_diagonal_offset ( ) const

Row-wise start of off-diagonal (unowned columns) on each row.

Note
Includes ghost rows

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