Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_partial_id_map.c

raw
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 #include "exodusII.h" // for ex_err, etc
10 #include "exodusII_int.h" // for EX_FATAL, EX_NOERR, etc
11
12 /*!
13 * \ingroup ModelDescription
14 *
15 * reads the a portion of the values of the id map for the entity type specified by `map_type`
16 * The beginning location of the read is a `start_entity_num` which is 1-based. The read will
17 * return `num_entities` values starting at that location. Requirements are:
18 * - `start_entity_num > 0`
19 * - `start_entity_num + num_entities - 1 <= num_entity` which is the number of entities of
20 * specified type (e.g. elements)
21 *
22 * \param exoid exodus file id
23 * \param map_type type (edge block, face block, edge set, ... )
24 * \param start_entity_num index of first entity in block to read (1-based)
25 * \param num_entities number of entries to read in this block/set
26 * \param map the values read are returned here.
27 */
28
29 int ex_get_partial_id_map(int exoid, ex_entity_type map_type, int64_t start_entity_num,
30 int64_t num_entities, void_int *map)
31 {
32 char errmsg[MAX_ERR_LENGTH];
33
34 EX_FUNC_ENTER();
35 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
36 EX_FUNC_LEAVE(EX_FATAL);
37 }
38
39 const char *dnumentries;
40 const char *vmap;
41 const char *tname;
42 switch (map_type) {
43 case EX_NODE_MAP:
44 tname = "node";
45 dnumentries = DIM_NUM_NODES;
46 vmap = VAR_NODE_NUM_MAP;
47 break;
48 case EX_EDGE_MAP:
49 tname = "edge";
50 dnumentries = DIM_NUM_EDGE;
51 vmap = VAR_EDGE_NUM_MAP;
52 break;
53 case EX_FACE_MAP:
54 tname = "face";
55 dnumentries = DIM_NUM_FACE;
56 vmap = VAR_FACE_NUM_MAP;
57 break;
58 case EX_ELEM_MAP:
59 tname = "element";
60 dnumentries = DIM_NUM_ELEM;
61 vmap = VAR_ELEM_NUM_MAP;
62 break;
63 default:
64 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Bad map type (%d) specified for file id %d", map_type,
65 exoid);
66 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
67 EX_FUNC_LEAVE(EX_FATAL);
68 }
69
70 /* See if any entries are stored in this file */
71 int dimid;
72 if (nc_inq_dimid(exoid, dnumentries, &dimid) != NC_NOERR) {
73 EX_FUNC_LEAVE(EX_NOERR);
74 }
75
76 size_t num_entries;
77 int status;
78 if ((status = nc_inq_dimlen(exoid, dimid, &num_entries)) != NC_NOERR) {
79 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of %ss in file id %d", tname,
80 exoid);
81 ex_err_fn(exoid, __func__, errmsg, status);
82 EX_FUNC_LEAVE(EX_FATAL);
83 }
84
85 if (start_entity_num < 1) {
86 snprintf(errmsg, MAX_ERR_LENGTH,
87 "ERROR: start index (%" PRId64 ") must be greater than 0 in file id %d",
88 start_entity_num, exoid);
89 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
90 EX_FUNC_LEAVE(EX_FATAL);
91 }
92
93 if (start_entity_num + num_entities - 1 > (int64_t)num_entries) {
94 snprintf(errmsg, MAX_ERR_LENGTH,
95 "ERROR: start index (%" PRId64 ") + entity count (%" PRId64
96 ") is larger than total number of entities (%zu) in file id %d",
97 start_entity_num, num_entities, num_entries, exoid);
98 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
99 EX_FUNC_LEAVE(EX_FATAL);
100 }
101
102 int mapid;
103 if (nc_inq_varid(exoid, vmap, &mapid) != NC_NOERR) {
104 /* generate portion of the default map (1..num_entries) */
105 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
106 int64_t *lmap = (int64_t *)map;
107 for (int64_t i = 0; i < num_entities; i++) {
108 lmap[i] = start_entity_num + i;
109 }
110 }
111 else {
112 int *lmap = (int *)map;
113 for (int64_t i = 0; i < num_entities; i++) {
114 lmap[i] = start_entity_num + i;
115 }
116 }
117
118 EX_FUNC_LEAVE(EX_NOERR);
119 }
120
121 size_t start[] = {start_entity_num - 1};
122 size_t count[] = {num_entities};
123 if (count[0] == 0) {
124 start[0] = 0;
125 }
126
127 /* read in the id map */
128 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
129 status = nc_get_vara_longlong(exoid, mapid, start, count, map);
130 }
131 else {
132 status = nc_get_vara_int(exoid, mapid, start, count, map);
133 }
134
135 if (status != NC_NOERR) {
136 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s id map in file id %d", tname, exoid);
137 ex_err_fn(exoid, __func__, errmsg, status);
138 EX_FUNC_LEAVE(EX_FATAL);
139 }
140
141 EX_FUNC_LEAVE(EX_NOERR);
142 }