| 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 |
/****************************************************************************/ |
| 11 |
/* Function(s) contained in this file: |
| 12 |
* ex_put_node_cmap() |
| 13 |
**************************************************************************** |
| 14 |
* This function outputs a nodal communication map. |
| 15 |
**************************************************************************** |
| 16 |
* Variable Index: |
| 17 |
* exoid - The NetCDF ID of an already open NemesisI file. |
| 18 |
* map_id - The ID of the nodal communication map to retrieve. |
| 19 |
* node_ids - Pointer to vector containing the FEM node IDs |
| 20 |
* that make up this communication map. |
| 21 |
* proc_ids - Pointer to vector containing the processors IDs |
| 22 |
* associated with each of the nodes in this nodal |
| 23 |
* communication map. |
| 24 |
* processor - The processor the file is being written for. |
| 25 |
*/ |
| 26 |
/****************************************************************************/ |
| 27 |
/****************************************************************************/ |
| 28 |
/****************************************************************************/ |
| 29 |
|
| 30 |
#include <exodusII.h> // for ex_err, etc |
| 31 |
#include <exodusII_int.h> // for EX_FATAL, DIM_NCNT_CMAP, etc |
| 32 |
|
| 33 |
int ex_put_node_cmap(int exoid, ex_entity_id map_id, const void_int *node_ids, |
| 34 |
const void_int *proc_ids, int processor) |
| 35 |
{ |
| 36 |
int map_idx, varid, dimid, status; |
| 37 |
size_t start[1], count[1], ret_val; |
| 38 |
int64_t varidx[2]; |
| 39 |
int value; |
| 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 index for the comm map information variables */ |
| 50 |
if (ex_get_idx(exoid, VAR_N_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_N_COMM_INFO_IDX, exoid); |
| 53 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 54 |
|
| 55 |
EX_FUNC_LEAVE(EX_FATAL); |
| 56 |
} |
| 57 |
|
| 58 |
/* Get the index for this map_id */ |
| 59 |
if ((map_idx = nei_id_lkup(exoid, VAR_N_COMM_IDS, varidx, map_id)) == -1) { |
| 60 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 61 |
"ERROR: failed to find index for variable \"%s\" in file ID %d", VAR_N_COMM_IDS, |
| 62 |
exoid); |
| 63 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 64 |
EX_FUNC_LEAVE(EX_FATAL); |
| 65 |
} |
| 66 |
|
| 67 |
/* |
| 68 |
* Find out if this is a NULL comm map by checking it's entry in |
| 69 |
* the status vector. |
| 70 |
*/ |
| 71 |
if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &varid)) != NC_NOERR) { |
| 72 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 73 |
VAR_N_COMM_STAT, exoid); |
| 74 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 75 |
EX_FUNC_LEAVE(EX_FATAL); |
| 76 |
} |
| 77 |
|
| 78 |
start[0] = map_idx; |
| 79 |
if ((status = nc_get_var1_int(exoid, varid, start, &value)) != NC_NOERR) { |
| 80 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to get variable \"%s\" from file ID %d", |
| 81 |
VAR_N_COMM_STAT, exoid); |
| 82 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 83 |
EX_FUNC_LEAVE(EX_FATAL); |
| 84 |
} |
| 85 |
|
| 86 |
if (value == 0) { |
| 87 |
EX_FUNC_LEAVE(EX_NOERR); /* NULL set */ |
| 88 |
} |
| 89 |
|
| 90 |
/* now I need to get the comm map data index */ |
| 91 |
if (ex_get_idx(exoid, VAR_N_COMM_DATA_IDX, varidx, map_idx) == -1) { |
| 92 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d", |
| 93 |
VAR_N_COMM_DATA_IDX, exoid); |
| 94 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 95 |
|
| 96 |
EX_FUNC_LEAVE(EX_FATAL); |
| 97 |
} |
| 98 |
|
| 99 |
/* check if I need to get the dimension of the cmap data */ |
| 100 |
if (varidx[1] == -1) { |
| 101 |
/* Get the size of the comm maps */ |
| 102 |
if ((status = nc_inq_dimid(exoid, DIM_NCNT_CMAP, &dimid)) != NC_NOERR) { |
| 103 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get dimension ID for \"%s\" in file ID %d", |
| 104 |
DIM_NCNT_CMAP, exoid); |
| 105 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 106 |
EX_FUNC_LEAVE(EX_FATAL); |
| 107 |
} |
| 108 |
|
| 109 |
if ((status = nc_inq_dimlen(exoid, dimid, &ret_val)) != NC_NOERR) { |
| 110 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 111 |
"ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_NCNT_CMAP, |
| 112 |
exoid); |
| 113 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 114 |
EX_FUNC_LEAVE(EX_FATAL); |
| 115 |
} |
| 116 |
|
| 117 |
varidx[1] = ret_val; |
| 118 |
} /* "if (varidx[1]==-1)" */ |
| 119 |
|
| 120 |
start[0] = varidx[0]; |
| 121 |
count[0] = varidx[1] - varidx[0]; |
| 122 |
|
| 123 |
/* Output the node IDs for this comm map */ |
| 124 |
if ((status = nc_inq_varid(exoid, VAR_N_COMM_NIDS, &varid)) != NC_NOERR) { |
| 125 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 126 |
VAR_N_COMM_NIDS, exoid); |
| 127 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 128 |
EX_FUNC_LEAVE(EX_FATAL); |
| 129 |
} |
| 130 |
|
| 131 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 132 |
status = nc_put_vara_longlong(exoid, varid, start, count, node_ids); |
| 133 |
} |
| 134 |
else { |
| 135 |
status = nc_put_vara_int(exoid, varid, start, count, node_ids); |
| 136 |
} |
| 137 |
if (status != NC_NOERR) { |
| 138 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output vector \"%s\" in file ID %d", |
| 139 |
VAR_N_COMM_NIDS, exoid); |
| 140 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 141 |
EX_FUNC_LEAVE(EX_FATAL); |
| 142 |
} |
| 143 |
|
| 144 |
/* Output the processor IDs for this map */ |
| 145 |
if ((status = nc_inq_varid(exoid, VAR_N_COMM_PROC, &varid)) != NC_NOERR) { |
| 146 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 147 |
VAR_N_COMM_PROC, exoid); |
| 148 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 149 |
EX_FUNC_LEAVE(EX_FATAL); |
| 150 |
} |
| 151 |
|
| 152 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 153 |
status = nc_put_vara_longlong(exoid, varid, start, count, proc_ids); |
| 154 |
} |
| 155 |
else { |
| 156 |
status = nc_put_vara_int(exoid, varid, start, count, proc_ids); |
| 157 |
} |
| 158 |
if (status != NC_NOERR) { |
| 159 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d", |
| 160 |
VAR_N_COMM_PROC, exoid); |
| 161 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 162 |
EX_FUNC_LEAVE(EX_FATAL); |
| 163 |
} |
| 164 |
|
| 165 |
EX_FUNC_LEAVE(EX_NOERR); |
| 166 |
} |