| 1 |
/* |
| 2 |
* Copyright(C) 1999-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 |
* expenm - ex_put_partial_id_map |
| 11 |
* |
| 12 |
* entry conditions - |
| 13 |
* input parameters: |
| 14 |
* int exoid exodus file id |
| 15 |
* ex_entity_type obj_type |
| 16 |
* int* elem_map element numbering map array |
| 17 |
* |
| 18 |
* exit conditions - |
| 19 |
* |
| 20 |
* revision history - |
| 21 |
* |
| 22 |
* |
| 23 |
*****************************************************************************/ |
| 24 |
|
| 25 |
#include "exodusII.h" // for ex_err, etc |
| 26 |
#include "exodusII_int.h" // for EX_FATAL, EX_NOERR, etc |
| 27 |
|
| 28 |
/*! |
| 29 |
* writes out a portion of the entity numbering map to the database; |
| 30 |
* this allows the entity numbers to be non-contiguous. This map is |
| 31 |
* used for mapping between local and global entity ids. |
| 32 |
* \param exoid exodus file id |
| 33 |
* \param map_type |
| 34 |
* \param start_entity_num |
| 35 |
* \param num_entities |
| 36 |
* \param map numbering map array |
| 37 |
*/ |
| 38 |
|
| 39 |
int ex_put_partial_id_map(int exoid, ex_entity_type map_type, int64_t start_entity_num, |
| 40 |
int64_t num_entities, const void_int *map) |
| 41 |
{ |
| 42 |
int dimid = 0, mapid = 0, status, dims[1]; |
| 43 |
int map_int_type; |
| 44 |
size_t start[1], count[1]; |
| 45 |
char errmsg[MAX_ERR_LENGTH]; |
| 46 |
const char *tname = NULL; |
| 47 |
const char *dnumentries = NULL; |
| 48 |
const char *vmap = NULL; |
| 49 |
|
| 50 |
EX_FUNC_ENTER(); |
| 51 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 52 |
EX_FUNC_LEAVE(EX_FATAL); |
| 53 |
} |
| 54 |
|
| 55 |
if (num_entities == 0 && !exi_is_parallel(exoid)) { |
| 56 |
EX_FUNC_LEAVE(EX_NOERR); |
| 57 |
} |
| 58 |
|
| 59 |
switch (map_type) { |
| 60 |
case EX_NODE_MAP: |
| 61 |
tname = "node"; |
| 62 |
dnumentries = DIM_NUM_NODES; |
| 63 |
vmap = VAR_NODE_NUM_MAP; |
| 64 |
break; |
| 65 |
case EX_EDGE_MAP: |
| 66 |
tname = "edge"; |
| 67 |
dnumentries = DIM_NUM_EDGE; |
| 68 |
vmap = VAR_EDGE_NUM_MAP; |
| 69 |
break; |
| 70 |
case EX_FACE_MAP: |
| 71 |
tname = "face"; |
| 72 |
dnumentries = DIM_NUM_FACE; |
| 73 |
vmap = VAR_FACE_NUM_MAP; |
| 74 |
break; |
| 75 |
case EX_ELEM_MAP: |
| 76 |
tname = "element"; |
| 77 |
dnumentries = DIM_NUM_ELEM; |
| 78 |
vmap = VAR_ELEM_NUM_MAP; |
| 79 |
break; |
| 80 |
default: |
| 81 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Bad map type (%d) specified for file id %d", map_type, |
| 82 |
exoid); |
| 83 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 84 |
EX_FUNC_LEAVE(EX_FATAL); |
| 85 |
} |
| 86 |
|
| 87 |
/* Make sure the file contains entries */ |
| 88 |
if (nc_inq_dimid(exoid, dnumentries, &dimid) != NC_NOERR) { |
| 89 |
/* Possible Error -- if we made it this far, num_entities is > 0, |
| 90 |
* or this is a parallel run but the dimension 'dnumentries' is |
| 91 |
* not defined which indicates that either the entity count is |
| 92 |
* zero, or there is an error in that the dimension has not yet |
| 93 |
* been defined. Assume that if num_entities == 0 and this is a |
| 94 |
* parallel run that there is no error; otherwise if in serial and |
| 95 |
* num_entities != 0, there is an error. |
| 96 |
*/ |
| 97 |
if (num_entities != 0) { |
| 98 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 99 |
"ERROR: The %s count is %" PRId64 |
| 100 |
", but the %s dimension is not defined on file id %d.", |
| 101 |
tname, num_entities, dnumentries, exoid); |
| 102 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 103 |
EX_FUNC_LEAVE(EX_FATAL); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
/* define the map if it doesn't already exist... */ |
| 108 |
if (nc_inq_varid(exoid, vmap, &mapid) != NC_NOERR) { |
| 109 |
if ((status = exi_redef(exoid, __func__)) != NC_NOERR) { |
| 110 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file id %d into define mode", exoid); |
| 111 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 112 |
EX_FUNC_LEAVE(EX_FATAL); |
| 113 |
} |
| 114 |
|
| 115 |
/* create a variable array in which to store the id map */ |
| 116 |
|
| 117 |
dims[0] = dimid; |
| 118 |
|
| 119 |
/* Check type to be used for maps... */ |
| 120 |
map_int_type = NC_INT; |
| 121 |
if (ex_int64_status(exoid) & EX_MAPS_INT64_DB) { |
| 122 |
map_int_type = NC_INT64; |
| 123 |
} |
| 124 |
|
| 125 |
if ((status = nc_def_var(exoid, vmap, map_int_type, 1, dims, &mapid)) != NC_NOERR) { |
| 126 |
if (status == NC_ENAMEINUSE) { |
| 127 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: %s numbering map already exists in file id %d", |
| 128 |
tname, exoid); |
| 129 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 130 |
} |
| 131 |
else { |
| 132 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to create %s id map in file id %d", tname, |
| 133 |
exoid); |
| 134 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 135 |
} |
| 136 |
goto error_ret; /* exit define mode and return */ |
| 137 |
} |
| 138 |
exi_compress_variable(exoid, mapid, 1); |
| 139 |
|
| 140 |
/* leave define mode */ |
| 141 |
if ((status = exi_leavedef(exoid, __func__)) != NC_NOERR) { |
| 142 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to exit define mode"); |
| 143 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 144 |
EX_FUNC_LEAVE(EX_FATAL); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
/* write out the entity numbering map */ |
| 149 |
start[0] = start_entity_num - 1; |
| 150 |
count[0] = num_entities; |
| 151 |
if (num_entities == 0) { |
| 152 |
start[0] = 0; |
| 153 |
} |
| 154 |
|
| 155 |
/* write out the entity numbering map */ |
| 156 |
if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { |
| 157 |
status = nc_put_vara_longlong(exoid, mapid, start, count, map); |
| 158 |
} |
| 159 |
else { |
| 160 |
status = nc_put_vara_int(exoid, mapid, start, count, map); |
| 161 |
} |
| 162 |
|
| 163 |
if (status != NC_NOERR) { |
| 164 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store %s numbering map in file id %d", tname, |
| 165 |
exoid); |
| 166 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 167 |
EX_FUNC_LEAVE(EX_FATAL); |
| 168 |
} |
| 169 |
|
| 170 |
EX_FUNC_LEAVE(EX_NOERR); |
| 171 |
|
| 172 |
/* Fatal error: exit definition mode and return */ |
| 173 |
error_ret: |
| 174 |
exi_leavedef(exoid, __func__); |
| 175 |
EX_FUNC_LEAVE(EX_FATAL); |
| 176 |
} |