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.8.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::common
16{
17class IndexMap;
18}
19
20namespace dolfinx::la
21{
26{
27public:
34 MPI_Comm comm,
35 const std::array<std::shared_ptr<const common::IndexMap>, 2>& maps,
36 const std::array<int, 2>& bs);
37
49 MPI_Comm comm,
50 const std::vector<std::vector<const SparsityPattern*>>& patterns,
51 const std::array<
52 std::vector<
53 std::pair<std::reference_wrapper<const common::IndexMap>, int>>,
54 2>& maps,
55 const std::array<std::vector<int>, 2>& bs);
56
57 SparsityPattern(const SparsityPattern& pattern) = delete;
58
60 SparsityPattern(SparsityPattern&& pattern) = default;
61
63 ~SparsityPattern() = default;
64
67
70 void insert(std::span<const std::int32_t> rows,
71 std::span<const std::int32_t> cols);
72
76 void insert_diagonal(std::span<const std::int32_t> rows);
77
79 void finalize();
80
85 std::shared_ptr<const common::IndexMap> index_map(int dim) const;
86
93 std::vector<std::int64_t> column_indices() const;
94
102
104 int block_size(int dim) const;
105
108 std::int64_t num_nonzeros() const;
109
113 std::int32_t nnz_diag(std::int32_t row) const;
114
118 std::int32_t nnz_off_diag(std::int32_t row) const;
119
126 std::pair<std::span<const std::int32_t>, std::span<const std::int64_t>>
127 graph() const;
128
132 std::span<const std::int32_t> off_diagonal_offsets() const;
133
135 MPI_Comm comm() const;
136
137private:
138 // MPI communicator
139 dolfinx::MPI::Comm _comm;
140
141 // Index maps for each dimension
142 std::array<std::shared_ptr<const common::IndexMap>, 2> _index_maps;
143
144 // Block size
145 std::array<int, 2> _bs;
146
147 // Non-zero ghost columns in owned rows
148 std::vector<std::int64_t> _col_ghosts;
149
150 // Owning process of ghost columns in owned rows
151 std::vector<std::int32_t> _col_ghost_owners;
152
153 // Cache for unassembled entries on owned and unowned (ghost) rows
154 std::vector<std::vector<std::int32_t>> _row_cache;
155
156 // Sparsity pattern adjacency data (computed once pattern is
157 // finalised). _edges holds the edges (connected dofs). The edges for
158 // node i are in the range [_offsets[i], _offsets[i + 1]).
159 std::vector<std::int32_t> _edges;
160 std::vector<std::int64_t> _offsets;
161
162 // Start of off-diagonal (unowned columns) on each row (row-wise)
163 std::vector<std::int32_t> _off_diagonal_offsets;
164};
165} // namespace dolfinx::la
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:43
Definition IndexMap.h:94
Definition SparsityPattern.h:26
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:193
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:403
void finalize()
Finalize sparsity pattern and communicate off-process entries.
Definition SparsityPattern.cpp:226
int block_size(int dim) const
Return index map block size for dimension dim.
Definition SparsityPattern.cpp:224
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:396
void insert(std::span< const std::int32_t > rows, std::span< const std::int32_t > cols)
Insert non-zero locations using local (process-wise) indices.
Definition SparsityPattern.cpp:143
void insert_diagonal(std::span< const std::int32_t > rows)
Insert non-zero locations on the diagonal.
Definition SparsityPattern.cpp:168
std::int64_t num_nonzeros() const
Number of nonzeros on this rank after assembly, including ghost rows.
Definition SparsityPattern.cpp:389
std::span< const std::int32_t > off_diagonal_offsets() const
Row-wise start of off-diagonals (unowned columns) for each row.
Definition SparsityPattern.cpp:418
std::vector< std::int64_t > column_indices() const
Global indices of non-zero columns on owned rows.
Definition SparsityPattern.cpp:198
common::IndexMap column_index_map() const
Builds the index map for columns after assembly of the sparsity pattern.
Definition SparsityPattern.cpp:213
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.
Definition SparsityPattern.cpp:19
MPI_Comm comm() const
Return MPI communicator.
Definition SparsityPattern.cpp:425
SparsityPattern & operator=(SparsityPattern &&pattern)=default
Move assignment.
~SparsityPattern()=default
Destructor.
std::pair< std::span< const std::int32_t >, std::span< const std::int64_t > > graph() const
Sparsity pattern graph after assembly. Uses local indices for the columns.
Definition SparsityPattern.cpp:411
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
Linear algebra interface.
Definition sparsitybuild.h:15