| 1 |
/* |
| 2 |
* Copyright(C) 1999-2021 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 |
* testrd - read exodus file test-nsided.exo created by testwt-nsided |
| 11 |
* |
| 12 |
*****************************************************************************/ |
| 13 |
|
| 14 |
#include "exodusII.h" |
| 15 |
#include <assert.h> |
| 16 |
#include <inttypes.h> |
| 17 |
#include <stdio.h> |
| 18 |
#include <stdlib.h> |
| 19 |
#include <string.h> |
| 20 |
|
| 21 |
int main(int argc, char **argv) |
| 22 |
{ |
| 23 |
int num_dim, num_nodes, num_elem_blk; |
| 24 |
int *num_elem_in_block, *num_face_in_block, *num_nodes_per_elem, *num_edges_per_elem, |
| 25 |
*num_faces_per_elem, *num_attr; |
| 26 |
int error, nnodes; |
| 27 |
int i, j, k; |
| 28 |
int *connect, *fconnect; |
| 29 |
int *ids, *nnpe, *nnpf; |
| 30 |
int num_qa_rec, num_info; |
| 31 |
int CPU_word_size, IO_word_size; |
| 32 |
int idum; |
| 33 |
|
| 34 |
float *x, *y, *z; |
| 35 |
float version, fdum; |
| 36 |
|
| 37 |
char *coord_names[3], *qa_record[2][4], *info[3]; |
| 38 |
char *block_names[10]; |
| 39 |
char *elem_type[10]; |
| 40 |
char *cdum = NULL; |
| 41 |
|
| 42 |
CPU_word_size = 0; /* sizeof(float) */ |
| 43 |
IO_word_size = 0; /* use what is stored in file */ |
| 44 |
|
| 45 |
ex_opts(EX_VERBOSE | EX_ABORT); |
| 46 |
|
| 47 |
/* open EXODUS II files */ |
| 48 |
int exoid = ex_open("test-nfaced.exo", /* filename path */ |
| 49 |
EX_READ, /* access mode = READ */ |
| 50 |
&CPU_word_size, /* CPU word size */ |
| 51 |
&IO_word_size, /* IO word size */ |
| 52 |
&version); /* ExodusII library version */ |
| 53 |
|
| 54 |
printf("\nafter ex_open\n"); |
| 55 |
if (exoid < 0) { |
| 56 |
exit(1); |
| 57 |
} |
| 58 |
|
| 59 |
printf("test.exo is an EXODUSII file; version %4.2f\n", version); |
| 60 |
printf(" I/O word size %1d\n", IO_word_size); |
| 61 |
|
| 62 |
ex_inquire(exoid, EX_INQ_LIB_VERS, &idum, &version, cdum); |
| 63 |
printf("EXODUSII Library API; version %4.2f (%d)\n", version, idum); |
| 64 |
|
| 65 |
/* read database parameters */ |
| 66 |
{ |
| 67 |
ex_init_params par; |
| 68 |
error = ex_get_init_ext(exoid, &par); |
| 69 |
|
| 70 |
printf("after ex_get_init, error = %3d\n", error); |
| 71 |
|
| 72 |
printf("database parameters:\n"); |
| 73 |
printf("title = '%s'\n", par.title); |
| 74 |
printf("num_dim = %" PRId64 "\n", par.num_dim); |
| 75 |
printf("num_nodes = %" PRId64 "\n", par.num_nodes); |
| 76 |
printf("num_edge = %" PRId64 "\n", par.num_edge); |
| 77 |
printf("num_face = %" PRId64 "\n", par.num_face); |
| 78 |
printf("num_elem = %" PRId64 "\n", par.num_elem); |
| 79 |
printf("num_elem_blk = %" PRId64 "\n", par.num_elem_blk); |
| 80 |
printf("num_node_sets = %" PRId64 "\n", par.num_node_sets); |
| 81 |
printf("num_side_sets = %" PRId64 "\n", par.num_side_sets); |
| 82 |
|
| 83 |
num_dim = par.num_dim; |
| 84 |
num_nodes = par.num_nodes; |
| 85 |
num_elem_blk = par.num_elem_blk; |
| 86 |
} |
| 87 |
|
| 88 |
assert(num_dim == 3); |
| 89 |
|
| 90 |
/* read nodal coordinates values and names from database */ |
| 91 |
|
| 92 |
x = (float *)calloc(num_nodes, sizeof(float)); |
| 93 |
y = (float *)calloc(num_nodes, sizeof(float)); |
| 94 |
z = (float *)calloc(num_nodes, sizeof(float)); |
| 95 |
|
| 96 |
error = ex_get_coord(exoid, x, y, z); |
| 97 |
printf("\nafter ex_get_coord, error = %3d\n", error); |
| 98 |
|
| 99 |
printf("x, y, z coords = \n"); |
| 100 |
for (i = 0; i < num_nodes; i++) { |
| 101 |
printf("%5.1f\t%5.1f\t%5.1f\n", x[i], y[i], z[i]); |
| 102 |
} |
| 103 |
|
| 104 |
free(x); |
| 105 |
free(y); |
| 106 |
free(z); |
| 107 |
|
| 108 |
for (i = 0; i < num_dim; i++) { |
| 109 |
coord_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); |
| 110 |
} |
| 111 |
|
| 112 |
error = ex_get_coord_names(exoid, coord_names); |
| 113 |
printf("\nafter ex_get_coord_names, error = %3d\n", error); |
| 114 |
|
| 115 |
printf("x coord name = '%s'\n", coord_names[0]); |
| 116 |
printf("y coord name = '%s'\n", coord_names[1]); |
| 117 |
printf("z coord name = '%s'\n", coord_names[2]); |
| 118 |
|
| 119 |
for (i = 0; i < num_dim; i++) { |
| 120 |
free(coord_names[i]); |
| 121 |
} |
| 122 |
|
| 123 |
/* read element block parameters */ |
| 124 |
if (num_elem_blk > 0) { |
| 125 |
ids = (int *)calloc(num_elem_blk, sizeof(int)); |
| 126 |
num_elem_in_block = (int *)calloc(num_elem_blk, sizeof(int)); |
| 127 |
num_face_in_block = (int *)calloc(num_elem_blk, sizeof(int)); |
| 128 |
num_nodes_per_elem = (int *)calloc(num_elem_blk, sizeof(int)); |
| 129 |
num_edges_per_elem = (int *)calloc(num_elem_blk, sizeof(int)); |
| 130 |
num_faces_per_elem = (int *)calloc(num_elem_blk, sizeof(int)); |
| 131 |
num_attr = (int *)calloc(num_elem_blk, sizeof(int)); |
| 132 |
|
| 133 |
for (i = 0; i < num_elem_blk; i++) { |
| 134 |
elem_type[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); |
| 135 |
block_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); |
| 136 |
} |
| 137 |
|
| 138 |
error = ex_get_ids(exoid, EX_ELEM_BLOCK, ids); |
| 139 |
printf("\nafter ex_get_elem_blk_ids, error = %3d\n", error); |
| 140 |
|
| 141 |
error = ex_get_names(exoid, EX_ELEM_BLOCK, block_names); |
| 142 |
printf("\nafter ex_get_names, error = %3d\n", error); |
| 143 |
|
| 144 |
for (i = 0; i < num_elem_blk; i++) { |
| 145 |
char name[MAX_STR_LENGTH + 1]; |
| 146 |
ex_get_name(exoid, EX_ELEM_BLOCK, ids[i], name); |
| 147 |
if (strcmp(name, block_names[i]) != 0) { |
| 148 |
printf("error in ex_get_name for block id %d\n", ids[i]); |
| 149 |
} |
| 150 |
error = ex_get_block(exoid, EX_ELEM_BLOCK, ids[i], elem_type[i], &(num_elem_in_block[i]), |
| 151 |
&(num_nodes_per_elem[i]), &(num_edges_per_elem[i]), |
| 152 |
&(num_faces_per_elem[i]), &(num_attr[i])); |
| 153 |
printf("\nafter ex_get_elem_block, error = %d\n", error); |
| 154 |
|
| 155 |
printf("element block id = %2d\n", ids[i]); |
| 156 |
printf("element block type = '%s'\n", elem_type[i]); |
| 157 |
printf("num_elem_in_block = %2d\n", num_elem_in_block[i]); |
| 158 |
printf("num_total_nodes_per_block = %2d\n", num_nodes_per_elem[i]); |
| 159 |
printf("num_total_edges_per_block = %2d\n", num_edges_per_elem[i]); |
| 160 |
printf("num_total_faces_per_block = %2d\n", num_faces_per_elem[i]); |
| 161 |
printf("num_attr = %2d\n", num_attr[i]); |
| 162 |
printf("name = '%s'\n", block_names[i]); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
/* read connectivity */ |
| 167 |
for (i = 0; i < num_elem_blk; i++) { |
| 168 |
if (num_elem_in_block[i] > 0) { |
| 169 |
if (strcmp(elem_type[i], "NFACED") == 0 || strcmp(elem_type[i], "nfaced") == 0) { |
| 170 |
int nfaces = 0; |
| 171 |
connect = (int *)calloc((num_faces_per_elem[i]), sizeof(int)); |
| 172 |
|
| 173 |
nnpe = (int *)calloc(num_elem_in_block[i], sizeof(int)); |
| 174 |
error = ex_get_entity_count_per_polyhedra(exoid, EX_ELEM_BLOCK, ids[i], nnpe); |
| 175 |
printf("\nafter ex_get_entity_count_per_polyhedra, error = %d\n", error); |
| 176 |
|
| 177 |
for (j = 0; j < num_elem_in_block[i]; j++) { |
| 178 |
nfaces += nnpe[j]; |
| 179 |
} |
| 180 |
assert(nfaces == num_faces_per_elem[i]); |
| 181 |
|
| 182 |
error = ex_get_conn(exoid, EX_ELEM_BLOCK, ids[i], NULL, NULL, connect); |
| 183 |
printf("\nafter ex_get_conn, error = %d\n", error); |
| 184 |
|
| 185 |
printf("face connectivity array for elem block %2d\n", ids[i]); |
| 186 |
nfaces = 0; |
| 187 |
for (j = 0; j < num_elem_in_block[i]; j++) { |
| 188 |
printf("Element %d, %d faces:\t", j + 1, nnpe[j]); |
| 189 |
for (k = 0; k < nnpe[j]; k++) { |
| 190 |
printf("%3d ", connect[nfaces + k]); |
| 191 |
} |
| 192 |
printf("\n"); |
| 193 |
nfaces += nnpe[j]; |
| 194 |
} |
| 195 |
|
| 196 |
/* Now get the faces and their connectivity... */ |
| 197 |
/* |
| 198 |
* Convention is that the faces for an nfaced block are in a |
| 199 |
* face block which has the same id as the element block... |
| 200 |
* (Or, at least let's try that for awhile and see if it works...) |
| 201 |
*/ |
| 202 |
|
| 203 |
/* NOTE: We are overwriting the element block data here... */ |
| 204 |
error = ex_get_block(exoid, EX_FACE_BLOCK, ids[i], elem_type[i], &(num_face_in_block[i]), |
| 205 |
&(num_nodes_per_elem[i]), NULL, NULL, &(num_attr[i])); |
| 206 |
|
| 207 |
printf("\nafter ex_get_block (EX_FACE_BLOCK), error = %d\n", error); |
| 208 |
|
| 209 |
error = ex_get_names(exoid, EX_FACE_BLOCK, block_names); |
| 210 |
printf("\nafter ex_get_names, error = %3d\n", error); |
| 211 |
|
| 212 |
printf("\tface block id = %2d\n", ids[i]); |
| 213 |
printf("\tface block type = '%s'\n", elem_type[i]); |
| 214 |
printf("\tnum_face_in_block = %2d\n", num_face_in_block[i]); |
| 215 |
printf("\tnum_total_nodes_per_block = %2d\n", num_nodes_per_elem[i]); |
| 216 |
printf("\tnum_attr = %2d\n", num_attr[i]); |
| 217 |
printf("\tname = '%s'\n", block_names[i]); |
| 218 |
|
| 219 |
fconnect = (int *)calloc((num_nodes_per_elem[i]), sizeof(int)); |
| 220 |
nnpf = (int *)calloc(num_face_in_block[i], sizeof(int)); |
| 221 |
error = ex_get_entity_count_per_polyhedra(exoid, EX_FACE_BLOCK, ids[i], nnpf); |
| 222 |
printf("\nafter ex_get_entity_count_per_polyhedra, error = %d\n", error); |
| 223 |
|
| 224 |
nnodes = 0; |
| 225 |
for (j = 0; j < num_face_in_block[i]; j++) { |
| 226 |
nnodes += nnpf[j]; |
| 227 |
} |
| 228 |
assert(nnodes == num_nodes_per_elem[i]); |
| 229 |
|
| 230 |
error = ex_get_conn(exoid, EX_FACE_BLOCK, ids[i], fconnect, NULL, NULL); |
| 231 |
printf("\nafter ex_get_conn, error = %d\n", error); |
| 232 |
|
| 233 |
printf("node connectivity array for face block %2d\n", ids[i]); |
| 234 |
nnodes = 0; |
| 235 |
for (j = 0; j < num_face_in_block[i]; j++) { |
| 236 |
printf("Face %d, %d nodes:\t", j + 1, nnpf[j]); |
| 237 |
for (k = 0; k < nnpf[j]; k++) { |
| 238 |
printf("%3d ", fconnect[nnodes + k]); |
| 239 |
} |
| 240 |
printf("\n"); |
| 241 |
nnodes += nnpf[j]; |
| 242 |
} |
| 243 |
free(fconnect); |
| 244 |
free(nnpe); |
| 245 |
free(nnpf); |
| 246 |
} |
| 247 |
else { |
| 248 |
connect = (int *)calloc((num_nodes_per_elem[i] * num_elem_in_block[i]), sizeof(int)); |
| 249 |
error = ex_get_conn(exoid, EX_ELEM_BLOCK, ids[i], connect, NULL, NULL); |
| 250 |
printf("\nafter ex_get_conn, error = %d\n", error); |
| 251 |
|
| 252 |
printf("connect array for elem block %2d\n", ids[i]); |
| 253 |
|
| 254 |
for (j = 0; j < num_nodes_per_elem[i]; j++) { |
| 255 |
printf("%3d\n", connect[j]); |
| 256 |
} |
| 257 |
} |
| 258 |
free(connect); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
for (i = 0; i < num_elem_blk; i++) { |
| 263 |
free(elem_type[i]); |
| 264 |
free(block_names[i]); |
| 265 |
} |
| 266 |
if (num_elem_blk > 0) { |
| 267 |
|
| 268 |
free(ids); |
| 269 |
free(num_nodes_per_elem); |
| 270 |
free(num_edges_per_elem); |
| 271 |
free(num_faces_per_elem); |
| 272 |
free(num_elem_in_block); |
| 273 |
free(num_face_in_block); |
| 274 |
free(num_attr); |
| 275 |
} |
| 276 |
|
| 277 |
/* read QA records */ |
| 278 |
ex_inquire(exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum); |
| 279 |
|
| 280 |
for (i = 0; i < num_qa_rec; i++) { |
| 281 |
for (j = 0; j < 4; j++) { |
| 282 |
qa_record[i][j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
error = ex_get_qa(exoid, qa_record); |
| 287 |
printf("\nafter ex_get_qa, error = %3d\n", error); |
| 288 |
|
| 289 |
printf("QA records = \n"); |
| 290 |
for (i = 0; i < num_qa_rec; i++) { |
| 291 |
for (j = 0; j < 4; j++) { |
| 292 |
printf(" '%s'\n", qa_record[i][j]); |
| 293 |
free(qa_record[i][j]); |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
/* read information records */ |
| 298 |
|
| 299 |
error = ex_inquire(exoid, EX_INQ_INFO, &num_info, &fdum, cdum); |
| 300 |
printf("\nafter ex_inquire, error = %3d\n", error); |
| 301 |
|
| 302 |
for (i = 0; i < num_info; i++) { |
| 303 |
info[i] = (char *)calloc((MAX_LINE_LENGTH + 1), sizeof(char)); |
| 304 |
} |
| 305 |
|
| 306 |
error = ex_get_info(exoid, info); |
| 307 |
printf("\nafter ex_get_info, error = %3d\n", error); |
| 308 |
|
| 309 |
printf("info records = \n"); |
| 310 |
for (i = 0; i < num_info; i++) { |
| 311 |
printf(" '%s'\n", info[i]); |
| 312 |
free(info[i]); |
| 313 |
} |
| 314 |
|
| 315 |
error = ex_close(exoid); |
| 316 |
printf("\nafter ex_close, error = %3d\n", error); |
| 317 |
return 0; |
| 318 |
} |