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 /*------------------------------------------------------------------------
53 * mat3d_3across.c -- 3d curvilinear test case with up to 3 materials/zone
54 *
55 *
56 * Programmer: Jeremy Meredith, March 28, 2000
57 *
58 * This test case creates a 3x3x3 curvilinear mesh. The 9 leftmost zones
59 * contain material 1. The 9 rightmost zones contain material 3. The 9
60 * central zones contain materials 1,2,3 in a 20/60/20 split.
61 *
62 * This should (ideally) produce a strip of material 2 down the center
63 * of the mesh.
64 *
65 *
66 * Modifications:
67 *
68 *-----------------------------------------------------------------------*/
69 #include <stdlib.h>
70 #include <string.h>
71 #include "silo.h"
72 #include <std.c>
73
74 #define zx 3
75 #define zy 3
76 #define zz 3
77
78 #define nx 4
79 #define ny 4
80 #define nz 4
81
82 float x[nx*ny*nz]={-1, 0, 1, 2, -1, 0, 1, 2, -1, 0, 1, 2, -1, 0, 1, 2,
83 -1, 0, 1, 2, -1, 0, 1, 2, -1, 0, 1, 2, -1, 0, 1, 2,
84 -1, 0, 1, 2, -1, 0, 1, 2, -1, 0, 1, 2, -1, 0, 1, 2,
85 -1, 0, 1, 2, -1, 0, 1, 2, -1, 0, 1, 2, -1, 0, 1, 2};
86 float y[nx*ny*nz]={-1,-1,-1,-1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
87 -1,-1,-1,-1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
88 -1,-1,-1,-1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
89 -1,-1,-1,-1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2};
90 float z[nx*ny*nz]={-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
93 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
94
95 int nmat=3;
96 int matnos[] = {1,2,3};
97
98 int matlist[nx*ny*nz] = { 1,-1,3, 1,-4,3, 1,-7,3,
99 1,-10,3, 1,-13,3, 1,-16,3,
100 1,-19,3, 1,-22,3, 1,-25,3 };
101 int mix_mat [100] = { 1,2,3, 1,2,3, 1,2,3,
102 1,2,3, 1,2,3, 1,2,3,
103 1,2,3, 1,2,3, 1,2,3 };
104 int mix_next[100] = { 2,3,0, 5,6,0, 8,9,0,
105 11,12,0, 14,15,0, 17,18,0,
106 20,21,0, 23,24,0, 26,27,0 };
107 #define M1 .2
108 #define M2 .6
109 #define M3 .2
110
111 float mix_vf [100] = { M1,M2,M3, M1,M2,M3, M1,M2,M3,
112 M1,M2,M3, M1,M2,M3, M1,M2,M3,
113 M1,M2,M3, M1,M2,M3, M1,M2,M3 };
114
115 int mix_zone[100] = { 2, 2, 2, 5, 5, 5, 8, 8, 8,
116 11,11,11, 14,14,14, 17,17,17,
117 20,20,20, 23,23,23, 26,26,26 };
118 int mixlen = 27;
119
120 int dims[3];
121
122 #define ALLOC_N(t,n) (t*)(calloc(n, sizeof(n)));
123
124 /*--------------------*/
125 /* Main Program */
126 /*--------------------*/
main(int argc,char ** argv)127 int main(int argc, char **argv) {
128 DBfile *db;
129 int i, driver = DB_PDB;
130 char *filename = "mat3d_3across.pdb";
131 int show_all_errors = FALSE;
132 int custom_mat = FALSE;
133 char const * const coordnames[3] = {"x", "y", "z"};
134 float *coord[3];
135
136 for (i=1; i<argc; i++) {
137 if (!strncmp(argv[i], "DB_PDB",6)) {
138 driver = StringToDriver(argv[i]);
139 filename = "mat3d_3across.pdb";
140 } else if (!strncmp(argv[i], "DB_HDF5", 7)) {
141 driver = StringToDriver(argv[i]);
142 filename = "mat3d_3across.h5";
143 } else if (!strcmp(argv[i], "show-all-errors")) {
144 show_all_errors = 1;
145 } else if (!strcmp(argv[i], "custom-mat")) {
146 custom_mat = 1;
147 } else if (argv[i][0] != '\0') {
148 fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
149 }
150 }
151
152 if (show_all_errors) DBShowErrors(DB_ALL_AND_DRVR, 0);
153
154 coord[0] = x;
155 coord[1] = y;
156 coord[2] = z;
157
158 dims[0]=nx;
159 dims[1]=ny;
160 dims[2]=nz;
161
162 db=DBCreate(filename, DB_CLOBBER, DB_LOCAL,
163 "Mixed zone 3d test", driver);
164
165 DBPutQuadmesh(db, "mesh", coordnames, coord, dims, 3,
166 DB_FLOAT, DB_NONCOLLINEAR, NULL);
167
168 dims[0]=zx;
169 dims[1]=zy;
170 dims[2]=zz;
171
172 DBPutMaterial(db, "material", "mesh", nmat, matnos, matlist, dims, 3,
173 mix_next, mix_mat, mix_zone, mix_vf, mixlen, DB_FLOAT, NULL);
174
175 if (custom_mat)
176 {
177 long count[3];
178 DBobject *udef_matobj = DBMakeObject("userdef_material", DB_MATERIAL, 20);
179
180 /* Standard material stuf (in order of args to DBPutMaterial but that doesn't matter) */
181 DBAddStrComponent(udef_matobj, "meshid", "mesh");
182 DBAddIntComponent(udef_matobj, "nmat", nmat);
183 count[0] = nmat;
184 DBWriteComponent(db, udef_matobj, "matnos", "userdef_material", "integer", matnos, 1, count);
185 count[0] = dims[0]; count[1] = dims[1]; count[2] = dims[2];
186 DBWriteComponent(db, udef_matobj, "matlist", "userdef_material", "integer", matlist, 3, count);
187 count[0] = 3;
188 DBWriteComponent(db, udef_matobj, "dims", "userdef_material", "integer", dims, 1, count);
189 DBAddIntComponent(udef_matobj, "ndims", 3);
190 count[0] = mixlen;
191 DBWriteComponent(db, udef_matobj, "mix_next", "userdef_material", "integer", mix_next, 1, count);
192 DBWriteComponent(db, udef_matobj, "mix_mat", "userdef_material", "integer", mix_mat, 1, count);
193 DBWriteComponent(db, udef_matobj, "mix_zone", "userdef_material", "integer", mix_zone, 1, count);
194 DBWriteComponent(db, udef_matobj, "mix_vf", "userdef_material", "float", mix_vf, 1, count);
195 DBAddIntComponent(udef_matobj, "mixlen", mixlen);
196 DBAddIntComponent(udef_matobj, "datatype", DB_FLOAT);
197
198 /* Ok, lets write some extra arrays with interesting stuff */
199 {
200 char *strArray[] = {"mark","sandy","fred","steve","sue","JayLo"};
201 char *tmpList = 0;
202 int len;
203
204 /* Add a simple integer valued scalar member */
205 DBAddIntComponent(udef_matobj, "foo", 42);
206
207 /* Add a simple double valued scalar member */
208 DBAddDblComponent(udef_matobj, "M_PI", 3.1415926);
209
210 /* Add a string valued component */
211 DBAddStrComponent(udef_matobj, "make", "Toyota");
212
213 /* Add an array of strings (Katie's case) */
214 DBStringArrayToStringList((DBCAS_t) strArray, 6, &tmpList, &len);
215 count[0] = len;
216 DBWriteComponent(db, udef_matobj, "Katies_Names", "userdef_material", "char", tmpList, 1, count);
217 free(tmpList);
218 }
219
220 /* Finally, write the generic object to the file */
221 DBWriteObject(db, udef_matobj, 0);
222
223 DBFreeObject(udef_matobj);
224 }
225
226
227 DBClose(db);
228
229 CleanupDriverStuff();
230 return 0;
231 }
232
233