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 <string>
13 #include <utility>
14 #include <vector>
15 
16 namespace dolfinx
17 {
18 
19 namespace graph
20 {
21 template <typename T>
22 class AdjacencyList;
23 }
24 
25 namespace common
26 {
27 class IndexMap;
28 }
29 
30 namespace la
31 {
32 
35 
37 {
38 
39 public:
42  MPI_Comm comm,
43  const std::array<std::shared_ptr<const common::IndexMap>, 2>& maps,
44  const std::array<int, 2>& bs);
45 
57  MPI_Comm comm,
58  const std::vector<std::vector<const SparsityPattern*>>& patterns,
59  const std::array<
60  std::vector<
61  std::pair<std::reference_wrapper<const common::IndexMap>, int>>,
62  2>& maps,
63  const std::array<std::vector<int>, 2>& bs);
64 
65  SparsityPattern(const SparsityPattern& pattern) = delete;
66 
68  SparsityPattern(SparsityPattern&& pattern) = default;
69 
71  ~SparsityPattern() = default;
72 
74  SparsityPattern& operator=(SparsityPattern&& pattern) = default;
75 
77  std::shared_ptr<const common::IndexMap> index_map(int dim) const;
78 
80  int block_size(int dim) const;
81 
83  void insert(const tcb::span<const std::int32_t>& rows,
84  const tcb::span<const std::int32_t>& cols);
85 
89  void insert_diagonal(const std::vector<std::int32_t>& rows);
90 
92  void assemble();
93 
95  std::int64_t num_nonzeros() const;
96 
100 
104 
106  MPI_Comm mpi_comm() const;
107 
108 private:
109  // MPI communicator
110  dolfinx::MPI::Comm _mpi_comm;
111 
112  // common::IndexMaps for each dimension
113  std::array<std::shared_ptr<const common::IndexMap>, 2> _index_maps;
114  std::array<int, 2> _bs;
115 
116  // Caches for unassembled entries on owned and unowned (ghost) rows
117  std::vector<std::vector<std::int32_t>> _cache_owned;
118  std::vector<std::vector<std::int32_t>> _cache_unowned;
119 
120  // Sparsity pattern data (computed once pattern is finalised)
121  std::shared_ptr<graph::AdjacencyList<std::int32_t>> _diagonal;
122  std::shared_ptr<graph::AdjacencyList<std::int32_t>> _off_diagonal;
123 };
124 } // namespace la
125 } // 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:46
This class provides a sparsity pattern data structure that can be used to initialize sparse matrices.
Definition: SparsityPattern.h:37
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:158
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
Return index map for dimension dim.
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:395
void assemble()
Finalize sparsity pattern and communicate off-process entries.
Definition: SparsityPattern.cpp:215
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:387
void insert_diagonal(const std::vector< std::int32_t > &rows)
Insert non-zero locations on the diagonal.
Definition: SparsityPattern.cpp:189
std::int64_t num_nonzeros() const
Return number of local nonzeros.
Definition: SparsityPattern.cpp:378
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:156
MPI_Comm mpi_comm() const
Return MPI communicator.
Definition: SparsityPattern.cpp:402