Debian Codegraph @

packages/seacas/libraries/exodus/test/testwt-one-attrib.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 #undef NDEBUG
9 #include "exodusII.h"
10 #include <assert.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 int main(int argc, char **argv)
15 {
16 int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
17 int num_elem_in_block[10], num_nodes_per_elem[10], num_attr[10];
18 int num_node_sets, num_side_sets, error;
19 int i, j, *connect;
20 int ebids[10], ids[10];
21 int CPU_word_size, IO_word_size;
22 char title[MAX_LINE_LENGTH + 1], elem_type[MAX_STR_LENGTH + 1];
23
24 float version;
25 float *attrib;
26 float x[100], y[100], z[100];
27 char *coord_names[3];
28
29 /* Coordinate Frames */
30 int cf_ids[2] = {20, 13};
31 float pt_coords[9 * 2] = {1, 0, 0, 1, 0, 1, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0};
32 char tags[2] = {'r', 'c'};
33
34 ex_opts(EX_VERBOSE | EX_ABORT);
35
36 /* Specify compute and i/o word size */
37
38 CPU_word_size = 0; /* sizeof(float) */
39 IO_word_size = 4; /* (4 bytes) */
40
41 /* create EXODUS II file */
42
43 exoid = ex_create("test.exo", /* filename path */
44 EX_CLOBBER, /* create mode */
45 &CPU_word_size, /* CPU float word size in bytes */
46 &IO_word_size); /* I/O float word size in bytes */
47 /* initialize file with parameters */
48
49 num_dim = 3;
50 num_nodes = 19;
51 num_elem = 12;
52 ;
53 num_elem_blk = 1;
54 num_node_sets = 0;
55 num_side_sets = 0;
56
57 error = ex_put_init(exoid, "This is testwt1", num_dim, num_nodes, num_elem, num_elem_blk,
58 num_node_sets, num_side_sets);
59 assert(error == 0);
60
61 /* write nodal coordinates values and names to database */
62
63 /* Quad #1 */
64 x[0] = 1.0000000E+00;
65 x[1] = 5.0000000E-01;
66 x[2] = 1.0000000E+00;
67 x[3] = 1.0000000E+00;
68 x[4] = 7.5000000E-01;
69 x[5] = 5.0000000E-01;
70 x[6] = 1.0000000E+00;
71 x[7] = 7.5000000E-01;
72 x[8] = 1.0000000E+00;
73 x[9] = 5.0000000E-01;
74 x[10] = 5.0000000E-01;
75 x[11] = 5.0000000E-01;
76 x[12] = 1.0000000E+00;
77 x[13] = 1.0000000E+00;
78 x[14] = 7.5000000E-01;
79 x[15] = 7.5000000E-01;
80 x[16] = 1.0000000E+00;
81 x[17] = 7.5000000E-01;
82 x[18] = 1.0000000E+00;
83
84 y[0] = 5.0000000E-01;
85 y[1] = 1.0000000E+00;
86 y[2] = 1.0000000E+00;
87 y[3] = 7.5000000E-01;
88 y[4] = 1.0000000E+00;
89 y[5] = 5.0000000E-01;
90 y[6] = 5.0000000E-01;
91 y[7] = 5.0000000E-01;
92 y[8] = 5.0000000E-01;
93 y[9] = 1.0000000E+00;
94 y[10] = 7.5000000E-01;
95 y[11] = 1.0000000E+00;
96 y[12] = 1.0000000E+00;
97 y[13] = 7.5000000E-01;
98 y[14] = 1.0000000E+00;
99 y[15] = 7.5000000E-01;
100 y[16] = 1.0000000E+00;
101 y[17] = 1.0000000E+00;
102 y[18] = 7.5000000E-01;
103
104 z[0] = 5.0000000E-01;
105 z[1] = 5.0000000E-01;
106 z[2] = 5.0000000E-01;
107 z[3] = 5.0000000E-01;
108 z[4] = 5.0000000E-01;
109 z[5] = 1.0000000E+00;
110 z[6] = 1.0000000E+00;
111 z[7] = 1.0000000E+00;
112 z[8] = 7.5000000E-01;
113 z[9] = 1.0000000E+00;
114 z[10] = 1.0000000E+00;
115 z[11] = 7.5000000E-01;
116 z[12] = 1.0000000E+00;
117 z[13] = 1.0000000E+00;
118 z[14] = 1.0000000E+00;
119 z[15] = 1.0000000E+00;
120 z[16] = 7.5000000E-01;
121 z[17] = 7.5000000E-01;
122 z[18] = 7.5000000E-01;
123
124 error = ex_put_coord(exoid, x, y, z);
125 assert(error == 0);
126
127 coord_names[0] = "xcoor";
128 coord_names[1] = "ycoor";
129 coord_names[2] = "zcoor";
130
131 error = ex_put_coord_names(exoid, coord_names);
132 assert(error == 0);
133
134 /* write element block parameters */
135 num_elem_in_block[0] = 12;
136 num_nodes_per_elem[0] = 4;
137 ebids[0] = 10;
138 num_attr[0] = 3;
139
140 error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[0], "quad", num_elem_in_block[0],
141 num_nodes_per_elem[0], 0, 0, num_attr[0]);
142 assert(error == 0);
143
144 /* write element connectivity */
145 connect = (int *)calloc(num_elem_in_block[0] * num_nodes_per_elem[0], sizeof(int));
146
147 connect[0] = 1;
148 connect[1] = 4;
149 connect[2] = 19;
150 connect[3] = 9;
151 connect[4] = 4;
152 connect[5] = 3;
153 connect[6] = 17;
154 connect[7] = 19;
155 connect[8] = 3;
156 connect[9] = 5;
157 connect[10] = 18;
158 connect[11] = 17;
159 connect[12] = 5;
160 connect[13] = 2;
161 connect[14] = 12;
162 connect[15] = 18;
163 connect[16] = 9;
164 connect[17] = 19;
165 connect[18] = 14;
166 connect[19] = 7;
167 connect[20] = 7;
168 connect[21] = 14;
169 connect[22] = 16;
170 connect[23] = 8;
171 connect[24] = 19;
172 connect[25] = 17;
173 connect[26] = 13;
174 connect[27] = 14;
175 connect[28] = 17;
176 connect[29] = 18;
177 connect[30] = 15;
178 connect[31] = 13;
179 connect[32] = 14;
180 connect[33] = 13;
181 connect[34] = 15;
182 connect[35] = 16;
183 connect[36] = 8;
184 connect[37] = 16;
185 connect[38] = 11;
186 connect[39] = 6;
187 connect[40] = 18;
188 connect[41] = 12;
189 connect[42] = 10;
190 connect[43] = 15;
191 connect[44] = 16;
192 connect[45] = 15;
193 connect[46] = 10;
194 connect[47] = 11;
195
196 error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL);
197 assert(error == 0);
198 free(connect);
199
200 /* write element block attributes (3 per block) */
201 attrib = (float *)calloc(num_elem_in_block[0] * num_attr[0], sizeof(float));
202
203 #if 0
204 {
205 k = 0;
206 for (i=0; i < num_elem_in_block[0]; i++) {
207 for (j = 0; j < num_attr[0]; j++) {
208 attrib[k++] = 10*(i+1) + j+1;
209 }
210 }
211 }
212
213 error = ex_put_attr (exoid, EX_ELEM_BLOCK, ebids[0], &attrib[0]);
214 assert(error == 0);
215 #else
216 {
217 for (j = 0; j < num_attr[0]; j++) {
218 for (i = 0; i < num_elem_in_block[0]; i++) {
219 attrib[i] = 10 * (i + 1) + j + 1;
220 }
221 error = ex_put_one_attr(exoid, EX_ELEM_BLOCK, ebids[0], j + 1, &attrib[0]);
222 assert(error == 0);
223 }
224 }
225 #endif
226 free(attrib);
227
228 /* Add a coordinate frame just to give test coverage... */
229 {
230 error = ex_put_coordinate_frames(exoid, 2, cf_ids, pt_coords, tags);
231 assert(error == 0);
232 }
233
234 /* close the EXODUS files
235 */
236 error = ex_close(exoid);
237 assert(error == 0);
238
239 /* Reopen the file and read the attributes to see if they were written correctly */
240 CPU_word_size = 0; /* sizeof(float) */
241 IO_word_size = 0; /* use what is stored in file */
242
243 /* open EXODUS II files */
244
245 exoid = ex_open("test.exo", /* filename path */
246 EX_READ, /* access mode = READ */
247 &CPU_word_size, /* CPU word size */
248 &IO_word_size, /* IO word size */
249 &version); /* ExodusII library version */
250
251 assert(exoid >= 0);
252 if (exoid < 0) {
253 exit(1);
254 }
255
256 error = ex_get_init(exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk, &num_node_sets,
257 &num_side_sets);
258
259 assert(error == 0);
260
261 if (num_elem_blk > 0) {
262 error = ex_get_ids(exoid, EX_ELEM_BLOCK, ids);
263 assert(error == 0);
264
265 for (i = 0; i < num_elem_blk; i++) {
266 error = ex_get_block(exoid, EX_ELEM_BLOCK, ids[i], elem_type, &(num_elem_in_block[i]),
267 &(num_nodes_per_elem[i]), NULL, NULL, &(num_attr[i]));
268 assert(error == 0);
269 }
270
271 /* read element block attributes */
272
273 attrib = (float *)calloc(num_elem_in_block[0], sizeof(float));
274 for (j = 0; j < num_attr[0]; j++) {
275 error = ex_get_one_attr(exoid, EX_ELEM_BLOCK, ids[0], j + 1, &attrib[0]);
276 assert(error == 0);
277
278 if (error == 0) {
279 for (i = 0; i < num_elem_in_block[0]; i++) {
280 assert(attrib[i] == 10 * (i + 1) + j + 1);
281 }
282 }
283 }
284 free(attrib);
285 }
286
287 /* Read the coordinate frame... */
288 {
289 int nframes;
290 int rdcf_ids[2];
291 float rdpt_coords[9 * 2];
292 char rdtags[2];
293
294 nframes = ex_inquire_int(exoid, EX_INQ_COORD_FRAMES);
295 assert(nframes == 2);
296
297 error = ex_get_coordinate_frames(exoid, &nframes, rdcf_ids, rdpt_coords, rdtags);
298 assert(error == 0);
299 assert(rdtags[0] == tags[0] && rdtags[1] == tags[1]);
300 assert(rdcf_ids[0] == cf_ids[0] && rdcf_ids[1] == cf_ids[1]);
301
302 for (i = 0; i < nframes * 9; i++) {
303 assert(rdpt_coords[i] == pt_coords[i]);
304 }
305 }
306 error = ex_close(exoid);
307 assert(error == 0);
308 return 0;
309 }