~ubuntu-branches/ubuntu/trusty/silo-llnl/trusty

« back to all changes in this revision

Viewing changes to tests/multi_file.c

  • Committer: Bazaar Package Importer
  • Author(s): Alastair McKinstry
  • Date: 2011-01-02 00:03:01 UTC
  • Revision ID: james.westby@ubuntu.com-20110102000301-9s2hfsjrkguz6h4r
Tags: upstream-4.8
ImportĀ upstreamĀ versionĀ 4.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * Create a multi-file multi-block mesh.
 
54
 *
 
55
 */
 
56
 
 
57
#include <math.h>
 
58
#include <stdarg.h>
 
59
#include <stdlib.h>
 
60
#include <string.h>
 
61
#include <sys/stat.h>
 
62
#include <sys/types.h>
 
63
 
 
64
#ifdef WIN32
 
65
#  include <direct.h>
 
66
#endif
 
67
 
 
68
#include <silo.h>
 
69
#include <std.c>
 
70
 
 
71
#define MAXBLOCKS       400       /* Maximum number of blocks in an object */
 
72
#define STRLEN          60
 
73
#define MIXMAX          20000     /* Maximum length of the mixed arrays */
 
74
#define NFILES          8         /* The number of files to create */
 
75
 
 
76
#define MIN(x, y) (x) < (y) ? (x) : (y)
 
77
#define MAX(x, y) (x) > (y) ? (x) : (y)
 
78
 
 
79
#define ALLOC_N(T,N)    ((T*)calloc((N),sizeof(T)))
 
80
#define FREE(M)         if(M){free(M);(M)=NULL;}
 
81
 
 
82
int multidir = 0;
 
83
int use_ns = 0;
 
84
 
 
85
void fill_bkgr(int *, int, int, int, int);
 
86
void fill_mat(float *, float *, float *, int *, int, int, int,
 
87
    int *, int *, int *, float *, int *, int, double, double, double, double);
 
88
 
 
89
int  build_multi(char *, int, char *, int, int, int);
 
90
 
 
91
void build_block_ucd3d(char *, int, char *, int, int, int);
 
92
 
 
93
/***********************************************************************
 
94
 *
 
95
 * Purpose:
 
96
 *    Generate a multi file 3d ucd multi block test file.
 
97
 *
 
98
 * Programmer:  Eric Brugger
 
99
 * Date:        September 17, 2001
 
100
 *
 
101
 * Modifications:
 
102
 *   Mark C. Miller, Wed Jul 14 15:33:43 PDT 2010
 
103
 *   Added use-ns (namescheme) options for multi-block objects. 
 
104
 ***********************************************************************/
 
105
int
 
106
main(int argc, char *argv[])
 
107
{
 
108
    int            i;
 
109
    char          *basename="ucd3d";
 
110
    char          *file_ext="pdb";
 
111
    int            driver=DB_PDB;
 
112
    int            show_all_errors = FALSE;
 
113
 
 
114
    /*
 
115
     * Parse the command-line.
 
116
     */
 
117
    for (i = 1; i < argc; i++)
 
118
    {
 
119
        if (!strncmp(argv[i], "DB_PDB", 6))
 
120
        {
 
121
            driver = StringToDriver(argv[i]);
 
122
            file_ext = "pdb";
 
123
        }
 
124
        else if (!strncmp(argv[i], "DB_HDF5", 7))
 
125
        {
 
126
            driver = StringToDriver(argv[i]);
 
127
            file_ext = "h5";
 
128
        }
 
129
        else if (!strcmp(argv[i], "multidir"))
 
130
        {
 
131
            multidir = 1;
 
132
        }
 
133
        else if (!strcmp(argv[i], "use-ns"))
 
134
        {
 
135
            use_ns = 1;
 
136
        }
 
137
        else if (!strcmp(argv[i], "show-all-errors"))
 
138
        {
 
139
            show_all_errors = 1;
 
140
        }
 
141
        else if (argv[i][0] != '\0')
 
142
        {
 
143
            fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
 
144
        }
 
145
    }
 
146
 
 
147
    if (show_all_errors) DBShowErrors(DB_ALL_AND_DRVR, 0);
 
148
 
 
149
    /* 
 
150
     * Create the multi-block ucd 3d mesh.
 
151
     */
 
152
    build_multi(basename, driver, file_ext, 6, 8, 6);
 
153
 
 
154
    CleanupDriverStuff();
 
155
    return 0;
 
156
}
 
157
 
 
158
/***********************************************************************      
 
159
 *
 
160
 * Purpose:
 
161
 *    Fill the entire material array with the material "matno".
 
162
 *
 
163
 * Programmer:  Eric Brugger
 
164
 * Date:        September 17, 2001
 
165
 *
 
166
 ***********************************************************************/
 
167
void
 
168
fill_bkgr(int *matlist, int nx, int ny, int nz, int matno)
 
169
{
 
170
    int             i, j, k;
 
171
 
 
172
    for (i = 0; i < nx; i++)
 
173
    {
 
174
        for (j = 0; j < ny; j++)
 
175
        {
 
176
            for (k = 0; k < nz; k++)
 
177
            {
 
178
                matlist[k * nx * ny + j * nx + i] = matno;
 
179
            }
 
180
        }
 
181
    }
 
182
}
 
183
 
 
184
/***********************************************************************      
 
185
 *
 
186
 * Purpose:
 
187
 *    Fill the specified material array with sphere centered at
 
188
 *    "xcenter", "ycenter", "zcenter" and radius of "radius" with
 
189
 *    the material "matno".
 
190
 *
 
191
 * Programmer:  Eric Brugger
 
192
 * Date:        September 17, 2001
 
193
 *
 
194
 ***********************************************************************/
 
195
void
 
196
fill_mat(float *x, float *y, float *z, int *matlist, int nx,
 
197
         int ny, int nz, int *mix_next, int *mix_mat, int *mix_zone,
 
198
         float *mix_vf, int *mixlen, int matno, double xcenter,
 
199
         double ycenter, double zcenter, double radius)
 
