| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020 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 |
/* Function(s) in this file: |
| 11 |
* ex_get_node_cmap() |
| 12 |
* |
| 13 |
**************************************************************************** |
| 14 |
* Variable Index: |
| 15 |
* exoid - The NetCDF ID of an already open NemesisI file. |
| 16 |
* map_id - The ID of the nodal communication map to retrieve. |
| 17 |
* node_ids - Pointer to vector for retrieval of FEM node IDs |
| 18 |
* that make up this communication map. |
| 19 |
* proc_ids - Pointer to vector for retrieval of the processors |
| 20 |
* associated with each of the nodes in this nodal |
| 21 |
* communication map. |
| 22 |
* processor - The processor the file being read was written for. |
| 23 |
*/ |
| 24 |
/****************************************************************************/ |
| 25 |
/****************************************************************************/ |
| 26 |
/****************************************************************************/ |
| 27 |
|
| 28 |
#include "exodusII.h" // for ex_err, etc |
| 29 |
#include "exodusII_int.h" // for EX_FATAL, DIM_NCNT_CMAP, etc |
| 30 |
|
| 31 |
int ex_get_node_cmap(int exoid, ex_entity_id map_id, void_int *node_ids, void_int *proc_ids, |
| 32 |
int processor) |
| 33 |
{ |
| 34 |
int map_idx, dimid, varid[2], status; |
| 35 |
size_t start[1], count[1]; |
| 36 |
int64_t varidx[2]; |
| 37 |
|
| 38 |
char errmsg[MAX_ERR_LENGTH]; |
| 39 |
|
| 40 |
EX_FUNC_ENTER(); |
| 41 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 42 |
EX_FUNC_LEAVE(EX_FATAL); |
| 43 |
} |
| 44 |
|
| 45 |
/* get the cmap information variables index */ |
| 46 |
if (ex_get_idx(exoid, VAR_N_COMM_INFO_IDX, varidx, processor) == -1) { |
| 47 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d", |
| 48 |
VAR_N_COMM_INFO_IDX, exoid); |
| 49 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 50 |
|
| 51 |
EX_FUNC_LEAVE(EX_FATAL); |
| 52 |
} |
| 53 |
|
| 54 |
/* |
| 55 |
* no need to check if the second index is -1 that is handled |
| 56 |
* in nei_id_lkup, where the dimension must be looked up anyways |
| 57 |
*/ |
| 58 |
|
| 59 |
/* Get the index of the nodal comm map with the given ID */ |
| 60 |
if ((map_idx = nei_id_lkup(exoid, VAR_N_COMM_IDS, varidx, map_id)) < 0) { |
| 61 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 62 |
"ERROR: failed to find nodal comm map with ID %" PRId64 " in file ID %d", map_id, |
| 63 |
exoid); |
| 64 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 65 |
EX_FUNC_LEAVE(EX_FATAL); |
| 66 |
} |
| 67 |
|
| 68 |
/* get the cmap data variables index for this map */ |
| 69 |
if (ex_get_idx(exoid, VAR_N_COMM_DATA_IDX, varidx, map_idx) == -1) { |
| 70 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d", |
| 71 |
VAR_N_COMM_DATA_IDX, exoid); |
| 72 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 73 |
|
| 74 |
EX_FUNC_LEAVE(EX_FATAL); |
| 75 |
} |
| 76 |
|
| 77 |
if (varidx[1] == -1) { |
| 78 |
/* Get the dimension of this nodal communication map */ |
| 79 |
if ((status = nc_inq_dimid(exoid, DIM_NCNT_CMAP, &dimid)) != NC_NOERR) { |
| 80 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 81 |
"ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NCNT_CMAP, exoid); |
| 82 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 83 |
EX_FUNC_LEAVE(EX_FATAL); |
| 84 |
} |
| 85 |
|
| 86 |
if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { |
| 87 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 88 |
"ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_NCNT_CMAP, |
| 89 |
exoid); |
| 90 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 91 |
EX_FUNC_LEAVE(EX_FATAL); |
| 92 |
} |
| 93 |
varidx[1] = count[0]; |
| 94 |
} |
| 95 |
|
| 96 |
/* Get the variable ID for the nodal comm map node IDs */ |
| 97 |
if ((status = nc_inq_varid(exoid, VAR_N_COMM_NIDS, &varid[0])) != NC_NOERR) { |
| 98 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 99 |
VAR_N_COMM_NIDS, exoid); |
| 100 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 101 |
EX_FUNC_LEAVE(EX_FATAL); |
| 102 |
} |
| 103 |
|
| 104 |
/* Get the variable ID for the nodal comm map processor IDs */ |
| 105 |
if ((status = nc_inq_varid(exoid, VAR_N_COMM_PROC, &varid[1])) != NC_NOERR) { |
| 106 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 107 |
VAR_N_COMM_PROC, exoid); |
| 108 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 109 |
EX_FUNC_LEAVE(EX_FATAL); |
| 110 |
} |
| 111 |
|
| 112 |
/* Get the nodal comm map node IDs */ |
| 113 |
start[0] = varidx[0]; |
| 114 |
count[0] = varidx[1] - varidx[0]; |
| 115 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 116 |
status = nc_get_vara_longlong(exoid, varid[0], start, count, node_ids); |
| 117 |
} |
| 118 |
else { |
| 119 |
status = nc_get_vara_int(exoid, varid[0], start, count, node_ids); |
| 120 |
} |
| 121 |
|
| 122 |
if (status != NC_NOERR) { |
| 123 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", |
| 124 |
VAR_N_COMM_NIDS, exoid); |
| 125 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 126 |
EX_FUNC_LEAVE(EX_FATAL); |
| 127 |
} |
| 128 |
|
| 129 |
/* Get the nodal comm map processor IDs */ |
| 130 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 131 |
status = nc_get_vara_longlong(exoid, varid[1], start, count, proc_ids); |
| 132 |
} |
| 133 |
else { |
| 134 |
status = nc_get_vara_int(exoid, varid[1], start, count, proc_ids); |
| 135 |
} |
| 136 |
|
| 137 |
if (status != NC_NOERR) { |
| 138 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", |
| 139 |
VAR_N_COMM_PROC, exoid); |
| 140 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 141 |
EX_FUNC_LEAVE(EX_FATAL); |
| 142 |
} |
| 143 |
|
| 144 |
EX_FUNC_LEAVE(EX_NOERR); |
| 145 |
} |