2
Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
6
This file is part of Silo. For details, see silo.llnl.gov.
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions
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
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.
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.
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.
58
#define IND(i,j) i-1][j-1
60
#define matrix_assign(matrix,a11,a12,a13,a14,a21,a22,a23,a24,a31,a32,a33,a34,a41,a42,a43,a44) \
62
matrix [IND(1,1)] = a11 ; \
63
matrix [IND(1,2)] = a12 ; \
64
matrix [IND(1,3)] = a13 ; \
65
matrix [IND(1,4)] = a14 ; \
66
matrix [IND(2,1)] = a21 ; \
67
matrix [IND(2,2)] = a22 ; \
68
matrix [IND(2,3)] = a23 ; \
69
matrix [IND(2,4)] = a24 ; \
70
matrix [IND(3,1)] = a31 ; \
71
matrix [IND(3,2)] = a32 ; \
72
matrix [IND(3,3)] = a33 ; \
73
matrix [IND(3,4)] = a34 ; \
74
matrix [IND(4,1)] = a41 ; \
75
matrix [IND(4,2)] = a42 ; \
76
matrix [IND(4,3)] = a43 ; \
77
matrix [IND(4,4)] = a44 ; \
80
#define matrix_mult(matrixa, matrixb, matrixc) \
82
for (i = 1; i < 5; i++) { \
83
for (j = 1; j < 5; j++) { \
84
matrixc [IND(i,j)] = matrixa [IND(i,1)] * matrixb [IND(1,j)] + \
85
matrixa [IND(i,2)] * matrixb [IND(2,j)] + \
86
matrixa [IND(i,3)] * matrixb [IND(3,j)] + \
87
matrixa [IND(i,4)] * matrixb [IND(4,j)] ; \
92
#ifndef M_PI /* yea, Solaris 5 */
93
#define M_PI 3.14159265358979323846264338327950288 /* pi */
95
#define RAD(deg) M_PI*(deg/180.0)
99
/******************************************************************************
101
* Mark C. Miller, Tue Mar 9 17:16:17 PST 2010
102
* Added explicit logic to set split vfd as an example of how to do it.
103
* Added missing DBFreeFacelist() so valgrind reports no leaks.
105
* Mark C. Miller, Wed Jul 14 15:43:10 PDT 2010
106
* Changed name of 'example' option to 'split'. Added code to Unregister
109
*****************************************************************************/
112
main(int argc, char *argv[])
114
DBfile *dbfile = NULL;
118
float x[8], y[8], z[8];
121
DBfacelist *facelist = NULL;
122
int matnos[1], matlist[1], dims[1];
124
char mesh_command[256];
125
float rot1[4][4], rot2[4][4], final[4][4];
131
char *filename = "onehex.silo";
132
int show_all_errors = FALSE;
135
int alloc_inc, vfd, core_vfd;
137
int meta_opts_id, raw_opts_id, split_opts_id;
138
DBoptlist *core_opts = 0, *split_opts = 0;
140
/* Parse command-line */
141
for (i=1; i<argc; i++) {
142
if (!strncmp(argv[i], "DB_", 3)) {
143
driver = StringToDriver(argv[i]);
144
} else if (!strcmp(argv[i], "split")) {
146
/* set up the meta file options for core vfd with 1K alloc */
147
core_opts = DBMakeOptlist(10);
149
/* indicate the vfd is core */
150
core_vfd = DB_H5VFD_CORE;
151
DBAddOption(core_opts, DBOPT_H5_VFD, &core_vfd);
153
/* indicate the allocation increment is 1K */
155
DBAddOption(core_opts, DBOPT_H5_CORE_ALLOC_INC, &alloc_inc);
157
/* register the core file options set with the library */
158
meta_opts_id = DBRegisterFileOptionsSet(core_opts);
160
/* set up the raw file options */
161
/* We're using pre-defined default file options for the raw part */
162
raw_opts_id = DB_FILE_OPTS_H5_DEFAULT_SEC2;
164
/* now, set up the split file options */
165
split_opts = DBMakeOptlist(10);
167
/* indicate the vfd is split */
168
vfd = DB_H5VFD_SPLIT;
169
DBAddOption(split_opts, DBOPT_H5_VFD, &vfd);
171
/* indicate the meta file options set */
172
DBAddOption(split_opts, DBOPT_H5_META_FILE_OPTS, &meta_opts_id);
174
/* indicate the meta file extension */
176
DBAddOption(split_opts, DBOPT_H5_META_EXTENSION, mext);
178
/* indicate the raw file options set */
179
DBAddOption(split_opts, DBOPT_H5_RAW_FILE_OPTS, &raw_opts_id);
181
/* indicate the raw file extension */
182
/* Note, this is NOT an extension but an sprintf name pattern */
183
rext = "silo_%s_raw.dat";
184
DBAddOption(split_opts, DBOPT_H5_RAW_EXTENSION, rext);
186
/* register the split file options set with the library */
187
split_opts_id = DBRegisterFileOptionsSet(split_opts);
189
/* set the 'driver' */
190
driver = DB_HDF5_OPTS(split_opts_id);
192
/* DO NOT FREE THE ASSOCIATED OPTLIST UNTIL AFTER OPEN/CREATE */
194
} else if (!strcmp(argv[i], "append")) {
196
} else if (!strcmp(argv[i], "inf")) {
198
} else if (!strcmp(argv[i], "nan")) {
200
} else if (!strcmp(argv[i], "show-all-errors")) {
202
} else if (argv[i][0] != '\0') {
203
fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
207
DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_ABORT, NULL);
208
printf("Creating test file \"%s\".\n", filename);
211
dbfile = DBOpen(filename, driver, DB_APPEND);
212
DBMkDir(dbfile, "dir1");
213
DBSetDir(dbfile, "dir1");
216
dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL, "3D ucd hex", driver);
218
/* Ok, now we can safely free the file options sets optlists */
221
DBUnregisterFileOptionsSet(meta_opts_id);
222
DBFreeOptlist(core_opts);
226
DBUnregisterFileOptionsSet(split_opts_id);
227
DBFreeOptlist(split_opts);
230
coordnames[0] = "xcoords";
231
coordnames[1] = "ycoords";
232
coordnames[2] = "zcoords";
234
x[0] = 0; y[0] = 0; z[0] = 0;
235
x[1] = 1; y[1] = 0; z[1] = 0;
236
x[2] = 1; y[2] = 0; z[2] = 1;
237
x[3] = 0; y[3] = 0; z[3] = 1;
238
x[4] = 0; y[4] = 1; z[4] = 0;
239
x[5] = 1; y[5] = 1; z[5] = 0;
240
x[6] = 1; y[6] = 1; z[6] = 1;
241
x[7] = 0; y[7] = 1; z[7] = 1;
248
angle = M_PI*(angle/180.0);
251
0, cos(angle), sin(angle), 0,
252
0, -sin(angle), cos(angle), 0,
255
cos(angle), 0, -sin(angle), 0,
257
sin(angle), 0, cos(angle), 0,
259
matrix_mult(rot1, rot2, final);
261
for (i = 0; i < 8; i++)
265
tx = x[i]*final[IND(1,1)] + y[i]*final[IND(1,2)] + z[i]*final[IND(1,3)] + final[IND(1,4)];
266
ty = x[i]*final[IND(2,1)] + y[i]*final[IND(2,2)] + z[i]*final[IND(2,3)] + final[IND(2,4)];
267
tz = x[i]*final[IND(3,1)] + y[i]*final[IND(3,2)] + z[i]*final[IND(3,3)] + final[IND(3,4)];
273
var[i] = x[i]+y[i]*z[i];
276
DBPutUcdmesh(dbfile, "hex", 3, coordnames, coords, 8, 1, "zonelist",
277
"facelist", DB_FLOAT, NULL);
283
DBPutMaterial(dbfile, "mat", "hex", 1, matnos, matlist, dims,
284
1, NULL, NULL, NULL, NULL, 0, DB_FLOAT, NULL);
296
DBPutUcdvar1(dbfile, "v", "hex", var, 8, NULL, 0, DB_FLOAT, DB_NODECENT,
311
DBSetDeprecateWarnings(0);
312
DBPutZonelist(dbfile, "zonelist", 1, 3, nodelist, 8, 0, shapesize,
314
DBSetDeprecateWarnings(3);
316
facelist = DBCalcExternalFacelist(nodelist, 8, 0, shapesize, shapecnt, 1,
319
DBPutFacelist(dbfile, "facelist", facelist->nfaces, facelist->ndims,
320
facelist->nodelist, facelist->lnodelist, facelist->origin,
321
facelist->zoneno, facelist->shapesize, facelist->shapecnt,
322
facelist->nshapes, facelist->types, facelist->typelist,
325
DBFreeFacelist(facelist);
326
sprintf(mesh_command, "mesh hex; contour v");
327
len = strlen(mesh_command) + 1;
328
DBWrite(dbfile, "_meshtvinfo", mesh_command, &len, 1, DB_CHAR);
332
CleanupDriverStuff();