200
{
 
201
    int             i, j, k, l, m, n;
 
202
    double          dist;
 
203
    int             cnt;
 
204
    int             mixlen2;
 
205
    int            *itemp=NULL;
 
206
    float           dx, dy, dz;
 
207
    float           xx[10], yy[10], zz[10];
 
208
 
 
209
    mixlen2 = *mixlen;
 
210
 
 
211
    itemp = ALLOC_N(int, (nx + 1) * (ny + 1) * (nz + 1));
 
212
 
 
213
    for (i = 0; i < nx; i++)
 
214
    {
 
215
        for (j = 0; j < ny; j++)
 
216
        {
 
217
            for (k = 0; k < nz; k++)
 
218
            {
 
219
                dist = sqrt((x[i] - xcenter) * (x[i] - xcenter) +
 
220
                            (y[j] - ycenter) * (y[j] - ycenter) +
 
221
                            (z[k] - zcenter) * (z[k] - zcenter));
 
222
                itemp[k * (nx + 1) * (ny + 1) + j * (nx + 1) + i] =
 
223
                    (dist < radius) ? 1 : 0;
 
224
            }
 
225
        }
 
226
    }
 
227
    for (i = 0; i < nx; i++)
 
228
    {
 
229
        for (j = 0; j < ny; j++)
 
230
        {
 
231
            for (k = 0; k < nz; k++)
 
232
            {
 
233
                cnt = itemp[(i)   * (nx+1) * (ny+1) + (j)   * (nx+1) + k  ] +
 
234
                      itemp[(i)   * (nx+1) * (ny+1) + (j+1) * (nx+1) + k  ] +
 
235
                      itemp[(i)   * (nx+1) * (ny+1) + (j+1) * (nx+1) + k+1] +
 
236
                      itemp[(i)   * (nx+1) * (ny+1) + (j)   * (nx+1) + k+1] +
 
237
                      itemp[(i+1) * (nx+1) * (ny+1) + (j)   * (nx+1) + k  ] +
 
238
                      itemp[(i+1) * (nx+1) * (ny+1) + (j+1) * (nx+1) + k  ] +
 
239
                      itemp[(i+1) * (nx+1) * (ny+1) + (j+1) * (nx+1) + k+1] +
 
240
                      itemp[(i+1) * (nx+1) * (ny+1) + (j)   * (nx+1) + k+1];
 
241
                if (cnt == 0)
 
242
                {
 
243
                    /* EMPTY */
 
244
                }
 
245
                else if (cnt == 8)
 
246
                {
 
247
                    matlist[i * nx * ny + j * nx + k] = matno;
 
248
                }
 
249
                else
 
250
                {
 
251
                    dx = (x[i + 1] - x[i]) / 11.;
 
252
                    dy = (y[j + 1] - y[j]) / 11.;
 
253
                    dz = (z[k + 1] - z[k]) / 11.;
 
254
                    for (l = 0; l < 10; l++)
 
255
                    {
 
256
                        xx[l] = x[i] + (dx / 2.) + (l * dx);
 
257
                        yy[l] = y[j] + (dy / 2.) + (l * dy);
 
258
                        zz[l] = z[k] + (dz / 2.) + (l * dz);
 
259
                    }
 
260
                    cnt = 0;
 
261
                    for (l = 0; l < 10; l++)
 
262
                    {
 
263
                        for (m = 0; m < 10; m++)
 
264
                        {
 
265
                            for (n = 0; n < 10; n++)
 
266
                            {
 
267
                                dist = sqrt((xx[l] - xcenter) *
 
268
                                            (xx[l] - xcenter) +
 
269
                                            (yy[m] - ycenter) *
 
270
                                            (yy[m] - ycenter) +
 
271
                                            (zz[n] - zcenter) *
 
272
                                            (zz[n] - zcenter));
 
273
                                cnt += (dist < radius) ? 1 : 0;
 
274
                            }
 
275
                        }
 
276
                    }
 
277
                    matlist[i * nx * ny + j * nx + k] = -(mixlen2 + 1);
 
278
                    mix_mat[mixlen2] = matno - 1;
 
279
                    mix_mat[mixlen2 + 1] = matno;
 
280
                    mix_next[mixlen2] = mixlen2 + 2;
 
281
                    mix_next[mixlen2 + 1] = 0;
 
282
                    mix_zone[mixlen2] = i * nx * ny + j * nx + k;
 
283
                    mix_zone[mixlen2 + 1] = i * nx * ny + j * nx + k;
 
284
                    mix_vf[mixlen2] = 1. - (((float)cnt) / 1000.);
 
285
                    mix_vf[mixlen2 + 1] = ((float)cnt) / 1000.;
 
286
                    mixlen2 += 2;
 
287
                }
 
288
            }
 
289
        }
 
290
    }
 
291
 
 
292
    FREE(itemp);
 
293
 
 
294
    *mixlen = mixlen2;
 
295
}
 
296
 
 
297
/***********************************************************************      
 
298
 *
 
299
 * Purpose:
 
300
 *    Make a multi-block mesh, multi-block variables, and a multi-block
 
301
 *    material based on the given meshtype, dimensionality of the mesh,
 
302
 *    and number of blocks in the x-direction, y-direction, and
 
303
 *    z-direction.  Also specify if the mesh is collinear when creating
 
304
 *    a quad mesh.  The total number of blocks created for the mesh
 
305
 *    equals number of blocks in x-direction times number of blocks in
 
306
 *    y-direction times number of blocks in z-direction.
 
307
 *
 
308
 *    nblocks = nblocks_x * nblocks_y * nblocks_z
 
309
 *
 
310
 * Programmer:  Eric Brugger
 
311
 * Date:        September 17, 2001
 
312
 *
 
313
 * Modifications:
 
314
 *   Mark C. Miller, Wed Jul 14 15:34:55 PDT 2010
 
315
 *   Added support for namescheme options on mulit-block objects.
 
316
 ***********************************************************************/
 
317
int
 
318
build_multi(char *basename, int driver, char *file_ext,
 
319
            int nblocks_x, int nblocks_y, int nblocks_z)
 
