OGS
NodeAdjacencyTable.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <algorithm>
14#include <vector>
15
16#include "Mesh.h"
17#include "Node.h"
18
19namespace MeshLib
20{
31{
32public:
33 explicit NodeAdjacencyTable(Mesh const& mesh)
34 {
35 _data.resize(mesh.getNodes().size());
36
37 createTable(mesh);
38 }
39
40 std::size_t size() const { return _data.size(); }
41
42 std::size_t getNodeDegree(std::size_t const node_id) const
43 {
44 return _data[node_id].size();
45 }
46
47 std::vector<std::size_t> const& getAdjacentNodes(
48 std::size_t const node_id) const
49 {
50 return _data[node_id];
51 }
52
53 void createTable(Mesh const& mesh)
54 {
55 auto const& nodes = mesh.getNodes();
56 if (_data.size() != nodes.size())
57 {
58 _data.resize(nodes.size());
59 }
60
61 auto const& connections =
63 for (auto const* node : nodes)
64 {
65 auto const node_id = node->getID();
66 auto const& connected_nodes = connections[node_id];
67 std::vector<std::size_t>& row = _data[node_id];
68 row.reserve(connected_nodes.size());
69 std::transform(connected_nodes.cbegin(), connected_nodes.cend(),
70 std::back_inserter(row),
71 [](Node const* const n) { return n->getID(); });
72 }
73 }
74
75private:
76 std::vector<std::vector<std::size_t>> _data;
77};
78
79} // namespace MeshLib
Definition of the Mesh class.
Definition of the Node class.
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:106
void createTable(Mesh const &mesh)
std::size_t getNodeDegree(std::size_t const node_id) const
std::vector< std::vector< std::size_t > > _data
NodeAdjacencyTable(Mesh const &mesh)
std::vector< std::size_t > const & getAdjacentNodes(std::size_t const node_id) const
std::vector< std::vector< Node * > > calculateNodesConnectedByElements(Mesh const &mesh)
Definition Mesh.cpp:308