39#include "GmshMeshReader.hpp"
42template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
44 unsigned orderOfElements,
45 unsigned orderOfBoundaryElements) :
46 mFileName(pathBaseName),
47 mOrderOfElements(orderOfElements),
48 mOrderOfBoundaryElements(orderOfBoundaryElements)
75template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
81template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
85 mNodeFile.open(mFileName.c_str());
86 mElementFile.open(mFileName.c_str());
87 mFaceFile.open(mFileName.c_str());
88 if (!mNodeFile.is_open() || !mElementFile.is_open() || !mFaceFile.is_open() )
90 EXCEPTION(
"Could not open data file: " + mFileName);
94template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
102template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
108 std::string this_line;
109 getline(mNodeFile, this_line);
111 assert(this_line ==
"$MeshFormat");
114 getline(mNodeFile, this_line);
115 std::stringstream line(this_line);
117 line >> mVersionNumber >> mFileType >> mDataSize;
119 if (mVersionNumber != 2.2)
121 EXCEPTION(
"Only .msh version 2.2 files are supported.");
123 assert(mFileType == 0);
126 getline(mNodeFile, this_line);
127 assert(this_line ==
"$EndMeshFormat");
133 if (mTotalNumElementsAndFaces != mNumElements + mNumFaces)
135 EXCEPTION(
"Unrecognised element types present in the .msh file: check mesh generation settings in gmsh.");
145template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
149 std::string this_line;
150 std::stringstream line(this_line);
152 while (this_line !=
"$Nodes")
154 getline(mNodeFile, this_line);
156 getline(mNodeFile, this_line);
163template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
167 std::string this_line;
168 std::stringstream line(this_line);
170 getline(mElementFile, this_line);
171 while (this_line !=
"$Elements")
173 getline(mElementFile, this_line);
175 getline(mElementFile, this_line);
178 line >> mTotalNumElementsAndFaces;
179 int ele_start = mElementFile.tellg();
182 getline(mElementFile, this_line);
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))
202 getline(mElementFile, this_line);
205 mElementFile.seekg(ele_start);
208template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
212 std::string this_line;
213 std::stringstream line(this_line);
215 getline(mFaceFile, this_line);
216 while (this_line !=
"$Elements")
218 getline(mFaceFile, this_line);
220 getline(mFaceFile, this_line);
221 int face_start = mFaceFile.tellg();
224 getline(mFaceFile, this_line);
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))
244 getline(mFaceFile, this_line);
247 mFaceFile.seekg(face_start);
250template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
256template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
262template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
269template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
277template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
280 return mOrderOfElements;
283template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
286 return mOrderOfBoundaryElements;
289template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
292 return mNumElementAttributes;
295template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
298 return mNumFaceAttributes;
302template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
310template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
319template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
322 std::vector<double> ret_coords(SPACE_DIM);
324 std::string this_line;
325 getline(mNodeFile, this_line);
327 std::stringstream line(this_line);
330 line >> node_index >> ret_coords[0] >> ret_coords[1];
334 line >> ret_coords[2];
340template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
343 return std::vector<double>(0);
346template<
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)
363 getline(mElementFile, this_line);
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)
380 mNumElementAttributes = 1u;
383 unsigned unused_attr;
384 for (
unsigned attr_index = 0; attr_index < (ele_attributes-1); ++attr_index)
390 for (
unsigned node_index = 0; node_index < mNodesPerElement; ++node_index)
401template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
408template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
412 face_data.
NodeIndices.resize(mNodesPerBoundaryElement);
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)
425 getline(mFaceFile, this_line);
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)
442 mNumFaceAttributes = 1u;
445 unsigned unused_attr;
446 for (
unsigned attr_index = 0; attr_index < (face_attributes-1); ++attr_index)
452 for (
unsigned node_index = 0; node_index < mNodesPerBoundaryElement; ++node_index)
463template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
471template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
479template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
#define EXCEPTION(message)
ElementData GetNextFaceData()
unsigned mOrderOfElements
unsigned GetNumElements() const
GmshMeshReader(std::string pathBaseName, unsigned orderOfElements=1, unsigned orderOfBoundaryElements=1)
unsigned GetNumCableElements() const
ElementData GetNextCableElementData()
unsigned GetOrderOfElements()
unsigned mOrderOfBoundaryElements
std::vector< double > GetNode(unsigned index)
unsigned mNodesPerElement
unsigned GetNumNodes() const
ElementData GetNextElementData()
unsigned mNodesPerBoundaryElement
unsigned GetNumElementAttributes() const
ElementData GetElementData(unsigned index)
unsigned GetNumCableElementAttributes() const
unsigned GetNumFaceAttributes() const
unsigned GetNumFaces() const
std::vector< double > GetNodeAttributes()
ElementData GetFaceData(unsigned index)
unsigned GetOrderOfBoundaryElements()
std::vector< double > GetNextNode()
std::vector< unsigned > NodeIndices