Exemple #1
0
void single_variable_silo_writer::start_write_locked(
    boost::uint64_t step
  , double time
  , mutex_type::scoped_lock& l
    )
{
    OCTOPUS_ASSERT(l.owns_lock());

    // Make sure we closed the last epoch.
    stop_write_locked(l);

    step_ = step;
    time_ = time; 

    try
    {
        std::string s = boost::str( boost::format(file_name_)
                                  % hpx::get_locality_id() % step_);
        file_ = DBCreate(s.c_str(), DB_CLOBBER, DB_LOCAL, NULL, DB_PDB);
    }
    // FIXME: Catch the specific boost.format exception.
    catch (...)
    {
        try
        {
            std::string s = boost::str( boost::format(file_name_)
                                      % hpx::get_locality_id());
            file_ = DBCreate(s.c_str(), DB_CLOBBER, DB_LOCAL, NULL, DB_PDB);
        }
        // FIXME: Catch the specific boost.format exception.
        catch (...)
        {
            file_ = DBCreate(file_name_.c_str()
                           , DB_CLOBBER, DB_LOCAL, NULL, DB_PDB);
        }
    }

    OCTOPUS_ASSERT(file_ != 0);

    directory_names_.reserve(config().levels_of_refinement + 1);
    for (boost::uint64_t i = 0; i < (config().levels_of_refinement + 1); ++i)
        directory_names_.push_back
            (boost::str(boost::format("/meshes_%1%") % i).c_str()); 

    for (boost::uint64_t i = 0; i < directory_names_.size(); ++i)
    {
        int error = DBMkDir(file_, directory_names_[i].c_str());
        OCTOPUS_ASSERT(error == 0);
    }
}
Exemple #2
0
/*-------------------------------------------------------------------------
 * Function:	test_quadmesh
 *
 * Purpose:	Tests reading and writing DBquadmesh objects.
 *
 * Return:	Success:	
 *
 *		Failure:	
 *
 * Programmer:	Robb Matzke
 *              Tuesday, March 30, 1999
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_quadmesh(DBfile *dbfile)
{
    int			nerrors=0;
    static int		dims[] = {5, 5};
    static float	coords0[] = {0.11, 0.12, 0.13, 0.14, 0.15};
    static float	coords1[] = {0.21, 0.22, 0.23, 0.24, 0.25};
    static float	*coords[] = {coords0, coords1};
    static double	varA[] = {10, 11, 12, 13, 14,
				  15, 16, 17, 18, 19,
				  20, 21, 22, 23, 24,
				  25, 26, 27, 28, 29,
				  30, 31, 32, 33, 34};
    static double	varB[] = {35, 36, 37, 38, 39,
				  40, 41, 42, 43, 44,
				  45, 46, 47, 48, 49,
				  50, 51, 52, 53, 54,
				  55, 56, 57, 58, 59};
    static double	varC[] = {60, 61, 62, 63, 64,
				  65, 66, 67, 68, 69,
				  70, 71, 72, 73, 74,
				  75, 76, 77, 78, 79,
				  80, 81, 82, 83, 84};
    static double	*vars[] = {varA, varB, varC};
    static char		*varnames[] = {"varA", "varB", "varC"};
	
    puts("=== Quadmesh ===");

    DBMkDir(dbfile, "/quad");
    DBSetDir(dbfile, "/quad");

    if (DBPutQuadmesh(dbfile, "qm1", NULL, coords, dims, 2, DB_FLOAT,
		      DB_COLLINEAR, NULL)<0) {
	puts("DBPutQuadmesh(qm1) failed");
	nerrors++;
    }

    if (DBPutQuadvar(dbfile, "qv1", "qm1", 3, varnames, (float**)vars, dims, 2,
		     NULL, 0, DB_DOUBLE, DB_NODECENT, NULL)<0) {
	puts("DBPutQuadmesh(qv1) failed");
	nerrors++;
    }
    

    return nerrors;
}
Exemple #3
0
/*-------------------------------------------------------------------------
 * Function:	test_curve
 *
 * Purpose:	Tests reading and writing DBcurve objects.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Tuesday, March 23, 1999
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_curve(DBfile *dbfile)
{
    int			nerrors = 0;
    static double	xvals_d[] = { 1.1,   2.2,   3.3,   4.4,   5.5 };
    static double	yvals_d[] = {10.01, 20.02, 30.03, 40.04, 50.05};
    
    puts("=== Curves ===");

    DBMkDir(dbfile, "/curves");
    DBSetDir(dbfile, "/curves");

    /* Write an initial curve along with its X and Y arrays */
    if (DBPutCurve(dbfile, "curve1", xvals_d, yvals_d, DB_DOUBLE,
		   NELMTS(xvals_d), NULL)<0) {
	puts("DBPutCurve(curve1) failed");
	nerrors++;
    }

    return nerrors;
}
Exemple #4
0
/*-------------------------------------------------------------------------
 * 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);
}
Exemple #5
0
/*-------------------------------------------------------------------------
 * Function:	test_ucdmesh
 *
 * Purpose:	Test unstructured mesh functions.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Thursday, April  1, 1999
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_ucdmesh(DBfile *dbfile)
{
    int			nerrors = 0;
    static double	coordA[] = {101, 102, 103, 104, 105};
    static double	coordB[] = {201, 202, 203, 204, 205};
    static double	coordC[] = {301, 302, 303, 304, 305};
    static double	*coords[] = {coordA, coordB, coordC};
    static char		*coordnames[] = {"coordA", "coordB", "coordC"};
    static int		nnodes = NELMTS(coordA);
    static int		ndims = NELMTS(coords);
    static int		nzones = 3;
    static float	varA[] = {1,  2,  3,  4,  5, 6, 7, 8};
    static float	*vars[] = {varA};
    static char		*varnames[] = {"varA"};
    static int		nels = NELMTS(varA);
    static int		nvars = NELMTS(vars);
    static float	mixA[] = {0.1, 0.2, 0.3};
    static float	*mixvars[] = {mixA};
    static int		mixlen = NELMTS(mixA);
    static int		nodelist[] = {500, 501, 502, 503, 504, 505, 506, 507};
    static int		lnodelist = NELMTS(nodelist);
    static int		shapecnt[] = {1,  1,  2,  2,  3,  3,  4,  4,  5,  5};
    static int		shapesize[]= {5,  5,  4,  4,  3,  3,  2,  2,  1,  1};
    static int		nshapes = NELMTS(shapecnt);
    static int		typelist[] = {99, 98, 97, 96, 95, 94};
    static int		ntypes = NELMTS(typelist);
    static int		types[]    = {193, 192, 191, 190, 189, 187, 186};
    static int		zoneno[]   = {185, 184, 183, 182, 181, 180, 179};
    static int		nfaces = NELMTS(types);
    static int		origin = 1;

    puts("=== Ucdmesh ===");

    DBMkDir(dbfile, "/ucd");
    DBSetDir(dbfile, "/ucd");

    /* Mesh */
    if (DBPutUcdmesh(dbfile, "um1", ndims, coordnames, (float**)coords, nnodes,
		     nzones, "zl1", "fl1", DB_DOUBLE,
		     NULL)<0) {
	puts("DBPutUcdmesh(um1) failed");
	nerrors++;
    }
    if (DBPutUcdsubmesh(dbfile, "um2", "um1", nzones, "zl1", "fl1", NULL)<0) {
	puts("DBPutUcdsubmesh(um2) failed");
	nerrors++;
    }
    
    /* Variable */
    if (DBPutUcdvar(dbfile, "uv1", "um1", nvars, varnames, vars, nels, mixvars,
		    mixlen, DB_FLOAT, DB_NODECENT, NULL)<0) {
	puts("DBPutUcdvar(uv1) failed");
	nerrors++;
    }

    /* Facelist */
    if (DBPutFacelist(dbfile, "fl1", nfaces, ndims, nodelist, lnodelist,
		      origin, zoneno, shapesize, shapecnt, nshapes, types,
		      typelist, ntypes)<0) {
	puts("DBPutFacelist(fl1) failed");
	nerrors++;
    }

    /* Zonelist */
    if (DBPutZonelist(dbfile, "zl1", nzones, ndims, nodelist, lnodelist,
		      origin, shapesize, shapecnt, nshapes)<0) {
	puts("DBPutZonelist(zl1) failed");
	nerrors++;
    }

    
    return nerrors;
}
Exemple #6
0
/*-------------------------------------------------------------------------
 * Function:	test_dirs
 *
 * Purpose:	Test directory operations
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Wednesday, February 10, 1999
 *
 * Modifications:
 *		Robb Matzke, 2000-01-12
 *		Changed hyphens to underscores in object names because silo
 *		now fails when underscores are present in the name.
 *-------------------------------------------------------------------------
 */
