int main(int argc, char *argv[]) { int nnodes = NNODES; int nzones = NZONES; int nodelist[23]; int shapesize[] = {8, 4, 5, 6}; int shapecnt[] = {1, 1, 1, 1}; char mesh_command[256]; int len; char *filename = "alltypes.silo"; int driver = DB_PDB; DBfile *dbfile = NULL; int ndims = NDIMS; int dims[NDIMS]; double *coords[NDIMS]; double x[NNODES]; double y[NNODES]; double z[NNODES]; DBfacelist *facelist = NULL; double nodal[NNODES]; double zonal[NZONES]; int matlist[NZONES]; int mats[] = {1,2,3,4}; int i,j; const int origin = 0; int show_all_errors = FALSE; /* Parse command-line options */ for (i=1; i<argc; i++) { if (!strncmp(argv[i], "DB_PDB",6)) { driver = StringToDriver(argv[i]); filename = "alltypes.pdb"; } else if (!strncmp(argv[i], "DB_HDF5", 7)) { driver = StringToDriver(argv[i]); filename = "alltypes.h5"; } else if (!strcmp(argv[i], "show-all-errors")) { show_all_errors = 1; } else if (argv[i][0] != '\0') { fprintf(stderr, "unknown option: %s\n", argv[i]); exit(1); } } /* Turn on error handling */ DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_ABORT, NULL); DBSetFriendlyHDF5Names(2); /* Create file */ printf("Creating test file \"%s\".\n", filename); dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL, "3D ucd", driver); i = 0; /* 0 */ x[i] = 0.5; y[i] = 1.0; z[i++] = 0.0; /* 1 */ x[i] = 1.5; y[i] = 1.0; z[i++] = 0.0; /* 2 */ x[i] = 1.5; y[i] = 1.0; z[i++] = 1.0; /* 3 */ x[i] = 0.5; y[i] = 1.0; z[i++] = 1.0; /* 4 */ x[i] = 0.5; y[i] = 2.0; z[i++] = 0.0; /* 5 */ x[i] = 1.5; y[i] = 2.0; z[i++] = 0.0; /* 6 */ x[i] = 2.5; y[i] = 2.0; z[i++] = 0.0; /* 7 */ x[i] = 2.5; y[i] = 2.0; z[i++] = 1.0; /* 8 */ x[i] = 1.5; y[i] = 2.0; z[i++] = 1.0; /* 9 */ x[i] = 0.5; y[i] = 2.0; z[i++] = 1.0; /* 10 */ x[i] = 0.0; y[i] = 3.0; z[i++] = 0.5; /* 11 */ x[i] = 1.0; y[i] = 3.0; z[i++] = 0.5; /* 12 */ x[i] = 2.0; y[i] = 3.0; z[i++] = 0.5; coords[0] = x; coords[1] = y; coords[2] = z; DBPutUcdmesh(dbfile, "mesh", 3, NULL, (void *)coords, nnodes, nzones, "zonelist", "facelist", DB_DOUBLE, NULL); i = 0; /* Hex */ nodelist[i++] = 4; nodelist[i++] = 5; nodelist[i++] = 8; nodelist[i++] = 9; nodelist[i++] = 0; nodelist[i++] = 1; nodelist[i++] = 2; nodelist[i++] = 3; /* Tet */ nodelist[i++] = 10; nodelist[i++] = 4; nodelist[i++] = 11; nodelist[i++] = 9; /* Pyramid */ nodelist[i++] = 4; nodelist[i++] = 5; nodelist[i++] = 8; nodelist[i++] = 9; nodelist[i++] = 11; /* Prism */ nodelist[i++] = 5; nodelist[i++] = 6; nodelist[i++] = 7; nodelist[i++] = 8; nodelist[i++] = 11; nodelist[i++] = 12; for (j=0; j<i; j++) nodelist[j] += origin; DBSetDeprecateWarnings(0); DBPutZonelist(dbfile, "zonelist", nzones, ndims, nodelist, 23, origin, shapesize, shapecnt, 4); DBSetDeprecateWarnings(3); facelist = DBCalcExternalFacelist(nodelist, nnodes, origin, shapesize, shapecnt, 4, NULL, 0); DBPutFacelist(dbfile, "facelist", facelist->nfaces, facelist->ndims, facelist->nodelist, facelist->lnodelist, facelist->origin, facelist->zoneno, facelist->shapesize, facelist->shapecnt, facelist->nshapes, facelist->types, facelist->typelist, facelist->ntypes); for(i=0;i<nnodes;i++) nodal[i] = x[i]; zonal[0] = 4.0; zonal[1] = 2.0; zonal[2] = 0.0; zonal[3] = 7.0; DBPutUcdvar1(dbfile, "nodal", "mesh", (void*)nodal, nnodes, NULL, 0, DB_DOUBLE, DB_NODECENT, NULL); DBPutUcdvar1(dbfile, "zonal", "mesh", (void*)zonal, nzones, NULL, 0, DB_DOUBLE, DB_ZONECENT, NULL); matlist[0] = 1; matlist[1] = 2; matlist[2] = 3; matlist[3] = 4; dims[0] = nzones; DBPutMaterial(dbfile, "mat", "mesh", 4, mats, matlist, dims, 1, NULL, NULL, NULL, NULL, 0, DB_DOUBLE, NULL); sprintf(mesh_command, "mesh mesh"); len = strlen(mesh_command) + 1; DBWrite(dbfile, "_meshtvinfo", mesh_command, &len, 1, DB_CHAR); DBClose(dbfile); DBFreeFacelist(facelist); CleanupDriverStuff(); return 0; }
/*---------------------------------------------------------------------- * Routine build_ucd3 * * Purpose * * Build in 3D a ucd-mesh, ucd-var, facelist and zonelist, and return * the mesh ID. * * Arguments * name Name to assign mesh. * * Modifications * * Lisa J. Roberts, Fri Apr 7 09:35:52 PDT 2000 * Changed the prototype to ANSI standard and explicitly indicated * the function returns an int. Got rid of flid, zlid, varid, i, * dfnew, dbid, ln, and matid, which were unused. * *--------------------------------------------------------------------*/ int build_ucd3(DBfile *dbfile, char *name) { #undef NZONES #define NZONES 3 #undef NFACES #define NFACES 14 #undef NNODES #define NNODES 16 #undef MAXMIX #define MAXMIX 12 #undef MAXOMIX #define MAXOMIX 4 #undef NZSHAPES #define NZSHAPES 1 #undef NFSHAPES #define NFSHAPES 1 #undef NFTYPES #define NFTYPES 0 #undef LZNODELIST #define LZNODELIST 24 #undef LFNODELIST #define LFNODELIST 56 /*---------------------------------------------------------------------- The test mesh looks like this: *---------------------------------------------------------------------*/ int meshid; static float x[NNODES] = {0., 1., 1., 0., 0., 1., 1., 0., 0., 1., 1., 0., 0., 1., 1., 0.}; static float y[NNODES] = {0., 0., 0., 0., 1., 1., 1., 1., 2., 2., 2., 2., 3., 3., 3., 3.}; static float z[NNODES] = {0., 0., 1., 1., 0., 0., 1., 1., 0., 0., 1., 1., 0., 0., 1., 1.}; static float u[NNODES] = {0., 0., 0., 0., .1, .1, .1, .1, .2, .2, .2, .2, .3, .3, .3, .3}; static float v[NNODES] = {0., 0., 0., 0., .1, .1, .1, .1, .2, .2, .2, .2, .3, .3, .3, .3}; static float w[NNODES] = {0., 0., 0., 0., .1, .1, .1, .1, .2, .2, .2, .2, .3, .3, .3, .3}; static float d[NZONES] = {2., 4., 6.}; #if 0 static float df[MAXOMIX] = {.58, .78, .42, .22}; static float vf[MAXOMIX] = {.4, .45, .6, .55}; #endif static int matlist[NZONES] = {1, 1, 2}; static int matnos[2] = {1, 2}; #if 0 static int fzoneno[NFACES]; static int fnodelist[LFNODELIST] = {0, 1, 5, 4, 1, 2, 6, 5, 3, 2, 7, 6, 3, 0, 4, 7, 4, 5, 9, 8, 6, 5, 9, 10, 7, 6, 10, 11, 4, 7, 11, 8, 8, 9, 13, 12, 10, 9, 13, 14, 11, 10, 14, 15, 11, 15, 12, 8, 0, 1, 2, 3, 12, 13, 14, 15}; #endif static int znodelist[LZNODELIST] = {0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 8, 9, 10, 11, 8, 9, 10, 11, 12, 13, 14, 15}; #if 0 int fshapesize, fshapecnt; #endif int zshapesize, zshapecnt; int idatatype; int dims; #if 0 double ttime = 2.345; int tcycle = 200; int mixlen = MAXMIX; #endif float *coords[3], *vars[3]; char *coordnames[3], *varnames[3]; DBfacelist *fl; #if 0 int inode, iface, izone, ifl, izl; int nface = 0; #endif int inode, izone, izl; #if 0 fshapesize = 4; fshapecnt = NFACES; #endif zshapesize = 8; zshapecnt = NZONES; idatatype = DB_FLOAT; dims = NZONES; coords[0] = x; coords[1] = y; coords[2] = z; coordnames[0] = "X"; coordnames[1] = "Y"; coordnames[2] = "Z"; vars[0] = d; varnames[0] = "d"; inode = 0; for (izone = 0; izone == NZONES; izone++) { x[inode++] = 0.; x[inode++] = 1.; x[inode++] = 1.; x[inode++] = 0.; inode -= 4; y[inode++] = (float)izone; y[inode++] = (float)izone; y[inode++] = (float)izone; y[inode++] = (float)izone; inode -= 4; z[inode++] = 0.; z[inode++] = 0.; z[inode++] = 1.; z[inode++] = 1.; } izl = 0; for (izone = 0; izone < NZONES; izone++) { for (inode = 0; inode < 4; inode++) { znodelist[izl++] = izone * 4 + inode; } for (inode = 0; inode < 4; inode++) { znodelist[izl++] = (izone + 1) * 4 + inode; } } #if 0 ifl = 0; for (izone = 0; izone < NZONES; izone++) { for (iface = 0; iface < 3; iface++) { fnodelist[ifl++] = izone * 4 + iface; fnodelist[ifl++] = izone * 4 + iface + 1; fnodelist[ifl++] = izone * 4 + iface + 5; fnodelist[ifl++] = izone * 4 + iface + 4; } fnodelist[ifl++] = izone * 4 + 3; fnodelist[ifl++] = izone * 4; fnodelist[ifl++] = izone * 4 + 4; fnodelist[ifl++] = izone * 4 + 7; for (iface = 0; iface < 4; iface++) fzoneno[nface++] = izone; } fnodelist[ifl++] = 0; fnodelist[ifl++] = 1; fnodelist[ifl++] = 2; fnodelist[ifl++] = 3; fzoneno[nface++] = 0; fnodelist[ifl++] = 12; fnodelist[ifl++] = 13; fnodelist[ifl++] = 14; fnodelist[ifl++] = 15; fzoneno[nface++] = NZONES - 1; #endif /* Last parameter was added by Sean Ahern - * Tue Aug 30 17:55:22 PDT 1994 * It is the boundary method. Arbitraryily chosen as 0 */ fl = (DBfacelist *) DBCalcExternalFacelist(znodelist, NNODES, 1, &zshapesize, &zshapecnt, NZSHAPES, matlist, 0); (void)DBPutFacelist(dbfile, "fl", fl->nfaces, 3, fl->nodelist, fl->lnodelist, 0, fl->zoneno, fl->shapesize, fl->shapecnt, fl->nshapes, NULL, NULL, 0); /* * flid = DBPutFacelist (dbfile, "fl", NFACES, 3, fnodelist, LFNODELIST, 0, * fzoneno, &fshapesize, &fshapecnt, NFSHAPES, * NULL, NULL, 0); */ (void)DBPutZonelist(dbfile, "zl", NZONES, 3, znodelist, LZNODELIST, 0, &zshapesize, &zshapecnt, NZSHAPES); meshid = DBPutUcdmesh(dbfile, name, 3, coordnames, coords, NNODES, NZONES, "zl", "fl", DB_FLOAT, NULL); (void)DBPutMaterial(dbfile, "material", name, 2, matnos, matlist, &dims, 1, NULL, NULL, NULL, NULL, 0, DB_FLOAT, NULL); vars[0] = d; varnames[0] = "d"; (void)DBPutUcdvar(dbfile, varnames[0], name, 1, varnames, vars, NZONES, NULL, 0, idatatype, DB_ZONECENT, NULL); vars[0] = u; varnames[0] = "u"; (void)DBPutUcdvar(dbfile, varnames[0], name, 1, varnames, vars, NNODES, NULL, 0, idatatype, DB_NODECENT, NULL); vars[0] = v; varnames[0] = "v"; (void)DBPutUcdvar(dbfile, varnames[0], name, 1, varnames, vars, NNODES, NULL, 0, idatatype, DB_NODECENT, NULL); vars[0] = w; varnames[0] = "w"; (void)DBPutUcdvar(dbfile, varnames[0], name, 1, varnames, vars, NNODES, NULL, 0, idatatype, DB_NODECENT, NULL); vars[0] = u; varnames[0] = "ucomp"; vars[1] = v; varnames[1] = "vcomp"; vars[2] = w; varnames[2] = "wcomp"; (void)DBPutUcdvar(dbfile, "velocity", name, 3, varnames, vars, NNODES, NULL, 0, idatatype, DB_NODECENT, NULL); return (meshid); }
/*---------------------------------------------------------------------- * Routine build_ucd3 * * Purpose * * Build a 3D ucd-mesh, ucd-var, facelist and zonelist, and return * the mesh ID. * * Arguments * name Name to assign mesh. * * Modifications * * Lisa J. Roberts, Fri Apr 7 10:48:31 PDT 2000 * Changed the prototype to ANSI standard and explicitly indicated * the function returns an int. Got rid of flid, zlid, varid, i, * ln, dbid, and matid, which were unused. * *--------------------------------------------------------------------*/ static int build_ucd3(DBfile *dbfile, char *name) { #define NZONES 3 /* Number of zones (elements) */ #define NFACES 14 /* Number of external faces */ #define NNODES 16 /* Number of mesh nodes */ #define NZSHAPES 1 /* Number of zone shapes */ #define NFSHAPES 1 /* Number of face shapes */ #define NFTYPES 0 /* Number of face types */ #define LZNODELIST 24 /* Length of zonelist nodelist */ #define LFNODELIST 56 /* Length of facelist nodelist */ /* Misc variables */ int meshid; int fshapesize, fshapecnt, zshapesize, zshapecnt; int idatatype; int dims; int inode, iface, izone, ifl, izl, nface = 0; #if 0 int mixlen = 0; int tcycle = 200; double ttime = 2.345; float *vars[3]; char *varnames[3]; DBfacelist *fl; #endif float *coords[3]; char *coordnames[3]; /* Coordinates */ float x[NNODES]; float y[NNODES]; float z[NNODES]; /* Nodal quantities */ static float u[NNODES] = {0., 0., 0., 0., .1, .1, .1, .1, .2, .2, .2, .2, .3, .3, .3, .3}; #if 0 static float v[NNODES] = {0., 0., 0., 0., .1, .1, .1, .1, .2, .2, .2, .2, .3, .3, .3, .3}; static float w[NNODES] = {0., 0., 0., 0., .1, .1, .1, .1, .2, .2, .2, .2, .3, .3, .3, .3}; #endif /* Zonal quantities */ static float d[NZONES] = {2., 4., 6.}; /* Material data */ static int matlist[NZONES] = {1, 1, 2}; static int matnos[2] = {1, 2}; /* Facelist data */ int fzoneno[NFACES]; int fnodelist[LFNODELIST]; /* Zonelist data */ int znodelist[LZNODELIST]; fshapesize = 4; fshapecnt = NFACES; zshapesize = 8; zshapecnt = NZONES; idatatype = DB_FLOAT; dims = NZONES; /*-------------------------------------------------- * Compute coordinate values, zonelist values, and * facelist values for a sample 3D mesh. *-------------------------------------------------*/ inode = 0; for (izone = 0; izone <= NZONES; izone++) { x[inode++] = 0.; x[inode++] = 1.; x[inode++] = 1.; x[inode++] = 0.; inode -= 4; y[inode++] = (float)izone; y[inode++] = (float)izone; y[inode++] = (float)izone; y[inode++] = (float)izone; inode -= 4; z[inode++] = 0.; z[inode++] = 0.; z[inode++] = 1.; z[inode++] = 1.; } izl = 0; for (izone = 0; izone < NZONES; izone++) { for (inode = 0; inode < 4; inode++) { znodelist[izl++] = izone * 4 + inode; } for (inode = 0; inode < 4; inode++) { znodelist[izl++] = (izone + 1) * 4 + inode; } } ifl = 0; for (izone = 0; izone < NZONES; izone++) { for (iface = 0; iface < 3; iface++) { fnodelist[ifl++] = izone * 4 + iface; fnodelist[ifl++] = izone * 4 + iface + 1; fnodelist[ifl++] = izone * 4 + iface + 5; fnodelist[ifl++] = izone * 4 + iface + 4; } fnodelist[ifl++] = izone * 4 + 3; fnodelist[ifl++] = izone * 4; fnodelist[ifl++] = izone * 4 + 4; fnodelist[ifl++] = izone * 4 + 7; for (iface = 0; iface < 4; iface++) fzoneno[nface++] = izone; } fnodelist[ifl++] = 0; fnodelist[ifl++] = 1; fnodelist[ifl++] = 2; fnodelist[ifl++] = 3; fzoneno[nface++] = 0; fnodelist[ifl++] = 12; fnodelist[ifl++] = 13; fnodelist[ifl++] = 14; fnodelist[ifl++] = 15; fzoneno[nface++] = NZONES - 1; #if 1 /*-------------------------------------------------- * Write out the external facelist we defined * above. *-------------------------------------------------*/ DBPutFacelist(dbfile, "fl", NFACES, 3, fnodelist, LFNODELIST, 0, fzoneno, &fshapesize, &fshapecnt, NFSHAPES, NULL, NULL, 0); #else /*-------------------------------------------------- * Calculate an external facelist from the zonelist * information. Write it out. *-------------------------------------------------*/ fl = (DBfacelist *) DBCalcExternalFacelist(znodelist, NNODES, 0, &zshapesize, &zshapecnt, NZSHAPES, matlist, 2); DBPutFacelist(dbfile, "fl", fl->nfaces, 3, fl->nodelist, fl->lnodelist, 0, fl->zoneno, fl->shapesize, fl->shapecnt, fl->nshapes, NULL, NULL, 0); #endif /*-------------------------------------------------- * Write out the zonelist. *-------------------------------------------------*/ DBSetDeprecateWarnings(0); DBPutZonelist(dbfile, "zl", NZONES, 3, znodelist, LZNODELIST, 0, &zshapesize, &zshapecnt, NZSHAPES); DBSetDeprecateWarnings(3); /*-------------------------------------------------- * Write out the mesh. *-------------------------------------------------*/ coords[0] = x; coords[1] = y; coords[2] = z; coordnames[0] = "X"; coordnames[1] = "Y"; coordnames[2] = "Z"; meshid = DBPutUcdmesh(dbfile, name, 3, (DBCAS_t) coordnames, coords, NNODES, NZONES, "zl", "fl", DB_FLOAT, NULL); /*-------------------------------------------------- * Write out the material data. *-------------------------------------------------*/ DBPutMaterial(dbfile, "material", name, 2, matnos, matlist, &dims, 1, NULL, NULL, NULL, NULL, 0, DB_FLOAT, NULL); /*-------------------------------------------------- * Write out a zonal variable. *-------------------------------------------------*/ DBPutUcdvar1(dbfile, "d", name, d, NZONES, NULL, 0, idatatype, DB_ZONECENT, NULL); /*-------------------------------------------------- * Write out a nodal variable. *-------------------------------------------------*/ DBPutUcdvar1(dbfile, "u", name, u, NNODES, NULL, 0, idatatype, DB_NODECENT, NULL); return (meshid); }