| 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 |
* exgnconn - exodusII read partial 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 |
* int start_num The starting index (1-based) of entities to read |
| 19 |
* int num_ent The number of entities to read connectivity info |
| 20 |
* for. |
| 21 |
* |
| 22 |
* exit conditions - |
| 23 |
* int* nodeconn nodal connectivity array |
| 24 |
* int* edgeconn edge connectivity array (where applicable) |
| 25 |
* int* faceconn face connectivity array (where applicable) |
| 26 |
* |
| 27 |
* revision history - |
| 28 |
* |
| 29 |
*/ |
| 30 |
|
| 31 |
#include "exodusII.h" // for ex_err, ex_name_of_object, etc |
| 32 |
#include "exodusII_int.h" // for exi_check_valid_file_id, etc |
| 33 |
|
| 34 |
/* |
| 35 |
* reads the connectivity array for an element block |
| 36 |
*/ |
| 37 |
|
| 38 |
int ex_get_partial_conn(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, int64_t start_num, |
| 39 |
int64_t num_ent, void_int *nodeconn, void_int *edgeconn, void_int *faceconn) |
| 40 |
{ |
| 41 |
int connid = -1; |
| 42 |
int econnid = -1; |
| 43 |
int fconnid = -1; |
| 44 |
|
| 45 |
int blk_id_ndx; |
| 46 |
int status = 0; |
| 47 |
|
| 48 |
int numnodperentdim = -1; |
| 49 |
int numedgperentdim = -1; |
| 50 |
int numfacperentdim = -1; |
| 51 |
|
| 52 |
size_t num_nodes_per_entry = 0; |
| 53 |
size_t num_edges_per_entry = 0; |
| 54 |
size_t num_faces_per_entry = 0; |
| 55 |
char errmsg[MAX_ERR_LENGTH]; |
| 56 |
|
| 57 |
const char *dnumnodent = NULL; |
| 58 |
const char *dnumedgent = NULL; |
| 59 |
const char *dnumfacent = NULL; |
| 60 |
const char *vnodeconn = NULL; |
| 61 |
const char *vedgeconn = NULL; |
| 62 |
const char *vfaceconn = NULL; |
| 63 |
|
| 64 |
EX_FUNC_ENTER(); |
| 65 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 66 |
EX_FUNC_LEAVE(EX_FATAL); |
| 67 |
} |
| 68 |
|
| 69 |
/* The partial connectivity input function can currently only handle nodal |
| 70 |
* connectivity. Print a warning if edgeconn or faceconn is non-NULL |
| 71 |
*/ |
| 72 |
if (edgeconn != NULL || faceconn != NULL) { |
| 73 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 74 |
"Warning: ex_get_partial_conn only supports nodal " |
| 75 |
"connectivity at this time. %s %" PRId64 " in file id %d", |
| 76 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 77 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 78 |
} |
| 79 |
|
| 80 |
/* Locate index of element block id in VAR_ID_EL_BLK array */ |
| 81 |
|
| 82 |
blk_id_ndx = exi_id_lkup(exoid, blk_type, blk_id); |
| 83 |
if (blk_id_ndx <= 0) { |
| 84 |
ex_get_err(NULL, NULL, &status); |
| 85 |
|
| 86 |
if (status != 0) { |
| 87 |
if (status == EX_NULLENTITY) { |
| 88 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 89 |
"Warning: no connectivity array for NULL %s %" PRId64 " in file id %d", |
| 90 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 91 |
ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY); |
| 92 |
EX_FUNC_LEAVE(EX_WARN); /* no connectivity array for this element block */ |
| 93 |
} |
| 94 |
|
| 95 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 96 |
"ERROR: failed to locate %s id %" PRId64 " in id array in file id %d", |
| 97 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 98 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 99 |
EX_FUNC_LEAVE(EX_FATAL); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
switch (blk_type) { |
| 104 |
case EX_EDGE_BLOCK: |
| 105 |
dnumnodent = DIM_NUM_NOD_PER_ED(blk_id_ndx); |
| 106 |
dnumedgent = NULL; |
| 107 |
dnumfacent = NULL; |
| 108 |
vnodeconn = VAR_EBCONN(blk_id_ndx); |
| 109 |
vedgeconn = NULL; |
| 110 |
vfaceconn = NULL; |
| 111 |
break; |
| 112 |
case EX_FACE_BLOCK: |
| 113 |
dnumnodent = DIM_NUM_NOD_PER_FA(blk_id_ndx); |
| 114 |
dnumedgent = NULL; |
| 115 |
dnumfacent = NULL; |
| 116 |
vnodeconn = VAR_FBCONN(blk_id_ndx); |
| 117 |
vedgeconn = NULL; |
| 118 |
vfaceconn = NULL; |
| 119 |
break; |
| 120 |
case EX_ELEM_BLOCK: |
| 121 |
dnumnodent = DIM_NUM_NOD_PER_EL(blk_id_ndx); |
| 122 |
dnumedgent = DIM_NUM_EDG_PER_EL(blk_id_ndx); |
| 123 |
dnumfacent = DIM_NUM_FAC_PER_EL(blk_id_ndx); |
| 124 |
vnodeconn = VAR_CONN(blk_id_ndx); |
| 125 |
vedgeconn = VAR_ECONN(blk_id_ndx); |
| 126 |
vfaceconn = VAR_FCONN(blk_id_ndx); |
| 127 |
break; |
| 128 |
default: |
| 129 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 130 |
"Internal ERROR: unrecognized block type in switch: %d in file id %d", blk_type, |
| 131 |
exoid); |
| 132 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 133 |
EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */ |
| 134 |
} |
| 135 |
/* inquire id's of previously defined dimensions */ |
| 136 |
|
| 137 |
if ((status = nc_inq_dimid(exoid, dnumnodent, &numnodperentdim)) != NC_NOERR) { |
| 138 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 139 |
"ERROR: failed to locate number of nodes/entity for %s %" PRId64 " in file id %d", |
| 140 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 141 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 142 |
EX_FUNC_LEAVE(EX_FATAL); |
| 143 |
} |
| 144 |
|
| 145 |
if (nc_inq_dimlen(exoid, numnodperentdim, &num_nodes_per_entry) != NC_NOERR) { |
| 146 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 147 |
"ERROR: failed to get number of nodes/entity 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 |
if (edgeconn && dnumedgent) { |
| 154 |
num_edges_per_entry = 0; |
| 155 |
if ((status = nc_inq_dimid(exoid, dnumedgent, &numedgperentdim)) != NC_NOERR) { |
| 156 |
numedgperentdim = -1; |
| 157 |
} |
| 158 |
else { |
| 159 |
if ((status = nc_inq_dimlen(exoid, numedgperentdim, &num_edges_per_entry)) != NC_NOERR) { |
| 160 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 161 |
"ERROR: failed to get number of edges/entry for %s %" PRId64 " in file id %d", |
| 162 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 163 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 164 |
EX_FUNC_LEAVE(EX_FATAL); |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
if (faceconn && dnumfacent) { |
| 170 |
num_faces_per_entry = 0; |
| 171 |
if ((status = nc_inq_dimid(exoid, dnumfacent, &numfacperentdim)) != NC_NOERR) { |
| 172 |
numfacperentdim = -1; |
| 173 |
} |
| 174 |
else { |
| 175 |
if ((status = nc_inq_dimlen(exoid, numfacperentdim, &num_faces_per_entry)) != NC_NOERR) { |
| 176 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 177 |
"ERROR: failed to get number of faces/entry for %s %" PRId64 " in file id %d", |
| 178 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 179 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 180 |
EX_FUNC_LEAVE(EX_FATAL); |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
if ((status = nc_inq_varid(exoid, vnodeconn, &connid)) != NC_NOERR) { |
| 186 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 187 |
"ERROR: failed to locate connectivity array for %s %" PRId64 " in file id %d", |
| 188 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 189 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 190 |
EX_FUNC_LEAVE(EX_FATAL); |
| 191 |
} |
| 192 |
|
| 193 |
status = 0; |
| 194 |
if (edgeconn && (numedgperentdim > 0) && |
| 195 |
((status = nc_inq_varid(exoid, vedgeconn, &econnid)) != NC_NOERR)) { |
| 196 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 197 |
"ERROR: failed to locate edge connectivity array for %s %" PRId64 " in file id %d", |
| 198 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 199 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 200 |
EX_FUNC_LEAVE(EX_FATAL); |
| 201 |
} |
| 202 |
|
| 203 |
if (faceconn && (numfacperentdim > 0) && |
| 204 |
((status = nc_inq_varid(exoid, vfaceconn, &fconnid)) != NC_NOERR)) { |
| 205 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 206 |
"ERROR: failed to locate face connectivity array for %s %" PRId64 " in file id %d", |
| 207 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 208 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 209 |
EX_FUNC_LEAVE(EX_FATAL); |
| 210 |
} |
| 211 |
|
| 212 |
/* read in the connectivity array */ |
| 213 |
if (edgeconn && num_edges_per_entry > 0) { |
| 214 |
size_t start[2], count[2]; |
| 215 |
|
| 216 |
start[0] = (start_num - 1); |
| 217 |
start[1] = 0; |
| 218 |
count[0] = num_ent; |
| 219 |
count[1] = num_edges_per_entry; |
| 220 |
if (count[0] == 0) { |
| 221 |
start[0] = 0; |
| 222 |
} |
| 223 |
|
| 224 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 225 |
status = nc_get_vara_longlong(exoid, econnid, start, count, edgeconn); |
| 226 |
} |
| 227 |
else { |
| 228 |
status = nc_get_vara_int(exoid, econnid, start, count, edgeconn); |
| 229 |
} |
| 230 |
|
| 231 |
if (status != NC_NOERR) { |
| 232 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 233 |
"ERROR: failed to get edge connectivity array for %s %" PRId64 " in file id %d", |
| 234 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 235 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 236 |
EX_FUNC_LEAVE(EX_FATAL); |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
if (faceconn && num_faces_per_entry > 0) { |
| 241 |
size_t start[2], count[2]; |
| 242 |
|
| 243 |
start[0] = start_num - 1; |
| 244 |
start[1] = 0; |
| 245 |
count[0] = num_ent; |
| 246 |
count[1] = num_faces_per_entry; |
| 247 |
if (count[0] == 0) { |
| 248 |
start[0] = 0; |
| 249 |
} |
| 250 |
|
| 251 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 252 |
status = nc_get_vara_longlong(exoid, fconnid, start, count, faceconn); |
| 253 |
} |
| 254 |
else { |
| 255 |
status = nc_get_vara_int(exoid, fconnid, start, count, faceconn); |
| 256 |
} |
| 257 |
|
| 258 |
if (status != NC_NOERR) { |
| 259 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 260 |
"ERROR: failed to get face connectivity array for %s %" PRId64 " in file id %d", |
| 261 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 262 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 263 |
EX_FUNC_LEAVE(EX_FATAL); |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
if ((nodeconn && num_nodes_per_entry > 0) || num_ent == 0) { |
| 268 |
size_t start[2], count[2]; |
| 269 |
|
| 270 |
start[0] = start_num - 1; |
| 271 |
start[1] = 0; |
| 272 |
count[0] = num_ent; |
| 273 |
count[1] = num_nodes_per_entry; |
| 274 |
if (count[0] == 0) { |
| 275 |
start[0] = 0; |
| 276 |
} |
| 277 |
|
| 278 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 279 |
status = nc_get_vara_longlong(exoid, connid, start, count, nodeconn); |
| 280 |
} |
| 281 |
else { |
| 282 |
status = nc_get_vara_int(exoid, connid, start, count, nodeconn); |
| 283 |
} |
| 284 |
|
| 285 |
if (status != NC_NOERR) { |
| 286 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 287 |
"ERROR: failed to get connectivity array for %s %" PRId64 " in file id %d", |
| 288 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 289 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 290 |
EX_FUNC_LEAVE(EX_FATAL); |
| 291 |
} |
| 292 |
} |
| 293 |
EX_FUNC_LEAVE(EX_NOERR); |
| 294 |
} |