Loading...
Searching...
No Matches
SparsityPattern.h
// Copyright (C) 2007-2020 Garth N. Wells
//
// This file is part of DOLFINx (https://www.fenicsproject.org)
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#pragma once
#include <dolfinx/common/MPI.h>
#include <memory>
#include <span>
#include <utility>
#include <vector>
namespace dolfinx::common
{
class IndexMap;
}
namespace dolfinx::la
{
class SparsityPattern
{
public:
SparsityPattern(MPI_Comm comm,
std::array<std::shared_ptr<const common::IndexMap>, 2> maps,
std::array<int, 2> bs);
SparsityPattern(
MPI_Comm comm,
const std::vector<std::vector<const SparsityPattern*>>& patterns,
const std::array<
std::vector<
std::pair<std::reference_wrapper<const common::IndexMap>, int>>,
2>& maps,
const std::array<std::vector<int>, 2>& bs);
SparsityPattern(const SparsityPattern& pattern) = delete;
SparsityPattern(SparsityPattern&& pattern) = default;
~SparsityPattern() = default;
SparsityPattern& operator=(SparsityPattern&& pattern) = default;
void insert(std::int32_t row, std::int32_t col);
void insert(std::span<const std::int32_t> rows,
std::span<const std::int32_t> cols);
void insert_diagonal(std::span<const std::int32_t> rows);
void finalize();
std::shared_ptr<const common::IndexMap> index_map(int dim) const;
std::vector<std::int64_t> column_indices() const;
common::IndexMap column_index_map() const;
int block_size(int dim) const;
std::int64_t num_nonzeros() const;
std::int32_t nnz_diag(std::int32_t row) const;
std::int32_t nnz_off_diag(std::int32_t row) const;
std::pair<std::span<const std::int32_t>, std::span<const std::int64_t>>
graph() const;
std::span<const std::int32_t> off_diagonal_offsets() const;
MPI_Comm comm() const;
private:
// MPI communicator
dolfinx::MPI::Comm _comm;
// Index maps for each dimension
std::array<std::shared_ptr<const common::IndexMap>, 2> _index_maps;
// Block size
std::array<int, 2> _bs;
// Non-zero ghost columns in owned rows
std::vector<std::int64_t> _col_ghosts;
// Owning process of ghost columns in owned rows
std::vector<std::int32_t> _col_ghost_owners;
// Cache for unassembled entries on owned and unowned (ghost) rows
std::vector<std::vector<std::int32_t>> _row_cache;
// Sparsity pattern adjacency data (computed once pattern is
// finalised). _edges holds the edges (connected dofs). The edges for
// node i are in the range [_offsets[i], _offsets[i + 1]).
std::vector<std::int32_t> _edges;
std::vector<std::int64_t> _offsets;
// Start of off-diagonal (unowned columns) on each row (row-wise)
std::vector<std::int32_t> _off_diagonal_offsets;
};
} // namespace dolfinx::la
dolfinx::MPI::Comm
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:42
dolfinx::common::IndexMap
Definition IndexMap.h:97
dolfinx::la::SparsityPattern::SparsityPattern
SparsityPattern(SparsityPattern &&pattern)=default
Move constructor.
dolfinx::la::SparsityPattern::index_map
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:212
dolfinx::la::SparsityPattern::nnz_off_diag
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:421
dolfinx::la::SparsityPattern::finalize
void finalize()
Finalize sparsity pattern and communicate off-process entries.
Definition SparsityPattern.cpp:244
dolfinx::la::SparsityPattern::block_size
int block_size(int dim) const
Return index map block size for dimension dim.
Definition SparsityPattern.cpp:242
dolfinx::la::SparsityPattern::nnz_diag
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:414
dolfinx::la::SparsityPattern::insert
void insert(std::int32_t row, std::int32_t col)
Insert non-zero locations using local (process-wise) indices.
Definition SparsityPattern.cpp:142
dolfinx::la::SparsityPattern::insert_diagonal
void insert_diagonal(std::span< const std::int32_t > rows)
Insert non-zero locations on the diagonal.
Definition SparsityPattern.cpp:187
dolfinx::la::SparsityPattern::num_nonzeros
std::int64_t num_nonzeros() const
Number of nonzeros on this rank after assembly, including ghost rows.
Definition SparsityPattern.cpp:407
dolfinx::la::SparsityPattern::off_diagonal_offsets
std::span< const std::int32_t > off_diagonal_offsets() const
Row-wise start of off-diagonals (unowned columns) for each row.
Definition SparsityPattern.cpp:436
dolfinx::la::SparsityPattern::column_indices
std::vector< std::int64_t > column_indices() const
Global indices of non-zero columns on owned rows.
Definition SparsityPattern.cpp:217
dolfinx::la::SparsityPattern::column_index_map
common::IndexMap column_index_map() const
Builds the index map for columns after assembly of the sparsity pattern.
Definition SparsityPattern.cpp:231
dolfinx::la::SparsityPattern::SparsityPattern
SparsityPattern(MPI_Comm comm, std::array< std::shared_ptr< const common::IndexMap >, 2 > maps, std::array< int, 2 > bs)
Create an empty sparsity pattern with specified dimensions.
Definition SparsityPattern.cpp:19
dolfinx::la::SparsityPattern::comm
MPI_Comm comm() const
Return MPI communicator.
Definition SparsityPattern.cpp:443
dolfinx::la::SparsityPattern::operator=
SparsityPattern & operator=(SparsityPattern &&pattern)=default
Move assignment.
dolfinx::la::SparsityPattern::~SparsityPattern
~SparsityPattern()=default
Destructor.
dolfinx::la::SparsityPattern::graph
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:429
dolfinx::common
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
dolfinx::la
Linear algebra interface.
Definition sparsitybuild.h:15