1 /*
2 Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
3 LLNL-CODE-425250.
4 All rights reserved.
5
6 This file is part of Silo. For details, see silo.llnl.gov.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
10 are met:
11
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the disclaimer below.
14 * Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the disclaimer (as noted
16 below) in the documentation and/or other materials provided with
17 the distribution.
18 * Neither the name of the LLNS/LLNL 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 LAWRENCE
26 LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR
27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35 This work was produced at Lawrence Livermore National Laboratory under
36 Contract No. DE-AC52-07NA27344 with the DOE. Neither the United
37 States Government nor Lawrence Livermore National Security, LLC nor
38 any of their employees, makes any warranty, express or implied, or
39 assumes any liability or responsibility for the accuracy,
40 completeness, or usefulness of any information, apparatus, product, or
41 process disclosed, or represents that its use would not infringe
42 privately-owned rights. Any reference herein to any specific
43 commercial products, process, or services by trade name, trademark,
44 manufacturer or otherwise does not necessarily constitute or imply its
45 endorsement, recommendation, or favoring by the United States
46 Government or Lawrence Livermore National Security, LLC. The views and
47 opinions of authors expressed herein do not necessarily state or
48 reflect those of the United States Government or Lawrence Livermore
49 National Security, LLC, and shall not be used for advertising or
50 product endorsement purposes.
51 */
52 #include <silo.h>
53 #include <stdio.h>
54 #include <stdlib.h>
55 #include <string.h>
56
57 #define NDIMS 3
58 #define NZONES 4
59 #define NNODES 13
60
61 /***************************************************************
62 *
63 * Modifications:
64 * Jeremy Meredith, Thu Jul 6 10:08:15 PDT 2000
65 * Added ability to change origin of objects.
66 *
67 ***************************************************************/
68
69 #include <std.c>
70
71 int
main(int argc,char * argv[])72 main(int argc, char *argv[])
73 {
74 int nnodes = NNODES;
75 int nzones = NZONES;
76 int nodelist[23];
77 int shapesize[] = {8, 4, 5, 6};
78 int shapecnt[] = {1, 1, 1, 1};
79 char mesh_command[256];
80 int len;
81 char *filename = "alltypes.silo";
82 int driver = DB_PDB;
83
84 DBfile *dbfile = NULL;
85 int ndims = NDIMS;
86 int dims[NDIMS];
87 double *coords[NDIMS];
88 double x[NNODES];
89 double y[NNODES];
90 double z[NNODES];
91
92 DBfacelist *facelist = NULL;
93
94 double nodal[NNODES];
95 double zonal[NZONES];
96 int matlist[NZONES];
97 int mats[] = {1,2,3,4};
98
99 int i,j;
100
101 const int origin = 0;
102 int show_all_errors = FALSE;
103
104 /* Parse command-line options */
105 for (i=1; i<argc; i++) {
106 if (!strncmp(argv[i], "DB_PDB",6)) {
107 driver = StringToDriver(argv[i]);
108 filename = "alltypes.pdb";
109 } else if (!strncmp(argv[i], "DB_HDF5", 7)) {
110 driver = StringToDriver(argv[i]);
111 filename = "alltypes.h5";
112 } else if (!strcmp(argv[i], "show-all-errors")) {
113 show_all_errors = 1;
114 } else if (argv[i][0] != '\0') {
115 fprintf(stderr, "unknown option: %s\n", argv[i]);
116 exit(1);
117 }
118 }
119
120 /* Turn on error handling */
121 DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_ABORT, NULL);
122 DBSetFriendlyHDF5Names(2);
123
124 /* Create file */
125 printf("Creating test file \"%s\".\n", filename);
126 dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL, "3D ucd", driver);
127
128 i = 0;
129
130 /* 0 */
131 x[i] = 0.5;
132 y[i] = 1.0;
133 z[i++] = 0.0;
134
135 /* 1 */
136 x[i] = 1.5;
137 y[i] = 1.0;
138 z[i++] = 0.0;
139
140 /* 2 */
141 x[i] = 1.5;
142 y[i] = 1.0;
143 z[i++] = 1.0;
144
145 /* 3 */
146 x[i] = 0.5;
147 y[i] = 1.0;
148 z[i++] = 1.0;
149
150 /* 4 */
151 x[i] = 0.5;
152 y[i] = 2.0;
153 z[i++] = 0.0;
154
155 /* 5 */
156 x[i] = 1.5;
157 y[i] = 2.0;
158 z[i++] = 0.0;
159
160 /* 6 */
161 x[i] = 2.5;
162 y[i] = 2.0;
163 z[i++] = 0.0;
164
165 /* 7 */
166 x[i] = 2.5;
167 y[i] = 2.0;
168 z[i++] = 1.0;
169
170 /* 8 */
171 x[i] = 1.5;
172 y[i] = 2.0;
173 z[i++] = 1.0;
174
175 /* 9 */
176 x[i] = 0.5;
177 y[i] = 2.0;
178 z[i++] = 1.0;
179
180 /* 10 */
181 x[i] = 0.0;
182 y[i] = 3.0;
183 z[i++] = 0.5;
184
185 /* 11 */
186 x[i] = 1.0;
187 y[i] = 3.0;
188 z[i++] = 0.5;
189
190 /* 12 */
191 x[i] = 2.0;
192 y[i] = 3.0;
193 z[i++] = 0.5;
194
195 coords[0] = x;
196 coords[1] = y;
197 coords[2] = z;
198
199 DBPutUcdmesh(dbfile, "mesh", 3, NULL, (void *)coords, nnodes, nzones, "zonelist",
200 "facelist", DB_DOUBLE, NULL);
201
202 i = 0;
203 /* Hex */
204 nodelist[i++] = 4;
205 nodelist[i++] = 5;
206 nodelist[i++] = 8;
207 nodelist[i++] = 9;
208 nodelist[i++] = 0;
209 nodelist[i++] = 1;
210 nodelist[i++] = 2;
211 nodelist[i++] = 3;
212
213 /* Tet */
214 nodelist[i++] = 10;
215 nodelist[i++] = 4;
216 nodelist[i++] = 11;
217 nodelist[i++] = 9;
218
219 /* Pyramid */
220 nodelist[i++] = 4;
221 nodelist[i++] = 5;
222 nodelist[i++] = 8;
223 nodelist[i++] = 9;
224 nodelist[i++] = 11;
225
226 /* Prism */
227 nodelist[i++] = 5;
228 nodelist[i++] = 6;
229 nodelist[i++] = 7;
230 nodelist[i++] = 8;
231 nodelist[i++] = 11;
232 nodelist[i++] = 12;
233
234 for (j=0; j<i; j++)
235 nodelist[j] += origin;
236
237 DBSetDeprecateWarnings(0);
238 DBPutZonelist(dbfile, "zonelist", nzones, ndims, nodelist, 23, origin,
239 shapesize, shapecnt, 4);
240 DBSetDeprecateWarnings(3);
241
242 facelist = DBCalcExternalFacelist(nodelist, nnodes, origin,
243 shapesize, shapecnt, 4, NULL, 0);
244
245 DBPutFacelist(dbfile, "facelist", facelist->nfaces, facelist->ndims,
246 facelist->nodelist, facelist->lnodelist, facelist->origin,
247 facelist->zoneno, facelist->shapesize, facelist->shapecnt,
248 facelist->nshapes, facelist->types, facelist->typelist,
249 facelist->ntypes);
250
251 for(i=0;i<nnodes;i++)
252 nodal[i] = x[i];
253
254 zonal[0] = 4.0;
255 zonal[1] = 2.0;
256 zonal[2] = 0.0;
257 zonal[3] = 7.0;
258
259 DBPutUcdvar1(dbfile, "nodal", "mesh", (void*)nodal, nnodes, NULL, 0,
260 DB_DOUBLE, DB_NODECENT, NULL);
261
262 DBPutUcdvar1(dbfile, "zonal", "mesh", (void*)zonal, nzones, NULL, 0,
263 DB_DOUBLE, DB_ZONECENT, NULL);
264
265 matlist[0] = 1;
266 matlist[1] = 2;
267 matlist[2] = 3;
268 matlist[3] = 4;
269
270 dims[0] = nzones;
271 DBPutMaterial(dbfile, "mat", "mesh", 4, mats, matlist, dims, 1, NULL, NULL,
272 NULL, NULL, 0, DB_DOUBLE, NULL);
273
274 sprintf(mesh_command, "mesh mesh");
275 len = strlen(mesh_command) + 1;
276 DBWrite(dbfile, "_meshtvinfo", mesh_command, &len, 1, DB_CHAR);
277
278 DBClose(dbfile);
279
280 DBFreeFacelist(facelist);
281
282 CleanupDriverStuff();
283 return 0;
284 }
285