Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2022, 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 * \undoc exgcss - ex_get_concat_sets
11 *
12 * reads the set ID's, set entry count array, set entry pointers
13 * array, set entry list, set extra list, and set distribution factors
14 * for all sets of the specified type.
15 *
16 * entry conditions -
17 * input parameters:
18 * int exoid exodus file id
19 * ex_entity_type set_type type of set
20 *
21 * exit conditions -
22 * struct ex_set_specs* set_specs set specs structure
23 *
24 * revision history -
25 *
26 *
27 *****************************************************************************/
28
29 #include "exodusII.h" // for ex_set_specs, ex_err, etc
30 #include "exodusII_int.h" // for exi_check_valid_file_id, etc
31
32 int ex_get_concat_sets(int exoid, ex_entity_type set_type, struct ex_set_specs *set_specs)
33 {
34 int status, dimid;
35 void_int *num_entries_per_set = set_specs->num_entries_per_set;
36 void_int *num_dist_per_set = set_specs->num_dist_per_set;
37 void_int *sets_entry_index = set_specs->sets_entry_index;
38 void_int *sets_dist_index = set_specs->sets_dist_index;
39
40 void *sets_dist_fact = set_specs->sets_dist_fact;
41
42 char errmsg[MAX_ERR_LENGTH];
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 /* setup pointers based on set_type
50 NOTE: there is another block that sets more stuff later ... */
51
52 ex_inquiry ex_inq_val;
53 if (set_type == EX_NODE_SET) {
54 ex_inq_val = EX_INQ_NODE_SETS;
55 }
56 else if (set_type == EX_EDGE_SET) {
57 ex_inq_val = EX_INQ_EDGE_SETS;
58 }
59 else if (set_type == EX_FACE_SET) {
60 ex_inq_val = EX_INQ_FACE_SETS;
61 }
62 else if (set_type == EX_SIDE_SET) {
63 ex_inq_val = EX_INQ_SIDE_SETS;
64 }
65 else if (set_type == EX_ELEM_SET) {
66 ex_inq_val = EX_INQ_ELEM_SETS;
67 }
68 else {
69 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: invalid set type (%d)", set_type);
70 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
71 EX_FUNC_LEAVE(EX_FATAL);
72 }
73
74 /* first check if any sets are specified */
75
76 if ((status = nc_inq_dimid(exoid, exi_dim_num_objects(set_type), &dimid)) != NC_NOERR) {
77 if (status == NC_EBADDIM) {
78 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %ss defined for file id %d",
79 ex_name_of_object(set_type), exoid);
80 ex_err_fn(exoid, __func__, errmsg, status);
81 EX_FUNC_LEAVE(EX_WARN);
82 }
83 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %ss defined in file id %d",
84 ex_name_of_object(set_type), exoid);
85 ex_err_fn(exoid, __func__, errmsg, status);
86 EX_FUNC_LEAVE(EX_FATAL);
87 }
88
89 /* inquire how many sets have been stored */
90
91 int num_sets = ex_inquire_int(exoid, ex_inq_val);
92 if (num_sets < 0) {
93 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of %ss defined for file id %d",
94 ex_name_of_object(set_type), exoid);
95 /* use error val from inquire */
96 ex_err_fn(exoid, __func__, errmsg, EX_LASTERR);
97 EX_FUNC_LEAVE(EX_FATAL);
98 }
99
100 if (ex_get_ids(exoid, set_type, set_specs->sets_ids) != NC_NOERR) {
101 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s ids for file id %d",
102 ex_name_of_object(set_type), exoid);
103 /* use error val from inquire */
104 ex_err_fn(exoid, __func__, errmsg, EX_LASTERR);
105 EX_FUNC_LEAVE(EX_FATAL);
106 }
107
108 if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
109 ((int64_t *)sets_entry_index)[0] = 0;
110 ((int64_t *)sets_dist_index)[0] = 0;
111 }
112 else {
113 ((int *)sets_entry_index)[0] = 0;
114 ((int *)sets_dist_index)[0] = 0;
115 }
116
117 for (int i = 0; i < num_sets; i++) {
118 int64_t set_id;
119 if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
120 set_id = ((int64_t *)set_specs->sets_ids)[i];
121 }
122 else {
123 set_id = ((int *)set_specs->sets_ids)[i];
124 }
125
126 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
127 if (ex_get_set_param(exoid, set_type, set_id, &(((int64_t *)num_entries_per_set)[i]),
128 &(((int64_t *)num_dist_per_set)[i])) != NC_NOERR) {
129 EX_FUNC_LEAVE(EX_FATAL); /* error will be reported by sub */
130 }
131
132 if (i < num_sets - 1) {
133 /* fill in entry and dist factor index arrays */
134 ((int64_t *)sets_entry_index)[i + 1] =
135 ((int64_t *)sets_entry_index)[i] + ((int64_t *)num_entries_per_set)[i];
136 ((int64_t *)sets_dist_index)[i + 1] =
137 ((int64_t *)sets_dist_index)[i] + ((int64_t *)num_dist_per_set)[i];
138 }
139
140 if (((int64_t *)num_entries_per_set)[i] == 0) { /* NULL set? */
141 continue;
142 }
143
144 {
145 /* Now, use ExodusII call to get sets */
146 int64_t *sets_entry_list = set_specs->sets_entry_list;
147 int64_t *sets_extra_list = set_specs->sets_extra_list;
148 int64_t *sets_extra =
149 sets_extra_list ? &(sets_extra_list)[((int64_t *)sets_entry_index)[i]] : NULL;
150 status = ex_get_set(exoid, set_type, set_id,
151 &(sets_entry_list[((int64_t *)sets_entry_index)[i]]), sets_extra);
152 }
153 }
154 else {
155 if (ex_get_set_param(exoid, set_type, set_id, &(((int *)num_entries_per_set)[i]),
156 &(((int *)num_dist_per_set)[i])) != NC_NOERR) {
157 EX_FUNC_LEAVE(EX_FATAL); /* error will be reported by sub */
158 }
159
160 if (i < num_sets - 1) {
161 /* fill in entry and dist factor index arrays */
162 ((int *)sets_entry_index)[i + 1] =
163 ((int *)sets_entry_index)[i] + ((int *)num_entries_per_set)[i];
164 ((int *)sets_dist_index)[i + 1] =
165 ((int *)sets_dist_index)[i] + ((int *)num_dist_per_set)[i];
166 }
167
168 if (((int *)num_entries_per_set)[i] == 0) { /* NULL set? */
169 continue;
170 }
171
172 {
173 /* Now, use ExodusII call to get sets */
174 int *sets_entry_list = set_specs->sets_entry_list;
175 int *sets_extra_list = set_specs->sets_extra_list;
176 int *sets_extra = sets_extra_list ? &(sets_extra_list)[((int *)sets_entry_index)[i]] : NULL;
177 status = ex_get_set(exoid, set_type, set_id,
178 &(sets_entry_list[((int *)sets_entry_index)[i]]), sets_extra);
179 }
180 }
181
182 if (status != NC_NOERR) {
183 EX_FUNC_LEAVE(EX_FATAL); /* error will be reported by subroutine */
184 }
185
186 /* get distribution factors for this set */
187 if (sets_dist_fact != NULL) {
188 size_t df_idx;
189 size_t num_dist;
190 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
191 df_idx = ((int64_t *)sets_dist_index)[i];
192 num_dist = ((int64_t *)num_dist_per_set)[i];
193 }
194 else {
195 df_idx = ((int *)sets_dist_index)[i];
196 num_dist = ((int *)num_dist_per_set)[i];
197 }
198 if (num_dist > 0) { /* only get df if they exist */
199 if (exi_comp_ws(exoid) == sizeof(float)) {
200 float *flt_dist_fact = sets_dist_fact;
201 status = ex_get_set_dist_fact(exoid, set_type, set_id, &(flt_dist_fact[df_idx]));
202 }
203 else {
204 double *dbl_dist_fact = sets_dist_fact;
205 status = ex_get_set_dist_fact(exoid, set_type, set_id, &(dbl_dist_fact[df_idx]));
206 }
207 if (status != NC_NOERR) {
208 EX_FUNC_LEAVE(EX_FATAL); /* error will be reported by subroutine */
209 }
210 }
211 }
212 }
213 EX_FUNC_LEAVE(EX_NOERR);
214 }