39 #include "GmshMeshReader.hpp" 42 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
44 unsigned orderOfElements,
45 unsigned orderOfBoundaryElements) :
46 mFileName(pathBaseName),
47 mOrderOfElements(orderOfElements),
48 mOrderOfBoundaryElements(orderOfBoundaryElements)
75 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
81 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
94 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
102 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
108 std::string this_line;
111 assert(this_line ==
"$MeshFormat");
115 std::stringstream line(this_line);
121 EXCEPTION(
"Only .msh version 2.2 files are supported.");
127 assert(this_line ==
"$EndMeshFormat");
135 EXCEPTION(
"Unrecognised element types present in the .msh file: check mesh generation settings in gmsh.");
145 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
149 std::string this_line;
150 std::stringstream line(this_line);
152 while (this_line !=
"$Nodes")
163 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
167 std::string this_line;
168 std::stringstream line(this_line);
171 while (this_line !=
"$Elements")
184 while (this_line !=
"$EndElements")
191 line >> ele_index >> ele_type;
193 if (ELEMENT_DIM == 2 && (ele_type == GmshTypes::TRIANGLE || ele_type == GmshTypes::QUADRATIC_TRIANGLE))
197 else if (ELEMENT_DIM == 3 && (ele_type == GmshTypes::TETRAHEDRON || ele_type == GmshTypes::QUADRATIC_TETRAHEDRON))
208 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
212 std::string this_line;
213 std::stringstream line(this_line);
216 while (this_line !=
"$Elements")
226 while (this_line !=
"$EndElements")
233 line >> ele_index >> ele_type;
235 if (ELEMENT_DIM == 2 && (ele_type == GmshTypes::LINE || ele_type == GmshTypes::QUADRATIC_LINE))
239 else if (ELEMENT_DIM == 3 && (ele_type == GmshTypes::TRIANGLE || ele_type == GmshTypes::QUADRATIC_TRIANGLE))
250 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
256 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
262 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
269 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
277 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
283 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
289 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
295 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
302 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
310 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
319 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
322 std::vector<double> ret_coords(SPACE_DIM);
324 std::string this_line;
327 std::stringstream line(this_line);
330 line >> node_index >> ret_coords[0] >> ret_coords[1];
334 line >> ret_coords[2];
340 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
343 return std::vector<double>(0);
346 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
353 std::string this_line;
354 std::stringstream line(this_line);
358 unsigned ele_attributes = 0;
359 bool volume_element_found =
false;
361 while (!volume_element_found)
367 line >> ele_index >> ele_type >> ele_attributes;
369 if ((ELEMENT_DIM == 2 && (ele_type == GmshTypes::TRIANGLE || ele_type == GmshTypes::QUADRATIC_TRIANGLE) ) ||
370 (ELEMENT_DIM == 3 && (ele_type == GmshTypes::TETRAHEDRON || ele_type == GmshTypes::QUADRATIC_TETRAHEDRON)))
372 volume_element_found =
true;
378 if (ele_attributes > 0)
383 unsigned unused_attr;
384 for (
unsigned attr_index = 0; attr_index < (ele_attributes-1); ++attr_index)
401 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
408 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
415 std::string this_line;
416 std::stringstream line(this_line);
420 unsigned face_attributes=0;
421 bool surface_element_found =
false;
423 while (!surface_element_found)
429 line >> face_index >> face_type >> face_attributes;
431 if ((ELEMENT_DIM == 2 && (face_type == GmshTypes::LINE || face_type == GmshTypes::QUADRATIC_LINE) ) ||
432 (ELEMENT_DIM == 3 && (face_type == GmshTypes::TRIANGLE || face_type == GmshTypes::QUADRATIC_TRIANGLE)))
434 surface_element_found =
true;
440 if (face_attributes > 0)
445 unsigned unused_attr;
446 for (
unsigned attr_index = 0; attr_index < (face_attributes-1); ++attr_index)
463 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
471 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
479 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
unsigned GetNumElements() const
unsigned GetOrderOfBoundaryElements()
unsigned GetNumFaceAttributes() const
unsigned mOrderOfBoundaryElements
ElementData GetFaceData(unsigned index)
ElementData GetNextCableElementData()
unsigned mNodesPerBoundaryElement
unsigned GetOrderOfElements()
ElementData GetNextFaceData()
#define EXCEPTION(message)
unsigned mTotalNumElementsAndFaces
unsigned mNumElementAttributes
ElementData GetNextElementData()
std::vector< unsigned > NodeIndices
std::ifstream mElementFile
unsigned GetNumFaces() const
std::vector< double > GetNodeAttributes()
ElementData GetElementData(unsigned index)
GmshMeshReader(std::string pathBaseName, unsigned orderOfElements=1, unsigned orderOfBoundaryElements=1)
std::vector< double > GetNode(unsigned index)
unsigned mNumFaceAttributes
unsigned GetNumCableElements() const
unsigned GetNumElementAttributes() const
unsigned mOrderOfElements
unsigned GetNumCableElementAttributes() const
unsigned GetNumNodes() const
unsigned mNodesPerElement
std::vector< double > GetNextNode()