OGS
QuadraticMeshGenerator.cpp File Reference

Detailed Description

Definition in file QuadraticMeshGenerator.cpp.

Include dependency graph for QuadraticMeshGenerator.cpp:

Go to the source code of this file.

Classes

struct  nodeByCoordinatesComparator
 

Namespaces

namespace  MeshToolsLib
 

Functions

template<typename QuadraticElement >
std::unique_ptr< QuadraticElement > convertLinearToQuadratic (MeshLib::Element const &e)
 
template<>
std::unique_ptr< MeshLib::Quad9convertLinearToQuadratic< MeshLib::Quad9 > (MeshLib::Element const &e)
 Special case for Quad-9 adding a centre node too.
 
template<>
std::unique_ptr< MeshLib::Prism15convertLinearToQuadratic< MeshLib::Prism15 > (MeshLib::Element const &e)
 Special case for Prism15.
 
std::unique_ptr< MeshLib::ElementcreateQuadraticElement (MeshLib::Element const &e, bool const add_centre_node)
 Return a new quadratic element corresponding to the linear element's type.
 
std::unique_ptr< MeshLib::MeshMeshToolsLib::createQuadraticOrderMesh (MeshLib::Mesh const &linear_mesh, bool const add_centre_node)
 

Function Documentation

◆ convertLinearToQuadratic()

template<typename QuadraticElement >
std::unique_ptr< QuadraticElement > convertLinearToQuadratic ( MeshLib::Element const & e)

Given an (linear) element divide all its edges by inserting a point in the middle and return a new element.

Definition at line 29 of file QuadraticMeshGenerator.cpp.

