OGS
DuplicateMeshComponents.cpp
Go to the documentation of this file.
1
16
18
19namespace MeshLib
20{
21std::vector<Node*> copyNodeVector(const std::vector<Node*>& nodes)
22{
23 const std::size_t nNodes(nodes.size());
24 std::vector<Node*> new_nodes;
25 new_nodes.reserve(nNodes);
26 for (std::size_t k = 0; k < nNodes; ++k)
27 {
28 new_nodes.push_back(new Node(nodes[k]->data(), new_nodes.size()));
29 }
30 return new_nodes;
31}
32
33std::vector<Element*> copyElementVector(
34 std::vector<Element*> const& elements,
35 std::vector<Node*> const& new_nodes,
36 std::vector<std::size_t> const* const node_id_map)
37{
38 std::vector<Element*> new_elements;
39 new_elements.reserve(elements.size());
40 std::transform(elements.begin(), elements.end(),
41 std::back_inserter(new_elements),
42 [&new_nodes, &node_id_map](auto const& element)
43 { return copyElement(element, new_nodes, node_id_map); });
44 return new_elements;
45}
46
49template <typename E>
50Element* copyElement(Element const* const element,
51 const std::vector<Node*>& nodes,
52 std::vector<std::size_t> const* const id_map)
53{
54 unsigned const number_of_element_nodes(element->getNumberOfNodes());
55 auto** new_nodes = new Node*[number_of_element_nodes];
56 if (id_map)
57 {
58 for (unsigned i = 0; i < number_of_element_nodes; ++i)
59 {
60 new_nodes[i] = nodes[(*id_map)[element->getNode(i)->getID()]];
61 }
62 }
63 else
64 {
65 for (unsigned i = 0; i < number_of_element_nodes; ++i)
66 {
67 new_nodes[i] = nodes[element->getNode(i)->getID()];
68 }
69 }
70 return new E(new_nodes);
71}
72
73Element* copyElement(Element const* const element,
74 const std::vector<Node*>& nodes,
75 std::vector<std::size_t> const* const id_map)
76{
77 switch (element->getCellType())
78 {
79 case CellType::LINE2:
80 return copyElement<Line>(element, nodes, id_map);
81 case CellType::LINE3:
82 return copyElement<Line3>(element, nodes, id_map);
83 case CellType::TRI3:
84 return copyElement<Tri>(element, nodes, id_map);
85 case CellType::TRI6:
86 return copyElement<Tri6>(element, nodes, id_map);
87 case CellType::QUAD4:
88 return copyElement<Quad>(element, nodes, id_map);
89 case CellType::QUAD8:
90 return copyElement<Quad8>(element, nodes, id_map);
91 case CellType::QUAD9:
92 return copyElement<Quad9>(element, nodes, id_map);
93 case CellType::TET4:
94 return copyElement<Tet>(element, nodes, id_map);
95 case CellType::TET10:
96 return copyElement<Tet10>(element, nodes, id_map);
97 case CellType::HEX8:
98 return copyElement<Hex>(element, nodes, id_map);
99 case CellType::HEX20:
100 return copyElement<Hex20>(element, nodes, id_map);
102 return copyElement<Pyramid>(element, nodes, id_map);
104 return copyElement<Pyramid13>(element, nodes, id_map);
105 case CellType::PRISM6:
106 return copyElement<Prism>(element, nodes, id_map);
108 return copyElement<Prism15>(element, nodes, id_map);
109 default:
110 {
111 ERR("Error: Unknown cell type.");
112 return nullptr;
113 }
114 }
115}
116
117std::vector<Element*> cloneElements(std::vector<Element*> const& elements)
118{
119 std::vector<Element*> cloned_elements;
120 cloned_elements.reserve(elements.size());
121 std::transform(begin(elements), end(elements),
122 std::back_inserter(cloned_elements),
123 [](Element const* const e) { return e->clone(); });
124 return cloned_elements;
125}
126
127} // namespace MeshLib
Definition of Duplicate functions.
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
std::size_t getID() const
virtual CellType getCellType() const =0
virtual unsigned getNumberOfNodes() const =0
virtual Element * clone() const =0
virtual const Node * getNode(unsigned idx) const =0
std::vector< Node * > copyNodeVector(const std::vector< Node * > &nodes)
Creates a deep copy of a Node vector.
Element * copyElement(Element const *const element, const std::vector< Node * > &nodes, std::vector< std::size_t > const *const id_map)
std::vector< Element * > copyElementVector(std::vector< Element * > const &elements, std::vector< Node * > const &new_nodes, std::vector< std::size_t > const *const node_id_map)
std::vector< Element * > cloneElements(std::vector< Element * > const &elements)
Clones a vector of elements using the Element::clone() function.