DOLFIN-X
DOLFIN-X C++ interface
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 <dolfinx/common/span.hpp>
11 #include <memory>
12 #include <utility>
13 #include <vector>
14 
15 namespace dolfinx
16 {
17 
18 namespace graph
19 {
20 template <typename T>
21 class AdjacencyList;
22 }
23 
24 namespace common
25 {
26 class IndexMap;
27 }
28 
29 namespace la
30 {
31 
34 
36 {
37 
38 public:
41  MPI_Comm comm,
42  const std::array<std::shared_ptr<const common::IndexMap>, 2>& maps,
43  const std::array<int, 2>& bs);
44 
56  MPI_Comm comm,
57  const std::vector<std::vector<const SparsityPattern*>>& patterns,
58  const std::array<
59  std::vector<
60  std::pair<std::reference_wrapper<const common::IndexMap>, int>>,
61  2>& maps,
62  const std::array<std::vector<int>, 2>& bs);
63 
64  SparsityPattern(const SparsityPattern& pattern) = delete;
65 
67  SparsityPattern(SparsityPattern&& pattern) = default;
68 
70  ~SparsityPattern() = default;
71 
73  SparsityPattern& operator=(SparsityPattern&& pattern) = default;
74 
80  std::shared_ptr<const common::IndexMap> index_map(int dim) const;
81 
88  std::vector<std::int64_t> column_indices() const;
89 
91  int block_size(int dim) const;
92 
94  void insert(const tcb::span<const std::int32_t>& rows,
95  const tcb::span<const std::int32_t>& cols);
96 
100  void insert_diagonal(const std::vector<std::int32_t>& rows);
101 
103  void assemble();
104 
106  std::int64_t num_nonzeros() const;
107 
111 
115 
117  MPI_Comm mpi_comm() const;
118 
119 private:
120  // MPI communicator
121  dolfinx::MPI::Comm _mpi_comm;
122 
123  // Index maps for each dimension
124  std::array<std::shared_ptr<const common::IndexMap>, 2> _index_maps;
125  std::array<int, 2> _bs;
126 
127  // Non-zero ghost columns in owned rows
128  std::vector<std::int64_t> _col_ghosts;
129 
130  // Caches for unassembled entries on owned and unowned (ghost) rows
131  std::vector<std::vector<std::int32_t>> _cache_owned;
132  std::vector<std::vector<std::int32_t>> _cache_unowned;
133 
134  // Sparsity pattern data (computed once pattern is finalised)
135  std::shared_ptr<graph::AdjacencyList<std::int32_t>> _diagonal;
136  std::shared_ptr<graph::AdjacencyList<std::int32_t>> _off_diagonal;
137 };
138 } // namespace la
139 } // namespace dolfinx
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:36
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:68
This class provides a sparsity pattern data structure that can be used to initialize sparse matrices.
Definition: SparsityPattern.h:36
void insert(const tcb::span< const std::int32_t > &rows, const tcb::span< const std::int32_t > &cols)
Insert non-zero locations using local (process-wise) indices.
Definition: SparsityPattern.cpp:170
SparsityPattern(SparsityPattern &&pattern)=default
Move constructor.
SparsityPattern & operator=(SparsityPattern &&pattern)=default
Move assignment.
~SparsityPattern()=default
Destructor.
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:151
const graph::AdjacencyList< std::int32_t > & off_diagonal_pattern() const
Sparsity pattern for the un-owned (off-diagonal) columns. Uses local indices for the columns....
Definition: SparsityPattern.cpp:409
void assemble()
Finalize sparsity pattern and communicate off-process entries.
Definition: SparsityPattern.cpp:227
std::vector< std::int64_t > column_indices() const
Global indices of non-zero columns on owned rows.
Definition: SparsityPattern.cpp:156
const graph::AdjacencyList< std::int32_t > & diagonal_pattern() const
Sparsity pattern for the owned (diagonal) block. Uses local indices for the columns.
Definition: SparsityPattern.cpp:401
void insert_diagonal(const std::vector< std::int32_t > &rows)
Insert non-zero locations on the diagonal.
Definition: SparsityPattern.cpp:201
std::int64_t num_nonzeros() const
Return number of local nonzeros.
Definition: SparsityPattern.cpp:392
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:20
int block_size(int dim) const
Return index map block size for dimension dim.
Definition: SparsityPattern.cpp:168
MPI_Comm mpi_comm() const
Return MPI communicator.
Definition: SparsityPattern.cpp:416