OGS
anonymous_namespace{MeshIO.cpp} Namespace Reference

Functions

int readMaterialID (std::istream &in)
 
MeshLib::ElementreadElement (std::istream &in, const std::vector< MeshLib::Node * > &nodes)
 
std::string ElemType2StringOutput (const MeshLib::MeshElemType t)
 
void writeElements (std::vector< MeshLib::Element * > const &ele_vec, MeshLib::PropertyVector< int > const *const material_ids, std::ostream &out)
 

Function Documentation

◆ ElemType2StringOutput()

std::string anonymous_namespace{MeshIO.cpp}::ElemType2StringOutput ( const MeshLib::MeshElemType t)

Definition at line 198 of file MeshIO.cpp.

199{
201 {
202 return "line";
203 }
205 {
206 return "quad";
207 }
209 {
210 return "hex";
211 }
213 {
214 return "tri";
215 }
217 {
218 return "tet";
219 }
221 {
222 return "pris";
223 }
225 {
226 return "pyra";
227 }
228 return "none";
229}

References MeshLib::HEXAHEDRON, MeshLib::LINE, MeshLib::PRISM, MeshLib::PYRAMID, MeshLib::QUAD, MeshLib::TETRAHEDRON, and MeshLib::TRIANGLE.

Referenced by writeElements().

◆ readElement()

MeshLib::Element * anonymous_namespace{MeshIO.cpp}::readElement ( std::istream & in,
const std::vector< MeshLib::Node * > & nodes )

Definition at line 48 of file MeshIO.cpp.

50{
51 std::string elem_type_str;
53
54 do
55 {
56 if (!(in >> elem_type_str))
57 {
58 return nullptr;
59 }
60 elem_type = MeshLib::String2MeshElemType(elem_type_str);
61 } while (elem_type == MeshLib::MeshElemType::INVALID);
62
63 auto* idx = new unsigned[8];
64 MeshLib::Element* elem;
65
66 switch (elem_type)
67 {
69 {
70 for (int i = 0; i < 2; ++i)
71 {
72 if (!(in >> idx[i]))
73 {
74 return nullptr;
75 }
76 }
77 // edge_nodes array will be deleted from Line object
78 auto** edge_nodes = new MeshLib::Node*[2];
79 for (unsigned k(0); k < 2; ++k)
80 {
81 edge_nodes[k] = nodes[idx[k]];
82 }
83 elem = new MeshLib::Line(edge_nodes);
84 break;
85 }
87 {
88 for (int i = 0; i < 3; ++i)
89 {
90 if (!(in >> idx[i]))
91 {
92 return nullptr;
93 }
94 }
95 auto** tri_nodes = new MeshLib::Node*[3];
96 for (unsigned k(0); k < 3; ++k)
97 {
98 tri_nodes[k] = nodes[idx[k]];
99 }
100 elem = new MeshLib::Tri(tri_nodes);
101 break;
102 }
104 {
105 for (int i = 0; i < 4; ++i)
106 {
107 if (!(in >> idx[i]))
108 {
109 return nullptr;
110 }
111 }
112 auto** quad_nodes = new MeshLib::Node*[4];
113 for (unsigned k(0); k < 4; ++k)
114 {
115 quad_nodes[k] = nodes[idx[k]];
116 }
117 elem = new MeshLib::Quad(quad_nodes);
118 break;
119 }
121 {
122 for (int i = 0; i < 4; ++i)
123 {
124 if (!(in >> idx[i]))
125 {
126 return nullptr;
127 }
128 }
129 auto** tet_nodes = new MeshLib::Node*[4];
130 for (unsigned k(0); k < 4; ++k)
131 {
132 tet_nodes[k] = nodes[idx[k]];
133 }
134 elem = new MeshLib::Tet(tet_nodes);
135 break;
136 }
138 {
139 for (int i = 0; i < 8; ++i)
140 {
141 if (!(in >> idx[i]))
142 {
143 return nullptr;
144 }
145 }
146 auto** hex_nodes = new MeshLib::Node*[8];
147 for (unsigned k(0); k < 8; ++k)
148 {
149 hex_nodes[k] = nodes[idx[k]];
150 }
151 elem = new MeshLib::Hex(hex_nodes);
152 break;
153 }
155 {
156 for (int i = 0; i < 5; ++i)
157 {
158 if (!(in >> idx[i]))
159 {
160 return nullptr;
161 }
162 }
163 auto** pyramid_nodes = new MeshLib::Node*[5];
164 for (unsigned k(0); k < 5; ++k)
165 {
166 pyramid_nodes[k] = nodes[idx[k]];
167 }
168 elem = new MeshLib::Pyramid(pyramid_nodes);
169 break;
170 }
172 {
173 for (int i = 0; i < 6; ++i)
174 {
175 if (!(in >> idx[i]))
176 {
177 return nullptr;
178 }
179 }
180 auto** prism_nodes = new MeshLib::Node*[6];
181 for (unsigned k(0); k < 6; ++k)
182 {
183 prism_nodes[k] = nodes[idx[k]];
184 }
185 elem = new MeshLib::Prism(prism_nodes);
186 break;
187 }
188 default:
189 elem = nullptr;
190 break;
191 }
192
193 delete[] idx;
194
195 return elem;
196}
MeshElemType String2MeshElemType(const std::string &s)
Given a string of the shortened name of the element type, this returns the corresponding MeshElemType...
Definition MeshEnums.cpp:95
TemplateElement< MeshLib::TetRule4 > Tet
Definition Tet.h:25
TemplateElement< MeshLib::LineRule2 > Line
Definition Line.h:25
TemplateElement< MeshLib::QuadRule4 > Quad
Definition Quad.h:28
TemplateElement< MeshLib::TriRule3 > Tri
Definition Tri.h:26
TemplateElement< MeshLib::PyramidRule5 > Pyramid
Definition Pyramid.h:25
TemplateElement< MeshLib::PrismRule6 > Prism
Definition Prism.h:25
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:27
TemplateElement< MeshLib::HexRule8 > Hex
Definition Hex.h:25

