Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/dolfinx/v0.9.0/cpp/doxygen/d6/df3/SparsityPattern_8h_source.html
DOLFINx 0.6.0
DOLFINx C++ interface
Loading...
Searching...
No Matches
SparsityPattern.h
1// Copyright (C) 2007-2020 Garth N. Wells
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#include <dolfinx/common/MPI.h>
10#include <memory>
11#include <span>
12#include <utility>
13#include <vector>
14
15namespace dolfinx::graph
16{
17template <typename T>
18class AdjacencyList;
19}
20
21namespace dolfinx::common
22{
23class IndexMap;
24}
25
26namespace dolfinx::la
27{
28
34{
35
36public:
43 MPI_Comm comm,
44 const std::array<std::shared_ptr<const common::IndexMap>, 2>& maps,
45 const std::array<int, 2>& bs);
46
58 MPI_Comm comm,
59 const std::vector<std::vector<const SparsityPattern*>>& patterns,
60 const std::array<
61 std::vector<
62 std::pair<std::reference_wrapper<const common::IndexMap>, int>>,
63 2>& maps,
64 const std::array<std::vector<int>, 2>& bs);
65
66 SparsityPattern(const SparsityPattern& pattern) = delete;
67
69 SparsityPattern(SparsityPattern&& pattern) = default;
70
72 ~SparsityPattern() = default;
73
76
78 void insert(const std::span<const std::int32_t>& rows,
79 const std::span<const std::int32_t>& cols);
80
84 void insert_diagonal(std::span<const std::int32_t> rows);
85
87 void assemble();
88
93 std::shared_ptr<const common::IndexMap> index_map(int dim) const;
94
101 std::vector<std::int64_t> column_indices() const;
102
110
112 int block_size(int dim) const;
113
116 std::int64_t num_nonzeros() const;
117
120 std::int32_t nnz_diag(std::int32_t row) const;
121
125 std::int32_t nnz_off_diag(std::int32_t row) const;
126
133
136 std::span<const int> off_diagonal_offset() const;
137
139 MPI_Comm comm() const;
140
141private:
142 // MPI communicator
143 dolfinx::MPI::Comm _comm;
144
145 // Index maps for each dimension
146 std::array<std::shared_ptr<const common::IndexMap>, 2> _index_maps;
147
148 // Block size
149 std::array<int, 2> _bs;
150
151 // Non-zero ghost columns in owned rows
152 std::vector<std::int64_t> _col_ghosts;
153 // Owning process of ghost columns in owned rows
154 std::vector<std::int32_t> _col_ghost_owners;
155
156 // Cache for unassembled entries on owned and unowned (ghost) rows
157 std::vector<std::vector<std::int32_t>> _row_cache;
158
159 // Sparsity pattern data (computed once pattern is finalised)
160 std::shared_ptr<graph::AdjacencyList<std::int32_t>> _graph;
161
162 // Start of off-diagonal (unowned columns) on each row
163 std::vector<int> _off_diagonal_offset;
164};
165} // namespace dolfinx::la
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:42
This class represents the distribution index arrays across processes. An index array is a contiguous ...
Definition: IndexMap.h:64
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:27
This class provides a sparsity pattern data structure that can be used to initialize sparse matrices....
Definition: SparsityPattern.h:34
SparsityPattern(SparsityPattern &&pattern)=default
Move constructor.
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 ...
Definition: SparsityPattern.cpp:194
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.
Definition: SparsityPattern.cpp:408
int block_size(int dim) const
Return index map block size for dimension dim.
Definition: SparsityPattern.cpp:225
const graph::AdjacencyList< std::int32_t > & graph() const
Sparsity pattern graph after assembly. Uses local indices for the columns.
Definition: SparsityPattern.cpp:415
std::int32_t nnz_diag(std::int32_t row) const
Number of non-zeros in owned columns (diagonal block) on a given row.
Definition: SparsityPattern.cpp:401
void insert_diagonal(std::span< const std::int32_t > rows)
Insert non-zero locations on the diagonal.
Definition: SparsityPattern.cpp:169
std::int64_t num_nonzeros() const
Number of nonzeros on this rank after assembly, including ghost rows.
Definition: SparsityPattern.cpp:394
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.
Definition: SparsityPattern.cpp:144
std::vector< std::int64_t > column_indices() const
Global indices of non-zero columns on owned rows.
Definition: SparsityPattern.cpp:199
common::IndexMap column_index_map() const
Builds the index map for columns after assembly of the sparsity pattern.
Definition: SparsityPattern.cpp:214
void assemble()
Finalize sparsity pattern and communicate off-process entries.
Definition: SparsityPattern.cpp:227
MPI_Comm comm() const
Return MPI communicator.
Definition: SparsityPattern.cpp:427
SparsityPattern & operator=(SparsityPattern &&pattern)=default
Move assignment.
~SparsityPattern()=default
Destructor.
std::span< const int > off_diagonal_offset() const
Row-wise start of off-diagonal (unowned columns) on each row.
Definition: SparsityPattern.cpp:422
Miscellaneous classes, functions and types.
Graph data structures and algorithms.
Definition: dofmapbuilder.h:25
Linear algebra interface.
Definition: sparsitybuild.h:15