1 /*
2 * Copyright (c) 1998 Sandia Corporation. Under the terms of Contract
3 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement
4 * retains certain rights in this software.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 *
18 * * Neither the name of Sandia Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
35
36 /*****************************************************************************
37 * This function outputs the nodal map.
38 *****************************************************************************
39 * Variable Index:
40 * exoid - The NetCDF ID of an already open NemesisI file.
41 * node_mapi - Pointer to vector containing the internal FEM
42 * nodal IDs.
43 * node_mapb - Pointer to vector containing the border FEM
44 * nodal IDs.
45 * node_mape - Pointer to vector containing the external FEM
46 * nodal IDs.
47 * proc_id - The processor the file is being written for.
48 */
49 /*****************************************************************************/
50 /*****************************************************************************/
51 /*****************************************************************************/
52
53 #include <stdio.h>
54
55 #include <netcdf.h>
56
57 #include <exodusII.h>
58 #include <exodusII_int.h>
59
ex_put_processor_node_maps(int exoid,void_int * node_mapi,void_int * node_mapb,void_int * node_mape,int proc_id)60 int ex_put_processor_node_maps(int exoid,
61 void_int *node_mapi,
62 void_int *node_mapb,
63 void_int *node_mape,
64 int proc_id
65 )
66 {
67 const char *func_name="ex_put_processor_node_maps";
68
69 int status, varid, dimid;
70 char ftype[2];
71 size_t start[1], count[1];
72 int64_t varidx[2];
73 int nmstat;
74
75 char errmsg[MAX_ERR_LENGTH];
76 /*-----------------------------Execution begins-----------------------------*/
77
78 exerrval = 0; /* clear error code */
79
80 /* Get the file type */
81 if (ex_get_file_type(exoid, ftype) != EX_NOERR) {
82 exerrval = EX_MSG;
83 sprintf(errmsg,
84 "Error: unable to find file type for file ID %d",
85 exoid);
86 ex_err(func_name, errmsg, exerrval);
87
88 return (EX_FATAL);
89 }
90
91 /* Get the status of this node map */
92 if ((status = nc_inq_varid(exoid, VAR_INT_N_STAT, &varid)) != NC_NOERR) {
93 exerrval = status;
94 sprintf(errmsg,
95 "Error: failed to find variable ID for \"%s\" from file ID %d",
96 VAR_INT_N_STAT, exoid);
97 ex_err(func_name, errmsg, exerrval);
98 return (EX_FATAL);
99 }
100
101 if (ftype[0] == 'p')
102 start[0] = 0;
103 else
104 start[0] = proc_id;
105
106 if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) {
107 exerrval = status;
108 sprintf(errmsg,
109 "Error: failed to get status for \"%s\" from file %d",
110 VAR_INT_N_STAT, exoid);
111 ex_err(func_name, errmsg, exerrval);
112 return (EX_FATAL);
113 }
114
115 /* Write out the internal node-number map */
116 if (nmstat == 1) {
117 /* get the index */
118 if (ex_get_idx(exoid, VAR_NODE_MAP_INT_IDX, varidx, proc_id) == -1) {
119 exerrval = status;
120 sprintf(errmsg,
121 "Error: failed to find index variable, \"%s\", in file ID %d",
122 VAR_NODE_MAP_INT_IDX, exoid);
123 ex_err(func_name, errmsg, exerrval);
124
125 return (EX_FATAL);
126 }
127
128 /* check if I need to get the dimension */
129 if (varidx[1] == -1) {
130 if ((status = nc_inq_dimid(exoid, DIM_NUM_INT_NODES, &dimid)) != NC_NOERR) {
131 exerrval = status;
132 sprintf(errmsg,
133 "Error: failed to find dimension ID for \"%s\" in file ID %d",
134 DIM_NUM_INT_NODES, exoid);
135 ex_err(func_name, errmsg, exerrval);
136 return (EX_FATAL);
137 }
138
139 if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
140 exerrval = status;
141 sprintf(errmsg,
142 "Error: failed to find length of dimension \"%s\" in file ID %d",
143 DIM_NUM_INT_NODES, exoid);
144 ex_err(func_name, errmsg, exerrval);
145 return (EX_FATAL);
146 }
147
148 varidx[1] = count[0];
149 }
150
151 if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_INT, &varid)) != NC_NOERR) {
152 exerrval = status;
153 sprintf(errmsg,
154 "Error: failed to find variable ID for \"%s\" in file ID %d",
155 VAR_NODE_MAP_INT, exoid);
156 ex_err(func_name, errmsg, exerrval);
157
158 return (EX_FATAL);
159 }
160
161 start[0] = varidx[0];
162 count[0] = varidx[1] - varidx[0];
163 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
164 status = nc_put_vara_longlong(exoid, varid, start, count, node_mapi);
165 } else {
166 status = nc_put_vara_int(exoid, varid, start, count, node_mapi);
167 }
168 if (status != NC_NOERR) {
169 exerrval = status;
170 sprintf(errmsg,
171 "Error: failed to output variable \"%s\" in file ID %d",
172 VAR_NODE_MAP_INT, exoid);
173 ex_err(func_name, errmsg, exerrval);
174 return (EX_FATAL);
175 }
176 } /* End "if (nmstat == 1)" */
177
178 /* Get the status of this node map */
179 if ((status = nc_inq_varid(exoid, VAR_BOR_N_STAT, &varid)) != NC_NOERR) {
180 exerrval = status;
181 sprintf(errmsg,
182 "Error: failed to find variable ID for \"%s\" from file ID %d",
183 VAR_BOR_N_STAT, exoid);
184 ex_err(func_name, errmsg, exerrval);
185 return (EX_FATAL);
186 }
187
188 if (ftype[0] == 'p')
189 start[0] = 0;
190 else
191 start[0] = proc_id;
192
193 if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) {
194 exerrval = status;
195 sprintf(errmsg,
196 "Error: failed to get status for \"%s\" from file %d",
197 VAR_BOR_N_STAT, exoid);
198 ex_err(func_name, errmsg, exerrval);
199 return (EX_FATAL);
200 }
201
202 if (nmstat == 1) {
203 /* Write out the border node-number map */
204 /* get the index */
205 if (ex_get_idx(exoid, VAR_NODE_MAP_BOR_IDX, varidx, proc_id) == -1) {
206 exerrval = status;
207 sprintf(errmsg,
208 "Error: failed to find index variable, \"%s\", in file ID %d",
209 VAR_NODE_MAP_BOR_IDX, exoid);
210 ex_err(func_name, errmsg, exerrval);
211
212 return (EX_FATAL);
213 }
214
215 /* check if I need to get the dimension */
216 if (varidx[1] == -1) {
217 if ((status = nc_inq_dimid(exoid, DIM_NUM_BOR_NODES, &dimid)) != NC_NOERR) {
218 exerrval = status;
219 sprintf(errmsg,
220 "Error: failed to find dimension ID for \"%s\" in file ID %d",
221 DIM_NUM_BOR_NODES, exoid);
222 ex_err(func_name, errmsg, exerrval);
223 return (EX_FATAL);
224 }
225
226 if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
227 exerrval = status;
228 sprintf(errmsg,
229 "Error: failed to find length of dimension \"%s\" in file ID %d",
230 DIM_NUM_BOR_NODES, exoid);
231 ex_err(func_name, errmsg, exerrval);
232 return (EX_FATAL);
233 }
234
235 varidx[1] = count[0];
236 }
237
238 if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_BOR, &varid)) != NC_NOERR) {
239 exerrval = status;
240 sprintf(errmsg,
241 "Error: failed to find variable ID for \"%s\" in file ID %d",
242 VAR_NODE_MAP_BOR, exoid);
243 ex_err(func_name, errmsg, exerrval);
244
245 return (EX_FATAL);
246 }
247
248 /* Output the map */
249 start[0] = varidx[0];
250 count[0] = varidx[1] - varidx[0];
251 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
252 status = nc_put_vara_longlong(exoid, varid, start, count, node_mapb);
253 } else {
254 status = nc_put_vara_int(exoid, varid, start, count, node_mapb);
255 }
256 if (status != NC_NOERR) {
257 exerrval = status;
258 sprintf(errmsg,
259 "Error: failed to output variable \"%s\" in file ID %d",
260 VAR_NODE_MAP_BOR, exoid);
261 ex_err(func_name, errmsg, exerrval);
262 return (EX_FATAL);
263 }
264 } /* End "if (nmstat == 1)" */
265
266 /* Get the status of this node map */
267 if ((status = nc_inq_varid(exoid, VAR_EXT_N_STAT, &varid)) != NC_NOERR) {
268 exerrval = status;
269 sprintf(errmsg,
270 "Error: failed to find variable ID for \"%s\" from file ID %d",
271 VAR_EXT_N_STAT, exoid);
272 ex_err(func_name, errmsg, exerrval);
273 return (EX_FATAL);
274 }
275
276 if (ftype[0] == 'p')
277 start[0] = 0;
278 else
279 start[0] = proc_id;
280
281 if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) {
282 exerrval = status;
283 sprintf(errmsg,
284 "Error: failed to get status for \"%s\" from file %d",
285 VAR_EXT_N_STAT, exoid);
286 ex_err(func_name, errmsg, exerrval);
287 return (EX_FATAL);
288 }
289
290 if (nmstat == 1) {
291 /* Write out the external node-number map */
292 if (ex_get_idx(exoid, VAR_NODE_MAP_EXT_IDX, varidx, proc_id) == -1) {
293 exerrval = status;
294 sprintf(errmsg,
295 "Error: failed to find index variable, \"%s\", in file ID %d",
296 VAR_NODE_MAP_EXT_IDX, exoid);
297 ex_err(func_name, errmsg, exerrval);
298
299 return (EX_FATAL);
300 }
301
302 /* check if I need to get the dimension */
303 if (varidx[1] == -1) {
304 if ((status = nc_inq_dimid(exoid, DIM_NUM_EXT_NODES, &dimid)) != NC_NOERR) {
305 exerrval = status;
306 sprintf(errmsg,
307 "Error: failed to find dimension ID for \"%s\" in file ID %d",
308 DIM_NUM_EXT_NODES, exoid);
309 ex_err(func_name, errmsg, exerrval);
310 return (EX_FATAL);
311 }
312
313 if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
314 exerrval = status;
315 sprintf(errmsg,
316 "Error: failed to find length of dimension \"%s\" in file ID %d",
317 DIM_NUM_EXT_NODES, exoid);
318 ex_err(func_name, errmsg, exerrval);
319 return (EX_FATAL);
320 }
321 varidx[1] = count[0];
322 }
323
324 if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_EXT, &varid)) != NC_NOERR) {
325 exerrval = status;
326 sprintf(errmsg,
327 "Error: failed to find variable ID for \"%s\" in file ID %d",
328 VAR_NODE_MAP_EXT, exoid);
329 ex_err(func_name, errmsg, exerrval);
330
331 return (EX_FATAL);
332 }
333
334 /* Output the map */
335 start[0] = varidx[0];
336 count[0] = varidx[1] - varidx[0];
337 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
338 status = nc_put_vara_longlong(exoid, varid, start, count, node_mape);
339 } else {
340 status = nc_put_vara_int(exoid, varid, start, count, node_mape);
341 }
342 if (status != NC_NOERR) {
343 exerrval = status;
344 sprintf(errmsg,
345 "Error: failed to output variable \"%s\" in file ID %d",
346 VAR_NODE_MAP_EXT, exoid);
347 ex_err(func_name, errmsg, exerrval);
348 return (EX_FATAL);
349 }
350 } /* End "if (nmstat == 1)" */
351 return (EX_NOERR);
352 }
353