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
add_edge(int nid1, int nid2, int *nedges, int *maxedges, int **edges)
60
if (*nedges == *maxedges)
62
*maxedges = (*maxedges) * 2 + 1;
63
*edges = (int *) realloc(*edges, *maxedges * 2 * sizeof(int));
65
(*edges)[2*(*nedges)+0] = nid1;
66
(*edges)[2*(*nedges)+1] = nid2;
67
*nedges = (*nedges) + 1;
71
have_edge(int nid1, int nid2, int nedges, const int *edges)
74
for (i = 0; i < nedges; i++)
76
if ((edges[2*i+0] == nid1 &&
77
edges[2*i+1] == nid2) ||
78
(edges[2*i+0] == nid2 &&
79
edges[2*i+1] == nid1))
85
#define HANDLE_EDGE(A,B) \
86
if (!have_edge(nodelist[nlidx+A],nodelist[nlidx+B],*nedges,*edges)) \
87
add_edge(nodelist[nlidx+A],nodelist[nlidx+B],nedges,&maxedges,edges)
90
build_edgelist(int nzones, int ndims, const int *nodelist,
91
int lnodelist, int origin, int lo_off, int hi_off,
92
const int *st, const int *sz, const int *sc, int nshapes,
93
int *nedges, int **edges)
101
for (shape = 0; shape < nshapes; shape++)
103
int zonetype = st[shape];
104
int zonesize = sz[shape];
106
for (zone = 0; zone < sc[shape]; zone++)
110
case DB_ZONETYPE_HEX:
132
int compare_nodes(const void *nap, const void *nbp)
134
int na = *((int*)nap);
135
int nb = *((int*)nbp);
136
if (na < nb) return -1;
137
else if (na > nb) return 1;
142
add_face(int nid1, int nid2, int nid3, int nid4, int *nfaces, int *maxfaces, int **faces)
150
qsort(fnid, sizeof(int), 4, compare_nodes);
151
if (*nfaces == *maxfaces)
153
*maxfaces = (*maxfaces) * 2 + 1;
154
*faces = (int *) realloc(*faces, *maxfaces * 4 * sizeof(int));
156
for (i = 0; i < 4; i++)
157
(*faces)[4*(*nfaces)+i] = fnid[i];
158
*nfaces = (*nfaces) + 1;
162
have_face(int nid1, int nid2, int nid3, int nid4, int nfaces, const int *faces)
170
qsort(fnid, sizeof(int), 4, compare_nodes);
171
for (i = 0; i < nfaces; i++)
174
for (j = 0; j < 4; j++)
176
if (faces[4*i+j] != fnid[j])
182
if (allmatch) return 1;
187
#define HANDLE_FACE(A,B,C,D) \
188
if (!have_face(nodelist[nlidx+A],nodelist[nlidx+B], \
189
nodelist[nlidx+C],nodelist[nlidx+D],*nfaces,*faces)) \
190
add_face(nodelist[nlidx+A],nodelist[nlidx+B], \
191
nodelist[nlidx+C],nodelist[nlidx+D],nfaces,&maxfaces,faces)
194
build_facelist(int nzones, int ndims, const int *nodelist,
195
int lnodelist, int origin, int lo_off, int hi_off,
196
const int *st, const int *sz, const int *sc, int nshapes,
197
int *nfaces, int **faces)
205
for (shape = 0; shape < nshapes; shape++)
207
int zonetype = st[shape];
208
int zonesize = sz[shape];
210
for (zone = 0; zone < sc[shape]; zone++)
214
case DB_ZONETYPE_HEX:
216
HANDLE_FACE(0,1,5,4);
217
HANDLE_FACE(0,3,2,1);
218
HANDLE_FACE(0,4,7,3);
219
HANDLE_FACE(1,2,6,5);
220
HANDLE_FACE(2,3,7,6);
221
HANDLE_FACE(4,5,6,7);
231
main(int argc, char *argv[])
233
DBfile *dbfile = NULL;
236
float x[64], y[64], z[64];
239
DBfacelist *facelist = NULL;
240
int matnos[1], matlist[1], dims[3];
242
float evar2d[2*16], evar3d[3*64], fvar3d[3*64];
244
char *filename = "efcentering.silo";
246
int nodelist2[9*4] = {0,1,5,4, 1,2,6,5, 2,3,7,6,
247
4,5,9,8, 5,6,10,9, 6,7,11,10,
248
8,9,13,12, 9,10,14,13, 10,11,15,14};
249
int st2 = DB_ZONETYPE_QUAD;
253
int st3 = DB_ZONETYPE_HEX;
262
int show_all_errors = FALSE;
264
/* Parse command-line */
265
for (i=1; i<argc; i++) {
266
if (!strncmp(argv[i], "DB_PDB",6)) {
267
driver = StringToDriver(argv[i]);
268
} else if (!strncmp(argv[i], "DB_HDF5", 7)) {
269
driver = StringToDriver(argv[i]);
270
} else if (!strcmp(argv[i], "show-all-errors")) {
272
} else if (argv[i][0] != '\0') {
273
fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
277
DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_ABORT, NULL);
278
dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL, "edge and face centered data", driver);
280
coordnames[0] = "xcoords";
281
coordnames[1] = "ycoords";
282
coordnames[2] = "zcoords";
287
for (k = 0; k < 4; k++)
289
for (j = 0; j < 4; j++)
291
for (i = 0; i < 4; i++)
293
x[k*4*4+j*4+i] = (float) i;
294
y[k*4*4+j*4+i] = (float) j;
295
z[k*4*4+j*4+i] = (float) k;
296
evar2d[0*16+j*4+i] = (float) i;
297
evar2d[1*16+j*4+i] = (float) j;
298
evar3d[0*64+k*4*4+j*4+i] = (float) i;
299
evar3d[1*64+k*4*4+j*4+i] = (float) j;
300
evar3d[2*64+k*4*4+j*4+i] = (float) k;
301
fvar3d[0*64+k*4*4+j*4+i] = (float) 10*i;
302
fvar3d[1*64+k*4*4+j*4+i] = (float) 100*j;
303
fvar3d[2*64+k*4*4+j*4+i] = (float) 1000*k;
312
/* build 3d zonelist by layering 2d zonelist */
313
for (layer = 0; layer < 3; layer++)
315
for (zone = 0; zone < 9; zone++)
317
nodelist3[layer*9*8+zone*8+0] = nodelist2[zone*4+0]+(layer+1)*16;
318
nodelist3[layer*9*8+zone*8+1] = nodelist2[zone*4+0]+layer*16;
319
nodelist3[layer*9*8+zone*8+2] = nodelist2[zone*4+1]+layer*16;
320
nodelist3[layer*9*8+zone*8+3] = nodelist2[zone*4+1]+(layer+1)*16;
321
nodelist3[layer*9*8+zone*8+4] = nodelist2[zone*4+3]+(layer+1)*16;
322
nodelist3[layer*9*8+zone*8+5] = nodelist2[zone*4+3]+layer*16;
323
nodelist3[layer*9*8+zone*8+6] = nodelist2[zone*4+2]+layer*16;
324
nodelist3[layer*9*8+zone*8+7] = nodelist2[zone*4+2]+(layer+1)*16;
328
DBPutQuadmesh(dbfile, "qmesh2", coordnames, coords, dims, 2, DB_FLOAT, DB_NONCOLLINEAR, 0);
329
DBPutQuadmesh(dbfile, "qmesh3", coordnames, coords, dims, 3, DB_FLOAT, DB_NONCOLLINEAR, 0);
330
DBPutQuadvar1(dbfile, "qevar2", "qmesh2", evar2d, dims, 2, 0, 0, DB_FLOAT, DB_EDGECENT, 0);
331
DBPutQuadvar1(dbfile, "qevar3", "qmesh3", evar3d, dims, 3, 0, 0, DB_FLOAT, DB_EDGECENT, 0);
332
DBPutQuadvar1(dbfile, "qfvar3", "qmesh3", fvar3d, dims, 3, 0, 0, DB_FLOAT, DB_FACECENT, 0);
334
DBPutUcdmesh(dbfile, "umesh2", 2, coordnames, coords, 16, 9, "um2zl", 0, DB_FLOAT, 0);
335
DBPutUcdmesh(dbfile, "umesh3", 3, coordnames, coords, 64, 27, "um3zl", 0, DB_FLOAT, 0);
336
DBPutZonelist2(dbfile, "um2zl", 9, 2, nodelist2, ss2*sc2, 0, 0, 0, &st2, &ss2, &sc2, 1, 0);
337
DBPutZonelist2(dbfile, "um3zl", 27, 3, nodelist3, ss3*sc3, 0, 0, 0, &st3, &ss3, &sc3, 1, 0);
339
/* Only reason we build an edgelist is so we know the number of unique edges in the mesh */
340
build_edgelist(27, 3, nodelist3, ss3*sc3, 0, 0, 0, &st3, &ss3, &sc3, 1, &nedges, &edges);
341
for (i = 0; i < nedges; i++)
343
DBPutUcdvar1(dbfile, "uevar3", "umesh3", evar3d, nedges, 0, 0, DB_FLOAT, DB_EDGECENT, 0);
347
DBWrite(dbfile, "edges", edges, dims, ndims, DB_INT);
350
/* Only reason we build a facelist is so we know the number of unique faces in the mesh */
351
build_facelist(27, 3, nodelist3, ss3*sc3, 0, 0, 0, &st3, &ss3, &sc3, 1, &nfaces, &faces);
352
for (i = 0; i < nfaces; i++)
354
DBPutUcdvar1(dbfile, "ufvar3", "umesh3", fvar3d, nfaces, 0, 0, DB_FLOAT, DB_FACECENT, 0);
357
DBWrite(dbfile, "faces", faces, dims, ndims, DB_INT);
362
CleanupDriverStuff();