Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_put_elem_cmap.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 /****************************************************************************/
11 /* Function(s) contained in this file:
12 * ex_put_elem_cmap()
13 ****************************************************************************
14 * The function outputs an elemental communication map.
15 ****************************************************************************
16 * Variable Index:
17 * exoid - The NetCDF ID of an already open NemesisI file.
18 * map_id - The ID of the elementa communication map to write.
19 * elem_ids - Pointer to vector of element IDs to output.
20 * side_ids - Pointer to vector of side IDs for each element
21 * in "elem_ids".
22 * proc_ids - Pointer to vector of processor IDs for each
23 * element in "elem_ids".
24 * processor - The processor the file being read was written for.
25 */
26 /****************************************************************************/
27 /****************************************************************************/
28 /****************************************************************************/
29
30 #include <exodusII.h> // for ex_err, etc
31 #include <exodusII_int.h> // for EX_FATAL, DIM_ECNT_CMAP, etc
32
33 int ex_put_elem_cmap(int exoid, ex_entity_id map_id, const void_int *elem_ids,
34 const void_int *side_ids, const void_int *proc_ids, int processor)
35 {
36 int map_idx, varid, dimid, status;
37 size_t start[1], count[1], ret_val;
38 int64_t varidx[2];
39 int value;
40
41 char errmsg[MAX_ERR_LENGTH];
42 /*-----------------------------Execution begins-----------------------------*/
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 /* get the index for the comm map information variables */
50 if (ex_get_idx(exoid, VAR_E_COMM_INFO_IDX, varidx, processor) == -1) {
51 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d",
52 VAR_E_COMM_INFO_IDX, exoid);
53 ex_err_fn(exoid, __func__, errmsg, EX_LASTERR);
54
55 EX_FUNC_LEAVE(EX_FATAL);
56 }
57
58 /* Get the index for this map_id */
59 if ((map_idx = nei_id_lkup(exoid, VAR_E_COMM_IDS, varidx, map_id)) == -1) {
60 snprintf(errmsg, MAX_ERR_LENGTH,
61 "ERROR: failed to find index for variable \"%s\" in file ID %d", VAR_E_COMM_IDS,
62 exoid);
63 ex_err_fn(exoid, __func__, errmsg, EX_LASTERR);
64 EX_FUNC_LEAVE(EX_FATAL);
65 }
66
67 /*
68 * Find out if this is a NULL comm map by checking it's entry in
69 * the status vector.
70 */
71 if ((status = nc_inq_varid(exoid, VAR_E_COMM_STAT, &varid)) != NC_NOERR) {
72 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
73 VAR_E_COMM_STAT, exoid);
74 ex_err_fn(exoid, __func__, errmsg, status);
75 EX_FUNC_LEAVE(EX_FATAL);
76 }
77
78 start[0] = map_idx;
79 if ((status = nc_get_var1_int(exoid, varid, start, &value)) != NC_NOERR) {
80 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
81 VAR_E_COMM_STAT, exoid);
82 ex_err_fn(exoid, __func__, errmsg, status);
83 EX_FUNC_LEAVE(EX_FATAL);
84 }
85
86 if (value == 0) {
87 EX_FUNC_LEAVE(EX_NOERR); /* NULL set */
88 }
89
90 /* now I need to get the comm map data index */
91 if (ex_get_idx(exoid, VAR_E_COMM_DATA_IDX, varidx, map_idx) == -1) {
92 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d",
93 VAR_E_COMM_DATA_IDX, exoid);
94 ex_err_fn(exoid, __func__, errmsg, status);
95
96 EX_FUNC_LEAVE(EX_FATAL);
97 }
98
99 /* check if I need to get the dimension of the cmap data */
100 if (varidx[1] == -1) {
101 /* Get the size of the comm maps */
102 if ((status = nc_inq_dimid(exoid, DIM_ECNT_CMAP, &dimid)) != NC_NOERR) {
103 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get dimension ID for \"%s\" in file ID %d",
104 DIM_ECNT_CMAP, exoid);
105 ex_err_fn(exoid, __func__, errmsg, status);
106 EX_FUNC_LEAVE(EX_FATAL);
107 }
108
109 if ((status = nc_inq_dimlen(exoid, dimid, &ret_val)) != NC_NOERR) {
110 snprintf(errmsg, MAX_ERR_LENGTH,
111 "ERROR: failed to get length of dimension \"%s\" in file ID %d", DIM_ECNT_CMAP,
112 exoid);
113 ex_err_fn(exoid, __func__, errmsg, status);
114 EX_FUNC_LEAVE(EX_FATAL);
115 }
116
117 varidx[1] = ret_val;
118 } /* "if (varidx[1]==-1)" */
119
120 start[0] = varidx[0];
121 count[0] = varidx[1] - varidx[0];
122
123 /* Output the element IDs for this comm map */
124 if ((status = nc_inq_varid(exoid, VAR_E_COMM_EIDS, &varid)) != NC_NOERR) {
125 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
126 VAR_E_COMM_EIDS, exoid);
127 ex_err_fn(exoid, __func__, errmsg, status);
128 EX_FUNC_LEAVE(EX_FATAL);
129 }
130
131 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
132 status = nc_put_vara_longlong(exoid, varid, start, count, elem_ids);
133 }
134 else {
135 status = nc_put_vara_int(exoid, varid, start, count, elem_ids);
136 }
137 if (status != NC_NOERR) {
138 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output vector \"%s\" in file ID %d",
139 VAR_E_COMM_EIDS, exoid);
140 ex_err_fn(exoid, __func__, errmsg, status);
141 EX_FUNC_LEAVE(EX_FATAL);
142 }
143
144 /* Output the processor IDs for this map */
145 if ((status = nc_inq_varid(exoid, VAR_E_COMM_PROC, &varid)) != NC_NOERR) {
146 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
147 VAR_E_COMM_PROC, exoid);
148 ex_err_fn(exoid, __func__, errmsg, status);
149 EX_FUNC_LEAVE(EX_FATAL);
150 }
151
152 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
153 status = nc_put_vara_longlong(exoid, varid, start, count, proc_ids);
154 }
155 else {
156 status = nc_put_vara_int(exoid, varid, start, count, proc_ids);
157 }
158 if (status != NC_NOERR) {
159 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d",
160 VAR_E_COMM_PROC, exoid);
161 ex_err_fn(exoid, __func__, errmsg, status);
162 EX_FUNC_LEAVE(EX_FATAL);
163 }
164
165 if ((status = nc_inq_varid(exoid, VAR_E_COMM_SIDS, &varid)) != NC_NOERR) {
166 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
167 VAR_E_COMM_SIDS, exoid);
168 ex_err_fn(exoid, __func__, errmsg, status);
169 EX_FUNC_LEAVE(EX_FATAL);
170 }
171
172 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
173 status = nc_put_vara_longlong(exoid, varid, start, count, side_ids);
174 }
175 else {
176 status = nc_put_vara_int(exoid, varid, start, count, side_ids);
177 }
178 if (status != NC_NOERR) {
179 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d",
180 VAR_E_COMM_SIDS, exoid);
181 ex_err_fn(exoid, __func__, errmsg, status);
182 EX_FUNC_LEAVE(EX_FATAL);
183 }
184 EX_FUNC_LEAVE(EX_NOERR);
185 }