Beispiel #1
0
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);
}
Beispiel #2
0
DBoptlist *
MakeOptList(int origin)
{
    int tmp;
    DBoptlist *optlist = DBMakeOptlist(4);
    tmp = origin;
    DBAddOption(optlist, DBOPT_ORIGIN, (void *)&tmp);
    DBAddOption(optlist, DBOPT_XUNITS, (void *)"cm");
    DBAddOption(optlist, DBOPT_YUNITS, (void *)"cm");
    DBAddOption(optlist, DBOPT_ZUNITS, (void *)"cm");
    return optlist;
}
Beispiel #3
0
    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);
    }
Beispiel #4
0
int
main(int argc, char *argv[])
{
    DBfile         *dbfile = NULL;
    int             i;
    int		    driver = DB_PDB;
    char 	    *filename = "majorder.silo";
    void           *coords[2];
    int             ndims = 2;
    int             dims[2] = {3,2}; 
    int             dims1[2] = {4,3}; 
    int             colmajor = DB_COLMAJOR;
    DBoptlist      *optlist;

    /* Parse command-line */
    for (i=1; i<argc; i++) {
	if (!strncmp(argv[i], "DB_", 3)) {
	    driver = StringToDriver(argv[i]);
	} else if (argv[i][0] != '\0') {
	    fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
	}
    }
    
    dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL, "test major order on quad meshes and vars", driver);

    coords[0] = row_maj_x_data;
    coords[1] = row_maj_y_data;
    DBPutQuadmesh(dbfile, "row_major_mesh", 0, coords, dims1, ndims, DB_FLOAT, DB_NONCOLLINEAR, 0);
    DBPutQuadvar1(dbfile, "row_major_var", "row_major_mesh", row_maj_v_data, dims, ndims, 0, 0, DB_INT, DB_ZONECENT, 0);

    optlist = DBMakeOptlist(1);
    DBAddOption(optlist, DBOPT_MAJORORDER, &colmajor);
    coords[0] = col_maj_x_data;
    coords[1] = col_maj_y_data;
    DBPutQuadmesh(dbfile, "col_major_mesh", 0, coords, dims1, ndims, DB_FLOAT, DB_NONCOLLINEAR, optlist);
    DBPutQuadvar1(dbfile, "col_major_var", "col_major_mesh", col_maj_v_data, dims, ndims, 0, 0, DB_INT, DB_ZONECENT, optlist);
    DBFreeOptlist(optlist);

    DBClose(dbfile);

    CleanupDriverStuff();

    return 0;
}
Beispiel #5
0
void
write_rect2d(DBfile *dbfile)
{
    /* Write a rectilinear mesh. */
    float x[] = {0., 1., 2.5, 5.};
    float y[] = {0., 2., 2.25, 2.55,  5.};
    int dims[] = {4, 5};
    int ndims = 2;
    float *coords[2];
    /* Create an option list for saving cycle and time values. */
    int cycle = 100;
    double dtime = 1.23456789;
    DBoptlist *optlist = DBMakeOptlist(2);
    coords[0] = x; coords[1] = y;
    DBAddOption(optlist, DBOPT_CYCLE, (void *)&cycle);
    DBAddOption(optlist, DBOPT_DTIME, (void *)&dtime);
    /* Write a quadmesh with an option list. */
    DBPutQuadmesh(dbfile, "quadmesh", NULL, coords, dims, ndims,
                  DB_FLOAT, DB_COLLINEAR, optlist);
    /* Free the option list. */
    DBFreeOptlist(optlist);
}
Beispiel #6
0
static void
build_curve (DBfile *dbfile, int driver)
{
   float        x[20], y[2][20] ;
   int          i ;
   DBoptlist    *opts ;

   /*
    * Sine and cosine for 1/2 cycle.  Both curves have the same
    * X data points and share the data in the file.
    */
   for (i=0; i<20; i++) {
      x[i] = i * M_PI / 20.0 ;
      y[0][i] = sin (x[i]) ;
      y[1][i] = cos (x[i]) ;
   }

   opts = DBMakeOptlist (10) ;
   DBAddOption (opts, DBOPT_XLABEL, "X Axis") ;
   DBAddOption (opts, DBOPT_YLABEL, "Y Axis") ;
   DBAddOption (opts, DBOPT_XUNITS, "radians") ;

   /*
    * Write the 'sincurve' curve. The hdf5 driver allows the user to specify
    * the name which will be used to store the x values, but the pdb driver
    * requires us to know where the values were stored.
    */
   if (DB_HDF5==driver) DBAddOption(opts, DBOPT_XVARNAME, "sincurve_xvals");
   DBPutCurve (dbfile, "sincurve", x, y[0], DB_FLOAT, 20, opts);
   if (DB_HDF5!=driver) DBAddOption(opts, DBOPT_XVARNAME, "sincurve_xvals");

   /*
    * Write the 'coscurve' curve. It shares x values with the 'sincurve'
    * curve.
    */
   DBPutCurve (dbfile, "coscurve", NULL, y[1], DB_FLOAT, 20, opts) ;
   DBFreeOptlist (opts) ;
}
Beispiel #7
0
/*----------------------------------------------------------------------------
 * Function: writemesh_curv2d()
 *
 * Inputs:   db (DBfile*): the Silo file handle
 *
 * Returns:  (void)
 *
 * Abstract: Write the mesh and variables stored in the global Mesh 
 *           to the Silo file as a quadmesh and quadvars
 *
 * Modifications:
 *---------------------------------------------------------------------------*/
void writemesh_curv2d(DBfile *db, int mixc, int reorder) {

  float f1[1000],f2[1000], fm[1000];
  int x,y,c;

  char  *coordnames[2];
  char  *varnames[6];
  void *varbufs[6];
  float *coord[2];
  int dims[2];

  char *cnvar, *czvar;
  short *snvar, *szvar;
  int *invar, *izvar;
  long *lnvar, *lzvar;
  long long *Lnvar, *Lzvar;
  float *fnvar, *fzvar;
  double *dnvar, *dzvar;

  int nnodes=mesh.nx*mesh.ny;
  int nzones=mesh.zx*mesh.zy;
  
  /* do mesh */
  c=0;
  for (x=0;x<mesh.nx;x++) {
    for (y=0;y<mesh.ny;y++) {
      f1[c]=mesh.node[x][y].x;
      f2[c]=mesh.node[x][y].y;
      c++;
    }
  }

  coordnames[0]=NEW(char,20);
  coordnames[1]=NEW(char,20);
  strcpy(coordnames[0],"x");
  strcpy(coordnames[1],"y");

  coord[0]=f1;
  coord[1]=f2;

  dims[0]=mesh.nx;
  dims[1]=mesh.ny;

  DBPutQuadmesh(db, "Mesh", (DBCAS_t) coordnames, coord,
      dims, 2, DB_FLOAT, DB_NONCOLLINEAR, NULL);

  /* Test outputting of ghost node and zone labels */
  {
      int i;
      int nnodes = mesh.nx * mesh.ny;
      int nzones = (mesh.nx-1) * (mesh.ny-1);
      char *gn = (char *) calloc(nnodes,1);
      char *gz = (char *) calloc(nzones,1);
      DBoptlist *ol = DBMakeOptlist(5);

      for (i = 0; i < nnodes; i++)
      {
          if (!(i % 3)) gn[i] = 1;
      }
      for (i = 0; i < nzones; i++)
      {
          if (!(i % 7)) gz[i] = 1;
      }

      strcpy(coordnames[0],"xn");
      strcpy(coordnames[1],"yn");
      DBAddOption(ol, DBOPT_GHOST_NODE_LABELS, gn);
      DBPutQuadmesh(db, "Mesh_gn", (DBCAS_t) coordnames,
          coord, dims, 2, DB_FLOAT, DB_NONCOLLINEAR, ol);
      DBClearOption(ol, DBOPT_GHOST_NODE_LABELS);

      strcpy(coordnames[0],"xz");
      strcpy(coordnames[1],"yz");
      DBAddOption(ol, DBOPT_GHOST_ZONE_LABELS, gz);
      DBPutQuadmesh(db, "Mesh_gz", (DBCAS_t) coordnames,
          coord, dims, 2, DB_FLOAT, DB_NONCOLLINEAR, ol);

      strcpy(coordnames[0],"xnz");
      strcpy(coordnames[1],"ynz");
      DBAddOption(ol, DBOPT_GHOST_NODE_LABELS, gn);
      DBPutQuadmesh(db, "Mesh_gnz", (DBCAS_t) coordnames,
          coord, dims, 2, DB_FLOAT, DB_NONCOLLINEAR, ol);

      DBFreeOptlist(ol);
      free(gn);
      free(gz);
  }

  free(coordnames[0]);
  free(coordnames[1]);

  /* do Node vars */

  cnvar = (char *)        malloc(sizeof(char)*nnodes); 
  snvar = (short *)       malloc(sizeof(short)*nnodes); 
  invar = (int *)         malloc(sizeof(int)*nnodes); 
  lnvar = (long *)        malloc(sizeof(long)*nnodes); 
  Lnvar = (long long *)   malloc(sizeof(long long)*nnodes); 
  fnvar = (float *)       malloc(sizeof(float)*nnodes); 
  dnvar = (double *)      malloc(sizeof(double)*nnodes); 
  c=0;
  for (x=0;x<mesh.nx;x++) {
    for (y=0;y<mesh.ny;y++) {
      f1[c]=mesh.node[x][y].vars[NV_U];
      f2[c]=mesh.node[x][y].vars[NV_V];
      cnvar[c] = (char)        (x<y?x:y);
      snvar[c] = (short)       (x<y?x:y);
      invar[c] = (int)         (x<y?x:y);
      lnvar[c] = (long)        (x<y?x:y);
      Lnvar[c] = (long long)   (x<y?x:y);
      fnvar[c] = (float)       (x<y?x:y);
      dnvar[c] = (double)      (x<y?x:y);
      c++;
    }
  }

  DBPutQuadvar1(db, "u", "Mesh", f1, dims, 2, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "v", "Mesh", f2, dims, 2, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "cnvar", "Mesh", cnvar, dims, 2, NULL, 0, DB_CHAR, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "snvar", "Mesh", snvar, dims, 2, NULL, 0, DB_SHORT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "invar", "Mesh", invar, dims, 2, NULL, 0, DB_INT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "lnvar", "Mesh", lnvar, dims, 2, NULL, 0, DB_LONG, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "Lnvar", "Mesh", Lnvar, dims, 2, NULL, 0, DB_LONG_LONG, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "fnvar", "Mesh", fnvar, dims, 2, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);
  DBPutQuadvar1(db, "dnvar", "Mesh", dnvar, dims, 2, NULL, 0, DB_DOUBLE, DB_NODECENT, NULL);
  free(cnvar);
  free(snvar);
  free(invar);
  free(lnvar);
  free(Lnvar);
  free(fnvar);
  free(dnvar);

  /* test writing a quadvar with many components */
  varnames[0] = "u0";
  varnames[1] = "v0";
  varnames[2] = "u1";
  varnames[3] = "v1";
  varnames[4] = "u2";
  varnames[5] = "v2";
  varbufs[0] = f1;
  varbufs[1] = f2;
  varbufs[2] = f1;
  varbufs[3] = f2;
  varbufs[4] = f1;
  varbufs[5] = f2;
  DBPutQuadvar(db, "manyc", "Mesh", 6, (DBCAS_t) varnames,
      varbufs, dims, 2, NULL, 0, DB_FLOAT, DB_NODECENT, NULL);

  /* do Zone vars */

  dims[0]--;
  dims[1]--;

  czvar = (char *)        malloc(sizeof(char)*nzones); 
  szvar = (short *)       malloc(sizeof(short)*nzones); 
  izvar = (int *)         malloc(sizeof(int)*nzones); 
  lzvar = (long *)        malloc(sizeof(long)*nzones); 
  Lzvar = (long long *)   malloc(sizeof(long long)*nzones); 
  fzvar = (float *)       malloc(sizeof(float)*nzones); 
  dzvar = (double *)      malloc(sizeof(double)*nzones); 
  c=0;
  for (x=0;x<mesh.zx;x++) {
    for (y=0;y<mesh.zy;y++) {
      f1[c]=mesh.zone[x][y].vars[ZV_P];
      f2[c]=mesh.zone[x][y].vars[ZV_D];
      czvar[c] = (char)        (x<y?x:y);
      szvar[c] = (short)       (x<y?x:y);
      izvar[c] = (int)         (x<y?x:y);
      lzvar[c] = (long)        (x<y?x:y);
      Lzvar[c] = (long long)   (x<y?x:y);
      fzvar[c] = (float)       (x<y?x:y);
      dzvar[c] = (double)      (x<y?x:y);
      c++;
    }
  }

  for (c=0; c<mixc; c++)
      fm[c] = 2.0/mixc*c;
  if (reorder)
  {
    float tmp=fm[mixc-1];
    fm[mixc-1]=fm[mixc-2];
    fm[mixc-2]=tmp;
  }

  DBPutQuadvar1(db, "p", "Mesh", f1, dims, 2, NULL, 0, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "d", "Mesh", f2, dims, 2, fm, mixc, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "czvar", "Mesh", czvar, dims, 2, NULL, 0, DB_CHAR, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "szvar", "Mesh", szvar, dims, 2, NULL, 0, DB_SHORT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "izvar", "Mesh", izvar, dims, 2, NULL, 0, DB_INT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "lzvar", "Mesh", lzvar, dims, 2, NULL, 0, DB_LONG, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "Lzvar", "Mesh", Lzvar, dims, 2, NULL, 0, DB_LONG_LONG, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "fzvar", "Mesh", fzvar, dims, 2, NULL, 0, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutQuadvar1(db, "dzvar", "Mesh", dzvar, dims, 2, NULL, 0, DB_DOUBLE, DB_ZONECENT, NULL);
  free(czvar);
  free(szvar);
  free(izvar);
  free(lzvar);
  free(Lzvar);
  free(fzvar);
  free(dzvar);
}
Beispiel #8
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);
}
bool SpeckleyElements::writeToSilo(DBfile* dbfile, const string& siloPath,
                                 const StringVec& labels,
                                 const StringVec& units, bool writeMeshData)
{
#ifdef ESYS_HAVE_SILO
    if (numElements == 0)
        return true;

    int ret;

    if (siloPath != "") {
        ret = DBSetDir(dbfile, siloPath.c_str());
        if (ret != 0)
            return false;
    }

    // write out the full mesh in any case
    nodeMesh->setSiloPath(siloPath);
    string siloMeshNameStr = nodeMesh->getFullSiloName();
    const char* siloMeshName = siloMeshNameStr.c_str();
    int arraylen = numElements * nodesPerElement;
    int eltype = toSiloElementType(type);

    string varName = name + string("_zones");
    ret = DBPutZonelist2(dbfile, varName.c_str(), numElements,
            nodeMesh->getNumDims(), &nodes[0], arraylen, 0, 0,
            numGhostElements, &eltype, &nodesPerElement, &numElements, 1, NULL);

    if (ret == 0) {
        CoordArray& coordbase = const_cast<CoordArray&>(nodeMesh->getCoords());
        DBoptlist* optList = NULL;
        int nOpts = labels.size()+units.size();
        if (nOpts>0) {
            optList = DBMakeOptlist(nOpts);
            if (labels.size()>0)
                DBAddOption(optList, DBOPT_XLABEL, (void*)labels[0].c_str());
            if (labels.size()>1)
                DBAddOption(optList, DBOPT_YLABEL, (void*)labels[1].c_str());
            if (labels.size()>2)
                DBAddOption(optList, DBOPT_ZLABEL, (void*)labels[2].c_str());
            if (units.size()>0)
                DBAddOption(optList, DBOPT_XUNITS, (void*)units[0].c_str());
            if (units.size()>1)
                DBAddOption(optList, DBOPT_YUNITS, (void*)units[1].c_str());
            if (units.size()>2)
                DBAddOption(optList, DBOPT_ZUNITS, (void*)units[2].c_str());
        }
        ret = DBPutUcdmesh(dbfile, siloMeshName,
                nodeMesh->getNumDims(), NULL, &coordbase[0],
                nodeMesh->getNumNodes(), numElements, varName.c_str(),
                /*"facelist"*/NULL, DB_FLOAT, optList);

        if (optList)
            DBFreeOptlist(optList);
    }
    
    if (ret != 0)
        return false;

    // write out the element-centered variables if enabled
    if (writeMeshData) {
        varName = name + string("_Id");
        ret = DBPutUcdvar1(dbfile, varName.c_str(), siloMeshName,
                (float*)&ID[0], numElements, NULL, 0, DB_INT, DB_ZONECENT,
                NULL);
        if (ret == 0) {
            varName = name + string("_Owner");
            ret = DBPutUcdvar1(dbfile, varName.c_str(), siloMeshName,
                (float*)&owner[0], numElements, NULL, 0, DB_INT, DB_ZONECENT,
                NULL);
        }
    }

    // "Elements" is a special case
    if (writeMeshData && name == "Elements") {
        nodeMesh->writeToSilo(dbfile);
    }

    return (ret == 0);

#else // !ESYS_HAVE_SILO
    return false;
#endif
}
Beispiel #10
0
    virtual bool WriteDomainFile(int dom, const particleVector &P)
    {
        if(P.empty())
            return false;

        std::string filename(DomainFile(dom));
        DBfile *dbfile = DBCreate(filename.c_str(), DB_CLOBBER, DB_LOCAL,
                                  "3D point mesh", DB_HDF5);
        if(dbfile == NULL)
        {
            fprintf(stderr, "Could not create Silo file!\n");
            return false;
        }

        double *m, *x, *y, *z, *vx, *vy, *vz, *r;
        int *id, *doms, *contact;
        int ndims = 3;
        float *coords[3];
        x = new double[P.size()];
        y = new double[P.size()];
        z = new double[P.size()];
        vx = new double[P.size()];
        vy = new double[P.size()];
        vz = new double[P.size()];
        m = new double[P.size()];
        r = new double[P.size()];
        id = new int[P.size()];
        doms = new int[P.size()];
        contact = new int[P.size()];

        coords[0] = (float*)x;
        coords[1] = (float*)y;
        coords[2] = (float*)z;

        for(size_t i = 0; i < P.size(); ++i)
        { 
            x[i] = P[i].location.x;
            y[i] = P[i].location.y;
            z[i] = P[i].location.z;

            vx[i] = P[i].velocity.x;
            vy[i] = P[i].velocity.y;
            vz[i] = P[i].velocity.z;

            m[i] = P[i].mass;
            r[i] = P[i].restitution;
            id[i] = P[i].ID;
            doms[i] = dom+1;
            contact[i] = P[i].contact ? 1 : 0;
        }

        // Create an option list for saving cycle and time values.
        DBoptlist *optlist = DBMakeOptlist(9);
        DBAddOption(optlist, DBOPT_CYCLE, (void *)&cycle);
        DBAddOption(optlist, DBOPT_DTIME, (void *)&time);
        DBAddOption(optlist, DBOPT_NODENUM, (void *)id);
        DBAddOption(optlist, DBOPT_XUNITS, (void *)"m");
        DBAddOption(optlist, DBOPT_YUNITS, (void *)"m");
        DBAddOption(optlist, DBOPT_ZUNITS, (void *)"m");
        DBAddOption(optlist, DBOPT_XLABEL, (void *)"Width");
        DBAddOption(optlist, DBOPT_YLABEL, (void *)"Height");
        DBAddOption(optlist, DBOPT_ZLABEL, (void *)"Depth");

        DBoptlist *voptlist = DBMakeOptlist(3);
        DBAddOption(voptlist, DBOPT_CYCLE, (void *)&cycle);
        DBAddOption(voptlist, DBOPT_DTIME, (void *)&time);

        // Write a point mesh.
        DBPutPointmesh(dbfile, "pointmesh", ndims, coords, P.size(),
                       DB_DOUBLE, optlist);

        // Write variables.
        DBPutPointvar1(dbfile, "vx", "pointmesh", vx, P.size(), DB_DOUBLE, voptlist);
        DBPutPointvar1(dbfile, "vy", "pointmesh", vy, P.size(), DB_DOUBLE, voptlist);
        DBPutPointvar1(dbfile, "vz", "pointmesh", vz, P.size(), DB_DOUBLE, voptlist);

        DBPutPointvar1(dbfile, "mass", "pointmesh", m, P.size(), DB_DOUBLE, voptlist);
        DBPutPointvar1(dbfile, "restitution", "pointmesh", r, P.size(), DB_DOUBLE, voptlist);
        DBPutPointvar1(dbfile, "dom", "pointmesh", doms, P.size(), DB_INT, voptlist);
        DBPutPointvar1(dbfile, "contact", "pointmesh", contact, P.size(), DB_INT, voptlist);

        delete [] x;
        delete [] y;
        delete [] z;
        delete [] vx;
        delete [] vy;
        delete [] vz;
        delete [] m;
        delete [] r;
        delete [] id;
        delete [] doms;
        delete [] contact;

        DBFreeOptlist(optlist);
        DBFreeOptlist(voptlist);
        DBClose(dbfile);

        return true;
    }