References MeshLib::HEXAHEDRON, MeshLib::INVALID, MeshLib::LINE, MeshLib::PRISM, MeshLib::PYRAMID, MeshLib::QUAD, MeshLib::String2MeshElemType(), MeshLib::TETRAHEDRON, and MeshLib::TRIANGLE.

◆ readMaterialID()

int anonymous_namespace{MeshIO.cpp}::readMaterialID ( std::istream & in)

Definition at line 32 of file MeshIO.cpp.

33{
34 unsigned index;
35 unsigned material_id;
36
37 if (!(in >> index >> material_id) ||
38 material_id > static_cast<unsigned>(std::numeric_limits<int>::max()))
39 {
40 // If read incorrectly or the material_id is not safely convertible to
41 // int.
42 return std::numeric_limits<int>::max();
43 }
44 // Safe conversion was checked above.
45 return static_cast<int>(material_id);
46}

◆ writeElements()

void anonymous_namespace{MeshIO.cpp}::writeElements ( std::vector< MeshLib::Element * > const & ele_vec,
MeshLib::PropertyVector< int > const *const material_ids,
std::ostream & out )

Definition at line 231 of file MeshIO.cpp.

234{
235 const std::size_t ele_vector_size(ele_vec.size());
236
237 out << ele_vector_size << "\n";
238 for (std::size_t i(0); i < ele_vector_size; ++i)
239 {
240 auto const& element = *ele_vec[i];
241 if (element.getNumberOfBaseNodes() != element.getNumberOfNodes())
242 {
243 OGS_FATAL(
244 "Found high order element in the mesh that is not required by "
245 "OGS 5 input. High order elements are generated in OGS 5 on "
246 "demand.");
247 }
248
249 out << i << " ";
250 if (!material_ids)
251 {
252 out << "0 ";
253 }
254 else
255 {
256 out << (*material_ids)[i] << " ";
257 }
258 out << ElemType2StringOutput(element.getGeomType()) << " ";
259 unsigned nElemNodes(element.getNumberOfBaseNodes());
260 for (std::size_t j = 0; j < nElemNodes; ++j)
261 {
262 out << element.getNode(j)->getID() << " ";
263 }
264 out << "\n";
265 }
266}
#define OGS_FATAL(...)
Definition Error.h:26
std::string ElemType2StringOutput(const MeshLib::MeshElemType t)
Definition MeshIO.cpp:198

References ElemType2StringOutput(), and OGS_FATAL.