CEPS  24.01
Cardiac ElectroPhysiology Simulator
MeshReader.cpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
31 
32 MeshReader::MeshReader (const CepsString &mesh, const CepsUInt &dim, CepsBool quads) :
33  FileReader (mesh),
34  m_expectedDim (dim),
35  m_quads (quads)
36 {
37  if (m_expectedDim == 0 or m_expectedDim > 3)
38  {
39  CEPS_ABORT ("Impossible to read meshes with main dimension 0 or >3");
40  }
41  if (not ceps::fileExists (ceps::getFilename (mesh), ceps::getDir (mesh)))
42  {
43  CEPS_ABORT ("Cannot find file " << mesh);
44  }
45 
46  m_cellsRead = 0U;
47  m_bdryCellsRead = 0U;
48  m_nbNodes = 0U;
49  m_nbCells = 0U;
50  m_nbBdryCells = 0U;
51  m_nbAttrPerNode = 0U;
52  m_nbAttrPerCell = 0U;
53  m_bdryCellsBegin = 0U;
54  m_cellsBegin = 0U;
55  m_nodesBegin = 0U;
57  m_initialized = false;
58 
59  if (m_quads)
60  {
61  m_nbNodesPerCell = pow (2, dim);
62  m_nbNodesPerBdryCell = pow (2, dim - 1);
63  }
64  else
65  {
66  m_nbNodesPerCell = dim + 1;
68  }
69 }
70 
72 {}
73 
76 {
77  return m_cellsRead;
78 }
79 
82 {
83  return m_bdryCellsRead;
84 }
85 
88 {
89  return m_nbNodes;
90 }
91 
94 {
95  return m_nbCells;
96 }
97 
100 {
101  return m_nbBdryCells;
102 }
103 
104 CepsInt
106 {
107  return m_nbAttrPerNode;
108 }
109 
110 CepsInt
112 {
113  return m_nbAttrPerCell;
114 }
115 
116 CepsInt
118 {
119  return m_nbAttrPerBdryCell;
120 }
121 
122 CepsBool
124 {
126  {
127  CEPS_ABORT (
128  "Mesh reader created with filename "
129  << m_fileName << " but is only compatible with extensions " << m_extension
130  );
131  return false;
132  }
133  return true;
134 }
135 
136 void
137 MeshReader::checkCanReadNodes (CepsUInt indexStart, CepsUInt indexEnd) const
138 {
140  "Must call initialize() beforehand"
141  );
142  CEPS_ABORT_IF (indexStart > indexEnd,
143  "index start > index end"
144  );
145  CEPS_ABORT_IF (indexStart > m_nbNodes or indexEnd > m_nbNodes,
146  "index start or index end larger than number of nodes"
147  );
148 }
149 
150 void
151 MeshReader::checkCanReadCells (CepsUInt indexStart, CepsUInt indexEnd) const
152 {
154  "Must call initialize() beforehand"
155  );
156  CEPS_ABORT_IF (indexStart > indexEnd,
157  "index start > index end"
158  );
159  CEPS_ABORT_IF (indexStart > m_nbCellsTotal or indexEnd > m_nbCellsTotal,
160  "Cannot read cells from index #" << indexStart << std::endl
161  << " to index #" << indexEnd << " in file " << m_fileName
162  );
163 }
#define CEPS_ABORT(message)
Stops the execution with a message. If testing is enabled, only throws a runtime_error.
#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.
Definition: CepsTypes.hpp:128
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
int32_t CepsInt
Need 32 bit integer.
Definition: CepsTypes.hpp:106
Base class that regroups common reader functionalities.
Definition: FileReader.hpp:43
CepsString m_fileName
file to open
Definition: FileReader.hpp:145
CepsInt m_nodesBegin
line start of nodes
Definition: MeshReader.hpp:183
CepsUInt m_nbAttrPerCell
attributes per cell
Definition: MeshReader.hpp:194
CepsUInt getNbCellsRead() const
Number of cells that have been read until now.
Definition: MeshReader.cpp:75
virtual CepsInt getNbAttributesPerCell() const
Number of attributes per cell.
Definition: MeshReader.cpp:111
CepsUInt getNbNodes() const
Number of nodes of current mesh.
Definition: MeshReader.cpp:87
CepsBool m_initialized
Flag to ensure call of initializeReader()
Definition: MeshReader.hpp:176
void checkCanReadNodes(CepsUInt indexStart, CepsUInt indexEnd) const
Aborts if passed indices are wrong.
Definition: MeshReader.cpp:137
MeshReader()=delete
Deleted default constructor.
CepsUInt m_nbNodesPerBdryCell
nb nodes per boundary cell
Definition: MeshReader.hpp:181
CepsBool m_quads
Reader for quadratic cells.
Definition: MeshReader.hpp:175
CepsUInt m_bdryCellsRead
Keeps track of already read boundary cells.
Definition: MeshReader.hpp:180
~MeshReader() override
Destructor.
Definition: MeshReader.cpp:71
CepsUInt m_nbNodesPerCell
nb nodes per cell
Definition: MeshReader.hpp:179
CepsUInt getNbBdryCells() const
Number of boundary cell of current mesh.
Definition: MeshReader.cpp:99
virtual CepsInt getNbAttributesPerBdryCell() const
Number of attributes per boundary cell.
Definition: MeshReader.cpp:117
CepsUInt m_nbBdryCells
number of boundary cells in mesh, appropriate for dimension
Definition: MeshReader.hpp:191
CepsUInt getNbCells() const
Number of cell of current mesh.
Definition: MeshReader.cpp:93
CepsUInt m_nbAttrPerBdryCell
attributes per boundary cell
Definition: MeshReader.hpp:195
CepsUInt m_cellsRead
Keeps track of already read cells.
Definition: MeshReader.hpp:178
CepsUInt m_nbAttrPerNode
attributes per node
Definition: MeshReader.hpp:193
virtual CepsInt getNbAttributesPerNode() const
Number of attributes per node.
Definition: MeshReader.cpp:105
virtual CepsBool checkExtension() const
Stop if extension is not ok, extension must be defined in child classes.
Definition: MeshReader.cpp:123
CepsInt m_cellsBegin
line start of cells
Definition: MeshReader.hpp:186
CepsUInt m_expectedDim
Expected dimension of mesh.
Definition: MeshReader.hpp:174
CepsUInt m_nbCellsTotal
number of all cells in file
Definition: MeshReader.hpp:188
CepsInt m_bdryCellsBegin
line start of boundary cells
Definition: MeshReader.hpp:190
CepsString m_extension
File name extension.
Definition: MeshReader.hpp:172
CepsUInt m_nbNodes
number of nodes in mesh
Definition: MeshReader.hpp:184
CepsUInt getNbBdryCellsRead() const
Number of boundary cells that have been read.
Definition: MeshReader.cpp:81
CepsUInt m_nbCells
number of cells in mesh, appropriate for dimension
Definition: MeshReader.hpp:187
void checkCanReadCells(CepsUInt indexStart, CepsUInt indexEnd) const
Aborts if passed indices are wrong.
Definition: MeshReader.cpp:151
CepsString getDir(const CepsString &str)
Get a substring of s, from beginning of s to the last '/' character. Example: "/home/someone/file....
Definition: CepsString.cpp:521
CepsString getFilename(const CepsString &str)
Returns a substring corresponding to the string after the last '/' character. Example: "/home/someone...
Definition: CepsString.cpp:556
CepsString getExtension(const CepsString &str)
Returns the extension of a file, if any.
Definition: CepsString.cpp:580
CepsBool fileExists(const CepsString &fileName, const CepsString &directory)
Definition: CepsString.cpp:595