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.
53
* Create a multi-file multi-block mesh.
62
#include <sys/types.h>
71
#define MAXBLOCKS 400 /* Maximum number of blocks in an object */
73
#define MIXMAX 20000 /* Maximum length of the mixed arrays */
74
#define NFILES 8 /* The number of files to create */
76
#define MIN(x, y) (x) < (y) ? (x) : (y)
77
#define MAX(x, y) (x) > (y) ? (x) : (y)
79
#define ALLOC_N(T,N) ((T*)calloc((N),sizeof(T)))
80
#define FREE(M) if(M){free(M);(M)=NULL;}
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);
89
int build_multi(char *, int, char *, int, int, int);
91
void build_block_ucd3d(char *, int, char *, int, int, int);
93
/***********************************************************************
96
* Generate a multi file 3d ucd multi block test file.
98
* Programmer: Eric Brugger
99
* Date: September 17, 2001
102
* Mark C. Miller, Wed Jul 14 15:33:43 PDT 2010
103
* Added use-ns (namescheme) options for multi-block objects.
104
***********************************************************************/
106
main(int argc, char *argv[])
109
char *basename="ucd3d";
110
char *file_ext="pdb";
112
int show_all_errors = FALSE;
115
* Parse the command-line.
117
for (i = 1; i < argc; i++)
119
if (!strncmp(argv[i], "DB_PDB", 6))
121
driver = StringToDriver(argv[i]);
124
else if (!strncmp(argv[i], "DB_HDF5", 7))
126
driver = StringToDriver(argv[i]);
129
else if (!strcmp(argv[i], "multidir"))
133
else if (!strcmp(argv[i], "use-ns"))
137
else if (!strcmp(argv[i], "show-all-errors"))
141
else if (argv[i][0] != '\0')
143
fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
147
if (show_all_errors) DBShowErrors(DB_ALL_AND_DRVR, 0);
150
* Create the multi-block ucd 3d mesh.
152
build_multi(basename, driver, file_ext, 6, 8, 6);
154
CleanupDriverStuff();
158
/***********************************************************************
161
* Fill the entire material array with the material "matno".
163
* Programmer: Eric Brugger
164
* Date: September 17, 2001
166
***********************************************************************/
168
fill_bkgr(int *matlist, int nx, int ny, int nz, int matno)
172
for (i = 0; i < nx; i++)
174
for (j = 0; j < ny; j++)
176
for (k = 0; k < nz; k++)
178
matlist[k * nx * ny + j * nx + i] = matno;
184
/***********************************************************************
187
* Fill the specified material array with sphere centered at
188
* "xcenter", "ycenter", "zcenter" and radius of "radius" with
189
* the material "matno".
191
* Programmer: Eric Brugger
192
* Date: September 17, 2001
194
***********************************************************************/
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)
201
int i, j, k, l, m, n;
207
float xx[10], yy[10], zz[10];
211
itemp = ALLOC_N(int, (nx + 1) * (ny + 1) * (nz + 1));
213
for (i = 0; i < nx; i++)
215
for (j = 0; j < ny; j++)
217
for (k = 0; k < nz; k++)
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;
227
for (i = 0; i < nx; i++)
229
for (j = 0; j < ny; j++)
231
for (k = 0; k < nz; k++)
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];
247
matlist[i * nx * ny + j * nx + k] = matno;
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++)
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);
261
for (l = 0; l < 10; l++)
263
for (m = 0; m < 10; m++)
265
for (n = 0; n < 10; n++)
267
dist = sqrt((xx[l] - xcenter) *
273
cnt += (dist < radius) ? 1 : 0;
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.;
297
/***********************************************************************
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.
308
* nblocks = nblocks_x * nblocks_y * nblocks_z
310
* Programmer: Eric Brugger
311
* Date: September 17, 2001
314
* Mark C. Miller, Wed Jul 14 15:34:55 PDT 2010
315
* Added support for namescheme options on mulit-block objects.
316
***********************************************************************/
318
build_multi(char *basename, int driver, char *file_ext,
319
int nblocks_x, int nblocks_y, int nblocks_z)
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];
347
DBoptlist *optlist=NULL;
352
int nblocks = nblocks_x * nblocks_y * nblocks_z;
355
* Initialize the names and create the directories for the blocks.
357
for (i = 0; i < nblocks; i++)
362
filenum = i / (nblocks / NFILES);
365
sprintf(prefix, "multi_file.dir\\%03d\\%s%d.%s:/block%d/", filenum, basename, filenum, file_ext, i);
367
sprintf(prefix, "multi_file.dir/%03d/%s%d.%s:/block%d/", filenum, basename, filenum, file_ext, i);
370
sprintf(prefix, "%s%d.%s:/block%d/", basename, filenum, file_ext, i);
372
sprintf(names[i], "%smesh1", prefix);
373
meshnames[i] = names[i];
374
meshtypes[i] = DB_UCDMESH;
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;
388
sprintf(names0[i], "%smat1", prefix);
389
matnames[i] = names0[i];
393
* Create nameschemes for files and blocks within files
400
sprintf(file_ns, "|multi_file.dir\\%%03d\\%%s%%d.%%s|n/36|'%s'|n/36|'%s'", basename, file_ext);
402
sprintf(file_ns, "|multi_file.dir/%%03d/%%s%%d.%%s|n/36|'%s'|n/36|'%s'", basename, file_ext);
406
sprintf(file_ns, "|%%s%%d.%%s|'%s'|n/36|'%s'", basename, file_ext);
407
sprintf(block_ns, "|/block%%d/mesh1|n");
413
build_block_ucd3d(basename, driver, file_ext,
414
nblocks_x, nblocks_y, nblocks_z);
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)
423
fprintf(stderr, "Could not create '%s'.\n", filename);
428
* Create the option lists for the multi-block calls.
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);
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);
452
* Create the multi-block mesh, variables and material.
454
block_type = DB_UCDMESH;
455
if (DBPutMultimesh(dbfile, "mesh1", nblocks,
456
use_ns?0:meshnames, use_ns?0:meshtypes, optlist) == -1)
458
DBFreeOptlist(optlist);
459
fprintf(stderr, "Error creating multi mesh\n");
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)
467
DBFreeOptlist(optlist);
468
fprintf(stderr, "Error creating multi var d\n");
471
sprintf(block_ns, "|/block%%d/p|n");
472
if (DBPutMultivar(dbfile, "p", nblocks, use_ns?0:var2names, use_ns?0:vartypes, optlist)
475
DBFreeOptlist(optlist);
476
fprintf(stderr, "Error creating multi var p\n");
479
sprintf(block_ns, "|/block%%d/u|n");
480
if (DBPutMultivar(dbfile, "u", nblocks, use_ns?0:var3names, use_ns?0:vartypes, optlist)
483
DBFreeOptlist(optlist);
484
fprintf(stderr, "Error creating multi var u\n");
487
sprintf(block_ns, "|/block%%d/v|n");
488
if (DBPutMultivar(dbfile, "v", nblocks, use_ns?0:var4names, use_ns?0:vartypes, optlist)
491
DBFreeOptlist(optlist);
492
fprintf(stderr, "Error creating multi var v\n");
495
sprintf(block_ns, "|/block%%d/w|n");
496
if (DBPutMultivar(dbfile, "w", nblocks, use_ns?0:var5names, use_ns?0:vartypes, optlist)
499
DBFreeOptlist(optlist);
500
fprintf(stderr, "Error creating multi var w\n");
503
sprintf(block_ns, "|/block%%d/mat1|n");
504
if (DBPutMultimat(dbfile, "mat1", nblocks, use_ns?0:matnames, optlist) == -1)
506
DBFreeOptlist(optlist);
507
fprintf(stderr, "Error creating multi material\n");
510
DBFreeOptlist(optlist);
520
/***********************************************************************
522
* Build a 3-d UCD mesh and add it to the open database.
524
* Programmer: Eric Brugger
525
* Date: September 17, 2001
527
***********************************************************************/
529
build_block_ucd3d(char *basename, int driver, char *file_ext,
530
int nblocks_x, int nblocks_y, int nblocks_z)
538
float *x=NULL, *y=NULL, *z=NULL;
540
char *meshname=NULL, *var1name=NULL, *var2name=NULL,
541
*var3name=NULL, *var4name=NULL, *var5name=NULL;
545
float *d=NULL, *p=NULL, *u=NULL, *v=NULL, *w=NULL;
551
int *mix_next=NULL, *mix_mat=NULL, *mix_zone=NULL;
553
float *xstrip=NULL, *ystrip=NULL, *zstrip=NULL;
557
float xcenter, ycenter;
564
int delta_x, delta_y, delta_z;
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));
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));
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);
586
xstrip = ALLOC_N(float, nx+ny+nz);
587
ystrip = ALLOC_N(float, nx+ny+nz);
588
zstrip = ALLOC_N(float, nx+ny+nz);
591
* Create the coordinate arrays for the entire mesh.
593
dh = 20. / (float)nx;
594
dtheta = (180. / (float)ny) * (3.1415926 / 180.);
597
for (i = 0; i < nx + 1; i++)
600
for (j = 0; j < ny + 1; j++)
603
for (k = 0; k < nz + 1; k++)
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;
616
* Create the density and pressure arrays for the entire mesh.
620
for (i = 0; i < nx + 1; i++)
622
for (j = 0; j < ny + 1; j++)
624
for (k = 0; k < nz + 1; k++)
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);
637
* Create the velocity component arrays for the entire mesh.
641
for (i = 0; i < nx + 1; i++)
643
for (j = 0; j < ny + 1; j++)
645
for (k = 0; k < nz + 1; k++)
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.;
657
* Put in the material for the entire mesh.
659
fill_bkgr(matlist, nx, ny, nz, 1);
661
for (i = 0; i < ny; i++)
663
xstrip[i] = (float)i;
664
ystrip[i] = (float)i;
665
zstrip[i] = (float)i;
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.);
675
printf("memory overwrite: mixlen = %d > 85000\n", mixlen);
679
* Set up variables that are independent of the block number.
686
coordnames[0] = "xcoords";
687
coordnames[1] = "ycoords";
688
coordnames[2] = "zcoords";
703
* Now extract the data for this block.
705
delta_x = nx / nblocks_x;
706
delta_y = ny / nblocks_y;
707
delta_z = nz / nblocks_z;
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");
738
st = mkdir("multi_file.dir",S_IRWXU|S_IRWXG|S_IRWXU);
740
st = _mkdir("multi_file.dir");
744
fprintf(stderr, "Unable to mkdir(\"multi_file.dir\")\n");
747
fprintf(stdout, "\tMade directory multi_file.dir\n");
751
* Create the blocks for the multi-block object.
754
for (block = 0; block < nblocks_x * nblocks_y * nblocks_z; block++)
760
int imin, imax, jmin, jmax, kmin, kmax;
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;
776
int nfaces, nzones, nnodes;
777
int lfacelist, lzonelist;
778
int fshapesize, fshapecnt;
779
int zshapetype, zshapesize, zshapecnt;
786
DBoptlist *optlist=NULL;
790
sprintf(dirname, "/block%d", block);
791
filenum = block / ((nblocks_x * nblocks_y * nblocks_z) / NFILES);
793
sprintf(filename, "multi_file.dir/%03d/%s%d.%s", filenum, basename, filenum, file_ext);
795
sprintf(filename, "%s%d.%s", basename, filenum, file_ext);
797
fprintf(stdout, "\t%s:%s\n", filename, dirname);
800
* Now extract the data for this block.
802
imin = (block % nblocks_x) * delta_x - 1;
803
imax = MIN(imin + delta_x + 3, nx + 1);
806
jmin = ((block % (nblocks_x * nblocks_y)) / nblocks_x) * delta_y - 1;
807
jmax = MIN(jmin + delta_y + 3, ny + 1);
810
kmin = (block / (nblocks_x * nblocks_y)) * delta_z - 1;
811
kmax = MIN(kmin + delta_z + 3, nz + 1);
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));
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++)
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];
852
zonelist = ALLOC_N(int, (nnx-1)*(nny-1)*(nnz-1)*8);
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++)
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;
869
matlist2[k * (nnx - 1) * (nny - 1) + j * (nnx - 1) + i] =
870
matlist[n_z * nx * ny + n_y * nx + n_x];
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;
880
ghost[k * (nnx-1) * (nny-1) + j * (nnx-1) + i] = 0;
884
* Resort the zonelist, matlist so that the ghost zones are at the
887
nzones = (nnx - 1) * (nny - 1) * (nnz - 1);
889
for (i = 0; i < nzones; i++)
892
for (i = 0; i < nreal; i++)
897
* Find the first non ghost zone.
899
while (ghost[ighost] == 1)
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;
929
matlist2[i] = matlist2[j];
939
* Calculate the external face list.
941
nnodes = nnx * nny * nnz;
942
hi_off = nzones - nreal;
946
zshapetype = DB_ZONETYPE_HEX;
947
lzonelist = nzones * 8;
949
fl = DBCalcExternalFacelist2(zonelist, nnodes, 0, hi_off, 0,
950
&zshapetype, &zshapesize, &zshapecnt, 1,
953
facelist = ALLOC_N(int, fl->lnodelist);
954
zoneno = ALLOC_N(int, fl->nfaces);
957
fshapecnt = fl->nfaces;
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];
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.
972
if (block % ((nblocks_x * nblocks_y * nblocks_z) / NFILES) == 0)
978
sprintf(dname, "multi_file.dir/%03d", filenum);
980
st = mkdir(dname, S_IRWXU|S_IRWXG|S_IRWXU);
986
fprintf(stderr, "Unable to make directory \"%s\"\n", dname);
989
fprintf(stdout, "\tMade directory %s\n", dname);
992
if ((dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL,
993
"multi-file ucd 3d test file", driver)) == NULL)
995
fprintf(stderr, "Could not create '%s'.\n", filename);
1001
if ((dbfile = DBOpen(filename, driver, DB_APPEND)) == NULL)
1003
fprintf(stderr, "Could not open '%s'.\n", filename);
1009
* Make the directory for the block and cd into it.
1011
if (DBMkDir(dbfile, dirname) == -1)
1013
fprintf(stderr, "Could not make directory \"%s\"\n", dirname);
1016
if (DBSetDir(dbfile, dirname) == -1)
1018
fprintf(stderr, "Could not set directory \"%s\"\n", dirname);
1023
* Write out the mesh and variables.
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);
1038
DBPutFacelist(dbfile, "fl1", nfaces, 3, facelist, lfacelist, 0,
1039
zoneno, &fshapesize, &fshapecnt, 1, NULL, NULL, 0);
1041
DBPutZonelist2(dbfile, "zl1", nzones, 3, zonelist, lzonelist, 0,
1042
0, hi_off, &zshapetype, &zshapesize, &zshapecnt, 1, 0);
1045
* Output the rest of the mesh and variables.
1048
DBPutUcdmesh(dbfile, meshname, 3, coordnames, coords,
1049
nnodes, nzones, "zl1", "fl1", DB_FLOAT, optlist);
1051
DBPutUcdmesh(dbfile, meshname, 3, coordnames, coords,
1052
nnodes, nzones, "zl1", NULL, DB_FLOAT, optlist);
1055
varnames[0] = var1name;
1056
DBPutUcdvar(dbfile, var1name, meshname, 1, varnames, vars,
1057
nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, optlist);
1060
varnames[0] = var2name;
1061
DBPutUcdvar(dbfile, var2name, meshname, 1, varnames, vars,
1062
nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, optlist);
1065
varnames[0] = var3name;
1066
DBPutUcdvar(dbfile, var3name, meshname, 1, varnames, vars,
1067
nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, optlist);
1070
varnames[0] = var4name;
1071
DBPutUcdvar(dbfile, var4name, meshname, 1, varnames, vars,
1072
nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, optlist);
1075
varnames[0] = var5name;
1076
DBPutUcdvar(dbfile, var5name, meshname, 1, varnames, vars,
1077
nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, optlist);
1079
DBPutMaterial(dbfile, matname, meshname, nmats, matnos,
1080
matlist2, &nzones, 1, mix_next, mix_mat, mix_zone,
1081
mix_vf, mixlen, DB_FLOAT, optlist);
1083
DBFreeOptlist(optlist);