Debian Codegraph @

packages/seacas/libraries/exodus/test/testwt-zeroe.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 *
10 * testwt - test write an ExodusII database file
11 *
12 * author - Sandia National Laboratories
13 * Larry A. Schoof - Original
14 * Vic Yarberry - Added headers and error logging
15 * 7/7/93 Modified for use with Exodus 2.00
16 *
17 *
18 * environment - UNIX
19 *
20 * entry conditions -
21 *
22 * exit conditions -
23 *
24 * revision history -
25 *
26 * This is a test program for the C binding of the EXODUS II
27 * database write routines.
28 *
29 *
30 *****************************************************************************/
31
32 #include "exodusII.h"
33 #include <stdio.h>
34 #include <stdlib.h>
35
36 int main(int argc, char **argv)
37 {
38 int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
39 int num_elem_in_block[10];
40 int num_node_sets, num_side_sets, error;
41 int i, j, k, m;
42 int node_list[100];
43 int ebids[10];
44 int num_qa_rec, num_info;
45 int num_glo_vars, num_nod_vars, num_ele_vars;
46 int whole_time_step, num_time_steps;
47 int CPU_word_size, IO_word_size;
48 int prop_array[2];
49
50 float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
51 float time_value;
52 float x[100], y[100], z[100];
53 float dist_fact[100];
54 char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
55
56 ex_opts(EX_VERBOSE | EX_ABORT);
57
58 /* Specify compute and i/o word size */
59
60 CPU_word_size = 0; /* sizeof(float) */
61 IO_word_size = 4; /* (4 bytes) */
62
63 /* create EXODUS II file */
64
65 exoid = ex_create("test.exo", /* filename path */
66 EX_CLOBBER, /* create mode */
67 &CPU_word_size, /* CPU float word size in bytes */
68 &IO_word_size); /* I/O float word size in bytes */
69 printf("after ex_create for test.exo, exoid = %d\n", exoid);
70 printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);
71
72 /* initialize file with parameters */
73
74 num_dim = 3;
75 num_nodes = 33;
76 num_elem = 0;
77 num_elem_blk = 0;
78 num_node_sets = 2;
79 num_side_sets = 0;
80
81 error = ex_put_init(exoid, "This is a test", num_dim, num_nodes, num_elem, num_elem_blk,
82 num_node_sets, num_side_sets);
83
84 printf("after ex_put_init, error = %d\n", error);
85
86 if (error) {
87 ex_close(exoid);
88 exit(-1);
89 }
90
91 /* write nodal coordinates values and names to database */
92
93 /* Quad #1 */
94 x[0] = 0.0;
95 y[0] = 0.0;
96 z[0] = 0.0;
97 x[1] = 1.0;
98 y[1] = 0.0;
99 z[1] = 0.0;
100 x[2] = 1.0;
101 y[2] = 1.0;
102 z[2] = 0.0;
103 x[3] = 0.0;
104 y[3] = 1.0;
105 z[3] = 0.0;
106
107 /* Quad #2 */
108 x[4] = 1.0;
109 y[4] = 0.0;
110 z[4] = 0.0;
111 x[5] = 2.0;
112 y[5] = 0.0;
113 z[5] = 0.0;
114 x[6] = 2.0;
115 y[6] = 1.0;
116 z[6] = 0.0;
117 x[7] = 1.0;
118 y[7] = 1.0;
119 z[7] = 0.0;
120
121 /* Hex #1 */
122 x[8] = 0.0;
123 y[8] = 0.0;
124 z[8] = 0.0;
125 x[9] = 10.0;
126 y[9] = 0.0;
127 z[9] = 0.0;
128 x[10] = 10.0;
129 y[10] = 0.0;
130 z[10] = -10.0;
131 x[11] = 1.0;
132 y[11] = 0.0;
133 z[11] = -10.0;
134 x[12] = 1.0;
135 y[12] = 10.0;
136 z[12] = 0.0;
137 x[13] = 10.0;
138 y[13] = 10.0;
139 z[13] = 0.0;
140 x[14] = 10.0;
141 y[14] = 10.0;
142 z[14] = -10.0;
143 x[15] = 1.0;
144 y[15] = 10.0;
145 z[15] = -10.0;
146
147 /* Tetra #1 */
148 x[16] = 0.0;
149 y[16] = 0.0;
150 z[16] = 0.0;
151 x[17] = 1.0;
152 y[17] = 0.0;
153 z[17] = 5.0;
154 x[18] = 10.0;
155 y[18] = 0.0;
156 z[18] = 2.0;
157 x[19] = 7.0;
158 y[19] = 5.0;
159 z[19] = 3.0;
160
161 /* Wedge #1 */
162 x[20] = 3.0;
163 y[20] = 0.0;
164 z[20] = 6.0;
165 x[21] = 6.0;
166 y[21] = 0.0;
167 z[21] = 0.0;
168 x[22] = 0.0;
169 y[22] = 0.0;
170 z[22] = 0.0;
171 x[23] = 3.0;
172 y[23] = 2.0;
173 z[23] = 6.0;
174 x[24] = 6.0;
175 y[24] = 2.0;
176 z[24] = 2.0;
177 x[25] = 0.0;
178 y[25] = 2.0;
179 z[25] = 0.0;
180
181 /* Tetra #2 */
182 x[26] = 2.7;
183 y[26] = 1.7;
184 z[26] = 2.7;
185 x[27] = 6.0;
186 y[27] = 1.7;
187 z[27] = 3.3;
188 x[28] = 5.7;
189 y[28] = 1.7;
190 z[28] = 1.7;
191 x[29] = 3.7;
192 y[29] = 0.0;
193 z[29] = 2.3;
194
195 /* 3d Tri */
196 x[30] = 0.0;
197 y[30] = 0.0;
198 z[30] = 0.0;
199 x[31] = 10.0;
200 y[31] = 0.0;
201 z[31] = 0.0;
202 x[32] = 10.0;
203 y[32] = 10.0;
204 z[32] = 10.0;
205
206 error = ex_put_coord(exoid, x, y, z);
207 printf("after ex_put_coord, error = %d\n", error);
208
209 if (error) {
210 ex_close(exoid);
211 exit(-1);
212 }
213
214 coord_names[0] = "xcoor";
215 coord_names[1] = "ycoor";
216 coord_names[2] = "zcoor";
217
218 error = ex_put_coord_names(exoid, coord_names);
219 printf("after ex_put_coord_names, error = %d\n", error);
220
221 if (error) {
222 ex_close(exoid);
223 exit(-1);
224 }
225
226 /* write individual node sets */
227
228 error = ex_put_set_param(exoid, EX_NODE_SET, 20, 5, 5);
229 printf("after ex_put_node_set_param, error = %d\n", error);
230
231 if (error) {
232 ex_close(exoid);
233 exit(-1);
234 }
235
236 node_list[0] = 10;
237 node_list[1] = 11;
238 node_list[2] = 12;
239 node_list[3] = 13;
240 node_list[4] = 14;
241
242 dist_fact[0] = 1.0;
243 dist_fact[1] = 2.0;
244 dist_fact[2] = 3.0;
245 dist_fact[3] = 4.0;
246 dist_fact[4] = 5.0;
247
248 error = ex_put_set(exoid, EX_NODE_SET, 20, node_list, NULL);
249 printf("after ex_put_node_set, error = %d\n", error);
250 if (error) {
251 ex_close(exoid);
252 exit(-1);
253 }
254
255 error = ex_put_set_dist_fact(exoid, EX_NODE_SET, 20, dist_fact);
256 printf("after ex_put_node_set_dist_fact, error = %d\n", error);
257 if (error) {
258 ex_close(exoid);
259 exit(-1);
260 }
261
262 error = ex_put_set_param(exoid, EX_NODE_SET, 21, 3, 3);
263 printf("after ex_put_node_set_param, error = %d\n", error);
264
265 if (error) {
266 ex_close(exoid);
267 exit(-1);
268 }
269
270 node_list[0] = 20;
271 node_list[1] = 21;
272 node_list[2] = 22;
273
274 dist_fact[0] = 1.1;
275 dist_fact[1] = 2.1;
276 dist_fact[2] = 3.1;
277
278 error = ex_put_set(exoid, EX_NODE_SET, 21, node_list, NULL);
279 printf("after ex_put_node_set, error = %d\n", error);
280 if (error) {
281 ex_close(exoid);
282 exit(-1);
283 }
284
285 error = ex_put_set_dist_fact(exoid, EX_NODE_SET, 21, dist_fact);
286 printf("after ex_put_node_set_dist_fact, error = %d\n", error);
287 if (error) {
288 ex_close(exoid);
289 exit(-1);
290 }
291
292 error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
293 printf("after ex_put_prop, error = %d\n", error);
294 if (error) {
295 ex_close(exoid);
296 exit(-1);
297 }
298
299 error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
300 printf("after ex_put_prop, error = %d\n", error);
301
302 if (error) {
303 ex_close(exoid);
304 exit(-1);
305 }
306
307 prop_array[0] = 1000;
308 prop_array[1] = 2000;
309
310 error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
311 printf("after ex_put_prop_array, error = %d\n", error);
312 if (error) {
313 ex_close(exoid);
314 exit(-1);
315 }
316
317 /* write QA records; test empty and just blank-filled records */
318
319 num_qa_rec = 2;
320
321 qa_record[0][0] = "TESTWT";
322 qa_record[0][1] = "testwt";
323 qa_record[0][2] = "07/07/93";
324 qa_record[0][3] = "15:41:33";
325 qa_record[1][0] = "";
326 qa_record[1][1] = " ";
327 qa_record[1][2] = "";
328 qa_record[1][3] = " ";
329
330 error = ex_put_qa(exoid, num_qa_rec, qa_record);
331 printf("after ex_put_qa, error = %d\n", error);
332
333 if (error) {
334 ex_close(exoid);
335 exit(-1);
336 }
337
338 /* write information records; test empty and just blank-filled records */
339
340 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
356 num_glo_vars = 1;
357
358 var_names[0] = "glo_vars";
359
360 error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars);
361 printf("after ex_put_variable_param, error = %d\n", error);
362 if (error) {
363 ex_close(exoid);
364 exit(-1);
365 }
366
367 error = ex_put_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names);
368 printf("after ex_put_variable_names, error = %d\n", error);
369 if (error) {
370 ex_close(exoid);
371 exit(-1);
372 }
373
374 num_nod_vars = 2;
375 /* 12345678901234567890123456789012 */
376 var_names[0] = "node_variable_a_very_long_name_0";
377 var_names[1] = "nod_var1";
378
379 error = ex_put_variable_param(exoid, EX_NODAL, num_nod_vars);
380 printf("after ex_put_variable_param, error = %d\n", error);
381 if (error) {
382 ex_close(exoid);
383 exit(-1);
384 }
385
386 error = ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names);
387 printf("after ex_put_variable_names, error = %d\n", error);
388 if (error) {
389 ex_close(exoid);
390 exit(-1);
391 }
392
393 num_ele_vars = 0;
394
395 /* for each time step, write the analysis results;
396 * the code below fills the arrays glob_var_vals,
397 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
398 * obviously the analysis code will populate these arrays
399 */
400
401 whole_time_step = 1;
402 num_time_steps = 10;
403
404 glob_var_vals = (float *)calloc(num_glo_vars, CPU_word_size);
405 nodal_var_vals = (float *)calloc(num_nodes, CPU_word_size);
406 elem_var_vals = (float *)calloc(4, CPU_word_size);
407
408 for (i = 0; i < num_time_steps; i++) {
409 time_value = (float)(i + 1) / 100.;
410
411 /* write time value */
412
413 error = ex_put_time(exoid, whole_time_step, &time_value);
414 printf("after ex_put_time, error = %d\n", error);
415
416 if (error) {
417 ex_close(exoid);
418 exit(-1);
419 }
420
421 /* write global variables */
422
423 for (j = 0; j < num_glo_vars; j++) {
424 glob_var_vals[j] = (float)(j + 2) * time_value;
425 }
426
427 error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
428 printf("after ex_put_glob_vars, error = %d\n", error);
429
430 if (error) {
431 ex_close(exoid);
432 exit(-1);
433 }
434
435 /* write nodal variables */
436
437 for (k = 1; k <= num_nod_vars; k++) {
438 for (j = 0; j < num_nodes; j++) {
439 nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value);
440 }
441
442 error = ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals);
443 printf("after ex_put_nodal_var, error = %d\n", error);
444 if (error) {
445 ex_close(exoid);
446 exit(-1);
447 }
448 }
449
450 /* write element variables */
451
452 for (k = 1; k <= num_ele_vars; k++) {
453 for (j = 0; j < num_elem_blk; j++) {
454 for (m = 0; m < num_elem_in_block[j]; m++) {
455 elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value);
456 /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
457 }
458 error = ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j],
459 elem_var_vals);
460 printf("after ex_put_elem_var, error = %d\n", error);
461 if (error) {
462 ex_close(exoid);
463 exit(-1);
464 }
465 }
466 }
467
468 whole_time_step++;
469
470 /* update the data file; this should be done at the end of every time step
471 * to ensure that no data is lost if the analysis dies
472 */
473 error = ex_update(exoid);
474 printf("after ex_update, error = %d\n", error);
475 if (error) {
476 ex_close(exoid);
477 exit(-1);
478 }
479 }
480 free(glob_var_vals);
481 free(nodal_var_vals);
482 free(elem_var_vals);
483
484 /* close the EXODUS files
485 */
486 error = ex_close(exoid);
487 printf("after ex_close, error = %d\n", error);
488 if (error) {
489 ex_close(exoid);
490 exit(-1);
491 }
492 return 0;
493 }