OGS
SparsityPattern.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <vector>
7
8#ifdef USE_PETSC
9#include <petscsystypes.h>
10#endif
11
12namespace MathLib
13{
18template <typename IndexType>
20{
21 std::vector<IndexType> number_non_zeros_per_row;
22
24 IndexType nnzInRow(IndexType const row) const
25 {
26 return number_non_zeros_per_row[row];
27 }
28
30 IndexType numberOfRows() const
31 {
32 return static_cast<IndexType>(number_non_zeros_per_row.size());
33 }
34};
35
36#ifdef USE_PETSC
43{
45 std::vector<PetscInt> row_ptr;
47 std::vector<PetscInt> col_idx;
48
50 PetscInt nnzInRow(PetscInt const row) const
51 {
52 return row_ptr[row + 1] - row_ptr[row];
53 }
54
56 PetscInt numberOfRows() const
57 {
58 // A default-constructed pattern has an empty row_ptr and describes
59 // zero rows; only a populated pattern carries the trailing sentinel.
60 return row_ptr.empty() ? 0 : static_cast<PetscInt>(row_ptr.size()) - 1;
61 }
62};
63#endif
64} // namespace MathLib
std::vector< PetscInt > col_idx
Global column indices, sorted within each local row.
std::vector< PetscInt > row_ptr
CSR row pointers (length n_local_rows + 1).
PetscInt nnzInRow(PetscInt const row) const
Number of nonzeros in the given local row.
PetscInt numberOfRows() const
Number of local rows the pattern describes.
IndexType numberOfRows() const
Number of global rows the pattern describes.
IndexType nnzInRow(IndexType const row) const
Number of nonzeros in the given global row.
std::vector< IndexType > number_non_zeros_per_row