OGS
FlipElements.cpp
Go to the documentation of this file.
1
11#include "FlipElements.h"
12
17#include "MeshLib/Node.h"
19
20namespace MeshToolsLib
21{
22std::unique_ptr<MeshLib::Element> createFlippedElement(
23 MeshLib::Element const& elem, std::vector<MeshLib::Node*> const& nodes)
24{
25 if (elem.getDimension() > 2)
26 {
27 return nullptr;
28 }
29
30 unsigned const n_nodes(elem.getNumberOfNodes());
31 auto elem_nodes = std::make_unique<MeshLib::Node*[]>(n_nodes);
32 for (unsigned i = 0; i < n_nodes; ++i)
33 {
34 elem_nodes[i] = nodes[elem.getNode(i)->getID()];
35 }
36 std::swap(elem_nodes[0], elem_nodes[1]);
37
39 {
40 return std::make_unique<MeshLib::Line>(elem_nodes.release(),
41 elem.getID());
42 }
44 {
45 return std::make_unique<MeshLib::Tri>(elem_nodes.release(),
46 elem.getID());
47 }
49 {
50 std::swap(elem_nodes[2], elem_nodes[3]);
51 return std::make_unique<MeshLib::Quad>(elem_nodes.release(),
52 elem.getID());
53 }
54 return nullptr;
55}
56
57std::unique_ptr<MeshLib::Mesh> createFlippedMesh(MeshLib::Mesh const& mesh)
58{
59 if (mesh.getDimension() > 2)
60 {
61 return nullptr;
62 }
63
64 std::vector<MeshLib::Node*> new_nodes(copyNodeVector(mesh.getNodes()));
65 std::vector<MeshLib::Element*> const& elems(mesh.getElements());
66 std::vector<MeshLib::Element*> new_elems;
67 std::size_t n_elems(mesh.getNumberOfElements());
68 new_elems.reserve(n_elems);
69
70 for (std::size_t i = 0; i < n_elems; ++i)
71 {
72 new_elems.push_back(
73 createFlippedElement(*elems[i], new_nodes).release());
74 }
75
76 return std::make_unique<MeshLib::Mesh>(
77 "FlippedElementMesh", new_nodes, new_elems,
78 true /* compute_element_neighbors */, mesh.getProperties());
79}
80
81} // namespace MeshToolsLib
Definition of Duplicate functions.
Definition of the Element class.
Definition of the Line class.
Definition of the Node class.
Definition of the Quad class.
Definition of the Tri class.
std::size_t getID() const
virtual MeshElemType getGeomType() const =0
virtual unsigned getNumberOfNodes() const =0
virtual const Node * getNode(unsigned idx) const =0
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
std::size_t getID() const
Returns the ID of the element.
Definition Element.h:89
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
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:88
Properties & getProperties()
Definition Mesh.h:134
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:97
std::unique_ptr< MeshLib::Element > createFlippedElement(MeshLib::Element const &elem, std::vector< MeshLib::Node * > const &nodes)
std::unique_ptr< MeshLib::Mesh > createFlippedMesh(MeshLib::Mesh const &mesh)