OGS 6.1.0-1721-g6382411ad
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  nodes[i] = const_cast<MeshLib::Node*>(vec_new_nodes[e->getNode(i)->getID()]);
40  return new T_ELEMENT(nodes);
41 }
42 
43 } // unnamed namespace
44 
45 
46 std::unique_ptr<MeshLib::Mesh> convertToLinearMesh(MeshLib::Mesh const& org_mesh, std::string const& new_mesh_name)
47 {
48  std::vector<MeshLib::Node*> vec_new_nodes = MeshLib::copyNodeVector(MeshLib::getBaseNodes(org_mesh.getElements()));
49 
50  // create new elements with the quadratic nodes
51  std::vector<MeshLib::Element*> vec_new_eles;
52  for (MeshLib::Element const* e : org_mesh.getElements())
53  {
54  if (e->getCellType() == MeshLib::CellType::LINE3)
55  {
56  vec_new_eles.push_back(createLinearElement<MeshLib::Line>(
57  e, vec_new_nodes));
58  }
59  else if (e->getCellType() == MeshLib::CellType::QUAD8)
60  {
61  vec_new_eles.push_back(createLinearElement<MeshLib::Quad>(
62  e, vec_new_nodes));
63  }
64  else if (e->getCellType() == MeshLib::CellType::TRI6)
65  {
66  vec_new_eles.push_back(createLinearElement<MeshLib::Tri>(
67  e, vec_new_nodes));
68  }
69  else if (e->getCellType() == MeshLib::CellType::HEX20)
70  {
71  vec_new_eles.push_back(createLinearElement<MeshLib::Hex>(
72  e, vec_new_nodes));
73  }
74  else if (e->getCellType() == MeshLib::CellType::TET10)
75  {
76  vec_new_eles.push_back(createLinearElement<MeshLib::Tet>(
77  e, vec_new_nodes));
78  }
79  else
80  {
81  OGS_FATAL("Mesh element type %s is not supported", MeshLib::CellType2String(e->getCellType()).c_str());
82  }
83  }
84 
85  auto new_mesh = std::make_unique<MeshLib::Mesh>(
86  new_mesh_name, vec_new_nodes, vec_new_eles,
88  std::vector<MeshLib::MeshItemType>(1,
90 
91  // copy property vectors for nodes
92  MeshLib::Properties const& src_properties = org_mesh.getProperties();
93  for (auto name : src_properties.getPropertyVectorNames())
94  {
95  if (!src_properties.existsPropertyVector<double>(name))
96  continue;
97  auto const* src_prop = src_properties.getPropertyVector<double>(name);
98  if (src_prop->getMeshItemType() != MeshLib::MeshItemType::Node)
99  continue;
100 
101  auto const n_src_comp = src_prop->getNumberOfComponents();
102  auto new_prop =
103  new_mesh->getProperties().createNewPropertyVector<double>(
104  name, MeshLib::MeshItemType::Node, n_src_comp);
105  new_prop->resize(new_mesh->getNumberOfNodes() * n_src_comp);
106 
107  // copy only base node values
108  for (unsigned i=0; i<org_mesh.getNumberOfBaseNodes(); i++)
109  {
110  for (int j = 0; j < n_src_comp; j++)
111  (*new_prop)[i*n_src_comp+j] = (*src_prop)[i*n_src_comp+j];
112  }
113  }
114 
115  return new_mesh;
116 }
117 
118 } // end namespace MeshLib
119 
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:104
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:63
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:57
Interface for heuristic search length strategy.
Definition: ProjectData.h:28
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:71
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:144