-
Notifications
You must be signed in to change notification settings - Fork 239
/
Copy pathNodeAdjacencyTable.h
84 lines (67 loc) · 2.05 KB
/
NodeAdjacencyTable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* \copyright
* Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#pragma once
#include <algorithm>
#include <vector>
#include "Node.h"
namespace MeshLib
{
/// Representation of topological node adjacency.
///
/// The topological sparsity pattern in the context of FEM is defined in terms of
/// supports of the nodal functions. Especially, two nodes i and j are called
/// adjacent if and only if there is a mesh element E including nodes i and j.
/// This information is represented by the NodeAdjacenceTable.
///
/// The topological adjacency of nodes is created by
/// Mesh::setNodesConnectedByElements() which is usually called upon mesh
/// construction.
class
NodeAdjacencyTable
{
public:
NodeAdjacencyTable() = default;
explicit
NodeAdjacencyTable(std::vector<Node*> const& nodes)
{
_data.resize(nodes.size());
createTable(nodes);
}
std::size_t size() const
{
return _data.size();
}
std::size_t getNodeDegree(std::size_t const node_id) const
{
return _data[node_id].size();
}
std::vector<std::size_t> const& getAdjacentNodes(std::size_t const node_id) const
{
return _data[node_id];
}
void createTable(std::vector<Node*> const& nodes)
{
if (_data.size() != nodes.size())
{
_data.resize(nodes.size());
}
for (auto n_ptr : nodes)
{
std::vector<Node*> const& connected_nodes = n_ptr->getConnectedNodes();
std::vector<std::size_t>& row = _data[n_ptr->getID()];
row.reserve(connected_nodes.size());
std::transform(connected_nodes.cbegin(), connected_nodes.cend(),
std::back_inserter(row),
[](Node const* const n) { return n->getID(); });
}
}
private:
std::vector<std::vector<std::size_t>> _data;
};
} // namespace MeshLib