Пример #1
0
static void
build_csg_time_series(int driver)
{
    for (int i = 0; i < 8; i++)
    {
        char fileName[64];
        sprintf(fileName, "csg_series_%03d.silo", i);
        DBfile *dbfile = DBCreate(fileName, 0, DB_LOCAL, "csg time series test file", driver);

        int typeflags[] =
        {
            DBCSG_SPHERE_PR,
            DBCSG_PLANE_X
        };

        float coeffs[] =
        {
            0.0, 0.0, 0.0, 1.0,               // point-radius form of sphere
            0.0                               // x-intercept form of plane
        };

        if (i == 3) coeffs[3] = 1.5;
        if (i == 6) coeffs[4] = -0.25;

        double extents[] = {-2.0, -2.0, -2.0, 2.0, 2.0, 2.0};

        char *bndnames[] = {"sphere", "plane"};

        DBoptlist *optlist = DBMakeOptlist(4);
        DBAddOption(optlist, DBOPT_EXTENTS, extents);
        DBAddOption(optlist, DBOPT_BNDNAMES, bndnames);

        DBPutCsgmesh(dbfile, "sphere", 3, 1, typeflags,
            NULL, coeffs, 4, DB_FLOAT, extents, "sphere_csgzl", optlist);

        DBPutCsgmesh(dbfile, "half_sphere", 3, 2, typeflags,
            NULL, coeffs, 5, DB_FLOAT, extents, "half_sphere_csgzl", optlist);

        DBPutCsgmesh(dbfile, "half_sphere_compliment", 3, 2, typeflags,
            NULL, coeffs, 5, DB_FLOAT, extents, "half_sphere_comp_csgzl", optlist);

        int typeflags2[] =
        {
            DBCSG_INNER,          // 0: inside of sphere 
            DBCSG_OUTER,          // 1: +x side of plane
            DBCSG_INTERSECT,      // 2: the +half sphere
            DBCSG_COMPLIMENT      // 3: the not of 2
        };
        //                 0   1   2   3
        int leftids[] =  { 0,  1,  1,  2};
        int rightids[] = {-1, -1,  0, -1};
        int zonelist1[] = {0};
        int zonelist2[] = {2};
        int zonelist3[] = {3};

        char *zonenames[] = {"region_1"};

        DBClearOptlist(optlist);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "sphere_csgzl", 1, typeflags2, leftids, rightids,
                         NULL, 0, DB_INT, 1, zonelist1, optlist);

        DBPutCSGZonelist(dbfile, "half_sphere_csgzl", 3, typeflags2, leftids, rightids,
                         NULL, 0, DB_INT, 1, zonelist2, optlist);

        DBPutCSGZonelist(dbfile, "half_sphere_comp_csgzl", 4, typeflags2, leftids, rightids,
                         NULL, 0, DB_INT, 1, zonelist3, optlist);

        DBClose(dbfile);
    }
}
Пример #2
0
/*----------------------------------------------------------------------------
 * Function: domatspec
 *
 * Inputs:   db (DBfile*): the Silo file handle
 *
 * Returns:  (void)
 *
 * Abstract: Write the material and species info stored in the global Mesh 
 *           to the Silo file.  Handle mixed zones properly for both.
 *
 * Modifications:
 *    Sean Ahern, Wed Feb  6 16:32:35 PST 2002
 *    Added material names.
 *---------------------------------------------------------------------------*/