static int
test_dirs(DBfile *dbfile)
{
    int		nerrors=0;
    char	curdir[1024];
    static int	in[1]={911}, value[1]={0};
    static int	dims[1]={1};

    puts("=== Directories ===");

    /* Make some directories */
    if (DBMkDir(dbfile, "dir1")<0) {
	puts("DBMkDir(dir1) failed");
	nerrors++;
    }
    if (DBMkDir(dbfile, "dir1/d1a")<0) {
	puts("DBMkDir(dir1/d1a) failed");
	nerrors++;
    }
    if (DBMkDir(dbfile, "/dir1/d1b")<0) {
	puts("DBMkDir(dir1/d1b) failed");
	nerrors++;
    }
    if (DBMkDir(dbfile, "/dir1/d1c/")<0) {
	puts("DBMkDir(dir1/d1c) failed");
	nerrors++;
    }
    if (DBMkdir(dbfile, "//dir2//")<0) {
	puts("DBMkDir(dir2) failed");
	nerrors++;
    }

    /* Set the CWD to /dir1/d1c and write a variable */
    if (DBSetDir(dbfile, "//dir1//d1c//")<0) {
	puts("DBSetDir(/dir1/d1c) failed");
	nerrors++;
    }
    if (DBWrite(dbfile, "d1c_A", value, dims, 1, DB_INT)<0) {
	puts("DBWrite(d1c_A) failed");
	nerrors++;
    }
    if (DBGetDir(dbfile, curdir)<0 || strcmp(curdir, "/dir1/d1c")) {
	puts("DBGetDir() failed");
	nerrors++;
    }
    if (DBReadVar(dbfile, "../d1c/..//..////dir1/d1c//d1c_A", in)<0 ||
	in[0]!=value[0]) {
	puts("DBReadVar(d1c_A) failed");
	nerrors++;
    }

    /* Test table of contents */
    if (NULL==DBGetToc(dbfile)) {
	puts("DBGetToc() failed");
	nerrors++;
    }
    
    /* Set CWD to top */
    if (DBSetDir(dbfile, "/")<0) {
	puts("DBSetDir(/) failed");
	nerrors++;
    }
    if (DBGetDir(dbfile, curdir)<0 || strcmp(curdir, "/")) {
	puts("DBetDir() failed");
	nerrors++;
    }

    return nerrors;
}
Exemple #7
0
    virtual void WriteBoundariesFile(const int *divisions, const double *extents)
    {
        std::string filename(BoundariesFile());
        DBfile *dbfile = DBCreate(filename.c_str(), DB_CLOBBER, DB_LOCAL,
                                  "3D point mesh domain boundaries", DB_HDF5);
        if(dbfile == NULL)
        {
            fprintf(stderr, "Could not create Silo file!\n");
            return;
        }

        double deltaX = (extents[1] - extents[0]) / double(divisions[0]);
        double deltaY = (extents[3] - extents[2]) / double(divisions[1]);
        double deltaZ = (extents[5] - extents[4]) / double(divisions[2]);

        char domname[30];
        double z0 = extents[4];
        int dom = 0;
        std::vector<std::string> names;
        int nDomains = divisions[0]*divisions[1]*divisions[2];
        char **varnames = new char *[nDomains];
        int *vartypes = new int[nDomains];
        for(int dz = 0; dz < divisions[2]; ++dz)
        {
            double y0 = extents[2];
            for(int dy = 0; dy < divisions[1]; ++dy)
            {
                double x0 = extents[0];
                for(int dx = 0; dx < divisions[0]; ++dx, ++dom)
                {
                    sprintf(domname, "domain%d", dom);
                    DBMkDir(dbfile, domname);
                    DBSetDir(dbfile, domname);

                    sprintf(domname, "domain%d/bounds", dom);
                    names.push_back(domname);
                    varnames[dom] = (char *)names[dom].c_str();
                    vartypes[dom] = DB_QUADMESH;

                    double thisExtents[6];
                    thisExtents[0] = x0 + (dx)   * deltaX;
                    thisExtents[1] = x0 + (dx+1) * deltaX;
                    thisExtents[2] = y0 + (dy)   * deltaX;
                    thisExtents[3] = y0 + (dy+1) * deltaY;
                    thisExtents[4] = z0 + (dz)   * deltaZ;
                    thisExtents[5] = z0 + (dz+1) * deltaZ;

                    // Create a simple mesh that shows this domain's boundaries.
                    const int nvals = 4;
                    double x[nvals];
                    double y[nvals];
                    double z[nvals];
                    for(int i = 0; i < nvals; ++i)
                    {
                        double t = double(i) / double(nvals-1);
                        x[i] = (1.-t)*thisExtents[0] + t*thisExtents[1];
                        y[i] = (1.-t)*thisExtents[2] + t*thisExtents[3];
                        z[i] = (1.-t)*thisExtents[4] + t*thisExtents[5];
                    }
                    int dims[3] = {nvals, nvals, nvals};
                    int ndims = 3;
                    float *coords[3];
                    coords[0] = (float*)x;
                    coords[1] = (float*)y;
                    coords[2] = (float*)z;
                    DBPutQuadmesh(dbfile, "bounds", NULL, coords, dims, ndims,
                        DB_DOUBLE, DB_COLLINEAR, NULL);

                    DBSetDir(dbfile, "..");
                }
            }
        }
        DBPutMultimesh(dbfile, "bounds", nDomains, varnames, vartypes, NULL);

        delete [] varnames;
        delete [] vartypes;

        DBClose(dbfile);
    }