| 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_elem_cmap() |
| 12 |
**************************************************************************** |
| 13 |
* This function retrieves an elemental communication map. |
| 14 |
**************************************************************************** |
| 15 |
* Variable Index: |
| 16 |
* exoid - The NetCDF ID of an already open NemesisI file. |
| 17 |
* map_id - The ID of the nodal communication map to retrieve. |
| 18 |
* elem_ids - Pointer to vector for retrieval of FEM element IDs |
| 19 |
* that make up this communication map. |
| 20 |
* side_ids - Pointer to vector for retrieval of FEM element |
| 21 |
* side IDs that make up this communication map. |
| 22 |
* proc_ids - Pointer to vector for retrieval of the processors |
| 23 |
* associated with each of the elements in this |
| 24 |
* elemental communication map. |
| 25 |
* processor - The processor the file being read was written for. |
| 26 |
*/ |
| 27 |
/****************************************************************************/ |
| 28 |
/****************************************************************************/ |
| 29 |
/****************************************************************************/ |
| 30 |
|
| 31 |
#include <exodusII.h> // for ex_err, etc |
| 32 |
#include <exodusII_int.h> // for EX_FATAL, DIM_ECNT_CMAP, etc |
| 33 |
|
| 34 |
int ex_get_elem_cmap(int exoid, ex_entity_id map_id, void_int *elem_ids, void_int *side_ids, |
| 35 |
void_int *proc_ids, int processor) |
| 36 |
{ |
| 37 |
int map_idx, dimid, varid[3], status; |
| 38 |
size_t start[1], count[1]; |
| 39 |
int64_t varidx[2]; |
| 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 cmap information variables index */ |
| 50 |
if (ex_get_idx(exoid, VAR_E_COMM_INFO_IDX, varidx, processor) == -1) { |
| 51 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d", |
| 52 |
VAR_E_COMM_INFO_IDX, exoid); |
| 53 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 54 |
|
| 55 |
EX_FUNC_LEAVE(EX_FATAL); |
| 56 |
} |
| 57 |
|
| 58 |
/* |
| 59 |
* no need to check if the second index is -1 that is handled |
| 60 |
* in nei_id_lkup, where the dimension must be looked up anyways |
| 61 |
*/ |
| 62 |
|
| 63 |
/* Get the index of the elemental comm map with the given ID */ |
| 64 |
if ((map_idx = nei_id_lkup(exoid, VAR_E_COMM_IDS, varidx, map_id)) < 0) { |
| 65 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 66 |
"ERROR: failed to find elemental comm map with ID %" PRId64 " in file \ |
| 67 |
ID %d", |
| 68 |
map_id, exoid); |
| 69 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 70 |
EX_FUNC_LEAVE(EX_FATAL); |
| 71 |
} |
| 72 |
|
| 73 |
/* get the cmap data variables index for this map */ |
| 74 |
if (ex_get_idx(exoid, VAR_E_COMM_DATA_IDX, varidx, map_idx) == -1) { |
| 75 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d", |
| 76 |
VAR_E_COMM_DATA_IDX, exoid); |
| 77 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 78 |
|
| 79 |
EX_FUNC_LEAVE(EX_FATAL); |
| 80 |
} |
| 81 |
|
| 82 |
if (varidx[1] == -1) { |
| 83 |
/* Get the dimension of this elemental communication map */ |
| 84 |
if ((status = nc_inq_dimid(exoid, DIM_ECNT_CMAP, &dimid)) != NC_NOERR) { |
| 85 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 86 |
"ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_ECNT_CMAP, exoid); |
| 87 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 88 |
EX_FUNC_LEAVE(EX_FATAL); |
| 89 |
} |
| 90 |
|
| 91 |
if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { |
| 92 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 93 |
"ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_ECNT_CMAP, |
| 94 |
exoid); |
| 95 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 96 |
EX_FUNC_LEAVE(EX_FATAL); |
| 97 |
} |
| 98 |
|
| 99 |
varidx[1] = count[0]; |
| 100 |
} |
| 101 |
|
| 102 |
/* Get the variable ID for the elemental comm map node IDs */ |
| 103 |
if ((status = nc_inq_varid(exoid, VAR_E_COMM_EIDS, &varid[0])) != NC_NOERR) { |
| 104 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 105 |
VAR_E_COMM_EIDS, exoid); |
| 106 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 107 |
EX_FUNC_LEAVE(EX_FATAL); |
| 108 |
} |
| 109 |
|
| 110 |
/* Get the variable ID for the elemental side set IDs */ |
| 111 |
if ((status = nc_inq_varid(exoid, VAR_E_COMM_SIDS, &varid[1])) != NC_NOERR) { |
| 112 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 113 |
VAR_E_COMM_SIDS, exoid); |
| 114 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 115 |
EX_FUNC_LEAVE(EX_FATAL); |
| 116 |
} |
| 117 |
|
| 118 |
/* Get the variable ID for the elemental comm map processor IDs */ |
| 119 |
if ((status = nc_inq_varid(exoid, VAR_E_COMM_PROC, &varid[2])) != NC_NOERR) { |
| 120 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 121 |
VAR_E_COMM_PROC, exoid); |
| 122 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 123 |
EX_FUNC_LEAVE(EX_FATAL); |
| 124 |
} |
| 125 |
|
| 126 |
/* Get the elemental comm map element IDs */ |
| 127 |
start[0] = varidx[0]; |
| 128 |
count[0] = varidx[1] - varidx[0]; |
| 129 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 130 |
status = nc_get_vara_longlong(exoid, varid[0], start, count, elem_ids); |
| 131 |
} |
| 132 |
else { |
| 133 |
status = nc_get_vara_int(exoid, varid[0], start, count, elem_ids); |
| 134 |
} |
| 135 |
if (status != NC_NOERR) { |
| 136 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", |
| 137 |
VAR_E_COMM_EIDS, exoid); |
| 138 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 139 |
EX_FUNC_LEAVE(EX_FATAL); |
| 140 |
} |
| 141 |
|
| 142 |
/* Get the elemental comm map side IDs */ |
| 143 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 144 |
status = nc_get_vara_longlong(exoid, varid[1], start, count, side_ids); |
| 145 |
} |
| 146 |
else { |
| 147 |
status = nc_get_vara_int(exoid, varid[1], start, count, side_ids); |
| 148 |
} |
| 149 |
if (status != NC_NOERR) { |
| 150 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", |
| 151 |
VAR_E_COMM_SIDS, exoid); |
| 152 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 153 |
EX_FUNC_LEAVE(EX_FATAL); |
| 154 |
} |
| 155 |
|
| 156 |
/* Get the elemental comm map processor IDs */ |
| 157 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 158 |
status = nc_get_vara_longlong(exoid, varid[2], start, count, proc_ids); |
| 159 |
} |
| 160 |
else { |
| 161 |
status = nc_get_vara_int(exoid, varid[2], start, count, proc_ids); |
| 162 |
} |
| 163 |
if (status != NC_NOERR) { |
| 164 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", |
| 165 |
VAR_E_COMM_PROC, exoid); |
| 166 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 167 |
EX_FUNC_LEAVE(EX_FATAL); |
| 168 |
} |
| 169 |
EX_FUNC_LEAVE(EX_NOERR); |
| 170 |
} |