Exodus 8.24
Loading...
Searching...
No Matches
/test/testrd-nfaced.c
/*
* Copyright(C) 1999-2021 National Technology & Engineering Solutions
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
* NTESS, the U.S. Government retains certain rights in this software.
*
* See packages/seacas/LICENSE for details
*/
/*****************************************************************************
*
* testrd - read exodus file test-nsided.exo created by testwt-nsided
*
*****************************************************************************/
#include "exodusII.h"
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
int num_dim, num_nodes, num_elem_blk;
int *num_elem_in_block, *num_face_in_block, *num_nodes_per_elem, *num_edges_per_elem,
*num_faces_per_elem, *num_attr;
int error, nnodes;
int i, j, k;
int *connect, *fconnect;
int *ids, *nnpe, *nnpf;
int num_qa_rec, num_info;
int CPU_word_size, IO_word_size;
int idum;
float *x, *y, *z;
float version, fdum;
char *coord_names[3], *qa_record[2][4], *info[3];
char *block_names[10];
char *elem_type[10];
char *cdum = NULL;
CPU_word_size = 0; /* sizeof(float) */
IO_word_size = 0; /* use what is stored in file */
/* open EXODUS II files */
int exoid = ex_open("test-nfaced.exo", /* filename path */
EX_READ, /* access mode = READ */
&CPU_word_size, /* CPU word size */
&IO_word_size, /* IO word size */
&version); /* ExodusII library version */
printf("\nafter ex_open\n");
if (exoid < 0) {
exit(1);
}
printf("test.exo is an EXODUSII file; version %4.2f\n", version);
printf(" I/O word size %1d\n", IO_word_size);
ex_inquire(exoid, EX_INQ_LIB_VERS, &idum, &version, cdum);
printf("EXODUSII Library API; version %4.2f (%d)\n", version, idum);
/* read database parameters */
{
error = ex_get_init_ext(exoid, &par);
printf("after ex_get_init, error = %3d\n", error);
printf("database parameters:\n");
printf("title = '%s'\n", par.title);
printf("num_dim = %" PRId64 "\n", par.num_dim);
printf("num_nodes = %" PRId64 "\n", par.num_nodes);
printf("num_edge = %" PRId64 "\n", par.num_edge);
printf("num_face = %" PRId64 "\n", par.num_face);
printf("num_elem = %" PRId64 "\n", par.num_elem);
printf("num_elem_blk = %" PRId64 "\n", par.num_elem_blk);
printf("num_node_sets = %" PRId64 "\n", par.num_node_sets);
printf("num_side_sets = %" PRId64 "\n", par.num_side_sets);
num_dim = par.num_dim;
num_nodes = par.num_nodes;
num_elem_blk = par.num_elem_blk;
}
assert(num_dim == 3);
/* read nodal coordinates values and names from database */
x = (float *)calloc(num_nodes, sizeof(float));
y = (float *)calloc(num_nodes, sizeof(float));
z = (float *)calloc(num_nodes, sizeof(float));
error = ex_get_coord(exoid, x, y, z);
printf("\nafter ex_get_coord, error = %3d\n", error);
printf("x, y, z coords = \n");
for (i = 0; i < num_nodes; i++) {
printf("%5.1f\t%5.1f\t%5.1f\n", x[i], y[i], z[i]);
}
free(x);
free(y);
free(z);
for (i = 0; i < num_dim; i++) {
coord_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
}
error = ex_get_coord_names(exoid, coord_names);
printf("\nafter ex_get_coord_names, error = %3d\n", error);
printf("x coord name = '%s'\n", coord_names[0]);
printf("y coord name = '%s'\n", coord_names[1]);
printf("z coord name = '%s'\n", coord_names[2]);
for (i = 0; i < num_dim; i++) {
free(coord_names[i]);
}
/* read element block parameters */
if (num_elem_blk > 0) {
ids = (int *)calloc(num_elem_blk, sizeof(int));
num_elem_in_block = (int *)calloc(num_elem_blk, sizeof(int));
num_face_in_block = (int *)calloc(num_elem_blk, sizeof(int));
num_nodes_per_elem = (int *)calloc(num_elem_blk, sizeof(int));
num_edges_per_elem = (int *)calloc(num_elem_blk, sizeof(int));
num_faces_per_elem = (int *)calloc(num_elem_blk, sizeof(int));
num_attr = (int *)calloc(num_elem_blk, sizeof(int));
for (i = 0; i < num_elem_blk; i++) {
elem_type[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
block_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
}
error = ex_get_ids(exoid, EX_ELEM_BLOCK, ids);
printf("\nafter ex_get_elem_blk_ids, error = %3d\n", error);
error = ex_get_names(exoid, EX_ELEM_BLOCK, block_names);
printf("\nafter ex_get_names, error = %3d\n", error);
for (i = 0; i < num_elem_blk; i++) {
char name[MAX_STR_LENGTH + 1];
ex_get_name(exoid, EX_ELEM_BLOCK, ids[i], name);
if (strcmp(name, block_names[i]) != 0) {
printf("error in ex_get_name for block id %d\n", ids[i]);
}
error = ex_get_block(exoid, EX_ELEM_BLOCK, ids[i], elem_type[i], &(num_elem_in_block[i]),
&(num_nodes_per_elem[i]), &(num_edges_per_elem[i]),
&(num_faces_per_elem[i]), &(num_attr[i]));
printf("\nafter ex_get_elem_block, error = %d\n", error);
printf("element block id = %2d\n", ids[i]);
printf("element block type = '%s'\n", elem_type[i]);
printf("num_elem_in_block = %2d\n", num_elem_in_block[i]);
printf("num_total_nodes_per_block = %2d\n", num_nodes_per_elem[i]);
printf("num_total_edges_per_block = %2d\n", num_edges_per_elem[i]);
printf("num_total_faces_per_block = %2d\n", num_faces_per_elem[i]);
printf("num_attr = %2d\n", num_attr[i]);
printf("name = '%s'\n", block_names[i]);
}
}
/* read connectivity */
for (i = 0; i < num_elem_blk; i++) {
if (num_elem_in_block[i] > 0) {
if (strcmp(elem_type[i], "NFACED") == 0 || strcmp(elem_type[i], "nfaced") == 0) {
int nfaces = 0;
connect = (int *)calloc((num_faces_per_elem[i]), sizeof(int));
nnpe = (int *)calloc(num_elem_in_block[i], sizeof(int));
error = ex_get_entity_count_per_polyhedra(exoid, EX_ELEM_BLOCK, ids[i], nnpe);
printf("\nafter ex_get_entity_count_per_polyhedra, error = %d\n", error);
for (j = 0; j < num_elem_in_block[i]; j++) {
nfaces += nnpe[j];
}
assert(nfaces == num_faces_per_elem[i]);
error = ex_get_conn(exoid, EX_ELEM_BLOCK, ids[i], NULL, NULL, connect);
printf("\nafter ex_get_conn, error = %d\n", error);
printf("face connectivity array for elem block %2d\n", ids[i]);
nfaces = 0;
for (j = 0; j < num_elem_in_block[i]; j++) {
printf("Element %d, %d faces:\t", j + 1, nnpe[j]);
for (k = 0; k < nnpe[j]; k++) {
printf("%3d ", connect[nfaces + k]);
}
printf("\n");
nfaces += nnpe[j];
}
/* Now get the faces and their connectivity... */
/*
* Convention is that the faces for an nfaced block are in a
* face block which has the same id as the element block...
* (Or, at least let's try that for awhile and see if it works...)
*/
/* NOTE: We are overwriting the element block data here... */
error = ex_get_block(exoid, EX_FACE_BLOCK, ids[i], elem_type[i], &(num_face_in_block[i]),
&(num_nodes_per_elem[i]), NULL, NULL, &(num_attr[i]));
printf("\nafter ex_get_block (EX_FACE_BLOCK), error = %d\n", error);
error = ex_get_names(exoid, EX_FACE_BLOCK, block_names);
printf("\nafter ex_get_names, error = %3d\n", error);
printf("\tface block id = %2d\n", ids[i]);
printf("\tface block type = '%s'\n", elem_type[i]);
printf("\tnum_face_in_block = %2d\n", num_face_in_block[i]);
printf("\tnum_total_nodes_per_block = %2d\n", num_nodes_per_elem[i]);
printf("\tnum_attr = %2d\n", num_attr[i]);
printf("\tname = '%s'\n", block_names[i]);
fconnect = (int *)calloc((num_nodes_per_elem[i]), sizeof(int));
nnpf = (int *)calloc(num_face_in_block[i], sizeof(int));
error = ex_get_entity_count_per_polyhedra(exoid, EX_FACE_BLOCK, ids[i], nnpf);
printf("\nafter ex_get_entity_count_per_polyhedra, error = %d\n", error);
nnodes = 0;
for (j = 0; j < num_face_in_block[i]; j++) {
nnodes += nnpf[j];
}
assert(nnodes == num_nodes_per_elem[i]);
error = ex_get_conn(exoid, EX_FACE_BLOCK, ids[i], fconnect, NULL, NULL);
printf("\nafter ex_get_conn, error = %d\n", error);
printf("node connectivity array for face block %2d\n", ids[i]);
nnodes = 0;
for (j = 0; j < num_face_in_block[i]; j++) {
printf("Face %d, %d nodes:\t", j + 1, nnpf[j]);
for (k = 0; k < nnpf[j]; k++) {
printf("%3d ", fconnect[nnodes + k]);
}
printf("\n");
nnodes += nnpf[j];
}
free(fconnect);
free(nnpe);
free(nnpf);
}
else {
connect = (int *)calloc((num_nodes_per_elem[i] * num_elem_in_block[i]), sizeof(int));
error = ex_get_conn(exoid, EX_ELEM_BLOCK, ids[i], connect, NULL, NULL);
printf("\nafter ex_get_conn, error = %d\n", error);
printf("connect array for elem block %2d\n", ids[i]);
for (j = 0; j < num_nodes_per_elem[i]; j++) {
printf("%3d\n", connect[j]);
}
}
free(connect);
}
}
for (i = 0; i < num_elem_blk; i++) {
free(elem_type[i]);
free(block_names[i]);
}
if (num_elem_blk > 0) {
free(ids);
free(num_nodes_per_elem);
free(num_edges_per_elem);
free(num_faces_per_elem);
free(num_elem_in_block);
free(num_face_in_block);
free(num_attr);
}
/* read QA records */
ex_inquire(exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum);
for (i = 0; i < num_qa_rec; i++) {
for (j = 0; j < 4; j++) {
qa_record[i][j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
}
}
error = ex_get_qa(exoid, qa_record);
printf("\nafter ex_get_qa, error = %3d\n", error);
printf("QA records = \n");
for (i = 0; i < num_qa_rec; i++) {
for (j = 0; j < 4; j++) {
printf(" '%s'\n", qa_record[i][j]);
free(qa_record[i][j]);
}
}
/* read information records */
error = ex_inquire(exoid, EX_INQ_INFO, &num_info, &fdum, cdum);
printf("\nafter ex_inquire, error = %3d\n", error);
for (i = 0; i < num_info; i++) {
info[i] = (char *)calloc((MAX_LINE_LENGTH + 1), sizeof(char));
}
error = ex_get_info(exoid, info);
printf("\nafter ex_get_info, error = %3d\n", error);
printf("info records = \n");
for (i = 0; i < num_info; i++) {
printf(" '%s'\n", info[i]);
free(info[i]);
}
error = ex_close(exoid);
printf("\nafter ex_close, error = %3d\n", error);
return 0;
}
@ EX_FACE_BLOCK
Definition exodusII.h:273
@ EX_ELEM_BLOCK
Definition exodusII.h:275
@ EX_ABORT
Definition exodusII.h:392
@ EX_VERBOSE
Definition exodusII.h:390
@ EX_INQ_INFO
Definition exodusII.h:158
@ EX_INQ_LIB_VERS
Definition exodusII.h:165
@ EX_INQ_QA
Definition exodusII.h:157
#define EX_READ
Definition exodusII.h:98
int ex_get_coord_names(int exoid, char **coord_names)
Definition ex_get_coord_names.c:46
int ex_get_coord(int exoid, void *x_coor, void *y_coor, void *z_coor)
Definition ex_get_coord.c:71
int ex_get_names(int exoid, ex_entity_type obj_type, char **names)
Definition ex_get_names.c:32
int ex_get_init_ext(int exoid, ex_init_params *info)
Definition ex_get_init_ext.c:81
int ex_get_block(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, char *elem_type, void_int *num_entries_this_blk, void_int *num_nodes_per_entry, void_int *num_edges_per_entry, void_int *num_faces_per_entry, void_int *num_attr_per_entry)
Definition ex_get_block.c:36
int ex_get_entity_count_per_polyhedra(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, int *entity_counts)
Definition ex_get_entity_count_per_polyhedra.c:26
int ex_get_ids(int exoid, ex_entity_type obj_type, void_int *ids)
Definition ex_get_ids.c:101
int ex_get_name(int exoid, ex_entity_type obj_type, ex_entity_id entity_id, char *name)
Definition ex_get_name.c:33
int ex_get_conn(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, void_int *nodeconn, void_int *edgeconn, void_int *faceconn)
Definition ex_get_conn.c:29
#define MAX_STR_LENGTH
Definition exodusII.h:409
#define MAX_LINE_LENGTH
Definition exodusII.h:415
int ex_get_info(int exoid, char **info)
Definition ex_get_info.c:48
int ex_opts(int options)
Definition ex_opts.c:56
int ex_inquire(int exoid, ex_inquiry req_info, void_int *ret_int, float *ret_float, char *ret_char)
Definition ex_inquire.c:1095
#define ex_open(path, mode, comp_ws, io_ws, version)
Definition exodusII.h:597
int ex_close(int exoid)
Definition ex_close.c:47
int ex_get_qa(int exoid, char *qa_record[][4])
Definition ex_get_qa.c:56
Definition exodusII.h:438
int64_t num_edge
Definition exodusII.h:442
int64_t num_node_sets
Definition exodusII.h:448
int64_t num_face
Definition exodusII.h:444
int64_t num_nodes
Definition exodusII.h:441
int64_t num_dim
Definition exodusII.h:440
int64_t num_elem
Definition exodusII.h:446
int64_t num_elem_blk
Definition exodusII.h:447
int64_t num_side_sets
Definition exodusII.h:451
char title[MAX_LINE_LENGTH+1]
Definition exodusII.h:439