int
domatspec(DBfile *db, DoSpecOp_t writeOrReadAndCheck, int forceSingle)
{
    int     x, y, c;
    int     dims[2];
    int     matlist[1000];
    int     mix_mat[1000];
    int     mix_zone[1000];
    int     mix_next[1000];
    float   mix_vf[1000];
    double  mix_vfd[1000];
    int     mixc;
    int     mfc;
    int     speclist[1000];
    int     mixspeclist[1000];
    float   specmf[10000];
    double  specmfd[10000];
    DBoptlist      *optlist;

    dims[0] = mesh.zx;
    dims[1] = mesh.zy;

    /* do Materials */

    c = 0;
    mixc = 0;
    for (x = 0; x < mesh.zx; x++)
    {
        for (y = 0; y < mesh.zy; y++)
        {
            int     nmats = mesh.zone[x][y].nmats;
            if (nmats == 1)
            {
                /* clean zone */
                int     m = -1;
                int     i;
                for (i = 1; i <= nmat; i++)
                    if (mesh.zone[x][y].matvf[i] > 0)
                        m = i;
                if (m < 0)
                {
                    printf("Internal error!\n");
                    exit(-1);
                };
                matlist[c] = m;
                c++;
            } else
            {
                /* mixed zone */
                int     m = 0;
                matlist[c] = -mixc - 1;
                for (m = 1; m <= nmat && nmats > 0; m++)
                {
                    if (mesh.zone[x][y].matvf[m] > 0)
                    {
                        mix_mat[mixc] = m;
                        mix_vf[mixc] = mesh.zone[x][y].matvf[m];
                        mix_vfd[mixc] = mesh.zone[x][y].matvfd[m];
                        mix_zone[mixc] = c + 1; /* 1-origin */
                        nmats--;
                        if (nmats)
                            mix_next[mixc] = mixc + 2; /* next + 1-origin */
                        else
                            mix_next[mixc] = 0;
                        mixc++;
                    }
                }
                c++;
            }
        }
    }

    if (writeOrReadAndCheck == doWrite)
    {
        optlist = DBMakeOptlist(10);
        DBAddOption(optlist, DBOPT_MATNAMES, matnames);

        DBPutMaterial(db, "Material", "Mesh", nmat, matnos, matlist, dims, 2,
                      mix_next, mix_mat, mix_zone, mix_vf, mixc, DB_FLOAT, optlist);
        DBPutMaterial(db, "Materiald", "Mesh", nmat, matnos, matlist, dims, 2,
                      mix_next, mix_mat, mix_zone, mix_vfd, mixc, DB_DOUBLE, optlist);

    }
    else /* doReadAndCheck */
    {
        int pass;
        for (pass = 0; pass < 2; pass++)
        {
            DBmaterial *mat = DBGetMaterial(db, pass?"Material":"Materiald");
            CHECKIVAL(mat->nmat, nmat);
            CHECKIARR(mat->matnos, matnos, nmat);
            CHECKIVAL(mat->ndims, 2);
            CHECKIARR(mat->dims, dims, 2);
            if (forceSingle)
            {
                CHECKIVAL(mat->datatype, DB_FLOAT);
            }
            else
            {
                CHECKIVAL(mat->datatype, pass?DB_FLOAT:DB_DOUBLE);
            }
            CHECKIVAL(mat->mixlen, mixc);
            CHECKIARR(mat->matlist, matlist, dims[0]*dims[1]);
            CHECKIARR(mat->mix_next, mix_next, mixc);
            CHECKIARR(mat->mix_mat, mix_mat, mixc);
            CHECKIARR(mat->mix_zone, mix_zone, mixc);
            if (forceSingle)
            {
                CHECKDARR(((float*)mat->mix_vf), mix_vf, mixc);
            }
            else if (pass)
            {
                CHECKDARR(((float*)mat->mix_vf), mix_vf, mixc);
            }
            else
            {
                CHECKDARR(((double*)mat->mix_vf), mix_vfd, mixc);
            }
        }
    }

    /* Okay! Now for the species! */

    c = 0;
    mixc = 0;
    mfc = 0;
    for (x = 0; x < mesh.zx; x++)
    {
        for (y = 0; y < mesh.zy; y++)
        {
            if (mesh.zone[x][y].nmats == 1)
            {
                int     m = -1;
                int     i, s;
                for (i = 1; i <= nmat; i++)
                    if (mesh.zone[x][y].matvf[i] > 0)
                        m = i;
                if (m < 0)
                {
                    printf("Internal error!\n");
                    exit(-1);
                };

                if (nspec[m - 1] == 1)
                {
                    speclist[c] = 0;   /* no mf for this mat: only 1 species */
                } else
                {
                    speclist[c] = mfc + 1; /* 1-origin */
                    for (s = 0; s < nspec[m - 1]; s++)
                    {
                        specmf[mfc] = mesh.zone[x][y].specmf[m][s];
                        specmfd[mfc] = mesh.zone[x][y].specmfd[m][s];
                        mfc++;
                    }
                }
                c++;
            } else
            {
                int     m;
                speclist[c] = -mixc - 1;

                for (m = 1; m <= nmat; m++)
                {
                    if (mesh.zone[x][y].matvf[m] > 0)
                    {
                        if (nspec[m - 1] == 1)
                        {
                            mixspeclist[mixc] = 0; /* no mf for this mat:
                                                    * only 1 species */
                        } else
                        {
                            int     s;
                            mixspeclist[mixc] = mfc + 1; /* 1-origin */
                            for (s = 0; s < nspec[m - 1]; s++)
                            {
                                specmf[mfc] = mesh.zone[x][y].specmf[m][s];
                                specmfd[mfc] = mesh.zone[x][y].specmfd[m][s];
                                mfc++;
                            }
                        }
                        mixc++;
                    }
                }
                c++;
            }
        }
    }

    if (writeOrReadAndCheck == doWrite)
    {
        DBClearOptlist(optlist);
        DBAddOption(optlist, DBOPT_SPECNAMES, specnames);
        DBAddOption(optlist, DBOPT_SPECCOLORS, speccolors);

        DBPutMatspecies(db, "Species", "Material", nmat, nspec, speclist, dims, 2,
                        mfc, specmf, mixspeclist, mixc, DB_FLOAT, optlist);

        DBPutMatspecies(db, "Speciesd", "Materiald", nmat, nspec, speclist, dims, 2,
                        mfc, specmfd, mixspeclist, mixc, DB_DOUBLE, optlist);

        DBFreeOptlist(optlist);
    }
    else /* doReadAndCheck */ 
    {
        int pass;
        for (pass = 0; pass < 2; pass++)
        {
            DBmatspecies *spec = DBGetMatspecies(db, pass?"Species":"Speciesd");
            CHECKIVAL(spec->nmat, nmat);
            CHECKIARR(spec->nmatspec, nspec, nmat);
            CHECKIVAL(spec->ndims, 2);
            CHECKIARR(spec->dims, dims, 2);
            if (forceSingle)
            {
                CHECKIVAL(spec->datatype, DB_FLOAT);
            }
            else
            {
                CHECKIVAL(spec->datatype, pass?DB_FLOAT:DB_DOUBLE);
            }
            CHECKIVAL(spec->mixlen, mixc);
            CHECKIVAL(spec->nspecies_mf, mfc);
            CHECKIARR(spec->speclist, speclist, dims[0]*dims[1]);
            CHECKIARR(spec->mix_speclist, mixspeclist, mixc);
            if (forceSingle)
            {
                CHECKDARR(((float*)spec->species_mf), specmf, mfc);
            }
            else if (pass)
            {
                CHECKDARR(((float*)spec->species_mf), specmf, mfc);
            }
            else
            {
                CHECKDARR(((double*)spec->species_mf), specmfd, mfc);
            }
        }
    }

    return mixc;
}
Пример #3
0
/*----------------------------------------------------------------------------
 * Function: writematspec
 *
 * Inputs:   db (DBfile*): the Silo file handle
 *
 * Returns:  (void)
 *
 * Abstract: Write the material and species info stored in the global Mesh 
 *           to the Silo file.  Handle mixed zones properly for both.
 *
 * Modifications:
 *    Sean Ahern, Wed Feb  6 16:32:35 PST 2002
 *    Added material names.
 *---------------------------------------------------------------------------*/