Beispiel #11
0
/*----------------------------------------------------------------------
 *  Routine                                                   build_quad
 *
 *  Purpose
 *
 *      Build quad-mesh, quad-var, and material data objects; 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 varid and matid, which
 *    were unused.
 *
 *--------------------------------------------------------------------*/
int
build_quad(DBfile *dbfile, char *name)
{
    int            i, dims[3], zones[3], ndims, cycle, meshid;
    float          time;
    double         dtime;
    int            zdims[3];
    float          x[10], y[8], d[80], *coords[3], *vars[3];
    float          u[80], v[80];
    int            matnos[3], matlist[63], nmat, mixlen;
    char          *coordnames[3], *varnames[3];
    DBoptlist     *optlist;

    optlist = DBMakeOptlist(10);
    DBAddOption(optlist, DBOPT_CYCLE, &cycle);
    DBAddOption(optlist, DBOPT_TIME, &time);
    DBAddOption(optlist, DBOPT_DTIME, &dtime);

    ndims = 2;
    dims[0] = 10;
    dims[1] = 8;

    zones[0] = 9;
    zones[1] = 7;

    cycle = 44;
    time = 4.4;
    dtime = 4.4;
    coords[0] = x;
    coords[1] = y;
    coordnames[0] = "xcoords";
    coordnames[1] = "ycoords";

    for (i = 0; i < dims[0]; i++)
        x[i] = (float)i;
    for (i = 0; i < dims[1]; i++)
        y[i] = (float)i + .1;

    meshid = DBPutQuadmesh(dbfile, name, coordnames, coords, dims, ndims,
                           DB_FLOAT, DB_COLLINEAR, optlist);

    varnames[0] = "d";
    vars[0] = d;
    zdims[0] = dims[0] - 1;
    zdims[1] = dims[1] - 1;

    for (i = 0; i < zdims[0] * zdims[1]; i++)
        d[i] = (float)i *.2;

    (void)DBPutQuadvar1(dbfile, "d", name, d, zdims, ndims,
                        NULL, 0, DB_FLOAT, DB_ZONECENT, optlist);

    for (i = 0; i < dims[0] * dims[1]; i++) {
        u[i] = (float)i *.1;
        v[i] = (float)i *.1;
    }

    (void)DBPutQuadvar1(dbfile, "ucomp", name, u, dims, ndims,
                        NULL, 0, DB_FLOAT, DB_NODECENT, optlist);
    (void)DBPutQuadvar1(dbfile, "vcomp", name, v, dims, ndims,
                        NULL, 0, DB_FLOAT, DB_NODECENT, optlist);

    vars[0] = u;
    vars[1] = v;
    varnames[0] = "u";
    varnames[1] = "v";

    (void)DBPutQuadvar(dbfile, "velocity", name, 2, varnames, vars,
                       dims, ndims, NULL, 0, DB_FLOAT, DB_NODECENT,
                       optlist);

    /*
     *  Build material data.
     */
    nmat = 3;
    mixlen = 0;
    matnos[0] = 1;
    matnos[1] = 2;
    matnos[2] = 3;

    for (i = 0; i < 27; i++)
        matlist[i] = 1;
    for (i = 27; i < 45; i++)
        matlist[i] = 2;
    for (i = 45; i < 63; i++)
        matlist[i] = 3;

    (void)DBPutMaterial(dbfile, "material", name, nmat, matnos,
                        matlist, zones, ndims, NULL, NULL, NULL, NULL,
                        mixlen, DB_FLOAT, NULL);

    return (meshid);
}
Beispiel #12
0
int
main(int argc, char *argv[])
{
    int		    driver = DB_PDB;
    char 	    *filename = "empty.silo";
    int             show_all_errors = FALSE;
    int             i, pass;
    char const * const cnames[3] = {"x","y","z"};
    void           *coords[3] = {(void*)1,(void*)2,(void*)3}; /* really funky dummy pointers */
    void           *vars[3] = {(void*)1,(void*)2,(void*)3}; /* really funky dummy pointers */
    void const * const vvars[3] = {(void*)1,(void*)2,(void*)3}; /* really funky dummy pointers */
    void           *var = (void*)1;
    int             iarr[3] = {1,1,1}; /* dummy int array */
    int             ZDIMS[3] = {0,0,0};
    double          exts[4] = {0,0,0,0};
    DBoptlist      *ol = 0;
    double          dtime = 0.0;
    int             hide_from_gui=0;
    int            *gnodeno = 0;
    int            *gzoneno = 0;
    char           *ghostn = 0;
    char           *ghostz = 0;

    /* Parse command-line */
    for (i=1; i<argc; i++) {
	if (!strncmp(argv[i], "DB_", 3)) {
	    driver = StringToDriver(argv[i]);
        } else if (!strcmp(argv[i], "show-all-errors")) {
            show_all_errors = 1;
	} else if (argv[i][0] != '\0') {
	    fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
	}
    }
    
    DBSetDeprecateWarnings(0);
    DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_NONE, NULL);
    printf("Creating test file \"%s\".\n", filename);
    dbfile = DBCreate(filename, DB_CLOBBER, DB_LOCAL, "test empty silo objects", driver);

    ol = DBMakeOptlist(10);
    DBAddOption(ol, DBOPT_DTIME, &dtime);
    DBAddOption(ol, DBOPT_HIDE_FROM_GUI, &hide_from_gui);
    DBAddOption(ol, DBOPT_NODENUM, gnodeno);
    DBAddOption(ol, DBOPT_ZONENUM, gzoneno);
    DBAddOption(ol, DBOPT_GHOST_NODE_LABELS, ghostn);
    DBAddOption(ol, DBOPT_GHOST_ZONE_LABELS, ghostz);

    /* first pass confirms we catch bad arguments; second pass confirms we permit empty objects */
    for (pass = 0; pass < 2; pass++)
    {
        const int dt = DB_FLOAT;
        const int ct = DB_ZONECENT;
        const int ZZ = 0; /* Used for sole arg causing emptiness */
        if (pass) DBSetAllowEmptyObjects(1);

        /* Because references to the following objects will not ever appear in a
           multi-xxx object, we do not currently test for support of empties...
               DBPutUcdsubmesh, DBPutMrgtree, DBPutMrgvar, DBPutGroupelmap

           Note: 'ZZ' or 'ZDIMS' is the key argument in each call that triggers an empty
        */

        /* empty curve objects */
        ASSERT(DBPutCurve(dbfile,"empty_curvea",coords[0],coords[0],dt,ZZ,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutCurve(dbfile,"empty_curveb",        0,coords[0],dt,ZZ,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutCurve(dbfile,"empty_curvec",coords[0],        0,dt,ZZ,OL(ol)),retval<0,retval==0);

        /* empty point meshes and vars */
        ASSERT(DBPutPointmesh(dbfile,"empty_pointmesha",1,coords,ZZ,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutPointmesh(dbfile,"empty_pointmeshb",3,     0,ZZ,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutPointvar(dbfile,"pva","empty_pointmesha",1,vars,ZZ,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutPointvar(dbfile,"pvb","empty_pointmesha",3,   0,ZZ,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutPointvar1(dbfile,"pv1a","empty_pointmesha",var,ZZ,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutPointvar1(dbfile,"pv1b","empty_pointmesha",  0,ZZ,dt,OL(ol)),retval<0,retval==0);

        /* empty quad meshes and vars (ZDIMS is the magic zero'ing arg) */
        ASSERT(DBPutQuadmesh(dbfile,"empty_quadmesha",     0,coords,ZDIMS,1,dt,DB_COLLINEAR,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutQuadmesh(dbfile,"empty_quadmeshb",cnames,     0,ZDIMS,2,dt,DB_COLLINEAR,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutQuadmesh(dbfile,"empty_quadmeshc",cnames,coords,ZDIMS,3,dt,DB_COLLINEAR,OL(ol)),retval<0,retval==0);

        ASSERT(DBPutQuadvar(dbfile,"qva","empty_quadmesha",2,     0,vars,ZDIMS,2,0,0,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutQuadvar(dbfile,"qvb","empty_quadmesha",3,cnames,   0,ZDIMS,3,0,0,dt,ct,OL(ol)),retval<0,retval==0);

        ASSERT(DBPutQuadvar1(dbfile,"qv1a","empty_quadmesha",  0,ZDIMS,ZZ,var,0,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutQuadvar1(dbfile,"qv1b","empty_quadmesha",var,ZDIMS,ZZ,  0,0,dt,ct,OL(ol)),retval<0,retval==0);

        /* empty ucd meshes, facelists, zonelists and vars */
        ASSERT(DBPutUcdmesh(dbfile,"empty_ucdmesh1",3,cnames,coords,ZZ,1,"foo","bar",dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutUcdmesh(dbfile,"empty_ucdmesh2",1,     0,coords,ZZ,1,"foo","bar",dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutUcdmesh(dbfile,"empty_ucdmesh3",2,cnames,     0,ZZ,0,"foo","bar",dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutUcdmesh(dbfile,"empty_ucdmesh3",0,     0,     0,ZZ,0,    0,    0,dt,OL(ol)),retval<0,retval==0);

        ASSERT(DBPutFacelist(dbfile,"empty_facelista",ZZ,0,iarr,1,1,iarr,iarr,iarr,1,iarr,iarr,1),retval<0,retval==0);
        ASSERT(DBPutFacelist(dbfile,"empty_facelistb",ZZ,0,   0,1,1,iarr,iarr,iarr,1,iarr,iarr,1),retval<0,retval==0);
        ASSERT(DBPutFacelist(dbfile,"empty_facelistc",ZZ,0,iarr,1,1,   0,iarr,iarr,1,iarr,iarr,1),retval<0,retval==0);
        ASSERT(DBPutFacelist(dbfile,"empty_facelistd",ZZ,0,iarr,1,1,iarr,   0,iarr,1,iarr,iarr,1),retval<0,retval==0);
        ASSERT(DBPutFacelist(dbfile,"empty_faceliste",ZZ,0,iarr,1,1,iarr,iarr,   0,1,iarr,iarr,1),retval<0,retval==0);
        ASSERT(DBPutFacelist(dbfile,"empty_facelistf",ZZ,0,iarr,1,1,iarr,iarr,iarr,1,   0,iarr,1),retval<0,retval==0);
        ASSERT(DBPutFacelist(dbfile,"empty_facelistg",ZZ,0,iarr,1,1,iarr,iarr,iarr,1,iarr,   0,1),retval<0,retval==0);

        ASSERT(DBPutZonelist(dbfile,"empty_zonelista",ZZ,1,iarr,10,0,iarr,iarr,10),retval<0,retval==0);
        ASSERT(DBPutZonelist(dbfile,"empty_zonelistb",ZZ,1,   0,10,0,iarr,iarr,10),retval<0,retval==0);
        ASSERT(DBPutZonelist(dbfile,"empty_zonelistc",ZZ,1,iarr,10,0,   0,iarr,10),retval<0,retval==0);
        ASSERT(DBPutZonelist(dbfile,"empty_zonelistd",ZZ,1,iarr,10,0,iarr,    0,10),retval<0,retval==0);

        ASSERT(DBPutZonelist2(dbfile,"empty_zonelist2a",ZZ,1,iarr,1,0,0,0,iarr,iarr,iarr,1,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutZonelist2(dbfile,"empty_zonelist2b",ZZ,0,   0,1,3,3,3,iarr,iarr,iarr,1,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutZonelist2(dbfile,"empty_zonelist2c",ZZ,1,iarr,0,3,3,3,   0,iarr,iarr,1,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutZonelist2(dbfile,"empty_zonelist2d",ZZ,1,iarr,1,0,3,0,iarr,   0,iarr,0,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutZonelist2(dbfile,"empty_zonelist2e",ZZ,1,iarr,1,3,0,0,iarr,iarr,   0,1,OL(ol)),retval<0,retval==0);

        ASSERT(DBPutPHZonelist(dbfile,"empty_phzonelista",ZZ,iarr,1,iarr,cnames[0],1,iarr,1,iarr,0,0,0,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutPHZonelist(dbfile,"empty_phzonelistb",ZZ,   0,1,iarr,cnames[0],1,iarr,1,iarr,0,0,0,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutPHZonelist(dbfile,"empty_phzonelistc",ZZ,iarr,1,   0,cnames[0],1,iarr,1,iarr,0,0,0,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutPHZonelist(dbfile,"empty_phzonelistd",ZZ,iarr,1,iarr,        0,1,iarr,1,iarr,0,0,0,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutPHZonelist(dbfile,"empty_phzoneliste",ZZ,iarr,1,iarr,cnames[0],1,   0,1,iarr,0,0,0,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutPHZonelist(dbfile,"empty_phzonelistf",ZZ,iarr,1,iarr,cnames[0],1,iarr,1,   0,0,0,0,OL(ol)),retval<0,retval==0);

        ASSERT(DBPutUcdvar(dbfile,"uva","empty_ucdmesh1",0,cnames,vars,ZZ,vars,1,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutUcdvar(dbfile,"uvb","empty_ucdmesh1",1,     0,vars,ZZ,vars,1,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutUcdvar(dbfile,"uvc","empty_ucdmesh1",2,cnames,   0,ZZ,vars,1,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutUcdvar(dbfile,"uvd","empty_ucdmesh1",3,cnames,vars,ZZ,   0,1,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutUcdvar(dbfile,"uve","empty_ucdmesh1",3,     0,   0,ZZ,   0,1,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutUcdvar1(dbfile,"uv1a","empty_ucdmesh1",var,ZZ,vars[0],1,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutUcdvar1(dbfile,"uv1b","empty_ucdmesh1",  0,ZZ,vars[0],1,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutUcdvar1(dbfile,"uv1c","empty_ucdmesh1",var,ZZ,      0,1,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutUcdvar1(dbfile,"uv1d","empty_ucdmesh1",  0,ZZ,      0,1,dt,ct,OL(ol)),retval<0,retval==0);

        /* csg meshes and vars */
        ASSERT(DBPutCsgmesh(dbfile,"empty_csgmesh1",2,ZZ,   0,iarr,var,1,dt,exts,"foo",OL(ol)),retval<0,retval==0);
        ASSERT(DBPutCsgmesh(dbfile,"empty_csgmesh2",2,ZZ,iarr,   0,var,2,dt,exts,"foo",OL(ol)),retval<0,retval==0);
        ASSERT(DBPutCsgmesh(dbfile,"empty_csgmesh3",3,ZZ,iarr,iarr,  0,3,dt,exts,"foo",OL(ol)),retval<0,retval==0);
        ASSERT(DBPutCsgmesh(dbfile,"empty_csgmesh4",3,ZZ,iarr,iarr,var,0,dt,exts,"foo",OL(ol)),retval<0,retval==0);

        ASSERT(DBPutCSGZonelist(dbfile,"empty_csgzonelista",0,iarr,iarr,iarr,0,0,dt,ZZ,iarr,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutCSGZonelist(dbfile,"empty_csgzonelistb",1,   0,iarr,iarr,0,0,dt,ZZ,iarr,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutCSGZonelist(dbfile,"empty_csgzonelistc",1,iarr,   0,iarr,0,0,dt,ZZ,iarr,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutCSGZonelist(dbfile,"empty_csgzonelistd",1,iarr,iarr,   0,0,0,dt,ZZ,iarr,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutCSGZonelist(dbfile,"empty_csgzoneliste",1,iarr,iarr,iarr,0,0,dt,ZZ,   0,OL(ol)),retval<0,retval==0);

        ASSERT(DBPutCsgvar(dbfile,"csgva","empty_csgmesh1",0,cnames,vvars,ZZ,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutCsgvar(dbfile,"csgvb","empty_csgmesh1",1,     0,vvars,ZZ,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutCsgvar(dbfile,"csgvc","empty_csgmesh1",1,cnames,   0, ZZ,dt,ct,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutCsgvar(dbfile,"csgvd","empty_csgmesh1",1,cnames,vvars,ZZ,dt,ct,OL(ol)),retval<0,retval==0);

        /* empty materials and species */
        ASSERT(DBPutMaterial(dbfile,"empty_mata","foo",1,iarr,iarr,ZDIMS,1,iarr,iarr,iarr,vars[0],1,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutMaterial(dbfile,"empty_matb","foo",1,   0,iarr,ZDIMS,1,iarr,iarr,iarr,vars[0],1,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutMaterial(dbfile,"empty_matc","foo",1,iarr,   0,ZDIMS,1,iarr,iarr,iarr,vars[0],1,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutMaterial(dbfile,"empty_matd","foo",1,iarr,iarr,ZDIMS,1,   0,iarr,iarr,vars[0],1,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutMaterial(dbfile,"empty_mate","foo",1,iarr,iarr,ZDIMS,1,iarr,   0,iarr,vars[0],1,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutMaterial(dbfile,"empty_matf","foo",1,iarr,iarr,ZDIMS,1,iarr,iarr,   0,vars[0],1,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutMaterial(dbfile,"empty_matg","foo",1,iarr,iarr,ZDIMS,1,iarr,iarr,iarr,   0,1,dt,OL(ol)),retval<0,retval==0);

        /* empty matspecies via dims[i] == 0 */
        ASSERT(DBPutMatspecies(dbfile,"empty_speca","empty_mata",1,iarr,iarr,ZDIMS,1,1,var,iarr,1,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutMatspecies(dbfile,"empty_specb","empty_mata",1,iarr,iarr,ZDIMS,2,1,var,iarr,1,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutMatspecies(dbfile,"empty_specc","empty_mata",1,iarr,iarr,ZDIMS,3,1,var,iarr,1,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutMatspecies(dbfile,"empty_specd","empty_mata",1,iarr,iarr,ZDIMS,1,1,  0,iarr,1,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutMatspecies(dbfile,"empty_spece","empty_mata",1,iarr,iarr,ZDIMS,1,1,var,   0,0,dt,OL(ol)),retval<0,retval==0);

        /* empty matspeces via nspecies_mf==0 */
        { int nd=2, d[2]={3,2}, slm[6]={0,0,-1,-3,0,0}, ml=4, msl[4]={1,2,1,2}, slc[6]={0,0,0,0,0,0};
        ASSERT(DBPutMatspecies(dbfile,"empty_specf","empty_mata",1,iarr,slc,d,nd,ZZ,var,  0, 0,dt,OL(ol)),retval<0,retval==0);
        ASSERT(DBPutMatspecies(dbfile,"empty_specg","empty_mata",1,iarr,slm,d,nd,ZZ,var,msl,ml,dt,OL(ol)),retval<0,retval==0);
        }
    }

    DBClose(dbfile);
    dbfile = 0;

    /* Ok, now try to read each empty object to make sure we get what we expect and nothing fails */
    dbfile = DBOpen(filename, DB_UNKNOWN, DB_READ);

    /* test read back of empty curves */
    {   int i=0; char *cnames[] = {"empty_curvea", "empty_curveb", "empty_curvec", 0};
        DBSetDir(dbfile, "DBPutCurve");
        while (cnames[i])
        {
            DBcurve *curve = DBGetCurve(dbfile, cnames[i++]);
            assert(DBIsEmptyCurve(curve));
            DBFreeCurve(curve);
        }
        DBSetDir(dbfile, "..");
    }

    /* test read back of empty point meshes and vars */
    {   int i=0; char *pmnames[] = {"empty_pointmesha", "empty_pointmeshb", 0};
        DBSetDir(dbfile, "DBPutPointmesh");
        while (pmnames[i])
        {
            DBpointmesh *pointmesh = DBGetPointmesh(dbfile, pmnames[i++]);
            assert(DBIsEmptyPointmesh(pointmesh));
            DBFreePointmesh(pointmesh);
        }
        DBSetDir(dbfile, "..");
    }
    {   int i=0; char *vnames[] = {"pva", "pvb", "pv1a", "pv1b", 0};
        DBSetDir(dbfile, "DBPutPointvar");
        while (vnames[i])
        {
            DBpointvar *pointvar = DBGetPointvar(dbfile, vnames[i++]);
            assert(DBIsEmptyPointvar(pointvar));
            DBFreePointvar(pointvar);
        }
        DBSetDir(dbfile, "..");
    }

    /* test read back of empty quad meshes and vars */
    {   int i=0; char *qmnames[] = {"empty_quadmesha", "empty_quadmeshb", "empty_quadmeshc", 0};
        DBSetDir(dbfile, "DBPutQuadmesh");
        while (qmnames[i])
        {
            DBquadmesh *quadmesh = DBGetQuadmesh(dbfile, qmnames[i++]);
            assert(DBIsEmptyQuadmesh(quadmesh));
            DBFreeQuadmesh(quadmesh);
        }
        DBSetDir(dbfile, "..");
    }
    {   int i=0; char *vnames[] = {"qva" , "qvb", "qv1a", "qv1b",  0};
        DBSetDir(dbfile, "DBPutQuadvar");
        while (vnames[i])
        {
            DBquadvar *quadvar = DBGetQuadvar(dbfile, vnames[i++]);
            assert(DBIsEmptyQuadvar(quadvar));
            DBFreeQuadvar(quadvar);
        }
        DBSetDir(dbfile, "..");
    }

    /* test read back of empty ucd meshes, zonelists and vars */
    {   int i=0; char *mnames[] = {"empty_ucdmesh1", "empty_ucdmesh2", "empty_ucdmesh3", 0};
        DBSetDir(dbfile, "DBPutUcdmesh");
        while (mnames[i])
        {
            DBucdmesh *ucdmesh = DBGetUcdmesh(dbfile, mnames[i++]);
            assert(DBIsEmptyUcdmesh(ucdmesh));
            DBFreeUcdmesh(ucdmesh);
        }
        DBSetDir(dbfile, "..");
    }
    {   int i=0; char *flnames[] = {"empty_facelista", "empty_facelistb",
                                    "empty_facelistc", "empty_facelistd",
                                    "empty_faceliste", "empty_facelistf",
                                    "empty_facelistg", 0};
        DBSetDir(dbfile, "DBPutFacelist");
        while (flnames[i])
        {
            DBfacelist *fl = DBGetFacelist(dbfile, flnames[i++]);
            assert(DBIsEmptyFacelist(fl));
            DBFreeFacelist(fl);
        }
        DBSetDir(dbfile, "..");
    }
    {   int i=0; char *zlnames[] = {"empty_zonelista", "empty_zonelistb",
                                    "empty_zonelistc", "empty_zonelistd",
                                    "empty_zonelist2a", "empty_zonelist2b",
                                    "empty_zonelist2c", "empty_zonelist2d",
                                    "empty_zonelist2e", 0};
        DBSetDir(dbfile, "DBPutZonelist");
        while (zlnames[i])
        {
            DBzonelist *zl = DBGetZonelist(dbfile, zlnames[i++]);
            assert(DBIsEmptyZonelist(zl));
            DBFreeZonelist(zl);
        }
        DBSetDir(dbfile, "..");
    }
    {   int i=0; char *zlnames[] = {"empty_phzonelista", "empty_phzonelistb",
                                    "empty_phzonelistc", "empty_phzonelistd",
                                    "empty_phzoneliste", "empty_phzonelistf", 0};
        DBSetDir(dbfile, "DBPutPHZonelist");
        while (zlnames[i])
        {
            DBphzonelist *zl = DBGetPHZonelist(dbfile, zlnames[i++]);
            assert(DBIsEmptyPHZonelist(zl));
            DBFreePHZonelist(zl);
        }
        DBSetDir(dbfile, "..");
    }
    {   int i=0; char *vnames[] = { "uva",  "uvb",  "uvc",
                                    "uvd",  "uve",  "uv1a",
                                    "uv1b", "uv1c", "uv1d", 0};
        DBSetDir(dbfile, "DBPutUcdvar");
        while (vnames[i])
        {
            DBucdvar *ucdvar = DBGetUcdvar(dbfile, vnames[i++]);
            assert(DBIsEmptyUcdvar(ucdvar));
            DBFreeUcdvar(ucdvar);
        }
        DBSetDir(dbfile, "..");
    }

    /* test read back of empty csg meshes and vars */
    {   int i=0; char *mnames[] = {"empty_csgmesh1", "empty_csgmesh2", "empty_csgmesh3", 0};
        DBSetDir(dbfile, "DBPutCsgmesh");
        while (mnames[i])
        {
            DBcsgmesh *csgmesh = DBGetCsgmesh(dbfile, mnames[i++]);
            assert(DBIsEmptyCsgmesh(csgmesh));
            DBFreeCsgmesh(csgmesh);
        }
        DBSetDir(dbfile, "..");
    }
    {   int i=0; char *zlnames[] = {"empty_csgzonelista", "empty_csgzonelistb",
                                    "empty_csgzonelistc", "empty_csgzonelistd", 
                                    "empty_csgzoneliste", 0};
        DBSetDir(dbfile, "DBPutCSGZonelist");
        while (zlnames[i])
        {
            DBcsgzonelist *zl = DBGetCSGZonelist(dbfile, zlnames[i++]);
            assert(DBIsEmptyCSGZonelist(zl));
            DBFreeCSGZonelist(zl);
        }
        DBSetDir(dbfile, "..");
    }
    {   int i=0; char *vnames[] = {"csgva", "csgvb", "csgvc", "csgvd", 0};
        DBSetDir(dbfile, "DBPutCsgvar");
        while (vnames[i])
        {
            DBcsgvar *csgvar = DBGetCsgvar(dbfile, vnames[i++]);
            assert(DBIsEmptyCsgvar(csgvar));
            DBFreeCsgvar(csgvar);
        }
        DBSetDir(dbfile, "..");
    }

    /* test read back of empty materials and matspecies */
    {   int i=0; char *vnames[] = {"empty_mata", "empty_matb", "empty_matc", "empty_matd",
                                   "empty_mate", "empty_matf", "empty_matg", 0};
        DBSetDir(dbfile, "DBPutMaterial");
        while (vnames[i])
        {
            DBmaterial *mat = DBGetMaterial(dbfile, vnames[i++]);
            assert(DBIsEmptyMaterial(mat));
            DBFreeMaterial(mat);
        }
        DBSetDir(dbfile, "..");
    }
    {   int i=0; char *vnames[] = {"empty_speca", "empty_specb", "empty_specc",
                                   "empty_specd", "empty_spece", "empty_specf", 
                                   "empty_specg", 0};
        DBSetDir(dbfile, "DBPutMatspecies");
        while (vnames[i])
        {
            DBmatspecies *spec = DBGetMatspecies(dbfile, vnames[i++]);
            assert(DBIsEmptyMatspecies(spec));
            DBFreeMatspecies(spec);
        }
        DBSetDir(dbfile, "..");
    }

    DBClose(dbfile);

    CleanupDriverStuff();

    return 0;
}
Beispiel #13
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;
}
Beispiel #14
0
void WriteMesh_SILO(DBfile *dbfile, char *mesh_name, int *dims, 
                    float **mesh_coords, int cycle, double time) {
    int i, j, k, n, Ntot;
    int Nq = dims[0], Nr = dims[1], Ns = dims[2];
    float *q = mesh_coords[0], *r = mesh_coords[1], *s = mesh_coords[2];
    float *s_ghost = NULL;
    

    //if halfcyl, just extend array. else ie. periodic, add ghost zones/
    if(half_cyl){
         Ns+=1;
         s_ghost=new float[Ns];
         //copy array across into new slightly alrger array
         for(k=0;k<Ns-1;k++){
                    s_ghost[k]=s[k];
         }
         //add final phi=pi point
         s_ghost[Ns-1]=s_ghost[Ns-2]+s_ghost[1];
    }else{
         AddGhostZones_Coord(s,s_ghost,Ns);               
    }
    Ntot = Nq*Nr*Ns;
    
    float *xg=NULL, *yg=NULL, *zg=NULL;
    xg = new float[Ntot];
    yg = new float[Ntot];
    zg = new float[Ntot];
    
    n = 0;
    for(k=0; k<Ns; k++) { 
        for(j=0; j<Nr; j++) {
            for(i=0; i<Nq; i++) {
                xg[n] = r[j]*cos(s_ghost[k]);
                yg[n] = r[j]*sin(s_ghost[k]);
                zg[n] = q[i];
                n++;
            } 
        }
    }
    
    delete [] s_ghost;
    
    // Create the arrays to write to the .silo database:
    int silodims[ndims] = {Nq,Nr,Ns};
    float *coords[ndims] = {(float*)xg, (float*)yg, (float*)zg};
    
    // Create an option list to save cycle and time values:
    DBoptlist *optlist = DBMakeOptlist(4);
    if(!half_cyl){
          int offset_low[ndims] = {0,0,Nghost};
          int offset_high[ndims] = {0,0,Nghost};
          DBAddOption(optlist, DBOPT_LO_OFFSET, offset_low);
          DBAddOption(optlist, DBOPT_HI_OFFSET, offset_high);                  
    }
    DBAddOption(optlist, DBOPT_DTIME, &time);
    DBAddOption(optlist, DBOPT_CYCLE, &cycle);

    // DBAddOption(optlist, DBOPT_COORDSYS, DB_CYLINDRICAL);

    // Write the mesh to the .silo file:
    DBPutQuadmesh(dbfile, mesh_name, NULL, coords, silodims, ndims,
                  DB_FLOAT, DB_NONCOLLINEAR, optlist);
                  
    DBFreeOptlist(optlist);
    
    delete [] xg;
    delete [] yg;
    delete [] zg;
    
}
Beispiel #15
0
static void
build_csg(DBfile *dbfile, char *name)
{
    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_SPHERE_PR,
            DBCSG_PLANE_X,
            DBCSG_PLANE_X,
            DBCSG_CYLINDER_PNLR,
            //DBCSG_QUADRIC_G,
            DBCSG_SPHERE_PR,
            DBCSG_SPHERE_PR
        };

        float coeffs[] =
        {
            0.0, 0.0, 0.0, 5.0,                // point-radius form of sphere
           -2.0,                               // x-intercept form of plane
            2.0,                               // x-intercept form of plane
           -10.0, 0.0, 0.0, 1.0, 0.0, 0.0, 20.0, 4.5, // point-normal-length-radius form of cylinder
          //  0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -20.25,
            0.0, 0.0, 49.5, 50.0,              // point-radius form of sphere
            0.0, 0.0, -49.5, 50.0              // point radius form of sphere
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

        DBPutCsgmesh(dbfile, name, 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "csgzl", NULL);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,       // 0: inside of sphere
            DBCSG_OUTER,       // 1: in-front of -X plane
            DBCSG_INNER,       // 2: in-back of +X plane 
            DBCSG_INNER,       // 3: inside of quadric cylinder
            DBCSG_INTERSECT,   // 4: sphere cut to -X plane
            DBCSG_INTERSECT,   // 5: -X-cut-sphere cut to +X plane
            DBCSG_DIFF,        // 6: cut-sphere minus quadric cylinder
            DBCSG_INNER,       // 7: inside of large upper sphere
            DBCSG_INNER,       // 8: inside of large lower sphere
            DBCSG_INTERSECT,   // 9: intersection of large spheres
            DBCSG_INTERSECT,   //10: 9 cut to inside of quadric cylinder 
            DBCSG_INTERSECT    //11: 10 cut to inside of smaller sphere 
        };
        //                 0   1   2   3   4   5   6   7   8   9  10  11
        int leftids[] =  { 0,  1,  2,  3,  0,  4,  5,  4,  5,  7,  9, 10};
        int rightids[] = {-1, -1, -1, -1,  1,  2,  3, -1, -1,  8,  3, 0}; 
        int zonelist[] = {6, 11};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

        char *zonenames[] = {"ring housing", "lens-shaped fin"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);

        DBFreeOptlist(optlist);
    }

    // output a csg variable
    {
        void *pv[1];
        double var1_data[] = {10.0, 100.0};
        char *pname[1];
        char name1[] = "var1";

        pv[0] = var1_data;
        pname[0] = name1;

#ifdef DB_SDX // Use existence of sdx driver to detect earlier versions.
              // Sdx driver exists in 4.5.1 and earlier.
        DBPutCsgvar(dbfile, "var1", "csgmesh", 1, (const char**)pname,
                    (const void**)pv, 2, DB_DOUBLE, DB_ZONECENT, 0);
#else
        DBPutCsgvar(dbfile, "var1", "csgmesh", 1, pname,
                    pv, 2, DB_DOUBLE, DB_ZONECENT, 0);
#endif
    }

    // output a material for this csg mesh
    {
        int matnos[] = {2, 3};
        int matlist[] = {2, 3};
        int dims = 2;
        DBPutMaterial(dbfile, "mat", "csgmesh", 2,  matnos,  matlist, &dims, 1,
            0, 0, 0, 0, 0, DB_FLOAT, 0);
    }
}
Beispiel #16
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);
    }
}
Beispiel #17
0
// This mesh is based on some test data from Greg Greenman
static void
build_greenman_csg(DBfile *dbfile, char *name)
{
    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_QUADRIC_G,
            DBCSG_QUADRIC_G,
            DBCSG_QUADRIC_G,
            DBCSG_QUADRIC_G,
            DBCSG_QUADRIC_G,
            DBCSG_QUADRIC_G
        };

        const float c0 = .464102;
        const float c1 = .707107;
        const float c2 = -1.0718;
        float coeffs[] =
        {
         // x^2  y^2  z^2  xy   yz   xz    x    y    z    c
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0,    // 0: "bottom" 
            1.0,  c0,  c0, 0.0,  c2, 0.0, 0.0, 0.0, 0.0, 0.0,    // 1: "cone"
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  c1,  c1, 0.0,    // 2: "cone_apex"
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  c1,  c1,-4.0,    // 3: "cone_end"
            1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -100.0, // 4: "cylinder"
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, -10.0   // 5: "top" 
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

        //double extents[] = {0.0, 0.0, 0.0, 10.0, 10.0, 10.0};
        double extents[] = {-10.0, -10.0, -10.0, 20.0, 20.0, 20.0};

        char *bndnames[] = {"bottom", "cone", "cone_apex", "cone_end",
                            "cylinder", "top"};

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

        DBPutCsgmesh(dbfile, name, 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "greenman_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_OUTER,          // 0: above bottom plane
            DBCSG_INNER,          // 1: below top plane
            DBCSG_INNER,          // 2: inside of cylinder
            DBCSG_INTERSECT,      // 3: between top/bottom
            DBCSG_INTERSECT,      // 4: cylinder clipped to between top/bottom
            DBCSG_OUTER,          // 5: outside of cylinder
            DBCSG_INTERSECT,      // 6: oustide of cylinder cliped to between top/bottom
            DBCSG_INNER,          // 7: inside of cone
            DBCSG_INNER,          // 8: below cone_end plane
            DBCSG_OUTER,          // 9: above cone_apex plane
            DBCSG_INTERSECT,      //10: between cone planes 
            DBCSG_INTERSECT,      //11: inside of cone between cone planes
            DBCSG_DIFF            //12: cylinder minus cone
        };
        //                 0   1   2   3   4   5   6   7   8   9  10  11  12
        int leftids[] =  { 0,  5,  4,  0,  3,  4,  5,  1,  3,  2,  8, 10,  4};
        int rightids[] = {-1, -1, -1,  1,  2, -1,  3, -1, -1, -1,  9,  7, 11};
        int zonelist[] = {6, 11, 12};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

        char *zonenames[] = {"void", "uranium", "air"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "greenman_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }
}
Beispiel #18
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	
 *
 * Return:	0
 *
 * Programmer:	
 *
 * Modifications:
 * 	Robb Matzke, 1999-04-09
 *	Added argument parsing to control the driver which is used.
 *
 *-------------------------------------------------------------------------
 */
int
main(int argc, char *argv[])
{
    int            i,j;
    DBfile        *file = NULL;
    char          *coordnames[2];  /* Name the axes */
    float          xcoords[NX + 1];
    float          ycoords[NY + 1];
    float         *coordinates[2];
    int            dims[2];
    float          float_var[NX*NY];
    float          dist_var[NX*NY];
    float          density_var[NX*NY];
    float          total_length, frac_length;
    int            matnos[2];
    int            nmatspec[2];
    float          species_mf[MAX_MIX_LEN];
    int            matlist[MAX_MIX_LEN];
    int            speclist[MAX_MIX_LEN];
    int            nspecies_mf;
    float          dist;
    DBoptlist      *optlist;
    int            value;
    int		   driver=DB_PDB;
    char	   *filename="species.silo";
    int            show_all_errors = FALSE;

    /* Parse command-line */
    for (i=1; i<argc; i++) {
	if (!strncmp(argv[i], "DB_PDB", 6)) {
	    driver = StringToDriver(argv[i]);
	    filename = "species.pdb";
	} else if (!strncmp(argv[i], "DB_HDF5", 7)) {
            driver = StringToDriver(argv[i]);
	    filename = "species.h5";
        } else if (!strcmp(argv[i], "show-all-errors")) {
            show_all_errors = 1;
	} else if (argv[i][0] != '\0') {
	    fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
	}
    }
    
    if (show_all_errors) DBShowErrors(DB_ALL_AND_DRVR, 0);

    printf("Creating a 2D rectilinear SILO file `%s'...\n", filename);

    /* Create the SILO file */
    if ((file = DBCreate(filename, DB_CLOBBER, DB_LOCAL, NULL,
			 driver)) == NULL)
    {
        fprintf(stderr, "Unable to create SILO file\n");
        exit(1);
    }

    /* Name the coordinate axes 'X' and 'Y' */
    coordnames[0] = (char *) _db_safe_strdup("X");
    coordnames[1] = (char *) _db_safe_strdup("Y");

    /* Set up the coordinate values */

    /* X Coordinates */
    for(i=0;i<NX+1;i++)
        xcoords[i] = ((double)i)/NX;

    /* Y Coordinates */
    for(j=0;j<NY+1;j++)
        ycoords[j] = ((double)j)/NY;

    coordinates[0] = xcoords;
    coordinates[1] = ycoords;

    /* Enumerate the dimensions (4 values in x direction, 3 in y) */
    dims[0] = NX + 1;
    dims[1] = NY + 1;

    /* Write out the mesh to the file */
    DBPutQuadmesh(file, "quad_mesh", (DBCAS_t) coordnames,
        coordinates, dims, 2, DB_FLOAT, DB_COLLINEAR, NULL);

    /* Set up the material and species information */

    /* Material numbers */
    matnos[0] = 1;
    matnos[1] = 2;

    /* Material species numbers */
    nmatspec[0] = 3;
    nmatspec[1] = 1;

    printf("Calculating material information.\n");
    /* Mixed species array */
    nspecies_mf = 0;
    for(j=0;j<NY;j++)
    {
        for(i=0;i<NX;i++)
        {
            if (xcoords[i] >= 0.8)
            {
                matlist[j*NX+i] = 2;

                /* All one species */
                speclist[j*NX+i] = nspecies_mf + 1;
                species_mf[nspecies_mf++] = 1.0;
            }
            else
            {
                matlist[j*NX+i] = 1;

                speclist[j*NX+i] = nspecies_mf + 1;

                if (xcoords[i+1] < (1.0/3.0))
                {
                    /* All on left - All species 1 */
                    species_mf[nspecies_mf++] = 1.0;
                    species_mf[nspecies_mf++] = 0.0;
                    species_mf[nspecies_mf++] = 0.0;
                } else if ((xcoords[i] > (1.0/3.0)) && (xcoords[i+1] < (2.0/3.0)))
                {
                    /* All in middle - All species 2 */
                    species_mf[nspecies_mf++] = 0.0;
                    species_mf[nspecies_mf++] = 1.0;
                    species_mf[nspecies_mf++] = 0.0;
                } else if (xcoords[i] > (2.0/3.0))
                {
                    /* All on right - All species 3 */
                    species_mf[nspecies_mf++] = 0.0;
                    species_mf[nspecies_mf++] = 0.0;
                    species_mf[nspecies_mf++] = 1.0;
                } else
                {
                    /* Somewhere on a boundary */
                    if (xcoords[i] < (1.0/3.0))
                    {
                        /* Left boundary */
                        total_length = (xcoords[i+1] - xcoords[i]);
                        frac_length = ((1.0/3.0) - xcoords[i]);
                        species_mf[nspecies_mf++] = (frac_length/total_length);
                        species_mf[nspecies_mf++] = 1 - (frac_length/total_length);
                        species_mf[nspecies_mf++] = 0.0;
                    } else
                    {
                        /* Right boundary */
                        total_length = (xcoords[i+1] - xcoords[i]);
                        frac_length = ((2.0/3.0) - xcoords[i]);
                        species_mf[nspecies_mf++] = 0.0;
                        species_mf[nspecies_mf++] = (frac_length/total_length);
                        species_mf[nspecies_mf++] = 1 - (frac_length/total_length);
                    }
                }
            }
        }
    }

    /* The dimensions have changed since materials are defined for zones,
     * not for nodes */
    dims[0] = NX;
    dims[1] = NY;

    if (nspecies_mf>MAX_MIX_LEN)
    {
        fprintf(stderr,"Length %d of mixed species arrays exceeds the max %d.\n",
            nspecies_mf,MAX_MIX_LEN);
        fprintf(stderr,"Memory may have been corrupted, and the SILO\n");
        fprintf(stderr,"file may be invalid.\n");
    }

    /* Write out the material to the file */
    DBPutMaterial(file, "mat1", "quad_mesh", 2, matnos, matlist, dims, 2, NULL,
                  NULL, NULL, NULL, 0, DB_FLOAT, NULL);

    /* Write out the material species to the file */
    DBPutMatspecies(file, "matspec1", "mat1", 2, nmatspec, speclist, dims,
                    2, nspecies_mf, species_mf, NULL, 0, DB_FLOAT, NULL);

    free(coordnames[0]);
    free(coordnames[1]);

    printf("Calculating variables.\n");
    /* Set up the variables */
    for(j=0;j<NY;j++)
        for(i=0;i<NX;i++)
        {
            dist = distance((xcoords[i]+xcoords[i+1])/2,(ycoords[j]+ycoords[j+1])/2,0.5,0.5);
            float_var[j*NX+i] = cos(SCALE*dist)/exp(dist*DAMP);
            dist_var[j*NX+i] = dist;
            if (xcoords[i]<(1.0/3.0))
                density_var[j*NX+i] = 30.0;
            else if ((xcoords[i]<(2.0/3.0)) || (xcoords[i] >= 0.8))
                density_var[j*NX+i] = 1000.0;
            else
                density_var[j*NX+i] = 200.0;
        }

    /* Make a DBoptlist so that we can tell the variables to use the
       material species stuff */

    optlist = DBMakeOptlist(1);
    value = DB_ON;
    DBAddOption(optlist, DBOPT_USESPECMF, &value);

    /* Write the data variables to the file */
    DBPutQuadvar1(file, "float_var", "quad_mesh", float_var, dims, 2, NULL,
                  0, DB_FLOAT, DB_ZONECENT, optlist);
    DBPutQuadvar1(file, "dist_var", "quad_mesh", dist_var, dims, 2, NULL,
                  0, DB_FLOAT, DB_ZONECENT, optlist);
    DBPutQuadvar1(file, "density_var", "quad_mesh", density_var, dims, 2, NULL,
                  0, DB_FLOAT, DB_ZONECENT, optlist);

    DBFreeOptlist(optlist);
    DBClose(file);

    printf("Finished.\n");

    CleanupDriverStuff();
    return (0);
}
Beispiel #19
0
void perform_write(
    hpx::lcos::local::channel<void>& sync
  , octree_server& e
  , DBfile* file 
  , std::vector<std::string> const& directory_names
  , std::string const& variable_name
  , boost::uint64_t variable_index
    )
{ // {{{
    boost::uint64_t const bw = science().ghost_zone_length;
    boost::uint64_t const gnx = config().grid_node_length;

    boost::uint64_t level = e.get_level();

    int nnodes[] = {
        int(gnx - 2 * bw + 1)
      , int(gnx - 2 * bw + 1)
      , int(gnx - 2 * bw + 1)
    };

    int nzones[] = {
        int(gnx - 2 * bw) 
      , int(gnx - 2 * bw) 
      , int(gnx - 2 * bw) 
    };

    //char* coordinate_names[] = { (char*) "X", (char*) "Y", (char*) "Z" };

    boost::scoped_array<double*> coordinates(new double* [3]);
    coordinates[0] = new double [nnodes[0]];
    coordinates[1] = new double [nnodes[1]];
    coordinates[2] = new double [nnodes[2]];

    boost::scoped_array<double> variables
        (new double [nzones[0] * nzones[1] * nzones[2]]);

    for (boost::uint64_t i = bw; i < (gnx - bw + 1); ++i) 
    {
        coordinates[0][i - bw] = e.x_face(i); 
        coordinates[1][i - bw] = e.y_face(i); 
        coordinates[2][i - bw] = e.z_face(i); 
    }

    for (boost::uint64_t i = bw; i < (gnx - bw); ++i) 
        for (boost::uint64_t j = bw; j < (gnx - bw); ++j) 
            for (boost::uint64_t k = bw; k < (gnx - bw); ++k) 
            {
                boost::uint64_t index = (i - bw)
                                      + (j - bw) * nzones[0]
                                      + (k - bw) * nzones[0] * nzones[1];
                variables[index] = e(i, j, k)[variable_index];
            }

    array<boost::uint64_t, 3> location = e.get_location();

    std::string mesh_name
        = boost::str( boost::format("mesh_L%i_%i_%i_%i")
                    % level
                    % location[0]
                    % location[1]
                    % location[2]);

    std::string value_name
        = boost::str( boost::format("%s_L%i_%i_%i_%i")
                    % variable_name
                    % level
                    % location[0]
                    % location[1]
                    % location[2]);

    int error = DBSetDir(file, directory_names[level].c_str());
    OCTOPUS_ASSERT(error == 0);

    {
        DBoptlist* optlist = DBMakeOptlist(1);
        // REVIEW: Verify this.
        int type = DB_ROWMAJOR;
        DBAddOption(optlist, DBOPT_MAJORORDER, &type);
        error = DBPutQuadmesh(file
                            , mesh_name.c_str()
                            //, coordinate_names
                            , NULL // SILO docs say this is ignored.
                            , coordinates.get()
                            , nnodes
                            , 3, DB_DOUBLE, DB_COLLINEAR, optlist);
        OCTOPUS_ASSERT(error == 0);
    }

    {
        DBoptlist* optlist = DBMakeOptlist(3);
        // REVIEW: Verify this.
        int type = DB_ROWMAJOR;
        DBAddOption(optlist, DBOPT_MAJORORDER, &type);
        error = DBPutQuadvar1(file
                            , value_name.c_str()
                            , mesh_name.c_str()
                            , variables.get()
                            , nzones
                            , 3, NULL, 0, DB_DOUBLE, DB_ZONECENT, optlist);
        OCTOPUS_ASSERT(error == 0);
    }

    delete[] coordinates[0];
    delete[] coordinates[1];
    delete[] coordinates[2]; 

    sync.post();
} // }}}
Beispiel #20
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();
} // }}}
Beispiel #21
0
/*----------------------------------------------------------------------------
 * Function: writemesh_ucd2d()
 *
 * Inputs:   db (DBfile*): the Silo file handle
 *
 * Returns:  (void)
 *
 * Abstract: Write the mesh and variables stored in the global Mesh 
 *           to the Silo file as a UCDmesh and UCDvars
 *
 * Modifications:
 *---------------------------------------------------------------------------*/
void writemesh_ucd2d(DBfile *db, int mixc, int reorder) {

  int   nl[5000];
  float f1[1000],f2[1000], fm[1000];
  int x,y,c;
  float *coord[2];
  int dims[2];
  char *cnvar, *czvar;
  short *snvar, *szvar;
  int *invar, *izvar;
  long *lnvar, *lzvar;
  long long *Lnvar, *Lzvar;
  float *fnvar, *fzvar;
  double *dnvar, *dzvar;

  int lnodelist;
  int nnodes;
  int nzones;
  int shapesize[1];
  int shapecnt[1];
  int shapetyp[1];

  /* do mesh */
  c=0;
  for (x=0;x<mesh.nx;x++) {
    for (y=0;y<mesh.ny;y++) {
      f1[c]=mesh.node[x][y].x;
      f2[c]=mesh.node[x][y].y;
      if (mesh.node[x][y].c != c) {
	printf("Node mismatch! mesh.c=%d c=%d\n",mesh.node[x][y].c,c);
	exit(-1);
      }
      c++;
    }
  }

  coord[0]=f1;
  coord[1]=f2;

  dims[0]=mesh.nx;
  dims[1]=mesh.ny;

  /* create the zonelist */
  c=0;
  for (x=0;x<mesh.zx;x++) {
    for (y=0;y<mesh.zy;y++) {
      nl[c++] = mesh.zone[x][y].n[0][0]->c;
      nl[c++] = mesh.zone[x][y].n[1][0]->c;
      nl[c++] = mesh.zone[x][y].n[1][1]->c;
      nl[c++] = mesh.zone[x][y].n[0][1]->c;
    }
  }
  lnodelist=c;

  nnodes=mesh.nx*mesh.ny;
  nzones=mesh.zx*mesh.zy;
  shapesize[0]=4;
  shapecnt[0]=nzones;
  shapetyp[0]=DB_ZONETYPE_QUAD;

  DBPutZonelist2(db,"Mesh_zonelist",nzones,2,nl,lnodelist,0,0,0,shapetyp,shapesize,shapecnt,1,NULL);
  DBPutUcdmesh (db,"Mesh",2,NULL,coord,nnodes,nzones,"Mesh_zonelist",NULL,DB_FLOAT,NULL);

  /* test output of ghost node and zone labels */
  {
      int i;
      char *gn = (char*)calloc(nnodes,1);
      char *gz = (char*)calloc(nzones,1);
      DBoptlist *ol = DBMakeOptlist(5);

      for (i = 0; i < nnodes; i++)
      {
          if (!(i % 3)) gn[i] = 1;
      } 
      for (i = 0; i < nzones; i++)
      {
          if (!(i % 7)) gz[i] = 1;
      } 

      DBAddOption(ol, DBOPT_GHOST_NODE_LABELS, gn);
      DBPutUcdmesh (db,"Mesh_gn",2,NULL,coord,nnodes,nzones,"Mesh_zonelist",NULL,DB_FLOAT,ol);
      DBClearOption(ol, DBOPT_GHOST_NODE_LABELS);

      DBPutUcdmesh (db,"Mesh_gz",2,NULL,coord,nnodes,nzones,"Mesh_zonelist_gz",NULL,DB_FLOAT,NULL);
      DBAddOption(ol, DBOPT_GHOST_ZONE_LABELS, gz);
      DBPutZonelist2(db,"Mesh_zonelist_gz",nzones,2,nl,lnodelist,0,0,0,shapetyp,shapesize,shapecnt,1,ol);

      DBAddOption(ol, DBOPT_GHOST_NODE_LABELS, gn);
      DBPutUcdmesh (db,"Mesh_gnz",2,NULL,coord,nnodes,nzones,"Mesh_zonelist_gnz",NULL,DB_FLOAT,ol);
      DBPutZonelist2(db,"Mesh_zonelist_gnz",nzones,2,nl,lnodelist,0,0,0,shapetyp,shapesize,shapecnt,1,ol);

      DBFreeOptlist(ol);
      free(gn);
      free(gz);
  }

  /* do Node vars */

  cnvar = (char *)        malloc(sizeof(char)*nnodes); 
  snvar = (short *)       malloc(sizeof(short)*nnodes); 
  invar = (int *)         malloc(sizeof(int)*nnodes); 
  lnvar = (long *)        malloc(sizeof(long)*nnodes); 
  Lnvar = (long long *)   malloc(sizeof(long long)*nnodes); 
  fnvar = (float *)       malloc(sizeof(float)*nnodes); 
  dnvar = (double *)      malloc(sizeof(double)*nnodes); 
  c=0;
  for (x=0;x<mesh.nx;x++) {
    for (y=0;y<mesh.ny;y++) {
      f1[c]=mesh.node[x][y].vars[NV_U];
      f2[c]=mesh.node[x][y].vars[NV_V];
      cnvar[c] = (char)        (x<y?x:y);
      snvar[c] = (short)       (x<y?x:y);
      invar[c] = (int)         (x<y?x:y);
      lnvar[c] = (long)        (x<y?x:y);
      Lnvar[c] = (long long)   (x<y?x:y);
      fnvar[c] = (float)       (x<y?x:y);
      dnvar[c] = (double)      (x<y?x:y);
      c++;
    }
  }

  
  {
    DBoptlist *opt = DBMakeOptlist(1);
    int val = DB_ON;

    DBAddOption(opt,DBOPT_USESPECMF,&val);
    DBPutUcdvar1(db, "u", "Mesh", f1, nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, opt);
    DBPutUcdvar1(db, "v", "Mesh", f2, nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, opt);
    DBPutUcdvar1(db, "u", "Mesh", f1, nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, opt);
    DBPutUcdvar1(db, "v", "Mesh", f2, nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, opt);
    DBPutUcdvar1(db, "cnvar", "Mesh", cnvar, nnodes, NULL, 0, DB_CHAR, DB_NODECENT, opt);
    DBPutUcdvar1(db, "snvar", "Mesh", snvar, nnodes, NULL, 0, DB_SHORT, DB_NODECENT, opt);
    DBPutUcdvar1(db, "invar", "Mesh", invar, nnodes, NULL, 0, DB_INT, DB_NODECENT, opt);
    DBPutUcdvar1(db, "lnvar", "Mesh", lnvar, nnodes, NULL, 0, DB_LONG, DB_NODECENT, opt);
    DBPutUcdvar1(db, "Lnvar", "Mesh", Lnvar, nnodes, NULL, 0, DB_LONG_LONG, DB_NODECENT, opt);
    DBPutUcdvar1(db, "fnvar", "Mesh", fnvar, nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, opt);
    DBPutUcdvar1(db, "dnvar", "Mesh", dnvar, nnodes, NULL, 0, DB_DOUBLE, DB_NODECENT, opt);
    DBFreeOptlist(opt);
  }
  free(cnvar);
  free(snvar);
  free(invar);
  free(lnvar);
  free(Lnvar);
  free(fnvar);
  free(dnvar);

  /* do Zone vars */

  dims[0]--;
  dims[1]--;

  czvar = (char *)        malloc(sizeof(char)*nzones); 
  szvar = (short *)       malloc(sizeof(short)*nzones); 
  izvar = (int *)         malloc(sizeof(int)*nzones); 
  lzvar = (long *)        malloc(sizeof(long)*nzones); 
  Lzvar = (long long *)   malloc(sizeof(long long)*nzones); 
  fzvar = (float *)       malloc(sizeof(float)*nzones); 
  dzvar = (double *)      malloc(sizeof(double)*nzones); 
  c=0;
  for (x=0;x<mesh.zx;x++) {
    for (y=0;y<mesh.zy;y++) {
      f1[c]=mesh.zone[x][y].vars[ZV_P];
      f2[c]=mesh.zone[x][y].vars[ZV_D];
      czvar[c] = (char)        (x<y?x:y);
      szvar[c] = (short)       (x<y?x:y);
      izvar[c] = (int)         (x<y?x:y);
      lzvar[c] = (long)        (x<y?x:y);
      Lzvar[c] = (long long)   (x<y?x:y);
      fzvar[c] = (float)       (x<y?x:y);
      dzvar[c] = (double)      (x<y?x:y);
      c++;
    }
  }

  for (c=0; c<mixc; c++)
      fm[c] = 2.0/mixc*c;
  if (reorder)
  {
    float tmp=fm[mixc-1];
    fm[mixc-1]=fm[mixc-2];
    fm[mixc-2]=tmp;
  }

  DBPutUcdvar1(db, "p", "Mesh", f1, nzones, NULL, 0, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "d", "Mesh", f2, nzones, fm, mixc, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "czvar", "Mesh", czvar, nzones, NULL, 0, DB_CHAR, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "szvar", "Mesh", szvar, nzones, NULL, 0, DB_SHORT, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "izvar", "Mesh", izvar, nzones, NULL, 0, DB_INT, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "lzvar", "Mesh", lzvar, nzones, NULL, 0, DB_LONG, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "Lzvar", "Mesh", Lzvar, nzones, NULL, 0, DB_LONG_LONG, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "fzvar", "Mesh", fzvar, nzones, NULL, 0, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "dzvar", "Mesh", dzvar, nzones, NULL, 0, DB_DOUBLE, DB_ZONECENT, NULL);
  free(czvar);
  free(szvar);
  free(izvar);
  free(lzvar);
  free(Lzvar);
  free(fzvar);
  free(dzvar);
}
Beispiel #22
0
//
// Writes the data to given Silo file under the virtual path provided.
// The corresponding mesh must have been written already.
//
bool DataVar::writeToSilo(DBfile* dbfile, const string& siloPath,
                          const string& units)
{
#ifdef ESYS_HAVE_SILO
    if (!initialized)
        return false;

    if (numSamples == 0)
        return true;

    int ret;

    if (siloPath != "") {
        ret = DBSetDir(dbfile, siloPath.c_str());
        if (ret != 0)
            return false;
    }
 
    char* siloMesh = const_cast<char*>(siloMeshName.c_str());
    int dcenter = (centering == NODE_CENTERED ? DB_NODECENT : DB_ZONECENT);
    DBoptlist* optList = DBMakeOptlist(2);
    if (units.length()>0) {
        DBAddOption(optList, DBOPT_UNITS, (void*)units.c_str());
    }

    if (rank == 0) {
        ret = DBPutUcdvar1(dbfile, varName.c_str(), siloMesh, dataArray[0],
                numSamples, NULL, 0, DB_FLOAT, dcenter, optList);
    }
    else if (rank == 1) {
        const string comps[3] = {
            varName+string("_x"), varName+string("_y"), varName+string("_z")
        };
        const char* varnames[3] = {
            comps[0].c_str(), comps[1].c_str(), comps[2].c_str()
        };

        ret = DBPutUcdvar(dbfile, varName.c_str(), siloMesh, shape[0],
                (char**)varnames, &dataArray[0], numSamples, NULL,
                0, DB_FLOAT, dcenter, optList);
    }
    else {
        string tensorDir = varName+string("_comps/");
        ret = DBMkdir(dbfile, tensorDir.c_str());
        if (ret == 0) {
            int one = 1;
            DBAddOption(optList, DBOPT_HIDE_FROM_GUI, &one);

            for (int i=0; i<shape[1]; i++) {
                for (int j=0; j<shape[0]; j++) {
                    ostringstream varname;
                    varname << tensorDir << "a_" << i << j;
                    ret = DBPutUcdvar1(dbfile, varname.str().c_str(), siloMesh,
                            dataArray[i*shape[0]+j], numSamples,
                            NULL, 0, DB_FLOAT, dcenter, optList);
                    if (ret != 0) break;
                }
                if (ret != 0) break;
            }
        } // ret==0
    } // rank

    DBFreeOptlist(optList);
    DBSetDir(dbfile, "/");
    return (ret == 0);

#else // !ESYS_HAVE_SILO
    return false;
#endif
}
Beispiel #23
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;
}
Beispiel #24
0
void grid::output(const output_list_type& olists, std::string _filename, real _t, int cycle, bool analytic) {
#ifdef DO_OUTPUT

	std::thread(
		[&](const std::string& filename, real t) {
			printf( "t = %e\n", t);
			const std::set<node_point>& node_list = olists.nodes;
			const std::vector<zone_int_type>& zone_list = olists.zones;

			const int nzones = zone_list.size() / NVERTEX;
			std::vector<int> zone_nodes;
			zone_nodes = std::move(zone_list);

			const int nnodes = node_list.size();
			std::vector<double> x_coord(nnodes);
			std::vector<double> y_coord(nnodes);
			std::vector<double> z_coord(nnodes);
			std::array<double*, NDIM> node_coords = {x_coord.data(), y_coord.data(), z_coord.data()};
			for (auto iter = node_list.begin(); iter != node_list.end(); ++iter) {
				const integer i = iter->index;
				x_coord[i] = iter->pt[0];
				y_coord[i] = iter->pt[1];
				z_coord[i] = iter->pt[2];
			}

			constexpr
			int nshapes = 1;
			int shapesize[1] = {NVERTEX};
			int shapetype[1] = {DB_ZONETYPE_HEX};
			int shapecnt[1] = {nzones};
			const char* coord_names[NDIM] = {"x", "y", "z"};

#ifndef	__MIC__
		auto olist = DBMakeOptlist(1);
		double time = double(t);
		int ndim = 3;
		DBAddOption(olist, DBOPT_CYCLE, &cycle);
		DBAddOption(olist, DBOPT_DTIME, &time);
		DBAddOption(olist, DBOPT_NSPACE, &ndim );
		DBfile *db = DBCreateReal(filename.c_str(), DB_CLOBBER, DB_LOCAL, "Euler Mesh", DB_PDB);
		assert(db);
		DBPutZonelist2(db, "zones", nzones, int(NDIM), zone_nodes.data(), nzones * NVERTEX, 0, 0, 0, shapetype, shapesize,
			shapecnt, nshapes, olist);
		DBPutUcdmesh(db, "mesh", int(NDIM), const_cast<char**>(coord_names), node_coords.data(), nnodes, nzones, "zones", nullptr, DB_DOUBLE,
			olist);
		const char* analytic_names[] = {"rho_a", "egas_a", "sx_a", "sy_a", "sz_a", "tau_a"};
		DBFreeOptlist(olist);
		for (int field = 0; field != NF + NGF + NPF; ++field) {
			auto olist = DBMakeOptlist(1);
			double time = double(t);
			int istrue = 1;
			int isfalse = 0;
			DBAddOption(olist, DBOPT_CYCLE, &cycle);
			DBAddOption(olist, DBOPT_DTIME, &time);
			DBAddOption(olist, DBOPT_NSPACE, &ndim );
			if( field == rho_i || field == sx_i || field == sy_i || field == sz_i || field == spc_ac_i || field == spc_ae_i || field == spc_dc_i || field == spc_de_i || field == spc_vac_i ) {
				DBAddOption(olist, DBOPT_CONSERVED, &istrue);
			} else {
				DBAddOption(olist, DBOPT_CONSERVED, &isfalse );
			}
			if( field < NF ) {
				DBAddOption(olist, DBOPT_EXTENSIVE, &istrue);
			} else {
				DBAddOption(olist, DBOPT_EXTENSIVE, &isfalse);
			}
			DBAddOption(olist, DBOPT_EXTENSIVE, &istrue);
			DBPutUcdvar1(db, field_names[field], "mesh", const_cast<void*>(reinterpret_cast<const void*>(olists.data[field].data())), nzones, nullptr, 0, DB_DOUBLE, DB_ZONECENT,
				olist);
			if( analytic && field < 6) {
				DBPutUcdvar1(db, analytic_names[field], "mesh", const_cast<void*>(reinterpret_cast<const void*>(olists.analytic[field].data())), nzones, nullptr, 0, DB_DOUBLE, DB_ZONECENT,
					olist);
			}
			DBFreeOptlist(olist);
#ifdef RHO_ONLY
		break;
#endif
	}
	DBClose(db);
#endif
	}, _filename, _t).join();
#endif
}
Beispiel #25
0
static void
build_primitives_csg(DBfile *dbfile)
{

    // build and output the csg mesh (boundaries)
    {
        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
        };

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

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

        DBoptlist *optlist = DBMakeOptlist(2);
        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);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            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"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

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

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

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

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_CYLINDER_PNLR,      // 0: cylinderY
            DBCSG_CYLINDER_PNLR,      // 1: cylinderX
            DBCSG_CYLINDER_PNLR       // 2: cylinderZ
        };

        float coeffs[] =
        {
           //0.0, -10.0, 0.0, 0.707, 0.0, 0.707, 20.0, 4.5 point-normal-length-radius form of cylinder
         -10.0, 0.0, 0.0, 1.0, 0.0, 0.0, 20.0, 4.5, // point-normal-length-radius form of cylinder
           0.0, -10.0, 0.0, 0.0, 1.0, 0.0, 20.0, 4.5, // point-normal-length-radius form of cylinder
           0.0, 0.0, -10.0, 0.0, 0.0, 1.0, 20.0, 4.5  // point-normal-length-radius form of cylinder
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

        char *bndnames[] = {"cylinderY", "cylinderX", "cylinderZ"};

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

        DBPutCsgmesh(dbfile, "cylinders", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "cylinders_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,          // 0: inside of cylinderY
            DBCSG_INNER,          // 1: inside of cylinderX 
            DBCSG_INNER,          // 2: inside of cylinderZ
            DBCSG_UNION,          // 3: 0 and 1 
            DBCSG_UNION           // 4: 2 and 3 
        };
        //                 0   1   2   3   4
        int leftids[] =  { 0,  1,  2,  0,  2};
        int rightids[] = {-1, -1, -1,  1,  3};
        int zonelist[] = {0, 1, 2, 4};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

        char *zonenames[] = {"cylinderY","cylinderX","cylinderZ","cylinderAll"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "cylinders_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_PLANE_PN
        };

        float coeffs[] =
        {
            1.0, 0.0, 0.0, 1.0, 0.0, 0.0  // point-normal form of plane
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

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

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

        DBPutCsgmesh(dbfile, "plane_pn_X", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "plane_pn_X_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,           // 0: inside (everything to left) of plane
            DBCSG_OUTER            // 1: outside (everything to right) of plane
        };
        //                 0
        int leftids[] =  { 0,  0};
        int rightids[] = {-1, -1};
        int zonelist[] = {0, 1};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

        char *zonenames[] = {"left-of-plane",
                             "right-of-plane"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "plane_pn_X_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_PLANE_X
        };

        float coeffs[] =
        {
            1.0  // x-intercept form of plane
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

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

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

        DBPutCsgmesh(dbfile, "plane_X", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "plane_X_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,          // 0: inside (everything to left) of plane
            DBCSG_OUTER           // 1: outside (everything to right) of plane
        };
        //                 0   1
        int leftids[] =  { 0,  0};
        int rightids[] = {-1, -1};
        int zonelist[] = { 0,  1};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

        char *zonenames[] = {"left-of-plane", "right-of-plane"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "plane_X_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_PLANE_Y
        };

        float coeffs[] =
        {
            1.0  // y-intercept form of plane
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

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

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

        DBPutCsgmesh(dbfile, "plane_Y", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "plane_Y_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,          // 0: inside (everything to bottom) of plane
            DBCSG_OUTER           // 1: outside (everything to top) of plane
        };
        //                 0   1
        int leftids[] =  { 0,  0};
        int rightids[] = {-1, -1};
        int zonelist[] = { 0,  1};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

        char *zonenames[] = {"bottom-of-plane", "top-of-plane"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "plane_Y_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_PLANE_Z
        };

        float coeffs[] =
        {
            1.0  // z-intercept form of plane
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

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

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

        DBPutCsgmesh(dbfile, "plane_Z", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "plane_Z_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,          // 0: inside (everything to back) of plane
            DBCSG_OUTER           // 1: outside (everything to front) of plane
        };
        //                 0   1
        int leftids[] =  { 0,  0};
        int rightids[] = {-1, -1};
        int zonelist[] = { 0,  1};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

        char *zonenames[] = {"back-of-plane", "front-of-plane"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "plane_Z_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_PLANE_X,
            DBCSG_PLANE_X,
            DBCSG_PLANE_Y,
            DBCSG_PLANE_Y,
            DBCSG_PLANE_Z,
            DBCSG_PLANE_Z
        };

        float coeffs[] =
        {
            1.0, -1.0,  // x-intercept form of plane
            1.0, -1.0,  // y-intercept form of plane
            1.0, -1.0   // z-intercept form of plane
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

        char *bndnames[] = {"XAplane","XBplane","YAplane","YBplane","ZAplane","ZBplane"};

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

        DBPutCsgmesh(dbfile, "Box", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "box_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,          // 0: inside (everything to left) of plane
            DBCSG_OUTER,          // 1: outside (everything to right) of plane
            DBCSG_INNER,          // 2: inside (everything to left) of plane
            DBCSG_OUTER,          // 3: outside (everything to right) of plane
            DBCSG_INNER,          // 4: inside (everything to left) of plane
            DBCSG_OUTER,          // 5: outside (everything to right) of plane
            DBCSG_INTERSECT,      // 6: between X planes
            DBCSG_INTERSECT,      // 7: between Y planes
            DBCSG_INTERSECT,      // 8: between Z planes
            DBCSG_INTERSECT,      // 9: between XY planes
            DBCSG_INTERSECT,      //10: between XY & Z planes
        };
        //                 0   1   2   3   4   5   6   7   8   9   10
        int leftids[] =  { 0,  1,  2,  3,  4,  5,  0,  2,  4,  6,  8};
        int rightids[] = {-1, -1, -1, -1, -1, -1,  1,  3,  5,  7,  9};
        int zonelist[] = {10};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

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

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "box_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_PLANE_PN
        };

        float coeffs[] =
        {
            1.0, 1.0, 1.0, 0.707, 0.707, 0.0  // point-normal form of plane
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

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

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

        DBPutCsgmesh(dbfile, "plane_PN", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "plane_PN_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,          // 0: inside (everything to back) of plane
            DBCSG_OUTER           // 1: outside (everything to front) of plane
        };
        //                 0   1
        int leftids[] =  { 0,  0};
        int rightids[] = {-1, -1};
        int zonelist[] = { 0,  1};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

        char *zonenames[] = {"sideA", "sideB"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "plane_PN_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_QUADRIC_G
        };

        float coeffs[] =
        {
            0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -20.25 // cylinder
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

        char *bndnames[] = {"cylinder"};

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

        DBPutCsgmesh(dbfile, "quadric_cylinder", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "quadric_cylinder_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,          // 0: inside (everything to back) of plane
            DBCSG_OUTER           // 1: outside (everything to front) of plane
        };
        //                 0   1
        int leftids[] =  { 0,  0};
        int rightids[] = {-1, -1};
        int zonelist[] = { 0,  1};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

        char *zonenames[] = {"inside", "outside"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "quadric_cylinder_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_QUADRIC_G
        };

        float coeffs[] =
        {
            1.0, 2.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -16.0 // spheriod
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

        char *bndnames[] = {"spheriod"};

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

        DBPutCsgmesh(dbfile, "quadric_spheriod", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "quadric_spheroid_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,          // 0: inside (everything to back) of plane
            DBCSG_OUTER           // 1: outside (everything to front) of plane
        };
        //                 0   1
        int leftids[] =  { 0,  0};
        int rightids[] = {-1, -1};
        int zonelist[] = { 0,  1};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

        char *zonenames[] = {"inside", "outside"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "quadric_spheroid_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_QUADRIC_G
        };

        float coeffs[] =
        {
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, -1.0 // plane
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

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

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

        DBPutCsgmesh(dbfile, "quadric_plane", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "quadric_plane_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,          // 0: inside (everything to back) of plane
            DBCSG_OUTER           // 1: outside (everything to front) of plane
        };
        //                 0   1
        int leftids[] =  { 0,  0};
        int rightids[] = {-1, -1};
        int zonelist[] = { 0,  1};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

        char *zonenames[] = {"inside", "outside"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "quadric_plane_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_QUADRIC_G
        };

        const float c0 = .464102;
        const float c2 = -1.0718;
        float coeffs[] =
        {
            1.0,  c0,  c0, 0.0,  c2, 0.0, 0.0, 0.0, 0.0, 0.0    // cone
            //1/9.0,  1/9.0,  -0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0    // good-cone
            //1/9.0,  1/9.0,  -0.01, 0.0, -.10, 0.0, 0.0, 0.0, 0.0, 0.0    // cone
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

        //double extents[] = {-1.0, -1.0, -1.0, 1.0, 1.0, 1.0};
        double extents[] = {-10.0, -10.0, -10.0, 10.0, 10.0, 10.0};

        char *bndnames[] = {"cone"};

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

        DBPutCsgmesh(dbfile, "quadric_cone", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "quadric_cone_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,          // 0: inside (everything to back) of plane
            DBCSG_OUTER           // 1: outside (everything to front) of plane
        };
        //                 0   1
        int leftids[] =  { 0,  0};
        int rightids[] = {-1, -1};
        int zonelist[] = { 0,  1};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

        char *zonenames[] = {"inside", "outside"};

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "quadric_cone_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_SPHERE_PR,
            DBCSG_SPHERE_PR
        };

        float coeffs[] =
        {
            0.0, 0.0, 0.0, 1.0,
            0.0, 0.0, 0.0, 0.9
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

        char *bndnames[] = {"outer-sphere", "inner-sphere"};

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

        DBPutCsgmesh(dbfile, "quadric_shell", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "quadric_shell_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,          // 0: inside of outer sphere 
            DBCSG_INNER,          // 1: inside of inner sphere 
            DBCSG_DIFF            // 2: difference 
        };
        //                 0   1   2
        int leftids[] =  { 0,  1,  0};
        int rightids[] = {-1, -1,  1};
        int zonelist[] = {2};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

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

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "quadric_shell_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }
    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_QUADRIC_G
        };

        float theta = 45.0f * 3.1415926f/180.0f;
        float a = cos(theta);
        float b = sin(theta);
        float coeffs[] =
        {
         // x^2  y^2   z^2  xy    yz    xz        x     y     z     c
            a*a, 1.0f, b*b, 0.0f, 0.0f, 2.0f*a*b, 0.0f, 0.0f, 0.0f, -1.0f
            //1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -4
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

        char *bndnames[] = {"quadric_cylinder"};

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

        DBPutCsgmesh(dbfile, "quadric_cylinder2", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "quadric_cylinder2_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER           // 0: inside of cylinder 
        };
        //                 0
        int leftids[] =  { 0};
        int rightids[] = {-1};
        int zonelist[] = {0};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

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

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "quadric_cylinder2_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_QUADRIC_G
        };

        float theta = 45.0 * 3.1415926/180.0;
        float phi  = 45.0 * 3.1415926/180.0;
        float a = cos(theta);
        float b = sin(theta); 
        float q = cos(-phi);
        float r = sin(-phi);
        float a2 = a*a;
        float b2 = b*b;
        float q2 = q*q;
        float r2 = r*r;
        float R = 2.0;
        float coeffs[] =
        {
         // x^2    y^2 z^2       xy          yz          xz                     x     y     z     c
         a2+r2*b2, q2, b2+r2*a2, 2.0f*q*r*b, 2.0f*q*r*a, -2.0f*a*b+2.0f*a*b*r2, 0.0f, 0.0f, 0.0f, -R*R
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

        char *bndnames[] = {"quadric_cylinder"};

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

        DBPutCsgmesh(dbfile, "quadric_cylinder3", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "quadric_cylinder3_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER           // 0: inside of cylinder 
        };
        //                 0
        int leftids[] =  { 0};
        int rightids[] = {-1};
        int zonelist[] = {0};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

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

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "quadric_cylinder3_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_CONE_PNLA
        };

        float coeffs[] =
        {
            0.0, 0.0, 0.0, 0.577, 0.577, 0.577, 5.0, 30.0
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

        char *bndnames[] = {"cone_pnla"};

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

        DBPutCsgmesh(dbfile, "cone_pnla", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "cone_pnla_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER           // 0: inside of cylinder 
        };
        //                 0
        int leftids[] =  { 0};
        int rightids[] = {-1};
        int zonelist[] = {0};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

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

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "cone_pnla_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg mesh (boundaries)
    {
        int typeflags[] =
        {
            DBCSG_SPHERE_PR,
            DBCSG_SPHERE_PR,
            DBCSG_CYLINDER_PNLR
        };

        float coeffs[] =
        {
            0.0, 0.0, 0.0, 0.975,
            0.0, 0.0, 0.0,  1.0,
            0.4, 0.4, 0.4, 0.57, 0.578, 0.578, 2.0, 0.1
        };

        int nbounds = sizeof(typeflags) / sizeof(typeflags[0]);
        int lcoeffs = sizeof(coeffs) / sizeof(coeffs[0]);

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

        DBoptlist *optlist = DBMakeOptlist(2);
        DBAddOption(optlist, DBOPT_EXTENTS, extents);

        DBPutCsgmesh(dbfile, "sphere_shell_by_intersection", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "ssbi_csgzl", optlist);

        DBPutCsgmesh(dbfile, "sphere_shell_by_diff", 3, nbounds, typeflags,
            NULL, coeffs, lcoeffs, DB_FLOAT, extents, "ssbd_csgzl", optlist);

        DBFreeOptlist(optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_OUTER,          // 0: outside of inner sphere
            DBCSG_INNER,          // 1: inside of outer sphere 
            DBCSG_INTERSECT,      // 2: intersection between them 
            DBCSG_INNER,          // 3: inside of cylinder
            DBCSG_DIFF            // 4: sphere shell minus cylinder
        };
        //                 0   1   2   3   4
        int leftids[] =  { 0,  1,  0,  2,  2};
        int rightids[] = {-1, -1,  1, -1,  3};
        int zonelist[] = {4};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

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

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "ssbi_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }

    // build and output the csg zonelist
    {
        int typeflags[] =
        {
            DBCSG_INNER,          // 0: inside of inner sphere
            DBCSG_INNER,          // 1: inside of outer sphere 
            DBCSG_DIFF,           // 2: outer minus inner 
            DBCSG_INNER,          // 3: inside of cylinder
            DBCSG_DIFF            // 4: sphere shell minus cylinder
        };
        //                 0   1   2   3   4
        int leftids[] =  { 0,  1,  1,  2,  2};
        int rightids[] = {-1, -1,  0, -1,  3};
        int zonelist[] = {2};

        int nregs = sizeof(typeflags) / sizeof(typeflags[0]);
        int nzones = sizeof(zonelist) / sizeof(zonelist[0]);

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

        DBoptlist *optlist = DBMakeOptlist(1);
        DBAddOption(optlist, DBOPT_ZONENAMES, zonenames);

        DBPutCSGZonelist(dbfile, "ssbd_csgzl", nregs, typeflags, leftids, rightids,
                         NULL, 0, DB_INT, nzones, zonelist, optlist);
    }
}
Beispiel #26
0
/*----------------------------------------------------------------------------
 * Function: writemesh_ucd2d()
 *
 * Inputs:   db (DBfile*): the Silo file handle
 *
 * Returns:  (void)
 *
 * Abstract: Write the mesh and variables stored in the global Mesh 
 *           to the Silo file as a UCDmesh and UCDvars
 *
 * Modifications:
 *---------------------------------------------------------------------------*/
void writemesh_ucd2d(DBfile *db, int mixc, int reorder) {

  int   nl[5000];
  float f1[1000],f2[1000], fm[1000];
  int x,y,c;
  char  *coordnames[2];
  float *coord[2];
  int dims[2];
  char *cnvar, *czvar;
  short *snvar, *szvar;
  int *invar, *izvar;
  long *lnvar, *lzvar;
  long long *Lnvar, *Lzvar;
  float *fnvar, *fzvar;
  double *dnvar, *dzvar;

  int lnodelist;
  int nnodes;
  int nzones;
  int shapesize[1];
  int shapecnt[1];

  /* do mesh */
  c=0;
  for (x=0;x<mesh.nx;x++) {
    for (y=0;y<mesh.ny;y++) {
      f1[c]=mesh.node[x][y].x;
      f2[c]=mesh.node[x][y].y;
      if (mesh.node[x][y].c != c) {
	printf("Node mismatch! mesh.c=%d c=%d\n",mesh.node[x][y].c,c);
	exit(-1);
      }
      c++;
    }
  }

  coordnames[0]=NEW(char,20);
  coordnames[1]=NEW(char,20);
  strcpy(coordnames[0],"x");
  strcpy(coordnames[1],"y");

  coord[0]=f1;
  coord[1]=f2;

  dims[0]=mesh.nx;
  dims[1]=mesh.ny;

  /* create the zonelist */
  c=0;
  for (x=0;x<mesh.zx;x++) {
    for (y=0;y<mesh.zy;y++) {
      nl[c++] = mesh.zone[x][y].n[0][0]->c;
      nl[c++] = mesh.zone[x][y].n[1][0]->c;
      nl[c++] = mesh.zone[x][y].n[1][1]->c;
      nl[c++] = mesh.zone[x][y].n[0][1]->c;
    }
  }
  lnodelist=c;

  nnodes=mesh.nx*mesh.ny;
  nzones=mesh.zx*mesh.zy;
  shapesize[0]=4;
  shapecnt[0]=nzones;

  DBSetDeprecateWarnings(0);
  DBPutZonelist(db,"Mesh_zonelist",nzones,2,nl,lnodelist,0,shapesize,shapecnt,1);
  DBSetDeprecateWarnings(3);
  DBPutUcdmesh (db,"Mesh",2,NULL,coord,nnodes,nzones,"Mesh_zonelist",NULL,DB_FLOAT,NULL);

  /* do Node vars */

  cnvar = (char *)        malloc(sizeof(char)*nnodes); 
  snvar = (short *)       malloc(sizeof(short)*nnodes); 
  invar = (int *)         malloc(sizeof(int)*nnodes); 
  lnvar = (long *)        malloc(sizeof(long)*nnodes); 
  Lnvar = (long long *)   malloc(sizeof(long long)*nnodes); 
  fnvar = (float *)       malloc(sizeof(float)*nnodes); 
  dnvar = (double *)      malloc(sizeof(double)*nnodes); 
  c=0;
  for (x=0;x<mesh.nx;x++) {
    for (y=0;y<mesh.ny;y++) {
      f1[c]=mesh.node[x][y].vars[NV_U];
      f2[c]=mesh.node[x][y].vars[NV_V];
      cnvar[c] = (char)        (x<y?x:y);
      snvar[c] = (short)       (x<y?x:y);
      invar[c] = (int)         (x<y?x:y);
      lnvar[c] = (long)        (x<y?x:y);
      Lnvar[c] = (long long)   (x<y?x:y);
      fnvar[c] = (float)       (x<y?x:y);
      dnvar[c] = (double)      (x<y?x:y);
      c++;
    }
  }

  
  {
    DBoptlist *opt = DBMakeOptlist(1);
    int val = DB_ON;

    DBAddOption(opt,DBOPT_USESPECMF,&val);
    DBPutUcdvar1(db, "u", "Mesh", f1, nnodes, NULL, 0, DB_FLOAT,
        DB_NODECENT, opt);
    DBPutUcdvar1(db, "v", "Mesh", f2, nnodes, NULL, 0, DB_FLOAT,
        DB_NODECENT, opt);
    DBPutUcdvar1(db, "u", "Mesh", f1, nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, opt);
    DBPutUcdvar1(db, "v", "Mesh", f2, nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, opt);
    DBPutUcdvar1(db, "cnvar", "Mesh", cnvar, nnodes, NULL, 0, DB_CHAR, DB_NODECENT, opt);
    DBPutUcdvar1(db, "snvar", "Mesh", snvar, nnodes, NULL, 0, DB_SHORT, DB_NODECENT, opt);
    DBPutUcdvar1(db, "invar", "Mesh", invar, nnodes, NULL, 0, DB_INT, DB_NODECENT, opt);
    DBPutUcdvar1(db, "lnvar", "Mesh", lnvar, nnodes, NULL, 0, DB_LONG, DB_NODECENT, opt);
    DBPutUcdvar1(db, "Lnvar", "Mesh", Lnvar, nnodes, NULL, 0, DB_LONG_LONG, DB_NODECENT, opt);
    DBPutUcdvar1(db, "fnvar", "Mesh", fnvar, nnodes, NULL, 0, DB_FLOAT, DB_NODECENT, opt);
    DBPutUcdvar1(db, "dnvar", "Mesh", dnvar, nnodes, NULL, 0, DB_DOUBLE, DB_NODECENT, opt);
    DBFreeOptlist(opt);
  }
  free(cnvar);
  free(snvar);
  free(invar);
  free(lnvar);
  free(Lnvar);
  free(fnvar);
  free(dnvar);

  /* do Zone vars */

  dims[0]--;
  dims[1]--;

  czvar = (char *)        malloc(sizeof(char)*nzones); 
  szvar = (short *)       malloc(sizeof(short)*nzones); 
  izvar = (int *)         malloc(sizeof(int)*nzones); 
  lzvar = (long *)        malloc(sizeof(long)*nzones); 
  Lzvar = (long long *)   malloc(sizeof(long long)*nzones); 
  fzvar = (float *)       malloc(sizeof(float)*nzones); 
  dzvar = (double *)      malloc(sizeof(double)*nzones); 
  c=0;
  for (x=0;x<mesh.zx;x++) {
    for (y=0;y<mesh.zy;y++) {
      f1[c]=mesh.zone[x][y].vars[ZV_P];
      f2[c]=mesh.zone[x][y].vars[ZV_D];
      czvar[c] = (char)        (x<y?x:y);
      szvar[c] = (short)       (x<y?x:y);
      izvar[c] = (int)         (x<y?x:y);
      lzvar[c] = (long)        (x<y?x:y);
      Lzvar[c] = (long long)   (x<y?x:y);
      fzvar[c] = (float)       (x<y?x:y);
      dzvar[c] = (double)      (x<y?x:y);
      c++;
    }
  }

  for (c=0; c<mixc; c++)
      fm[c] = 2.0/mixc*c;
  if (reorder)
  {
    float tmp=fm[mixc-1];
    fm[mixc-1]=fm[mixc-2];
    fm[mixc-2]=tmp;
  }

  DBPutUcdvar1(db, "p", "Mesh", f1, nzones, NULL, 0, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "d", "Mesh", f2, nzones, fm, mixc, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "czvar", "Mesh", czvar, nzones, NULL, 0, DB_CHAR, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "szvar", "Mesh", szvar, nzones, NULL, 0, DB_SHORT, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "izvar", "Mesh", izvar, nzones, NULL, 0, DB_INT, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "lzvar", "Mesh", lzvar, nzones, NULL, 0, DB_LONG, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "Lzvar", "Mesh", Lzvar, nzones, NULL, 0, DB_LONG_LONG, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "fzvar", "Mesh", fzvar, nzones, NULL, 0, DB_FLOAT, DB_ZONECENT, NULL);
  DBPutUcdvar1(db, "dzvar", "Mesh", dzvar, nzones, NULL, 0, DB_DOUBLE, DB_ZONECENT, NULL);
  free(czvar);
  free(szvar);
  free(izvar);
  free(lzvar);
  free(Lzvar);
  free(fzvar);
  free(dzvar);
}