OGS
MeshEnums.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "MeshEnums.h"
5
6#include <boost/algorithm/string/predicate.hpp>
7
8#include "BaseLib/Error.h"
9
10namespace MeshLib
11{
13{
14 if (t == MeshElemType::POINT)
15 {
16 return "Point";
17 }
18 if (t == MeshElemType::LINE)
19 {
20 return "Line";
21 }
22 if (t == MeshElemType::QUAD)
23 {
24 return "Quad";
25 }
27 {
28 return "Hexahedron";
29 }
31 {
32 return "Triangle";
33 }
35 {
36 return "Tetrahedron";
37 }
38 if (t == MeshElemType::PRISM)
39 {
40 return "Prism";
41 }
42 if (t == MeshElemType::PYRAMID)
43 {
44 return "Pyramid";
45 }
46 return "none";
47}
48
50{
51 if (t == MeshElemType::POINT)
52 {
53 return "point";
54 }
55 if (t == MeshElemType::LINE)
56 {
57 return "line";
58 }
59 if (t == MeshElemType::QUAD)
60 {
61 return "quad";
62 }
64 {
65 return "hex";
66 }
68 {
69 return "tri";
70 }
72 {
73 return "tet";
74 }
75 if (t == MeshElemType::PRISM)
76 {
77 return "pris";
78 }
79 if (t == MeshElemType::PYRAMID)
80 {
81 return "pyra";
82 }
83 return "none";
84}
85
86MeshElemType String2MeshElemType(const std::string& s)
87{
88 if (boost::iequals(s, "point"))
89 {
91 }
92 if (boost::iequals(s, "line"))
93 {
94 return MeshElemType::LINE;
95 }
96 if (boost::iequals(s, "quad") || boost::iequals(s, "Quadrilateral"))
97 {
98 return MeshElemType::QUAD;
99 }
100 if (boost::iequals(s, "hex") || boost::iequals(s, "Hexahedron"))
101 {
103 }
104 if (boost::iequals(s, "tri") || boost::iequals(s, "Triangle"))
105 {
107 }
108 if (boost::iequals(s, "tet") || boost::iequals(s, "Tetrahedron"))
109 {
111 }
112 if (boost::iequals(s, "pris") || boost::iequals(s, "Prism"))
113 {
114 return MeshElemType::PRISM;
115 }
116 if (boost::iequals(s, "pyra") || boost::iequals(s, "Pyramid"))
117 {
119 }
121}
122
123std::vector<MeshElemType> getMeshElemTypes()
124{
125 std::vector<MeshElemType> vec;
126 vec.push_back(MeshElemType::POINT);
127 vec.push_back(MeshElemType::LINE);
128 vec.push_back(MeshElemType::QUAD);
129 vec.push_back(MeshElemType::HEXAHEDRON);
130 vec.push_back(MeshElemType::TRIANGLE);
131 vec.push_back(MeshElemType::TETRAHEDRON);
132 vec.push_back(MeshElemType::PRISM);
133 vec.push_back(MeshElemType::PYRAMID);
134 return vec;
135}
136
137std::vector<std::string> getMeshElemTypeStringsShort()
138{
139 std::vector<std::string> vec;
140 auto const& mesh_elem_types = getMeshElemTypes();
141 std::transform(mesh_elem_types.begin(), mesh_elem_types.end(),
142 std::back_inserter(vec),
143 [](auto const& element_type)
144 { return MeshElemType2StringShort(element_type); });
145 return vec;
146}
147
148std::string CellType2String(const CellType t)
149{
150#define RETURN_CELL_TYPE_STR(t, type) \
151 if ((t) == CellType::type) \
152 return #type;
153
171
172 return "none";
173
174#undef RETURN_CELL_TYPE_STR
175}
176
178{
180 {
181 return "ElementSize";
182 }
184 {
185 return "EdgeRatio";
186 }
188 {
189 return "EquiAngleSkew";
190 }
192 {
193 return "RadiusEdgeRatio";
194 }
196 {
197 return "SizeDifference";
198 }
199 return "none";
200}
201
203{
204 if (boost::iequals(s, "ElementSize"))
205 {
207 }
208 if (boost::iequals(s, "EdgeRatio"))
209 {
211 }
212 if (boost::iequals(s, "EquiAngleSkew"))
213 {
215 }
216 if (boost::iequals(s, "RadiusEdgeRatio"))
217 {
219 }
220 if (boost::iequals(s, "SizeDifference"))
221 {
223 }
225}
226
228{
229 if (boost::iequals(s, toString(MeshItemType::Node)))
230 {
231 return MeshItemType::Node;
232 }
233 if (boost::iequals(s, toString(MeshItemType::Edge)))
234 {
235 return MeshItemType::Edge;
236 }
237 if (boost::iequals(s, toString(MeshItemType::Face)))
238 {
239 return MeshItemType::Face;
240 }
241 if (boost::iequals(s, toString(MeshItemType::Cell)))
242 {
243 return MeshItemType::Cell;
244 }
245 if (boost::iequals(s, toString(MeshItemType::IntegrationPoint)))
246 {
248 }
249 OGS_FATAL(
250 "The mesh item type '{:s}' is unknown. Valid values are "
251 "'cell', 'integration_point', 'edge', 'face' and 'node'.",
252 s);
253}
254
255} // namespace MeshLib
#define OGS_FATAL(...)
Definition Error.h:10
#define RETURN_CELL_TYPE_STR(t, type)
MeshElemType String2MeshElemType(const std::string &s)
Definition MeshEnums.cpp:86
CellType
Types of mesh elements supported by OpenGeoSys.
Definition MeshEnums.h:58
MeshLib::MeshQualityType String2MeshQualityType(std::string const &s)
std::string MeshElemType2String(const MeshElemType t)
Given a MeshElemType this returns the appropriate string.
Definition MeshEnums.cpp:12
MeshQualityType
Describes a mesh quality metric.
Definition MeshEnums.h:85
std::vector< MeshElemType > getMeshElemTypes()
Returns a vector of all mesh element types.
std::string MeshElemType2StringShort(const MeshElemType t)
Given a MeshElemType this returns the appropriate string with a short name.
Definition MeshEnums.cpp:49
std::vector< std::string > getMeshElemTypeStringsShort()
Returns a vector of strings of mesh element types.
std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.
std::string MeshQualityType2String(const MeshQualityType t)
static constexpr char const * toString(const MeshItemType t)
Returns a char array for a specific MeshItemType.
Definition MeshEnums.h:26
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:42
MeshItemType string2MeshItemType(const std::string &s)