320
{
 
321
    int             i;
 
322
    int             cycle;
 
323
    float           time;
 
324
    double          dtime;
 
325
    int             nmatnos;
 
326
    int             matnos[3];
 
327
    char            names[MAXBLOCKS][STRLEN];
 
328
    char           *meshnames[MAXBLOCKS];
 
329
    int             meshtypes[MAXBLOCKS];
 
330
    char            names1[MAXBLOCKS][STRLEN];
 
331
    char            names2[MAXBLOCKS][STRLEN];
 
332
    char            names3[MAXBLOCKS][STRLEN];
 
333
    char            names4[MAXBLOCKS][STRLEN];
 
334
    char            names5[MAXBLOCKS][STRLEN];
 
335
    char           *var1names[MAXBLOCKS];
 
336
    char           *var2names[MAXBLOCKS];
 
337
    char           *var3names[MAXBLOCKS];
 
338
    char           *var4names[MAXBLOCKS];
 
339
    char           *var5names[MAXBLOCKS];
 
340
    int             vartypes[MAXBLOCKS];
 
341
    char            names0[MAXBLOCKS][STRLEN];
 
342
    char           *matnames[MAXBLOCKS];
 
343
    char           file_ns[128];
 
344
    char           block_ns[128];
 
345
    int            block_type;
 
346
 
 
347
    DBoptlist      *optlist=NULL;
 
348
 
 
349
    char            filename[80];
 
350
    DBfile         *dbfile=NULL;
 
351
 
 
352
    int             nblocks = nblocks_x * nblocks_y * nblocks_z;
 
353
 
 
354
    /* 
 
355
     * Initialize the names and create the directories for the blocks.
 
356
     */
 
357
    for (i = 0; i < nblocks; i++)
 
358
    {
 
359
        int       filenum;
 
360
        char      prefix[120];
 
361
 
 
362
        filenum = i / (nblocks / NFILES);
 
363
        if (multidir)
 
364
#ifdef WIN32    
 
365
            sprintf(prefix, "multi_file.dir\\%03d\\%s%d.%s:/block%d/", filenum, basename, filenum, file_ext, i);
 
366
#else
 
367
            sprintf(prefix, "multi_file.dir/%03d/%s%d.%s:/block%d/", filenum, basename, filenum, file_ext, i);
 
368
#endif
 
369
        else
 
370
            sprintf(prefix, "%s%d.%s:/block%d/", basename, filenum, file_ext, i);
 
371
 
 
372
        sprintf(names[i], "%smesh1", prefix);
 
373
        meshnames[i] = names[i];
 
374
        meshtypes[i] = DB_UCDMESH;
 
375
 
 
376
        sprintf(names1[i], "%sd", prefix);
 
377
        sprintf(names2[i], "%sp", prefix);
 
378
        sprintf(names3[i], "%su", prefix);
 
379
        sprintf(names4[i], "%sv", prefix);
 
380
        sprintf(names5[i], "%sw", prefix);
 
381
        var1names[i] = names1[i];
 
382
        var2names[i] = names2[i];
 
383
        var3names[i] = names3[i];
 
384
        var4names[i] = names4[i];
 
385
        var5names[i] = names5[i];
 
386
        vartypes[i] = DB_UCDVAR;
 
387
 
 
388
        sprintf(names0[i], "%smat1", prefix);
 
389
        matnames[i] = names0[i];
 
390
    }
 
391
 
 
392
    /*
 
393
     * Create nameschemes for files and blocks within files
 
394
     */
 
395
    if (use_ns)
 
396
    {
 
397
        if (multidir)
 
398
        {
 
399
#ifdef WIN32    
 
400
            sprintf(file_ns, "|multi_file.dir\\%%03d\\%%s%%d.%%s|n/36|'%s'|n/36|'%s'", basename, file_ext);
 
401
#else
 
402
            sprintf(file_ns, "|multi_file.dir/%%03d/%%s%%d.%%s|n/36|'%s'|n/36|'%s'", basename, file_ext);
 
403
#endif
 
404
        }
 
405
        else
 
406
            sprintf(file_ns, "|%%s%%d.%%s|'%s'|n/36|'%s'", basename, file_ext);
 
407
        sprintf(block_ns, "|/block%%d/mesh1|n");
 
408
    }
 
409
 
 
410
    /*
 
411
     * Create the blocks.
 
412
     */
 
413
    build_block_ucd3d(basename, driver, file_ext, 
 
414
                      nblocks_x, nblocks_y, nblocks_z);
 
415
 
 
416
    /*
 
417
     * Create the file.
 
418
     */
 
419
    sprintf(filename, "%s_root.%s", basename, file_ext);
 
420
    if ((dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL,
 
421
        "multi-file ucd 3d test file", driver)) == NULL)
 
422
    {
 
423
        fprintf(stderr, "Could not create '%s'.\n", filename);
 
424
        return -1;
 
425
    }
 
426
 
 
427
    /*
 
428
     * Create the option lists for the multi-block calls.
 
429
     */
 
430
    cycle = 48;
 
431
    time = 4.8;
 
432
    dtime = 4.8;
 
433
    nmatnos = 3;
 
434
    matnos[0] = 1;
 
435
    matnos[1] = 2;
 
436
    matnos[2] = 3;
 
437
 
 
438
    optlist = DBMakeOptlist(10);
 
439
    DBAddOption(optlist, DBOPT_CYCLE, &cycle);
 
440
    DBAddOption(optlist, DBOPT_TIME, &time);
 
441
    DBAddOption(optlist, DBOPT_DTIME, &dtime);
 
442
    DBAddOption(optlist, DBOPT_NMATNOS, &nmatnos);
 
443
    DBAddOption(optlist, DBOPT_MATNOS, matnos);
 
444
    if (use_ns)
 
445
    {
 
446
        DBAddOption(optlist, DBOPT_MB_FILE_NS, file_ns);
 
447
        DBAddOption(optlist, DBOPT_MB_BLOCK_NS, block_ns);
 
448
        DBAddOption(optlist, DBOPT_MB_BLOCK_TYPE, &block_type);
 
449
    }
 
450
 
 
451
    /*
 
452
     * Create the multi-block mesh, variables and material.
 
453
     */
 
454
    block_type = DB_UCDMESH;
 
455
    if (DBPutMultimesh(dbfile, "mesh1", nblocks,
 
456
                       use_ns?0:meshnames, use_ns?0:meshtypes, optlist) == -1)
 
457
    {
 
458
        DBFreeOptlist(optlist);
 
459
        fprintf(stderr, "Error creating multi mesh\n");
 
460
        return -1;
 
461
    }
 
462
    block_type = DB_UCDVAR;
 
463
    sprintf(block_ns, "|/block%%d/d|n");
 
464
    if (DBPutMultivar(dbfile, "d", nblocks, use_ns?0:var1names, use_ns?0:vartypes, optlist)
 
465
        == -1)
 
466
    {
 
467
        DBFreeOptlist(optlist);
 
468
        fprintf(stderr, "Error creating multi var d\n");
 
469
        return -1;
 
470
    }
 
471
    sprintf(block_ns, "|/block%%d/p|n");
 
472
    if (DBPutMultivar(dbfile, "p", nblocks, use_ns?0:var2names, use_ns?0:vartypes, optlist)
 
473
        == -1)
 
