OGS
ComputeSparsityPattern.cpp
Go to the documentation of this file.
1
12
13#include <numeric>
14
17
18#ifdef USE_PETSC
20
22 NumLib::LocalToGlobalIndexMap const& dof_table, MeshLib::Mesh const& mesh)
23{
24 assert(dynamic_cast<MeshLib::NodePartitionedMesh const*>(&mesh));
25 auto const& npmesh =
26 *static_cast<MeshLib::NodePartitionedMesh const*>(&mesh);
27
28 auto const max_nonzeroes = dof_table.getNumberOfGlobalComponents() *
29 npmesh.getMaximumNConnectedNodesToNode();
30
31 // The sparsity pattern is misused here in the sense that it will only
32 // contain a single value.
33 return GlobalSparsityPattern(1, max_nonzeroes);
34}
35#else
36GlobalSparsityPattern computeSparsityPatternNonPETSc(
37 NumLib::LocalToGlobalIndexMap const& dof_table, MeshLib::Mesh const& mesh)
38{
39 MeshLib::NodeAdjacencyTable const node_adjacency_table(mesh);
40
41 // A mapping mesh node id -> global indices
42 // It acts as a cache for dof table queries.
43 std::vector<std::vector<GlobalIndexType>> global_idcs;
44
45 global_idcs.reserve(mesh.getNumberOfNodes());
46 for (std::size_t n = 0; n < mesh.getNumberOfNodes(); ++n)
47 {
49 global_idcs.push_back(dof_table.getGlobalIndices(l));
50 }
51
52 GlobalSparsityPattern sparsity_pattern(dof_table.dofSizeWithGhosts());
53
54 // Map adjacent mesh nodes to "adjacent global indices".
55 for (std::size_t n = 0; n < mesh.getNumberOfNodes(); ++n)
56 {
57 auto const& an = node_adjacency_table.getAdjacentNodes(n);
58 auto const n_connected_dof =
59 std::accumulate(cbegin(an), cend(an), 0,
60 [&](auto const result, auto const i)
61 { return result + global_idcs[i].size(); });
62 for (auto global_index : global_idcs[n])
63 {
64 sparsity_pattern[global_index] = n_connected_dof;
65 }
66 }
67
68 return sparsity_pattern;
69}
70#endif
71
72namespace NumLib
73{
75 LocalToGlobalIndexMap const& dof_table, MeshLib::Mesh const& mesh)
76{
77#ifdef USE_PETSC
78 return computeSparsityPatternPETSc(dof_table, mesh);
79#else
80 return computeSparsityPatternNonPETSc(dof_table, mesh);
81#endif
82}
83
84} // namespace NumLib
GlobalSparsityPattern computeSparsityPatternPETSc(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh)
MathLib::SparsityPattern< GlobalIndexType > GlobalSparsityPattern
Definition of mesh class for partitioned mesh (by node) for parallel computing within the framework o...
std::size_t getID() const
Get id of the mesh.
Definition Mesh.h:121
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:100
std::vector< GlobalIndexType > getGlobalIndices(const MeshLib::Location &l) const
Forwards the respective method from MeshComponentMap.
GlobalSparsityPattern computeSparsityPattern(LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh)
Computes a sparsity pattern for the given inputs.