Debian Codegraph @

packages/seacas/libraries/exodus/test/testwt-long-name.c

raw
1 /*
2 * Copyright(C) 1999-2020 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 #include "exodusII.h"
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 int main(int argc, char **argv)
14 {
15 int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
16 int num_elem_in_block[10], num_nodes_per_elem[10];
17 int num_face_in_sset[10], num_nodes_in_nset[10];
18 int num_node_sets, num_side_sets, error;
19 int i, j, k, m, *elem_map, *connect;
20 int node_list[100], elem_list[100], side_list[100];
21 int ebids[10], ssids[10], nsids[10];
22 int num_qa_rec, num_info;
23 int num_glo_vars, num_nod_vars, num_ele_vars, num_sset_vars, num_nset_vars;
24 int *truth_tab;
25 int whole_time_step, num_time_steps;
26 int CPU_word_size, IO_word_size;
27 int prop_array[2];
28
29 float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
30 float *sset_var_vals, *nset_var_vals;
31 float time_value;
32 float x[100], y[100], z[100];
33 float attrib[1], dist_fact[100];
34 char *coord_names[3], *qa_record[2][4], *info[3], *variable_names[3];
35 char *block_names[10], *nset_names[10], *sset_names[10];
36 char *prop_names[2], *attrib_names[2];
37 char *title = "This is a test";
38 ex_opts(EX_VERBOSE | EX_ABORT);
39
40 /* Specify compute and i/o word size */
41
42 CPU_word_size = 0; /* sizeof(float) */
43 IO_word_size = 4; /* (4 bytes) */
44
45 /* create EXODUS II file */
46
47 exoid = ex_create("test.exo", /* filename path */
48 EX_CLOBBER, /* create mode */
49 &CPU_word_size, /* CPU float word size in bytes */
50 &IO_word_size); /* I/O float word size in bytes */
51 printf("after ex_create for test.exo, exoid = %d\n", exoid);
52 printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);
53
54 ex_set_option(exoid, EX_OPT_MAX_NAME_LENGTH, 127); /* Using long names */
55
56 /* initialize file with parameters */
57
58 num_dim = 3;
59 num_nodes = 33;
60 num_elem = 7;
61 num_elem_blk = 7;
62 num_node_sets = 2;
63 num_side_sets = 5;
64
65 error = ex_put_init(exoid, title, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets,
66 num_side_sets);
67
68 printf("after ex_put_init, error = %d\n", error);
69
70 if (error) {
71 ex_close(exoid);
72 exit(-1);
73 }
74
75 /* write nodal coordinates values and names to database */
76
77 /* Quad #1 */
78 x[0] = 0.0;
79 y[0] = 0.0;
80 z[0] = 0.0;
81 x[1] = 1.0;
82 y[1] = 0.0;
83 z[1] = 0.0;
84 x[2] = 1.0;
85 y[2] = 1.0;
86 z[2] = 0.0;
87 x[3] = 0.0;
88 y[3] = 1.0;
89 z[3] = 0.0;
90
91 /* Quad #2 */
92 x[4] = 1.0;
93 y[4] = 0.0;
94 z[4] = 0.0;
95 x[5] = 2.0;
96 y[5] = 0.0;
97 z[5] = 0.0;
98 x[6] = 2.0;
99 y[6] = 1.0;
100 z[6] = 0.0;
101 x[7] = 1.0;
102 y[7] = 1.0;
103 z[7] = 0.0;
104
105 /* Hex #1 */
106 x[8] = 0.0;
107 y[8] = 0.0;
108 z[8] = 0.0;
109 x[9] = 10.0;
110 y[9] = 0.0;
111 z[9] = 0.0;
112 x[10] = 10.0;
113 y[10] = 0.0;
114 z[10] = -10.0;
115 x[11] = 1.0;
116 y[11] = 0.0;
117 z[11] = -10.0;
118 x[12] = 1.0;
119 y[12] = 10.0;
120 z[12] = 0.0;
121 x[13] = 10.0;
122 y[13] = 10.0;
123 z[13] = 0.0;
124 x[14] = 10.0;
125 y[14] = 10.0;
126 z[14] = -10.0;
127 x[15] = 1.0;
128 y[15] = 10.0;
129 z[15] = -10.0;
130
131 /* Tetra #1 */
132 x[16] = 0.0;
133 y[16] = 0.0;
134 z[16] = 0.0;
135 x[17] = 1.0;
136 y[17] = 0.0;
137 z[17] = 5.0;
138 x[18] = 10.0;
139 y[18] = 0.0;
140 z[18] = 2.0;
141 x[19] = 7.0;
142 y[19] = 5.0;
143 z[19] = 3.0;
144
145 /* Wedge #1 */
146 x[20] = 3.0;
147 y[20] = 0.0;
148 z[20] = 6.0;
149 x[21] = 6.0;
150 y[21] = 0.0;
151 z[21] = 0.0;
152 x[22] = 0.0;
153 y[22] = 0.0;
154 z[22] = 0.0;
155 x[23] = 3.0;
156 y[23] = 2.0;
157 z[23] = 6.0;
158 x[24] = 6.0;
159 y[24] = 2.0;
160 z[24] = 2.0;
161 x[25] = 0.0;
162 y[25] = 2.0;
163 z[25] = 0.0;
164
165 /* Tetra #2 */
166 x[26] = 2.7;
167 y[26] = 1.7;
168 z[26] = 2.7;
169 x[27] = 6.0;
170 y[27] = 1.7;
171 z[27] = 3.3;
172 x[28] = 5.7;
173 y[28] = 1.7;
174 z[28] = 1.7;
175 x[29] = 3.7;
176 y[29] = 0.0;
177 z[29] = 2.3;
178
179 /* 3d Tri */
180 x[30] = 0.0;
181 y[30] = 0.0;
182 z[30] = 0.0;
183 x[31] = 10.0;
184 y[31] = 0.0;
185 z[31] = 0.0;
186 x[32] = 10.0;
187 y[32] = 10.0;
188 z[32] = 10.0;
189
190 error = ex_put_coord(exoid, x, y, z);
191 printf("after ex_put_coord, error = %d\n", error);
192
193 if (error) {
194 ex_close(exoid);
195 exit(-1);
196 }
197 /* 0 1 2 3 4 5 6 */
198 /* 1234567890123456789012345678901234567890123456789012345678901234 */
199 coord_names[0] = "X coordinate name that is padded to be longer than 32 characters";
200 coord_names[1] = "Y coordinate name that is padded to be longer than 32 characters";
201 coord_names[2] = "Z coordinate name that is padded to be longer than 32 characters";
202
203 error = ex_put_coord_names(exoid, coord_names);
204 printf("after ex_put_coord_names, error = %d\n", error);
205
206 if (error) {
207 ex_close(exoid);
208 exit(-1);
209 }
210
211 /* Add nodal attributes */
212 error = ex_put_attr_param(exoid, EX_NODAL, 0, 2);
213 printf("after ex_put_attr_param, error = %d\n", error);
214
215 if (error) {
216 ex_close(exoid);
217 exit(-1);
218 }
219
220 error = ex_put_one_attr(exoid, EX_NODAL, 0, 1, x);
221 if (error) {
222 ex_close(exoid);
223 exit(-1);
224 }
225
226 error = ex_put_one_attr(exoid, EX_NODAL, 0, 2, y);
227 if (error) {
228 ex_close(exoid);
229 exit(-1);
230 }
231
232 {
233 attrib_names[0] = "Node_attr_1";
234 attrib_names[1] = "Node_attr_2";
235 error = ex_put_attr_names(exoid, EX_NODAL, 0, attrib_names);
236 if (error) {
237 ex_close(exoid);
238 exit(-1);
239 }
240 }
241
242 /* write element order map */
243
244 elem_map = (int *)calloc(num_elem, sizeof(int));
245
246 for (i = 1; i <= num_elem; i++) {
247 elem_map[i - 1] = i;
248 }
249
250 error = ex_put_id_map(exoid, EX_ELEM_MAP, elem_map);
251 printf("after ex_put_id_map, error = %d\n", error);
252
253 if (error) {
254 ex_close(exoid);
255 exit(-1);
256 }
257
258 free(elem_map);
259
260 /* write element block parameters */
261
262 /* 0 1 2 3 4 5 6 */
263 /* 1234567890123456789012345678901234567890123456789012345678901234 */
264 block_names[0] = "Very long name for block_1 that exceeds 32 characters";
265 block_names[1] = "Very long name for block_2 that exceeds 32 characters";
266 block_names[2] = "Very long name for block_3 that exceeds 32 characters";
267 block_names[3] = "Very long name for block_4 that exceeds 32 characters";
268 block_names[4] = "Very long name for block_5 that exceeds 32 characters";
269 block_names[5] = "Very long name for block_6 that exceeds 32 characters";
270 block_names[6] = "Very long name for block_7 that exceeds 32 characters";
271 num_elem_in_block[0] = 1;
272 num_elem_in_block[1] = 1;
273 num_elem_in_block[2] = 1;
274 num_elem_in_block[3] = 1;
275 num_elem_in_block[4] = 1;
276 num_elem_in_block[5] = 1;
277 num_elem_in_block[6] = 1;
278
279 num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads */
280 num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads */
281 num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes */
282 num_nodes_per_elem[3] = 4; /* elements in block #4 are 4-node tetras */
283 num_nodes_per_elem[4] = 6; /* elements in block #5 are 6-node wedges */
284 num_nodes_per_elem[5] = 8; /* elements in block #6 are 8-node tetras */
285 num_nodes_per_elem[6] = 3; /* elements in block #7 are 3-node tris */
286
287 ebids[0] = 10;
288 ebids[1] = 11;
289 ebids[2] = 12;
290 ebids[3] = 13;
291 ebids[4] = 14;
292 ebids[5] = 15;
293 ebids[6] = 16;
294
295 error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[0], "quad", num_elem_in_block[0],
296 num_nodes_per_elem[0], 0, 0, 1);
297 printf("after ex_put_elem_block, error = %d\n", error);
298
299 if (error) {
300 ex_close(exoid);
301 exit(-1);
302 }
303
304 error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[1], "quad", num_elem_in_block[1],
305 num_nodes_per_elem[1], 0, 0, 1);
306 printf("after ex_put_elem_block, error = %d\n", error);
307
308 if (error) {
309 ex_close(exoid);
310 exit(-1);
311 }
312
313 error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[2], "hex", num_elem_in_block[2],
314 num_nodes_per_elem[2], 0, 0, 1);
315 printf("after ex_put_elem_block, error = %d\n", error);
316
317 if (error) {
318 ex_close(exoid);
319 exit(-1);
320 }
321
322 error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[3], "tetra", num_elem_in_block[3],
323 num_nodes_per_elem[3], 0, 0, 1);
324 printf("after ex_put_elem_block, error = %d\n", error);
325
326 if (error) {
327 ex_close(exoid);
328 exit(-1);
329 }
330
331 error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[4], "wedge", num_elem_in_block[4],
332 num_nodes_per_elem[4], 0, 0, 1);
333 printf("after ex_put_elem_block, error = %d\n", error);
334
335 if (error) {
336 ex_close(exoid);
337 exit(-1);
338 }
339
340 error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[5], "tetra", num_elem_in_block[5],
341 num_nodes_per_elem[5], 0, 0, 1);
342 printf("after ex_put_elem_block, error = %d\n", error);
343
344 if (error) {
345 ex_close(exoid);
346 exit(-1);
347 }
348
349 error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[6], "tri", num_elem_in_block[6],
350 num_nodes_per_elem[6], 0, 0, 1);
351 printf("after ex_put_elem_block, error = %d\n", error);
352
353 if (error) {
354 ex_close(exoid);
355 exit(-1);
356 }
357
358 /* Write element block names */
359 error = ex_put_names(exoid, EX_ELEM_BLOCK, block_names);
360 printf("after ex_put_names, error = %d\n", error);
361
362 if (error) {
363 ex_close(exoid);
364 exit(-1);
365 }
366
367 /* write element block properties */
368
369 /* 0 1 2 3 4 5 6 */
370 /* 1234567890123456789012345678901234567890123456789012345678901234 */
371 prop_names[0] = "MATERIAL_PROPERTY_LONG_NAME_32CH";
372 prop_names[1] = "DENSITY";
373 error = ex_put_prop_names(exoid, EX_ELEM_BLOCK, 2, prop_names);
374 printf("after ex_put_prop_names, error = %d\n", error);
375
376 if (error) {
377 ex_close(exoid);
378 exit(-1);
379 }
380
381 error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], prop_names[0], 10);
382 printf("after ex_put_prop, error = %d\n", error);
383 if (error) {
384 ex_close(exoid);
385 exit(-1);
386 }
387
388 error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], prop_names[0], 20);
389 printf("after ex_put_prop, error = %d\n", error);
390 if (error) {
391 ex_close(exoid);
392 exit(-1);
393 }
394
395 error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], prop_names[0], 30);
396 printf("after ex_put_prop, error = %d\n", error);
397 if (error) {
398 ex_close(exoid);
399 exit(-1);
400 }
401
402 error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], prop_names[0], 40);
403 printf("after ex_put_prop, error = %d\n", error);
404 if (error) {
405 ex_close(exoid);
406 exit(-1);
407 }
408
409 error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], prop_names[0], 50);
410 printf("after ex_put_prop, error = %d\n", error);
411 if (error) {
412 ex_close(exoid);
413 exit(-1);
414 }
415
416 error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], prop_names[0], 60);
417 printf("after ex_put_prop, error = %d\n", error);
418 if (error) {
419 ex_close(exoid);
420 exit(-1);
421 }
422
423 error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], prop_names[0], 70);
424 printf("after ex_put_prop, error = %d\n", error);
425 if (error) {
426 ex_close(exoid);
427 exit(-1);
428 }
429
430 /* write element connectivity */
431
432 connect = (int *)calloc(8, sizeof(int));
433 connect[0] = 1;
434 connect[1] = 2;
435 connect[2] = 3;
436 connect[3] = 4;
437
438 error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL);
439 printf("after ex_put_elem_conn, error = %d\n", error);
440 if (error) {
441 ex_close(exoid);
442 exit(-1);
443 }
444
445 connect[0] = 5;
446 connect[1] = 6;
447 connect[2] = 7;
448 connect[3] = 8;
449
450 error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[1], connect, NULL, NULL);
451 printf("after ex_put_elem_conn, error = %d\n", error);
452
453 if (error) {
454 ex_close(exoid);
455 exit(-1);
456 }
457
458 connect[0] = 9;
459 connect[1] = 10;
460 connect[2] = 11;
461 connect[3] = 12;
462 connect[4] = 13;
463 connect[5] = 14;
464 connect[6] = 15;
465 connect[7] = 16;
466
467 error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL);
468 printf("after ex_put_elem_conn, error = %d\n", error);
469
470 if (error) {
471 ex_close(exoid);
472 exit(-1);
473 }
474
475 connect[0] = 17;
476 connect[1] = 18;
477 connect[2] = 19;
478 connect[3] = 20;
479
480 error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[3], connect, NULL, NULL);
481 printf("after ex_put_elem_conn, error = %d\n", error);
482
483 if (error) {
484 ex_close(exoid);
485 exit(-1);
486 }
487
488 connect[0] = 21;
489 connect[1] = 22;
490 connect[2] = 23;
491 connect[3] = 24;
492 connect[4] = 25;
493 connect[5] = 26;
494
495 error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[4], connect, NULL, NULL);
496 printf("after ex_put_elem_conn, error = %d\n", error);
497
498 if (error) {
499 ex_close(exoid);
500 exit(-1);
501 }
502
503 connect[0] = 17;
504 connect[1] = 18;
505 connect[2] = 19;
506 connect[3] = 20;
507 connect[4] = 27;
508 connect[5] = 28;
509 connect[6] = 30;
510 connect[7] = 29;
511
512 error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[5], connect, NULL, NULL);
513 printf("after ex_put_elem_conn, error = %d\n", error);
514
515 if (error) {
516 ex_close(exoid);
517 exit(-1);
518 }
519
520 connect[0] = 31;
521 connect[1] = 32;
522 connect[2] = 33;
523
524 error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[6], connect, NULL, NULL);
525 printf("after ex_put_elem_conn, error = %d\n", error);
526
527 if (error) {
528 ex_close(exoid);
529 exit(-1);
530 }
531
532 free(connect);
533
534 /* write element block attributes */
535
536 attrib[0] = 3.14159;
537 error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[0], attrib);
538 printf("after ex_put_elem_attr, error = %d\n", error);
539 if (error) {
540 ex_close(exoid);
541 exit(-1);
542 }
543
544 error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[0], attrib);
545 printf("after ex_put_elem_attr, error = %d\n", error);
546 if (error) {
547 ex_close(exoid);
548 exit(-1);
549 }
550
551 attrib[0] = 6.14159;
552 error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[1], attrib);
553 printf("after ex_put_elem_attr, error = %d\n", error);
554
555 if (error) {
556 ex_close(exoid);
557 exit(-1);
558 }
559
560 error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[2], attrib);
561 printf("after ex_put_elem_attr, error = %d\n", error);
562
563 if (error) {
564 ex_close(exoid);
565 exit(-1);
566 }
567
568 error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[3], attrib);
569 printf("after ex_put_elem_attr, error = %d\n", error);
570
571 if (error) {
572 ex_close(exoid);
573 exit(-1);
574 }
575
576 error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[4], attrib);
577 printf("after ex_put_elem_attr, error = %d\n", error);
578
579 if (error) {
580 ex_close(exoid);
581 exit(-1);
582 }
583
584 error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[5], attrib);
585 printf("after ex_put_elem_attr, error = %d\n", error);
586
587 if (error) {
588 ex_close(exoid);
589 exit(-1);
590 }
591
592 error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[6], attrib);
593 printf("after ex_put_elem_attr, error = %d\n", error);
594
595 if (error) {
596 ex_close(exoid);
597 exit(-1);
598 }
599
600 /* 0 1 2 3 4 5 6 */
601 /* 1234567890123456789012345678901234567890123456789012345678901234 */
602 attrib_names[0] = "The name for the attribute representing the shell thickness";
603 for (i = 0; i < 7; i++) {
604 error = ex_put_attr_names(exoid, EX_ELEM_BLOCK, ebids[i], attrib_names);
605 printf("after ex_put_elem_attr_names, error = %d\n", error);
606 if (error) {
607 ex_close(exoid);
608 exit(-1);
609 }
610 }
611
612 /* write individual node sets */
613
614 num_nodes_in_nset[0] = 5;
615 num_nodes_in_nset[1] = 3;
616
617 nsids[0] = 20;
618 nsids[1] = 21;
619
620 error = ex_put_set_param(exoid, EX_NODE_SET, nsids[0], 5, 5);
621 printf("after ex_put_node_set_param, error = %d\n", error);
622
623 if (error) {
624 ex_close(exoid);
625 exit(-1);
626 }
627
628 node_list[0] = 10;
629 node_list[1] = 11;
630 node_list[2] = 12;
631 node_list[3] = 13;
632 node_list[4] = 14;
633
634 dist_fact[0] = 1.0;
635 dist_fact[1] = 2.0;
636 dist_fact[2] = 3.0;
637 dist_fact[3] = 4.0;
638 dist_fact[4] = 5.0;
639
640 error = ex_put_set(exoid, EX_NODE_SET, nsids[0], node_list, NULL);
641 printf("after ex_put_node_set, error = %d\n", error);
642 if (error) {
643 ex_close(exoid);
644 exit(-1);
645 }
646
647 error = ex_put_set_dist_fact(exoid, EX_NODE_SET, nsids[0], dist_fact);
648 printf("after ex_put_node_set_dist_fact, error = %d\n", error);
649 if (error) {
650 ex_close(exoid);
651 exit(-1);
652 }
653
654 error = ex_put_set_param(exoid, EX_NODE_SET, nsids[1], 3, 3);
655 printf("after ex_put_node_set_param, error = %d\n", error);
656
657 if (error) {
658 ex_close(exoid);
659 exit(-1);
660 }
661
662 node_list[0] = 20;
663 node_list[1] = 21;
664 node_list[2] = 22;
665
666 dist_fact[0] = 1.1;
667 dist_fact[1] = 2.1;
668 dist_fact[2] = 3.1;
669
670 error = ex_put_set(exoid, EX_NODE_SET, nsids[1], node_list, NULL);
671 printf("after ex_put_node_set, error = %d\n", error);
672 if (error) {
673 ex_close(exoid);
674 exit(-1);
675 }
676
677 error = ex_put_set_dist_fact(exoid, EX_NODE_SET, nsids[1], dist_fact);
678 printf("after ex_put_node_set_dist_fact, error = %d\n", error);
679 if (error) {
680 ex_close(exoid);
681 exit(-1);
682 }
683
684 /* Write node set names */
685 nset_names[0] = "nset_1";
686 nset_names[1] = "nset_2";
687
688 error = ex_put_names(exoid, EX_NODE_SET, nset_names);
689 printf("after ex_put_names, error = %d\n", error);
690
691 if (error) {
692 ex_close(exoid);
693 exit(-1);
694 }
695
696 error = ex_put_prop(exoid, EX_NODE_SET, nsids[0], "FACE", 4);
697 printf("after ex_put_prop, error = %d\n", error);
698 if (error) {
699 ex_close(exoid);
700 exit(-1);
701 }
702
703 error = ex_put_prop(exoid, EX_NODE_SET, nsids[1], "FACE", 5);
704 printf("after ex_put_prop, error = %d\n", error);
705
706 if (error) {
707 ex_close(exoid);
708 exit(-1);
709 }
710
711 prop_array[0] = 1000;
712 prop_array[1] = 2000;
713
714 error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
715 printf("after ex_put_prop_array, error = %d\n", error);
716 if (error) {
717 ex_close(exoid);
718 exit(-1);
719 }
720
721 /* Add nodeset attributes */
722 error = ex_put_attr_param(exoid, EX_NODE_SET, nsids[0], 1);
723 printf("after ex_put_attr_param, error = %d\n", error);
724
725 if (error) {
726 ex_close(exoid);
727 exit(-1);
728 }
729
730 error = ex_put_attr(exoid, EX_NODE_SET, nsids[0], x);
731 if (error) {
732 ex_close(exoid);
733 exit(-1);
734 }
735
736 {
737 attrib_names[0] = "Nodeset_attribute";
738 error = ex_put_attr_names(exoid, EX_NODE_SET, nsids[0], attrib_names);
739 if (error) {
740 ex_close(exoid);
741 exit(-1);
742 }
743 }
744
745 /* write individual side sets */
746 num_face_in_sset[0] = 2;
747 num_face_in_sset[1] = 2;
748 num_face_in_sset[2] = 7;
749 num_face_in_sset[3] = 8;
750 num_face_in_sset[4] = 10;
751
752 ssids[0] = 30;
753 ssids[1] = 31;
754 ssids[2] = 32;
755 ssids[3] = 33;
756 ssids[4] = 34;
757
758 /* side set #1 - quad */
759
760 error = ex_put_set_param(exoid, EX_SIDE_SET, ssids[0], 2, 4);
761 printf("after ex_put_side_set_param, error = %d\n", error);
762
763 if (error) {
764 ex_close(exoid);
765 exit(-1);
766 }
767
768 elem_list[0] = 2;
769 elem_list[1] = 2;
770
771 side_list[0] = 4;
772 side_list[1] = 2;
773
774 dist_fact[0] = 30.0;
775 dist_fact[1] = 30.1;
776 dist_fact[2] = 30.2;
777 dist_fact[3] = 30.3;
778
779 error = ex_put_set(exoid, EX_SIDE_SET, 30, elem_list, side_list);
780 printf("after ex_put_side_set, error = %d\n", error);
781
782 if (error) {
783 ex_close(exoid);
784 exit(-1);
785 }
786
787 error = ex_put_set_dist_fact(exoid, EX_SIDE_SET, 30, dist_fact);
788 printf("after ex_put_side_set_dist_fact, error = %d\n", error);
789
790 if (error) {
791 ex_close(exoid);
792 exit(-1);
793 }
794
795 /* side set #2 - quad, spanning 2 elements */
796
797 error = ex_put_set_param(exoid, EX_SIDE_SET, 31, 2, 4);
798 printf("after ex_put_side_set_param, error = %d\n", error);
799
800 if (error) {
801 ex_close(exoid);
802 exit(-1);
803 }
804
805 elem_list[0] = 1;
806 elem_list[1] = 2;
807
808 side_list[0] = 2;
809 side_list[1] = 3;
810
811 dist_fact[0] = 31.0;
812 dist_fact[1] = 31.1;
813 dist_fact[2] = 31.2;
814 dist_fact[3] = 31.3;
815
816 error = ex_put_set(exoid, EX_SIDE_SET, 31, elem_list, side_list);
817 printf("after ex_put_side_set, error = %d\n", error);
818
819 if (error) {
820 ex_close(exoid);
821 exit(-1);
822 }
823
824 error = ex_put_set_dist_fact(exoid, EX_SIDE_SET, 31, dist_fact);
825 printf("after ex_put_side_set_dist_fact, error = %d\n", error);
826
827 if (error) {
828 ex_close(exoid);
829 exit(-1);
830 }
831
832 /* side set #3 - hex */
833
834 error = ex_put_set_param(exoid, EX_SIDE_SET, 32, 7, 0);
835 printf("after ex_put_side_set_param, error = %d\n", error);
836
837 if (error) {
838 ex_close(exoid);
839 exit(-1);
840 }
841
842 elem_list[0] = 3;
843 elem_list[1] = 3;
844 elem_list[2] = 3;
845 elem_list[3] = 3;
846 elem_list[4] = 3;
847 elem_list[5] = 3;
848 elem_list[6] = 3;
849
850 side_list[0] = 5;
851 side_list[1] = 3;
852 side_list[2] = 3;
853 side_list[3] = 2;
854 side_list[4] = 4;
855 side_list[5] = 1;
856 side_list[6] = 6;
857
858 error = ex_put_set(exoid, EX_SIDE_SET, 32, elem_list, side_list);
859 printf("after ex_put_side_set, error = %d\n", error);
860
861 if (error) {
862 ex_close(exoid);
863 exit(-1);
864 }
865
866 /* side set #4 - tetras */
867
868 error = ex_put_set_param(exoid, EX_SIDE_SET, 33, 8, 0);
869 printf("after ex_put_side_set_param, error = %d\n", error);
870
871 if (error) {
872 ex_close(exoid);
873 exit(-1);
874 }
875
876 elem_list[0] = 4;
877 elem_list[1] = 4;
878 elem_list[2] = 4;
879 elem_list[3] = 4;
880 elem_list[4] = 6;
881 elem_list[5] = 6;
882 elem_list[6] = 6;
883 elem_list[7] = 6;
884
885 side_list[0] = 1;
886 side_list[1] = 2;
887 side_list[2] = 3;
888 side_list[3] = 4;
889 side_list[4] = 1;
890 side_list[5] = 2;
891 side_list[6] = 3;
892 side_list[7] = 4;
893
894 error = ex_put_set(exoid, EX_SIDE_SET, 33, elem_list, side_list);
895 printf("after ex_put_side_set, error = %d\n", error);
896
897 if (error) {
898 ex_close(exoid);
899 exit(-1);
900 }
901
902 /* side set #5 - wedges and tris */
903
904 error = ex_put_set_param(exoid, EX_SIDE_SET, 34, 10, 0);
905 printf("after ex_put_side_set_param, error = %d\n", error);
906
907 if (error) {
908 ex_close(exoid);
909 exit(-1);
910 }
911
912 elem_list[0] = 5;
913 elem_list[1] = 5;
914 elem_list[2] = 5;
915 elem_list[3] = 5;
916 elem_list[4] = 5;
917 elem_list[5] = 7;
918 elem_list[6] = 7;
919 elem_list[7] = 7;
920 elem_list[8] = 7;
921 elem_list[9] = 7;
922
923 side_list[0] = 1;
924 side_list[1] = 2;
925 side_list[2] = 3;
926 side_list[3] = 4;
927 side_list[4] = 5;
928 side_list[5] = 1;
929 side_list[6] = 2;
930 side_list[7] = 3;
931 side_list[8] = 4;
932 side_list[9] = 5;
933
934 error = ex_put_set(exoid, EX_SIDE_SET, 34, elem_list, side_list);
935 printf("after ex_put_side_set, error = %d\n", error);
936
937 if (error) {
938 ex_close(exoid);
939 exit(-1);
940 }
941
942 /* Write side set names */
943 sset_names[0] = "sset_1";
944 sset_names[1] = "sset_2";
945 sset_names[2] = "sset_3";
946 sset_names[3] = "sset_4";
947 sset_names[4] = "sset_5";
948
949 error = ex_put_names(exoid, EX_SIDE_SET, sset_names);
950 printf("after ex_put_names, error = %d\n", error);
951
952 if (error) {
953 ex_close(exoid);
954 exit(-1);
955 }
956
957 error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
958 printf("after ex_put_prop, error = %d\n", error);
959
960 if (error) {
961 ex_close(exoid);
962 exit(-1);
963 }
964
965 error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
966 printf("after ex_put_prop, error = %d\n", error);
967
968 if (error) {
969 ex_close(exoid);
970 exit(-1);
971 }
972
973 /* write QA records; test empty and just blank-filled records */
974
975 num_qa_rec = 2;
976
977 qa_record[0][0] = "TESTWT";
978 qa_record[0][1] = "testwt";
979 qa_record[0][2] = "07/07/93";
980 qa_record[0][3] = "15:41:33";
981 qa_record[1][0] = "";
982 qa_record[1][1] = " ";
983 qa_record[1][2] = "";
984 qa_record[1][3] = " ";
985
986 error = ex_put_qa(exoid, num_qa_rec, qa_record);
987 printf("after ex_put_qa, error = %d\n", error);
988
989 if (error) {
990 ex_close(exoid);
991 exit(-1);
992 }
993
994 /* write information records; test empty and just blank-filled records */
995
996 num_info = 3;
997
998 info[0] = "This is the first information record.";
999 info[1] = "";
1000 info[2] = " ";
1001
1002 error = ex_put_info(exoid, num_info, info);
1003 printf("after ex_put_info, error = %d\n", error);
1004
1005 if (error) {
1006 ex_close(exoid);
1007 exit(-1);
1008 }
1009
1010 /* write results variables parameters and names */
1011
1012 num_glo_vars = 1;
1013
1014 variable_names[0] = "glo_vars";
1015
1016 error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars);
1017 printf("after ex_put_variable_param, error = %d\n", error);
1018 if (error) {
1019 ex_close(exoid);
1020 exit(-1);
1021 }
1022
1023 error = ex_put_variable_names(exoid, EX_GLOBAL, num_glo_vars, variable_names);
1024 printf("after ex_put_variable_names, error = %d\n", error);
1025 if (error) {
1026 ex_close(exoid);
1027 exit(-1);
1028 }
1029
1030 num_nod_vars = 2;
1031 /* 0 1 2 3 4 5 6 */
1032 /* 1234567890123456789012345678901234567890123456789012345678901234 */
1033 variable_names[0] = "node_variable_a_somewhat_long_name_0";
1034 variable_names[1] = "node_variable_a_much_longer_name_that_is_not_too_long_name";
1035
1036 error = ex_put_variable_param(exoid, EX_NODAL, num_nod_vars);
1037 printf("after ex_put_variable_param, error = %d\n", error);
1038 if (error) {
1039 ex_close(exoid);
1040 exit(-1);
1041 }
1042
1043 error = ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, variable_names);
1044 printf("after ex_put_variable_names, error = %d\n", error);
1045 if (error) {
1046 ex_close(exoid);
1047 exit(-1);
1048 }
1049
1050 num_ele_vars = 3;
1051
1052 /* 0 1 2 3 4 5 6 */
1053 /* 1234567890123456789012345678901234567890123456789012345678901234 */
1054 variable_names[0] = "the_stress_on_the_elements_in_this_block_that_are_active_now";
1055 variable_names[1] = "ele_var1";
1056 variable_names[2] = "ele_var2";
1057
1058 error = ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars);
1059 printf("after ex_put_variable_param, error = %d\n", error);
1060 if (error) {
1061 ex_close(exoid);
1062 exit(-1);
1063 }
1064
1065 error = ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, variable_names);
1066 printf("after ex_put_variable_names, error = %d\n", error);
1067 if (error) {
1068 ex_close(exoid);
1069 exit(-1);
1070 }
1071
1072 {
1073 num_nset_vars = 3;
1074
1075 variable_names[0] = "ns_var0";
1076 variable_names[1] = "ns_var1";
1077 variable_names[2] = "ns_var2";
1078
1079 error = ex_put_variable_param(exoid, EX_NODE_SET, num_nset_vars);
1080 printf("after ex_put_variable_param, error = %d\n", error);
1081 if (error) {
1082 ex_close(exoid);
1083 exit(-1);
1084 }
1085
1086 error = ex_put_variable_names(exoid, EX_NODE_SET, num_nset_vars, variable_names);
1087 printf("after ex_put_variable_names, error = %d\n", error);
1088 if (error) {
1089 ex_close(exoid);
1090 exit(-1);
1091 }
1092 }
1093
1094 {
1095 num_sset_vars = 3;
1096
1097 variable_names[0] = "ss_var0";
1098 variable_names[1] = "ss_var1";
1099 variable_names[2] = "ss_var2";
1100
1101 error = ex_put_variable_param(exoid, EX_SIDE_SET, num_sset_vars);
1102 printf("after ex_put_variable_param, error = %d\n", error);
1103 if (error) {
1104 ex_close(exoid);
1105 exit(-1);
1106 }
1107
1108 error = ex_put_variable_names(exoid, EX_SIDE_SET, num_sset_vars, variable_names);
1109 printf("after ex_put_variable_names, error = %d\n", error);
1110 if (error) {
1111 ex_close(exoid);
1112 exit(-1);
1113 }
1114 }
1115
1116 /* write element variable truth table */
1117
1118 truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int));
1119
1120 k = 0;
1121 for (i = 0; i < num_elem_blk; i++) {
1122 for (j = 0; j < num_ele_vars; j++) {
1123 truth_tab[k++] = 1;
1124 }
1125 }
1126
1127 error = ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab);
1128 printf("after ex_put_elem_var_tab, error = %d\n", error);
1129
1130 if (error) {
1131 ex_close(exoid);
1132 exit(-1);
1133 }
1134
1135 free(truth_tab);
1136
1137 /* for each time step, write the analysis results;
1138 * the code below fills the arrays glob_var_vals,
1139 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
1140 * obviously the analysis code will populate these arrays
1141 */
1142
1143 whole_time_step = 1;
1144 num_time_steps = 10;
1145
1146 glob_var_vals = (float *)calloc(num_glo_vars, CPU_word_size);
1147 nodal_var_vals = (float *)calloc(num_nodes, CPU_word_size);
1148 elem_var_vals = (float *)calloc(4, CPU_word_size);
1149 sset_var_vals = (float *)calloc(10, CPU_word_size);
1150 nset_var_vals = (float *)calloc(10, CPU_word_size);
1151
1152 for (i = 0; i < num_time_steps; i++) {
1153 time_value = (float)(i + 1) / 100.;
1154
1155 /* write time value */
1156
1157 error = ex_put_time(exoid, whole_time_step, &time_value);
1158 printf("after ex_put_time, error = %d\n", error);
1159
1160 if (error) {
1161 ex_close(exoid);
1162 exit(-1);
1163 }
1164
1165 /* write global variables */
1166
1167 for (j = 0; j < num_glo_vars; j++) {
1168 glob_var_vals[j] = (float)(j + 2) * time_value;
1169 }
1170
1171 error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
1172 printf("after ex_put_glob_vars, error = %d\n", error);
1173
1174 if (error) {
1175 ex_close(exoid);
1176 exit(-1);
1177 }
1178
1179 /* write nodal variables */
1180
1181 for (k = 1; k <= num_nod_vars; k++) {
1182 for (j = 0; j < num_nodes; j++) {
1183 nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value);
1184 }
1185
1186 error = ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals);
1187 printf("after ex_put_nodal_var, error = %d\n", error);
1188 if (error) {
1189 ex_close(exoid);
1190 exit(-1);
1191 }
1192 }
1193
1194 /* write element variables */
1195
1196 for (k = 1; k <= num_ele_vars; k++) {
1197 for (j = 0; j < num_elem_blk; j++) {
1198 for (m = 0; m < num_elem_in_block[j]; m++) {
1199 elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value);
1200 /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
1201 }
1202 error = ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j],
1203 elem_var_vals);
1204 printf("after ex_put_elem_var, error = %d\n", error);
1205 if (error) {
1206 ex_close(exoid);
1207 exit(-1);
1208 }
1209 }
1210 }
1211
1212 /* write sideset variables */
1213
1214 for (k = 1; k <= num_sset_vars; k++) {
1215 for (j = 0; j < num_side_sets; j++) {
1216 for (m = 0; m < num_face_in_sset[j]; m++) {
1217 sset_var_vals[m] = (float)(k + 2) + (float)(j + 3) + ((float)(m + 1) * time_value);
1218 /* printf("sset_var_vals[%d]: %f\n",m,sset_var_vals[m]); */
1219 }
1220 error = ex_put_var(exoid, whole_time_step, EX_SIDE_SET, k, ssids[j], num_face_in_sset[j],
1221 sset_var_vals);
1222 printf("after ex_put_sset_var, error = %d\n", error);
1223 if (error) {
1224 ex_close(exoid);
1225 exit(-1);
1226 }
1227 }
1228 }
1229
1230 /* write nodeset variables */
1231
1232 for (k = 1; k <= num_nset_vars; k++) {
1233 for (j = 0; j < num_node_sets; j++) {
1234 for (m = 0; m < num_nodes_in_nset[j]; m++) {
1235 nset_var_vals[m] = (float)(k + 3) + (float)(j + 4) + ((float)(m + 1) * time_value);
1236 /* printf("nset_var_vals[%d]: %f\n",m,nset_var_vals[m]); */
1237 }
1238 error = ex_put_var(exoid, whole_time_step, EX_NODE_SET, k, nsids[j], num_nodes_in_nset[j],
1239 nset_var_vals);
1240 printf("after ex_put_nset_var, error = %d\n", error);
1241 if (error) {
1242 ex_close(exoid);
1243 exit(-1);
1244 }
1245 }
1246 }
1247
1248 whole_time_step++;
1249
1250 /* update the data file; this should be done at the end of every time step
1251 * to ensure that no data is lost if the analysis dies
1252 */
1253 error = ex_update(exoid);
1254 printf("after ex_update, error = %d\n", error);
1255 if (error) {
1256 ex_close(exoid);
1257 exit(-1);
1258 }
1259 }
1260 free(glob_var_vals);
1261 free(nodal_var_vals);
1262 free(elem_var_vals);
1263 free(sset_var_vals);
1264 free(nset_var_vals);
1265
1266 /* close the EXODUS files
1267 */
1268 error = ex_close(exoid);
1269 printf("after ex_close, error = %d\n", error);
1270 if (error) {
1271 ex_close(exoid);
1272 exit(-1);
1273 }
1274 return 0;
1275 }