OGS 6.2.0-97-g4a610c866
ConvertToLinearMesh.cpp
Go to the documentation of this file.
1 
10 #include "ConvertToLinearMesh.h"
11 
13 #include "MeshLib/Elements/Line.h"
14 #include "MeshLib/Elements/Quad.h"
15 #include "MeshLib/Elements/Hex.h"
16 #include "MeshLib/Elements/Tet.h"
17 #include "MeshLib/Elements/Tri.h"
18 #include "MeshLib/Elements/Utils.h"
19 #include "MeshLib/Mesh.h"
21 #include "MeshLib/Node.h"
22 #include "MeshLib/Properties.h"
23 #include "MeshLib/PropertyVector.h"
24 
25 
26 namespace MeshLib
27 {
28 
29 namespace
30 {
31 
32 template <typename T_ELEMENT>
34  std::vector<MeshLib::Node*> const& vec_new_nodes)
35 {
36  auto const n_base_nodes = T_ELEMENT::n_base_nodes;
37  auto** nodes = new MeshLib::Node*[n_base_nodes];
38  for (unsigned i = 0; i < e->getNumberOfBaseNodes(); i++)
39  {
40  nodes[i] =
41  const_cast<MeshLib::Node*>(vec_new_nodes[e->getNode(i)->getID()]);
42  }
43  return new T_ELEMENT(nodes);
44 }
45 
46 } // unnamed namespace
47 
48 
49 std::unique_ptr<MeshLib::Mesh> convertToLinearMesh(MeshLib::Mesh const& org_mesh, std::string const& new_mesh_name)
50 {
51  std::vector<MeshLib::Node*> vec_new_nodes = MeshLib::copyNodeVector(MeshLib::getBaseNodes(org_mesh.getElements()));
52 
53  // create new elements with the quadratic nodes
54  std::vector<MeshLib::Element*> vec_new_eles;
55  for (MeshLib::Element const* e : org_mesh.getElements())
56  {
57  if (e->getCellType() == MeshLib::CellType::LINE3)
58  {
59  vec_new_eles.push_back(createLinearElement<MeshLib::Line>(
60  e, vec_new_nodes));
61  }
62  else if (e->getCellType() == MeshLib::CellType::QUAD8)
63  {
64  vec_new_eles.push_back(createLinearElement<MeshLib::Quad>(
65  e, vec_new_nodes));
66  }
67  else if (e->getCellType() == MeshLib::CellType::TRI6)
68  {
69  vec_new_eles.push_back(createLinearElement<MeshLib::Tri>(
70  e, vec_new_nodes));
71  }
72  else if (e->getCellType() == MeshLib::CellType::HEX20)
73  {
74  vec_new_eles.push_back(createLinearElement<MeshLib::Hex>(
75  e, vec_new_nodes));
76  }
77  else if (e->getCellType() == MeshLib::CellType::TET10)
78  {
79  vec_new_eles.push_back(createLinearElement<MeshLib::Tet>(
80  e, vec_new_nodes));
81  }
82  else
83  {
84  OGS_FATAL("Mesh element type %s is not supported", MeshLib::CellType2String(e->getCellType()).c_str());
85  }
86  }
87 
88  auto new_mesh = std::make_unique<MeshLib::Mesh>(
89  new_mesh_name, vec_new_nodes, vec_new_eles,
91  std::vector<MeshLib::MeshItemType>(1,
93 
94  // copy property vectors for nodes
95  MeshLib::Properties const& src_properties = org_mesh.getProperties();
96  for (auto name : src_properties.getPropertyVectorNames())
97  {
98  if (!src_properties.existsPropertyVector<double>(name))
99  {
100  continue;
101  }
102  auto const* src_prop = src_properties.getPropertyVector<double>(name);
103  if (src_prop->getMeshItemType() != MeshLib::MeshItemType::Node)
104  {
105  continue;
106  }
107 
108  auto const n_src_comp = src_prop->getNumberOfComponents();
109  auto new_prop =
110  new_mesh->getProperties().createNewPropertyVector<double>(
111  name, MeshLib::MeshItemType::Node, n_src_comp);
112  new_prop->resize(new_mesh->getNumberOfNodes() * n_src_comp);
113 
114  // copy only base node values
115  for (unsigned i=0; i<org_mesh.getNumberOfBaseNodes(); i++)
116  {
117  for (int j = 0; j < n_src_comp; j++)
118  {
119  (*new_prop)[i * n_src_comp + j] =
120  (*src_prop)[i * n_src_comp + j];
121  }
122  }
123  }
124 
125  return new_mesh;
126 }
127 
128 } // end namespace MeshLib
129 
virtual unsigned getNumberOfBaseNodes() const =0
std::vector< Node * > getBaseNodes(std::vector< Element *> const &elements)
Definition: Utils.h:25
const std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.
Definition: MeshEnums.cpp:154
Definition of the Line class.
std::size_t getNumberOfBaseNodes() const
Get the number of base nodes.
Definition: Mesh.h:126
Definition of the Node class.
Definition of the Tet class.
MeshLib::Properties & getProperties()
Definition: Mesh.h:134
Definition of the Mesh class.
std::size_t getID() const
Definition: Point3dWithID.h:64
std::unique_ptr< MeshLib::Mesh > convertToLinearMesh(MeshLib::Mesh const &org_mesh, std::string const &new_mesh_name)
Definition of the Tri class.
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties...
Definition: Properties.h:37
Properties excludeCopyProperties(std::vector< std::size_t > const &exclude_elem_ids, std::vector< std::size_t > const &exclude_node_ids) const
Definition: Properties.cpp:61
Interface for heuristic search length strategy.
Definition: ProjectData.h:29
Definition of Duplicate functions.
std::vector< MeshLib::Node * > copyNodeVector(const std::vector< MeshLib::Node *> &nodes)
Creates a deep copy of a Node vector.
PropertyVector< T > const * getPropertyVector(std::string const &name) const
Definition: Properties.h:119
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:108
Definition of the Quad class.
Definition of the class Properties that implements a container of properties.
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
Definition of the Element class.
Definition of the Hex class.
T_ELEMENT * createLinearElement(MeshLib::Element const *e, std::vector< MeshLib::Node *> const &vec_new_nodes)
const Node * getNode(unsigned i) const
Definition: Element.cpp:156