Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/v0.3.0/v0.9.0/cpp
DOLFINx  0.3.0
DOLFINx 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 <memory>
11 #include <utility>
12 #include <vector>
13 #include <xtl/xspan.hpp>
14 
15 namespace dolfinx::graph
16 {
17 template <typename T>
18 class AdjacencyList;
19 }
20 
21 namespace dolfinx::common
22 {
23 class IndexMap;
24 }
25 
26 namespace dolfinx::la
27 {
28 
31 
33 {
34 
35 public:
38  MPI_Comm comm,
39  const std::array<std::shared_ptr<const common::IndexMap>, 2>& maps,
40  const std::array<int, 2>& bs);
41 
53  MPI_Comm comm,
54  const std::vector<std::vector<const SparsityPattern*>>& patterns,
55  const std::array<
56  std::vector<
57  std::pair<std::reference_wrapper<const common::IndexMap>, int>>,
58  2>& maps,
59  const std::array<std::vector<int>, 2>& bs);
60 
61  SparsityPattern(const SparsityPattern& pattern) = delete;
62 
64  SparsityPattern(SparsityPattern&& pattern) = default;
65 
67  ~SparsityPattern() = default;
68 
70  SparsityPattern& operator=(SparsityPattern&& pattern) = default;
71 
77  std::shared_ptr<const common::IndexMap> index_map(int dim) const;
78 
85  std::vector<std::int64_t> column_indices() const;
86 
88  int block_size(int dim) const;
89 
91  void insert(const xtl::span<const std::int32_t>& rows,
92  const xtl::span<const std::int32_t>& cols);
93 
97  void insert_diagonal(const std::vector<std::int32_t>& rows);
98 
100  void assemble();
101 
103  std::int64_t num_nonzeros() const;
104 
108 
112 
114  MPI_Comm mpi_comm() const;
115 
116 private:
117  // MPI communicator
118  dolfinx::MPI::Comm _mpi_comm;
119 
120  // Index maps for each dimension
121  std::array<std::shared_ptr<const common::IndexMap>, 2> _index_maps;
122  std::array<int, 2> _bs;
123 
124  // Non-zero ghost columns in owned rows
125  std::vector<std::int64_t> _col_ghosts;
126 
127  // Caches for unassembled entries on owned and unowned (ghost) rows
128  std::vector<std::vector<std::int32_t>> _cache_owned;
129  std::vector<std::vector<std::int32_t>> _cache_unowned;
130 
131  // Sparsity pattern data (computed once pattern is finalised)
132  std::shared_ptr<graph::AdjacencyList<std::int32_t>> _diagonal;
133  std::shared_ptr<graph::AdjacencyList<std::int32_t>> _off_diagonal;
134 };
135 } // namespace dolfinx::la
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:32
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:47
This class provides a sparsity pattern data structure that can be used to initialize sparse matrices.
Definition: SparsityPattern.h:33
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 insert(const xtl::span< const std::int32_t > &rows, const xtl::span< const std::int32_t > &cols)
Insert non-zero locations using local (process-wise) indices.
Definition: SparsityPattern.cpp:170
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
Miscellaneous classes, functions and types.
Graph data structures and algorithms.
Definition: AdjacencyList.h:19
Linear algebra interface.
Definition: sparsitybuild.h:13