OGS 6.2.1-76-gbb689931b
DuplicateMeshComponents.cpp
Go to the documentation of this file.
1 
16 
17 #include "MeshLib/Mesh.h"
19 
20 namespace MeshLib
21 {
22 
23 std::vector<MeshLib::Node*> copyNodeVector(const std::vector<MeshLib::Node*> &nodes)
24 {
25  const std::size_t nNodes(nodes.size());
26  std::vector<MeshLib::Node*> new_nodes;
27  new_nodes.reserve(nNodes);
28  for (std::size_t k = 0; k < nNodes; ++k)
29  {
30  new_nodes.push_back(
31  new MeshLib::Node(nodes[k]->getCoords(), new_nodes.size()));
32  }
33  return new_nodes;
34 }
35 
36 std::vector<MeshLib::Element*> copyElementVector(const std::vector<MeshLib::Element*> &elements, const std::vector<MeshLib::Node*> &nodes)
37 {
38  const std::size_t nElements(elements.size());
39  std::vector<MeshLib::Element*> new_elements;
40  new_elements.reserve(nElements);
41  for (std::size_t k = 0; k < nElements; ++k)
42  {
43  new_elements.push_back(copyElement(elements[k], nodes));
44  }
45  return new_elements;
46 }
47 
48 MeshLib::Element* copyElement(MeshLib::Element const*const element, const std::vector<MeshLib::Node*> &nodes)
49 {
50  if (element->getGeomType() == MeshElemType::LINE)
51  {
52  return copyElement<MeshLib::Line>(element, nodes);
53  }
54  if (element->getGeomType() == MeshElemType::TRIANGLE)
55  {
56  return copyElement<MeshLib::Tri>(element, nodes);
57  }
58  if (element->getGeomType() == MeshElemType::QUAD)
59  {
60  return copyElement<MeshLib::Quad>(element, nodes);
61  }
62  if (element->getGeomType() == MeshElemType::TETRAHEDRON)
63  {
64  return copyElement<MeshLib::Tet>(element, nodes);
65  }
66  if (element->getGeomType() == MeshElemType::HEXAHEDRON)
67  {
68  return copyElement<MeshLib::Hex>(element, nodes);
69  }
70  if (element->getGeomType() == MeshElemType::PYRAMID)
71  {
72  return copyElement<MeshLib::Pyramid>(element, nodes);
73  }
74  if (element->getGeomType() == MeshElemType::PRISM)
75  {
76  return copyElement<MeshLib::Prism>(element, nodes);
77  }
78 
79  ERR ("Error: Unknown element type.");
80  return nullptr;
81 }
82 
83 template <typename E>
84 MeshLib::Element* copyElement(MeshLib::Element const*const element, const std::vector<MeshLib::Node*> &nodes)
85 {
86  auto** new_nodes = new MeshLib::Node*[element->getNumberOfNodes()];
87  for (unsigned i = 0; i < element->getNumberOfNodes(); ++i)
88  {
89  new_nodes[i] = nodes[element->getNode(i)->getID()];
90  }
91  return new E(new_nodes);
92 }
93 
94 std::vector<MeshLib::Element*> cloneElements(
95  std::vector<MeshLib::Element*> const& elements)
96 {
97  std::vector<MeshLib::Element*> cloned_elements;
98  cloned_elements.reserve(elements.size());
99  std::transform(begin(elements), end(elements),
100  std::back_inserter(cloned_elements),
101  [](MeshLib::Element* const e) { return e->clone(); });
102  return cloned_elements;
103 }
104 
105 } // namespace MeshLib
std::vector< MeshLib::Element * > copyElementVector(const std::vector< MeshLib::Element *> &elements, const std::vector< MeshLib::Node *> &nodes)
std::vector< MeshLib::Element * > cloneElements(std::vector< MeshLib::Element *> const &elements)
Clones a vector of elements using the Element::clone() function.
Definition of the Mesh class.
std::size_t getID() const
Definition: Point3dWithID.h:62
virtual Element * clone() const =0
MeshLib::Element * copyElement(MeshLib::Element const *const element, const std::vector< MeshLib::Node *> &nodes)
Copies an element without change, using the nodes vector from the result mesh.
Interface for heuristic search length strategy.
Definition: ProjectData.h:30
Definition of Duplicate functions.
std::vector< MeshLib::Node * > copyNodeVector(const std::vector< MeshLib::Node *> &nodes)
Creates a deep copy of a Node vector.
virtual unsigned getNumberOfNodes() const =0
Returns the number of all nodes including both linear and nonlinear nodes.
virtual MeshElemType getGeomType() const =0
const Node * getNode(unsigned i) const
Definition: Element.cpp:158