Select Git revision
MeshData.hpp
GmshReader.hpp 3.57 KiB
#ifndef GMSH_READER_HPP
#define GMSH_READER_HPP
#include <string>
#include <array>
#include <vector>
#include <map>
#include <fstream>
#include <Kokkos_Core.hpp>
#include <TinyVector.hpp>
class GmshReader
{
public:
typedef TinyVector<3, double> R3;
private:
std::ifstream m_fin;
const std::string m_filename;
int _getInteger()
{
int i;
m_fin >> i;
return std::move(i);
}
double _getReal()
{
double d;
m_fin >> d;
return std::move(d);
}
/**
* Gmsh format provides a numbered, none ordrered and none dense
* vertices list, this stores the number of read vertices.
*/
std::vector<int> __verticesNumbers;
Kokkos::View<R3*> __vertices;
typedef TinyVector<2,unsigned int> Edge;
Kokkos::View<Edge*> __edges;
std::vector<int> __edges_ref;
typedef TinyVector<3,unsigned int> Triangle;
Kokkos::View<Triangle*> __triangles;
std::vector<int> __triangles_ref;
typedef TinyVector<4,unsigned int> Quadrangle;
Kokkos::View<Quadrangle*> __quadrangles;
std::vector<int> __quadrangles_ref;
typedef TinyVector<4,unsigned int> Tetrahedron;
Kokkos::View<Tetrahedron*> __tetrahedra;
std::vector<int> __tetrahedra_ref;
typedef TinyVector<8,unsigned int> Hexahedron;
Kokkos::View<Hexahedron*> __hexahedra;
std::vector<int> __hexahedra_ref;
/**
* Gmsh format provides a numbered, none ordrered and none dense
* vertices list, this provides vertices renumbering correspondance
*/
std::vector<int> __verticesCorrepondance;
/**
* elements types
*/
std::vector<short> __elementType;
/**
* References
*/
std::vector<int> __references;
/**
* References
*/
std::vector<std::vector<int> > __elementVertices;
/**
* Stores the number of nodes associated to each primitive
*
*/
std::vector<int> __numberOfPrimitiveNodes;
/**
* Array of boolean describing gmsh supported primitives by ff3d
*
*/
std::array<bool, 15> __supportedPrimitives;
/**
* Primitives names according to there number
*
*/
std::map<int, std::string> __primitivesNames;
bool __binary; /**< true if binary format */
bool __convertEndian; /**< true if needs to adapt endianess */
/**
* Adapts gmsh data to ff3d's structures
*
*/
void __proceedData();
/**
* Reads data in format 2.2
*
*/
void __readGmshFormat2_2();
/**
* List of allowed keyword in mesh file
*
*/
enum KeywordType {
// gmsh 2.2
MESHFORMAT,
ENDMESHFORMAT,
NODES,
ENDNODES,
ELEMENTS,
ENDELEMENTS,
Unknown,
EndOfFile
};
/**
* List of known keywords
*
*/
typedef std::map<std::string, int> KeywordList;
KeywordList __keywordList; /**< The keyword list */
/**
* Type for keyword
*
*/
typedef std::pair<std::string, int> Keyword;
/**
* Skips next comments if exists
*
*/
void __skipComments();
/**
* Reads the next keyword and returns its token
*
* @return KeywordToken
*/
Keyword __nextKeyword();
/**
* get list of vertices
*
*/
void __getVertices();
/**
* Read list of vertices
*
*/
void __readVertices();
/**
* Read all elements in format 2.0
*
*/
void __readElements2_2();
// /**
// * Common interface for writing references
// *
// * @param references the set of computed references
// * @param objectName the type of refernces
// */
// void __writeReferences(const std::set<size_t>& references,
// std::string objectName);
public:
GmshReader(const std::string& filename);
~GmshReader() = default;
};
#endif // GMSH_READER_HPP