Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-, 20212021 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 * This function outputs a portion of the nodal communication map.
10 ****************************************************************************
11 * Variable Index:
12 * exoid - The NetCDF ID of an already open NemesisI file.
13 * map_id - The ID of the nodal communication map to retrieve.
14 * node_ids - Pointer to vector containing the FEM node IDs
15 * that make up this communication map.
16 * proc_ids - Pointer to vector containing the processors IDs
17 * associated with each of the nodes in this nodal
18 * communication map.
19 * processor - The processor the file is being written for.
20 */
21 /****************************************************************************/
22 /****************************************************************************/
23 /****************************************************************************/
24
25 #include <exodusII.h> // for ex_err, etc
26 #include <exodusII_int.h> // for EX_FATAL, DIM_NCNT_CMAP, etc
27
28 /*!
29 * writes out a portion of the nodal communication map to the
30 * database; This map specifies the nodes on a processor boundary and
31 * the processors that those nodes are shared with.
32 *
33 * \param exoid exodus file id
34 * \param map_id
35 * \param start_entity_num
36 * \param num_entities
37 * \param node_ids the file-local node ids on the processor boundary
38 * \param proc_ids the processor ids associated with each of the node_ids
39 * \param processor the processor the file is being written for.
40 */
41
42 int ex_put_partial_node_cmap(int exoid, ex_entity_id map_id, int64_t start_entity_num,
43 int64_t num_entities, const void_int *node_ids,
44 const void_int *proc_ids, int processor)
45 {
46 int map_idx, varid, dimid, status;
47 size_t start[1], count[1], ret_val;
48 int64_t varidx[2];
49 int value;
50
51 char errmsg[MAX_ERR_LENGTH];
52 /*-----------------------------Execution begins-----------------------------*/
53
54 EX_FUNC_ENTER();
55 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
56 EX_FUNC_LEAVE(EX_FATAL);
57 }
58
59 /* get the index for the comm map information variables */
60 if (ex_get_idx(exoid, VAR_N_COMM_INFO_IDX, varidx, processor) == -1) {
61 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d",
62 VAR_N_COMM_INFO_IDX, exoid);
63 ex_err_fn(exoid, __func__, errmsg, EX_LASTERR);
64
65 EX_FUNC_LEAVE(EX_FATAL);
66 }
67
68 /* Get the index for this map_id */
69 if ((map_idx = nei_id_lkup(exoid, VAR_N_COMM_IDS, varidx, map_id)) == -1) {
70 snprintf(errmsg, MAX_ERR_LENGTH,
71 "ERROR: failed to find index for variable \"%s\" in file ID %d", VAR_N_COMM_IDS,
72 exoid);
73 ex_err_fn(exoid, __func__, errmsg, EX_LASTERR);
74 EX_FUNC_LEAVE(EX_FATAL);
75 }
76
77 /*
78 * Find out if this is a NULL comm map by checking it's entry in
79 * the status vector.
80 */
81 if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &varid)) != NC_NOERR) {
82 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
83 VAR_N_COMM_STAT, exoid);
84 ex_err_fn(exoid, __func__, errmsg, status);
85 EX_FUNC_LEAVE(EX_FATAL);
86 }
87
88 start[0] = map_idx;
89 if ((status = nc_get_var1_int(exoid, varid, start, &value)) != NC_NOERR) {
90 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to get variable \"%s\" from file ID %d",
91 VAR_N_COMM_STAT, exoid);
92 ex_err_fn(exoid, __func__, errmsg, status);
93 EX_FUNC_LEAVE(EX_FATAL);
94 }
95
96 if (value == 0) {
97 EX_FUNC_LEAVE(EX_NOERR); /* NULL set */
98 }
99
100 /* now I need to get the comm map data index */
101 if (ex_get_idx(exoid, VAR_N_COMM_DATA_IDX, varidx, map_idx) == -1) {
102 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d",
103 VAR_N_COMM_DATA_IDX, exoid);
104 ex_err_fn(exoid, __func__, errmsg, status);
105
106 EX_FUNC_LEAVE(EX_FATAL);
107 }
108
109 /* check if I need to get the dimension of the cmap data */
110 if (varidx[1] == -1) {
111 /* Get the size of the comm maps */
112 if ((status = nc_inq_dimid(exoid, DIM_NCNT_CMAP, &dimid)) != NC_NOERR) {
113 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get dimension ID for \"%s\" in file ID %d",
114 DIM_NCNT_CMAP, exoid);
115 ex_err_fn(exoid, __func__, errmsg, status);
116 EX_FUNC_LEAVE(EX_FATAL);
117 }
118
119 if ((status = nc_inq_dimlen(exoid, dimid, &ret_val)) != NC_NOERR) {
120 snprintf(errmsg, MAX_ERR_LENGTH,
121 "ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_NCNT_CMAP,
122 exoid);
123 ex_err_fn(exoid, __func__, errmsg, status);
124 EX_FUNC_LEAVE(EX_FATAL);
125 }
126
127 varidx[1] = ret_val;
128 } /* "if (varidx[1]==-1)" */
129
130 start[0] = varidx[0] + start_entity_num - 1;
131 count[0] = num_entities; /* varidx[1] - varidx[0]; */
132 if (num_entities == 0) {
133 start[0] = 0;
134 }
135
136 /* Output the node IDs for this comm map */
137 if ((status = nc_inq_varid(exoid, VAR_N_COMM_NIDS, &varid)) != NC_NOERR) {
138 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
139 VAR_N_COMM_NIDS, exoid);
140 ex_err_fn(exoid, __func__, errmsg, status);
141 EX_FUNC_LEAVE(EX_FATAL);
142 }
143
144 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
145 status = nc_put_vara_longlong(exoid, varid, start, count, node_ids);
146 }
147 else {
148 status = nc_put_vara_int(exoid, varid, start, count, node_ids);
149 }
150 if (status != NC_NOERR) {
151 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output vector \"%s\" in file ID %d",
152 VAR_N_COMM_NIDS, exoid);
153 ex_err_fn(exoid, __func__, errmsg, status);
154 EX_FUNC_LEAVE(EX_FATAL);
155 }
156
157 /* Output the processor IDs for this map */
158 if ((status = nc_inq_varid(exoid, VAR_N_COMM_PROC, &varid)) != NC_NOERR) {
159 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
160 VAR_N_COMM_PROC, exoid);
161 ex_err_fn(exoid, __func__, errmsg, status);
162 EX_FUNC_LEAVE(EX_FATAL);
163 }
164
165 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
166 status = nc_put_vara_longlong(exoid, varid, start, count, proc_ids);
167 }
168 else {
169 status = nc_put_vara_int(exoid, varid, start, count, proc_ids);
170 }
171 if (status != NC_NOERR) {
172 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d",
173 VAR_N_COMM_PROC, exoid);
174 ex_err_fn(exoid, __func__, errmsg, status);
175 EX_FUNC_LEAVE(EX_FATAL);
176 }
177
178 EX_FUNC_LEAVE(EX_NOERR);
179 }