Debian Codegraph @

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

raw
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 * This function outputs the nodal map.
11 *****************************************************************************
12 * Variable Index:
13 * exoid - The NetCDF ID of an already open NemesisI file.
14 * node_mapi - Pointer to vector containing the internal FEM
15 * nodal IDs.
16 * node_mapb - Pointer to vector containing the border FEM
17 * nodal IDs.
18 * node_mape - Pointer to vector containing the external FEM
19 * nodal IDs.
20 * proc_id - The processor the file is being written for.
21 */
22 /*****************************************************************************/
23 /*****************************************************************************/
24 /*****************************************************************************/
25
26 #include <exodusII.h> // for ex_err, etc
27 #include <exodusII_int.h> // for EX_FATAL, DIM_NUM_BOR_NODES, etc
28
29 int ex_put_processor_node_maps(int exoid, const void_int *node_mapi, const void_int *node_mapb,
30 const void_int *node_mape, int proc_id)
31 {
32 int status, varid, dimid;
33 char ftype[2];
34 size_t start[1], count[1];
35 int64_t varidx[2];
36 int nmstat;
37
38 char errmsg[MAX_ERR_LENGTH];
39 /*-----------------------------Execution begins-----------------------------*/
40
41 EX_FUNC_ENTER();
42 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
43 EX_FUNC_LEAVE(EX_FATAL);
44 }
45
46 /* Get the file type */
47 if (exi_get_file_type(exoid, ftype) != EX_NOERR) {
48 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to find file type for file ID %d", exoid);
49 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
50
51 EX_FUNC_LEAVE(EX_FATAL);
52 }
53
54 /* Get the status of this node map */
55 if ((status = nc_inq_varid(exoid, VAR_INT_N_STAT, &varid)) != NC_NOERR) {
56 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" from file ID %d",
57 VAR_INT_N_STAT, exoid);
58 ex_err_fn(exoid, __func__, errmsg, status);
59 EX_FUNC_LEAVE(EX_FATAL);
60 }
61
62 if (ftype[0] == 'p') {
63 start[0] = 0;
64 }
65 else {
66 start[0] = proc_id;
67 }
68
69 if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) {
70 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file %d",
71 VAR_INT_N_STAT, exoid);
72 ex_err_fn(exoid, __func__, errmsg, status);
73 EX_FUNC_LEAVE(EX_FATAL);
74 }
75
76 /* Write out the internal node-number map */
77 if (nmstat == 1) {
78 /* get the index */
79 if (ex_get_idx(exoid, VAR_NODE_MAP_INT_IDX, varidx, proc_id) == -1) {
80 snprintf(errmsg, MAX_ERR_LENGTH,
81 "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_INT_IDX,
82 exoid);
83 ex_err_fn(exoid, __func__, errmsg, status);
84
85 EX_FUNC_LEAVE(EX_FATAL);
86 }
87
88 /* check if I need to get the dimension */
89 if (varidx[1] == -1) {
90 if ((status = nc_inq_dimid(exoid, DIM_NUM_INT_NODES, &dimid)) != NC_NOERR) {
91 snprintf(errmsg, MAX_ERR_LENGTH,
92 "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_INT_NODES,
93 exoid);
94 ex_err_fn(exoid, __func__, errmsg, status);
95 EX_FUNC_LEAVE(EX_FATAL);
96 }
97
98 if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
99 snprintf(errmsg, MAX_ERR_LENGTH,
100 "ERROR: failed to find length of dimension \"%s\" in file ID %d",
101 DIM_NUM_INT_NODES, exoid);
102 ex_err_fn(exoid, __func__, errmsg, status);
103 EX_FUNC_LEAVE(EX_FATAL);
104 }
105
106 varidx[1] = count[0];
107 }
108
109 if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_INT, &varid)) != NC_NOERR) {
110 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
111 VAR_NODE_MAP_INT, exoid);
112 ex_err_fn(exoid, __func__, errmsg, status);
113
114 EX_FUNC_LEAVE(EX_FATAL);
115 }
116
117 start[0] = varidx[0];
118 count[0] = varidx[1] - varidx[0];
119 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
120 status = nc_put_vara_longlong(exoid, varid, start, count, node_mapi);
121 }
122 else {
123 status = nc_put_vara_int(exoid, varid, start, count, node_mapi);
124 }
125 if (status != NC_NOERR) {
126 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d",
127 VAR_NODE_MAP_INT, exoid);
128 ex_err_fn(exoid, __func__, errmsg, status);
129 EX_FUNC_LEAVE(EX_FATAL);
130 }
131 } /* End "if (nmstat == 1)" */
132
133 /* Get the status of this node map */
134 if ((status = nc_inq_varid(exoid, VAR_BOR_N_STAT, &varid)) != NC_NOERR) {
135 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" from file ID %d",
136 VAR_BOR_N_STAT, exoid);
137 ex_err_fn(exoid, __func__, errmsg, status);
138 EX_FUNC_LEAVE(EX_FATAL);
139 }
140
141 if (ftype[0] == 'p') {
142 start[0] = 0;
143 }
144 else {
145 start[0] = proc_id;
146 }
147
148 if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) {
149 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file %d",
150 VAR_BOR_N_STAT, exoid);
151 ex_err_fn(exoid, __func__, errmsg, status);
152 EX_FUNC_LEAVE(EX_FATAL);
153 }
154
155 if (nmstat == 1) {
156 /* Write out the border node-number map */
157 /* get the index */
158 if (ex_get_idx(exoid, VAR_NODE_MAP_BOR_IDX, varidx, proc_id) == -1) {
159 snprintf(errmsg, MAX_ERR_LENGTH,
160 "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_BOR_IDX,
161 exoid);
162 ex_err_fn(exoid, __func__, errmsg, status);
163
164 EX_FUNC_LEAVE(EX_FATAL);
165 }
166
167 /* check if I need to get the dimension */
168 if (varidx[1] == -1) {
169 if ((status = nc_inq_dimid(exoid, DIM_NUM_BOR_NODES, &dimid)) != NC_NOERR) {
170 snprintf(errmsg, MAX_ERR_LENGTH,
171 "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_BOR_NODES,
172 exoid);
173 ex_err_fn(exoid, __func__, errmsg, status);
174 EX_FUNC_LEAVE(EX_FATAL);
175 }
176
177 if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
178 snprintf(errmsg, MAX_ERR_LENGTH,
179 "ERROR: failed to find length of dimension \"%s\" in file ID %d",
180 DIM_NUM_BOR_NODES, exoid);
181 ex_err_fn(exoid, __func__, errmsg, status);
182 EX_FUNC_LEAVE(EX_FATAL);
183 }
184
185 varidx[1] = count[0];
186 }
187
188 if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_BOR, &varid)) != NC_NOERR) {
189 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
190 VAR_NODE_MAP_BOR, exoid);
191 ex_err_fn(exoid, __func__, errmsg, status);
192
193 EX_FUNC_LEAVE(EX_FATAL);
194 }
195
196 /* Output the map */
197 start[0] = varidx[0];
198 count[0] = varidx[1] - varidx[0];
199 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
200 status = nc_put_vara_longlong(exoid, varid, start, count, node_mapb);
201 }
202 else {
203 status = nc_put_vara_int(exoid, varid, start, count, node_mapb);
204 }
205 if (status != NC_NOERR) {
206 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d",
207 VAR_NODE_MAP_BOR, exoid);
208 ex_err_fn(exoid, __func__, errmsg, status);
209 EX_FUNC_LEAVE(EX_FATAL);
210 }
211 } /* End "if (nmstat == 1)" */
212
213 /* Get the status of this node map */
214 if ((status = nc_inq_varid(exoid, VAR_EXT_N_STAT, &varid)) != NC_NOERR) {
215 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" from file ID %d",
216 VAR_EXT_N_STAT, exoid);
217 ex_err_fn(exoid, __func__, errmsg, status);
218 EX_FUNC_LEAVE(EX_FATAL);
219 }
220
221 if (ftype[0] == 'p') {
222 start[0] = 0;
223 }
224 else {
225 start[0] = proc_id;
226 }
227
228 if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) {
229 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file %d",
230 VAR_EXT_N_STAT, exoid);
231 ex_err_fn(exoid, __func__, errmsg, status);
232 EX_FUNC_LEAVE(EX_FATAL);
233 }
234
235 if (nmstat == 1) {
236 /* Write out the external node-number map */
237 if (ex_get_idx(exoid, VAR_NODE_MAP_EXT_IDX, varidx, proc_id) == -1) {
238 snprintf(errmsg, MAX_ERR_LENGTH,
239 "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_EXT_IDX,
240 exoid);
241 ex_err_fn(exoid, __func__, errmsg, status);
242
243 EX_FUNC_LEAVE(EX_FATAL);
244 }
245
246 /* check if I need to get the dimension */
247 if (varidx[1] == -1) {
248 if ((status = nc_inq_dimid(exoid, DIM_NUM_EXT_NODES, &dimid)) != NC_NOERR) {
249 snprintf(errmsg, MAX_ERR_LENGTH,
250 "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_EXT_NODES,
251 exoid);
252 ex_err_fn(exoid, __func__, errmsg, status);
253 EX_FUNC_LEAVE(EX_FATAL);
254 }
255
256 if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
257 snprintf(errmsg, MAX_ERR_LENGTH,
258 "ERROR: failed to find length of dimension \"%s\" in file ID %d",
259 DIM_NUM_EXT_NODES, exoid);
260 ex_err_fn(exoid, __func__, errmsg, status);
261 EX_FUNC_LEAVE(EX_FATAL);
262 }
263 varidx[1] = count[0];
264 }
265
266 if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_EXT, &varid)) != NC_NOERR) {
267 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
268 VAR_NODE_MAP_EXT, exoid);
269 ex_err_fn(exoid, __func__, errmsg, status);
270
271 EX_FUNC_LEAVE(EX_FATAL);
272 }
273
274 /* Output the map */
275 start[0] = varidx[0];
276 count[0] = varidx[1] - varidx[0];
277 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
278 status = nc_put_vara_longlong(exoid, varid, start, count, node_mape);
279 }
280 else {
281 status = nc_put_vara_int(exoid, varid, start, count, node_mape);
282 }
283 if (status != NC_NOERR) {
284 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d",
285 VAR_NODE_MAP_EXT, exoid);
286 ex_err_fn(exoid, __func__, errmsg, status);
287 EX_FUNC_LEAVE(EX_FATAL);
288 }
289 } /* End "if (nmstat == 1)" */
290 EX_FUNC_LEAVE(EX_NOERR);
291 }