474
    {
 
475
        DBFreeOptlist(optlist);
 
476
        fprintf(stderr, "Error creating multi var p\n");
 
477
        return -1;
 
478
    }
 
479
    sprintf(block_ns, "|/block%%d/u|n");
 
480
    if (DBPutMultivar(dbfile, "u", nblocks, use_ns?0:var3names, use_ns?0:vartypes, optlist)
 
481
        == -1)
 
482
    {
 
483
        DBFreeOptlist(optlist);
 
484
        fprintf(stderr, "Error creating multi var u\n");
 
485
        return -1;
 
486
    }
 
487
    sprintf(block_ns, "|/block%%d/v|n");
 
488
    if (DBPutMultivar(dbfile, "v", nblocks, use_ns?0:var4names, use_ns?0:vartypes, optlist)
 
489
        == -1)
 
490
    {
 
491
        DBFreeOptlist(optlist);
 
492
        fprintf(stderr, "Error creating multi var v\n");
 
493
        return -1;
 
494
    }
 
495
    sprintf(block_ns, "|/block%%d/w|n");
 
496
    if (DBPutMultivar(dbfile, "w", nblocks, use_ns?0:var5names, use_ns?0:vartypes, optlist)
 
497
        == -1)
 
498
    {
 
499
        DBFreeOptlist(optlist);
 
500
        fprintf(stderr, "Error creating multi var w\n");
 
501
        return -1;
 
502
    }
 
503
    sprintf(block_ns, "|/block%%d/mat1|n");
 
504
    if (DBPutMultimat(dbfile, "mat1", nblocks, use_ns?0:matnames, optlist) == -1)
 
505
    {
 
506
        DBFreeOptlist(optlist);
 
507
        fprintf(stderr, "Error creating multi material\n");
 
508
        return -1;
 
509
    }
 
510
    DBFreeOptlist(optlist);
 
511
 
 
512
    /*
 
513
     * Close the file.
 
514
     */
 
515
    DBClose(dbfile);
 
516
 
 
517
    return 0;
 
518
}
 
519
 
 
520
/***********************************************************************
 
521
 * Purpose:
 
522
 *    Build a 3-d UCD mesh and add it to the open database.
 
523
 *
 
524
 * Programmer:  Eric Brugger
 
525
 * Date:        September 17, 2001
 
526
 *
 
527
 ***********************************************************************/
 
528
void
 
529
build_block_ucd3d(char *basename, int driver, char *file_ext,
 
530
                  int nblocks_x, int nblocks_y, int nblocks_z)
 
