7#include <range/v3/algorithm/sort.hpp>
8#include <range/v3/algorithm/unique.hpp>
9#include <range/v3/range/conversion.hpp>
10#include <range/v3/view/transform.hpp>
29 auto const global_idcs =
31 ranges::views::transform([&](
auto&& l)
33 ranges::to<std::vector>();
49 MPI_Exscan(&n_local, &global_start, 1, MPIU_INT, MPI_SUM, PETSC_COMM_WORLD);
53 MPI_Allreduce(&n_local, &num_global_dof, 1, MPIU_INT, MPI_SUM,
64 std::vector<std::vector<GlobalIndexType>> col_lists(n_local);
76 return (-raw == num_global_dof) ? 0 : -raw;
93 assert(local_row >= 0 && local_row < n_local);
94 col_lists[local_row].push_back(decode_col(col));
104 for (
auto const row_idx : global_idcs[n])
106 for (
auto const adj : adj_nodes)
108 for (
auto const col_idx : global_idcs[adj])
110 collect(row_idx, col_idx);
118 std::size_t number_of_nonzeros = 0;
119 for (
auto& cols : col_lists)
122 cols.erase(ranges::unique(cols), cols.end());
123 number_of_nonzeros += cols.size();
128 sparsity_pattern.
row_ptr.resize(n_local + 1);
129 sparsity_pattern.
row_ptr[0] = 0;
130 sparsity_pattern.
col_idx.reserve(number_of_nonzeros);
134 auto const& cols = col_lists[local_row];
136 cols.begin(), cols.end());
137 sparsity_pattern.
row_ptr[local_row + 1] =
138 sparsity_pattern.
row_ptr[local_row] +
142 return sparsity_pattern;
152 auto const global_idcs =
154 ranges::views::transform([&](
auto&& l)
156 ranges::to<std::vector>();
159 sparsity_pattern.number_non_zeros_per_row.assign(
165 auto const& an = node_adjacency_table.getAdjacentNodes(n);
166 auto const n_self_dof = global_idcs[n].size();
167 auto const n_connected_dof = std::accumulate(
168 cbegin(an), cend(an), 0, [&](
auto const result,
auto const i)
169 {
return result + global_idcs[i].size(); });
170 auto const n_dof = n_self_dof + n_connected_dof;
171 for (
auto global_index : global_idcs[n])
173 sparsity_pattern.number_non_zeros_per_row[global_index] = n_dof;
177 return sparsity_pattern;
189 return computeSparsityPatternNonPETSc(dof_table, mesh);
GlobalSparsityPattern computeSparsityPatternPETSc(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh)
MathLib::PETScSparsityPattern GlobalSparsityPattern
GlobalMatrix::IndexType GlobalIndexType
std::size_t getNumberOfNodes() const
Get the number of nodes.
std::vector< std::size_t > const & getAdjacentNodes(std::size_t const node_id) const
std::size_t dofSizeWithGhosts() const
std::size_t dofSizeWithoutGhosts() const
std::vector< GlobalIndexType > getGlobalIndices(const MeshLib::Location &l) const
Forwards the respective method from MeshComponentMap.
auto meshLocations(Mesh const &mesh, MeshItemType const item_type)
GlobalSparsityPattern computeSparsityPattern(LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh)
Computes a sparsity pattern for the given inputs.
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).