| 1 |
/* |
| 2 |
* Copyright(C) 1999-2021, 2024 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_init_global() |
| 12 |
***************************************************************************** |
| 13 |
* This function reads the global initial information. |
| 14 |
***************************************************************************** |
| 15 |
* Variable Index: |
| 16 |
* exoid - The NetCDF ID of an already open NemesisI file. |
| 17 |
* num_nodes_g - The number of global FEM nodes. This is output as |
| 18 |
* a NetCDF variable. |
| 19 |
* num_elems_g - The number of global FEM elements. This is output |
| 20 |
* as a NetCDF variable. |
| 21 |
* num_elem_blks_g - The number of global element blocks. This is output |
| 22 |
* as a NetCDF dimension. |
| 23 |
* num_node_sets_g - The number of global node sets. This is output as |
| 24 |
* a NetCDF dimension. |
| 25 |
* num_side_sets_g - The number of global side sets. This is output as |
| 26 |
* a NetCDF dimension. |
| 27 |
*/ |
| 28 |
/*****************************************************************************/ |
| 29 |
/*****************************************************************************/ |
| 30 |
/*****************************************************************************/ |
| 31 |
|
| 32 |
#include "exodusII.h" // for ex_err, void_int, etc |
| 33 |
#include "exodusII_int.h" // for EX_FATAL, etc |
| 34 |
|
| 35 |
/* Used to reduce repeated code below */ |
| 36 |
static int ex_get_dim_value(int exoid, const char *name, const char *dimension_name, int dimension, |
| 37 |
size_t *value) |
| 38 |
{ |
| 39 |
|
| 40 |
if (nc_inq_dimid(exoid, dimension_name, &dimension) != NC_NOERR) { |
| 41 |
/* optional and default to zero. */ |
| 42 |
*value = 0; |
| 43 |
} |
| 44 |
else { |
| 45 |
size_t tmp; |
| 46 |
int status; |
| 47 |
if ((status = nc_inq_dimlen(exoid, dimension, &tmp)) != NC_NOERR) { |
| 48 |
char errmsg[MAX_ERR_LENGTH]; |
| 49 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of %s in file id %d", name, |
| 50 |
exoid); |
| 51 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 52 |
return EX_FATAL; |
| 53 |
} |
| 54 |
*value = tmp; |
| 55 |
} |
| 56 |
return EX_NOERR; |
| 57 |
} |
| 58 |
|
| 59 |
/*! |
| 60 |
* \ingroup ModelDescription |
| 61 |
* \undoc |
| 62 |
*/ |
| 63 |
int ex_get_init_global(int exoid, void_int *num_nodes_g, void_int *num_elems_g, |
| 64 |
void_int *num_elem_blks_g, void_int *num_node_sets_g, |
| 65 |
void_int *num_side_sets_g) |
| 66 |
{ |
| 67 |
EX_FUNC_ENTER(); |
| 68 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 69 |
EX_FUNC_LEAVE(EX_FATAL); |
| 70 |
} |
| 71 |
|
| 72 |
/* Check the file version information */ |
| 73 |
int dimid; |
| 74 |
if ((dimid = nei_check_file_version(exoid)) != EX_NOERR) { |
| 75 |
EX_FUNC_LEAVE(dimid); |
| 76 |
} |
| 77 |
|
| 78 |
size_t nng; |
| 79 |
if (ex_get_dim_value(exoid, "global nodes", DIM_NUM_NODES_GLOBAL, dimid, &nng) != EX_NOERR) { |
| 80 |
EX_FUNC_LEAVE(EX_FATAL); |
| 81 |
} |
| 82 |
|
| 83 |
size_t neg; |
| 84 |
if (ex_get_dim_value(exoid, "global elements", DIM_NUM_ELEMS_GLOBAL, dimid, &neg) != EX_NOERR) { |
| 85 |
EX_FUNC_LEAVE(EX_FATAL); |
| 86 |
} |
| 87 |
|
| 88 |
size_t nebg; |
| 89 |
if (ex_get_dim_value(exoid, "global element blocks", DIM_NUM_ELBLK_GLOBAL, dimid, &nebg) != |
| 90 |
EX_NOERR) { |
| 91 |
EX_FUNC_LEAVE(EX_FATAL); |
| 92 |
} |
| 93 |
|
| 94 |
size_t nnsg; |
| 95 |
if (ex_get_dim_value(exoid, "global node sets", DIM_NUM_NS_GLOBAL, dimid, &nnsg) != EX_NOERR) { |
| 96 |
EX_FUNC_LEAVE(EX_FATAL); |
| 97 |
} |
| 98 |
|
| 99 |
size_t nssg; |
| 100 |
if (ex_get_dim_value(exoid, "global side sets", DIM_NUM_SS_GLOBAL, dimid, &nssg) != EX_NOERR) { |
| 101 |
EX_FUNC_LEAVE(EX_FATAL); |
| 102 |
} |
| 103 |
|
| 104 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 105 |
*(int64_t *)num_nodes_g = nng; |
| 106 |
*(int64_t *)num_elems_g = neg; |
| 107 |
*(int64_t *)num_elem_blks_g = nebg; |
| 108 |
*(int64_t *)num_node_sets_g = nnsg; |
| 109 |
*(int64_t *)num_side_sets_g = nssg; |
| 110 |
} |
| 111 |
else { |
| 112 |
*(int *)num_nodes_g = nng; |
| 113 |
*(int *)num_elems_g = neg; |
| 114 |
*(int *)num_elem_blks_g = nebg; |
| 115 |
*(int *)num_node_sets_g = nnsg; |
| 116 |
*(int *)num_side_sets_g = nssg; |
| 117 |
} |
| 118 |
|
| 119 |
EX_FUNC_LEAVE(EX_NOERR); |
| 120 |
} |