531
{
 
532
    int             nx, ny, nz;
 
533
    int             cycle;
 
534
    float           time;
 
535
    double          dtime;
 
536
    char           *coordnames[3];
 
537
    float          *coords[3];
 
538
    float          *x=NULL, *y=NULL, *z=NULL;
 
539
 
 
540
    char           *meshname=NULL, *var1name=NULL, *var2name=NULL,
 
541
                   *var3name=NULL, *var4name=NULL, *var5name=NULL;
 
542
    char           *matname=NULL;
 
543
    float          *vars[1];
 
544
    char           *varnames[1];
 
545
    float          *d=NULL, *p=NULL, *u=NULL, *v=NULL, *w=NULL;
 
546
 
 
547
    int             nmats;
 
548
    int             matnos[3];
 
549
    int            *matlist=NULL;
 
550
    int             mixlen;
 
551
    int            *mix_next=NULL, *mix_mat=NULL, *mix_zone=NULL;
 
552
    float          *mix_vf=NULL;
 
553
    float          *xstrip=NULL, *ystrip=NULL, *zstrip=NULL;
 
554
 
 
555
    int             i, j, k;
 
556
    int             iz;
 
557
    float           xcenter, ycenter;
 
558
    float           theta, dtheta;
 
559
    float           r, dr;
 
560
    float           h, dh;
 
561
    float           dist;
 
562
 
 
563
    int             block;
 
564
    int             delta_x, delta_y, delta_z;
 
565
 
 
566
    nx = 120;
 
567
    ny = 160;
 
568
    nz = 120;
 
569
 
 
570
    x = ALLOC_N(float, (nx+1)*(ny+1)*(nz+1));
 
571
    y = ALLOC_N(float, (nx+1)*(ny+1)*(nz+1));
 
572
    z = ALLOC_N(float, (nx+1)*(ny+1)*(nz+1));
 
573
 
 
574
    d = ALLOC_N(float, (nx+1)*(ny+1)*(nz+1));
 
575
    p = ALLOC_N(float, (nx+1)*(ny+1)*(nz+1));
 
576
    u = ALLOC_N(float, (nx+1)*(ny+1)*(nz+1));
 
577
    v = ALLOC_N(float, (nx+1)*(ny+1)*(nz+1));
 
578
    w = ALLOC_N(float, (nx+1)*(ny+1)*(nz+1));
 
579
 
 
580
    matlist  = ALLOC_N(int, nx*ny*nz);
 
581
    mix_next = ALLOC_N(int, 85000);
 
582
    mix_mat  = ALLOC_N(int, 85000);
 
583
    mix_zone = ALLOC_N(int, 85000);
 
584
    mix_vf   = ALLOC_N(float, 85000);
 
585
 
 
586
    xstrip   = ALLOC_N(float, nx+ny+nz);
 
587
    ystrip   = ALLOC_N(float, nx+ny+nz);
 
588
    zstrip   = ALLOC_N(float, nx+ny+nz);
 
589
 
 
590
    /* 
 
591
     * Create the coordinate arrays for the entire mesh.
 
592
     */
 
593
    dh = 20. / (float)nx;
 
594
    dtheta = (180. / (float)ny) * (3.1415926 / 180.);
 
595
    dr = 3. / (float)nz;
 
596
    h = 0.;
 
597
    for (i = 0; i < nx + 1; i++)
 
598
    {
 
599
        theta = 0.;
 
600
        for (j = 0; j < ny + 1; j++)
 
601
        {
 
602
            r = 2.;
 
603
            for (k = 0; k < nz + 1; k++)
 
604
            {
 
605
                x[i * (nx+1)*(ny+1) + j * (nx+1) + k] = r * cos(theta);
 
606
                y[i * (nx+1)*(ny+1) + j * (nx+1) + k] = r * sin(theta);
 
607
                z[i * (nx+1)*(ny+1) + j * (nx+1) + k] = h;
 
608
                r += dr;
 
609
            }
 
610
            theta += dtheta;
 
611
        }
 
612
        h += dh;
 
613
    }
 
614
 
 
615
    /* 
 
616
     * Create the density and pressure arrays for the entire mesh.
 
617
     */
 
618
    xcenter = 0.;
 
619
    ycenter = 0.;
 
620
    for (i = 0; i < nx + 1; i++)
 
621
    {
 
622
        for (j = 0; j < ny + 1; j++)
 
623
        {
 
624
            for (k = 0; k < nz + 1; k++)
 
625
            {
 
626
                dist = sqrt((x[i * (nx+1)*(ny+1) + j * (nx+1) + k] - xcenter) *
 
627
                            (x[i * (nx+1)*(ny+1) + j * (nx+1) + k] - xcenter) +
 
628
                            (y[i * (nx+1)*(ny+1) + j * (nx+1) + k] - ycenter) *
 
629
                            (y[i * (nx+1)*(ny+1) + j * (nx+1) + k] - ycenter));
 
630
                d[i * (nx+1)*(ny+1) + j * (nx+1) + k] = dist;
 
631
                p[i * (nx+1)*(ny+1) + j * (nx+1) + k] = 1. / (dist + .0001);
 
632
            }
 
633
        }
 
634
    }
 
635
 
 
636
    /* 
 
637
     * Create the velocity component arrays for the entire mesh.
 
638
     */
 
639
    xcenter = 0.;
 
640
    ycenter = 0.;
 
641
    for (i = 0; i < nx + 1; i++)
 
642
    {
 
643
        for (j = 0; j < ny + 1; j++)
 
644
        {
 
645
            for (k = 0; k < nz + 1; k++)
 
646
            {
 
647
                dist = sqrt((x[i] - xcenter) * (x[i] - xcenter) +
 
648
                            (y[j] - ycenter) * (y[j] - ycenter));
 
649
                u[i * (nx+1)*(ny+1) + j * (nx+1) + k] = (x[i] - xcenter) / dist;
 
650
                v[i * (nx+1)*(ny+1) + j * (nx+1) + k] = (y[j] - ycenter) / dist;
 
651
                w[i * (nx+1)*(ny+1) + j * (nx+1) + k] = 0.;
 
652
            }
 
653
        }
 
654
    }
 
655
 
 
656
    /* 
 
657
     * Put in the material for the entire mesh.
 
658
     */
 
659
    fill_bkgr(matlist, nx, ny, nz, 1);
 
660
 
 
661
    for (i = 0; i < ny; i++)
 
662
    {
 
663
        xstrip[i] = (float)i;
 
664
        ystrip[i] = (float)i;
 
665
        zstrip[i] = (float)i;
 
666
    }
 
667
 
 
668
    mixlen = 0;
 
669
    fill_mat(xstrip, ystrip, zstrip, matlist, nx, ny, nz, mix_next,
 
670
             mix_mat, mix_zone, mix_vf, &mixlen, 2, 60., 80., 60., 40.);
 
671
    fill_mat(xstrip, ystrip, zstrip, matlist, nx, ny, nz, mix_next,
 
672
             mix_mat, mix_zone, mix_vf, &mixlen, 3, 60., 80., 60., 20.);
 
673
    if (mixlen > 85000)
 
674
    {
 
675
        printf("memory overwrite: mixlen = %d > 85000\n", mixlen);
 
676
        exit(-1);
 
677
    }
 
678
    /* 
 
679
     * Set up variables that are independent of the block number.
 
680
     */
 
681
    cycle = 48;
 
682
    time = 4.8;
 
683
    dtime = 4.8;
 
684
 
 
685
    meshname = "mesh1";
 
686
    coordnames[0] = "xcoords";
 
687
    coordnames[1] = "ycoords";
 
688
    coordnames[2] = "zcoords";
 
689
 
 
690
    var1name = "d";
 
691
    var2name = "p";
 
692
    var3name = "u";
 
693
    var4name = "v";
 
694
    var5name = "w";
 
695
 
 
696
    matname = "mat1";
 
697
    nmats = 3;
 
698
    matnos[0] = 1;
 
699
    matnos[1] = 2;
 
700
    matnos[2] = 3;
 
701
 
 
702
    /* 
 
703
     * Now extract the data for this block.
 
704
     */
 
705
    delta_x = nx / nblocks_x;
 
706
    delta_y = ny / nblocks_y;
 
707
    delta_z = nz / nblocks_z;
 
708
 
 
709
    if (multidir)
 
710
    {
 
711
        int st;
 
712
        unlink("multi_file.dir/000/ucd3d0.pdb");
 
713
        unlink("multi_file.dir/000/ucd3d0.h5");
 
714
        rmdir("multi_file.dir/000");
 
715
        unlink("multi_file.dir/001/ucd3d1.pdb");
 
716
        unlink("multi_file.dir/001/ucd3d1.h5");
 
717
        rmdir("multi_file.dir/001");
 
718
        unlink("multi_file.dir/002/ucd3d2.pdb");
 
719
        unlink("multi_file.dir/002/ucd3d2.h5");
 
720
        rmdir("multi_file.dir/002");
 
721
        unlink("multi_file.dir/003/ucd3d3.pdb");
 
722
        unlink("multi_file.dir/003/ucd3d3.h5");
 
723
        rmdir("multi_file.dir/003");
 
724
        unlink("multi_file.dir/004/ucd3d4.pdb");
 
725
        unlink("multi_file.dir/004/ucd3d4.h5");
 
726
        rmdir("multi_file.dir/004");
 
727
        unlink("multi_file.dir/005/ucd3d5.pdb");
 
728
        unlink("multi_file.dir/005/ucd3d5.h5");
 
729
        rmdir("multi_file.dir/005");
 
730
        unlink("multi_file.dir/006/ucd3d6.pdb");
 
731
        unlink("multi_file.dir/006/ucd3d6.h5");
 
732
        rmdir("multi_file.dir/006");
 
733
        unlink("multi_file.dir/007/ucd3d7.pdb");
 
734
        unlink("multi_file.dir/007/ucd3d7.h5");
 
735
        rmdir("multi_file.dir/007");
 
736
        rmdir("multi_file.dir");
 
737
#ifndef WIN32
 
738
        st = mkdir("multi_file.dir",S_IRWXU|S_IRWXG|S_IRWXU);
 
739
#else
 
740
        st = _mkdir("multi_file.dir");
 
741
#endif
 
742
        if (st < 0)
 
743
        {
 
744
            fprintf(stderr, "Unable to mkdir(\"multi_file.dir\")\n");
 
745
            return;
 
746
        }
 
747
        fprintf(stdout, "\tMade directory multi_file.dir\n");
 
748
    }
 
749
 
 
750
    /* 
 
751
     * Create the blocks for the multi-block object.
 
752
     */
 
753
 
 
754
    for (block = 0; block < nblocks_x * nblocks_y * nblocks_z; block++)
 
755
    {
 
756
        char            dirname[80];
 
757
        int             filenum;
 
758
        char            filename[120];
 
759
 
 
760
        int             imin, imax, jmin, jmax, kmin, kmax;
 
761
        int             nnx, nny, nnz;
 
762
 
 
763
        float          *x2=NULL, *y2=NULL, *z2=NULL;
 
764
        float          *d2=NULL, *p2=NULL, *u2=NULL, *v2=NULL, *w2=NULL;
 
765
        int            *matlist2=NULL, *ghost=NULL;
 
766
 
 
767
        int             n_x, n_y, n_z;
 
768
 
 
769
        int             nreal;
 
770
        int             ighost;
 
771
        int             itemp;
 
772
        int             hi_off;
 
773
 
 
774
        int             one = 1;
 
775
 
 
776
        int             nfaces, nzones, nnodes;
 
777
        int             lfacelist, lzonelist;
 
778
        int             fshapesize, fshapecnt;
 
779
        int             zshapetype, zshapesize, zshapecnt;
 
780
        int            *zonelist=NULL;
 
781
        int            *facelist=NULL;
 
782
        int            *zoneno=NULL;
 
783
 
 
784
        DBfacelist     *fl=NULL;
 
785
 
 
786
        DBoptlist      *optlist=NULL;
 
787
        DBobject       *obj=NULL;
 
788
        DBfile         *dbfile;
 
789
 
 
790
        sprintf(dirname, "/block%d", block);
 
791
        filenum = block / ((nblocks_x * nblocks_y * nblocks_z) / NFILES);
 
792
        if (multidir)
 
793
            sprintf(filename, "multi_file.dir/%03d/%s%d.%s", filenum, basename, filenum, file_ext);
 
794
        else
 
795
            sprintf(filename, "%s%d.%s", basename, filenum, file_ext);
 
796
 
 
797
        fprintf(stdout, "\t%s:%s\n", filename, dirname);
 
798
 
 
799
        /* 
 
800
         * Now extract the data for this block.
 
801
         */
 
802
        imin = (block % nblocks_x) * delta_x - 1;
 
803
        imax = MIN(imin + delta_x + 3, nx + 1);
 
804
        imin = MAX(imin, 0);
 
805
        nnx = imax - imin;
 
806
        jmin = ((block % (nblocks_x * nblocks_y)) / nblocks_x) * delta_y - 1;
 
807
        jmax = MIN(jmin + delta_y + 3, ny + 1);
 
808
        jmin = MAX(jmin, 0);
 
809
        nny = jmax - jmin;
 
810
        kmin = (block / (nblocks_x * nblocks_y)) * delta_z - 1;
 
811
        kmax = MIN(kmin + delta_z + 3, nz + 1);
 
812
        kmin = MAX(kmin, 0);
 
813
        nnz = kmax - kmin;
 
814
 
 
815
        x2 = ALLOC_N(float, nnx*nny*nnz);
 
816
        y2 = ALLOC_N(float, nnx*nny*nnz);
 
817
        z2 = ALLOC_N(float, nnx*nny*nnz);
 
818
        d2 = ALLOC_N(float, nnx*nny*nnz);
 
819
        p2 = ALLOC_N(float, nnx*nny*nnz);
 
820
        u2 = ALLOC_N(float, nnx*nny*nnz);
 
821
        v2 = ALLOC_N(float, nnx*nny*nnz);
 
822
        w2 = ALLOC_N(float, nnx*nny*nnz);
 
823
        matlist2 = ALLOC_N(int, (nnx-1)*(nny-1)*(nnz-1));
 
824
        ghost    = ALLOC_N(int, (nnx-1)*(nny-1)*(nnz-1));
 
825
 
 
826
        coords[0] = x2;
 
827
        coords[1] = y2;
 
828
        coords[2] = z2;
 
829
 
 
830
        for (k = 0, n_z = kmin; n_z < kmax; k++, n_z++)
 
831
            for (j = 0, n_y = jmin; n_y < jmax; j++, n_y++)
 
832
                for (i = 0, n_x = imin; n_x < imax; i++, n_x++)
 
833
                {
 
834
                    x2[k * nnx * nny + j * nnx + i] =
 
835
                        x[n_z * (nx + 1) * (ny + 1) + n_y * (nx + 1) + n_x];
 
836
                    y2[k * nnx * nny + j * nnx + i] =
 
837
                        y[n_z * (nx + 1) * (ny + 1) + n_y * (nx + 1) + n_x];
 
838
                    z2[k * nnx * nny + j * nnx + i] =
 
839
                        z[n_z * (nx + 1) * (ny + 1) + n_y * (nx + 1) + n_x];
 
840
                    d2[k * nnx * nny + j * nnx + i] =
 
841
                        d[n_z * (nx + 1) * (ny + 1) + n_y * (nx + 1) + n_x];
 
842
                    p2[k * nnx * nny + j * nnx + i] =
 
843
                        p[n_z * (nx + 1) * (ny + 1) + n_y * (nx + 1) + n_x];
 
844
                    u2[k * nnx * nny + j * nnx + i] =
 
845
                        u[n_z * (nx + 1) * (ny + 1) + n_y * (nx + 1) + n_x];
 
846
                    v2[k * nnx * nny + j * nnx + i] =
 
847
                        v[n_z * (nx + 1) * (ny + 1) + n_y * (nx + 1) + n_x];
 
848
                    w2[k * nnx * nny + j * nnx + i] =
 
849
                        w[n_z * (nx + 1) * (ny + 1) + n_y * (nx + 1) + n_x];
 
850
                }
 
851
 
 
852
        zonelist = ALLOC_N(int, (nnx-1)*(nny-1)*(nnz-1)*8);
 
853
 
 
854
        iz = 0;
 
855
        for (k = 0, n_z = kmin; n_z < kmax - 1; k++, n_z++)
 
856
            for (j = 0, n_y = jmin; n_y < jmax - 1; j++, n_y++)
 
857
                for (i = 0, n_x = imin; n_x < imax - 1; i++, n_x++)
 
858
                {
 
859
                    zonelist[iz]     = (k+0) * nnx*nny + (j+1) * nnx + i+1;
 
860
                    zonelist[iz + 1] = (k+0) * nnx*nny + (j+0) * nnx + i+1;
 
861
                    zonelist[iz + 2] = (k+1) * nnx*nny + (j+0) * nnx + i+1;
 
862
                    zonelist[iz + 3] = (k+1) * nnx*nny + (j+1) * nnx + i+1;
 
863
                    zonelist[iz + 4] = (k+0) * nnx*nny + (j+1) * nnx + i+0;
 
864
                    zonelist[iz + 5] = (k+0) * nnx*nny + (j+0) * nnx + i+0;
 
865
                    zonelist[iz + 6] = (k+1) * nnx*nny + (j+0) * nnx + i+0;
 
866
                    zonelist[iz + 7] = (k+1) * nnx*nny + (j+1) * nnx + i+0;
 
867
                    iz += 8;
 
868
 
 
869
                    matlist2[k * (nnx - 1) * (nny - 1) + j * (nnx - 1) + i] =
 
870
                        matlist[n_z * nx * ny + n_y * nx + n_x];
 
871
 
 
872
                    if (((k == 0 || n_z == kmax - 2) &&
 
873
                         (n_z != 0 && n_z != nz - 1)) ||
 
874
                        ((j == 0 || n_y == jmax - 2) &&
 
875
                         (n_y != 0 && n_y != ny - 1)) ||
 
876
                        ((i == 0 || n_x == imax - 2) &&
 
877
                         (n_x != 0 && n_x != nx - 1)))
 
878
                        ghost[k * (nnx-1) * (nny-1) + j * (nnx-1) + i] = 1;
 
879
                    else
 
880
                        ghost[k * (nnx-1) * (nny-1) + j * (nnx-1) + i] = 0;
 
881
                }
 
882
 
 
883
        /* 
 
884
         * Resort the zonelist, matlist so that the ghost zones are at the
 
885
         * end.
 
886
         */
 
887
        nzones = (nnx - 1) * (nny - 1) * (nnz - 1);
 
888
        nreal = nzones;
 
889
        for (i = 0; i < nzones; i++)
 
890
            nreal -= ghost[i];
 
891
        ighost = nzones - 1;
 
892
        for (i = 0; i < nreal; i++)
 
893
        {
 
894
            if (ghost[i] == 1)
 
895
            {
 
896
                /* 
 
897
                 * Find the first non ghost zone.
 
898
                 */
 
899
                while (ghost[ighost] == 1)
 
900
                    ighost--;
 
901
                j = ighost;
 
902
 
 
903
                itemp = zonelist[i * 8];
 
904
                zonelist[i * 8] = zonelist[j * 8];
 
905
                zonelist[j * 8] = itemp;
 
906
                itemp = zonelist[i * 8 + 1];
 
907
                zonelist[i * 8 + 1] = zonelist[j * 8 + 1];
 
908
                zonelist[j * 8 + 1] = itemp;
 
909
                itemp = zonelist[i * 8 + 2];
 
910
                zonelist[i * 8 + 2] = zonelist[j * 8 + 2];
 
911
                zonelist[j * 8 + 2] = itemp;
 
912
                itemp = zonelist[i * 8 + 3];
 
913
                zonelist[i * 8 + 3] = zonelist[j * 8 + 3];
 
914
                zonelist[j * 8 + 3] = itemp;
 
915
                itemp = zonelist[i * 8 + 4];
 
916
                zonelist[i * 8 + 4] = zonelist[j * 8 + 4];
 
917
                zonelist[j * 8 + 4] = itemp;
 
918
                itemp = zonelist[i * 8 + 5];
 
919
                zonelist[i * 8 + 5] = zonelist[j * 8 + 5];
 
920
                zonelist[j * 8 + 5] = itemp;
 
921
                itemp = zonelist[i * 8 + 6];
 
922
                zonelist[i * 8 + 6] = zonelist[j * 8 + 6];
 
923
                zonelist[j * 8 + 6] = itemp;
 
924
                itemp = zonelist[i * 8 + 7];
 
925
                zonelist[i * 8 + 7] = zonelist[j * 8 + 7];
 
926
                zonelist[j * 8 + 7] = itemp;
 
927
 
 
928
                itemp = matlist2[i];
 
929
                matlist2[i] = matlist2[j];
 
930
                matlist2[j] = itemp;
 
931
 
 
932
                itemp = ghost[i];
 
933
                ghost[i] = ghost[j];
 
934
                ghost[j] = itemp;
 
935
            }
 
936
        }
 
937
 
 
938
        /* 
 
939
         * Calculate the external face list.
 
940
         */
 
941
        nnodes = nnx * nny * nnz;
 
942
        hi_off = nzones - nreal;
 
943
 
 
944
        zshapesize = 8;
 
945
        zshapecnt = nzones;
 
946
        zshapetype = DB_ZONETYPE_HEX;
 
947
        lzonelist = nzones * 8;
 
948
 
 
949
        fl = DBCalcExternalFacelist2(zonelist, nnodes, 0, hi_off, 0,
 
950
                                     &zshapetype, &zshapesize, &zshapecnt, 1,
 
951
                                     matlist2, 0);
 
952
 
 
953
        facelist = ALLOC_N(int, fl->lnodelist);
 
954
        zoneno   = ALLOC_N(int, fl->nfaces);
 
955
 
 
956
        nfaces = fl->nfaces;
 
957
        fshapecnt = fl->nfaces;
 
958
        fshapesize = 4;
 
959
        lfacelist = fl->lnodelist;
 
960
        for (i = 0; i < lfacelist; i++)
 
961
            facelist[i] = fl->nodelist[i];
 
962
        for (i = 0; i < nfaces; i++)
 
963
            zoneno[i] = fl->zoneno[i];
 
964
 
 
965
        DBFreeFacelist(fl);
 
966
 
 
967
        /*
 
968
         * If the block number is devisible by 1/NFILES of the total number
 
969
         * of blocks then create the file, otherwise just open the file
 
970
         * since it has already been created.
 
971
         */
 
972
        if (block % ((nblocks_x * nblocks_y * nblocks_z) / NFILES) == 0)
 
973
        {
 
974
            if (multidir)
 
975
            {
 
976
                int st;
 
977
                char dname[60];
 
978
                sprintf(dname, "multi_file.dir/%03d", filenum);
 
979
#ifndef WIN32
 
980
                st = mkdir(dname, S_IRWXU|S_IRWXG|S_IRWXU);
 
981
#else
 
982
                st = _mkdir(dname);
 
983
#endif
 
984
                if (st < 0)
 
985
                {
 
986
                    fprintf(stderr, "Unable to make directory \"%s\"\n", dname);
 
987
                    return;
 
988
                }
 
989
                fprintf(stdout, "\tMade directory %s\n", dname);
 
990
            }
 
991
 
 
992
            if ((dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL,
 
993
                "multi-file ucd 3d test file", driver)) == NULL)
 
994
            {
 
995
                fprintf(stderr, "Could not create '%s'.\n", filename);
 
996
                return;
 
997
            }
 
998
        }
 
999
        else
 
1000
        {
 
1001
            if ((dbfile = DBOpen(filename, driver, DB_APPEND)) == NULL)
 
1002
            {
 
1003
                fprintf(stderr, "Could not open '%s'.\n", filename);
 
1004
                return;
 
1005
            }
 
1006
        }
 
1007
 
 
1008
        /*
 
1009
         * Make the directory for the block and cd into it.
 
1010
         */
 
1011
        if (DBMkDir(dbfile, dirname) == -1)
 
1012
        {
 
1013
            fprintf(stderr, "Could not make directory \"%s\"\n", dirname);
 
1014
            return;
 
1015
        }
 
1016
        if (DBSetDir(dbfile, dirname) == -1)
 
1017
        {
 
1018
            fprintf(stderr, "Could not set directory \"%s\"\n", dirname);
 
1019
            return;
 
1020
        }
 
1021
 
 
1022
        /*
 
1023
         * Write out the mesh and variables.
 
1024
         */
 
1025
        optlist = DBMakeOptlist(10);
 
1026
        DBAddOption(optlist, DBOPT_CYCLE, &cycle);
 
1027
        DBAddOption(optlist, DBOPT_TIME, &time);
 
1028
        DBAddOption(optlist, DBOPT_DTIME, &dtime);
 
1029
        DBAddOption(optlist, DBOPT_XLABEL, "X Axis");
 
1030
        DBAddOption(optlist, DBOPT_YLABEL, "Y Axis");
 
1031
        DBAddOption(optlist, DBOPT_ZLABEL, "Z Axis");
 
1032
        DBAddOption(optlist, DBOPT_XUNITS, "cm");
 
1033
        DBAddOption(optlist, DBOPT_YUNITS, "cm");
 
1034
        DBAddOption(optlist, DBOPT_ZUNITS, "cm");
 
1035
        DBAddOption(optlist, DBOPT_HI_OFFSET, &hi_off);
 
1036
 
 
1037
        if (nfaces > 0)
 
1038
            DBPutFacelist(dbfile, "fl1", nfaces, 3, facelist, lfacelist, 0,
 
1039
                      zoneno, &fshapesize, &fshapecnt, 1, NULL, NULL, 0);
 
1040
 
 
1041
        DBPutZonelist2(dbfile, "zl1", nzones, 3, zonelist, lzonelist, 0,
 
1042
            0, hi_off, &zshapetype, &zshapesize, &zshapecnt, 1, 0);
 
1043
 
 
1044
        /* 
 
1045
         * Output the rest of the mesh and variables.
 
1046
         */
 
1047
        if (nfaces > 0)
 
1048
            DBPutUcdmesh(dbfile, meshname, 3, coordnames, coords,
 
1049
                         nnodes, nzones, "zl1", "fl1", DB_FLOAT, optlist);
 
1050
        else
 
1051
            DBPutUcdmesh(dbfile, meshname, 3, coordnames, coords,
 
1052
                         nnodes, nzones, "zl1", NULL, DB_FLOAT, optlist);
 
1053
 
 
1054
        vars[0] = d2;
 
1055
        varnames[0] = var1name;
 
1056
        DBPutUcdvar(dbfile, var1name, meshname, 1, varnames, vars,
 
1057
                    nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, optlist);
 
1058
 
 
1059
        vars[0] = p2;
 
1060
        varnames[0] = var2name;
 
1061
        DBPutUcdvar(dbfile, var2name, meshname, 1, varnames, vars,
 
1062
                    nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, optlist);
 
1063
 
 
1064
        vars[0] = u2;
 
1065
        varnames[0] = var3name;
 
1066
        DBPutUcdvar(dbfile, var3name, meshname, 1, varnames, vars,
 
1067
                    nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, optlist);
 
1068
 
 
1069
        vars[0] = v2;
 
1070
        varnames[0] = var4name;
 
1071
        DBPutUcdvar(dbfile, var4name, meshname, 1, varnames, vars,
 
1072
                    nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, optlist);
 
1073
 
 
1074
        vars[0] = w2;
 
1075
        varnames[0] = var5name;
 
1076
        DBPutUcdvar(dbfile, var5name, meshname, 1, varnames, vars,
 
1077
                    nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, optlist);
 
1078
 
 
1079
        DBPutMaterial(dbfile, matname, meshname, nmats, matnos,
 
1080
                      matlist2, &nzones, 1, mix_next, mix_mat, mix_zone,
 
1081
                      mix_vf, mixlen, DB_FLOAT, optlist);
 
1082
 
 
1083
        DBFreeOptlist(optlist);
 
1084
 
 
1085
        FREE(x2);
 
1086
        FREE(y2);
 
1087
        FREE(z2);
 
1088
        FREE(d2);
 
1089
        FREE(p2);
 
1090
        FREE(u2);
 
1091
        FREE(v2);
 
1092
        FREE(w2);
 
1093
        FREE(matlist2);
 
1094
        FREE(ghost);
 
1095
 
 
1096
        FREE(zonelist);
 
1097
        FREE(facelist);
 
1098
        FREE(zoneno);
 
1099
 
 
1100
        /*
 
1101
         * Close the file.
 
1102
         */
 
1103
        DBClose(dbfile);
 
1104
    }
 
1105
 
 
1106
    FREE(x);
 
1107
    FREE(y);
 
1108
    FREE(z);
 
1109
 
 
1110
    FREE(d);
 
1111
    FREE(p);
 
1112
    FREE(u);
 
1113
    FREE(v);
 
1114
    FREE(w);
 
1115
 
 
1116
    FREE(matlist);
 
1117
    FREE(mix_next);
 
1118
    FREE(mix_mat);
 
1119
    FREE(mix_zone);
 
1120
    FREE(mix_vf);
 
1121
 
 
1122
    FREE(xstrip);
 
1123
    FREE(ystrip);
 
1124
    FREE(zstrip);
 
1125
}
 
1126