73 CepsInt nbToRead = indexEnd-indexStart;
76 std::getline(
m_file,dummy);
79 h <<
"Gmsh mesh reader: in file " <<
m_fileName <<
"," << std::endl
80 <<
" unable to read ";
82 for (
CepsInt i=0; i<nbToRead; i++)
93 attrPtr[nodeId+1] = attrPtr[nodeId] + 1;
119 std::getline(
m_file,line);
127 cellOffset+
m_cellsRead,i,nodeOffset,nodeIndices,nodeIndicesPtr,
128 cellAttr,cellAttrPtr,isBoundaryCell,
false
135 std::getline(
m_file,line);
140 cellAttr,cellAttrPtr,isBoundaryCell,
true
160 std::getline(
m_file,line);
168 if (words.size()>1 and words[1] == cellType)
170 std::stringstream hh;
171 hh <<
"Gmsh mesh reader: in file " <<
m_fileName <<
"," << std::endl <<
" unable to read ";
175 std::istringstream iss(line);
182 cellAttr[cellAttrPtr[cellId]+i] = i<nbAttrToRead ?
ceps::readInt(iss,h+
"attribute of cell #"+c) :-1;
184 for (
CepsUInt i=0U; i<nbPoints; i++)
185 nodeIndices[nodeIndicesPtr[cellId]+i] =
ceps::readInt(iss,h+
"node indices of cell #"+c)+nodeOffset-1;
187 cellAttrPtr [cellId+1] = cellAttrPtr [cellId] + nbAttr;
188 nodeIndicesPtr[cellId+1] = nodeIndicesPtr[cellId] + nbPoints;
189 isBoundaryCell[cellId ] = boundaryFlag;
203 std::stringstream hh;
204 hh <<
"Gmsh mesh reader: in file " <<
m_fileName <<
"," << std::endl <<
" ";
236 std::getline(
m_file, line);
239 std::getline (
m_file, line);
244 CepsUInt nAttr(std::stoi(words[2]));
258 CEPS_ABORT (h+
"error while reading cell types and number of attributes");
278 std::getline(
m_file, line);
280 "Gmsh files format other than 2 are not supported by CEPS."
281 <<
"Please select \"version 2\" when exporting your mesh in gmsh." << std::endl
#define CEPS_ABORT(message)
Stops the execution with a message. If testing is enabled, only throws a runtime_error.
#define CEPS_SAYS(message)
Writes a message in the debug log and in the terminal (stdio).
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
std::basic_string< CepsChar > CepsString
C++ format string.
std::vector< _Type, _Alloc > CepsVector
C++ vector.
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
int32_t CepsInt
Need 32 bit integer.
CepsInt lineIndex(const CepsString &word)
Index of first line starting with word, search starting from the current stream position.
void reset()
Set file stream to the beginning of the file.
virtual CepsBool open()
Opens the designated file in read mode.
CepsString m_fileName
file to open
std::ifstream m_file
stream
virtual void close()
Close the file.
void readCells(CepsUInt indexStart, CepsUInt indexEnd, CepsUInt nodeOffset, CepsUInt cellOffset, CepsVector< CepsNodeGlobalIndex > &nodeIndices, CepsVector< CepsUInt > &nodeIndicesPtr, CepsVector< CepsAttribute > &cellAttr, CepsVector< CepsUInt > &cellAttrPtr, CepsVector< CepsChar > &isBoundaryCell) override
Reads several cells in mesh file.
GmshMeshReader(const CepsString &fileName, const CepsUInt &dim, CepsBool quads=false)
Constructor with full fileName.
CepsString m_bdryCellType
CepsVector< CepsString > m_keywordsT
Read type of cells (tetras, tris, etc)
void checkFormatVersion()
Stops if the format version of the msh file is not 2.X.
void initialize() override
Get the number of nodes cells and boundary cells before reading.
void getNextCell(CepsUInt cellId, CepsUInt fileCellId, CepsUInt nodeOffset, CepsVector< CepsNodeGlobalIndex > &nodeIndices, CepsVector< CepsUInt > &nodeIndicesPtr, CepsVector< CepsAttribute > &cellAttr, CepsVector< CepsUInt > &cellAttrPtr, CepsVector< CepsChar > &isBoundaryCell, CepsBool boundaryFlag) override
Reads a single cell in mesh file.
CepsVector< CepsString > m_keywordsQ
Keywords used to separate cells in medit format, for quads.
void readNodes(CepsUInt indexStart, CepsUInt indexEnd, CepsUInt nodeOffset, CepsVector< CepsReal > &coords, CepsVector< CepsAttribute > &attr, CepsVector< CepsUInt > &attrPtr) override
Reads several nodes in mesh file.
~GmshMeshReader() override
Destructor.
Abstract base class that encapsulates primary functionalities of each mesh reader.
CepsInt m_nodesBegin
line start of nodes
CepsUInt m_nbAttrPerCell
attributes per cell
CepsBool m_initialized
Flag to ensure call of initializeReader()
void checkCanReadNodes(CepsUInt indexStart, CepsUInt indexEnd) const
Aborts if passed indices are wrong.
CepsUInt m_nbNodesPerBdryCell
nb nodes per boundary cell
CepsBool m_quads
Reader for quadratic cells.
CepsUInt m_bdryCellsRead
Keeps track of already read boundary cells.
CepsUInt m_nbNodesPerCell
nb nodes per cell
CepsUInt m_nbBdryCells
number of boundary cells in mesh, appropriate for dimension
CepsUInt m_nbAttrPerBdryCell
attributes per boundary cell
CepsUInt m_cellsRead
Keeps track of already read cells.
CepsUInt m_nbAttrPerNode
attributes per node
virtual CepsBool checkExtension() const
Stop if extension is not ok, extension must be defined in child classes.
CepsInt m_cellsBegin
line start of cells
CepsUInt m_expectedDim
Expected dimension of mesh.
CepsUInt m_nbCellsTotal
number of all cells in file
CepsInt m_bdryCellsBegin
line start of boundary cells
CepsString m_extension
File name extension.
CepsUInt m_nbNodes
number of nodes in mesh
CepsUInt m_nbCells
number of cells in mesh, appropriate for dimension
void checkCanReadCells(CepsUInt indexStart, CepsUInt indexEnd) const
Aborts if passed indices are wrong.
CepsString toString(_Tp value)
Convert a given value to a string (input has to be compatible with std::to_string)
const _Type & max(const CepsVector< _Type, _Alloc > &vec)
Returns the maximum of the vector, const version.
CepsInt readInt(std::istream &file, const CepsString &errorMessage="")
Reads an integral number from an istream, aborts if conversion fails advances the stream by 1 word.
CepsVector< CepsString > split(const CepsString &s, const CepsString &delimiters=CepsString(" \t"))
Splits a string using mulitple delimiters in a single string.
CepsReal readReal(std::istream &file, const CepsString &errorMessage="")
Reads a floating point number from an istream, aborts if conversion fails advances the stream by 1 wo...