1 /*
2 * Copyright (c) 2010 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 * testwt - test write an ExodusII database file (testwt-nfaced.exo)
38 *
39 *****************************************************************************/
40
41
42 #include <stdlib.h>
43 #include <string.h>
44 #include <stdio.h>
45 #include <assert.h>
46 #include "exodusII.h"
47
main(int argc,char ** argv)48 int main (int argc, char **argv)
49 {
50 int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
51 int num_elem_in_block[10], num_total_nodes_per_blk[10];
52 int num_face_in_block[10], num_total_faces_per_blk[10];
53 int num_node_sets, error;
54 int i, j, *connect;
55 int bids, nnpe[20];
56 int num_qa_rec, num_info;
57 int CPU_word_size,IO_word_size;
58
59 float x[100], y[100], z[100];
60 char *coord_names[3], *qa_record[2][4], *info[3];
61 char *block_names[10];
62 char *title = "This is a test";
63 ex_opts (EX_VERBOSE | EX_ABORT );
64
65 /* Specify compute and i/o word size */
66
67 CPU_word_size = 0; /* sizeof(float) */
68 IO_word_size = 4; /* (4 bytes) */
69
70 /* create EXODUS II file */
71
72 exoid = ex_create ("test-nfaced.exo", /* filename path */
73 EX_CLOBBER, /* create mode */
74 &CPU_word_size, /* CPU float word size in bytes */
75 &IO_word_size); /* I/O float word size in bytes */
76 printf ("after ex_create for test.exo, exoid = %d\n", exoid);
77 printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);
78
79 /* ncopts = NC_VERBOSE; */
80
81 /* initialize file with parameters */
82 {
83 ex_init_params par;
84
85 num_dim = 3;
86 num_nodes = 14;
87 num_elem = 3;
88 num_elem_blk = 1;
89 num_node_sets = 0;
90
91 strcpy( par.title, title );
92 par.num_dim = num_dim;
93 par.num_nodes = num_nodes;
94 par.num_edge = 0;
95 par.num_edge_blk = 0;
96 par.num_face = 15;
97 par.num_face_blk = 1;
98 par.num_elem = num_elem;
99 par.num_elem_blk = num_elem_blk;
100 par.num_node_sets = num_node_sets;
101 par.num_edge_sets = 0;
102 par.num_face_sets = 0;
103 par.num_side_sets = 0;
104 par.num_elem_sets = 0;
105 par.num_node_maps = 0;
106 par.num_edge_maps = 0;
107 par.num_face_maps = 0;
108 par.num_elem_maps = 0;
109
110 error = ex_put_init_ext (exoid, &par);
111
112 printf ("after ex_put_init_ext, error = %d\n", error);
113
114 if (error) {
115 ex_close (exoid);
116 exit(-1);
117 }
118 }
119
120 /* write nodal coordinates values and names to database */
121 x[ 0] = 0.00000e+00 ; y[ 0] = 0.00000e+00 ; z[ 0] = 0.00000e+00 ;
122 x[ 1] = 2.00000e+00 ; y[ 1] = 0.00000e+00 ; z[ 1] = 0.00000e+00 ;
123 x[ 2] = 0.00000e+00 ; y[ 2] = 2.00000e+00 ; z[ 2] = 0.00000e+00 ;
124 x[ 3] = 2.00000e+00 ; y[ 3] = 2.00000e+00 ; z[ 3] = 0.00000e+00 ;
125 x[ 4] = 0.00000e+00 ; y[ 4] = 0.00000e+00 ; z[ 4] = 2.00000e+00 ;
126 x[ 5] = 2.00000e+00 ; y[ 5] = 0.00000e+00 ; z[ 5] = 2.00000e+00 ;
127 x[ 6] = 0.00000e+00 ; y[ 6] = 2.00000e+00 ; z[ 6] = 2.00000e+00 ;
128 x[ 7] = 2.00000e+00 ; y[ 7] = 2.00000e+00 ; z[ 7] = 2.00000e+00 ;
129 x[ 8] = 0.00000e+00 ; y[ 8] = 3.50000e+00 ; z[ 8] = 1.00000e+00 ;
130 x[ 9] = 2.00000e+00 ; y[ 9] = 3.50000e+00 ; z[ 9] = 1.00000e+00 ;
131 x[10] = 0.00000e+00 ; y[10] = 3.00000e+00 ; z[10] = 1.50000e+00 ;
132 x[11] = 2.00000e+00 ; y[11] = 3.00000e+00 ; z[11] = 1.50000e+00 ;
133 x[12] = 0.00000e+00 ; y[12] = 3.00000e+00 ; z[12] = 0.50000e+00 ;
134 x[13] = 2.00000e+00 ; y[13] = 3.00000e+00 ; z[13] = 0.50000e+00 ;
135
136 error = ex_put_coord (exoid, x, y, z);
137 printf ("after ex_put_coord, error = %d\n", error);
138
139 if (error) {
140 ex_close (exoid);
141 exit(-1);
142 }
143
144 coord_names[0] = "x";
145 coord_names[1] = "y";
146 coord_names[2] = "z";
147
148 error = ex_put_coord_names (exoid, coord_names);
149 printf ("after ex_put_coord_names, error = %d\n", error);
150
151 if (error) {
152 ex_close (exoid);
153 exit(-1);
154 }
155
156
157 /* Write the face block parameters */
158 block_names[0] = "face_block_1";
159 num_face_in_block[0] = 15;
160 num_total_nodes_per_blk[0] = 58;
161 bids = 10;
162
163 error = ex_put_block (exoid, EX_FACE_BLOCK, bids, "nsided",
164 num_face_in_block[0],
165 num_total_nodes_per_blk[0],
166 0, 0, 0);
167 printf ("after ex_put_block, error = %d\n", error);
168
169 if (error) {
170 ex_close (exoid);
171 exit(-1);
172 }
173
174 /* Write face block names */
175 error = ex_put_names(exoid, EX_FACE_BLOCK, block_names);
176 printf ("after ex_put_names, error = %d\n", error);
177
178 if (error) {
179 ex_close (exoid);
180 exit(-1);
181 }
182
183
184
185 /* write face connectivity */
186
187 connect = (int *) calloc(num_total_nodes_per_blk[0], sizeof(int));
188
189 i = 0;
190 j = 0;
191
192 connect[i++] = 5;
193 connect[i++] = 6;
194 connect[i++] = 8; /* connectivity of face 1 of element 1 */
195 nnpe[j++] = 3;
196
197 connect[i++] = 2;
198 connect[i++] = 1;
199 connect[i++] = 4; /* face 2 of element 1 */
200 nnpe[j++] = 3;
201
202 connect[i++] = 6;
203 connect[i++] = 2;
204 connect[i++] = 4;
205 connect[i++] = 8; /* face 3 of element 1 */
206 nnpe[j++] = 4;
207
208 connect[i++] = 8;
209 connect[i++] = 4;
210 connect[i++] = 1;
211 connect[i++] = 5; /* face 4 of element 1 */
212 nnpe[j++] = 4;
213
214 connect[i++] = 1;
215 connect[i++] = 2;
216 connect[i++] = 6;
217 connect[i++] = 5; /* face 5 of element 1 */
218 nnpe[j++] = 4;
219
220 connect[i++] = 5;
221 connect[i++] = 8;
222 connect[i++] = 7; /* connectivity of face 1 of element 2 */
223 nnpe[j++] = 3;
224
225 connect[i++] = 1;
226 connect[i++] = 3;
227 connect[i++] = 4; /* face 2 of element 2 */
228 nnpe[j++] = 3;
229
230 connect[i++] = 7;
231 connect[i++] = 8;
232 connect[i++] = 4;
233 connect[i++] = 3; /* face 3 of element 2 */
234 nnpe[j++] = 4;
235
236 connect[i++] = 7;
237 connect[i++] = 3;
238 connect[i++] = 1;
239 connect[i++] = 5; /* face 4 of element 2 */
240 nnpe[j++] = 4;
241
242 connect[i++] = 8;
243 connect[i++] = 4;
244 connect[i++] = 14;
245 connect[i++] = 10;
246 connect[i++] = 12; /* connectivity of face 1 of element 3 */
247 nnpe[j++] = 5;
248
249 connect[i++] = 7;
250 connect[i++] = 11;
251 connect[i++] = 9;
252 connect[i++] = 13;
253 connect[i++] = 3; /* face 2 of element 3 */
254 nnpe[j++] = 5;
255
256 connect[i++] = 7;
257 connect[i++] = 8;
258 connect[i++] = 12;
259 connect[i++] = 11; /* face 3 of element 3 */
260 nnpe[j++] = 4;
261
262 connect[i++] = 11;
263 connect[i++] = 12;
264 connect[i++] = 10;
265 connect[i++] = 9; /* face 4 of element 3 */
266 nnpe[j++] = 4;
267
268 connect[i++] = 9;
269 connect[i++] = 10;
270 connect[i++] = 14;
271 connect[i++] = 13; /* face 5 of element 3 */
272 nnpe[j++] = 4;
273
274 connect[i++] = 13;
275 connect[i++] = 14;
276 connect[i++] = 4;
277 connect[i++] = 3; /* face 6 of element 3 */
278 nnpe[j++] = 4;
279
280 assert(i == num_total_nodes_per_blk[0]);
281 assert(j == num_face_in_block[0]);
282
283 error = ex_put_conn (exoid, EX_FACE_BLOCK, bids, connect, NULL, NULL);
284 printf ("after ex_put_conn, error = %d\n", error);
285
286 if (error) {
287 ex_close (exoid);
288 exit(-1);
289 }
290
291 free (connect);
292 connect = NULL;
293
294 error = ex_put_entity_count_per_polyhedra(exoid, EX_FACE_BLOCK, bids, nnpe);
295 printf ("after ex_put_entity_count_per_polyhedra, error = %d\n", error);
296
297 if (error) {
298 ex_close (exoid);
299 exit(-1);
300 }
301
302 /* write element block parameters */
303 block_names[0] = "nfaced_1";
304
305 num_elem_in_block[0] = 3;
306 num_total_faces_per_blk[0] = 5 + 5 + 7;
307
308 bids = 10;
309
310 error = ex_put_block (exoid, EX_ELEM_BLOCK, bids, "nfaced",
311 num_elem_in_block[0],
312 0,
313 0,
314 num_total_faces_per_blk[0],
315 0);
316 printf ("after ex_put_block, error = %d\n", error);
317
318 if (error) {
319 ex_close (exoid);
320 exit(-1);
321 }
322
323 /* Write element block names */
324 error = ex_put_names(exoid, EX_ELEM_BLOCK, block_names);
325 printf ("after ex_put_names, error = %d\n", error);
326
327 if (error) {
328 ex_close (exoid);
329 exit(-1);
330 }
331
332 /* write element-face connectivity */
333 connect = (int *) calloc(num_total_faces_per_blk[0], sizeof(int));
334
335 i = 0;
336 j = 0;
337 connect[i++] = 1;
338 connect[i++] = 2;
339 connect[i++] = 3;
340 connect[i++] = 4;
341 connect[i++] = 5;
342 nnpe[j++] = 5; /* Number of faces per element 1 */
343
344 connect[i++] = 4;
345 connect[i++] = 6;
346 connect[i++] = 7;
347 connect[i++] = 8;
348 connect[i++] = 9;
349 nnpe[j++] = 5; /* Number of faces per element 2 */
350
351
352 connect[i++] = 8;
353 connect[i++] = 10;
354 connect[i++] = 11;
355 connect[i++] = 12;
356 connect[i++] = 13;
357 connect[i++] = 14;
358 connect[i++] = 15;
359 nnpe[j++] = 7; /* Number of faces per element 3 */
360
361 assert(i == num_total_faces_per_blk[0]);
362 assert(j == num_elem_in_block[0]);
363
364 error = ex_put_conn (exoid, EX_ELEM_BLOCK, bids, NULL, NULL, connect);
365 printf ("after ex_put_conn, error = %d\n", error);
366
367 if (error) {
368 ex_close (exoid);
369 exit(-1);
370 }
371
372 free (connect);
373
374 error = ex_put_entity_count_per_polyhedra(exoid, EX_ELEM_BLOCK, bids, nnpe);
375 printf ("after ex_put_entity_count_per_polyhedra, error = %d\n", error);
376
377 if (error) {
378 ex_close (exoid);
379 exit(-1);
380 }
381
382 /* write QA records; test empty and just blank-filled records */
383 num_qa_rec = 2;
384
385
386 qa_record[0][0] = "TESTWT-NFACED";
387 qa_record[0][1] = "testwt-nfaced";
388 qa_record[0][2] = "2010/02/15";
389 qa_record[0][3] = "06:35:15";
390 qa_record[1][0] = "";
391 qa_record[1][1] = " ";
392 qa_record[1][2] = "";
393 qa_record[1][3] = " ";
394
395 error = ex_put_qa (exoid, num_qa_rec, qa_record);
396 printf ("after ex_put_qa, error = %d\n", error);
397
398 if (error) {
399 ex_close (exoid);
400 exit(-1);
401 }
402
403
404 /* write information records; test empty and just blank-filled records */
405 num_info = 3;
406
407
408 info[0] = "This is the first information record.";
409 info[1] = "";
410 info[2] = " ";
411
412 error = ex_put_info (exoid, num_info, info);
413 printf ("after ex_put_info, error = %d\n", error);
414
415 if (error) {
416 ex_close (exoid);
417 exit(-1);
418 }
419
420 /* close the EXODUS files
421 */
422 error = ex_close (exoid);
423 printf ("after ex_close, error = %d\n", error);
424 if (error) {
425 ex_close (exoid);
426 exit(-1);
427 }
428 return 0;
429 }
430