OGS
MeshSubset.h
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #include <cassert>
16 #include <vector>
17 
18 #include "Mesh.h"
19 #include "Node.h"
20 #include "Elements/Element.h"
21 
22 
23 namespace MeshLib
24 {
27 {
28 public:
32  MeshSubset(const Mesh& msh, std::vector<Node*> const& vec_items)
33  : _msh(msh), _nodes(vec_items)
34  {
35  // If the mesh nodes and the given nodes point to the same vector, they
36  // must be equal.
37  if (&_msh.getNodes() == &_nodes)
38  {
39  return;
40  }
41 
42  //
43  // Testing if the given nodes belong to the mesh.
44  //
45  {
46  // Need sorted version of the large vector.
47  auto sorted_nodes = _msh.getNodes(); // full copy of pointers.
48  sort(begin(sorted_nodes), end(sorted_nodes));
49 
50  // Then proceed with the search function.
51  auto node_is_part_of_mesh = [& mesh_nodes = sorted_nodes](
52  MeshLib::Node* const& n) {
53  auto it = lower_bound(begin(mesh_nodes), end(mesh_nodes), n);
54  if (it == end(mesh_nodes))
55  {
56  ERR("A node {:d} ({:g}, {:g}, {:g}) in mesh subset is not "
57  "a part of the mesh.",
58  n->getID(), (*n)[0], (*n)[1], (*n)[2]);
59  return false;
60  }
61  return true;
62  };
63  if (!std::all_of(begin(_nodes), end(_nodes), node_is_part_of_mesh))
64  {
65  OGS_FATAL("The mesh subset construction failed.");
66  }
67  }
68  }
69 
71  std::size_t getMeshID() const
72  {
73  return _msh.getID();
74  }
75 
77  std::size_t getNumberOfNodes() const
78  {
79  return _nodes.size();
80  }
81 
85  std::size_t getNodeID(std::size_t const i) const
86  {
87  assert(i < _nodes.size());
88  return _nodes[i]->getID();
89  }
90 
91  std::vector<Element*>::const_iterator elementsBegin() const
92  {
93  return _msh.getElements().cbegin();
94  }
95 
96  std::vector<Element*>::const_iterator elementsEnd() const
97  {
98  return _msh.getElements().cend();
99  }
100 
101  std::vector<Node*> const& getNodes() const
102  {
103  return _nodes;
104  }
105 
106  Mesh const& getMesh() const
107  {
108  return _msh;
109  }
110 
111 private:
112  Mesh const& _msh;
113  std::vector<Node*> const& _nodes;
114 };
115 } // namespace MeshLib
Definition of the Element class.
#define OGS_FATAL(...)
Definition: Error.h:26
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
Definition of the Mesh class.
Definition of the Node class.
A subset of nodes on a single mesh.
Definition: MeshSubset.h:27
std::vector< Node * > const & _nodes
Definition: MeshSubset.h:113
Mesh const & _msh
Definition: MeshSubset.h:112
std::size_t getNumberOfNodes() const
return the number of registered nodes
Definition: MeshSubset.h:77
Mesh const & getMesh() const
Definition: MeshSubset.h:106
std::size_t getNodeID(std::size_t const i) const
Definition: MeshSubset.h:85
std::vector< Element * >::const_iterator elementsEnd() const
Definition: MeshSubset.h:96
MeshSubset(const Mesh &msh, std::vector< Node * > const &vec_items)
Definition: MeshSubset.h:32
std::vector< Element * >::const_iterator elementsBegin() const
Definition: MeshSubset.h:91
std::size_t getMeshID() const
return this mesh ID
Definition: MeshSubset.h:71
std::vector< Node * > const & getNodes() const
Definition: MeshSubset.h:101
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:95
std::size_t getID() const
Get id of the mesh.
Definition: Mesh.h:110
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:98