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