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
22namespace MeshLib
23{
26{
27public:
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
80 std::vector<Element*>::const_iterator elementsBegin() const
81 {
82 return _msh.getElements().cbegin();
83 }
84
85 std::vector<Element*>::const_iterator elementsEnd() const
86 {
87 return _msh.getElements().cend();
88 }
89
90 std::vector<Node*> const& getNodes() const { return _nodes; }
91
92 Mesh const& getMesh() const { return _msh; }
93
94private:
95 Mesh const& _msh;
96 std::vector<Node*> const& _nodes;
98};
99} // namespace MeshLib
Definition of the Element class.
#define OGS_FATAL(...)
Definition Error.h:26
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
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:96
Mesh const & _msh
Definition MeshSubset.h:95
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:78
std::vector< Element * >::const_iterator elementsEnd() const
Definition MeshSubset.h:85
Mesh const & getMesh() const
Definition MeshSubset.h:92
std::size_t getMeshID() const
return this mesh ID
Definition MeshSubset.h:76
std::vector< Element * >::const_iterator elementsBegin() const
Definition MeshSubset.h:80
bool const _use_taylor_hood_elements
Definition MeshSubset.h:97
std::vector< Node * > const & getNodes() const
Definition MeshSubset.h:90
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:106
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
std::size_t getID() const
Get id of the mesh.
Definition Mesh.h:121