31{
32 int const n_all_nodes = QuadraticElement::n_all_nodes;
33 int const n_base_nodes = QuadraticElement::n_base_nodes;
34 assert(n_base_nodes == e.getNumberOfBaseNodes());
35
36 // Copy base nodes of element to the quadratic element new nodes'.
37 std::array<MeshLib::Node*, n_all_nodes> nodes{};
38 for (int i = 0; i < n_base_nodes; i++)
39 {
40 nodes[i] = const_cast<MeshLib::Node*>(e.getNode(i));
41 }
42
43 // For each edge create a middle node.
44 int const number_of_edges = e.getNumberOfEdges();
45 for (int i = 0; i < number_of_edges; i++)
46 {
47 auto const& a = *e.getEdgeNode(i, 0);
48 auto const& b = *e.getEdgeNode(i, 1);
49
50 nodes[n_base_nodes + i] = new MeshLib::Node(
51 (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2);
52 }
53
54 return std::make_unique<QuadraticElement>(nodes, e.getID());
55}

References MeshLib::Element::getEdgeNode(), MeshLib::Element::getID(), MeshLib::Element::getNode(), MeshLib::Element::getNumberOfBaseNodes(), MeshLib::Element::getNumberOfEdges(), and MeshLib::Node.

◆ convertLinearToQuadratic< MeshLib::Prism15 >()

template<>
std::unique_ptr< MeshLib::Prism15 > convertLinearToQuadratic< MeshLib::Prism15 > ( MeshLib::Element const & e)

Special case for Prism15.

Definition at line 29 of file QuadraticMeshGenerator.cpp.

102{
103 int const n_all_nodes = MeshLib::Prism15::n_all_nodes;
104 int const n_base_nodes = MeshLib::Prism15::n_base_nodes;
105 assert(n_base_nodes == e.getNumberOfBaseNodes());
106
107 // Copy base nodes of element to the quadratic element new nodes'.
108 std::array<MeshLib::Node*, n_all_nodes> nodes{};
109 for (int i = 0; i < n_base_nodes; i++)
110 {
111 nodes[i] = const_cast<MeshLib::Node*>(e.getNode(i));
112 }
113
114 // For each edge create a middle node.
115 int const number_of_edges = e.getNumberOfEdges();
116 for (int i = 0; i < 3; i++)
117 {
118 auto const& a = *e.getEdgeNode(i, 0);
119 auto const& b = *e.getEdgeNode(i, 1);
120
121 nodes[n_base_nodes + i] = new MeshLib::Node(
122 (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2);
123 }
124 for (int i = 3; i < 6; i++)
125 {
126 auto const& a = *e.getEdgeNode(i + 3, 0);
127 auto const& b = *e.getEdgeNode(i + 3, 1);
128
129 nodes[n_base_nodes + i] = new MeshLib::Node(
130 (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2);
131 }
132 for (int i = 6; i < number_of_edges; i++)
133 {
134 auto const& a = *e.getEdgeNode(i - 3, 0);
135 auto const& b = *e.getEdgeNode(i - 3, 1);
136
137 nodes[n_base_nodes + i] = new MeshLib::Node(
138 (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2);
139 }
140
141 return std::make_unique<MeshLib::Prism15>(nodes, e.getID());
142}
static const unsigned n_all_nodes
Constant: The number of all nodes for this element.
static const unsigned n_base_nodes
Constant: The number of base nodes for this element.

Referenced by createQuadraticElement().

◆ convertLinearToQuadratic< MeshLib::Quad9 >()

template<>
std::unique_ptr< MeshLib::Quad9 > convertLinearToQuadratic< MeshLib::Quad9 > ( MeshLib::Element const & e)

Special case for Quad-9 adding a centre node too.

Definition at line 29 of file QuadraticMeshGenerator.cpp.

61{
62 int const n_all_nodes = MeshLib::Quad9::n_all_nodes;
63 int const n_base_nodes = MeshLib::Quad9::n_base_nodes;
64 assert(n_base_nodes == e.getNumberOfBaseNodes());
65
66 // Copy base nodes of element to the quadratic element new nodes'.
67 std::array<MeshLib::Node*, n_all_nodes> nodes{};
68 for (int i = 0; i < n_base_nodes; i++)
69 {
70 nodes[i] = const_cast<MeshLib::Node*>(e.getNode(i));
71 }
72
73 // For each edge create a middle node.
74 int const number_of_edges = e.getNumberOfEdges();
75 for (int i = 0; i < number_of_edges; i++)
76 {
77 auto const& a = *e.getEdgeNode(i, 0);
78 auto const& b = *e.getEdgeNode(i, 1);
79
80 nodes[n_base_nodes + i] = new MeshLib::Node(
81 (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2);
82 }
83
84 // Compute the centre point coordinates.
85 auto* centre_node = new MeshLib::Node(0, 0, 0);
86 for (int i = 0; i < n_base_nodes; i++)
87 {
88 for (int d = 0; d < 3; d++)
89 {
90 (*centre_node)[d] += (*nodes[i])[d] / n_base_nodes;
91 }
92 }
93 nodes[n_all_nodes - 1] = centre_node;
94
95 return std::make_unique<MeshLib::Quad9>(nodes, e.getID());
96}

Referenced by createQuadraticElement().

◆ createQuadraticElement()

std::unique_ptr< MeshLib::Element > createQuadraticElement ( MeshLib::Element const & e,
bool const add_centre_node )

Return a new quadratic element corresponding to the linear element's type.

Definition at line 145 of file QuadraticMeshGenerator.cpp.

147{
148 if (e.getCellType() == MeshLib::CellType::LINE2)
149 {
150 return convertLinearToQuadratic<MeshLib::Line3>(e);
151 }
152 if (e.getCellType() == MeshLib::CellType::TRI3)
153 {
154 return convertLinearToQuadratic<MeshLib::Tri6>(e);
155 }
156 if (e.getCellType() == MeshLib::CellType::TET4)
157 {
158 return convertLinearToQuadratic<MeshLib::Tet10>(e);
159 }
160 if (e.getCellType() == MeshLib::CellType::QUAD4)
161 {
162 if (add_centre_node)
163 {
165 }
166 return convertLinearToQuadratic<MeshLib::Quad8>(e);
167 }
168 if (e.getCellType() == MeshLib::CellType::HEX8)
169 {
170 return convertLinearToQuadratic<MeshLib::Hex20>(e);
171 }
172 if (e.getCellType() == MeshLib::CellType::PRISM6)
173 {
175 }
176 if (e.getCellType() == MeshLib::CellType::PYRAMID5)
177 {
178 return convertLinearToQuadratic<MeshLib::Pyramid13>(e);
179 }
180
181 OGS_FATAL("Mesh element type {:s} is not supported",
182 MeshLib::CellType2String(e.getCellType()));
183}
#define OGS_FATAL(...)
Definition Error.h:26
std::unique_ptr< MeshLib::Prism15 > convertLinearToQuadratic< MeshLib::Prism15 >(MeshLib::Element const &e)
Special case for Prism15.
std::unique_ptr< MeshLib::Quad9 > convertLinearToQuadratic< MeshLib::Quad9 >(MeshLib::Element const &e)
Special case for Quad-9 adding a centre node too.
std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.

References MeshLib::CellType2String(), convertLinearToQuadratic< MeshLib::Prism15 >(), convertLinearToQuadratic< MeshLib::Quad9 >(), MeshLib::Element::getCellType(), MeshLib::HEX8, MeshLib::LINE2, OGS_FATAL, MeshLib::PRISM6, MeshLib::PYRAMID5, MeshLib::QUAD4, MeshLib::TET4, and MeshLib::TRI3.

Referenced by MeshToolsLib::createQuadraticOrderMesh().