| 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 |
/*****************************************************************************/ |
| 12 |
/* Function(s) contained in this file: |
| 13 |
* ex_put_init_global() |
| 14 |
***************************************************************************** |
| 15 |
* This function outputs the initial global information. |
| 16 |
***************************************************************************** |
| 17 |
* Variable Index: |
| 18 |
* exoid - The NetCDF ID of an already open NemesisI file. |
| 19 |
* num_nodes_g - The number of global FEM nodes. This is output as |
| 20 |
* a NetCDF variable. |
| 21 |
* num_elems_g - The number of global FEM elements. This is output |
| 22 |
* as a NetCDF variable. |
| 23 |
* num_elem_blks_g - The number of global element blocks. This is output |
| 24 |
* as a NetCDF dimension. |
| 25 |
* num_node_sets_g - The number of global node sets. This is output as |
| 26 |
* a NetCDF dimension. |
| 27 |
* num_side_sets_g - The number of global side sets. This is output as |
| 28 |
* a NetCDF dimension. |
| 29 |
*/ |
| 30 |
/*****************************************************************************/ |
| 31 |
/*****************************************************************************/ |
| 32 |
/*****************************************************************************/ |
| 33 |
|
| 34 |
#include <exodusII.h> // for ex_err, etc |
| 35 |
#include <exodusII_int.h> // for exi_leavedef, EX_FATAL, etc |
| 36 |
|
| 37 |
/*! |
| 38 |
* \ingroup ModelDescription |
| 39 |
* \undoc |
| 40 |
*/ |
| 41 |
int ex_put_init_global(int exoid, int64_t num_nodes_g, int64_t num_elems_g, int64_t num_elem_blks_g, |
| 42 |
int64_t num_node_sets_g, int64_t num_side_sets_g) |
| 43 |
{ |
| 44 |
int varid, dimid, status; |
| 45 |
char errmsg[MAX_ERR_LENGTH]; |
| 46 |
|
| 47 |
int int_type = NC_INT; |
| 48 |
int id_type = NC_INT; |
| 49 |
|
| 50 |
/*-----------------------------Execution begins-----------------------------*/ |
| 51 |
EX_FUNC_ENTER(); |
| 52 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 53 |
EX_FUNC_LEAVE(EX_FATAL); |
| 54 |
} |
| 55 |
|
| 56 |
if (ex_int64_status(exoid) & EX_BULK_INT64_DB) { |
| 57 |
int_type = NC_INT64; |
| 58 |
} |
| 59 |
if (ex_int64_status(exoid) & EX_IDS_INT64_DB) { |
| 60 |
id_type = NC_INT64; |
| 61 |
} |
| 62 |
/* Put NetCDF file into define mode */ |
| 63 |
if ((status = exi_redef(exoid, __func__)) != NC_NOERR) { |
| 64 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file ID %d into define mode", exoid); |
| 65 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 66 |
EX_FUNC_LEAVE(EX_FATAL); |
| 67 |
} |
| 68 |
|
| 69 |
/* Output the file version */ |
| 70 |
if ((status = exi_put_nemesis_version(exoid)) < 0) { |
| 71 |
EX_FUNC_LEAVE(status); |
| 72 |
} |
| 73 |
|
| 74 |
/* Define dimension for number of global nodes */ |
| 75 |
if ((status = nc_def_dim(exoid, DIM_NUM_NODES_GLOBAL, num_nodes_g, &dimid)) != NC_NOERR) { |
| 76 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to dimension \"%s\" in file ID %d", |
| 77 |
DIM_NUM_NODES_GLOBAL, exoid); |
| 78 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 79 |
/* Leave define mode before returning */ |
| 80 |
exi_leavedef(exoid, __func__); |
| 81 |
|
| 82 |
EX_FUNC_LEAVE(EX_FATAL); |
| 83 |
} |
| 84 |
|
| 85 |
/* Define dimension for number of global elements */ |
| 86 |
if ((status = nc_def_dim(exoid, DIM_NUM_ELEMS_GLOBAL, num_elems_g, &dimid)) != NC_NOERR) { |
| 87 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to dimension \"%s\" in file ID %d", |
| 88 |
DIM_NUM_ELEMS_GLOBAL, exoid); |
| 89 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 90 |
/* Leave define mode before returning */ |
| 91 |
exi_leavedef(exoid, __func__); |
| 92 |
|
| 93 |
EX_FUNC_LEAVE(EX_FATAL); |
| 94 |
} |
| 95 |
|
| 96 |
/* |
| 97 |
* Output the number of global element blocks. This is output as a |
| 98 |
* dimension since the vector of global element block IDs is sized |
| 99 |
* by this quantity. |
| 100 |
*/ |
| 101 |
if ((status = nc_def_dim(exoid, DIM_NUM_ELBLK_GLOBAL, num_elem_blks_g, &dimid)) != NC_NOERR) { |
| 102 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to dimension \"%s\" in file ID %d", |
| 103 |
DIM_NUM_ELBLK_GLOBAL, exoid); |
| 104 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 105 |
/* Leave define mode before returning */ |
| 106 |
exi_leavedef(exoid, __func__); |
| 107 |
|
| 108 |
EX_FUNC_LEAVE(EX_FATAL); |
| 109 |
} |
| 110 |
|
| 111 |
/* Define the element block IDs variable. */ |
| 112 |
if ((status = nc_def_var(exoid, VAR_ELBLK_IDS_GLOBAL, id_type, 1, &dimid, &varid)) != NC_NOERR) { |
| 113 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 114 |
"ERROR: failed to put variable definition for \"%s\" into file ID %d", |
| 115 |
VAR_ELBLK_IDS_GLOBAL, exoid); |
| 116 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 117 |
/* Leave define mode before returning */ |
| 118 |
exi_leavedef(exoid, __func__); |
| 119 |
|
| 120 |
EX_FUNC_LEAVE(EX_FATAL); |
| 121 |
} |
| 122 |
|
| 123 |
/* Define the element block counts variable. */ |
| 124 |
if ((status = nc_def_var(exoid, VAR_ELBLK_CNT_GLOBAL, int_type, 1, &dimid, &varid)) != NC_NOERR) { |
| 125 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 126 |
"ERROR: failed to put variable definition for \"%s\" into file ID %d", |
| 127 |
VAR_ELBLK_CNT_GLOBAL, exoid); |
| 128 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 129 |
/* Leave define mode before returning */ |
| 130 |
exi_leavedef(exoid, __func__); |
| 131 |
|
| 132 |
EX_FUNC_LEAVE(EX_FATAL); |
| 133 |
} |
| 134 |
|
| 135 |
/* |
| 136 |
* Output the number of global node sets. This is output as a |
| 137 |
* dimension since the vector of global element block IDs is sized |
| 138 |
* by this quantity. |
| 139 |
*/ |
| 140 |
if (num_node_sets_g > 0) { |
| 141 |
if ((status = nc_def_dim(exoid, DIM_NUM_NS_GLOBAL, num_node_sets_g, &dimid)) != NC_NOERR) { |
| 142 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to dimension \"%s\" in file ID %d", |
| 143 |
DIM_NUM_NS_GLOBAL, exoid); |
| 144 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 145 |
/* Leave define mode before returning */ |
| 146 |
exi_leavedef(exoid, __func__); |
| 147 |
|
| 148 |
EX_FUNC_LEAVE(EX_FATAL); |
| 149 |
} |
| 150 |
|
| 151 |
/* Define the variable for output of global node set IDs */ |
| 152 |
if ((status = nc_def_var(exoid, VAR_NS_IDS_GLOBAL, id_type, 1, &dimid, &varid)) != NC_NOERR) { |
| 153 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 154 |
"ERROR: failed to put variable definition for \"%s\" into file ID %d", |
| 155 |
VAR_NS_IDS_GLOBAL, exoid); |
| 156 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 157 |
|
| 158 |
/* Leave define mode before returning */ |
| 159 |
exi_leavedef(exoid, __func__); |
| 160 |
|
| 161 |
EX_FUNC_LEAVE(EX_FATAL); |
| 162 |
} |
| 163 |
|
| 164 |
/* Define variable for global node counts in each global node set */ |
| 165 |
if ((status = nc_def_var(exoid, VAR_NS_NODE_CNT_GLOBAL, int_type, 1, &dimid, &varid)) != |
| 166 |
NC_NOERR) { |
| 167 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 168 |
"ERROR: failed to put variable definition for \"%s\" into file ID %d", |
| 169 |
VAR_NS_NODE_CNT_GLOBAL, exoid); |
| 170 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 171 |
/* Leave define mode before returning */ |
| 172 |
exi_leavedef(exoid, __func__); |
| 173 |
|
| 174 |
EX_FUNC_LEAVE(EX_FATAL); |
| 175 |
} |
| 176 |
|
| 177 |
/* |
| 178 |
* Define variable for global dist. factor count in each global |
| 179 |
* node set |
| 180 |
*/ |
| 181 |
if ((status = nc_def_var(exoid, VAR_NS_DF_CNT_GLOBAL, int_type, 1, &dimid, &varid)) != |
| 182 |
NC_NOERR) { |
| 183 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 184 |
"ERROR: failed to put variable definition for \"%s\" into file ID %d", |
| 185 |
VAR_NS_DF_CNT_GLOBAL, exoid); |
| 186 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 187 |
/* Leave define mode before returning */ |
| 188 |
exi_leavedef(exoid, __func__); |
| 189 |
|
| 190 |
EX_FUNC_LEAVE(EX_FATAL); |
| 191 |
} |
| 192 |
|
| 193 |
} /* End "if (num_node_sets_g > 0)" */ |
| 194 |
|
| 195 |
/* |
| 196 |
* Output the number of global side sets. This is output as a |
| 197 |
* dimension since the vector of global element block IDs is sized |
| 198 |
* by this quantity. |
| 199 |
*/ |
| 200 |
if (num_side_sets_g > 0) { |
| 201 |
if ((status = nc_def_dim(exoid, DIM_NUM_SS_GLOBAL, num_side_sets_g, &dimid)) != NC_NOERR) { |
| 202 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to dimension \"%s\" in file id %d", |
| 203 |
DIM_NUM_SS_GLOBAL, exoid); |
| 204 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 205 |
/* Leave define mode before returning */ |
| 206 |
exi_leavedef(exoid, __func__); |
| 207 |
|
| 208 |
EX_FUNC_LEAVE(EX_FATAL); |
| 209 |
} |
| 210 |
|
| 211 |
/* Define the variable for output of global side set IDs */ |
| 212 |
if ((status = nc_def_var(exoid, VAR_SS_IDS_GLOBAL, id_type, 1, &dimid, &varid)) != NC_NOERR) { |
| 213 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 214 |
"ERROR: failed to put variable definition for \"%s\" into file id %d", |
| 215 |
VAR_SS_IDS_GLOBAL, exoid); |
| 216 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 217 |
|
| 218 |
/* Leave define mode before returning */ |
| 219 |
exi_leavedef(exoid, __func__); |
| 220 |
|
| 221 |
EX_FUNC_LEAVE(EX_FATAL); |
| 222 |
} |
| 223 |
|
| 224 |
/* |
| 225 |
* Define the variable for count of global number of sides in the |
| 226 |
* global side sets. |
| 227 |
*/ |
| 228 |
if ((status = nc_def_var(exoid, VAR_SS_SIDE_CNT_GLOBAL, int_type, 1, &dimid, &varid)) != |
| 229 |
NC_NOERR) { |
| 230 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 231 |
"ERROR: failed to put variable definition for \"%s\" into file id %d", |
| 232 |
VAR_SS_SIDE_CNT_GLOBAL, exoid); |
| 233 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 234 |
|
| 235 |
/* Leave define mode before returning */ |
| 236 |
exi_leavedef(exoid, __func__); |
| 237 |
|
| 238 |
EX_FUNC_LEAVE(EX_FATAL); |
| 239 |
} |
| 240 |
|
| 241 |
/* |
| 242 |
* Define the variable for count of global dist. factors in the |
| 243 |
* global side sets. |
| 244 |
*/ |
| 245 |
if ((status = nc_def_var(exoid, VAR_SS_DF_CNT_GLOBAL, int_type, 1, &dimid, &varid)) != |
| 246 |
NC_NOERR) { |
| 247 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 248 |
"ERROR: failed to put variable definition for \"%s\" into file id %d", |
| 249 |
VAR_SS_DF_CNT_GLOBAL, exoid); |
| 250 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 251 |
|
| 252 |
/* Leave define mode before returning */ |
| 253 |
exi_leavedef(exoid, __func__); |
| 254 |
|
| 255 |
EX_FUNC_LEAVE(EX_FATAL); |
| 256 |
} |
| 257 |
|
| 258 |
} /* End "if (num_side_sets_g > 0)" */ |
| 259 |
|
| 260 |
/* End define mode */ |
| 261 |
if (exi_leavedef(exoid, __func__) != EX_NOERR) { |
| 262 |
EX_FUNC_LEAVE(EX_FATAL); |
| 263 |
} |
| 264 |
|
| 265 |
EX_FUNC_LEAVE(EX_NOERR); |
| 266 |
} |