void write_multivar(DBfile *dbfile, double extents[4][2]) { char **varnames = NULL; int dom, nvar = 4, two = 2, *vartypes = NULL; DBoptlist *optlist = NULL; /* Create the list of var names. */ varnames = (char **)malloc(nvar * sizeof(char *)); for(dom = 0; dom < nvar; ++dom) { char tmp[100]; sprintf(tmp, "dataextents.%d:var", dom); varnames[dom] = strdup(tmp); } /* Create the list of var types. */ vartypes = (int *)malloc(nvar * sizeof(int)); for(dom = 0; dom < nvar; ++dom) vartypes[dom] = DB_QUADVAR; /* Write the multivar. */ optlist = DBMakeOptlist(2); DBAddOption(optlist, DBOPT_EXTENTS_SIZE, (void *)&two); DBAddOption(optlist, DBOPT_EXTENTS, (void *)extents); DBPutMultivar(dbfile, "var", nvar, (DBCAS_t)varnames, vartypes, optlist); DBFreeOptlist(optlist); /* Free the memory*/ for(dom = 0; dom < nvar; ++dom) free(varnames[dom]); free(varnames); free(vartypes); }
virtual void WriteMasterFile(const bool *domainsHaveData) { std::string filename(MasterFile()); DBfile *dbfile = DBCreate(filename.c_str(), DB_CLOBBER, DB_LOCAL, "3D point mesh", DB_HDF5); if(dbfile == NULL) { fprintf(stderr, "Could not create master Silo file!\n"); return; } // Create an option list for saving cycle and time values. DBoptlist *optlist = DBMakeOptlist(2); DBAddOption(optlist, DBOPT_CYCLE, (void *)&cycle); DBAddOption(optlist, DBOPT_DTIME, (void *)&time); const char *snames[] = {"pointmesh", "vx", "vy", "vz", "restitution", "mass", "dom", "contact"}; const int svartypes[] = {DB_POINTMESH, DB_POINTVAR, DB_POINTVAR, DB_POINTVAR, DB_POINTVAR, DB_POINTVAR, DB_POINTVAR, DB_POINTVAR}; const bool isMesh[] = {true, false, false, false, false, false, false, false}; for(size_t i = 0; i < (sizeof(snames)/sizeof(const char*)); ++i) { std::vector<std::string> names; for(int d = 0; d < nDomains; ++d) { std::string domName("EMPTY"); if(domainsHaveData[d]) domName = (DomainFile(d) + ":") + snames[i]; names.push_back(domName); } char **varnames = new char *[nDomains]; int *vartypes = new int[nDomains]; for(int d = 0; d < nDomains; ++d) { varnames[d] = (char*)names[d].c_str(); vartypes[d] = svartypes[i]; } if(isMesh[i]) DBPutMultimesh(dbfile, snames[i], nDomains, varnames, vartypes, optlist); else DBPutMultivar(dbfile, snames[i], nDomains, varnames, vartypes, optlist); } const char *names[] = {"velocity", "speed", "ID"}; const char *defs[] = {"{vx,vy,vz}", "magnitude(velocity)", "global_nodeid(pointmesh)"}; int types[] = {DB_VARTYPE_VECTOR, DB_VARTYPE_SCALAR, DB_VARTYPE_SCALAR}; DBPutDefvars(dbfile, "defvars", 3, (char**)names, types, (char**)defs, NULL); DBFreeOptlist(optlist); DBClose(dbfile); }
void SubMesh_wtroot ( DBfile *idbid, DBoptlist *ioptnod, char **rootnames ) { char *me = "SubMesh_wtroot"; int i,j,k,n; int len; int gblk; int nw = 0; int *tag; int error = 0; char name[MAXLINE]; char msg[MAXLINE]; UserList_t *ul; SubMesh_t *subm; HashElm_t **hashelm; NodeWindow_t *ndxin; char **meshnames; int *meshtypes; int *vartypes; hashelm = hash_get_elm_list(&n, "SubMesh_t", gv_hash_tbl); if (n == 0) { FREEMEM(hashelm); return; } tag = MALLOT(int, gnblk); for (j = 0; j < n; j++) { subm = (SubMesh_t *) hashelm[j]->obj; sprintf(name,"SubMesh_%s",subm->name); nw = 0; for (gblk = 0; gblk < gnblk; gblk++) { Extents_t ext1, ext2, ext3; tag[gblk] = 0; CPYEXT(ext2,gmap[gblk]); ndxin = subm->ndxin; while (ndxin != NULL) { if (gmap[gblk].ublk == ndxin->ublk) { CPYEXT(ext1,(*ndxin)); len = extents_overlap(&ext2, &ext1, &ext3); if (len > 0) tag[gblk]++; } ndxin = ndxin->next; } nw = nw + tag[gblk]; } meshtypes = MALLOT(int, nw); vartypes = MALLOT(int, nw); meshnames = MALLOT(char *, nw); for (i = 0; i < nw; i++) { meshtypes[i] = 0; vartypes[i] = 0; } i = 0; for(gblk = 0; gblk < gnblk; gblk++){ if (tag[gblk] > 0) { for(k=0; k < tag[gblk]; k++){ if(subm->type == 0){ sprintf(msg,"%s/SubMesh_%s",rootnames[gblk],subm->name); meshtypes[i] = DB_POINTMESH; vartypes[i] = DB_POINTVAR; } else{ sprintf(msg,"%s/SubMesh_%s_%d",rootnames[gblk],subm->name, k); meshtypes[i] = DB_QUADMESH; vartypes[i] = DB_QUADVAR; } meshnames[i] = strsave(msg); i++; } } } if (i > 0) { error += DBPutMultimesh(idbid, name, i, meshnames, meshtypes, ioptnod); } ul = UserList_find(name); while (ul != NULL) { i = 0; for (gblk = 0; gblk < gnblk; gblk++) { if (tag[gblk] > 0) { for(k=0; k < tag[gblk]; k++){ FREEMEM(meshnames[i]); if(subm->type == 0){ sprintf(msg,"%s/SubMesh_%s_%s",rootnames[gblk],subm->name, ul->name); } else{ sprintf(msg,"%s/SubMesh_%s_%s_%d",rootnames[gblk],subm->name, ul->name, k); } meshnames[i] = strsave(msg); i++; } } } if (i > 0) { char varn[MAXLINE]; sprintf(varn,"SubMesh_%s_%s",subm->name, ul->name); error += DBPutMultivar(idbid, varn, i, meshnames, vartypes, ioptnod); } ul = ul->next; } for(gblk = 0; gblk < gnblk; gblk++){ if (tag[gblk] > 0){ for(i = 0; i < tag[gblk]; i++){ FREEMEM(meshnames[i]); } } } } if (error != 0) { ctlwarning(me,"Error writing out sub mesh root info."); } FREEMEM(hashelm); FREEMEM(tag); FREEMEM(meshnames); FREEMEM(vartypes); FREEMEM(meshtypes); }
/*------------------------------------------------------------------------- * Function: build_dbfile * * Purpose: Make a multi-block mesh, multi-block variables, and a * multi-block material * * Return: Success: 0 * Failure: -1 * * Programmer: Jeremy Meredith, Sept 29, 1998 * * Modifications: * *------------------------------------------------------------------------*/ int build_dbfile(DBfile *dbfile) { /* multiblock data */ int nblocks_x=5; int nblocks_y=1; int nblocks = nblocks_x * nblocks_y; char *meshnames[MAXBLOCKS]; int meshtypes[MAXBLOCKS]; char names[7][MAXBLOCKS][STRLEN]; char *varnames[4][MAXBLOCKS]; int vartypes[MAXBLOCKS]; char *matnames[MAXBLOCKS]; char *specnames[MAXBLOCKS]; char dirnames[MAXBLOCKS][STRLEN]; char *meshname, *varname[4], *matname; /* mesh data */ int meshtype=DB_QUADMESH; int vartype=DB_QUADVAR; int coord_type=DB_NONCOLLINEAR; char *coordnames[3]; int ndims; int dims[3], zdims[3]; float *coords[3]; float x[(NX + 1) * (NY + 1)], y[(NX + 1) * (NY + 1)]; /* variables data */ float d[NX * NY], p[NX * NY], u[(NX + 1) * (NY + 1)], v[(NX + 1) * (NY + 1)]; int usespecmf=1; /* (multi)material data */ int nmats; int matnos[3]; int matlist[NX * NY]; /* (multi)species data */ char *specname; int speclist[NX*NY],speclist2[NX*NY]; float species_mf[NX*NY*5]; int nspecies_mf; int nmatspec[3]; /* time data */ int cycle; float time; double dtime; /* option list */ DBoptlist *optlist; /* internal data */ int i, j; float xave, yave; float xcenter, ycenter; float theta, dtheta; float r, dr; float dist; int block; int delta_x, delta_y; int base_x, base_y; int n_x, n_y; /* single block data */ float x2[(NX + 1) * (NY + 1)], y2[(NX + 1) * (NY + 1)]; float d2[NX * NY], p2[NX * NY], u2[(NX + 1) * (NY + 1)], v2[(NX + 1) * (NY + 1)]; int matlist2[NX * NY]; int dims2[3]; /* * Initialize the names and create the directories for the blocks. */ for (i = 0; i < nblocks; i++) { sprintf(names[6][i], "/block%d/mesh1", i); meshnames[i] = names[6][i]; meshtypes[i] = meshtype; sprintf(names[0][i], "/block%d/d", i); sprintf(names[1][i], "/block%d/p", i); sprintf(names[2][i], "/block%d/u", i); sprintf(names[3][i], "/block%d/v", i); varnames[0][i] = names[0][i]; varnames[1][i] = names[1][i]; varnames[2][i] = names[2][i]; varnames[3][i] = names[3][i]; vartypes[i] = vartype; sprintf(names[4][i], "/block%d/mat1", i); matnames[i] = names[4][i]; sprintf(names[5][i], "/block%d/species1",i); specnames[i]= names[5][i]; /* make the directory for the block mesh */ sprintf(dirnames[i], "/block%d", i); if (DBMkDir(dbfile, dirnames[i]) == -1) { fprintf(stderr, "Could not make directory \"%s\"\n", dirnames[i]); return (-1); } /* if */ } /* for */ /* * Initalize species info */ specname = "species1"; nmatspec[0]=3; nmatspec[1]=1; nmatspec[2]=2; /* * Initialize time info */ cycle = 48; time = 4.8; dtime = 4.8; /* * Create the mesh. */ meshname = "mesh1"; coordnames[0] = "xcoords"; coordnames[1] = "ycoords"; coordnames[2] = "zcoords"; coords[0] = x; coords[1] = y; ndims = 2; dims[0] = NX + 1; dims[1] = NY + 1; dtheta = (180. / NX) * (3.1415926 / 180.); dr = 3. / NY; theta = 0; for (i = 0; i < NX + 1; i++) { r = 2.; for (j = 0; j < NY + 1; j++) { x[j * (NX + 1) + i] = r * cos(theta); y[j * (NX + 1) + i] = r * sin(theta); r += dr; } theta += dtheta; } /* * Create the density and pressure arrays. */ varname[0] = "d"; varname[1] = "p"; xcenter = 0.; ycenter = 0.; zdims[0] = NX; zdims[1] = NY; for (i = 0; i < NX; i++) { for (j = 0; j < NY; j++) { xave = (x[(j) * (NX + 1) + i] + x[(j) * (NX + 1) + i + 1] + x[(j + 1) * (NX + 1) + i + 1] + x[(j + 1) * (NX + 1) + i]) / 4.; yave = (y[(j) * (NX + 1) + i] + y[(j) * (NX + 1) + i + 1] + y[(j + 1) * (NX + 1) + i + 1] + y[(j + 1) * (NX + 1) + i]) / 4.; dist = sqrt((xave - xcenter) * (xave - xcenter) + (yave - ycenter) * (yave - ycenter)); d[j * NX + i] = dist*((float)i/(float)NX); p[j * NX + i] = 1. / (dist + .0001); } } /* * Create the velocity component arrays. Note that the indexing * on the x and y coordinates is for rectilinear meshes. It * generates a nice vector field. */ varname[2] = "u"; varname[3] = "v"; xcenter = 0.; ycenter = 0.; for (i = 0; i < NX + 1; i++) { for (j = 0; j < NY + 1; j++) { dist = sqrt((x[i] - xcenter) * (x[i] - xcenter) + (y[j] - ycenter) * (y[j] - ycenter)); u[j * (NX + 1) + i] = (x[i] - xcenter) / dist; v[j * (NX + 1) + i] = (y[j] - ycenter) / dist; } } /* * Create the material array. */ matname = "mat1"; nmats = 3; matnos[0] = 1; matnos[1] = 2; matnos[2] = 3; dims2[0] = NX; dims2[1] = NY; /* * Put in the material in 3 shells. */ nspecies_mf=0; for (i = 0; i < NX; i++) { for (j = 0; j < 10; j++) { matlist[j * NX + i] = 1; speclist[j*NX+i]=nspecies_mf+1; if (i<10) { species_mf[nspecies_mf++]=.2; species_mf[nspecies_mf++]=.3; species_mf[nspecies_mf++]=.5; } else { species_mf[nspecies_mf++]=.9; species_mf[nspecies_mf++]=.1; species_mf[nspecies_mf++]=.0; } } for (j = 10; j < 20; j++) { matlist[j * NX + i] = 2; speclist[j*NX+i]=nspecies_mf+1; species_mf[nspecies_mf++]=1.; } for (j = 20; j < NY; j++) { matlist[j * NX + i] = 3; speclist[j*NX+i]=nspecies_mf+1; if (i<20) { species_mf[nspecies_mf++]=.3; species_mf[nspecies_mf++]=.7; } else { species_mf[nspecies_mf++]=.9; species_mf[nspecies_mf++]=.1; } } } delta_x = NX / nblocks_x; delta_y = NY / nblocks_y; coords[0] = x2; coords[1] = y2; dims[0] = delta_x + 1; dims[1] = delta_y + 1; zdims[0] = delta_x; zdims[1] = delta_y; dims2[0] = delta_x; dims2[1] = delta_y; /* * Create the blocks for the multi-block object. */ for (block = 0; block < nblocks_x * nblocks_y; block++) { fprintf(stdout, "\t%s\n", dirnames[block]); /* * Now extract the data for this block. */ base_x = (block % nblocks_x) * delta_x; base_y = (block / nblocks_x) * delta_y; for (j = 0, n_y = base_y; j < delta_y + 1; j++, n_y++) for (i = 0, n_x = base_x; i < delta_x + 1; i++, n_x++) { x2[j * (delta_x + 1) + i] = x[n_y * (NX + 1) + n_x]; y2[j * (delta_x + 1) + i] = y[n_y * (NX + 1) + n_x]; u2[j * (delta_x + 1) + i] = u[n_y * (NX + 1) + n_x]; v2[j * (delta_x + 1) + i] = v[n_y * (NX + 1) + n_x]; } for (j = 0, n_y = base_y; j < delta_y; j++, n_y++) for (i = 0, n_x = base_x; i < delta_x; i++, n_x++) { d2[j * delta_x + i] = d[n_y * NX + n_x]; p2[j * delta_x + i] = p[n_y * NX + n_x]; matlist2[j * delta_x + i] = matlist[n_y * NX + n_x]; speclist2[j*delta_x+i]=speclist[n_y*NX+n_x]; } if (DBSetDir(dbfile, dirnames[block]) == -1) { fprintf(stderr, "Could not set directory \"%s\"\n", dirnames[block]); return -1; } /* if */ /* Write out the variables. */ optlist = DBMakeOptlist(10); DBAddOption(optlist, DBOPT_CYCLE, &cycle); DBAddOption(optlist, DBOPT_TIME, &time); DBAddOption(optlist, DBOPT_DTIME, &dtime); DBAddOption(optlist, DBOPT_XLABEL, "X Axis"); DBAddOption(optlist, DBOPT_YLABEL, "Y Axis"); DBAddOption(optlist, DBOPT_XUNITS, "cm"); DBAddOption(optlist, DBOPT_YUNITS, "cm"); DBPutQuadmesh(dbfile, meshname, coordnames, coords, dims, ndims, DB_FLOAT, DB_NONCOLLINEAR, optlist); DBPutQuadvar1(dbfile, varname[2], meshname, u2, dims, ndims, NULL, 0, DB_FLOAT, DB_NODECENT, optlist); DBPutQuadvar1(dbfile, varname[3], meshname, v2, dims, ndims, NULL, 0, DB_FLOAT, DB_NODECENT, optlist); DBAddOption(optlist, DBOPT_USESPECMF, &usespecmf); DBPutQuadvar1(dbfile, varname[0], meshname, d2, zdims, ndims, NULL, 0, DB_FLOAT, DB_ZONECENT, optlist); DBPutQuadvar1(dbfile, varname[1], meshname, p2, zdims, ndims, NULL, 0, DB_FLOAT, DB_ZONECENT, optlist); DBPutMaterial(dbfile, matname, meshname, nmats, matnos, matlist2, dims2, ndims, NULL, NULL, NULL, NULL, 0, DB_FLOAT, optlist); DBPutMatspecies(dbfile, specname, matname, nmats, nmatspec, speclist2, dims2, ndims, nspecies_mf, species_mf, NULL, 0, DB_FLOAT, optlist); DBFreeOptlist(optlist); if (DBSetDir(dbfile, "..") == -1) { fprintf(stderr, "Could not return to base directory\n"); return -1; } /* if */ } /* for */ /* create the option lists for the multi-block calls. */ optlist = DBMakeOptlist(10); /* For all calls: */ DBAddOption(optlist, DBOPT_CYCLE, &cycle); DBAddOption(optlist, DBOPT_TIME, &time); DBAddOption(optlist, DBOPT_DTIME, &dtime); /* For multi-materials: */ DBAddOption(optlist, DBOPT_NMATNOS, &nmats); DBAddOption(optlist, DBOPT_MATNOS, matnos); /* For multi-species: */ DBAddOption(optlist, DBOPT_MATNAME, "mat1"); DBAddOption(optlist, DBOPT_NMAT, &nmats); DBAddOption(optlist, DBOPT_NMATSPEC, nmatspec); DBAddOption(optlist, DBOPT_SPECNAMES, species_names); DBAddOption(optlist, DBOPT_SPECCOLORS, speccolors); /* create the multi-block mesh */ if (DBPutMultimesh(dbfile, "mesh1", nblocks, meshnames, meshtypes, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi mesh\n"); return (-1); } /* if */ /* create the multi-block variables */ if (DBPutMultivar(dbfile, "d", nblocks, varnames[0], vartypes, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi var d\n"); return (-1); } /* if */ if (DBPutMultivar(dbfile, "p", nblocks, varnames[1], vartypes, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi var p\n"); return (-1); } /* if */ if (DBPutMultivar(dbfile, "u", nblocks, varnames[2], vartypes, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi var u\n"); return (-1); } /* if */ if (DBPutMultivar(dbfile, "v", nblocks, varnames[3], vartypes, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi var v\n"); return (-1); } /* if */ /* create the multi-block material */ if (DBPutMultimat(dbfile, "mat1", nblocks, matnames, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi material\n"); return (-1); } /* if */ /* create the multi-block species */ if (DBPutMultimatspecies(dbfile, "species1", nblocks, specnames, optlist) == -1) { DBFreeOptlist(optlist); fprintf(stderr, "Error creating multi species\n"); return (-1); } /* if */ DBFreeOptlist(optlist); return (0); }
void perform_merge( hpx::lcos::local::channel<void>& sync , DBfile* file , std::vector<std::string> const& directory_names , std::string const& variable_name , boost::uint64_t& step , double& time ) { // {{{ for (boost::uint64_t level = 0; level < directory_names.size(); ++level) { int error = DBSetDir(file, directory_names[level].c_str()); OCTOPUS_ASSERT(error == 0); // Get a list of all the meshes and variables in that directory. DBtoc* contents = DBGetToc(file); // Make the mesh and variable names. boost::ptr_vector<char> mesh_names(contents->nqmesh); boost::ptr_vector<char> variable_names(contents->nqmesh); double grid_dim = config().spatial_domain; for (boost::uint64_t i = 1; i < level; ++i) grid_dim *= 0.5; for (boost::uint64_t j = 0; j < boost::uint64_t(contents->nqmesh); ++j) { std::string tmp; /////////////////////////////////////////////////////////////////// tmp = directory_names[level]; tmp += "/"; tmp += contents->qmesh_names[j]; // The extra character is for the terminating byte. mesh_names.push_back(new char[tmp.size() + 1]); std::strcpy(&mesh_names[j], tmp.c_str()); /////////////////////////////////////////////////////////////////// tmp = directory_names[level]; tmp += "/"; tmp += contents->qvar_names[j]; // The extra character is for the terminating byte. variable_names.push_back(new char[tmp.size() + 1]); std::strcpy(&variable_names[j], tmp.c_str()); } // when we change directories below, "contents" will go out of scope boost::uint64_t nqmesh = contents->nqmesh; error = DBSetDir(file, "/"); OCTOPUS_ASSERT(error == 0); std::string multi_mesh_name = boost::str( boost::format("mesh_level_%1%") % level); std::string multi_variable_name = boost::str( boost::format("%1%_level_%2%") % variable_name % level); { DBoptlist* optlist = DBMakeOptlist(4); DBObjectType type1 = DB_QUADRECT; DBAddOption(optlist, DBOPT_MB_BLOCK_TYPE, &type1); DBAddOption(optlist, DBOPT_CYCLE, &step); DBAddOption(optlist, DBOPT_DTIME, &time); error = DBPutMultimesh(file , multi_mesh_name.c_str() , nqmesh , mesh_names.c_array() , NULL, optlist); OCTOPUS_ASSERT(error == 0); } { DBoptlist* optlist = DBMakeOptlist(4); DBObjectType type1 = DB_QUADVAR; DBAddOption(optlist, DBOPT_MB_BLOCK_TYPE, &type1); DBAddOption(optlist, DBOPT_CYCLE, &step); DBAddOption(optlist, DBOPT_DTIME, &time); int type2 = DB_ROWMAJOR; DBAddOption(optlist, DBOPT_MAJORORDER, &type2); error = DBPutMultivar(file , multi_variable_name.c_str() , nqmesh , variable_names.c_array() , NULL, optlist); OCTOPUS_ASSERT(error == 0); } } sync.post(); } // }}}