Debian Codegraph @

packages/seacas/libraries/exodus/test/testwt-nface-nside.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 int num_elem_in_block[10], num_total_nodes_per_blk[10];
23 int num_face_in_block[10], num_total_faces_per_blk[10];
24 int error;
25 int i, j;
26 int bids[10], nnpe[10];
27
28 float x[100], y[100], z[100];
29 char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
30 char *block_names[10], *nset_names[10], *sset_names[10];
31 char *prop_names[2], *attrib_names[2];
32 ex_opts(EX_VERBOSE | EX_ABORT);
33
34 /* Specify compute and i/o word size */
35
36 int CPU_word_size = 0; /* sizeof(float) */
37 int IO_word_size = 4; /* (4 bytes) */
38
39 /* create EXODUS II file */
40
41 int exoid = ex_create("test-nfaced.exo", /* filename path */
42 EX_CLOBBER, /* create mode */
43 &CPU_word_size, /* CPU float word size in bytes */
44 &IO_word_size); /* I/O float word size in bytes */
45 printf("after ex_create for test.exo, exoid = %d\n", exoid);
46 printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);
47
48 /* initialize file with parameters */
49 {
50 ex_init_params par;
51
52 int num_dim = 3;
53 int num_nodes = 14;
54 int num_elem = 1;
55 int num_elem_blk = 1;
56 int num_node_sets = 0;
57
58 char *title = "This is a test";
59 ex_copy_string(par.title, title, MAX_LINE_LENGTH + 1);
60 par.num_dim = num_dim;
61 par.num_nodes = num_nodes;
62 par.num_edge = 0;
63 par.num_edge_blk = 0;
64 par.num_face = 5;
65 par.num_face_blk = 1;
66 par.num_elem = num_elem;
67 par.num_elem_blk = num_elem_blk;
68 par.num_node_sets = num_node_sets;
69 par.num_edge_sets = 0;
70 par.num_face_sets = 0;
71 par.num_side_sets = 0;
72 par.num_elem_sets = 0;
73 par.num_node_maps = 0;
74 par.num_edge_maps = 0;
75 par.num_face_maps = 0;
76 par.num_elem_maps = 0;
77
78 error = ex_put_init_ext(exoid, &par);
79
80 printf("after ex_put_init_ext, error = %d\n", error);
81
82 if (error) {
83 ex_close(exoid);
84 exit(-1);
85 }
86 }
87
88 /* write nodal coordinates values and names to database */
89 x[0] = 0.00000e+00;
90 y[0] = 0.00000e+00;
91 z[0] = 0.00000e+00;
92 x[1] = 2.00000e+00;
93 y[1] = 0.00000e+00;
94 z[1] = 0.00000e+00;
95 x[2] = 0.00000e+00;
96 y[2] = 2.00000e+00;
97 z[2] = 0.00000e+00;
98 x[3] = 2.00000e+00;
99 y[3] = 2.00000e+00;
100 z[3] = 0.00000e+00;
101 x[4] = 0.00000e+00;
102 y[4] = 0.00000e+00;
103 z[4] = 2.00000e+00;
104 x[5] = 2.00000e+00;
105 y[5] = 0.00000e+00;
106 z[5] = 2.00000e+00;
107 x[6] = 0.00000e+00;
108 y[6] = 2.00000e+00;
109 z[6] = 2.00000e+00;
110 x[7] = 2.00000e+00;
111 y[7] = 2.00000e+00;
112 z[7] = 2.00000e+00;
113 x[8] = 0.00000e+00;
114 y[8] = 3.50000e+00;
115 z[8] = 1.00000e+00;
116 x[9] = 2.00000e+00;
117 y[9] = 3.50000e+00;
118 z[9] = 1.00000e+00;
119 x[10] = 0.00000e+00;
120 y[10] = 3.00000e+00;
121 z[10] = 1.50000e+00;
122 x[11] = 2.00000e+00;
123 y[11] = 3.00000e+00;
124 z[11] = 1.50000e+00;
125 x[12] = 0.00000e+00;
126 y[12] = 3.00000e+00;
127 z[12] = 0.50000e+00;
128 x[13] = 2.00000e+00;
129 y[13] = 3.00000e+00;
130 z[13] = 0.50000e+00;
131
132 error = ex_put_coord(exoid, x, y, z);
133 printf("after ex_put_coord, error = %d\n", error);
134
135 if (error) {
136 ex_close(exoid);
137 exit(-1);
138 }
139
140 coord_names[0] = "x";
141 coord_names[1] = "y";
142 coord_names[2] = "z";
143
144 error = ex_put_coord_names(exoid, coord_names);
145 printf("after ex_put_coord_names, error = %d\n", error);
146
147 if (error) {
148 ex_close(exoid);
149 exit(-1);
150 }
151
152 /* Write the face block parameters */
153 block_names[0] = "face_block_1";
154 num_face_in_block[0] = 15;
155 num_total_nodes_per_blk[0] = 54;
156 bids[0] = 10;
157
158 error = ex_put_block(exoid, EX_FACE_BLOCK, bids[0], "nsided", num_face_in_block[0],
159 num_total_nodes_per_blk[0], 0, 0, 0);
160 printf("after ex_put_block, error = %d\n", error);
161
162 if (error) {
163 ex_close(exoid);
164 exit(-1);
165 }
166
167 /* write face connectivity */
168
169 int *connect = (int *)calloc(num_total_nodes_per_blk[0], sizeof(int));
170
171 i = 0;
172 j = 0;
173
174 connect[i++] = 5;
175 connect[i++] = 6;
176 connect[i++] = 8; /* connectivity of face 1 of element 1 */
177
178 connect[i++] = 2;
179 connect[i++] = 1;
180 connect[i++] = 4; /* face 2 of element 1 */
181
182 connect[i++] = 6;
183 connect[i++] = 2;
184 connect[i++] = 4;
185 connect[i++] = 8; /* face 3 of element 1 */
186
187 connect[i++] = 8;
188 connect[i++] = 4;
189 connect[i++] = 1;
190 connect[i++] = 5; /* face 4 of element 1 */
191
192 connect[i++] = 1;
193 connect[i++] = 2;
194 connect[i++] = 6;
195 connect[i++] = 5; /* face 5 of element 1 */
196
197 connect[i++] = 5;
198 connect[i++] = 8;
199 connect[i++] = 7; /* connectivity of face 1 of element 2 */
200
201 connect[i++] = 1;
202 connect[i++] = 2;
203 connect[i++] = 3;
204 connect[i++] = 4;
205 nnpe[j++] = 4;
206
207 connect[i++] = 5;
208 connect[i++] = 3;
209 connect[i++] = 4;
210 connect[i++] = 6;
211 nnpe[j++] = 4;
212
213 connect[i++] = 5;
214 connect[i++] = 1;
215 connect[i++] = 2;
216 connect[i++] = 6;
217 nnpe[j++] = 4;
218
219 connect[i++] = 6;
220 connect[i++] = 2;
221 connect[i++] = 4;
222 nnpe[j++] = 3;
223
224 connect[i++] = 5;
225 connect[i++] = 3;
226 connect[i++] = 1;
227 nnpe[j++] = 3;
228
229 assert(i == num_total_nodes_per_blk[0]);
230 assert(j == num_face_in_block[0]);
231
232 error = ex_put_conn(exoid, EX_FACE_BLOCK, bids[0], connect, NULL, NULL);
233 printf("after ex_put_conn, error = %d\n", error);
234
235 if (error) {
236 ex_close(exoid);
237 exit(-1);
238 }
239
240 free(connect);
241 connect = NULL;
242
243 error = ex_put_entity_count_per_polyhedra(exoid, EX_FACE_BLOCK, bids[0], nnpe);
244 printf("after ex_put_entity_count_per_polyhedra, error = %d\n", error);
245
246 if (error) {
247 ex_close(exoid);
248 exit(-1);
249 }
250
251 /* write element block parameters */
252 block_names[0] = "nfaced_1";
253
254 num_elem_in_block[0] = 1;
255 num_total_faces_per_blk[0] = 5;
256
257 bids[0] = 10;
258
259 error = ex_put_block(exoid, EX_ELEM_BLOCK, bids[0], "nfaced", num_elem_in_block[0], 0, 0,
260 num_total_faces_per_blk[0], 0);
261 printf("after ex_put_block, error = %d\n", error);
262
263 if (error) {
264 ex_close(exoid);
265 exit(-1);
266 }
267
268 /* Write face block names */
269 error = ex_put_names(exoid, EX_FACE_BLOCK, block_names);
270 printf("after ex_put_names, error = %d\n", error);
271
272 if (error) {
273 ex_close(exoid);
274 exit(-1);
275 }
276
277 /* Write element block names */
278 error = ex_put_names(exoid, EX_ELEM_BLOCK, block_names);
279 printf("after ex_put_names, error = %d\n", error);
280
281 if (error) {
282 ex_close(exoid);
283 exit(-1);
284 }
285
286 /* write element-face connectivity */
287 connect = (int *)calloc(num_total_faces_per_blk[0], sizeof(int));
288
289 i = 0;
290 j = 0;
291 connect[i++] = 1;
292 connect[i++] = 2;
293 connect[i++] = 3;
294 connect[i++] = 4;
295 connect[i++] = 5;
296 nnpe[j++] = 5; /* Number of faces per element */
297
298 assert(i == num_total_faces_per_blk[0]);
299 assert(j == num_elem_in_block[0]);
300
301 error = ex_put_conn(exoid, EX_ELEM_BLOCK, bids[0], NULL, NULL, connect);
302 printf("after ex_put_conn, error = %d\n", error);
303
304 if (error) {
305 ex_close(exoid);
306 exit(-1);
307 }
308
309 free(connect);
310
311 error = ex_put_entity_count_per_polyhedra(exoid, EX_ELEM_BLOCK, bids[0], nnpe);
312 printf("after ex_put_entity_count_per_polyhedra, error = %d\n", error);
313
314 if (error) {
315 ex_close(exoid);
316 exit(-1);
317 }
318
319 /* write QA records; test empty and just blank-filled records */
320 int num_qa_rec = 2;
321
322 qa_record[0][0] = "TESTWT-NFACED";
323 qa_record[0][1] = "testwt-nfaced";
324 qa_record[0][2] = "2010/02/15";
325 qa_record[0][3] = "06:35:15";
326 qa_record[1][0] = "";
327 qa_record[1][1] = " ";
328 qa_record[1][2] = "";
329 qa_record[1][3] = " ";
330
331 error = ex_put_qa(exoid, num_qa_rec, qa_record);
332 printf("after ex_put_qa, error = %d\n", error);
333
334 if (error) {
335 ex_close(exoid);
336 exit(-1);
337 }
338
339 /* write information records; test empty and just blank-filled records */
340 int num_info = 3;
341
342 info[0] = "This is the first information record.";
343 info[1] = "";
344 info[2] = " ";
345
346 error = ex_put_info(exoid, num_info, info);
347 printf("after ex_put_info, error = %d\n", error);
348
349 if (error) {
350 ex_close(exoid);
351 exit(-1);
352 }
353
354 /* write results variables parameters and names */
355 int num_glo_vars = 1;
356
357 var_names[0] = "glo_vars";
358
359 error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars);
360 printf("after ex_put_variable_param, error = %d\n", error);
361 if (error) {
362 ex_close(exoid);
363 exit(-1);
364 }
365
366 error = ex_put_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names);
367 printf("after ex_put_variable_names, error = %d\n", error);
368 if (error) {
369 ex_close(exoid);
370 exit(-1);
371 }
372
373 int num_nod_vars = 2;
374 /* 12345678901234567890123456789012 */
375 var_names[0] = "node_variable_a_very_long_name_0";
376 var_names[1] = EX_NODE_SET;
377
378 error = ex_put_variable_param(exoid, EX_NODAL, num_nod_vars);
379 printf("after ex_put_variable_param, error = %d\n", error);
380 if (error) {
381 ex_close(exoid);
382 exit(-1);
383 }
384
385 error = ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names);
386 printf("after ex_put_variable_names, error = %d\n", error);
387 if (error) {
388 ex_close(exoid);
389 exit(-1);
390 }
391
392 int num_ele_vars = 3;
393
394 var_names[0] = "ele_var0";
395 var_names[1] = "ele_var1";
396 var_names[2] = "ele_var2";
397
398 error = ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars);
399 printf("after ex_put_variable_param, error = %d\n", error);
400 if (error) {
401 ex_close(exoid);
402 exit(-1);
403 }
404
405 error = ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names);
406 printf("after ex_put_variable_names, error = %d\n", error);
407 if (error) {
408 ex_close(exoid);
409 exit(-1);
410 }
411
412 /* write element variable truth table */
413 int *truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int));
414
415 int k = 0;
416 for (i = 0; i < num_elem_blk; i++) {
417 for (j = 0; j < num_ele_vars; j++) {
418 truth_tab[k++] = 1;
419 }
420 }
421
422 error = ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab);
423 printf("after ex_put_elem_var_tab, error = %d\n", error);
424
425 if (error) {
426 ex_close(exoid);
427 exit(-1);
428 }
429
430 free(truth_tab);
431
432 /* for each time step, write the analysis results;
433 * the code below fills the arrays glob_var_vals,
434 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
435 * obviously the analysis code will populate these arrays
436 */
437
438 int whole_time_step = 1;
439 int num_time_steps = 10;
440
441 float *glob_var_vals = (float *)calloc(num_glo_vars, CPU_word_size);
442 float *nodal_var_vals = (float *)calloc(num_nodes, CPU_word_size);
443 float *elem_var_vals = (float *)calloc(8, CPU_word_size);
444
445 for (i = 0; i < num_time_steps; i++) {
446 float time_value = (float)(i + 1) / 100.;
447
448 /* write time value */
449 error = ex_put_time(exoid, whole_time_step, &time_value);
450 printf("after ex_put_time, error = %d\n", error);
451
452 if (error) {
453 ex_close(exoid);
454 exit(-1);
455 }
456
457 /* write global variables */
458 for (j = 0; j < num_glo_vars; j++) {
459 glob_var_vals[j] = (float)(j + 2) * time_value;
460 }
461
462 error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
463 printf("after ex_put_glob_vars, error = %d\n", error);
464
465 if (error) {
466 ex_close(exoid);
467 exit(-1);
468 }
469
470 /* write nodal variables */
471 for (k = 1; k <= num_nod_vars; k++) {
472 for (j = 0; j < num_nodes; j++) {
473 nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value);
474 }
475
476 error = ex_put_nodal_var(exoid, whole_time_step, k, num_nodes, nodal_var_vals);
477 printf("after ex_put_nodal_var, error = %d\n", error);
478 if (error) {
479 ex_close(exoid);
480 exit(-1);
481 }
482 }
483
484 /* write element variables */
485 for (k = 1; k <= num_ele_vars; k++) {
486 for (j = 0; j < num_elem_blk; j++) {
487 for (int m = 0; m < num_elem_in_block[j]; m++) {
488 elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value);
489 /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
490 }
491 error = ex_put_elem_var(exoid, whole_time_step, k, bids[j], num_elem_in_block[j],
492 elem_var_vals);
493 printf("after ex_put_elem_var, error = %d\n", error);
494 if (error) {
495 ex_close(exoid);
496 exit(-1);
497 }
498 }
499 }
500
501 whole_time_step++;
502
503 /* update the data file; this should be done at the end of every time step
504 * to ensure that no data is lost if the analysis dies
505 */
506 error = ex_update(exoid);
507 printf("after ex_update, error = %d\n", error);
508 if (error) {
509 ex_close(exoid);
510 exit(-1);
511 }
512 }
513 free(glob_var_vals);
514 free(nodal_var_vals);
515 free(elem_var_vals);
516
517 /* close the EXODUS files
518 */
519 error = ex_close(exoid);
520 printf("after ex_close, error = %d\n", error);
521 if (error) {
522 ex_close(exoid);
523 exit(-1);
524 }
525 return 0;
526 }