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 197 of file MeshIO.cpp.

198{
200 {
201 return "line";
202 }
204 {
205 return "quad";
206 }
208 {
209 return "hex";
210 }
212 {
213 return "tri";
214 }
216 {
217 return "tet";
218 }
220 {
221 return "pris";
222 }
224 {
225 return "pyra";
226 }
227 return "none";
228}

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 47 of file MeshIO.cpp.

49{
50 std::string elem_type_str;
52
53 do
54 {
55 if (!(in >> elem_type_str))
56 {
57 return nullptr;
58 }
59 elem_type = MeshLib::String2MeshElemType(elem_type_str);
60 } while (elem_type == MeshLib::MeshElemType::INVALID);
61
62 auto* idx = new unsigned[8];
63 MeshLib::Element* elem;
64
65 switch (elem_type)
66 {
68 {
69 for (int i = 0; i < 2; ++i)
70 {
71 if (!(in >> idx[i]))
72 {
73 return nullptr;
74 }
75 }
76 // edge_nodes array will be deleted from Line object
77 auto** edge_nodes = new MeshLib::Node*[2];
78 for (unsigned k(0); k < 2; ++k)
79 {
80 edge_nodes[k] = nodes[idx[k]];
81 }
82 elem = new MeshLib::Line(edge_nodes);
83 break;
84 }
86 {
87 for (int i = 0; i < 3; ++i)
88 {
89 if (!(in >> idx[i]))
90 {
91 return nullptr;
92 }
93 }
94 auto** tri_nodes = new MeshLib::Node*[3];
95 for (unsigned k(0); k < 3; ++k)
96 {
97 tri_nodes[k] = nodes[idx[k]];
98 }
99 elem = new MeshLib::Tri(tri_nodes);
100 break;
101 }
103 {
104 for (int i = 0; i < 4; ++i)
105 {
106 if (!(in >> idx[i]))
107 {
108 return nullptr;
109 }
110 }
111 auto** quad_nodes = new MeshLib::Node*[4];
112 for (unsigned k(0); k < 4; ++k)
113 {
114 quad_nodes[k] = nodes[idx[k]];
115 }
116 elem = new MeshLib::Quad(quad_nodes);
117 break;
118 }
120 {
121 for (int i = 0; i < 4; ++i)
122 {
123 if (!(in >> idx[i]))
124 {
125 return nullptr;
126 }
127 }
128 auto** tet_nodes = new MeshLib::Node*[4];
129 for (unsigned k(0); k < 4; ++k)
130 {
131 tet_nodes[k] = nodes[idx[k]];
132 }
133 elem = new MeshLib::Tet(tet_nodes);
134 break;
135 }
137 {
138 for (int i = 0; i < 8; ++i)
139 {
140 if (!(in >> idx[i]))
141 {
142 return nullptr;
143 }
144 }
145 auto** hex_nodes = new MeshLib::Node*[8];
146 for (unsigned k(0); k < 8; ++k)
147 {
148 hex_nodes[k] = nodes[idx[k]];
149 }
150 elem = new MeshLib::Hex(hex_nodes);
151 break;
152 }
154 {
155 for (int i = 0; i < 5; ++i)
156 {
157 if (!(in >> idx[i]))
158 {
159 return nullptr;
160 }
161 }
162 auto** pyramid_nodes = new MeshLib::Node*[5];
163 for (unsigned k(0); k < 5; ++k)
164 {
165 pyramid_nodes[k] = nodes[idx[k]];
166 }
167 elem = new MeshLib::Pyramid(pyramid_nodes);
168 break;
169 }
171 {
172 for (int i = 0; i < 6; ++i)
173 {
174 if (!(in >> idx[i]))
175 {
176 return nullptr;
177 }
178 }
179 auto** prism_nodes = new MeshLib::Node*[6];
180 for (unsigned k(0); k < 6; ++k)
181 {
182 prism_nodes[k] = nodes[idx[k]];
183 }
184 elem = new MeshLib::Prism(prism_nodes);
185 break;
186 }
187 default:
188 elem = nullptr;
189 break;
190 }
191
192 delete[] idx;
193
194 return elem;
195}
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:48
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 31 of file MeshIO.cpp.

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

◆ 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 230 of file MeshIO.cpp.

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

References ElemType2StringOutput(), and OGS_FATAL.