Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2022 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
11 *
12 * This is a test program for the C binding of the EXODUS II
13 * database write routines.
14 *
15 *****************************************************************************/
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20
21 #include "exodusII.h"
22 #include "exodusII_int.h"
23
24 #define STRINGIFY(x) #x
25 #define TOSTRING(x) STRINGIFY(x)
26
27 #define EXCHECK(funcall) \
28 do { \
29 int f_error = (funcall); \
30 printf("after %s, error = %d\n", TOSTRING(funcall), f_error); \
31 if (f_error != EX_NOERR && f_error != EX_WARN) { \
32 fprintf(stderr, "Error calling %s\n", TOSTRING(funcall)); \
33 ex_close(exoid); \
34 exit(-1); \
35 } \
36 } while (0)
37
38 int main(int argc, char **argv)
39 {
40 ex_opts(EX_VERBOSE);
41
42 /* Specify compute and i/o word size */
43 int CPU_word_size = 0; /* sizeof(float) */
44 int IO_word_size = 4; /* (4 bytes) */
45
46 /* create EXODUS II file */
47 int 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 /* initialize file with parameters */
55 int num_dim = 3;
56 int num_nodes = 33;
57 int num_elem = 7;
58 int num_elem_blk = 7;
59 int num_node_sets = 2;
60 int num_side_sets = 5;
61
62 char *title = "This is a test";
63 EXCHECK(ex_put_init(exoid, title, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets,
64 num_side_sets));
65
66 /* clang-format off */
67 /* write nodal coordinates values and names to database */
68
69 /* Quad #1 */
70 float x[100], y[100], z[100];
71 x[0] = 0.0; y[0] = 0.0; z[0] = 0.0;
72 x[1] = 1.0; y[1] = 0.0; z[1] = 0.0;
73 x[2] = 1.0; y[2] = 1.0; z[2] = 0.0;
74 x[3] = 0.0; y[3] = 1.0; z[3] = 0.0;
75
76 /* Quad #2 */
77 x[4] = 1.0; y[4] = 0.0; z[4] = 0.0;
78 x[5] = 2.0; y[5] = 0.0; z[5] = 0.0;
79 x[6] = 2.0; y[6] = 1.0; z[6] = 0.0;
80 x[7] = 1.0; y[7] = 1.0; z[7] = 0.0;
81
82 /* Hex #1 */
83 x[8] = 0.0; y[8] = 0.0; z[8] = 0.0;
84 x[9] = 10.0; y[9] = 0.0; z[9] = 0.0;
85 x[10] = 10.0; y[10] = 0.0; z[10] = -10.0;
86 x[11] = 1.0; y[11] = 0.0; z[11] = -10.0;
87 x[12] = 1.0; y[12] = 10.0; z[12] = 0.0;
88 x[13] = 10.0; y[13] = 10.0; z[13] = 0.0;
89 x[14] = 10.0; y[14] = 10.0; z[14] = -10.0;
90 x[15] = 1.0; y[15] = 10.0; z[15] = -10.0;
91
92 /* Tetra #1 */
93 x[16] = 0.0; y[16] = 0.0; z[16] = 0.0;
94 x[17] = 1.0; y[17] = 0.0; z[17] = 5.0;
95 x[18] = 10.0; y[18] = 0.0; z[18] = 2.0;
96 x[19] = 7.0; y[19] = 5.0; z[19] = 3.0;
97
98 /* Wedge #1 */
99 x[20] = 3.0; y[20] = 0.0; z[20] = 6.0;
100 x[21] = 6.0; y[21] = 0.0; z[21] = 0.0;
101 x[22] = 0.0; y[22] = 0.0; z[22] = 0.0;
102 x[23] = 3.0; y[23] = 2.0; z[23] = 6.0;
103 x[24] = 6.0; y[24] = 2.0; z[24] = 2.0;
104 x[25] = 0.0; y[25] = 2.0; z[25] = 0.0;
105
106 /* Tetra #2 */
107 x[26] = 2.7; y[26] = 1.7; z[26] = 2.7;
108 x[27] = 6.0; y[27] = 1.7; z[27] = 3.3;
109 x[28] = 5.7; y[28] = 1.7; z[28] = 1.7;
110 x[29] = 3.7; y[29] = 0.0; z[29] = 2.3;
111
112 /* 3d Tri */
113 x[30] = 0.0; y[30] = 0.0; z[30] = 0.0;
114 x[31] = 10.0; y[31] = 0.0; z[31] = 0.0;
115 x[32] = 10.0; y[32] = 10.0; z[32] = 10.0;
116 /* clang-format on */
117
118 EXCHECK(ex_put_coord(exoid, x, y, z));
119
120 char *coord_names[] = {"xcoor", "ycoor", "zcoor"};
121 EXCHECK(ex_put_coord_names(exoid, coord_names));
122
123 /* Add nodal attributes */
124 EXCHECK(ex_put_attr_param(exoid, EX_NODAL, 0, 2));
125 EXCHECK(ex_put_one_attr(exoid, EX_NODAL, 0, 1, x));
126 EXCHECK(ex_put_one_attr(exoid, EX_NODAL, 0, 2, y));
127
128 {
129 char *attrib_names[] = {"Node_attr_1", "Node_attr_2"};
130 EXCHECK(ex_put_attr_names(exoid, EX_NODAL, 0, attrib_names));
131 }
132
133 /* write element id map */
134 int *elem_map = (int *)calloc(num_elem, sizeof(int));
135 for (int i = 1; i <= num_elem; i++) {
136 elem_map[i - 1] = i * 10;
137 }
138
139 EXCHECK(ex_put_id_map(exoid, EX_ELEM_MAP, elem_map));
140
141 free(elem_map);
142
143 /* write element block parameters */
144 struct ex_block blocks[10];
145 for (int i = 0; i < 10; i++) {
146 blocks[i].type = EX_ELEM_BLOCK;
147 blocks[i].id = 0;
148 blocks[i].num_entry = 0;
149 blocks[i].num_nodes_per_entry = 0;
150 blocks[i].num_edges_per_entry = 0;
151 blocks[i].num_faces_per_entry = 0;
152 blocks[i].num_attribute = 0;
153 }
154
155 char *block_names[10];
156 block_names[0] = "block_1";
157 block_names[1] = "block_2";
158 block_names[2] = "block_3";
159 block_names[3] = "block_4";
160 block_names[4] = "block_5";
161 block_names[5] = "block_6";
162 block_names[6] = "block_7";
163
164 ex_copy_string(blocks[0].topology, "quad", MAX_STR_LENGTH + 1);
165 ex_copy_string(blocks[1].topology, "quad", MAX_STR_LENGTH + 1);
166 ex_copy_string(blocks[2].topology, "hex", MAX_STR_LENGTH + 1);
167 ex_copy_string(blocks[3].topology, "tetra", MAX_STR_LENGTH + 1);
168 ex_copy_string(blocks[4].topology, "wedge", MAX_STR_LENGTH + 1);
169 ex_copy_string(blocks[5].topology, "tetra", MAX_STR_LENGTH + 1);
170 ex_copy_string(blocks[6].topology, "tri", MAX_STR_LENGTH + 1);
171
172 blocks[0].num_entry = 1;
173 blocks[1].num_entry = 1;
174 blocks[2].num_entry = 1;
175 blocks[3].num_entry = 1;
176 blocks[4].num_entry = 1;
177 blocks[5].num_entry = 1;
178 blocks[6].num_entry = 1;
179
180 blocks[0].num_attribute = 1;
181 blocks[1].num_attribute = 1;
182 blocks[2].num_attribute = 1;
183 blocks[3].num_attribute = 1;
184 blocks[4].num_attribute = 1;
185 blocks[5].num_attribute = 1;
186 blocks[6].num_attribute = 1;
187
188 blocks[0].num_nodes_per_entry = 4; /* elements in block #1 are 4-node quads */
189 blocks[1].num_nodes_per_entry = 4; /* elements in block #2 are 4-node quads */
190 blocks[2].num_nodes_per_entry = 8; /* elements in block #3 are 8-node hexes */
191 blocks[3].num_nodes_per_entry = 4; /* elements in block #4 are 4-node tetras */
192 blocks[4].num_nodes_per_entry = 6; /* elements in block #5 are 6-node wedges */
193 blocks[5].num_nodes_per_entry = 8; /* elements in block #6 are 8-node tetras */
194 blocks[6].num_nodes_per_entry = 3; /* elements in block #7 are 3-node tris */
195
196 blocks[0].id = 10;
197 blocks[1].id = 11;
198 blocks[2].id = 12;
199 blocks[3].id = 13;
200 blocks[4].id = 14;
201 blocks[5].id = 15;
202 blocks[6].id = 16;
203
204 /* Generate an error that name is not found since blocks have not
205 yet been defined
206 */
207 int error = ex_put_name(exoid, EX_ELEM_BLOCK, blocks[0].id, block_names[0]);
208 printf("after ex_put_name, error = %d\n", error);
209
210 EXCHECK(ex_put_block_params(exoid, num_elem_blk, blocks));
211
212 /* Write element block names */
213 for (int i = 0; i < num_elem_blk; i++) {
214 EXCHECK(ex_put_name(exoid, EX_ELEM_BLOCK, blocks[i].id, block_names[i]));
215 }
216
217 /* write element block properties */
218 /* 12345678901234567890123456789012 */
219 char *prop_names[2];
220 prop_names[0] = "MATERIAL_PROPERTY_LONG_NAME_32CH";
221 prop_names[1] = "DENSITY";
222
223 EXCHECK(ex_put_prop_names(exoid, EX_ELEM_BLOCK, 2, prop_names));
224 EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, blocks[0].id, prop_names[0], 10));
225 EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, blocks[1].id, prop_names[0], 20));
226 EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, blocks[2].id, prop_names[0], 30));
227 EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, blocks[3].id, prop_names[0], 40));
228 EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, blocks[4].id, prop_names[0], 50));
229 EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, blocks[5].id, prop_names[0], 60));
230 EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, blocks[6].id, prop_names[0], 70));
231
232 /* write element connectivity */
233 {
234 int connect[] = {1, 2, 3, 4};
235 EXCHECK(ex_put_conn(exoid, EX_ELEM_BLOCK, blocks[0].id, connect, NULL, NULL));
236 }
237
238 {
239 int connect[] = {5, 6, 7, 8};
240 EXCHECK(ex_put_conn(exoid, EX_ELEM_BLOCK, blocks[1].id, connect, NULL, NULL));
241 }
242
243 {
244 int connect[] = {9, 10, 11, 12, 13, 14, 15, 16};
245 EXCHECK(ex_put_conn(exoid, EX_ELEM_BLOCK, blocks[2].id, connect, NULL, NULL));
246 }
247
248 {
249 int connect[] = {17, 18, 19, 20};
250 EXCHECK(ex_put_conn(exoid, EX_ELEM_BLOCK, blocks[3].id, connect, NULL, NULL));
251 }
252
253 {
254 int connect[] = {21, 22, 23, 24, 25, 26};
255 EXCHECK(ex_put_conn(exoid, EX_ELEM_BLOCK, blocks[4].id, connect, NULL, NULL));
256 }
257
258 {
259 int connect[] = {17, 18, 19, 20, 27, 28, 30, 29};
260 EXCHECK(ex_put_conn(exoid, EX_ELEM_BLOCK, blocks[5].id, connect, NULL, NULL));
261 }
262
263 {
264 int connect[] = {31, 32, 33};
265 EXCHECK(ex_put_conn(exoid, EX_ELEM_BLOCK, blocks[6].id, connect, NULL, NULL));
266 }
267
268 /* write element block attributes */
269 float attrib[1];
270 attrib[0] = 3.14159;
271 EXCHECK(ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[0].id, attrib));
272 EXCHECK(ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[0].id, attrib));
273
274 attrib[0] = 6.14159;
275 EXCHECK(ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[1].id, attrib));
276 EXCHECK(ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[2].id, attrib));
277 EXCHECK(ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[3].id, attrib));
278 EXCHECK(ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[4].id, attrib));
279 EXCHECK(ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[5].id, attrib));
280 EXCHECK(ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[6].id, attrib));
281
282 {
283 char *attrib_names[] = {"THICKNESS"};
284 for (int i = 0; i < num_elem_blk; i++) {
285 EXCHECK(ex_put_attr_names(exoid, EX_ELEM_BLOCK, blocks[i].id, attrib_names));
286 }
287 }
288
289 /* write individual node sets */
290 int num_nodes_in_nset[] = {5, 3};
291 int nsids[] = {20, 21};
292
293 {
294 EXCHECK(ex_put_set_param(exoid, EX_NODE_SET, nsids[0], 5, 5));
295
296 int node_list[] = {10, 11, 12, 13, 14};
297 float dist_fact[] = {1.0, 2.0, 3.0, 4.0, 5.0};
298
299 EXCHECK(ex_put_set(exoid, EX_NODE_SET, nsids[0], node_list, NULL));
300 EXCHECK(ex_put_set_dist_fact(exoid, EX_NODE_SET, nsids[0], dist_fact));
301 }
302
303 {
304 EXCHECK(ex_put_set_param(exoid, EX_NODE_SET, nsids[1], 3, 3));
305
306 int node_list[] = {20, 21, 22};
307 float dist_fact[] = {1.1, 2.1, 3.1};
308
309 EXCHECK(ex_put_set(exoid, EX_NODE_SET, nsids[1], node_list, NULL));
310 EXCHECK(ex_put_set_dist_fact(exoid, EX_NODE_SET, nsids[1], dist_fact));
311 }
312
313 /* Write node set names */
314 char *nset_names[] = {"nset_1", "nset_2"};
315 EXCHECK(ex_put_names(exoid, EX_NODE_SET, nset_names));
316 EXCHECK(ex_put_prop(exoid, EX_NODE_SET, nsids[0], "FACE", 4));
317 EXCHECK(ex_put_prop(exoid, EX_NODE_SET, nsids[1], "FACE", 5));
318
319 int prop_array[] = {1000, 2000};
320 EXCHECK(ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array));
321
322 /* Add nodeset attributes */
323 EXCHECK(ex_put_attr_param(exoid, EX_NODE_SET, nsids[0], 1));
324 EXCHECK(ex_put_attr(exoid, EX_NODE_SET, nsids[0], x));
325
326 {
327 char *attrib_names[] = {"Nodeset_attribute"};
328 EXCHECK(ex_put_attr_names(exoid, EX_NODE_SET, nsids[0], attrib_names));
329 }
330
331 /* write individual side sets */
332 int num_face_in_sset[] = {2, 2, 7, 8, 10};
333 int ssids[] = {30, 31, 32, 33, 34};
334
335 {
336 /* side set #1 - quad */
337 EXCHECK(ex_put_set_param(exoid, EX_SIDE_SET, ssids[0], 2, 4));
338
339 int elem_list[] = {2, 2};
340 int side_list[] = {4, 2};
341 float dist_fact[] = {30.0, 30.1, 30.2, 30.3};
342
343 EXCHECK(ex_put_set(exoid, EX_SIDE_SET, 30, elem_list, side_list));
344 EXCHECK(ex_put_set_dist_fact(exoid, EX_SIDE_SET, 30, dist_fact));
345 }
346
347 {
348 /* side set #2 - quad, spanning 2 elements */
349 EXCHECK(ex_put_set_param(exoid, EX_SIDE_SET, 31, 2, 4));
350
351 int elem_list[] = {1, 2};
352 int side_list[] = {2, 3};
353 float dist_fact[] = {31.0, 31.1, 31.2, 31.3};
354
355 EXCHECK(ex_put_set(exoid, EX_SIDE_SET, 31, elem_list, side_list));
356 EXCHECK(ex_put_set_dist_fact(exoid, EX_SIDE_SET, 31, dist_fact));
357 }
358
359 {
360 /* side set #3 - hex */
361 EXCHECK(ex_put_set_param(exoid, EX_SIDE_SET, 32, 7, 0));
362
363 int elem_list[] = {3, 3, 3, 3, 3, 3, 3};
364 int side_list[] = {5, 3, 3, 2, 4, 1, 6};
365
366 EXCHECK(ex_put_set(exoid, EX_SIDE_SET, 32, elem_list, side_list));
367 }
368
369 {
370 /* side set #4 - tetras */
371 EXCHECK(ex_put_set_param(exoid, EX_SIDE_SET, 33, 8, 0));
372
373 int elem_list[] = {4, 4, 4, 4, 6, 6, 6, 6};
374 int side_list[] = {1, 2, 3, 4, 1, 2, 3, 4};
375
376 EXCHECK(ex_put_set(exoid, EX_SIDE_SET, 33, elem_list, side_list));
377 }
378
379 {
380 /* side set #5 - wedges and tris */
381 EXCHECK(ex_put_set_param(exoid, EX_SIDE_SET, 34, 10, 0));
382
383 int elem_list[] = {5, 5, 5, 5, 5, 7, 7, 7, 7, 7};
384 int side_list[] = {1, 2, 3, 4, 5, 1, 2, 3, 4, 5};
385
386 EXCHECK(ex_put_set(exoid, EX_SIDE_SET, 34, elem_list, side_list));
387 }
388
389 /* Write side set names */
390 char *sset_names[] = {"sset_1", "sset_2", "sset_3", "sset_4", "sset_5"};
391 EXCHECK(ex_put_names(exoid, EX_SIDE_SET, sset_names));
392 EXCHECK(ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100));
393 EXCHECK(ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101));
394
395 /* write QA records; test empty and just blank-filled records */
396 int num_qa_rec = 2;
397 char *qa_record[2][4];
398 qa_record[0][0] = "TESTWT";
399 qa_record[0][1] = "testwt";
400 qa_record[0][2] = "07/07/93";
401 qa_record[0][3] = "15:41:33";
402 qa_record[1][0] = "Thirty-Two character QA Record|";
403 qa_record[1][1] = " ";
404 qa_record[1][2] = "";
405 qa_record[1][3] = " ";
406
407 EXCHECK(ex_put_qa(exoid, num_qa_rec, qa_record));
408
409 /* write information records; test empty and just blank-filled records */
410 char *info[3];
411 info[0] = "This is the first information record.";
412 info[1] = "";
413 info[2] = "This info record is exactly 80 characters long. last character should be pipe |";
414
415 int num_info = 3;
416 EXCHECK(ex_put_info(exoid, num_info, info));
417
418 /* write results variables parameters and names */
419 int num_glo_vars = 1;
420 {
421 char *var_names[] = {"glo_vars"};
422
423 EXCHECK(ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars));
424 EXCHECK(ex_put_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names));
425 }
426
427 int num_nod_vars = 2;
428 {
429 /* 12345678901234567890123456789012 */
430 char *var_names[] = {"node_variable_a_very_long_name_0", "nod_var1"};
431
432 EXCHECK(ex_put_variable_param(exoid, EX_NODAL, num_nod_vars));
433 EXCHECK(ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names));
434 }
435
436 int num_ele_vars = 3;
437 {
438 /* 0 1 2 3 */
439 /* 12345678901234567890123456789012 */
440 char *var_names[] = {"this_variable_name_is_short", "this_variable_name_is_just_right",
441 "this_variable_name_is_tooooo_long"};
442
443 EXCHECK(ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars));
444 EXCHECK(ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names));
445 }
446
447 int num_nset_vars = 3;
448 {
449 char *var_names[] = {"ns_var0", "ns_var1", "ns_var2"};
450
451 EXCHECK(ex_put_variable_param(exoid, EX_NODE_SET, num_nset_vars));
452 EXCHECK(ex_put_variable_names(exoid, EX_NODE_SET, num_nset_vars, var_names));
453 }
454
455 int num_sset_vars = 3;
456 {
457 char *var_names[] = {"ss_var0", "ss_var1", "ss_var2"};
458
459 EXCHECK(ex_put_variable_param(exoid, EX_SIDE_SET, num_sset_vars));
460 EXCHECK(ex_put_variable_names(exoid, EX_SIDE_SET, num_sset_vars, var_names));
461 }
462
463 /* write element variable truth table */
464 int *truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int));
465
466 {
467 int k = 0;
468 for (int i = 0; i < num_elem_blk; i++) {
469 for (int j = 0; j < num_ele_vars; j++) {
470 truth_tab[k++] = 1;
471 }
472 }
473 }
474
475 EXCHECK(ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab));
476
477 free(truth_tab);
478
479 /* for each time step, write the analysis results;
480 * the code below fills the arrays glob_var_vals,
481 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
482 * obviously the analysis code will populate these arrays
483 */
484
485 float *glob_var_vals = (float *)calloc(num_glo_vars, CPU_word_size);
486 float *nodal_var_vals = (float *)calloc(num_nodes, CPU_word_size);
487 float *elem_var_vals = (float *)calloc(num_ele_vars, CPU_word_size);
488 float *sset_var_vals = (float *)calloc(10, CPU_word_size); /* max sides_in_sset */
489 float *nset_var_vals = (float *)calloc(5, CPU_word_size); /* max nodes_in_nset */
490
491 int num_time_steps = 10;
492 for (int i = 0; i < num_time_steps; i++) {
493 int whole_time_step = i + 1;
494 float time_value = (float)(i + 1) / 100.;
495
496 /* write time value */
497 EXCHECK(ex_put_time(exoid, whole_time_step, &time_value));
498
499 /* write global variables */
500 for (int j = 0; j < num_glo_vars; j++) {
501 glob_var_vals[j] = (float)(j + 2) * time_value;
502 }
503 EXCHECK(ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals));
504
505 /* write nodal variables */
506 for (int k = 1; k <= num_nod_vars; k++) {
507 for (int j = 0; j < num_nodes; j++) {
508 nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value);
509 }
510 EXCHECK(ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals));
511 }
512
513 /* write element variables */
514 for (int k = 1; k <= num_ele_vars; k++) {
515 for (int j = 0; j < num_elem_blk; j++) {
516 for (int m = 0; m < blocks[j].num_entry; m++) {
517 elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value);
518 /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
519 }
520 EXCHECK(ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, blocks[j].id,
521 blocks[j].num_entry, elem_var_vals));
522 }
523 }
524
525 /* write sideset variables */
526 for (int k = 1; k <= num_sset_vars; k++) {
527 for (int j = 0; j < num_side_sets; j++) {
528 for (int m = 0; m < num_face_in_sset[j]; m++) {
529 sset_var_vals[m] = (float)(k + 2) + (float)(j + 3) + ((float)(m + 1) * time_value);
530 /* printf("sset_var_vals[%d]: %f\n",m,sset_var_vals[m]); */
531 }
532 EXCHECK(ex_put_var(exoid, whole_time_step, EX_SIDE_SET, k, ssids[j], num_face_in_sset[j],
533 sset_var_vals));
534 }
535 }
536
537 /* write nodeset variables */
538 for (int k = 1; k <= num_nset_vars; k++) {
539 for (int j = 0; j < num_node_sets; j++) {
540 for (int m = 0; m < num_nodes_in_nset[j]; m++) {
541 nset_var_vals[m] = (float)(k + 3) + (float)(j + 4) + ((float)(m + 1) * time_value);
542 /* printf("nset_var_vals[%d]: %f\n",m,nset_var_vals[m]); */
543 }
544 EXCHECK(ex_put_var(exoid, whole_time_step, EX_NODE_SET, k, nsids[j], num_nodes_in_nset[j],
545 nset_var_vals));
546 }
547 }
548
549 /* update the data file; this should be done at the end of every time step
550 * to ensure that no data is lost if the analysis dies
551 */
552 EXCHECK(ex_update(exoid));
553 }
554 free(glob_var_vals);
555 free(nodal_var_vals);
556 free(elem_var_vals);
557 free(sset_var_vals);
558 free(nset_var_vals);
559
560 /* close the EXODUS files
561 */
562 EXCHECK(ex_close(exoid));
563 return 0;
564 }