| 1 |
/* |
| 2 |
* Copyright(C) 2022 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 |
* ex_get_block_id_map |
| 11 |
* |
| 12 |
* entry conditions - |
| 13 |
* input parameters: |
| 14 |
* int exoid exodus file id |
| 15 |
* int map_type type of map (node, edge, face, element) |
| 16 |
* |
| 17 |
* exit conditions - |
| 18 |
* int* map map |
| 19 |
* |
| 20 |
*****************************************************************************/ |
| 21 |
|
| 22 |
#include "exodusII.h" // for ex_err, etc |
| 23 |
#include "exodusII_int.h" // for EX_FATAL, EX_NOERR, etc |
| 24 |
|
| 25 |
/* |
| 26 |
* reads the id map for the edge/face/element block with the specified id. |
| 27 |
*/ |
| 28 |
|
| 29 |
int ex_get_block_id_map(int exoid, ex_entity_type obj_type, ex_entity_id entity_id, void_int *map) |
| 30 |
{ |
| 31 |
int status; |
| 32 |
char errmsg[MAX_ERR_LENGTH]; |
| 33 |
const char *dnument = NULL; |
| 34 |
ex_entity_type map_type = EX_INVALID; |
| 35 |
|
| 36 |
EX_FUNC_ENTER(); |
| 37 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 38 |
EX_FUNC_LEAVE(EX_FATAL); |
| 39 |
} |
| 40 |
|
| 41 |
/* Determine index of entity_id in id array */ |
| 42 |
int blk_id_ndx = exi_id_lkup(exoid, obj_type, entity_id); |
| 43 |
if (blk_id_ndx <= 0) { /* Empty block */ |
| 44 |
ex_get_err(NULL, NULL, &status); |
| 45 |
if (status != 0) { |
| 46 |
if (status == EX_NULLENTITY) { /* NULL element block? */ |
| 47 |
EX_FUNC_LEAVE(EX_NOERR); |
| 48 |
} |
| 49 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 50 |
"ERROR: failed to locate %s id %" PRId64 " in id array in file id %d", |
| 51 |
ex_name_of_object(obj_type), entity_id, exoid); |
| 52 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 53 |
EX_FUNC_LEAVE(EX_FATAL); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
size_t offset = 1; |
| 58 |
size_t len = 0; |
| 59 |
for (int i = 1; i <= blk_id_ndx; i++) { |
| 60 |
offset += len; |
| 61 |
/* inquire values of some dimensions */ |
| 62 |
int dimid = 0; |
| 63 |
|
| 64 |
/* Determine the number of entities in all previous blocks. */ |
| 65 |
switch (obj_type) { |
| 66 |
case EX_EDGE_BLOCK: |
| 67 |
dnument = DIM_NUM_ED_IN_EBLK(i); |
| 68 |
map_type = EX_EDGE_MAP; |
| 69 |
break; |
| 70 |
case EX_FACE_BLOCK: |
| 71 |
dnument = DIM_NUM_FA_IN_FBLK(i); |
| 72 |
map_type = EX_FACE_MAP; |
| 73 |
break; |
| 74 |
case EX_ELEM_BLOCK: |
| 75 |
dnument = DIM_NUM_EL_IN_BLK(i); |
| 76 |
map_type = EX_ELEM_MAP; |
| 77 |
break; |
| 78 |
default: |
| 79 |
snprintf(errmsg, MAX_ERR_LENGTH, "Bad block type parameter (%d) specified for file id %d.", |
| 80 |
obj_type, exoid); |
| 81 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 82 |
EX_FUNC_LEAVE(EX_FATAL); |
| 83 |
} |
| 84 |
if ((status = nc_inq_dimid(exoid, dnument, &dimid)) != NC_NOERR) { |
| 85 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 86 |
"ERROR: failed to locate number of entities in %s %" PRId64 " in file id %d", |
| 87 |
ex_name_of_object(obj_type), entity_id, exoid); |
| 88 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 89 |
EX_FUNC_LEAVE(EX_FATAL); |
| 90 |
} |
| 91 |
|
| 92 |
if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) { |
| 93 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 94 |
"ERROR: failed to get number of %ss in block %" PRId64 " in file id %d", |
| 95 |
ex_name_of_object(obj_type), entity_id, exoid); |
| 96 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 97 |
EX_FUNC_LEAVE(EX_FATAL); |
| 98 |
} |
| 99 |
} |
| 100 |
EX_FUNC_UNLOCK(); |
| 101 |
return ex_get_partial_id_map(exoid, map_type, offset, len, map); |
| 102 |
} |