proteus 1.9.0
C/C++/Fortran libraries
Loading...
Searching...
No Matches
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 **********************************************************************/
9namespace IOutils
10{
11std::istream& eatline(std::istream& s);
12std::istream& eatchar(std::istream& s);
13std::istream& eatcomments(std::istream& s);
14bool iswhitespace(const char& c);
15} //end IOutils
16
17namespace 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
49bool
50readTriangleMeshNodesAndElements(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
90bool
91writeTriangleMeshNodesAndElements(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
119bool
120readTriangleElementBoundaries(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 ***********************************************************************/
132bool
133writeTriangleElementBoundaryNodes(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
169bool
170readTetgenMeshNodesAndElements(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
202bool
203readTetgenElementBoundaries(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
241bool
242writeTetgenMeshNodesAndElements(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 ***********************************************************************/
259bool
260writeTetgenElementBoundaryNodes(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
290bool
291write3dmMeshNodesAndElements(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
322bool
323write2dmMeshNodesAndElements(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
Double s
Definition Headers.h:84
#define c(i)
Definition jf.h:21
std::istream & eatchar(std::istream &s)
Definition meshio.cpp:17
std::istream & eatcomments(std::istream &s)
Definition meshio.cpp:21
std::istream & eatline(std::istream &s)
Definition meshio.cpp:11
bool iswhitespace(const char &c)
Definition meshio.cpp:19
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
bool writeTriangleElementBoundaryNodes(const char *filebase, const int &indexBase, const int &nElementBoundaries, const int *elementBoundaryNodesArray, const int *elementBoundaryMaterialTypes)
Definition meshio.cpp:290
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
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
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
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
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
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
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
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