| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020, 2023 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 |
* testwt1 - 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], num_nodes_per_elem[10], num_attr[10]; |
| 40 |
int num_node_sets, num_side_sets, error; |
| 41 |
int num_node_maps, num_elem_maps; |
| 42 |
int i, j, k, m, *elem_map, *connect, *node_map; |
| 43 |
int node_list[100], elem_list[100], side_list[100]; |
| 44 |
int id, ebids[10], ids[10]; |
| 45 |
int num_nodes_per_set[10], num_elem_per_set[10]; |
| 46 |
int num_df_per_set[10]; |
| 47 |
int node_ind[10], elem_ind[10]; |
| 48 |
int num_qa_rec, num_info; |
| 49 |
int num_glo_vars, num_nod_vars, num_ele_vars; |
| 50 |
int whole_time_step, num_time_steps; |
| 51 |
int CPU_word_size, IO_word_size; |
| 52 |
int prop_array[2]; |
| 53 |
|
| 54 |
float *glob_var_vals, *nodal_var_vals, *elem_var_vals; |
| 55 |
float time_value; |
| 56 |
float x[100], y[100], z[100]; |
| 57 |
float attrib[100], dist_fact[100]; |
| 58 |
char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3]; |
| 59 |
char *emap_names[2]; |
| 60 |
char *prop_names[2]; |
| 61 |
|
| 62 |
ex_opts(EX_VERBOSE | EX_ABORT); |
| 63 |
|
| 64 |
/* Specify compute and i/o word size */ |
| 65 |
|
| 66 |
CPU_word_size = 0; /* sizeof(float) */ |
| 67 |
IO_word_size = 4; /* (4 bytes) */ |
| 68 |
|
| 69 |
/* create EXODUS II file */ |
| 70 |
|
| 71 |
exoid = ex_create("test.exo", /* filename path */ |
| 72 |
EX_CLOBBER, /* create mode */ |
| 73 |
&CPU_word_size, /* CPU float word size in bytes */ |
| 74 |
&IO_word_size); /* I/O float word size in bytes */ |
| 75 |
printf("after ex_create for test.exo, exoid = %d\n", exoid); |
| 76 |
printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size); |
| 77 |
|
| 78 |
/* initialize file with parameters */ |
| 79 |
|
| 80 |
num_dim = 3; |
| 81 |
num_nodes = 28; |
| 82 |
num_elem = 8; |
| 83 |
num_elem_blk = 7; |
| 84 |
num_node_sets = 2; |
| 85 |
num_side_sets = 5; |
| 86 |
/* num_side_sets = 6; Uncomment to test NULL side sets */ |
| 87 |
|
| 88 |
error = ex_put_init(exoid, "This is testwt1", num_dim, num_nodes, num_elem, num_elem_blk, |
| 89 |
num_node_sets, num_side_sets); |
| 90 |
|
| 91 |
printf("after ex_put_init, error = %d\n", error); |
| 92 |
|
| 93 |
/* write nodal coordinates values and names to database */ |
| 94 |
|
| 95 |
/* Quad #1 */ |
| 96 |
x[0] = 0.0; |
| 97 |
y[0] = 0.0; |
| 98 |
z[0] = 0.0; |
| 99 |
x[1] = 1.0; |
| 100 |
y[1] = 0.0; |
| 101 |
z[1] = 0.0; |
| 102 |
x[2] = 1.0; |
| 103 |
y[2] = 1.0; |
| 104 |
z[2] = 0.0; |
| 105 |
x[3] = 0.0; |
| 106 |
y[3] = 1.0; |
| 107 |
z[3] = 0.0; |
| 108 |
|
| 109 |
/* Quad #2 */ |
| 110 |
x[4] = 1.0; |
| 111 |
y[4] = 0.0; |
| 112 |
z[4] = 0.0; |
| 113 |
x[5] = 2.0; |
| 114 |
y[5] = 0.0; |
| 115 |
z[5] = 0.0; |
| 116 |
x[6] = 2.0; |
| 117 |
y[6] = 1.0; |
| 118 |
z[6] = 0.0; |
| 119 |
x[7] = 1.0; |
| 120 |
y[7] = 1.0; |
| 121 |
z[7] = 0.0; |
| 122 |
|
| 123 |
/* Hex #1 */ |
| 124 |
x[8] = 0.0; |
| 125 |
y[8] = 0.0; |
| 126 |
z[8] = 0.0; |
| 127 |
x[9] = 10.0; |
| 128 |
y[9] = 0.0; |
| 129 |
z[9] = 0.0; |
| 130 |
x[10] = 10.0; |
| 131 |
y[10] = 0.0; |
| 132 |
z[10] = -10.0; |
| 133 |
x[11] = 1.0; |
| 134 |
y[11] = 0.0; |
| 135 |
z[11] = -10.0; |
| 136 |
x[12] = 1.0; |
| 137 |
y[12] = 10.0; |
| 138 |
z[12] = 0.0; |
| 139 |
x[13] = 10.0; |
| 140 |
y[13] = 10.0; |
| 141 |
z[13] = 0.0; |
| 142 |
x[14] = 10.0; |
| 143 |
y[14] = 10.0; |
| 144 |
z[14] = -10.0; |
| 145 |
x[15] = 1.0; |
| 146 |
y[15] = 10.0; |
| 147 |
z[15] = -10.0; |
| 148 |
|
| 149 |
/* Tetra #1 */ |
| 150 |
x[16] = 0.0; |
| 151 |
y[16] = 0.0; |
| 152 |
z[16] = 0.0; |
| 153 |
x[17] = 1.0; |
| 154 |
y[17] = 0.0; |
| 155 |
z[17] = 5.0; |
| 156 |
x[18] = 10.0; |
| 157 |
y[18] = 0.0; |
| 158 |
z[18] = 2.0; |
| 159 |
x[19] = 7.0; |
| 160 |
y[19] = 5.0; |
| 161 |
z[19] = 3.0; |
| 162 |
|
| 163 |
/* Circle #1 */ |
| 164 |
x[20] = 100.0; |
| 165 |
y[20] = 100.0; |
| 166 |
z[20] = 0.0; |
| 167 |
|
| 168 |
/* Sphere #1 */ |
| 169 |
x[21] = 50.0; |
| 170 |
y[21] = 50.0; |
| 171 |
z[21] = 20.0; |
| 172 |
|
| 173 |
/* Wedge #1 */ |
| 174 |
x[22] = 3.0; |
| 175 |
y[22] = 0.0; |
| 176 |
z[22] = 6.0; |
| 177 |
x[23] = 6.0; |
| 178 |
y[23] = 0.0; |
| 179 |
z[23] = 0.0; |
| 180 |
x[24] = 0.0; |
| 181 |
y[24] = 0.0; |
| 182 |
z[24] = 0.0; |
| 183 |
x[25] = 3.0; |
| 184 |
y[25] = 2.0; |
| 185 |
z[25] = 6.0; |
| 186 |
x[26] = 6.0; |
| 187 |
y[26] = 2.0; |
| 188 |
z[26] = 2.0; |
| 189 |
x[27] = 0.0; |
| 190 |
y[27] = 2.0; |
| 191 |
z[27] = 0.0; |
| 192 |
|
| 193 |
error = ex_put_coord(exoid, x, y, z); |
| 194 |
printf("after ex_put_coord, error = %d\n", error); |
| 195 |
|
| 196 |
coord_names[0] = "xcoor"; |
| 197 |
coord_names[1] = "ycoor"; |
| 198 |
coord_names[2] = "zcoor"; |
| 199 |
|
| 200 |
error = ex_put_coord_names(exoid, coord_names); |
| 201 |
printf("after ex_put_coord_names, error = %d\n", error); |
| 202 |
|
| 203 |
/* write node and element map parameters */ |
| 204 |
|
| 205 |
num_node_maps = 1; |
| 206 |
num_elem_maps = 2; |
| 207 |
|
| 208 |
error = ex_put_map_param(exoid, num_node_maps, num_elem_maps); |
| 209 |
|
| 210 |
printf("after ex_put_map_param, error = %d\n", error); |
| 211 |
|
| 212 |
/* write element map properties */ |
| 213 |
|
| 214 |
prop_names[0] = "ORDER"; |
| 215 |
prop_names[1] = "NUMBER"; |
| 216 |
error = ex_put_prop_names(exoid, EX_ELEM_MAP, 2, prop_names); |
| 217 |
printf("after ex_put_prop_names, error = %d\n", error); |
| 218 |
|
| 219 |
/* write element order map */ |
| 220 |
|
| 221 |
elem_map = (int *)calloc(num_elem, sizeof(int)); |
| 222 |
|
| 223 |
for (i = 1; i <= num_elem; i++) { |
| 224 |
elem_map[i - 1] = i; |
| 225 |
} |
| 226 |
|
| 227 |
id = 111; |
| 228 |
error = ex_put_num_map(exoid, EX_ELEM_MAP, id, elem_map); |
| 229 |
printf("after ex_put_elem_map, error = %d\n", error); |
| 230 |
|
| 231 |
free(elem_map); |
| 232 |
|
| 233 |
error = ex_put_prop(exoid, EX_ELEM_MAP, id, "ORDER", 1); |
| 234 |
printf("after ex_put_prop, error = %d\n", error); |
| 235 |
|
| 236 |
/* write element numbering map */ |
| 237 |
|
| 238 |
elem_map = (int *)calloc(num_elem, sizeof(int)); |
| 239 |
|
| 240 |
for (i = 1; i <= num_elem; i++) { |
| 241 |
elem_map[i - 1] = i * 2; |
| 242 |
} |
| 243 |
|
| 244 |
id = 222; |
| 245 |
/* Output the map 1 element at a time... */ |
| 246 |
for (i = 1; i <= num_elem; i++) { |
| 247 |
error = ex_put_partial_num_map(exoid, EX_ELEM_MAP, id, i, 1, &elem_map[i - 1]); |
| 248 |
printf("after ex_put_partial_elem_map, error = %d\n", error); |
| 249 |
} |
| 250 |
|
| 251 |
free(elem_map); |
| 252 |
|
| 253 |
error = ex_put_prop(exoid, EX_ELEM_MAP, id, "NUMBER", 1); |
| 254 |
printf("after ex_put_prop, error = %d\n", error); |
| 255 |
|
| 256 |
/* write element map names */ |
| 257 |
emap_names[0] = "Element_Map_111"; |
| 258 |
emap_names[1] = "Element_Map_222"; |
| 259 |
|
| 260 |
error = ex_put_names(exoid, EX_ELEM_MAP, emap_names); |
| 261 |
printf("after ex_put_names, error = %d\n", error); |
| 262 |
|
| 263 |
/* write node map properties */ |
| 264 |
|
| 265 |
prop_names[0] = "NUMBER"; |
| 266 |
error = ex_put_prop_names(exoid, EX_NODE_MAP, 1, prop_names); |
| 267 |
printf("after ex_put_prop_names, error = %d\n", error); |
| 268 |
|
| 269 |
/* write node numbering map */ |
| 270 |
|
| 271 |
node_map = (int *)calloc(num_nodes, sizeof(int)); |
| 272 |
|
| 273 |
for (i = 1; i <= num_nodes; i++) { |
| 274 |
node_map[i - 1] = i * 3; |
| 275 |
} |
| 276 |
|
| 277 |
id = 333; |
| 278 |
error = ex_put_num_map(exoid, EX_NODE_MAP, id, node_map); |
| 279 |
printf("after ex_put_node_map, error = %d\n", error); |
| 280 |
|
| 281 |
error = ex_put_name(exoid, EX_NODE_MAP, id, "Node_Map_111"); |
| 282 |
printf("after ex_put_name, error = %d\n", error); |
| 283 |
|
| 284 |
free(node_map); |
| 285 |
|
| 286 |
error = ex_put_prop(exoid, EX_NODE_MAP, id, "NUMBER", 1); |
| 287 |
printf("after ex_put_prop, error = %d\n", error); |
| 288 |
|
| 289 |
/* write element block parameters */ |
| 290 |
|
| 291 |
num_elem_in_block[0] = 1; /* element 1: Shell 1 */ |
| 292 |
num_elem_in_block[1] = 2; /* elements 2, 3: Shell 1 & 2 */ |
| 293 |
num_elem_in_block[2] = 1; /* element 4: Hex */ |
| 294 |
num_elem_in_block[3] = 1; /* element 5: Tetra */ |
| 295 |
num_elem_in_block[4] = 1; /* element 6: Circle */ |
| 296 |
num_elem_in_block[5] = 1; /* element 7: Sphere */ |
| 297 |
num_elem_in_block[6] = 1; /* element 8: Wedge */ |
| 298 |
|
| 299 |
num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node shells */ |
| 300 |
num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node shells */ |
| 301 |
num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes */ |
| 302 |
num_nodes_per_elem[3] = 4; /* elements in block #3 are 4-node tetras */ |
| 303 |
num_nodes_per_elem[4] = 1; /* elements in block #4 are 1-node circles */ |
| 304 |
num_nodes_per_elem[5] = 1; /* elements in block #5 are 1-node spheres */ |
| 305 |
num_nodes_per_elem[6] = 6; /* elements in block #6 are 6-node wedges */ |
| 306 |
|
| 307 |
ebids[0] = 10; |
| 308 |
ebids[1] = 11; |
| 309 |
ebids[2] = 12; |
| 310 |
ebids[3] = 13; |
| 311 |
ebids[4] = 14; |
| 312 |
ebids[5] = 15; |
| 313 |
ebids[6] = 16; |
| 314 |
|
| 315 |
num_attr[0] = 3; |
| 316 |
num_attr[1] = 3; |
| 317 |
num_attr[2] = 3; |
| 318 |
num_attr[3] = 3; |
| 319 |
num_attr[4] = 3; |
| 320 |
num_attr[5] = 3; |
| 321 |
num_attr[6] = 3; |
| 322 |
|
| 323 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[0], "shell", num_elem_in_block[0], |
| 324 |
num_nodes_per_elem[0], 0, 0, num_attr[0]); |
| 325 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 326 |
|
| 327 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[1], "shell", num_elem_in_block[1], |
| 328 |
num_nodes_per_elem[1], 0, 0, num_attr[1]); |
| 329 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 330 |
|
| 331 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[2], "hex", num_elem_in_block[2], |
| 332 |
num_nodes_per_elem[2], 0, 0, num_attr[2]); |
| 333 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 334 |
|
| 335 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[3], "tetra", num_elem_in_block[3], |
| 336 |
num_nodes_per_elem[3], 0, 0, num_attr[3]); |
| 337 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 338 |
|
| 339 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[4], "circle", num_elem_in_block[4], |
| 340 |
num_nodes_per_elem[4], 0, 0, num_attr[4]); |
| 341 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 342 |
|
| 343 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[5], "sphere", num_elem_in_block[5], |
| 344 |
num_nodes_per_elem[5], 0, 0, num_attr[5]); |
| 345 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 346 |
|
| 347 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[6], "wedge", num_elem_in_block[6], |
| 348 |
num_nodes_per_elem[6], 0, 0, num_attr[6]); |
| 349 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 350 |
|
| 351 |
/* write element block properties */ |
| 352 |
|
| 353 |
prop_names[0] = "MATL"; |
| 354 |
prop_names[1] = "DENSITY"; |
| 355 |
error = ex_put_prop_names(exoid, EX_ELEM_BLOCK, 2, prop_names); |
| 356 |
printf("after ex_put_prop_names, error = %d\n", error); |
| 357 |
|
| 358 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10); |
| 359 |
printf("after ex_put_prop, error = %d\n", error); |
| 360 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20); |
| 361 |
printf("after ex_put_prop, error = %d\n", error); |
| 362 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30); |
| 363 |
printf("after ex_put_prop, error = %d\n", error); |
| 364 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40); |
| 365 |
printf("after ex_put_prop, error = %d\n", error); |
| 366 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50); |
| 367 |
printf("after ex_put_prop, error = %d\n", error); |
| 368 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], "MATL", 60); |
| 369 |
printf("after ex_put_prop, error = %d\n", error); |
| 370 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], "MATL", 70); |
| 371 |
printf("after ex_put_prop, error = %d\n", error); |
| 372 |
|
| 373 |
/* write element connectivity */ |
| 374 |
|
| 375 |
connect = (int *)calloc(8, sizeof(int)); |
| 376 |
connect[0] = 1; |
| 377 |
connect[1] = 2; |
| 378 |
connect[2] = 3; |
| 379 |
connect[3] = 4; |
| 380 |
|
| 381 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL); |
| 382 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 383 |
|
| 384 |
connect[0] = 1; |
| 385 |
connect[1] = 2; |
| 386 |
connect[2] = 3; |
| 387 |
connect[3] = 4; |
| 388 |
connect[4] = 5; |
| 389 |
connect[5] = 6; |
| 390 |
connect[6] = 7; |
| 391 |
connect[7] = 8; |
| 392 |
|
| 393 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[1], connect, NULL, NULL); |
| 394 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 395 |
|
| 396 |
connect[0] = 9; |
| 397 |
connect[1] = 10; |
| 398 |
connect[2] = 11; |
| 399 |
connect[3] = 12; |
| 400 |
connect[4] = 13; |
| 401 |
connect[5] = 14; |
| 402 |
connect[6] = 15; |
| 403 |
connect[7] = 16; |
| 404 |
|
| 405 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL); |
| 406 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 407 |
|
| 408 |
connect[0] = 17; |
| 409 |
connect[1] = 18; |
| 410 |
connect[2] = 19; |
| 411 |
connect[3] = 20; |
| 412 |
|
| 413 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[3], connect, NULL, NULL); |
| 414 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 415 |
|
| 416 |
connect[0] = 21; |
| 417 |
|
| 418 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[4], connect, NULL, NULL); |
| 419 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 420 |
|
| 421 |
connect[0] = 22; |
| 422 |
|
| 423 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[5], connect, NULL, NULL); |
| 424 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 425 |
|
| 426 |
connect[0] = 23; |
| 427 |
connect[1] = 24; |
| 428 |
connect[2] = 25; |
| 429 |
connect[3] = 26; |
| 430 |
connect[4] = 27; |
| 431 |
connect[5] = 28; |
| 432 |
|
| 433 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[6], connect, NULL, NULL); |
| 434 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 435 |
|
| 436 |
free(connect); |
| 437 |
|
| 438 |
/* write element block attributes (3 per block) */ |
| 439 |
|
| 440 |
attrib[0] = 1.0; |
| 441 |
attrib[1] = 2.0; |
| 442 |
attrib[2] = 3.0; |
| 443 |
attrib[3] = 1.11; |
| 444 |
attrib[4] = 2.11; |
| 445 |
attrib[5] = 3.11; |
| 446 |
attrib[6] = 1.12; |
| 447 |
attrib[7] = 2.12; |
| 448 |
attrib[8] = 3.12; |
| 449 |
attrib[9] = 1.2; |
| 450 |
attrib[10] = 2.2; |
| 451 |
attrib[11] = 3.2; |
| 452 |
attrib[12] = 1.3; |
| 453 |
attrib[13] = 2.3; |
| 454 |
attrib[14] = 3.3; |
| 455 |
attrib[15] = 1.4; |
| 456 |
attrib[16] = 2.4; |
| 457 |
attrib[17] = 3.4; |
| 458 |
attrib[18] = 1.5; |
| 459 |
attrib[19] = 2.5; |
| 460 |
attrib[20] = 3.5; |
| 461 |
attrib[21] = 1.6; |
| 462 |
attrib[22] = 2.6; |
| 463 |
attrib[23] = 3.6; |
| 464 |
|
| 465 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[0], &attrib[0]); |
| 466 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 467 |
|
| 468 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[1], &attrib[3]); |
| 469 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 470 |
|
| 471 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[2], &attrib[9]); |
| 472 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 473 |
|
| 474 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[3], &attrib[12]); |
| 475 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 476 |
|
| 477 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[4], &attrib[15]); |
| 478 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 479 |
|
| 480 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[5], &attrib[18]); |
| 481 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 482 |
|
| 483 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[6], &attrib[21]); |
| 484 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 485 |
|
| 486 |
ids[0] = 20; |
| 487 |
ids[1] = 21; |
| 488 |
|
| 489 |
num_nodes_per_set[0] = 5; |
| 490 |
num_nodes_per_set[1] = 3; |
| 491 |
/* num_nodes_per_set[1] = 0; Uncomment to test NULL node sets */ |
| 492 |
|
| 493 |
node_ind[0] = 0; |
| 494 |
node_ind[1] = 5; |
| 495 |
|
| 496 |
node_list[0] = 10; |
| 497 |
node_list[1] = 11; |
| 498 |
node_list[2] = 12; |
| 499 |
node_list[3] = 13; |
| 500 |
node_list[4] = 14; |
| 501 |
node_list[5] = 20; |
| 502 |
node_list[6] = 21; |
| 503 |
node_list[7] = 22; |
| 504 |
|
| 505 |
num_df_per_set[0] = 5; |
| 506 |
num_df_per_set[1] = 3; |
| 507 |
|
| 508 |
int ns_df_ind[2] = {0, 5}; |
| 509 |
|
| 510 |
dist_fact[0] = 1.0; |
| 511 |
dist_fact[1] = 2.0; |
| 512 |
dist_fact[2] = 3.0; |
| 513 |
dist_fact[3] = 4.0; |
| 514 |
dist_fact[4] = 5.0; |
| 515 |
dist_fact[5] = 1.1; |
| 516 |
dist_fact[6] = 2.1; |
| 517 |
dist_fact[7] = 3.1; |
| 518 |
|
| 519 |
{ |
| 520 |
struct ex_set_specs set_specs; |
| 521 |
|
| 522 |
set_specs.sets_ids = ids; |
| 523 |
set_specs.num_entries_per_set = num_nodes_per_set; |
| 524 |
set_specs.num_dist_per_set = num_df_per_set; |
| 525 |
set_specs.sets_entry_index = node_ind; |
| 526 |
set_specs.sets_dist_index = ns_df_ind; |
| 527 |
set_specs.sets_entry_list = node_list; |
| 528 |
set_specs.sets_extra_list = NULL; |
| 529 |
set_specs.sets_dist_fact = dist_fact; |
| 530 |
|
| 531 |
error = ex_put_concat_sets(exoid, EX_NODE_SET, &set_specs); |
| 532 |
} |
| 533 |
printf("after ex_put_concat_node_sets, error = %d\n", error); |
| 534 |
|
| 535 |
error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4); |
| 536 |
printf("after ex_put_prop, error = %d\n", error); |
| 537 |
error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5); |
| 538 |
printf("after ex_put_prop, error = %d\n", error); |
| 539 |
|
| 540 |
prop_array[0] = 1000; |
| 541 |
prop_array[1] = 2000; |
| 542 |
|
| 543 |
error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array); |
| 544 |
printf("after ex_put_prop_array, error = %d\n", error); |
| 545 |
|
| 546 |
/* write concatenated side sets; this produces the same information as |
| 547 |
* the above code which writes individual side sets |
| 548 |
*/ |
| 549 |
|
| 550 |
ids[0] = 30; |
| 551 |
ids[1] = 31; |
| 552 |
ids[2] = 32; |
| 553 |
ids[3] = 33; |
| 554 |
ids[4] = 34; |
| 555 |
ids[5] = 35; |
| 556 |
|
| 557 |
/* side set #1 - shell */ |
| 558 |
node_list[0] = 8; |
| 559 |
node_list[1] = 5; |
| 560 |
elem_list[0] = 3; |
| 561 |
node_list[2] = 6; |
| 562 |
node_list[3] = 7; |
| 563 |
elem_list[1] = 3; |
| 564 |
|
| 565 |
/* side set #2 - shell/hex, spanning 2 element types */ |
| 566 |
node_list[4] = 2; |
| 567 |
node_list[5] = 3; |
| 568 |
elem_list[2] = 1; |
| 569 |
node_list[6] = 7; |
| 570 |
node_list[7] = 8; |
| 571 |
elem_list[3] = 3; |
| 572 |
|
| 573 |
/* side set #3 - hex */ |
| 574 |
node_list[8] = 9; |
| 575 |
node_list[9] = 12; |
| 576 |
node_list[10] = 11; |
| 577 |
node_list[11] = 10; |
| 578 |
elem_list[4] = 4; |
| 579 |
|
| 580 |
node_list[12] = 11; |
| 581 |
node_list[13] = 12; |
| 582 |
node_list[14] = 16; |
| 583 |
node_list[15] = 15; |
| 584 |
elem_list[5] = 4; |
| 585 |
|
| 586 |
node_list[16] = 16; |
| 587 |
node_list[17] = 15; |
| 588 |
node_list[18] = 11; |
| 589 |
node_list[19] = 12; |
| 590 |
elem_list[6] = 4; |
| 591 |
|
| 592 |
node_list[20] = 10; |
| 593 |
node_list[21] = 11; |
| 594 |
node_list[22] = 15; |
| 595 |
node_list[23] = 14; |
| 596 |
elem_list[7] = 4; |
| 597 |
|
| 598 |
node_list[24] = 13; |
| 599 |
node_list[25] = 16; |
| 600 |
node_list[26] = 12; |
| 601 |
node_list[27] = 9; |
| 602 |
elem_list[8] = 4; |
| 603 |
|
| 604 |
node_list[28] = 14; |
| 605 |
node_list[29] = 13; |
| 606 |
node_list[30] = 9; |
| 607 |
node_list[31] = 10; |
| 608 |
elem_list[9] = 4; |
| 609 |
|
| 610 |
node_list[32] = 16; |
| 611 |
node_list[33] = 13; |
| 612 |
node_list[34] = 14; |
| 613 |
node_list[35] = 15; |
| 614 |
elem_list[10] = 4; |
| 615 |
|
| 616 |
/* side set #4 - tetras */ |
| 617 |
node_list[36] = 17; |
| 618 |
node_list[37] = 18; |
| 619 |
node_list[38] = 20; |
| 620 |
elem_list[11] = 5; |
| 621 |
|
| 622 |
node_list[39] = 18; |
| 623 |
node_list[40] = 19; |
| 624 |
node_list[41] = 20; |
| 625 |
elem_list[12] = 5; |
| 626 |
|
| 627 |
node_list[42] = 20; |
| 628 |
node_list[43] = 19; |
| 629 |
node_list[44] = 17; |
| 630 |
elem_list[13] = 5; |
| 631 |
|
| 632 |
node_list[45] = 19; |
| 633 |
node_list[46] = 18; |
| 634 |
node_list[47] = 17; |
| 635 |
elem_list[14] = 5; |
| 636 |
|
| 637 |
/* side set #5 - circle and sphere */ |
| 638 |
node_list[48] = 21; |
| 639 |
elem_list[15] = 6; |
| 640 |
node_list[49] = 22; |
| 641 |
elem_list[16] = 7; |
| 642 |
|
| 643 |
/* side set #6 - wedges */ |
| 644 |
node_list[50] = 27; |
| 645 |
node_list[51] = 26; |
| 646 |
node_list[52] = 23; |
| 647 |
node_list[53] = 24; |
| 648 |
elem_list[17] = 8; |
| 649 |
|
| 650 |
node_list[54] = 28; |
| 651 |
node_list[55] = 27; |
| 652 |
node_list[56] = 24; |
| 653 |
node_list[57] = 25; |
| 654 |
elem_list[18] = 8; |
| 655 |
|
| 656 |
node_list[58] = 28; |
| 657 |
node_list[59] = 25; |
| 658 |
node_list[60] = 23; |
| 659 |
node_list[61] = 26; |
| 660 |
elem_list[19] = 8; |
| 661 |
|
| 662 |
node_list[62] = 25; |
| 663 |
node_list[63] = 24; |
| 664 |
node_list[64] = 23; |
| 665 |
elem_list[20] = 8; |
| 666 |
|
| 667 |
node_list[65] = 26; |
| 668 |
node_list[66] = 27; |
| 669 |
node_list[67] = 28; |
| 670 |
elem_list[21] = 8; |
| 671 |
|
| 672 |
node_ind[0] = 0; |
| 673 |
node_ind[1] = 4; |
| 674 |
node_ind[2] = 8; |
| 675 |
node_ind[3] = 36; |
| 676 |
node_ind[4] = 47; |
| 677 |
node_ind[5] = 49; |
| 678 |
|
| 679 |
num_elem_per_set[0] = 2; /* two sides uses 2 elements */ |
| 680 |
num_elem_per_set[1] = 2; |
| 681 |
num_elem_per_set[2] = 7; |
| 682 |
num_elem_per_set[3] = 4; |
| 683 |
num_elem_per_set[4] = 2; |
| 684 |
num_elem_per_set[5] = 5; |
| 685 |
/* num_elem_per_set[5] = 0; Uncomment to test NULL side sets */ |
| 686 |
|
| 687 |
num_nodes_per_set[0] = 4; |
| 688 |
num_nodes_per_set[1] = 4; |
| 689 |
num_nodes_per_set[2] = 28; |
| 690 |
num_nodes_per_set[3] = 12; |
| 691 |
num_nodes_per_set[4] = 2; |
| 692 |
num_nodes_per_set[5] = 18; |
| 693 |
|
| 694 |
elem_ind[0] = 0; |
| 695 |
elem_ind[1] = 2; |
| 696 |
elem_ind[2] = 4; |
| 697 |
elem_ind[3] = 11; |
| 698 |
elem_ind[4] = 15; |
| 699 |
elem_ind[5] = 17; |
| 700 |
|
| 701 |
error = ex_cvt_nodes_to_sides(exoid, num_elem_per_set, num_nodes_per_set, elem_ind, node_ind, |
| 702 |
elem_list, node_list, side_list); |
| 703 |
printf("after ex_cvt_nodes_to_sides, error = %d\n", error); |
| 704 |
|
| 705 |
num_df_per_set[0] = 4; |
| 706 |
num_df_per_set[1] = 4; |
| 707 |
num_df_per_set[2] = 0; |
| 708 |
num_df_per_set[3] = 0; |
| 709 |
num_df_per_set[4] = 0; |
| 710 |
num_df_per_set[5] = 0; |
| 711 |
|
| 712 |
int ss_df_ind[] = {0, 4, 4, 4, 4, 4}; |
| 713 |
|
| 714 |
/* side set #1 df */ |
| 715 |
dist_fact[0] = 30.0; |
| 716 |
dist_fact[1] = 30.1; |
| 717 |
dist_fact[2] = 30.2; |
| 718 |
dist_fact[3] = 30.3; |
| 719 |
|
| 720 |
/* side set #2 df */ |
| 721 |
dist_fact[4] = 31.0; |
| 722 |
dist_fact[5] = 31.1; |
| 723 |
dist_fact[6] = 31.2; |
| 724 |
dist_fact[7] = 31.3; |
| 725 |
|
| 726 |
{ |
| 727 |
struct ex_set_specs set_specs; |
| 728 |
|
| 729 |
set_specs.sets_ids = ids; |
| 730 |
set_specs.num_entries_per_set = num_elem_per_set; |
| 731 |
set_specs.num_dist_per_set = num_df_per_set; |
| 732 |
set_specs.sets_entry_index = elem_ind; |
| 733 |
set_specs.sets_dist_index = ss_df_ind; |
| 734 |
set_specs.sets_entry_list = elem_list; |
| 735 |
set_specs.sets_extra_list = side_list; |
| 736 |
set_specs.sets_dist_fact = dist_fact; |
| 737 |
error = ex_put_concat_sets(exoid, EX_SIDE_SET, &set_specs); |
| 738 |
} |
| 739 |
printf("after ex_put_concat_side_sets, error = %d\n", error); |
| 740 |
|
| 741 |
error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100); |
| 742 |
printf("after ex_put_prop, error = %d\n", error); |
| 743 |
|
| 744 |
error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101); |
| 745 |
printf("after ex_put_prop, error = %d\n", error); |
| 746 |
|
| 747 |
/* END COMMENTED OUT SECTION */ |
| 748 |
|
| 749 |
/* write QA records */ |
| 750 |
|
| 751 |
num_qa_rec = 2; |
| 752 |
|
| 753 |
qa_record[0][0] = "TESTWT1"; |
| 754 |
qa_record[0][1] = "testwt1"; |
| 755 |
qa_record[0][2] = "03/16/94"; |
| 756 |
qa_record[0][3] = "15:41:33"; |
| 757 |
qa_record[1][0] = "FASTQ"; |
| 758 |
qa_record[1][1] = "fastq"; |
| 759 |
qa_record[1][2] = "07/07/93"; |
| 760 |
qa_record[1][3] = "16:41:33"; |
| 761 |
|
| 762 |
error = ex_put_qa(exoid, num_qa_rec, qa_record); |
| 763 |
printf("after ex_put_qa, error = %d\n", error); |
| 764 |
|
| 765 |
/* write information records */ |
| 766 |
|
| 767 |
num_info = 3; |
| 768 |
|
| 769 |
info[0] = "This is the first information record."; |
| 770 |
info[1] = "This is the second information record."; |
| 771 |
info[2] = "This is the third information record."; |
| 772 |
|
| 773 |
error = ex_put_info(exoid, num_info, info); |
| 774 |
printf("after ex_put_info, error = %d\n", error); |
| 775 |
|
| 776 |
/* write results variables parameters and names */ |
| 777 |
|
| 778 |
num_glo_vars = 1; |
| 779 |
|
| 780 |
var_names[0] = "glo vars"; |
| 781 |
|
| 782 |
error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars); |
| 783 |
printf("after ex_put_variable_param, error = %d\n", error); |
| 784 |
error = ex_put_variable_name(exoid, EX_GLOBAL, 1, var_names[0]); |
| 785 |
printf("after ex_put_variable_name, error = %d\n", error); |
| 786 |
|
| 787 |
num_nod_vars = 2; |
| 788 |
|
| 789 |
var_names[0] = "nod_var0"; |
| 790 |
var_names[1] = "nod_var1"; |
| 791 |
|
| 792 |
error = ex_put_variable_param(exoid, EX_NODAL, num_nod_vars); |
| 793 |
printf("after ex_put_variable_param, error = %d\n", error); |
| 794 |
error = ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names); |
| 795 |
printf("after ex_put_variable_names, error = %d\n", error); |
| 796 |
|
| 797 |
num_ele_vars = 3; |
| 798 |
|
| 799 |
var_names[0] = "ele_var0"; |
| 800 |
var_names[1] = "ele_var1"; |
| 801 |
var_names[2] = "ele_var2"; |
| 802 |
|
| 803 |
error = ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars); |
| 804 |
printf("after ex_put_variable_param, error = %d\n", error); |
| 805 |
error = ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names); |
| 806 |
printf("after ex_put_variable_names, error = %d\n", error); |
| 807 |
|
| 808 |
/* for each time step, write the analysis results; |
| 809 |
* the code below fills the arrays glob_var_vals, |
| 810 |
* nodal_var_vals, and elem_var_vals with values for debugging purposes; |
| 811 |
* obviously the analysis code will populate these arrays |
| 812 |
*/ |
| 813 |
|
| 814 |
whole_time_step = 1; |
| 815 |
num_time_steps = 10; |
| 816 |
|
| 817 |
glob_var_vals = (float *)calloc(num_glo_vars, CPU_word_size); |
| 818 |
nodal_var_vals = (float *)calloc(num_nodes, CPU_word_size); |
| 819 |
elem_var_vals = (float *)calloc(4, CPU_word_size); |
| 820 |
|
| 821 |
for (i = 0; i < num_time_steps; i++) { |
| 822 |
time_value = (float)(i + 1) / 100.; |
| 823 |
|
| 824 |
/* write time value */ |
| 825 |
|
| 826 |
error = ex_put_time(exoid, whole_time_step, &time_value); |
| 827 |
printf("after ex_put_time, error = %d\n", error); |
| 828 |
|
| 829 |
/* write global variables */ |
| 830 |
|
| 831 |
for (j = 0; j < num_glo_vars; j++) { |
| 832 |
glob_var_vals[j] = (float)(j + 2) * time_value; |
| 833 |
} |
| 834 |
|
| 835 |
error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals); |
| 836 |
printf("after ex_put_glob_vars, error = %d\n", error); |
| 837 |
|
| 838 |
/* write nodal variables */ |
| 839 |
|
| 840 |
for (k = 1; k <= num_nod_vars; k++) { |
| 841 |
for (j = 0; j < num_nodes; j++) { |
| 842 |
nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value); |
| 843 |
} |
| 844 |
|
| 845 |
error = ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals); |
| 846 |
printf("after ex_put_nodal_var, error = %d\n", error); |
| 847 |
} |
| 848 |
|
| 849 |
/* write element variables */ |
| 850 |
|
| 851 |
for (k = 1; k <= num_ele_vars; k++) { |
| 852 |
for (j = 0; j < num_elem_blk; j++) { |
| 853 |
for (m = 0; m < num_elem_in_block[j]; m++) { |
| 854 |
elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value); |
| 855 |
} |
| 856 |
if (k == 1 && j == 2) { |
| 857 |
continue; /* skip element block 3, variable 1 */ |
| 858 |
} |
| 859 |
|
| 860 |
error = ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j], |
| 861 |
elem_var_vals); |
| 862 |
printf("after ex_put_elem_var, error = %d\n", error); |
| 863 |
} |
| 864 |
} |
| 865 |
|
| 866 |
whole_time_step++; |
| 867 |
|
| 868 |
/* update the data file; this should be done at the end of every time step |
| 869 |
* to ensure that no data is lost if the analysis dies |
| 870 |
*/ |
| 871 |
error = ex_update(exoid); |
| 872 |
printf("after ex_update, error = %d\n", error); |
| 873 |
} |
| 874 |
free(glob_var_vals); |
| 875 |
free(nodal_var_vals); |
| 876 |
free(elem_var_vals); |
| 877 |
|
| 878 |
/* close the EXODUS files |
| 879 |
*/ |
| 880 |
error = ex_close(exoid); |
| 881 |
printf("after ex_close, error = %d\n", error); |
| 882 |
return 0; |
| 883 |
} |