proteus  1.8.1
C/C++/Fortran libraries
meshio.h
Go to the documentation of this file.
1 #ifndef MESH_IO_H
2 #define MESH_IO_H
3 
4 #include <iostream>
5 #include <vector>
6 /***********************************************************************
7  some basic utilities for reading formatted files
8  **********************************************************************/
9 namespace IOutils
10 {
11 std::istream& eatline(std::istream& s);
12 std::istream& eatchar(std::istream& s);
13 std::istream& eatcomments(std::istream& s);
14 bool iswhitespace(const char& c);
15 } //end IOutils
16 
17 namespace meshIO
18 {
19 /***********************************************************************
20  \brief simple routine for reading in the vertex and element
21  information for a triangular mesh. Should be compatible with Triangle.
22  Heavily borrowed from p2mesh
23 
24  @param filebase, IN. the base name for mesh files. The routine tries
25  to open filebase.ele, filebase.node
26  @param indexBase, IN. The base numbering convetion (e.g., 0 or 1)
27  for the mesh
28 
29  @param nElements, OUT. The number of elements in the mesh
30  @param nNodes, OUT. The number of nodes/vertices in the mesh
31 
32  @param nodeArray, OUT. physical coordinates of each node in mesh
33  nodeArray[I,j] = x^j_I, coordinate j of global node I
34  Dim = Nn x 3.
35 
36  @param elementNodesArray, OUT. Map from each element to its global
37  node numbers elementNodesArray[I,j] = J, the global node
38  number J of global element I's local node j
39  Dim: nElements x 3
40 
41  @param nodeMaterialTypes, OUT. optional flag for nodes (0 by default)
42  nodeMaterialTypesArray[I] = f_I,
43  Dim = Nn .
44  @param elementMaterialTypes, OUT. optional flag for elements (0 by default)
45  elementMaterialTypesArray[I] = f_I,
46  Dim = nElements .
47  **********************************************************************/
48 
49 bool
50 readTriangleMeshNodesAndElements(const char * filebase,
51  const int& indexBase,
52  int& nElements, int& nNodes,
53  std::vector<double>& nodeArray,
54  std::vector<int>&
55  elementNodesArray,
56  std::vector<int>& elementNodeTypesArray,
57  std::vector<int>& elementMaterialTypesArray,
58  const int& defaultElementMaterialType = 0,
59  const int& defaultNodeMaterialType = 0);
60 
61 /***********************************************************************
62  \brief simple routine for writing the vertex and element
63  information for a triangular mesh. Should be compatible with Triangle
64 
65  @param filebase, IN. the base name for mesh files. The routine tries
66  to open filebase.ele, filebase.node
67  @param indexBase, IN. The base numbering convetion (e.g., 0 or 1)
68  for the mesh
69 
70  @param nElements, IN. The number of elements in the mesh
71  @param nNodes, IN. The number of nodes/vertices in the mesh
72 
73  @param nodeArray, IN. physical coordinates of each node in mesh
74  nodeArray[I,j] = x^j_I, coordinate j of global node I
75  Dim = Nn x 3.
76 
77  @param elementNodesArray, IN. Map from each element to its global
78  node numbers elementNodesArray[I,j] = J, the global node
79  number J of global element I's local node j
80  Dim: nElements x 3
81 
82  @param nodeMaterialTypes, IN. optional flag for nodes (0 by default)
83  nodeMaterialTypesArray[I] = f_I,
84  Dim = Nn .
85  @param elementMaterialTypes, IN. optional flag for elements (0 by default)
86  elementMaterialTypesArray[I] = f_I,
87  Dim = nElements .
88  **********************************************************************/
89 
90 bool
91 writeTriangleMeshNodesAndElements(const char * filebase,
92  const int& indexBase,
93  const int& nElements, const int& nNodes,
94  const double* nodeArray,
95  const int* elementNodesArray,
96  const int* nodeMaterialTypes = 0,
97  const int* elementMaterialTypes = 0);
98 
99 /***********************************************************************
100  \brief simple routine for reading in the element Boundary
101  information for a triangular mesh. Should be compatible with Triangle.
102 
103  @param filebase, IN. the base name for mesh files. The routine tries
104  to open filebase.edge,
105  @param indexBase, IN. The base numbering convetion (e.g., 0 or 1)
106  for the mesh
107 
108  @param nElementBoundaries, OUT. The number of elementBoundaries in the mesh
109 
110  @param elementBoundaryNodesArray, OUT. map from element boundary to global id of nodes defining it
111  elementBoundaryNodesArray[I,j] = eb_I->node_j, local node j on edge I
112  Dim = nElementBoundaries x 2.
113 
114  @param elementBoundaryMaterialTypes, OUT. optional flag for elementBoundaries
115  elementBoundaryMaterialTypes[I] = f_I,
116  Dim = nElementBoundaries .
117  **********************************************************************/
118 
119 bool
120 readTriangleElementBoundaries(const char * filebase,
121  const int& indexBase,
122  bool& hasMarkers,
123  int& nElementBoundaries,
124  std::vector<int>& elementBoundaryNodesArray,
125  std::vector<int>& elementBoundaryMaterialTypesArray,
126  const int& defaultBoundaryMaterialType = 0);
127 
128 /***********************************************************************
129  write out element boundary nodes array and optionally element
130  boundary identifiers.
131  ***********************************************************************/
132 bool
133 writeTriangleElementBoundaryNodes(const char * filebase,
134  const int& indexBase,
135  const int& nElementBoundaries,
136  const int* elementBoundaryNodesArray,
137  const int* elementBoundaryMaterialTypesArray = 0);
138 
139 
140 /***********************************************************************
141  \brief simple routine for reading in the vertex and element
142  information for a tetrahedral mesh. Should be compatible with tetgen.
143 
144  @param filebase, IN. the base name for mesh files. The routine tries
145  to open filebase.ele, filebase.node
146  @param indexBase, IN. The base numbering convetion (e.g., 0 or 1)
147  for the mesh
148 
149  @param nElements, OUT. The number of elements in the mesh
150  @param nNodes, OUT. The number of nodes/vertices in the mesh
151 
152  @param nodeArray, OUT. physical coordinates of each node in mesh
153  nodeArray[I,j] = x^j_I, coordinate j of global node I
154  Dim = Nn x 3.
155 
156  @param elementNodesArray, OUT. Map from each element to its global
157  node numbers elementNodesArray[I,j] = J, the global node
158  number J of global element I's local node j
159  Dim: nElements x 4
160 
161  @param nodeMaterialTypes, OUT. optional flag for nodes (0 by default)
162  nodeMaterialTypesArray[I] = f_I,
163  Dim = Nn .
164  @param elementMaterialTypes, OUT. optional flag for elements (0 by default)
165  elementMaterialTypesArray[I] = f_I,
166  Dim = nElements .
167  **********************************************************************/
168 
169 bool
170 readTetgenMeshNodesAndElements(const char * filebase,
171  const int& indexBase,
172  int& nElements, int& nNodes,
173  std::vector<double>& nodeArray,
174  std::vector<int>& elementNodesArray,
175  std::vector<int>& elementNodeTypesArray,
176  std::vector<int>& elementMaterialTypesArray,
177  const int& defaultElementMaterialType = 0,
178  const int& defaultNodeMaterialType = 0);
179 
180 
181 
182 /***********************************************************************
183  \brief simple routine for reading in the element Boundary
184  information for a triangular mesh. Should be compatible with Triangle.
185 
186  @param filebase, IN. the base name for mesh files. The routine tries
187  to open filebase.edge,
188  @param indexBase, IN. The base numbering convetion (e.g., 0 or 1)
189  for the mesh
190 
191  @param nElementBoundaries, OUT. The number of elementBoundaries in the mesh
192 
193  @param elementBoundaryNodesArray, OUT. map from element boundary to global id of nodes defining it
194  elementBoundaryNodesArray[I,j] = eb_I->node_j, local node j on edge I
195  Dim = nElementBoundaries x 3.
196 
197  @param elementBoundaryMaterialTypes, OUT. optional flag for elementBoundaries
198  elementBoundaryMaterialTypes[I] = f_I,
199  Dim = nElementBoundaries .
200  **********************************************************************/
201 
202 bool
203 readTetgenElementBoundaries(const char * filebase,
204  const int& indexBase,
205  bool& hasMarkers,
206  int& nElementBoundaries,
207  std::vector<int>& elementBoundaryNodesArray,
208  std::vector<int>& elementBoundaryMaterialTypesArray,
209  const int& defaultBoundaryMaterialType = 0);
210 
211 
212 /***********************************************************************
213  \brief simple routine for writing the vertex and element
214  information for a tetrahedral mesh. Should be compatible with Tetgen
215 
216  @param filebase, IN. the base name for mesh files. The routine tries
217  to open filebase.ele, filebase.node
218  @param indexBase, IN. The base numbering convetion (e.g., 0 or 1)
219  for the mesh
220 
221  @param nElements, IN. The number of elements in the mesh
222  @param nNodes, IN. The number of nodes/vertices in the mesh
223 
224  @param nodeArray, IN. physical coordinates of each node in mesh
225  nodeArray[I,j] = x^j_I, coordinate j of global node I
226  Dim = Nn x 3.
227 
228  @param elementNodesArray, IN. Map from each element to its global
229  node numbers elementNodesArray[I,j] = J, the global node
230  number J of global element I's local node j
231  Dim: nElements x 4
232 
233  @param nodeMaterialTypes, OUT. optional flag for nodes (0 by default)
234  nodeMaterialTypesArray[I] = f_I,
235  Dim = Nn .
236  @param elementMaterialTypes, OUT. optional flag for elements (0 by default)
237  elementMaterialTypesArray[I] = f_I,
238  Dim = nElements .
239  **********************************************************************/
240 
241 bool
242 writeTetgenMeshNodesAndElements(const char * filebase,
243  const int& indexBase,
244  const int& nElements, const int& nNodes,
245  const double* nodeArray,
246  const int* elementNodesArray,
247  const int* nodeMaterialTypes = 0,
248  const int* elementMaterialTypes = 0);
249 
250 /***********************************************************************
251  write out element boundary nodes array and optionally element
252  boundary identifiers.
253  flag writeExteriorBoundariesOnly determines if write only exterior
254  boundaries or write them all.
255  In nElementBoundaries should be nExteriorElementBoundaries_global if
256  only writing out exterior boundaries and nElementBoundaries_global
257  otherwise.
258  ***********************************************************************/
259 bool
260 writeTetgenElementBoundaryNodes(const char * filebase,
261  const int& indexBase,
262  const int& nElementBoundaries,
263  const int* elementBoundaryNodesArray,
264  const int* elementBoundaryMaterialTypesArray = 0,
265  const bool& writeExteriorBoundariesOnly = false,
266  const int* exteriorElementBoundariesArray = 0);
267 
268 /***********************************************************************
269  \brief simple routine for writing the vertex and element
270  information for a tetrahedral mesh in a 3dm.
271 
272  @param filebase, IN. the base name for mesh files. The routine tries
273  to open filebase.3dm
274  @param indexBase, IN. The base numbering convetion (e.g., 0 or 1)
275  for the mesh
276 
277  @param nElements, IN. The number of elements in the mesh
278  @param nNodes, IN. The number of nodes/vertices in the mesh
279 
280  @param nodeArray, IN. physical coordinates of each node in mesh
281  nodeArray[I,j] = x^j_I, coordinate j of global node I
282  Dim = Nn x 3.
283 
284  @param elementNodesArray, IN. Map from each element to its global
285  node numbers elementNodesArray[I,j] = J, the global node
286  number J of global element I's local node j
287  Dim: nElements x 4
288  **********************************************************************/
289 
290 bool
291 write3dmMeshNodesAndElements(const char * filebase,
292  const int& indexBase,
293  const int& nElements, const int& nNodes,
294  const double* nodeArray,
295  const int* elementNodesArray,
296  const int* elementMaterialTypes = 0);
297 
298 
299 
300 /***********************************************************************
301  \brief simple routine for writing the vertex and element
302  information for a triangular mesh in a 2dm.
303 
304  @param filebase, IN. the base name for mesh files. The routine tries
305  to open filebase.2dm
306  @param indexBase, IN. The base numbering convetion (e.g., 0 or 1)
307  for the mesh
308 
309  @param nElements, IN. The number of elements in the mesh
310  @param nNodes, IN. The number of nodes/vertices in the mesh
311 
312  @param nodeArray, IN. physical coordinates of each node in mesh
313  nodeArray[I,j] = x^j_I, coordinate j of global node I
314  Dim = Nn x 3.
315 
316  @param elementNodesArray, IN. Map from each element to its global
317  node numbers elementNodesArray[I,j] = J, the global node
318  number J of global element I's local node j
319  Dim: nElements x 3
320  **********************************************************************/
321 
322 bool
323 write2dmMeshNodesAndElements(const char * filebase,
324  const int& indexBase,
325  const int& nElements, const int& nNodes,
326  const double* nodeArray,
327  const int* elementNodesArray,
328  const int* elementMaterialTypes = 0);
329 
330 
331 }
332 
333 #endif
IOutils
Definition: meshio.cpp:10
s
Double s
Definition: Headers.h:84
meshIO::writeTetgenMeshNodesAndElements
bool writeTetgenMeshNodesAndElements(const char *filebase, const int &indexBase, const int &nElements, const int &nNodes, const double *nodeArray, const int *elementNodesArray, const int *nodeMaterialTypes, const int *elementMaterialTypes)
Definition: meshio.cpp:508
meshIO::writeTriangleElementBoundaryNodes
bool writeTriangleElementBoundaryNodes(const char *filebase, const int &indexBase, const int &nElementBoundaries, const int *elementBoundaryNodesArray, const int *elementBoundaryMaterialTypes)
Definition: meshio.cpp:290
IOutils::eatcomments
std::istream & eatcomments(std::istream &s)
Definition: meshio.cpp:21
meshIO
Definition: meshio.cpp:34
meshIO::write2dmMeshNodesAndElements
bool write2dmMeshNodesAndElements(const char *filebase, const int &indexBase, const int &nElements, const int &nNodes, const double *nodeArray, const int *elementNodesArray, const int *elementMaterialTypes)
Definition: meshio.cpp:718
IOutils::eatchar
std::istream & eatchar(std::istream &s)
Definition: meshio.cpp:17
IOutils::eatline
std::istream & eatline(std::istream &s)
Definition: meshio.cpp:11
c
Double c
Definition: Headers.h:54
meshIO::write3dmMeshNodesAndElements
bool write3dmMeshNodesAndElements(const char *filebase, const int &indexBase, const int &nElements, const int &nNodes, const double *nodeArray, const int *elementNodesArray, const int *elementMaterialTypes)
Definition: meshio.cpp:668
meshIO::readTriangleMeshNodesAndElements
bool readTriangleMeshNodesAndElements(const char *filebase, const int &indexBase, int &nElements, int &nNodes, std::vector< double > &nodeArray, std::vector< int > &elementNodesArray, std::vector< int > &nodeMaterialTypes, std::vector< int > &elementMaterialTypes, const int &defaultElementMaterialType, const int &defaultNodeMaterialType)
Definition: meshio.cpp:41
meshIO::writeTetgenElementBoundaryNodes
bool writeTetgenElementBoundaryNodes(const char *filebase, const int &indexBase, const int &nElementBoundariesToWrite, const int *elementBoundaryNodesArray, const int *elementBoundaryMaterialTypes, const bool &writeExteriorElementBoundariesOnly, const int *exteriorElementBoundariesArray)
Definition: meshio.cpp:586
IOutils::iswhitespace
bool iswhitespace(const char &c)
Definition: meshio.cpp:19
meshIO::readTetgenMeshNodesAndElements
bool readTetgenMeshNodesAndElements(const char *filebase, const int &indexBase, int &nElements, int &nNodes, std::vector< double > &nodeArray, std::vector< int > &elementNodesArray, std::vector< int > &nodeMaterialTypes, std::vector< int > &elementMaterialTypes, const int &defaultElementMaterialType, const int &defaultNodeMaterialType)
Definition: meshio.cpp:339
meshIO::writeTriangleMeshNodesAndElements
bool writeTriangleMeshNodesAndElements(const char *filebase, const int &indexBase, const int &nElements, const int &nNodes, const double *nodeArray, const int *elementNodesArray, const int *nodeMaterialTypes, const int *elementMaterialTypes)
Definition: meshio.cpp:150
meshIO::readTetgenElementBoundaries
bool readTetgenElementBoundaries(const char *filebase, const int &indexBase, bool &hasMarkers, int &nElementBoundaries, std::vector< int > &elementBoundaryNodesArray, std::vector< int > &elementBoundaryMaterialTypesArray, const int &defaultBoundaryMaterialType)
Definition: meshio.cpp:448
meshIO::readTriangleElementBoundaries
bool readTriangleElementBoundaries(const char *filebase, const int &indexBase, bool &hasMarkers, int &nElementBoundaries, std::vector< int > &elementBoundaryNodesArray, std::vector< int > &elementBoundaryMaterialTypesArray, const int &defaultBoundaryMaterialType)
Definition: meshio.cpp:232