Debian Codegraph @

packages/seacas/libraries/exodus/test/testwt-nfaced.c

raw
1 /*
2 * Copyright(C) 1999-2021 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8 /*****************************************************************************
9 *
10 * testwt - test write an ExodusII database file (testwt-nfaced.exo)
11 *
12 *****************************************************************************/
13
14 #include "exodusII.h"
15 #include <assert.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 int main(int argc, char **argv)
21 {
22 ex_opts(EX_VERBOSE | EX_ABORT);
23
24 /* Specify compute and i/o word size */
25 int CPU_word_size = 0; /* sizeof(float) */
26 int IO_word_size = 4; /* (4 bytes) */
27
28 /* create EXODUS II file */
29 int exoid = ex_create("test-nfaced.exo", /* filename path */
30 EX_CLOBBER, /* create mode */
31 &CPU_word_size, /* CPU float word size in bytes */
32 &IO_word_size); /* I/O float word size in bytes */
33 printf("after ex_create for test.exo, exoid = %d\n", exoid);
34 printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);
35
36 /* initialize file with parameters */
37 {
38 ex_init_params par;
39
40 int num_dim = 3;
41 int num_nodes = 14;
42 int num_elem = 3;
43 int num_elem_blk = 1;
44 int num_node_sets = 0;
45
46 char *title = "This is a test";
47 ex_copy_string(par.title, title, MAX_LINE_LENGTH + 1);
48 par.num_dim = num_dim;
49 par.num_nodes = num_nodes;
50 par.num_edge = 0;
51 par.num_edge_blk = 0;
52 par.num_face = 15;
53 par.num_face_blk = 1;
54 par.num_elem = num_elem;
55 par.num_elem_blk = num_elem_blk;
56 par.num_node_sets = num_node_sets;
57 par.num_edge_sets = 0;
58 par.num_face_sets = 0;
59 par.num_side_sets = 0;
60 par.num_elem_sets = 0;
61 par.num_node_maps = 0;
62 par.num_edge_maps = 0;
63 par.num_face_maps = 0;
64 par.num_elem_maps = 0;
65
66 int error = ex_put_init_ext(exoid, &par);
67
68 printf("after ex_put_init_ext, error = %d\n", error);
69
70 if (error) {
71 ex_close(exoid);
72 exit(-1);
73 }
74 }
75
76 /* write nodal coordinates values and names to database */
77 float x[100], y[100], z[100];
78 x[0] = 0.00000e+00;
79 y[0] = 0.00000e+00;
80 z[0] = 0.00000e+00;
81 x[1] = 2.00000e+00;
82 y[1] = 0.00000e+00;
83 z[1] = 0.00000e+00;
84 x[2] = 0.00000e+00;
85 y[2] = 2.00000e+00;
86 z[2] = 0.00000e+00;
87 x[3] = 2.00000e+00;
88 y[3] = 2.00000e+00;
89 z[3] = 0.00000e+00;
90 x[4] = 0.00000e+00;
91 y[4] = 0.00000e+00;
92 z[4] = 2.00000e+00;
93 x[5] = 2.00000e+00;
94 y[5] = 0.00000e+00;
95 z[5] = 2.00000e+00;
96 x[6] = 0.00000e+00;
97 y[6] = 2.00000e+00;
98 z[6] = 2.00000e+00;
99 x[7] = 2.00000e+00;
100 y[7] = 2.00000e+00;
101 z[7] = 2.00000e+00;
102 x[8] = 0.00000e+00;
103 y[8] = 3.50000e+00;
104 z[8] = 1.00000e+00;
105 x[9] = 2.00000e+00;
106 y[9] = 3.50000e+00;
107 z[9] = 1.00000e+00;
108 x[10] = 0.00000e+00;
109 y[10] = 3.00000e+00;
110 z[10] = 1.50000e+00;
111 x[11] = 2.00000e+00;
112 y[11] = 3.00000e+00;
113 z[11] = 1.50000e+00;
114 x[12] = 0.00000e+00;
115 y[12] = 3.00000e+00;
116 z[12] = 0.50000e+00;
117 x[13] = 2.00000e+00;
118 y[13] = 3.00000e+00;
119 z[13] = 0.50000e+00;
120
121 int error = ex_put_coord(exoid, x, y, z);
122 printf("after ex_put_coord, error = %d\n", error);
123
124 if (error) {
125 ex_close(exoid);
126 exit(-1);
127 }
128
129 char *coord_names[3];
130 coord_names[0] = "x";
131 coord_names[1] = "y";
132 coord_names[2] = "z";
133
134 error = ex_put_coord_names(exoid, coord_names);
135 printf("after ex_put_coord_names, error = %d\n", error);
136
137 if (error) {
138 ex_close(exoid);
139 exit(-1);
140 }
141
142 /* Write the face block parameters */
143 char *block_names[10];
144 block_names[0] = "face_block_1";
145
146 int num_face_in_block[10];
147 num_face_in_block[0] = 15;
148
149 int num_total_nodes_per_blk[10];
150 num_total_nodes_per_blk[0] = 58;
151 int bids = 10;
152
153 error = ex_put_block(exoid, EX_FACE_BLOCK, bids, "nsided", num_face_in_block[0],
154 num_total_nodes_per_blk[0], 0, 0, 0);
155 printf("after ex_put_block, error = %d\n", error);
156
157 if (error) {
158 ex_close(exoid);
159 exit(-1);
160 }
161
162 /* Write face block names */
163 error = ex_put_names(exoid, EX_FACE_BLOCK, block_names);
164 printf("after ex_put_names, error = %d\n", error);
165
166 if (error) {
167 ex_close(exoid);
168 exit(-1);
169 }
170
171 /* write face connectivity */
172
173 int *connect = (int *)calloc(num_total_nodes_per_blk[0], sizeof(int));
174
175 int i = 0;
176 int j = 0;
177
178 int nnpe[20];
179 connect[i++] = 5;
180 connect[i++] = 6;
181 connect[i++] = 8; /* connectivity of face 1 of element 1 */
182 nnpe[j++] = 3;
183
184 connect[i++] = 2;
185 connect[i++] = 1;
186 connect[i++] = 4; /* face 2 of element 1 */
187 nnpe[j++] = 3;
188
189 connect[i++] = 6;
190 connect[i++] = 2;
191 connect[i++] = 4;
192 connect[i++] = 8; /* face 3 of element 1 */
193 nnpe[j++] = 4;
194
195 connect[i++] = 8;
196 connect[i++] = 4;
197 connect[i++] = 1;
198 connect[i++] = 5; /* face 4 of element 1 */
199 nnpe[j++] = 4;
200
201 connect[i++] = 1;
202 connect[i++] = 2;
203 connect[i++] = 6;
204 connect[i++] = 5; /* face 5 of element 1 */
205 nnpe[j++] = 4;
206
207 connect[i++] = 5;
208 connect[i++] = 8;
209 connect[i++] = 7; /* connectivity of face 1 of element 2 */
210 nnpe[j++] = 3;
211
212 connect[i++] = 1;
213 connect[i++] = 3;
214 connect[i++] = 4; /* face 2 of element 2 */
215 nnpe[j++] = 3;
216
217 connect[i++] = 7;
218 connect[i++] = 8;
219 connect[i++] = 4;
220 connect[i++] = 3; /* face 3 of element 2 */
221 nnpe[j++] = 4;
222
223 connect[i++] = 7;
224 connect[i++] = 3;
225 connect[i++] = 1;
226 connect[i++] = 5; /* face 4 of element 2 */
227 nnpe[j++] = 4;
228
229 connect[i++] = 8;
230 connect[i++] = 4;
231 connect[i++] = 14;
232 connect[i++] = 10;
233 connect[i++] = 12; /* connectivity of face 1 of element 3 */
234 nnpe[j++] = 5;
235
236 connect[i++] = 7;
237 connect[i++] = 11;
238 connect[i++] = 9;
239 connect[i++] = 13;
240 connect[i++] = 3; /* face 2 of element 3 */
241 nnpe[j++] = 5;
242
243 connect[i++] = 7;
244 connect[i++] = 8;
245 connect[i++] = 12;
246 connect[i++] = 11; /* face 3 of element 3 */
247 nnpe[j++] = 4;
248
249 connect[i++] = 11;
250 connect[i++] = 12;
251 connect[i++] = 10;
252 connect[i++] = 9; /* face 4 of element 3 */
253 nnpe[j++] = 4;
254
255 connect[i++] = 9;
256 connect[i++] = 10;
257 connect[i++] = 14;
258 connect[i++] = 13; /* face 5 of element 3 */
259 nnpe[j++] = 4;
260
261 connect[i++] = 13;
262 connect[i++] = 14;
263 connect[i++] = 4;
264 connect[i++] = 3; /* face 6 of element 3 */
265 nnpe[j++] = 4;
266
267 assert(i == num_total_nodes_per_blk[0]);
268 assert(j == num_face_in_block[0]);
269
270 error = ex_put_conn(exoid, EX_FACE_BLOCK, bids, connect, NULL, NULL);
271 printf("after ex_put_conn, error = %d\n", error);
272
273 if (error) {
274 ex_close(exoid);
275 exit(-1);
276 }
277
278 free(connect);
279 connect = NULL;
280
281 error = ex_put_entity_count_per_polyhedra(exoid, EX_FACE_BLOCK, bids, nnpe);
282 printf("after ex_put_entity_count_per_polyhedra, error = %d\n", error);
283
284 if (error) {
285 ex_close(exoid);
286 exit(-1);
287 }
288
289 /* write element block parameters */
290 block_names[0] = "nfaced_1";
291
292 int num_elem_in_block[10];
293 num_elem_in_block[0] = 3;
294 int num_total_faces_per_blk[10];
295 num_total_faces_per_blk[0] = 5 + 5 + 7;
296
297 bids = 10;
298
299 error = ex_put_block(exoid, EX_ELEM_BLOCK, bids, "nfaced", num_elem_in_block[0], 0, 0,
300 num_total_faces_per_blk[0], 0);
301 printf("after ex_put_block, error = %d\n", error);
302
303 if (error) {
304 ex_close(exoid);
305 exit(-1);
306 }
307
308 /* Write element block names */
309 error = ex_put_names(exoid, EX_ELEM_BLOCK, block_names);
310 printf("after ex_put_names, error = %d\n", error);
311
312 if (error) {
313 ex_close(exoid);
314 exit(-1);
315 }
316
317 /* write element-face connectivity */
318 connect = (int *)calloc(num_total_faces_per_blk[0], sizeof(int));
319
320 i = 0;
321 j = 0;
322 connect[i++] = 1;
323 connect[i++] = 2;
324 connect[i++] = 3;
325 connect[i++] = 4;
326 connect[i++] = 5;
327 nnpe[j++] = 5; /* Number of faces per element 1 */
328
329 connect[i++] = 4;
330 connect[i++] = 6;
331 connect[i++] = 7;
332 connect[i++] = 8;
333 connect[i++] = 9;
334 nnpe[j++] = 5; /* Number of faces per element 2 */
335
336 connect[i++] = 8;
337 connect[i++] = 10;
338 connect[i++] = 11;
339 connect[i++] = 12;
340 connect[i++] = 13;
341 connect[i++] = 14;
342 connect[i++] = 15;
343 nnpe[j++] = 7; /* Number of faces per element 3 */
344
345 assert(i == num_total_faces_per_blk[0]);
346 assert(j == num_elem_in_block[0]);
347
348 error = ex_put_conn(exoid, EX_ELEM_BLOCK, bids, NULL, NULL, connect);
349 printf("after ex_put_conn, error = %d\n", error);
350
351 if (error) {
352 ex_close(exoid);
353 exit(-1);
354 }
355
356 free(connect);
357
358 error = ex_put_entity_count_per_polyhedra(exoid, EX_ELEM_BLOCK, bids, nnpe);
359 printf("after ex_put_entity_count_per_polyhedra, error = %d\n", error);
360
361 if (error) {
362 ex_close(exoid);
363 exit(-1);
364 }
365
366 /* write QA records; test empty and just blank-filled records */
367 int num_qa_rec = 2;
368
369 char *qa_record[2][4];
370 qa_record[0][0] = "TESTWT-NFACED";
371 qa_record[0][1] = "testwt-nfaced";
372 qa_record[0][2] = "2010/02/15";
373 qa_record[0][3] = "06:35:15";
374 qa_record[1][0] = "";
375 qa_record[1][1] = " ";
376 qa_record[1][2] = "";
377 qa_record[1][3] = " ";
378
379 error = ex_put_qa(exoid, num_qa_rec, qa_record);
380 printf("after ex_put_qa, error = %d\n", error);
381
382 if (error) {
383 ex_close(exoid);
384 exit(-1);
385 }
386
387 /* write information records; test empty and just blank-filled records */
388 int num_info = 3;
389
390 char *info[3];
391 info[0] = "This is the first information record.";
392 info[1] = "";
393 info[2] = " ";
394
395 error = ex_put_info(exoid, num_info, info);
396 printf("after ex_put_info, error = %d\n", error);
397
398 if (error) {
399 ex_close(exoid);
400 exit(-1);
401 }
402
403 /* close the EXODUS files
404 */
405 error = ex_close(exoid);
406 printf("after ex_close, error = %d\n", error);
407 if (error) {
408 ex_close(exoid);
409 exit(-1);
410 }
411 return 0;
412 }