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 namespace MeshLib
23 {
26 {
27 public:
33  MeshSubset(const Mesh& msh, std::vector<Node*> const& vec_items,
34  const bool use_taylor_hood_elements = false)
35  : _msh(msh),
36  _nodes(vec_items),
37  _use_taylor_hood_elements(use_taylor_hood_elements)
38  {
39  // If the mesh nodes and the given nodes point to the same vector, they
40  // must be equal.
41  if (&_msh.getNodes() == &_nodes)
42  {
43  return;
44  }
45
46  //
47  // Testing if the given nodes belong to the mesh.
48  //
49  {
50  // Need sorted version of the large vector.
51  auto sorted_nodes = _msh.getNodes(); // full copy of pointers.
52  sort(begin(sorted_nodes), end(sorted_nodes));
53
54  // Then proceed with the search function.
55  auto node_is_part_of_mesh =
56  [&mesh_nodes = sorted_nodes](MeshLib::Node* const& n)
57  {
58  auto it = lower_bound(begin(mesh_nodes), end(mesh_nodes), n);
59  if (it == end(mesh_nodes))
60  {
61  ERR("A node {:d} ({:g}, {:g}, {:g}) in mesh subset is not "
62  "a part of the mesh.",
63  n->getID(), (*n)[0], (*n)[1], (*n)[2]);
64  return false;
65  }
66  return true;
67  };
68  if (!std::all_of(begin(_nodes), end(_nodes), node_is_part_of_mesh))
69  {
70  OGS_FATAL("The mesh subset construction failed.");
71  }
72  }
73  }
74
76  std::size_t getMeshID() const { return _msh.getID(); }
77
79  std::size_t getNumberOfNodes() const { return _nodes.size(); }
80
84  std::size_t getNodeID(std::size_t const i) const
85  {
86  assert(i < _nodes.size());
87  return _nodes[i]->getID();
88  }
89
91
92  std::vector<Element*>::const_iterator elementsBegin() const
93  {
94  return _msh.getElements().cbegin();
95  }
96
97  std::vector<Element*>::const_iterator elementsEnd() const
98  {
99  return _msh.getElements().cend();
100  }
101
102  std::vector<Node*> const& getNodes() const { return _nodes; }
103
104  Mesh const& getMesh() const { return _msh; }
105
106 private:
107  Mesh const& _msh;
108  std::vector<Node*> const& _nodes;
110 };
111 } // 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:26
std::vector< Node * > const & _nodes
Definition: MeshSubset.h:108
Mesh const & _msh
Definition: MeshSubset.h:107
std::size_t getNumberOfNodes() const
return the number of registered nodes
Definition: MeshSubset.h:79
MeshSubset(const Mesh &msh, std::vector< Node * > const &vec_items, const bool use_taylor_hood_elements=false)
Definition: MeshSubset.h:33
bool useTaylorHoodElements() const
Definition: MeshSubset.h:90
Mesh const & getMesh() const
Definition: MeshSubset.h:104
std::size_t getNodeID(std::size_t const i) const
Definition: MeshSubset.h:84
std::vector< Element * >::const_iterator elementsEnd() const
Definition: MeshSubset.h:97
std::vector< Element * >::const_iterator elementsBegin() const
Definition: MeshSubset.h:92
std::size_t getMeshID() const
return this mesh ID
Definition: MeshSubset.h:76
std::vector< Node * > const & getNodes() const
Definition: MeshSubset.h:102
bool const _use_taylor_hood_elements
Definition: MeshSubset.h:109
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
constexpr bool all_of(List const &values)
Checks if all of the elements in the given list are true.
Definition: Algorithm.h:341