| 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 |
* \undoc exgconn - exodusII read edge/face/element block connectivity |
| 11 |
* |
| 12 |
* entry conditions - |
| 13 |
* expelb must be called first to establish element block parameters. |
| 14 |
* input parameters: |
| 15 |
* int exoid exodus file id |
| 16 |
* int blk_type block type (edge, face, element) |
| 17 |
* int blk_id block id |
| 18 |
* |
| 19 |
* exit conditions - |
| 20 |
* int* nodeconn nodal connectivity array |
| 21 |
* int* edgeconn edge connectivity array (where applicable) |
| 22 |
* int* faceconn face connectivity array (where applicable) |
| 23 |
* |
| 24 |
* |
| 25 |
*/ |
| 26 |
#include "exodusII.h" // for ex_err, etc |
| 27 |
#include "exodusII_int.h" // for EX_FATAL, exi_id_lkup, etc |
| 28 |
|
| 29 |
int ex_get_conn(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, void_int *nodeconn, |
| 30 |
void_int *edgeconn, void_int *faceconn) |
| 31 |
{ |
| 32 |
int connid = -1; |
| 33 |
int econnid = -1; |
| 34 |
int fconnid = -1; |
| 35 |
|
| 36 |
int blk_id_ndx, status; |
| 37 |
|
| 38 |
int numnodperentdim = -1; |
| 39 |
int numedgperentdim = -1; |
| 40 |
int numfacperentdim = -1; |
| 41 |
|
| 42 |
size_t num_nodes_per_entry = 0; |
| 43 |
size_t num_edges_per_entry = 0; |
| 44 |
size_t num_faces_per_entry = 0; |
| 45 |
|
| 46 |
char errmsg[MAX_ERR_LENGTH]; |
| 47 |
|
| 48 |
const char *dnumnodent = NULL; |
| 49 |
const char *dnumedgent = NULL; |
| 50 |
const char *dnumfacent = NULL; |
| 51 |
const char *vnodeconn = NULL; |
| 52 |
const char *vedgeconn = NULL; |
| 53 |
const char *vfaceconn = NULL; |
| 54 |
|
| 55 |
EX_FUNC_ENTER(); |
| 56 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 57 |
EX_FUNC_LEAVE(EX_FATAL); |
| 58 |
} |
| 59 |
|
| 60 |
/* Should we warn if edgeconn or faceconn are non-NULL? |
| 61 |
* No, fail silently so the same code can be used to read any type of block |
| 62 |
* info. |
| 63 |
* However, we will warn if edgeconn or faceconn are NULL but |
| 64 |
* num_edges_per_entry |
| 65 |
* or num_faces_per_entry (respectively) are positive. |
| 66 |
*/ |
| 67 |
|
| 68 |
/* Locate index of element block id in VAR_ID_EL_BLK array */ |
| 69 |
|
| 70 |
blk_id_ndx = exi_id_lkup(exoid, blk_type, blk_id); |
| 71 |
if (blk_id_ndx <= 0) { |
| 72 |
ex_get_err(NULL, NULL, &status); |
| 73 |
if (status != 0) { |
| 74 |
if (status == EX_NULLENTITY) { |
| 75 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 76 |
"Warning: no connectivity array for NULL %s %" PRId64 " in file id %d", |
| 77 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 78 |
ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY); |
| 79 |
EX_FUNC_LEAVE(EX_WARN); /* no connectivity array for this element block */ |
| 80 |
} |
| 81 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 82 |
"ERROR: failed to locate %s id %" PRId64 " in id array in file id %d", |
| 83 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 84 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 85 |
EX_FUNC_LEAVE(EX_FATAL); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
switch (blk_type) { |
| 90 |
case EX_EDGE_BLOCK: |
| 91 |
dnumnodent = DIM_NUM_NOD_PER_ED(blk_id_ndx); |
| 92 |
dnumedgent = NULL; |
| 93 |
dnumfacent = NULL; |
| 94 |
vnodeconn = VAR_EBCONN(blk_id_ndx); |
| 95 |
vedgeconn = NULL; |
| 96 |
vfaceconn = NULL; |
| 97 |
break; |
| 98 |
case EX_FACE_BLOCK: |
| 99 |
dnumnodent = DIM_NUM_NOD_PER_FA(blk_id_ndx); |
| 100 |
dnumedgent = NULL; |
| 101 |
dnumfacent = NULL; |
| 102 |
vnodeconn = VAR_FBCONN(blk_id_ndx); |
| 103 |
vedgeconn = NULL; |
| 104 |
vfaceconn = NULL; |
| 105 |
break; |
| 106 |
case EX_ELEM_BLOCK: |
| 107 |
dnumnodent = DIM_NUM_NOD_PER_EL(blk_id_ndx); |
| 108 |
dnumedgent = DIM_NUM_EDG_PER_EL(blk_id_ndx); |
| 109 |
dnumfacent = DIM_NUM_FAC_PER_EL(blk_id_ndx); |
| 110 |
vnodeconn = VAR_CONN(blk_id_ndx); |
| 111 |
vedgeconn = VAR_ECONN(blk_id_ndx); |
| 112 |
vfaceconn = VAR_FCONN(blk_id_ndx); |
| 113 |
break; |
| 114 |
default: |
| 115 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 116 |
"Internal ERROR: unrecognized block type in switch: %d in file id %d", blk_type, |
| 117 |
exoid); |
| 118 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 119 |
EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */ |
| 120 |
} |
| 121 |
/* inquire id's of previously defined dimensions */ |
| 122 |
|
| 123 |
num_nodes_per_entry = 0; |
| 124 |
if (nodeconn && dnumnodent) { |
| 125 |
if ((status = nc_inq_dimid(exoid, dnumnodent, &numnodperentdim)) != NC_NOERR) { |
| 126 |
numnodperentdim = -1; |
| 127 |
} |
| 128 |
else { |
| 129 |
if ((status = nc_inq_dimlen(exoid, numnodperentdim, &num_nodes_per_entry)) != NC_NOERR) { |
| 130 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 131 |
"ERROR: failed to get number of nodes/entity for %s %" PRId64 " in file id %d", |
| 132 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 133 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 134 |
EX_FUNC_LEAVE(EX_FATAL); |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
if (edgeconn && dnumedgent) { |
| 140 |
num_edges_per_entry = 0; |
| 141 |
if ((status = nc_inq_dimid(exoid, dnumedgent, &numedgperentdim)) != NC_NOERR) { |
| 142 |
numedgperentdim = -1; |
| 143 |
} |
| 144 |
else { |
| 145 |
if ((status = nc_inq_dimlen(exoid, numedgperentdim, &num_edges_per_entry)) != NC_NOERR) { |
| 146 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 147 |
"ERROR: failed to get number of edges/entry for %s %" PRId64 " in file id %d", |
| 148 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 149 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 150 |
EX_FUNC_LEAVE(EX_FATAL); |
| 151 |
} |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
if (faceconn && dnumfacent) { |
| 156 |
num_faces_per_entry = 0; |
| 157 |
if ((status = nc_inq_dimid(exoid, dnumfacent, &numfacperentdim)) != NC_NOERR) { |
| 158 |
numfacperentdim = -1; |
| 159 |
} |
| 160 |
else { |
| 161 |
if ((status = nc_inq_dimlen(exoid, numfacperentdim, &num_faces_per_entry)) != NC_NOERR) { |
| 162 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 163 |
"ERROR: failed to get number of faces/entry for %s %" PRId64 " in file id %d", |
| 164 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 165 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 166 |
EX_FUNC_LEAVE(EX_FATAL); |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
status = 0; |
| 172 |
if (nodeconn && (numnodperentdim >= 0) && |
| 173 |
((status = nc_inq_varid(exoid, vnodeconn, &connid)) != NC_NOERR)) { |
| 174 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 175 |
"ERROR: failed to locate node connectivity array for %s %" PRId64 " in file id %d", |
| 176 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 177 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 178 |
EX_FUNC_LEAVE(EX_FATAL); |
| 179 |
} |
| 180 |
|
| 181 |
status = 0; |
| 182 |
if (edgeconn && (numedgperentdim >= 0) && |
| 183 |
((status = nc_inq_varid(exoid, vedgeconn, &econnid)) != NC_NOERR)) { |
| 184 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 185 |
"ERROR: failed to locate edge connectivity array for %s %" PRId64 " in file id %d", |
| 186 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 187 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 188 |
EX_FUNC_LEAVE(EX_FATAL); |
| 189 |
} |
| 190 |
|
| 191 |
if (faceconn && (numfacperentdim >= 0) && |
| 192 |
((status = nc_inq_varid(exoid, vfaceconn, &fconnid)) != NC_NOERR)) { |
| 193 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 194 |
"ERROR: failed to locate face connectivity array for %s %" PRId64 " in file id %d", |
| 195 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 196 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 197 |
EX_FUNC_LEAVE(EX_FATAL); |
| 198 |
} |
| 199 |
|
| 200 |
/* read in the connectivity array */ |
| 201 |
if (edgeconn && num_edges_per_entry > 0) { |
| 202 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 203 |
status = nc_get_var_longlong(exoid, econnid, edgeconn); |
| 204 |
} |
| 205 |
else { |
| 206 |
status = nc_get_var_int(exoid, econnid, edgeconn); |
| 207 |
} |
| 208 |
|
| 209 |
if (status != NC_NOERR) { |
| 210 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 211 |
"ERROR: failed to get edge connectivity array for %s %" PRId64 " in file id %d", |
| 212 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 213 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 214 |
EX_FUNC_LEAVE(EX_FATAL); |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
if (faceconn && num_faces_per_entry > 0) { |
| 219 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 220 |
status = nc_get_var_longlong(exoid, fconnid, faceconn); |
| 221 |
} |
| 222 |
else { |
| 223 |
status = nc_get_var_int(exoid, fconnid, faceconn); |
| 224 |
} |
| 225 |
|
| 226 |
if (status != NC_NOERR) { |
| 227 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 228 |
"ERROR: failed to get face connectivity array for %s %" PRId64 " in file id %d", |
| 229 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 230 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 231 |
EX_FUNC_LEAVE(EX_FATAL); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
if (nodeconn && num_nodes_per_entry > 0) { |
| 236 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 237 |
status = nc_get_var_longlong(exoid, connid, nodeconn); |
| 238 |
} |
| 239 |
else { |
| 240 |
status = nc_get_var_int(exoid, connid, nodeconn); |
| 241 |
} |
| 242 |
|
| 243 |
if (status != NC_NOERR) { |
| 244 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 245 |
"ERROR: failed to get node connectivity array for %s %" PRId64 " in file id %d", |
| 246 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 247 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 248 |
EX_FUNC_LEAVE(EX_FATAL); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
EX_FUNC_LEAVE(EX_NOERR); |
| 253 |
} |