-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtriangle_io_prb.cpp
383 lines (351 loc) · 9.01 KB
/
triangle_io_prb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <cstring>
using namespace std;
# include "triangle_io.hpp"
int main ( );
void test01 ( );
void test02 ( );
void test03 ( );
void test04 ( );
//****************************************************************************80
int main ( )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for TRIANGLE_IO_PRB.
//
// Discussion:
//
// TRIANGLE_IO_PRB tests the TRIANGLE_IO library.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 07 December 2010
//
// Author:
//
// John Burkardt
//
{
timestamp ( );
cout << "\n";
cout << "TRIANGLE_IO_PRB\n";
cout << " C++ version\n";
cout << " Test the TRIANGLE_IO library.\n";
test01 ( );
test02 ( );
test03 ( );
test04 ( );
//
// Terminate.
//
cout << "\n";
cout << "TRIANGLE_IO_PRB\n";
cout << " Normal end of execution.\n";
cout << "\n";
timestamp ( );
return 0;
}
//****************************************************************************80
void test01 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST01 gets the example node data and writes it to a file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 07 December 2010
//
// Author:
//
// John Burkardt
//
{
double *node_att;
int node_att_num;
double *node_coord;
int node_dim;
string node_file = "example.node";
int *node_marker;
int node_marker_num;
int node_num;
cout << "\n";
cout << "TEST01:\n";
cout << " Get example node data, write to a node file.\n";
//
// Get node example size.
//
triangle_node_size_example ( &node_num, &node_dim, &node_att_num,
&node_marker_num );
//
// Print the sizes.
//
cout << "\n";
cout << " Number of nodes = " << node_num << "\n";
cout << " Spatial dimension =" << node_dim << "\n";
cout << " Number of node attributes = " << node_att_num << "\n";
cout << " Number of node markers = " << node_marker_num << "\n";
//
// Allocate memory for node data.
//
node_coord = new double[ node_dim * node_num ];
node_att = new double[ node_att_num * node_num ];
node_marker = new int[ node_marker_num * node_num ];
//
// Get the node data.
//
triangle_node_data_example ( node_num, node_dim, node_att_num,
node_marker_num, node_coord, node_att, node_marker );
//
// Print some of the data.
//
r8mat_transpose_print_some ( node_dim, node_num, node_coord,
1, 1, node_dim, 10, " Coordinates for first 10 nodes:" );
r8mat_transpose_print_some ( node_att_num, node_num, node_att,
1, 1, node_att_num, 10, " Attributes for first 10 nodes:" );
i4mat_transpose_print_some ( node_marker_num, node_num, node_marker,
1, 1, node_marker_num, 10, " Markers for first 10 nodes:" );
//
// Write the node information to node file.
//
triangle_node_write ( node_file, node_num, node_dim, node_att_num,
node_marker_num, node_coord, node_att, node_marker );
cout << "\n";
cout << " Node data written to file \"" << node_file << "\"\n";
//
// Clean up.
//
delete [] node_att;
delete [] node_coord;
delete [] node_marker;
return;
}
//****************************************************************************80
void test02 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST02 gets the example element data and writes it to a file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 07 December 2010
//
// Author:
//
// John Burkardt
//
{
double *element_att;
int element_att_num;
string element_file = "example.ele";
int *element_node;
int element_num;
int element_order;
cout << "\n";
cout << "TEST02:\n";
cout << " Get example element data, write to an element file.\n";
//
// Get element example size.
//
triangle_element_size_example ( &element_num, &element_order,
&element_att_num );
//
// Print the sizes.
//
cout << "\n";
cout << " Number of elements = " << element_num << "\n";
cout << " Order of elements = " << element_order << "\n";
cout << " Number of element attributes = " << element_att_num << "\n";
//
// Allocate memory.
//
element_node = new int[ element_order * element_num ];
element_att = new double[ element_att_num * element_num ];
//
// Get the data.
//
triangle_element_data_example ( element_num, element_order, element_att_num,
element_node, element_att );
//
// Print some of the data.
//
i4mat_transpose_print_some ( element_order, element_num, element_node,
1, 1, element_order, 10, " Node connectivity of first 10 elements:" );
r8mat_transpose_print_some ( element_att_num, element_num, element_att,
1, 1, element_att_num, 10, " Attributes for first 10 elements:" );
//
// Write the node information to node file.
//
triangle_element_write ( element_file, element_num, element_order,
element_att_num, element_node, element_att );
cout << "\n";
cout << " Element data written to file \"" << element_file << "\"\n";
//
// Clean up.
//
delete [] element_att;
delete [] element_node;
return;
}
//****************************************************************************80
void test03 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST03 reads the example node data from a file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 07 December 2010
//
// Author:
//
// John Burkardt
//
{
double *node_att;
int node_att_num;
double *node_coord;
int node_dim;
string node_file = "example.node";
int *node_marker;
int node_marker_num;
int node_num;
cout << "\n";
cout << "TEST03:\n";
cout << " Read node data from a node file.\n";
//
// Get the data size.
//
triangle_node_size_read ( node_file, &node_num, &node_dim, &node_att_num,
&node_marker_num );
//
// Print the sizes.
//
cout << "\n";
cout << " Node data read from file \"" << node_file << "\"\n";
cout << "\n";
cout << " Number of nodes = " << node_num << "\n";
cout << " Spatial dimension = " << node_dim << "\n";
cout << " Number of node attributes = " << node_att_num << "\n";
cout << " Number of node markers = " << node_marker_num << "\n";
//
// Allocate memory.
//
node_coord = new double[ node_dim * node_num ];
node_att = new double[ node_att_num * node_num ];
node_marker = new int[ node_marker_num * node_num ];
//
// Get the data.
//
triangle_node_data_read ( node_file, node_num, node_dim, node_att_num,
node_marker_num, node_coord, node_att, node_marker );
//
// Print some of the data.
//
r8mat_transpose_print_some ( node_dim, node_num, node_coord,
1, 1, node_dim, 10, " Coordinates for first 10 nodes:" );
r8mat_transpose_print_some ( node_att_num, node_num, node_att,
1, 1, node_att_num, 10, " Attributes for first 10 nodes:" );
i4mat_transpose_print_some ( node_marker_num, node_num, node_marker,
1, 1, node_marker_num, 10, " Markers for first 10 nodes:" );
//
// Clean up.
//
delete [] node_att;
delete [] node_coord;
delete [] node_marker;
return;
}
//****************************************************************************80
void test04 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST04 reads the example element data from a file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 09 November 2010
//
// Author:
//
// John Burkardt
//
{
double *element_att;
int element_att_num;
string element_file = "example.ele";
int *element_node;
int element_num;
int element_order;
cout << "\n";
cout << "TEST04:\n";
cout << " Read element data from an element file.\n";
//
// Get data size.
//
triangle_element_size_read ( element_file, &element_num, &element_order,
&element_att_num );
//
// Print the sizes.
//
cout << "\n";
cout << " Element data read from file \"" << element_file << "\"\n";
cout << "\n";
cout << " Number of elements = " << element_num << "\n";
cout << " Element order = " << element_order << "\n";
cout << " Number of element attributes = " << element_att_num << "\n";
//
// Allocate memory.
//
element_node = new int[ element_order * element_num ];
element_att = new double[ element_att_num * element_num ];
//
// Get the data.
//
triangle_element_data_read ( element_file, element_num, element_order,
element_att_num, element_node, element_att );
//
// Print some of the data.
//
i4mat_transpose_print_some ( element_order, element_num, element_node,
1, 1, element_order, 10, " Connectivity for first 10 elements:" );
r8mat_transpose_print_some ( element_att_num, element_num, element_att,
1, 1, element_att_num, 10, " Attributes for first 10 elements:" );
//
// Clean up.
//
delete [] element_att;
delete [] element_node;
return;
}