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