int
writematspec(DBfile *db)
{
    int     x, y, c;
    int     dims[2];
    int     matlist[1000];
    int     mix_mat[1000];
    int     mix_zone[1000];
    int     mix_next[1000];
    float   mix_vf[1000];
    int     mixc;
    int     mfc;
    int     speclist[1000];
    int     mixspeclist[1000];
    float   specmf[10000];
    DBoptlist      *optlist;

    dims[0] = mesh.zx;
    dims[1] = mesh.zy;

    /* do Materials */

    c = 0;
    mixc = 0;
    for (x = 0; x < mesh.zx; x++)
    {
        for (y = 0; y < mesh.zy; y++)
        {
            int     nmats = mesh.zone[x][y].nmats;
            if (nmats == 1)
            {
                /* clean zone */
                int     m = -1;
                int     i;
                for (i = 1; i <= nmat; i++)
                    if (mesh.zone[x][y].matvf[i] > 0)
                        m = i;
                if (m < 0)
                {
                    printf("Internal error!\n");
                    exit(-1);
                };
                matlist[c] = m;
                c++;
            } else
            {
                /* mixed zone */
                int     m = 0;
                matlist[c] = -mixc - 1;
                for (m = 1; m <= nmat && nmats > 0; m++)
                {
                    if (mesh.zone[x][y].matvf[m] > 0)
                    {
                        mix_mat[mixc] = m;
                        mix_vf[mixc] = mesh.zone[x][y].matvf[m];
                        mix_zone[mixc] = c + 1; /* 1-origin */
                        nmats--;
                        if (nmats)
                            mix_next[mixc] = mixc + 2; /* next + 1-origin */
                        else
                            mix_next[mixc] = 0;
                        mixc++;
                    }
                }
                c++;
            }
        }
    }

    optlist = DBMakeOptlist(10);
    DBAddOption(optlist, DBOPT_MATNAMES, matnames);

    DBPutMaterial(db, "Material", "Mesh", nmat, matnos, matlist, dims, 2,
                  mix_next, mix_mat, mix_zone, mix_vf, mixc, DB_FLOAT,
                  optlist);

    /* Okay! Now for the species! */

    c = 0;
    mixc = 0;
    mfc = 0;
    for (x = 0; x < mesh.zx; x++)
    {
        for (y = 0; y < mesh.zy; y++)
        {
            if (mesh.zone[x][y].nmats == 1)
            {
                int     m = -1;
                int     i, s;
                for (i = 1; i <= nmat; i++)
                    if (mesh.zone[x][y].matvf[i] > 0)
                        m = i;
                if (m < 0)
                {
                    printf("Internal error!\n");
                    exit(-1);
                };

                if (nspec[m - 1] == 1)
                {
                    speclist[c] = 0;   /* no mf for this mat: only 1 species */
                } else
                {
                    speclist[c] = mfc + 1; /* 1-origin */
                    for (s = 0; s < nspec[m - 1]; s++)
                    {
                        specmf[mfc] = mesh.zone[x][y].specmf[m][s];
                        mfc++;
                    }
                }
                c++;
            } else
            {
                int     m;
                speclist[c] = -mixc - 1;

                for (m = 1; m <= nmat; m++)
                {
                    if (mesh.zone[x][y].matvf[m] > 0)
                    {
                        if (nspec[m - 1] == 1)
                        {
                            mixspeclist[mixc] = 0; /* no mf for this mat:
                                                    * only 1 species */
                        } else
                        {
                            int     s;
                            mixspeclist[mixc] = mfc + 1; /* 1-origin */
                            for (s = 0; s < nspec[m - 1]; s++)
                            {
                                specmf[mfc] = mesh.zone[x][y].specmf[m][s];
                                mfc++;
                            }
                        }
                        mixc++;
                    }
                }
                c++;
            }
        }
    }

    DBClearOptlist(optlist);
    DBAddOption(optlist, DBOPT_SPECNAMES, specnames);
    DBAddOption(optlist, DBOPT_SPECCOLORS, speccolors);

    DBPutMatspecies(db, "Species", "Material", nmat, nspec, speclist, dims, 2,
                    mfc, specmf, mixspeclist, mixc, DB_FLOAT, optlist);

    return mixc;
}