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 <math.h>
55 #include <string.h>
56 #include <std.c>
57
58 #define IND(i,j) i-1][j-1
59
60 #define matrix_assign(matrix,a11,a12,a13,a14,a21,a22,a23,a24,a31,a32,a33,a34,a41,a42,a43,a44) \
61 { \
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 ; \
78 }
79
80 #define matrix_mult(matrixa, matrixb, matrixc) \
81 { \
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)] ; \
88 } \
89 } \
90 }
91
92 #ifndef M_PI /* yea, Solaris 5 */
93 #define M_PI 3.14159265358979323846264338327950288 /* pi */
94 #endif
95 #define RAD(deg) M_PI*(deg/180.0)
96
97 /*-------------------------------------------------------------------------
98 * Modifications:
99 * Hank Childs, Wed Feb 16 15:35:56 PST 2005
100 * Prism is inside out. Correct it.
101 *-------------------------------------------------------------------------*/
102
103 int
main(int argc,char * argv[])104 main(int argc, char *argv[])
105 {
106 DBfile *dbfile = NULL;
107 char *coordnames[3];
108 float *coords[3];
109 int nodelist[6];
110 float x[6], y[6], z[6];
111 int shapesize[1];
112 int shapecnt[1];
113 DBfacelist *facelist = NULL;
114 int matnos[1], matlist[1], dims[1];
115 int i, j, len;
116 char mesh_command[256];
117 float rot1[4][4], rot2[4][4], final[4][4];
118 float angle;
119 float var[6];
120 int driver=DB_PDB;
121 char *filename = "oneprism.silo";
122 int show_all_errors = FALSE;
123
124 for (i=1; i<argc; i++) {
125 if (!strncmp(argv[i], "DB_PDB", 6)) {
126 driver = StringToDriver(argv[i]);
127 filename = "oneprism.pdb";
128 } else if (!strncmp(argv[i], "DB_HDF5", 7)) {
129 driver = StringToDriver(argv[i]);
130 filename = "oneprism.h5";
131 } else if (!strcmp(argv[i], "show-all-errors")) {
132 show_all_errors = 1;
133 } else if (argv[i][0] != '\0') {
134 fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
135 }
136 }
137
138
139
140 DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_ABORT, NULL);
141 printf("Creating test file \"%s\".\n", filename);
142 dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL, "3D ucd prism", driver);
143
144 coordnames[0] = "xcoords";
145 coordnames[1] = "ycoords";
146 coordnames[2] = "zcoords";
147
148 /* This prism has the exact same shape and coordinates as zone 40 in
149 * globe.silo. However, the variable stored across it is not the same as
150 * any globe.silo variables. */
151
152 x[0] = 0.515; y[3] = 0; z[3] = 1.585;
153 x[1] = 1.030; y[2] = 0; z[2] = 3.170;
154 x[2] = 0; y[1] = 0; z[1] = 3.333;
155 x[3] = 0; y[0] = 0; z[0] = 1.667;
156 x[4] = 0.490; y[4] = 0.159; z[4] = 1.585;
157 x[5] = 0.980; y[5] = 0.318; z[5] = 3.170;
158
159 coords[0] = x;
160 coords[1] = y;
161 coords[2] = z;
162
163 angle = 0;
164 angle = M_PI*(angle/180.0);
165 matrix_assign(rot1,
166 1, 0, 0, 0,
167 0, cos(angle), sin(angle), 0,
168 0, -sin(angle), cos(angle), 0,
169 0, 0, 0, 1);
170 matrix_assign(rot2,
171 cos(angle), 0, -sin(angle), 0,
172 0, 1, 0, 0,
173 sin(angle), 0, cos(angle), 0,
174 0, 0, 0, 1);
175 matrix_mult(rot1, rot2, final);
176
177 for (i = 0; i < 6; i++)
178 {
179 float tx, ty,tz;
180
181 tx = x[i]*final[IND(1,1)] + y[i]*final[IND(1,2)] + z[i]*final[IND(1,3)] + final[IND(1,4)];
182 ty = x[i]*final[IND(2,1)] + y[i]*final[IND(2,2)] + z[i]*final[IND(2,3)] + final[IND(2,4)];
183 tz = x[i]*final[IND(3,1)] + y[i]*final[IND(3,2)] + z[i]*final[IND(3,3)] + final[IND(3,4)];
184
185 x[i] = tx;
186 y[i] = ty;
187 z[i] = tz;
188
189 var[i] = x[i]+y[i]*z[i];
190 }
191
192 DBPutUcdmesh(dbfile, "prism", 3, (DBCAS_t) coordnames,
193 coords, 6, 1, "zonelist", "facelist", DB_FLOAT, NULL);
194
195 matnos[0] = 1;
196 matlist[0] = 1;
197 dims[0] = 1;
198
199 DBPutMaterial(dbfile, "mat", "prism", 1, matnos, matlist, dims,
200 1, NULL, NULL, NULL, NULL, 0, DB_FLOAT, NULL);
201
202 DBPutUcdvar1(dbfile, "v", "prism", var, 6, NULL, 0, DB_FLOAT, DB_NODECENT,
203 NULL);
204
205 nodelist[0] = 0;
206 nodelist[1] = 1;
207 nodelist[2] = 2;
208 nodelist[3] = 3;
209 nodelist[4] = 4;
210 nodelist[5] = 5;
211
212 shapesize[0] = 6;
213 shapecnt[0] = 1;
214
215 DBSetDeprecateWarnings(0);
216 DBPutZonelist(dbfile, "zonelist", 1, 3, nodelist, 6, 0, shapesize,
217 shapecnt, 1);
218 DBSetDeprecateWarnings(3);
219
220 facelist = DBCalcExternalFacelist(nodelist, 6, 0, shapesize, shapecnt, 1,
221 NULL, 0);
222
223 DBPutFacelist(dbfile, "facelist", facelist->nfaces, facelist->ndims,
224 facelist->nodelist, facelist->lnodelist, facelist->origin,
225 facelist->zoneno, facelist->shapesize, facelist->shapecnt,
226 facelist->nshapes, facelist->types, facelist->typelist,
227 facelist->ntypes);
228
229 sprintf(mesh_command, "mesh prism; contour v");
230 len = strlen(mesh_command) + 1;
231 DBWrite(dbfile, "_meshtvinfo", mesh_command, &len, 1, DB_CHAR);
232
233 DBClose(dbfile);
234
235 DBFreeFacelist(facelist);
236
237 CleanupDriverStuff();
238 return (0);
239 }
240