OGS
NodePartitionedMesh.h
Go to the documentation of this file.
1 
16 #pragma once
17 
18 #include <algorithm>
19 #include <string>
20 #include <vector>
21 
22 #include "Mesh.h"
23 #include "Node.h"
24 
25 namespace MeshLib
26 {
28 class NodePartitionedMesh : public Mesh
29 {
30 public:
31  // Copy a global mesh for the case of the thread number is one,
32  // i.e the global mesh is not partitioned.
33  // \param mesh The global mesh
34  explicit NodePartitionedMesh(const Mesh& mesh)
35  : Mesh(mesh),
40  _is_single_thread(true)
41  {
42  for (std::size_t i = 0; i < _nodes.size(); i++)
43  {
44  _global_node_ids[i] = _nodes[i]->getID();
45  }
46  }
47 
63  NodePartitionedMesh(const std::string& name,
64  const std::vector<Node*>& nodes,
65  const std::vector<std::size_t>& glb_node_ids,
66  const std::vector<Element*>& elements,
67  Properties properties,
68  const std::size_t n_global_nodes,
69  const std::size_t n_active_base_nodes,
70  const std::size_t n_active_nodes)
71  : Mesh(name, nodes, elements, properties),
72  _global_node_ids(glb_node_ids),
73  _n_global_nodes(n_global_nodes),
74  _n_active_base_nodes(n_active_base_nodes),
75  _n_active_nodes(n_active_nodes),
76  _is_single_thread(false)
77  {
78  }
79 
81  std::size_t getNumberOfGlobalNodes() const { return _n_global_nodes; }
83  std::size_t getGlobalNodeID(const std::size_t node_id) const
84  {
85  return _global_node_ids[node_id];
86  }
87 
89  std::size_t getNumberOfActiveBaseNodes() const
90  {
91  return _n_active_base_nodes;
92  }
93 
95  std::size_t getNumberOfActiveNodes() const { return _n_active_nodes; }
97  bool isGhostNode(const std::size_t node_id) const
98  {
99  if (node_id < _n_active_base_nodes)
100  {
101  return false;
102  }
103  if (!isBaseNode(*_nodes[node_id],
104  getElementsConnectedToNode(node_id)) &&
105  node_id < getLargestActiveNodeID())
106  {
107  return false;
108  }
109  return true;
110  }
111 
114  std::size_t getLargestActiveNodeID() const
115  {
117  }
118 
119  // TODO I guess that is a simplified version of computeSparsityPattern()
122  {
123  auto const& nodes_connections =
125  auto const max_connections = std::max_element(
126  nodes_connections.cbegin(), nodes_connections.cend(),
127  [](auto const& connections_node_a, auto const& connections_node_b) {
128  return (connections_node_a.size() < connections_node_b.size());
129  });
130  // Return the number of connected nodes +1 for the node itself.
131  return max_connections->size() + 1;
132  }
133 
134  bool isForSingleThread() const { return _is_single_thread; }
135 
136 private:
138  std::vector<std::size_t> _global_node_ids;
139 
141  std::size_t _n_global_nodes;
142 
144  std::size_t _n_active_base_nodes;
145 
147  std::size_t _n_active_nodes;
148 
149  const bool _is_single_thread;
150 };
151 
152 } // namespace MeshLib
Definition of the Mesh class.
Definition of the Node class.
std::size_t getNumberOfBaseNodes() const
Get the number of base nodes.
Definition: Mesh.cpp:214
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:89
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
Definition: Mesh.cpp:232
std::vector< Node * > _nodes
Definition: Mesh.h:151
bool isGhostNode(const std::size_t node_id) const
Check whether a node with ID of node_id is a ghost node.
std::size_t _n_active_base_nodes
Number of the active nodes for linear interpolations.
std::vector< std::size_t > _global_node_ids
Global IDs of nodes of a partition.
NodePartitionedMesh(const std::string &name, const std::vector< Node * > &nodes, const std::vector< std::size_t > &glb_node_ids, const std::vector< Element * > &elements, Properties properties, const std::size_t n_global_nodes, const std::size_t n_active_base_nodes, const std::size_t n_active_nodes)
Constructor.
std::size_t getGlobalNodeID(const std::size_t node_id) const
Get the global node ID of a node with its local ID.
std::size_t getNumberOfGlobalNodes() const
Get the number of all nodes of the global mesh.
std::size_t getLargestActiveNodeID() const
std::size_t getNumberOfActiveBaseNodes() const
Get the number of the active nodes of the partition for linear elements.
std::size_t getNumberOfActiveNodes() const
Get the number of all active nodes of the partition.
NodePartitionedMesh(const Mesh &mesh)
std::size_t _n_active_nodes
Number of the all active nodes.
std::size_t getMaximumNConnectedNodesToNode() const
Get the maximum number of connected nodes to node.
std::size_t _n_global_nodes
Number of all nodes of the global mesh.
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition: Properties.h:36
std::vector< std::vector< Node * > > calculateNodesConnectedByElements(Mesh const &mesh)
Definition: Mesh.cpp:331
bool isBaseNode(Node const &node, std::vector< Element const * > const &elements_connected_to_node)
Definition: Mesh.cpp:370