| 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) contained in this file: |
| 11 |
* ex_get_node_map() |
| 12 |
***************************************************************************** |
| 13 |
* This function retrieves the nodal map. |
| 14 |
***************************************************************************** |
| 15 |
* Variable Index: |
| 16 |
* exoid - The NetCDF ID of an already open NemesisI file. |
| 17 |
* node_mapi - Pointer to vector for retrieval of internal FEM |
| 18 |
* nodal IDs. |
| 19 |
* node_mapb - Pointer to vector for retrieval of border FEM |
| 20 |
* nodal IDs. |
| 21 |
* node_mape - Pointer to vector for retrieval of external FEM |
| 22 |
* nodal IDs. |
| 23 |
* processor - The processor the file being read was written for. |
| 24 |
*/ |
| 25 |
/*****************************************************************************/ |
| 26 |
/*****************************************************************************/ |
| 27 |
/*****************************************************************************/ |
| 28 |
|
| 29 |
#include "exodusII.h" // for ex_err, etc |
| 30 |
#include "exodusII_int.h" // for EX_FATAL, DIM_NUM_BOR_NODES, etc |
| 31 |
|
| 32 |
int ex_get_processor_node_maps(int exoid, void_int *node_mapi, void_int *node_mapb, |
| 33 |
void_int *node_mape, int processor) |
| 34 |
{ |
| 35 |
char ftype[2]; |
| 36 |
int status, varid, dimid; |
| 37 |
size_t start[1], count[1]; |
| 38 |
int64_t varidx[2]; |
| 39 |
int nmstat; |
| 40 |
|
| 41 |
char errmsg[MAX_ERR_LENGTH]; |
| 42 |
/*-----------------------------Execution begins-----------------------------*/ |
| 43 |
|
| 44 |
EX_FUNC_ENTER(); |
| 45 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 46 |
EX_FUNC_LEAVE(EX_FATAL); |
| 47 |
} |
| 48 |
|
| 49 |
/* Get the file type */ |
| 50 |
if (exi_get_file_type(exoid, ftype) != EX_NOERR) { |
| 51 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to find file type for file ID %d", exoid); |
| 52 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 53 |
EX_FUNC_LEAVE(EX_FATAL); |
| 54 |
} |
| 55 |
|
| 56 |
/* Get the status of this node map */ |
| 57 |
if ((status = nc_inq_varid(exoid, VAR_INT_N_STAT, &varid)) != NC_NOERR) { |
| 58 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" from file ID %d", |
| 59 |
VAR_INT_N_STAT, exoid); |
| 60 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 61 |
EX_FUNC_LEAVE(EX_FATAL); |
| 62 |
} |
| 63 |
|
| 64 |
if (ftype[0] == 'p') { |
| 65 |
start[0] = 0; |
| 66 |
} |
| 67 |
else { |
| 68 |
start[0] = processor; |
| 69 |
} |
| 70 |
|
| 71 |
if (nc_get_var1_int(exoid, varid, start, &nmstat) != NC_NOERR) { |
| 72 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" in file ID %d", |
| 73 |
VAR_INT_N_STAT, exoid); |
| 74 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 75 |
EX_FUNC_LEAVE(EX_FATAL); |
| 76 |
} |
| 77 |
|
| 78 |
if (nmstat == 1) { |
| 79 |
/* get the index */ |
| 80 |
if (ex_get_idx(exoid, VAR_NODE_MAP_INT_IDX, varidx, processor) == -1) { |
| 81 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 82 |
"ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_INT_IDX, |
| 83 |
exoid); |
| 84 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 85 |
|
| 86 |
EX_FUNC_LEAVE(EX_FATAL); |
| 87 |
} |
| 88 |
|
| 89 |
/* check if I need to get the dimension */ |
| 90 |
if (varidx[1] == -1) { |
| 91 |
if ((status = nc_inq_dimid(exoid, DIM_NUM_INT_NODES, &dimid)) != NC_NOERR) { |
| 92 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 93 |
"ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_INT_NODES, |
| 94 |
exoid); |
| 95 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 96 |
EX_FUNC_LEAVE(EX_FATAL); |
| 97 |
} |
| 98 |
|
| 99 |
if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { |
| 100 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 101 |
"ERROR: failed to find length of dimension \"%s\" in file ID %d", |
| 102 |
DIM_NUM_INT_NODES, exoid); |
| 103 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 104 |
EX_FUNC_LEAVE(EX_FATAL); |
| 105 |
} |
| 106 |
varidx[1] = count[0]; |
| 107 |
} |
| 108 |
|
| 109 |
if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_INT, &varid)) != NC_NOERR) { |
| 110 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 111 |
VAR_NODE_MAP_INT, exoid); |
| 112 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 113 |
EX_FUNC_LEAVE(EX_FATAL); |
| 114 |
} |
| 115 |
|
| 116 |
start[0] = varidx[0]; |
| 117 |
count[0] = varidx[1] - varidx[0]; |
| 118 |
if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { |
| 119 |
status = nc_get_vara_longlong(exoid, varid, start, count, node_mapi); |
| 120 |
} |
| 121 |
else { |
| 122 |
status = nc_get_vara_int(exoid, varid, start, count, node_mapi); |
| 123 |
} |
| 124 |
if (status != NC_NOERR) { |
| 125 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", |
| 126 |
VAR_NODE_MAP_INT, exoid); |
| 127 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 128 |
EX_FUNC_LEAVE(EX_FATAL); |
| 129 |
} |
| 130 |
|
| 131 |
} /* End "if (nmstat == 1)" */ |
| 132 |
|
| 133 |
/* Get the status of this node map */ |
| 134 |
if ((status = nc_inq_varid(exoid, VAR_BOR_N_STAT, &varid)) != NC_NOERR) { |
| 135 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" from file ID %d", |
| 136 |
VAR_BOR_N_STAT, exoid); |
| 137 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 138 |
EX_FUNC_LEAVE(EX_FATAL); |
| 139 |
} |
| 140 |
|
| 141 |
if (ftype[0] == 'p') { |
| 142 |
start[0] = 0; |
| 143 |
} |
| 144 |
else { |
| 145 |
start[0] = processor; |
| 146 |
} |
| 147 |
|
| 148 |
if (nc_get_var1_int(exoid, varid, start, &nmstat) != NC_NOERR) { |
| 149 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file ID %d", |
| 150 |
VAR_BOR_N_STAT, exoid); |
| 151 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 152 |
EX_FUNC_LEAVE(EX_FATAL); |
| 153 |
} |
| 154 |
|
| 155 |
if (nmstat == 1) { |
| 156 |
/* get the index */ |
| 157 |
if (ex_get_idx(exoid, VAR_NODE_MAP_BOR_IDX, varidx, processor) == -1) { |
| 158 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 159 |
"ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_BOR_IDX, |
| 160 |
exoid); |
| 161 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 162 |
|
| 163 |
EX_FUNC_LEAVE(EX_FATAL); |
| 164 |
} |
| 165 |
|
| 166 |
/* check if I need to get the dimension */ |
| 167 |
if (varidx[1] == -1) { |
| 168 |
if ((status = nc_inq_dimid(exoid, DIM_NUM_BOR_NODES, &dimid)) != NC_NOERR) { |
| 169 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 170 |
"ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_BOR_NODES, |
| 171 |
exoid); |
| 172 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 173 |
EX_FUNC_LEAVE(EX_FATAL); |
| 174 |
} |
| 175 |
|
| 176 |
if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { |
| 177 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 178 |
"ERROR: failed to find length of dimension \"%s\" in file ID %d", |
| 179 |
DIM_NUM_BOR_NODES, exoid); |
| 180 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 181 |
EX_FUNC_LEAVE(EX_FATAL); |
| 182 |
} |
| 183 |
varidx[1] = count[0]; |
| 184 |
} |
| 185 |
|
| 186 |
if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_BOR, &varid)) != NC_NOERR) { |
| 187 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 188 |
VAR_NODE_MAP_BOR, exoid); |
| 189 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 190 |
EX_FUNC_LEAVE(EX_FATAL); |
| 191 |
} |
| 192 |
|
| 193 |
start[0] = varidx[0]; |
| 194 |
count[0] = varidx[1] - varidx[0]; |
| 195 |
if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { |
| 196 |
status = nc_get_vara_longlong(exoid, varid, start, count, node_mapb); |
| 197 |
} |
| 198 |
else { |
| 199 |
status = nc_get_vara_int(exoid, varid, start, count, node_mapb); |
| 200 |
} |
| 201 |
if (status != NC_NOERR) { |
| 202 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", |
| 203 |
VAR_NODE_MAP_BOR, exoid); |
| 204 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 205 |
EX_FUNC_LEAVE(EX_FATAL); |
| 206 |
} |
| 207 |
} /* End "if (nmstat == 1)" */ |
| 208 |
|
| 209 |
/* Get the status of this node map */ |
| 210 |
if ((status = nc_inq_varid(exoid, VAR_EXT_N_STAT, &varid)) != NC_NOERR) { |
| 211 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" from file ID %d", |
| 212 |
VAR_EXT_N_STAT, exoid); |
| 213 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 214 |
EX_FUNC_LEAVE(EX_FATAL); |
| 215 |
} |
| 216 |
|
| 217 |
if (ftype[0] == 'p') { |
| 218 |
start[0] = 0; |
| 219 |
} |
| 220 |
else { |
| 221 |
start[0] = processor; |
| 222 |
} |
| 223 |
|
| 224 |
if (nc_get_var1_int(exoid, varid, start, &nmstat) != NC_NOERR) { |
| 225 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file ID %d", |
| 226 |
VAR_EXT_N_STAT, exoid); |
| 227 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 228 |
EX_FUNC_LEAVE(EX_FATAL); |
| 229 |
} |
| 230 |
|
| 231 |
if (nmstat == 1) { |
| 232 |
/* get the index */ |
| 233 |
if (ex_get_idx(exoid, VAR_NODE_MAP_EXT_IDX, varidx, processor) == -1) { |
| 234 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 235 |
"ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_EXT_IDX, |
| 236 |
exoid); |
| 237 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 238 |
|
| 239 |
EX_FUNC_LEAVE(EX_FATAL); |
| 240 |
} |
| 241 |
|
| 242 |
/* check if I need to get the dimension */ |
| 243 |
if (varidx[1] == -1) { |
| 244 |
if ((status = nc_inq_dimid(exoid, DIM_NUM_EXT_NODES, &dimid)) != NC_NOERR) { |
| 245 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 246 |
"ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_EXT_NODES, |
| 247 |
exoid); |
| 248 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 249 |
EX_FUNC_LEAVE(EX_FATAL); |
| 250 |
} |
| 251 |
|
| 252 |
if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { |
| 253 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 254 |
"ERROR: failed to find length of dimension \"%s\" in file ID %d", |
| 255 |
DIM_NUM_EXT_NODES, exoid); |
| 256 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 257 |
EX_FUNC_LEAVE(EX_FATAL); |
| 258 |
} |
| 259 |
varidx[1] = count[0]; |
| 260 |
} |
| 261 |
|
| 262 |
if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_EXT, &varid)) != NC_NOERR) { |
| 263 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 264 |
VAR_NODE_MAP_EXT, exoid); |
| 265 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 266 |
EX_FUNC_LEAVE(EX_FATAL); |
| 267 |
} |
| 268 |
|
| 269 |
start[0] = varidx[0]; |
| 270 |
count[0] = varidx[1] - varidx[0]; |
| 271 |
if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { |
| 272 |
status = nc_get_vara_longlong(exoid, varid, start, count, node_mape); |
| 273 |
} |
| 274 |
else { |
| 275 |
status = nc_get_vara_int(exoid, varid, start, count, node_mape); |
| 276 |
} |
| 277 |
if (status != NC_NOERR) { |
| 278 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", |
| 279 |
VAR_NODE_MAP_EXT, exoid); |
| 280 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 281 |
EX_FUNC_LEAVE(EX_FATAL); |
| 282 |
} |
| 283 |
} /* End "if (nmstat == 1)" */ |
| 284 |
EX_FUNC_LEAVE(EX_NOERR); |
| 285 |
} |