| 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 |
/*****************************************************************************/ |
| 11 |
/* Function(s) contained in this file: |
| 12 |
* ex_get_cmap_params() |
| 13 |
***************************************************************************** |
| 14 |
* This function outputs the communication map parameters. |
| 15 |
***************************************************************************** |
| 16 |
* Variable Index: |
| 17 |
* exoid - The NetCDF ID of an already open NemesisI file. |
| 18 |
* node_cmap_ids - Pointer to vector of nodal communication |
| 19 |
* set IDs. |
| 20 |
* node_cmap_node_cnts - Pointer to a vector which contains a count of |
| 21 |
* the number of FEM nodes for each nodal |
| 22 |
* communication map. |
| 23 |
* elem_cmap_ids - Pointer to vector for retrieval of elemental |
| 24 |
* communication set IDs. |
| 25 |
* elem_cmap_elem_cnts - Pointer to a vector which contains a count of |
| 26 |
* the number of FEM elements for each elemental |
| 27 |
* communication map. |
| 28 |
* processor - The processor the file being read was written |
| 29 |
* for. |
| 30 |
*/ |
| 31 |
/*****************************************************************************/ |
| 32 |
/*****************************************************************************/ |
| 33 |
/*****************************************************************************/ |
| 34 |
|
| 35 |
#include <exodusII.h> // for ex_err, etc |
| 36 |
#include <exodusII_int.h> // for EX_FATAL, VAR_E_COMM_IDS, etc |
| 37 |
|
| 38 |
int ex_get_cmap_params(int exoid, void_int *node_cmap_ids, void_int *node_cmap_node_cnts, |
| 39 |
void_int *elem_cmap_ids, void_int *elem_cmap_elem_cnts, int processor) |
| 40 |
{ |
| 41 |
size_t start[1], count[1]; |
| 42 |
int status, map_idx, varid, dimid; |
| 43 |
int nmstat; |
| 44 |
int64_t cmap_data_idx[2]; |
| 45 |
|
| 46 |
char errmsg[MAX_ERR_LENGTH]; |
| 47 |
/*-----------------------------Execution begins-----------------------------*/ |
| 48 |
|
| 49 |
EX_FUNC_ENTER(); |
| 50 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 51 |
EX_FUNC_LEAVE(EX_FATAL); |
| 52 |
} |
| 53 |
|
| 54 |
/*****************************************************************************/ |
| 55 |
/*****************************************************************************/ |
| 56 |
/* Nodal communication map(s) */ |
| 57 |
/*****************************************************************************/ |
| 58 |
/*****************************************************************************/ |
| 59 |
|
| 60 |
/* get the cmap information variables index */ |
| 61 |
int64_t cmap_info_idx[2]; |
| 62 |
if (ex_get_idx(exoid, VAR_N_COMM_INFO_IDX, cmap_info_idx, processor) == -1) { |
| 63 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d", |
| 64 |
VAR_N_COMM_INFO_IDX, exoid); |
| 65 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 66 |
|
| 67 |
EX_FUNC_LEAVE(EX_FATAL); |
| 68 |
} |
| 69 |
|
| 70 |
/* Get the number of nodal communications maps in the file */ |
| 71 |
if ((status = nc_inq_dimid(exoid, DIM_NUM_N_CMAPS, &dimid)) == NC_NOERR) { |
| 72 |
/* check if I need to get the dimension of the nodal comm map */ |
| 73 |
if (cmap_info_idx[1] == -1) { |
| 74 |
if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { |
| 75 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 76 |
"ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_N_CMAPS, |
| 77 |
exoid); |
| 78 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 79 |
EX_FUNC_LEAVE(EX_FATAL); |
| 80 |
} |
| 81 |
|
| 82 |
/* set the end value for the node map */ |
| 83 |
cmap_info_idx[1] = count[0]; |
| 84 |
} /* End "if (cmap_info_idx[1] == -1) */ |
| 85 |
|
| 86 |
size_t num_n_comm_maps = cmap_info_idx[1] - cmap_info_idx[0]; |
| 87 |
|
| 88 |
if (num_n_comm_maps > 0) { |
| 89 |
count[0] = num_n_comm_maps; |
| 90 |
|
| 91 |
/* Get the variable ID for the vector of nodal comm map IDs */ |
| 92 |
if ((status = nc_inq_varid(exoid, VAR_N_COMM_IDS, &varid)) != NC_NOERR) { |
| 93 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 94 |
"ERROR: failed to get variable ID for \"%s\" in file ID %d", VAR_N_COMM_IDS, |
| 95 |
exoid); |
| 96 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 97 |
EX_FUNC_LEAVE(EX_FATAL); |
| 98 |
} |
| 99 |
|
| 100 |
/* Get the vector of nodal communication map IDs */ |
| 101 |
if (node_cmap_ids != NULL) { |
| 102 |
start[0] = cmap_info_idx[0]; |
| 103 |
if (ex_int64_status(exoid) & EX_IDS_INT64_API) { |
| 104 |
status = nc_get_vara_longlong(exoid, varid, start, count, node_cmap_ids); |
| 105 |
} |
| 106 |
else { |
| 107 |
status = nc_get_vara_int(exoid, varid, start, count, node_cmap_ids); |
| 108 |
} |
| 109 |
|
| 110 |
if (status != NC_NOERR) { |
| 111 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", |
| 112 |
VAR_N_COMM_IDS, exoid); |
| 113 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 114 |
EX_FUNC_LEAVE(EX_FATAL); |
| 115 |
} |
| 116 |
|
| 117 |
if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &varid)) != NC_NOERR) { |
| 118 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 119 |
"ERROR: failed to find variable ID for \"%s\" from file ID %d", VAR_N_COMM_STAT, |
| 120 |
exoid); |
| 121 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 122 |
EX_FUNC_LEAVE(EX_FATAL); |
| 123 |
} |
| 124 |
|
| 125 |
if (node_cmap_node_cnts != NULL) { |
| 126 |
|
| 127 |
/* Get the node counts in each of the nodal communication maps */ |
| 128 |
for (size_t cnt = 0; cnt < num_n_comm_maps; cnt++) { |
| 129 |
int64_t cmap_id; |
| 130 |
if (ex_int64_status(exoid) & EX_IDS_INT64_API) { |
| 131 |
cmap_id = ((int64_t *)node_cmap_ids)[cnt]; |
| 132 |
} |
| 133 |
else { |
| 134 |
cmap_id = ((int *)node_cmap_ids)[cnt]; |
| 135 |
} |
| 136 |
|
| 137 |
if ((map_idx = nei_id_lkup(exoid, VAR_N_COMM_IDS, cmap_info_idx, cmap_id)) < 0) { |
| 138 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 139 |
"ERROR: failed to find nodal comm map with ID %" PRId64 " in file ID %d", |
| 140 |
cmap_id, exoid); |
| 141 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 142 |
EX_FUNC_LEAVE(EX_FATAL); |
| 143 |
} |
| 144 |
|
| 145 |
/* Check the status of the node map */ |
| 146 |
start[0] = map_idx; |
| 147 |
if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) { |
| 148 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 149 |
"ERROR: failed to get status for \"%s\" from file ID %d", VAR_N_COMM_STAT, |
| 150 |
exoid); |
| 151 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 152 |
EX_FUNC_LEAVE(EX_FATAL); |
| 153 |
} |
| 154 |
|
| 155 |
if (nmstat == 1) { |
| 156 |
|
| 157 |
/* get the cmap information variables index */ |
| 158 |
if (ex_get_idx(exoid, VAR_N_COMM_DATA_IDX, cmap_data_idx, map_idx) == -1) { |
| 159 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 160 |
"ERROR: failed to find index variable, \"%s\", " |
| 161 |
"in file ID %d", |
| 162 |
VAR_N_COMM_DATA_IDX, exoid); |
| 163 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 164 |
|
| 165 |
EX_FUNC_LEAVE(EX_FATAL); |
| 166 |
} |
| 167 |
|
| 168 |
if (cmap_data_idx[1] == -1) { |
| 169 |
/* |
| 170 |
* Find the dimension ID of the variable containing the |
| 171 |
* node count |
| 172 |
*/ |
| 173 |
if ((status = nc_inq_dimid(exoid, DIM_NCNT_CMAP, &dimid)) != NC_NOERR) { |
| 174 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 175 |
"ERROR: failed to find dimension ID for " |
| 176 |
"\"%s\" in file ID %d", |
| 177 |
DIM_NCNT_CMAP, exoid); |
| 178 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 179 |
EX_FUNC_LEAVE(EX_FATAL); |
| 180 |
} |
| 181 |
|
| 182 |
/* Find the value of the number of nodes in this nodal comm map |
| 183 |
*/ |
| 184 |
if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { |
| 185 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 186 |
"ERROR: failed to find length of dimension " |
| 187 |
"\"%s\" in file ID %d", |
| 188 |
DIM_NCNT_CMAP, exoid); |
| 189 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 190 |
EX_FUNC_LEAVE(EX_FATAL); |
| 191 |
} |
| 192 |
|
| 193 |
cmap_data_idx[1] = count[0]; |
| 194 |
} |
| 195 |
|
| 196 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 197 |
((int64_t *)node_cmap_node_cnts)[cnt] = cmap_data_idx[1] - cmap_data_idx[0]; |
| 198 |
} |
| 199 |
else { |
| 200 |
((int *)node_cmap_node_cnts)[cnt] = cmap_data_idx[1] - cmap_data_idx[0]; |
| 201 |
} |
| 202 |
} |
| 203 |
else if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 204 |
((int64_t *)node_cmap_node_cnts)[cnt] = 0; |
| 205 |
} |
| 206 |
else { |
| 207 |
((int *)node_cmap_node_cnts)[cnt] = 0; |
| 208 |
} |
| 209 |
} /* "for(cnt=0; cnt < num_n_comm_maps; cnt++)" */ |
| 210 |
} /* "if (node_cmap_node_cnts != NULL)" */ |
| 211 |
} /* "if (node_cmap_ids != NULL)" */ |
| 212 |
} /* "if (num_n_comm_maps > 0)" */ |
| 213 |
} /* End "if ((dimid = nc_inq_dimid(exoid, DIM_NUM_N_CMAPS)) != -1)" */ |
| 214 |
|
| 215 |
/*****************************************************************************/ |
| 216 |
/*****************************************************************************/ |
| 217 |
/* Elemental communication map(s) */ |
| 218 |
/*****************************************************************************/ |
| 219 |
/*****************************************************************************/ |
| 220 |
|
| 221 |
/* get the cmap information variables index */ |
| 222 |
if (ex_get_idx(exoid, VAR_E_COMM_INFO_IDX, cmap_info_idx, processor) == -1) { |
| 223 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d", |
| 224 |
VAR_E_COMM_INFO_IDX, exoid); |
| 225 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 226 |
|
| 227 |
EX_FUNC_LEAVE(EX_FATAL); |
| 228 |
} |
| 229 |
|
| 230 |
/* Get the number of elemental communications maps in the file */ |
| 231 |
if (nc_inq_dimid(exoid, DIM_NUM_E_CMAPS, &dimid) == NC_NOERR) { |
| 232 |
/* check if I need to get the dimension of the nodal comm map */ |
| 233 |
if (cmap_info_idx[1] == -1) { |
| 234 |
if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { |
| 235 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 236 |
"ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_E_CMAPS, |
| 237 |
exoid); |
| 238 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 239 |
EX_FUNC_LEAVE(EX_FATAL); |
| 240 |
} |
| 241 |
|
| 242 |
/* set the end value for the node map */ |
| 243 |
cmap_info_idx[1] = count[0]; |
| 244 |
} /* End "if (cmap_info_idx[1] == -1) */ |
| 245 |
|
| 246 |
size_t num_e_comm_maps = cmap_info_idx[1] - cmap_info_idx[0]; |
| 247 |
|
| 248 |
if (num_e_comm_maps > 0) { |
| 249 |
count[0] = num_e_comm_maps; |
| 250 |
|
| 251 |
/* Get the variable ID for the vector of nodal comm map IDs */ |
| 252 |
if ((status = nc_inq_varid(exoid, VAR_E_COMM_IDS, &varid)) != NC_NOERR) { |
| 253 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 254 |
"ERROR: failed to get variable ID for \"%s\" in file ID %d", VAR_E_COMM_IDS, |
| 255 |
exoid); |
| 256 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 257 |
EX_FUNC_LEAVE(EX_FATAL); |
| 258 |
} |
| 259 |
|
| 260 |
/* Get the vector of elemental communication map IDs */ |
| 261 |
if (elem_cmap_ids != NULL) { |
| 262 |
start[0] = cmap_info_idx[0]; |
| 263 |
if (ex_int64_status(exoid) & EX_IDS_INT64_API) { |
| 264 |
status = nc_get_vara_longlong(exoid, varid, start, count, elem_cmap_ids); |
| 265 |
} |
| 266 |
else { |
| 267 |
status = nc_get_vara_int(exoid, varid, start, count, elem_cmap_ids); |
| 268 |
} |
| 269 |
if (status != NC_NOERR) { |
| 270 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", |
| 271 |
VAR_E_COMM_IDS, exoid); |
| 272 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 273 |
EX_FUNC_LEAVE(EX_FATAL); |
| 274 |
} |
| 275 |
|
| 276 |
if ((status = nc_inq_varid(exoid, VAR_E_COMM_STAT, &varid)) != NC_NOERR) { |
| 277 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 278 |
"ERROR: failed to find variable ID for \"%s\" from file ID %d", VAR_E_COMM_STAT, |
| 279 |
exoid); |
| 280 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 281 |
EX_FUNC_LEAVE(EX_FATAL); |
| 282 |
} |
| 283 |
|
| 284 |
if (elem_cmap_elem_cnts != NULL) { |
| 285 |
/* |
| 286 |
* Get the element counts in each of the elemental |
| 287 |
* communication maps |
| 288 |
*/ |
| 289 |
for (size_t cnt = 0; cnt < num_e_comm_maps; cnt++) { |
| 290 |
int64_t cmap_id; |
| 291 |
if (ex_int64_status(exoid) & EX_IDS_INT64_API) { |
| 292 |
cmap_id = ((int64_t *)elem_cmap_ids)[cnt]; |
| 293 |
} |
| 294 |
else { |
| 295 |
cmap_id = ((int *)elem_cmap_ids)[cnt]; |
| 296 |
} |
| 297 |
|
| 298 |
if ((map_idx = nei_id_lkup(exoid, VAR_E_COMM_IDS, cmap_info_idx, cmap_id)) < 0) { |
| 299 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 300 |
"ERROR: failed to find elemental comm map with ID %" PRId64 " in file ID %d", |
| 301 |
cmap_id, exoid); |
| 302 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 303 |
EX_FUNC_LEAVE(EX_FATAL); |
| 304 |
} |
| 305 |
|
| 306 |
/* Check the status of the requested elemental map */ |
| 307 |
start[0] = map_idx; |
| 308 |
if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) { |
| 309 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 310 |
"ERROR: failed to get status for \"%s\" from file ID %d", VAR_E_COMM_STAT, |
| 311 |
exoid); |
| 312 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 313 |
EX_FUNC_LEAVE(EX_FATAL); |
| 314 |
} |
| 315 |
|
| 316 |
if (nmstat == 1) { |
| 317 |
|
| 318 |
/* get the cmap information variables index */ |
| 319 |
if (ex_get_idx(exoid, VAR_E_COMM_DATA_IDX, cmap_data_idx, map_idx) == -1) { |
| 320 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 321 |
"ERROR: failed to find index variable, \"%s\", " |
| 322 |
"in file ID %d", |
| 323 |
VAR_E_COMM_DATA_IDX, exoid); |
| 324 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 325 |
|
| 326 |
EX_FUNC_LEAVE(EX_FATAL); |
| 327 |
} |
| 328 |
|
| 329 |
if (cmap_data_idx[1] == -1) { |
| 330 |
/* |
| 331 |
* Find the dimension ID of the variable containing the |
| 332 |
* element count |
| 333 |
*/ |
| 334 |
if ((status = nc_inq_dimid(exoid, DIM_ECNT_CMAP, &dimid)) != NC_NOERR) { |
| 335 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 336 |
"ERROR: failed to find dimension ID for " |
| 337 |
"\"%s\" in file ID %d", |
| 338 |
DIM_ECNT_CMAP, exoid); |
| 339 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 340 |
EX_FUNC_LEAVE(EX_FATAL); |
| 341 |
} |
| 342 |
|
| 343 |
/* |
| 344 |
* Find the value of the number of elements in this elemental |
| 345 |
* comm map |
| 346 |
*/ |
| 347 |
if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { |
| 348 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 349 |
"ERROR: failed to find length of dimension " |
| 350 |
"\"%s\" in file ID %d", |
| 351 |
DIM_ECNT_CMAP, exoid); |
| 352 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 353 |
EX_FUNC_LEAVE(EX_FATAL); |
| 354 |
} |
| 355 |
cmap_data_idx[1] = count[0]; |
| 356 |
} |
| 357 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 358 |
((int64_t *)elem_cmap_elem_cnts)[cnt] = cmap_data_idx[1] - cmap_data_idx[0]; |
| 359 |
} |
| 360 |
else { |
| 361 |
((int *)elem_cmap_elem_cnts)[cnt] = cmap_data_idx[1] - cmap_data_idx[0]; |
| 362 |
} |
| 363 |
} |
| 364 |
else if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 365 |
((int64_t *)elem_cmap_elem_cnts)[cnt] = 0; |
| 366 |
} |
| 367 |
else { |
| 368 |
((int *)elem_cmap_elem_cnts)[cnt] = 0; |
| 369 |
} |
| 370 |
} /* "for(cnt=0; cnt < num_e_comm_maps; cnt++)" */ |
| 371 |
} /* "if (elem_cmap_elem_cnts != NULL)" */ |
| 372 |
} /* "if (elem_cmap_ids != NULL)" */ |
| 373 |
} /* "if (num_e_comm_maps > 0)" */ |
| 374 |
} /* End "if ((dimid = nc_inq_dimid(exoid, DIM_NUM_E_CMAPS(processor))) != |
| 375 |
-1)" */ |
| 376 |
EX_FUNC_LEAVE(EX_NOERR); |
| 377 |
} |