示例#1
0
文件: wr_exo.c 项目: goma/goma
void 
wr_elem_result_exo(Exo_DB *exo, const char *filename, double ***vector, 
		   const int variable_index, const int time_step,
		   const double time_value, 
		   struct Results_Description *rd)
{
  int error, i;
  double local_time_value=time_value;
  /* static char *yo = "wr_elem_result_exo"; */

  /*
   * This file must already exist.
   */

  exo->cmode = EX_WRITE;

  exo->io_wordsize = 0;		/* query */
  exo->exoid = ex_open(filename, exo->cmode, &exo->comp_wordsize, 
		       &exo->io_wordsize, &exo->version);
  EH(exo->exoid, "ex_open");

#ifdef DEBUG
  fprintf(stderr, "\t\tfilename    = \"%s\"\n", filename);
  fprintf(stderr, "\t\tcomp_ws     = %d\n", exo->comp_wordsize);
  fprintf(stderr, "\t\tio_wordsize = %d\n", exo->io_wordsize);
#endif

  error = ex_put_time (exo->exoid, time_step, &local_time_value );
  EH(error, "ex_put_time");

  /* If the truth table has NOT been set up, this will be really slow... */

  for (i = 0; i < exo->num_elem_blocks; i++) {
    if (exo->elem_var_tab_exists == TRUE) {
      /* Only write out vals if this variable exists for the block */
      if (exo->elem_var_tab[i*rd->nev + variable_index] == 1) {
	error = ex_put_var(exo->exoid, time_step, EX_ELEM_BLOCK, variable_index+1,
				exo->eb_id[i], exo->eb_num_elems[i],
				vector[i][variable_index]);
	EH(error, "ex_put_var elem");
      }
    }
    else {
      /* write it anyway (not really recommended from a performance viewpoint) */
      error      = ex_put_var ( exo->exoid,
				time_step, EX_ELEM_BLOCK,
				variable_index+1, /* Convert to 1 based for
						     exodus */
				exo->eb_id[i],
				exo->eb_num_elems[i],
				vector[i][variable_index] );
      EH(error, "ex_put_var elem");
    }
  }

  error      = ex_close ( exo->exoid );
  EH(error, "ex_close");

  return;
}
示例#2
0
int exodus_file_write_time(exodus_file_t* file, real_t time)
{
  ASSERT(file->writing);
  int next_index = file->last_time_index + 1;
  int status = ex_put_time(file->ex_id, next_index, &time);
  if (status >= 0)
    file->last_time_index = next_index;
  else 
    next_index = status;
  return next_index;
}
示例#3
0
文件: wr_exo.c 项目: goma/goma
void 
wr_nodal_result_exo(Exo_DB *exo, char *filename, double vector[],
		    int variable_index, int time_step, double time_value)

     /*****************************************************************
      * write_nodal_result_exo() 
      *     -- open/write/close EXODUS II db for 1 nodal var at one
      *        time step.
      *
      * The output EXODUS II database contains the original model
      * information with some minor QA and info additions, with new 
      * nodal value solution data written.
      * 
      ******************************************************************/
{
  char err_msg[MAX_CHAR_IN_INPUT];
  int error;
  exo->cmode = EX_WRITE;
  exo->io_wordsize = 0;		/* query */
  exo->exoid = ex_open(filename, exo->cmode, &exo->comp_wordsize, 
		       &exo->io_wordsize, &exo->version);
  if (exo->exoid < 0)
    {
      sr = sprintf(err_msg, 
		   "ex_open() = %d on \"%s\" failure @ step %d, time = %g",
		   exo->exoid, filename, time_step, time_value);
      EH(-1, err_msg);
    }
  error      = ex_put_time(exo->exoid, time_step, &time_value);
  EH(error, "ex_put_time");
  error      = ex_put_var(exo->exoid, time_step, EX_NODAL, variable_index, 1,
				exo->num_nodes, vector);
  EH(error, "ex_put_var nodal");
  error      = ex_close(exo->exoid);
  return;
}
示例#4
0
void write_exo_mesh(int debug, char *file_name, INT map_origin, INT num_nodes, INT num_elements,
                    INT num_domains, INT num_nodal_fields, INT num_global_fields,
                    INT num_element_fields, INT num_timesteps, realtyp *x, realtyp *y, realtyp *z,
                    INT *connect, int compression_level, int shuffle, int int64bit)
{
  int  CPU_word_size = sizeof(realtyp);
  int  IO_word_size  = sizeof(realtyp);
  int  exoid, err, num_dim, num_elem_blk, num_node_sets, num_side_sets;
  INT  i, j, t, index, loc_num_elements, loc_num_nodes, len_connect;
  INT *elem_map = NULL, *node_map = NULL, *domain_connect = NULL, *loc_connect = NULL;
  int *elem_var_tab;
  INT  accum_num_elements = 0;
  INT  loc_node_size      = -1;

  realtyp *loc_xcoords = NULL;
  realtyp *loc_ycoords = NULL;
  realtyp *loc_zcoords = NULL;
  realtyp *globals     = NULL;

  char   temporary_name[MAX_STRING_LEN];
  char **var_name;

  accum_num_elements = 0;
  for (i = 0; i < num_domains; i++) {
    int mymode = EX_MAPS_INT64_API | EX_BULK_INT64_API | EX_IDS_INT64_API;
    if (int64bit) {
      mymode |= EX_MAPS_INT64_DB | EX_BULK_INT64_DB | EX_IDS_INT64_DB;
    }

    /* create the EXODUSII file */
    get_file_name(file_name, "e", i, num_domains, NULL, temporary_name);

    exoid = ex_create(temporary_name, EX_CLOBBER | mymode, &CPU_word_size, &IO_word_size);

    if (exoid < 0) {
      fprintf(stderr, "after ex_create, error = %d\n", exoid);
      exit(-1);
    }

    ex_set_option(exoid, EX_OPT_COMPRESSION_LEVEL, compression_level);
    ex_set_option(exoid, EX_OPT_COMPRESSION_SHUFFLE, shuffle);

    if (num_domains > 1) {
      /* Determine local number of elements */
      if (num_elements < num_domains) {
        fprintf(stderr, "number of elements is less than number of domains.\n");
        if (i < num_elements)
          loc_num_elements = 1;
        else
          loc_num_elements = 0;
      }
      else {
        loc_num_elements = num_elements / num_domains;
        if (i < (num_elements % num_domains))
          loc_num_elements++;
      }

      len_connect = NUM_NODES_PER_ELEM * loc_num_elements;

      /* malloc things we need */

      if (i == 0) { /* first time through; max size arrays occur on
                       first iteration */
        elem_map       = malloc(loc_num_elements * sizeof(INT));
        domain_connect = malloc(len_connect * sizeof(INT));
        loc_connect    = malloc(len_connect * sizeof(INT));
        node_map       = malloc(num_nodes * sizeof(INT));
      }

      /* Create element local/global map */
      create_elem_map(loc_num_elements, accum_num_elements, elem_map, map_origin);

      /* Extract current domain's connectivity, referencing global node ids */
      extract_connect(accum_num_elements, loc_num_elements, elem_map, connect, domain_connect,
                      map_origin);

      accum_num_elements += loc_num_elements;

      /* The local/global node map is just the current domain's connectivity,
         sorted with duplicate entries removed */
      create_node_map(num_nodes, len_connect, domain_connect, node_map, &loc_num_nodes, map_origin);

      /* Using local/global node map, convert the domain connectivity
         (referencing global node ids) to local connectivity (referencing
         local node ids) */

      create_local_connect(node_map, loc_num_nodes, len_connect, domain_connect, loc_connect,
                           map_origin);
    }
    else {
      loc_num_elements = num_elements;
      loc_num_nodes    = num_nodes;
    }

    if (debug) {
      fprintf(stderr, "\n\n\n");

      fprintf(stderr, "\n domain: %" PRId64 "\n", i);
      fprintf(stderr, "\n loc_num_elements: %" PRId64 "\n", loc_num_elements);
      fprintf(stderr, "\n loc_num_nodes: %" PRId64 "\n", loc_num_nodes);
    }

    num_dim       = 3;
    num_elem_blk  = 1;
    num_node_sets = 0;
    num_side_sets = 0;

    err = ex_put_init(exoid, "This is an EXODUSII performance test.", num_dim, loc_num_nodes,
                      loc_num_elements, num_elem_blk, num_node_sets, num_side_sets);

    if (err) {
      fprintf(stderr, "after ex_put_init, error = %d\n", err);
      ex_close(exoid);
      exit(-1);
    }

    /* Extract the local x and y coordinates */
    if (num_domains > 1) {
      if (loc_num_nodes > loc_node_size) {
        loc_xcoords   = realloc(loc_xcoords, loc_num_nodes * sizeof(realtyp));
        loc_ycoords   = realloc(loc_ycoords, loc_num_nodes * sizeof(realtyp));
        loc_zcoords   = realloc(loc_zcoords, loc_num_nodes * sizeof(realtyp));
        loc_node_size = loc_num_nodes;
      }

      for (j = 0; j < loc_num_nodes; j++) {
        index          = node_map[j] - map_origin;
        loc_xcoords[j] = x[index];
        loc_ycoords[j] = y[index];
        loc_zcoords[j] = z[index];
      }

      err = ex_put_coord(exoid, loc_xcoords, loc_ycoords, loc_zcoords);
    }
    else {
      err = ex_put_coord(exoid, x, y, z);
    }
    if (err) {
      fprintf(stderr, "after ex_put_coord, error = %d\n", err);
      ex_close(exoid);
      exit(-1);
    }
    if (debug) {
      fprintf(stderr, "\tCoordinates output.\n");
    }
#if 1
    {
      INT   ids[1] = {EBLK_ID};
      INT   num_elem_per_block[1];
      char *names[1] = {"hex"};
      INT   num_node_per_elem[1];
      INT   num_attr_per_block[1];
      int   write_map       = num_domains > 1 ? EX_TRUE : EX_FALSE;
      num_elem_per_block[0] = loc_num_elements;
      num_node_per_elem[0]  = NUM_NODES_PER_ELEM;
      num_attr_per_block[0] = 0;
      err = ex_put_concat_elem_block(exoid, ids, names, num_elem_per_block, num_node_per_elem,
                                     num_attr_per_block, write_map);
    }
#else
    err = ex_put_elem_block(exoid, 10000000000, "hex", loc_num_elements, NUM_NODES_PER_ELEM, 0);
#endif

    if (err) {
      fprintf(stderr, "after ex_put_elem_block, error = %d\n", err);
      ex_close(exoid);
      exit(-1);
    }

    if (num_domains > 1) {
      err = ex_put_elem_conn(exoid, EBLK_ID, loc_connect);
    }
    else {
      err = ex_put_elem_conn(exoid, EBLK_ID, connect);
    }

    if (err) {
      fprintf(stderr, "after ex_put_elem_conn, error = %d\n", err);
      ex_close(exoid);
      exit(-1);
    }

    if (debug) {
      fprintf(stderr, "\tConnectivity output.\n");
    }
    /* write out element and node maps */

    if (num_domains > 1) {
      err = ex_put_id_map(exoid, EX_NODE_MAP, node_map);

      if (err) {
        fprintf(stderr, "after ex_put_id_map, error = %d\n", err);
        ex_close(exoid);
        exit(-1);
      }

      err = ex_put_id_map(exoid, EX_ELEM_MAP, elem_map);

      if (err) {
        fprintf(stderr, "after ex_put_id_map, error = %d\n", err);
        ex_close(exoid);
        exit(-1);
      }

      if (debug) {
        fprintf(stderr, "\tMaps output.\n");
      }
    }

    /* write out simulated results fields;
       we'll just write out the x coordinate field 'num_nodal_fields' times */
    if (loc_num_nodes < loc_num_elements) {
      fprintf(stderr, "INTERNAL ERROR: Programmer assumed number of nodes > number of elements, "
                      "but that is not true.\n");
      ex_close(exoid);
      exit(-1);
    }

    if (num_element_fields > 0) {
      elem_var_tab = malloc(num_element_fields * sizeof(int));
      for (j            = 0; j < num_element_fields; j++)
        elem_var_tab[j] = 1;
    }
    else {
      elem_var_tab = 0;
    }
    err = ex_put_all_var_param(exoid, num_global_fields, num_nodal_fields, num_element_fields,
                               elem_var_tab, 0, 0, 0, 0);
    if (err) {
      fprintf(stderr, "after ex_put_all_var_param, error = %d\n", err);
      ex_close(exoid);
      exit(-1);
    }

    if (num_nodal_fields > 0) {

      var_name = malloc(num_nodal_fields * sizeof(char *));
      for (j = 0; j < num_nodal_fields; j++) {
        var_name[j] = malloc((MAX_STRING_LEN + 1) * sizeof(char));
        sprintf(var_name[j], "node_field_%" PRId64, j + 1);
      }
      err = ex_put_variable_names(exoid, EX_NODAL, num_nodal_fields, var_name);
      for (j = 0; j < num_nodal_fields; j++) {
        free(var_name[j]);
      }
      free(var_name);
    }

    if (num_global_fields > 0) {
      globals  = malloc(num_global_fields * sizeof(realtyp));
      var_name = malloc(num_global_fields * sizeof(char *));
      for (j = 0; j < num_global_fields; j++) {
        var_name[j] = malloc((MAX_STRING_LEN + 1) * sizeof(char));
        sprintf(var_name[j], "global_field_%" PRId64, j + 1);
        globals[j] = j;
      }
      err = ex_put_variable_names(exoid, EX_GLOBAL, num_global_fields, var_name);
      for (j = 0; j < num_global_fields; j++) {
        free(var_name[j]);
      }
      free(var_name);
    }

    if (num_element_fields > 0) {
      free(elem_var_tab);
      var_name = malloc(num_element_fields * sizeof(char *));
      for (j = 0; j < num_element_fields; j++) {
        var_name[j] = malloc((MAX_STRING_LEN + 1) * sizeof(char));
        sprintf(var_name[j], "element_field_%" PRId64, j + 1);
      }
      err = ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_element_fields, var_name);
      for (j = 0; j < num_element_fields; j++) {
        free(var_name[j]);
      }
      free(var_name);
    }

    if (num_nodal_fields + num_global_fields + num_element_fields > 0) {
      fprintf(stderr, "Domain %" PRId64 "/%" PRId64 ", Writing Timestep: ", i + 1, num_domains);
      for (t = 0; t < num_timesteps; t++) {
        realtyp time = t;
        ex_put_time(exoid, t + 1, &time);
        fprintf(stderr, "%" PRId64 ", ", t + 1);
        if (num_global_fields > 0) {
          err = ex_put_var(exoid, t + 1, EX_GLOBAL, 1, 0, num_global_fields, globals);
          if (err) {
            fprintf(stderr, "after ex_put_global_var, error = %d\n", err);
            ex_close(exoid);
            exit(-1);
          }
        }
        for (j = 0; j < num_nodal_fields; j++) {
          err = ex_put_var(exoid, t + 1, EX_NODAL, j + 1, 0, loc_num_nodes, x);
          if (err) {
            fprintf(stderr, "after ex_put_nodal_var, error = %d\n", err);
            ex_close(exoid);
            exit(-1);
          }
        }
        for (j = 0; j < num_element_fields; j++) {
          err = ex_put_var(exoid, t + 1, EX_ELEM_BLOCK, j + 1, EBLK_ID, loc_num_elements, x);
          if (err) {
            fprintf(stderr, "after ex_put_element_var, error = %d\n", err);
            ex_close(exoid);
            exit(-1);
          }
        }
      }
      fprintf(stderr, "\n");
    }

    err = ex_close(exoid);

    if (err) {
      fprintf(stderr, "after ex_close, error = %d\n", err);
      exit(-1);
    }
    if (debug) {
      fprintf(stderr, "\tFile written.\n");
    }
  }

  /*
   * Free Memory
   */

  if (num_domains > 1) {
    free(domain_connect);
    free(elem_map);
    free(loc_connect);
    free(loc_xcoords);
    free(loc_ycoords);
    free(loc_zcoords);
    free(node_map);
  }
  if (num_global_fields > 0)
    free(globals);
}
示例#5
0
int main (int argc, char **argv)
{
  int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
  int num_elem_in_block[10], num_nodes_per_elem[10];
  int num_node_sets, num_side_sets, error;
  int i, j, k, kk, m, *elem_map, *connect;
  int node_list[100],elem_list[100],side_list[100];
  int ebids[10], ssids[10], nsids[10], nattr[10];
  int num_nodes_per_set[10], num_elem_per_set[10];
  int num_df_per_set[10];
  int  num_qa_rec, num_info;
  int num_glo_vars, num_nod_vars, num_ele_vars, num_nset_vars, num_sset_vars;
  int *truth_tab, *nset_tab, *sset_tab;
  int whole_time_step, num_time_steps;
  int CPU_word_size,IO_word_size;
  int prop_array[2];

  float *glob_var_vals, *nodal_var_vals, *elem_var_vals, *nset_var_vals, *sset_var_vals;
  float time_value;
  float x[100], y[100], z[100];
  float attrib[1], dist_fact[100];
  char *coord_names[3], *qa_record[2][4], *info[3], *var_names[7];
  char *prop_names[2];
  char *eb_type[10];
   
  ex_opts (EX_VERBOSE|EX_ABORT);

  /* Specify compute and i/o word size */

  CPU_word_size = 0;                   /* sizeof(float) */
  IO_word_size = 4;                    /* (4 bytes) */

  /* create EXODUS II file */

  exoid = ex_create ("test.exo",       /* filename path */
		     EX_CLOBBER,      /* create mode */
		     &CPU_word_size,  /* CPU float word size in bytes */
		     &IO_word_size);  /* I/O float word size in bytes */
  printf ("after ex_create for test.exo, exoid = %d\n", exoid);
  printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

  /* ncopts = NC_VERBOSE; */

  /* initialize file with parameters */

  num_dim = 3;
  num_nodes = 33;
  num_elem = 7;
  num_elem_blk = 7;
  num_node_sets = 2;
  num_side_sets = 5;

  error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem,
		       num_elem_blk, num_node_sets, num_side_sets);

  printf ("after ex_put_init, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  /* write nodal coordinates values and names to database */

  /* Quad #1 */
  x[0] = 0.0; y[0] = 0.0; z[0] = 0.0;
  x[1] = 1.0; y[1] = 0.0; z[1] = 0.0;
  x[2] = 1.0; y[2] = 1.0; z[2] = 0.0;
  x[3] = 0.0; y[3] = 1.0; z[3] = 0.0;

  /* Quad #2 */
  x[4]  =  1.0; y[4]  =  0.0; z[4]  =  0.0;
  x[5]  =  2.0; y[5]  =  0.0; z[5]  =  0.0;
  x[6]  =  2.0; y[6]  =  1.0; z[6]  =  0.0;
  x[7]  =  1.0; y[7]  =  1.0; z[7]  =  0.0;

  /* Hex #1 */
  x[8]  =  0.0; y[8]  =  0.0; z[8]  =  0.0;
  x[9]  = 10.0; y[9]  =  0.0; z[9]  =  0.0;
  x[10] = 10.0; y[10] =  0.0; z[10] =-10.0;
  x[11] =  1.0; y[11] =  0.0; z[11] =-10.0;
  x[12] =  1.0; y[12] = 10.0; z[12] =  0.0;
  x[13] = 10.0; y[13] = 10.0; z[13] =  0.0;
  x[14] = 10.0; y[14] = 10.0; z[14] =-10.0;
  x[15] =  1.0; y[15] = 10.0; z[15] =-10.0;

  /* Tetra #1 */
  x[16] =  0.0; y[16] =  0.0; z[16] =  0.0;
  x[17] =  1.0; y[17] =  0.0; z[17] =  5.0;
  x[18] = 10.0; y[18] =  0.0; z[18] =  2.0;
  x[19] =  7.0; y[19] =  5.0; z[19] =  3.0;

  /* Wedge #1 */
  x[20] =  3.0; y[20] =  0.0; z[20] =  6.0;
  x[21] =  6.0; y[21] =  0.0; z[21] =  0.0;
  x[22] =  0.0; y[22] =  0.0; z[22] =  0.0;
  x[23] =  3.0; y[23] =  2.0; z[23] =  6.0;
  x[24] =  6.0; y[24] =  2.0; z[24] =  2.0;
  x[25] =  0.0; y[25] =  2.0; z[25] =  0.0;

  /* Tetra #2 */
  x[26] =  2.7; y[26] =  1.7; z[26] =  2.7;
  x[27] =  6.0; y[27] =  1.7; z[27] =  3.3;
  x[28] =  5.7; y[28] =  1.7; z[28] =  1.7;
  x[29] =  3.7; y[29] =  0.0; z[29] =  2.3;

  /* 3d Tri */
  x[30] =  0.0; y[30] =  0.0; z[30] =  0.0;
  x[31] = 10.0; y[31] =  0.0; z[31] =  0.0;
  x[32] = 10.0; y[32] = 10.0; z[32] = 10.0;

  error = ex_put_coord (exoid, x, y, z);
  printf ("after ex_put_coord, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  coord_names[0] = "xcoor";
  coord_names[1] = "ycoor";
  coord_names[2] = "zcoor";

  error = ex_put_coord_names (exoid, coord_names);
  printf ("after ex_put_coord_names, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  /* write element order map */

  elem_map = (int *) calloc(num_elem, sizeof(int));

  for (i=1; i<=num_elem; i++)
    {
      elem_map[i-1] = i;
    }

  error = ex_put_map (exoid, elem_map);
  printf ("after ex_put_map, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  free (elem_map);


  /* write element block parameters */

  num_elem_in_block[0] = 1;
  num_elem_in_block[1] = 1;
  num_elem_in_block[2] = 1;
  num_elem_in_block[3] = 1;
  num_elem_in_block[4] = 1;
  num_elem_in_block[5] = 1;
  num_elem_in_block[6] = 1;

  num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
  num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
  num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
  num_nodes_per_elem[3] = 4; /* elements in block #4 are 4-node tetras */
  num_nodes_per_elem[4] = 6; /* elements in block #5 are 6-node wedges */
  num_nodes_per_elem[5] = 8; /* elements in block #6 are 8-node tetras */
  num_nodes_per_elem[6] = 3; /* elements in block #7 are 3-node tris   */

  ebids[0] = 10;
  ebids[1] = 11;
  ebids[2] = 12;
  ebids[3] = 13;
  ebids[4] = 14;
  ebids[5] = 15;
  ebids[6] = 16;

  nattr[0] = nattr[1] = nattr[2] = nattr[3] = 1;
  nattr[4] = nattr[5] = nattr[6] = 1;
   
  eb_type[0] = "quad";
  eb_type[1] = "quad";
  eb_type[2] = "hex";
  eb_type[3] = "tetra";
  eb_type[4] = "wedge";
  eb_type[5] = "tetra";
  eb_type[6] = "tri";
     
  error = ex_put_concat_elem_block (exoid, ebids, eb_type,
				    num_elem_in_block, num_nodes_per_elem,
				    nattr, 0);
  printf ("after ex_put_concat_elem_block, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  /* write element block properties */

  prop_names[0] = "MATL";
  prop_names[1] = "DENSITY";
  error = ex_put_prop_names(exoid,EX_ELEM_BLOCK,2,prop_names);
  printf ("after ex_put_prop_names, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], "MATL", 60);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], "MATL", 70);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* write element connectivity */

  connect = (int *) calloc(8, sizeof(int));
  connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;

  error = ex_put_elem_conn (exoid, ebids[0], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  connect[0] = 5; connect[1] = 6; connect[2] = 7; connect[3] = 8;

  error = ex_put_elem_conn (exoid, ebids[1], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12;
  connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16;

  error = ex_put_elem_conn (exoid, ebids[2], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;

  error = ex_put_elem_conn (exoid, ebids[3], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  connect[0] = 21; connect[1] = 22; connect[2] = 23;
  connect[3] = 24; connect[4] = 25; connect[5] = 26;

  error = ex_put_elem_conn (exoid, ebids[4], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;
  connect[4] = 27; connect[5] = 28; connect[6] = 30; connect[7] = 29;

  error = ex_put_elem_conn (exoid, ebids[5], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  connect[0] = 31; connect[1] = 32; connect[2] = 33;

  error = ex_put_elem_conn (exoid, ebids[6], connect);
  printf ("after ex_put_elem_conn, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  free (connect);


  /* write element block attributes */

  attrib[0] = 3.14159;
  error = ex_put_elem_attr (exoid, ebids[0], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  attrib[0] = 6.14159;
  error = ex_put_elem_attr (exoid, ebids[1], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_elem_attr (exoid, ebids[2], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_elem_attr (exoid, ebids[3], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_elem_attr (exoid, ebids[4], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_elem_attr (exoid, ebids[5], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_elem_attr (exoid, ebids[6], attrib);
  printf ("after ex_put_elem_attr, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  /* write individual node sets */


  nsids[0] = 20; nsids[1] = 21;
  num_nodes_per_set[0] = 5; num_nodes_per_set[1] = 3;
  num_df_per_set[0] = 5; num_df_per_set[1] = 3;

  error = ex_put_concat_node_sets (exoid, nsids, num_nodes_per_set,
				   num_df_per_set, 0, 0, 0, 0);

  printf ("after ex_put_concat_node_sets, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; 
  node_list[3] = 13; node_list[4] = 14; 

  dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0;
  dist_fact[3] = 4.0; dist_fact[4] = 5.0;

  error = ex_put_node_set (exoid, 20, node_list);
  printf ("after ex_put_node_set, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_node_set_dist_fact (exoid, 20, dist_fact);
  printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  node_list[0] = 20; node_list[1] = 21; node_list[2] = 22; 

  dist_fact[0] = 1.1; dist_fact[1] = 2.1; dist_fact[2] = 3.1;

  error = ex_put_node_set (exoid, 21, node_list);
  printf ("after ex_put_node_set, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_node_set_dist_fact (exoid, 21, dist_fact);
  printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
  printf ("after ex_put_prop, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
  printf ("after ex_put_prop, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  prop_array[0] = 1000;
  prop_array[1] = 2000;

  error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
  printf ("after ex_put_prop_array, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  /* Define the sideset params at one time, then write individually */
  ssids[0] = 30;
  ssids[1] = 31;
  ssids[2] = 32;
  ssids[3] = 33;
  ssids[4] = 34;

  num_elem_per_set[0] = 2;
  num_elem_per_set[1] = 2;
  num_elem_per_set[2] = 7;
  num_elem_per_set[3] = 8;
  num_elem_per_set[4] = 10;

  num_df_per_set[0] = 4;
  num_df_per_set[1] = 4;
  num_df_per_set[2] = 0;
  num_df_per_set[3] = 0;
  num_df_per_set[4] = 0;

  error = ex_put_concat_side_sets (exoid, ssids, num_elem_per_set,
				   num_df_per_set, 0, 0, 0, 0, 0);
  printf ("after ex_put_concat_side_sets, error = %d\n", error);

  /* write individual side sets */

  /* side set #1  - quad */

  elem_list[0] = 2; elem_list[1] = 2;

  side_list[0] = 4; side_list[1] = 2;

  dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2;
  dist_fact[3] = 30.3;

  error = ex_put_side_set (exoid, 30, elem_list, side_list);
  printf ("after ex_put_side_set, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_side_set_dist_fact (exoid, 30, dist_fact);
  printf ("after ex_put_side_set_dist_fact, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* side set #2  - quad, spanning 2 elements  */

  elem_list[0] = 1; elem_list[1] = 2;

  side_list[0] = 2; side_list[1] = 3;

  dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2;
  dist_fact[3] = 31.3;

  error = ex_put_side_set (exoid, 31, elem_list, side_list);
  printf ("after ex_put_side_set, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_side_set_dist_fact (exoid, 31, dist_fact);
  printf ("after ex_put_side_set_dist_fact, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* side set #3  - hex */

  elem_list[0] = 3; elem_list[1] = 3;
  elem_list[2] = 3; elem_list[3] = 3;
  elem_list[4] = 3; elem_list[5] = 3;
  elem_list[6] = 3;

  side_list[0] = 5; side_list[1] = 3;
  side_list[2] = 3; side_list[3] = 2;
  side_list[4] = 4; side_list[5] = 1;
  side_list[6] = 6;

  error = ex_put_side_set (exoid, 32, elem_list, side_list);
  printf ("after ex_put_side_set, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* side set #4  - tetras */

  elem_list[0] = 4; elem_list[1] = 4;
  elem_list[2] = 4; elem_list[3] = 4;
  elem_list[4] = 6; elem_list[5] = 6;
  elem_list[6] = 6; elem_list[7] = 6;

  side_list[0] = 1; side_list[1] = 2;
  side_list[2] = 3; side_list[3] = 4;
  side_list[4] = 1; side_list[5] = 2;
  side_list[6] = 3; side_list[7] = 4;

  error = ex_put_side_set (exoid, 33, elem_list, side_list);
  printf ("after ex_put_side_set, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* side set #5  - wedges and tris */

  elem_list[0] = 5; elem_list[1] = 5;
  elem_list[2] = 5; elem_list[3] = 5;
  elem_list[4] = 5; elem_list[5] = 7;
  elem_list[6] = 7; elem_list[7] = 7;
  elem_list[8] = 7; elem_list[9] = 7;

  side_list[0] = 1; side_list[1] = 2;
  side_list[2] = 3; side_list[3] = 4;
  side_list[4] = 5; side_list[5] = 1;
  side_list[6] = 2; side_list[7] = 3;
  side_list[8] = 4; side_list[9] = 5;

  error = ex_put_side_set (exoid, 34, elem_list, side_list);
  printf ("after ex_put_side_set, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
  printf ("after ex_put_prop, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
  printf ("after ex_put_prop, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* write QA records; test empty and just blank-filled records */

  num_qa_rec = 2;


  qa_record[0][0] = "TESTWT";
  qa_record[0][1] = "testwt";
  qa_record[0][2] = "07/07/93";
  qa_record[0][3] = "15:41:33";
  qa_record[1][0] = "";
  qa_record[1][1] = "                            ";
  qa_record[1][2] = "";
  qa_record[1][3] = "                        ";

  error = ex_put_qa (exoid, num_qa_rec, qa_record);
  printf ("after ex_put_qa, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* write information records; test empty and just blank-filled records */

  num_info = 3;


  info[0] = "This is the first information record.";
  info[1] = "";
  info[2] = "                                     ";

  error = ex_put_info (exoid, num_info, info);
  printf ("after ex_put_info, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }



  /* write results variables parameters and names */
  num_glo_vars  = 1;
  num_nod_vars  = 2;
  num_ele_vars  = 3;
  num_nset_vars = 4;
  num_sset_vars = 7;

  truth_tab = (int *) calloc ((num_elem_blk  * num_ele_vars),  sizeof(int));
  nset_tab  = (int *) calloc ((num_node_sets * num_nset_vars), sizeof(int));
  sset_tab  = (int *) calloc ((num_side_sets * num_sset_vars), sizeof(int));

  k = 0;
  for (i=0; i<num_elem_blk; i++) {
    for (j=0; j<num_ele_vars; j++) {
      truth_tab[k++] = 1;
    }
  }
   
  k = 0;
  for (i=0; i<num_node_sets; i++) {
    for (j=0; j<num_nset_vars; j++) {
      if (k%2 == 0)
	nset_tab[k++] = 1;
      else
	nset_tab[k++] = 0;
    }
  }
   
  k = 0;
  for (i=0; i<num_side_sets; i++) {
    for (j=0; j<num_sset_vars; j++) {
      if (k%2 == 0)
	sset_tab[k++] = 0;
      else
	sset_tab[k++] = 1;
    }
  }
   
  ex_put_all_var_param(exoid, num_glo_vars, num_nod_vars, num_ele_vars, truth_tab,
		       num_nset_vars, nset_tab, num_sset_vars, sset_tab);
  printf ("after ex_put_all_var_param, error = %d\n", error);

  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  free (truth_tab);
  free (nset_tab);
  free (sset_tab);
   
  var_names[0] = "glo_vars";
  error = ex_put_var_names (exoid, "g", num_glo_vars, var_names);
  printf ("after ex_put_var_names, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  /*              12345678901234567890123456789012 */
  var_names[0] = "node_variable_a_very_long_name_0";
  var_names[1] = "nod_var1";
  error = ex_put_var_names (exoid, "n", num_nod_vars, var_names);
  printf ("after ex_put_var_names, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }



  var_names[0] = "ele_var0";
  var_names[1] = "ele_var1";
  var_names[2] = "ele_var2";
  error = ex_put_var_names (exoid, "e", num_ele_vars, var_names);
  printf ("after ex_put_var_names, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  var_names[0] = "nset_var0";
  var_names[1] = "nset_var1";
  var_names[2] = "nset_var2";
  var_names[3] = "nset_var3";
  error = ex_put_var_names (exoid, "m", num_nset_vars, var_names);
  printf ("after ex_put_var_names, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }

  var_names[0] = "sset_var0";
  var_names[1] = "sset_var1";
  var_names[2] = "sset_var2";
  var_names[3] = "sset_var3";
  var_names[4] = "sset_var4";
  var_names[5] = "sset_var5";
  var_names[6] = "sset_var6";
  error = ex_put_var_names (exoid, "s", num_sset_vars, var_names);
  printf ("after ex_put_var_names, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }


  /* for each time step, write the analysis results;
   * the code below fills the arrays glob_var_vals, 
   * nodal_var_vals, and elem_var_vals with values for debugging purposes;
   * obviously the analysis code will populate these arrays
   */

  whole_time_step = 1;
  num_time_steps = 10;

  glob_var_vals =  (float *) calloc (num_glo_vars, CPU_word_size);
  nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
  elem_var_vals =  (float *) calloc (4, CPU_word_size);
  nset_var_vals =  (float *) calloc (5, CPU_word_size);
  sset_var_vals =  (float *) calloc (10, CPU_word_size);

  for (i=0; i<num_time_steps; i++)
    {
      time_value = (float)(i+1)/100.;

      /* write time value */

      error = ex_put_time (exoid, whole_time_step, &time_value);
      printf ("after ex_put_time, error = %d\n", error);

      if (error) {
	ex_close (exoid);
	exit(-1);
      }

      /* write global variables */

      for (j=0; j<num_glo_vars; j++) {
	glob_var_vals[j] = (float)(j+2) * time_value;
      }

      error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
				glob_var_vals);
      printf ("after ex_put_glob_vars, error = %d\n", error);

      if (error) {
	ex_close (exoid);
	exit(-1);
      }

      /* write nodal variables */

      for (k=1; k<=num_nod_vars; k++) {
	for (j=0; j<num_nodes; j++) {
	  nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
	}

	error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes,
				  nodal_var_vals);
	printf ("after ex_put_nodal_var, error = %d\n", error);
	if (error) {
	  ex_close (exoid);
	  exit(-1);
	}

      }

      /* write element variables */

      for (k=1; k<=num_ele_vars; k++) {
	for (j=0; j<num_elem_blk; j++) {
	  for (m=0; m<num_elem_in_block[j]; m++) {
	    elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
	      ((float)(m+1)*time_value);
	  }
	  error = ex_put_elem_var (exoid, whole_time_step, k, ebids[j],
				   num_elem_in_block[j], elem_var_vals);
	  printf ("after ex_put_elem_var, error = %d\n", error);
	  if (error) {
	    ex_close (exoid);
	    exit(-1);
	  }
	}
      }

      /* write nodeset variables */

      kk = 0;
      for (j=0; j<num_node_sets; j++) {
	for (k=0; k<num_nset_vars; k++) {
	  if (kk++ % 2 == 0) {
	    for (m=0; m<num_nodes_per_set[j]; m++) {
	      nset_var_vals[m] = (float)(k+1) + (float)(j+2) + 
		((float)(m+1)*time_value);
	    }
	    error = ex_put_nset_var (exoid, whole_time_step, k+1, nsids[j],
				     num_nodes_per_set[j], nset_var_vals);
	    printf ("after ex_put_nset_var, error = %d\n", error);
	    if (error) {
	      ex_close (exoid);
	      exit(-1);
	    }
	  }
	}
      }

      /* write sideset variables */

      kk = 0;
      for (j=0; j<num_side_sets; j++) {
	for (k=0; k<num_sset_vars; k++) {
	  if (kk++ % 2 != 0) {
	    for (m=0; m<num_elem_per_set[j]; m++) {
	      sset_var_vals[m] = (float)(k+1) + (float)(j+2) + 
		((float)(m+1)*time_value);
	    }
	    error = ex_put_sset_var (exoid, whole_time_step, k+1, ssids[j],
				     num_elem_per_set[j], sset_var_vals);
	    printf ("after ex_put_sset_var, error = %d\n", error);
	    if (error) {
	      ex_close (exoid);
	      exit(-1);
	    }
	  }
	}
      }

      whole_time_step++;

      /* update the data file; this should be done at the end of every time step
       * to ensure that no data is lost if the analysis dies
       */
      error = ex_update (exoid);
      printf ("after ex_update, error = %d\n", error);
      if (error) {
	ex_close (exoid);
	exit(-1);
      }
    }
  free(glob_var_vals);
  free(nodal_var_vals);
  free(elem_var_vals);
  free(nset_var_vals);
  free(sset_var_vals);

  /* close the EXODUS files
   */
  error = ex_close (exoid);
  printf ("after ex_close, error = %d\n", error);
  if (error) {
    ex_close (exoid);
    exit(-1);
  }
  return 0;
}
示例#6
0
int main(int argc, char **argv)
{
  int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
  int num_elem_in_block[10], num_nodes_per_elem[10], num_attr[10];
  int num_node_sets, num_side_sets, error;
  int i, j, k, m, *elem_map, *connect, *node_map;
  int node_list[100], elem_list[100], side_list[100];
  int ebids[10], ids[10];
  int num_nodes_per_set[10], num_elem_per_set[10];
  int num_df_per_set[10];
  int df_ind[10], node_ind[10], elem_ind[10];
  int num_qa_rec, num_info;
  int num_glo_vars, num_nod_vars, num_ele_vars;
  int whole_time_step, num_time_steps;
  int CPU_word_size, IO_word_size;
  int prop_array[2];

  float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
  float  time_value;
  float  x[100], y[100], z[100];
  float  attrib[100], dist_fact[100];
  char * coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
  char * prop_names[2];

  ex_opts(EX_VERBOSE | EX_ABORT);

  /* Specify compute and i/o word size */

  CPU_word_size = 0; /* float or double */
  IO_word_size  = 0; /* use system default (4 bytes) */

  /* create EXODUS II file */

  exoid = ex_create("test.exo",     /* filename path */
                    EX_CLOBBER,     /* create mode */
                    &CPU_word_size, /* CPU float word size in bytes */
                    &IO_word_size); /* I/O float word size in bytes */
  printf("after ex_create for test.exo, exoid = %d\n", exoid);
  printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);

  /* initialize file with parameters */

  num_dim       = 3;
  num_nodes     = 28;
  num_elem      = 8;
  num_elem_blk  = 7;
  num_node_sets = 2;
  num_side_sets = 5;
  /* num_side_sets = 6; Uncomment to test NULL side sets */

  error = ex_put_init(exoid, "This is testwt1", num_dim, num_nodes, num_elem, num_elem_blk,
                      num_node_sets, num_side_sets);

  printf("after ex_put_init, error = %d\n", error);

  /* write nodal coordinates values and names to database */

  /* Quad #1 */
  x[0] = 0.0;
  y[0] = 0.0;
  z[0] = 0.0;
  x[1] = 1.0;
  y[1] = 0.0;
  z[1] = 0.0;
  x[2] = 1.0;
  y[2] = 1.0;
  z[2] = 0.0;
  x[3] = 0.0;
  y[3] = 1.0;
  z[3] = 0.0;

  /* Quad #2 */
  x[4] = 1.0;
  y[4] = 0.0;
  z[4] = 0.0;
  x[5] = 2.0;
  y[5] = 0.0;
  z[5] = 0.0;
  x[6] = 2.0;
  y[6] = 1.0;
  z[6] = 0.0;
  x[7] = 1.0;
  y[7] = 1.0;
  z[7] = 0.0;

  /* Hex #1 */
  x[8]  = 0.0;
  y[8]  = 0.0;
  z[8]  = 0.0;
  x[9]  = 10.0;
  y[9]  = 0.0;
  z[9]  = 0.0;
  x[10] = 10.0;
  y[10] = 0.0;
  z[10] = -10.0;
  x[11] = 1.0;
  y[11] = 0.0;
  z[11] = -10.0;
  x[12] = 1.0;
  y[12] = 10.0;
  z[12] = 0.0;
  x[13] = 10.0;
  y[13] = 10.0;
  z[13] = 0.0;
  x[14] = 10.0;
  y[14] = 10.0;
  z[14] = -10.0;
  x[15] = 1.0;
  y[15] = 10.0;
  z[15] = -10.0;

  /* Tetra #1 */
  x[16] = 0.0;
  y[16] = 0.0;
  z[16] = 0.0;
  x[17] = 1.0;
  y[17] = 0.0;
  z[17] = 5.0;
  x[18] = 10.0;
  y[18] = 0.0;
  z[18] = 2.0;
  x[19] = 7.0;
  y[19] = 5.0;
  z[19] = 3.0;

  /* Circle #1 */
  x[20] = 100.0;
  y[20] = 100.0;
  z[20] = 0.0;

  /* Sphere #1 */
  x[21] = 50.0;
  y[21] = 50.0;
  z[21] = 20.0;

  /* Wedge #1 */
  x[22] = 3.0;
  y[22] = 0.0;
  z[22] = 6.0;
  x[23] = 6.0;
  y[23] = 0.0;
  z[23] = 0.0;
  x[24] = 0.0;
  y[24] = 0.0;
  z[24] = 0.0;
  x[25] = 3.0;
  y[25] = 2.0;
  z[25] = 6.0;
  x[26] = 6.0;
  y[26] = 2.0;
  z[26] = 2.0;
  x[27] = 0.0;
  y[27] = 2.0;
  z[27] = 0.0;

  error = ex_put_coord(exoid, x, y, z);
  printf("after ex_put_coord, error = %d\n", error);

  coord_names[0] = "xcoor";
  coord_names[1] = "ycoor";
  coord_names[2] = "zcoor";

  error = ex_put_coord_names(exoid, coord_names);
  printf("after ex_put_coord_names, error = %d\n", error);

  /* write element order map */

  elem_map = (int *)calloc(num_elem, sizeof(int));

  for (i = 1; i <= num_elem; i++) {
    elem_map[i - 1] = i;
  }

  error = ex_put_map(exoid, elem_map);
  printf("after ex_put_map, error = %d\n", error);

  free(elem_map);

  /* write element numbering map */

  elem_map = (int *)calloc(num_elem, sizeof(int));

  for (i = 1; i <= num_elem; i++) {
    elem_map[i - 1] = i * 2;
  }

  error = ex_put_id_map(exoid, EX_ELEM_MAP, elem_map);
  printf("after ex_put_elem_num_map, error = %d\n", error);

  free(elem_map);

  /* write node numbering map */

  node_map = (int *)calloc(num_nodes, sizeof(int));

  for (i = 1; i <= num_nodes; i++) {
    node_map[i - 1] = i * 3;
  }

  error = ex_put_id_map(exoid, EX_NODE_MAP, node_map);
  printf("after ex_put_node_num_map, error = %d\n", error);

  free(node_map);

  /* write element block parameters */

  num_elem_in_block[0] = 1; /* element 1: Quad 1 */
  num_elem_in_block[1] = 2; /* elements 2, 3: Quad 1 & 2 */
  num_elem_in_block[2] = 1; /* element 4: Hex    */
  num_elem_in_block[3] = 1; /* element 5: Tetra  */
  num_elem_in_block[4] = 1; /* element 6: Circle */
  num_elem_in_block[5] = 1; /* element 7: Sphere */
  num_elem_in_block[6] = 1; /* element 8: Wedge  */

  num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
  num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
  num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
  num_nodes_per_elem[3] = 4; /* elements in block #3 are 4-node tetras */
  num_nodes_per_elem[4] = 1; /* elements in block #4 are 1-node circles */
  num_nodes_per_elem[5] = 1; /* elements in block #5 are 1-node spheres */
  num_nodes_per_elem[6] = 6; /* elements in block #6 are 6-node wedges */

  ebids[0] = 10;
  ebids[1] = 11;
  ebids[2] = 12;
  ebids[3] = 13;
  ebids[4] = 14;
  ebids[5] = 15;
  ebids[6] = 16;

  num_attr[0] = 3;
  num_attr[1] = 3;
  num_attr[2] = 3;
  num_attr[3] = 3;
  num_attr[4] = 3;
  num_attr[5] = 3;
  num_attr[6] = 3;

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[0], "quad", num_elem_in_block[0],
                       num_nodes_per_elem[0], 0, 0, num_attr[0]);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[1], "quad", num_elem_in_block[1],
                       num_nodes_per_elem[1], 0, 0, num_attr[1]);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[2], "hex", num_elem_in_block[2],
                       num_nodes_per_elem[2], 0, 0, num_attr[2]);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[3], "tetra", num_elem_in_block[3],
                       num_nodes_per_elem[3], 0, 0, num_attr[3]);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[4], "circle", num_elem_in_block[4],
                       num_nodes_per_elem[4], 0, 0, num_attr[4]);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[5], "sphere", num_elem_in_block[5],
                       num_nodes_per_elem[5], 0, 0, num_attr[5]);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[6], "wedge", num_elem_in_block[6],
                       num_nodes_per_elem[6], 0, 0, num_attr[6]);
  printf("after ex_put_elem_block, error = %d\n", error);

  /* write element block properties */

  prop_names[0] = "MATL";
  prop_names[1] = "DENSITY";
  error         = ex_put_prop_names(exoid, EX_ELEM_BLOCK, 2, prop_names);
  printf("after ex_put_prop_names, error = %d\n", error);

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], "MATL", 60);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], "MATL", 70);
  printf("after ex_put_prop, error = %d\n", error);

  /* write element connectivity */

  connect    = (int *)calloc(8, sizeof(int));
  connect[0] = 1;
  connect[1] = 2;
  connect[2] = 3;
  connect[3] = 4;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 1;
  connect[1] = 2;
  connect[2] = 3;
  connect[3] = 4;
  connect[4] = 5;
  connect[5] = 6;
  connect[6] = 7;
  connect[7] = 8;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[1], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 9;
  connect[1] = 10;
  connect[2] = 11;
  connect[3] = 12;
  connect[4] = 13;
  connect[5] = 14;
  connect[6] = 15;
  connect[7] = 16;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 17;
  connect[1] = 18;
  connect[2] = 19;
  connect[3] = 20;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[3], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 21;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[4], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 22;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[5], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 23;
  connect[1] = 24;
  connect[2] = 25;
  connect[3] = 26;
  connect[4] = 27;
  connect[5] = 28;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[6], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  free(connect);

  /* write element block attributes  (3 per block) */

  attrib[0]  = 1.0;
  attrib[1]  = 2.0;
  attrib[2]  = 3.0;
  attrib[3]  = 1.11;
  attrib[4]  = 2.11;
  attrib[5]  = 3.11;
  attrib[6]  = 1.12;
  attrib[7]  = 2.12;
  attrib[8]  = 3.12;
  attrib[9]  = 1.2;
  attrib[10] = 2.2;
  attrib[11] = 3.2;
  attrib[12] = 1.3;
  attrib[13] = 2.3;
  attrib[14] = 3.3;
  attrib[15] = 1.4;
  attrib[16] = 2.4;
  attrib[17] = 3.4;
  attrib[18] = 1.5;
  attrib[19] = 2.5;
  attrib[20] = 3.5;
  attrib[21] = 1.6;
  attrib[22] = 2.6;
  attrib[23] = 3.6;

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[0], &attrib[0]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[1], &attrib[3]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[2], &attrib[9]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[3], &attrib[12]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[4], &attrib[15]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[5], &attrib[18]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[6], &attrib[21]);
  printf("after ex_put_elem_attr, error = %d\n", error);

  /* write individual node sets */

  ids[0] = 20;
  ids[1] = 21;

  num_nodes_per_set[0] = 5;
  num_nodes_per_set[1] = 3;
  /* num_nodes_per_set[1] = 0; Uncomment to test NULL node sets */

  node_ind[0] = 0;
  node_ind[1] = 5;

  node_list[0] = 10;
  node_list[1] = 11;
  node_list[2] = 12;
  node_list[3] = 13;
  node_list[4] = 14;
  node_list[5] = 20;
  node_list[6] = 21;
  node_list[7] = 22;

  num_df_per_set[0] = 5;
  num_df_per_set[1] = 3;

  df_ind[0] = 0;
  df_ind[1] = 5;

  dist_fact[0] = 1.0;
  dist_fact[1] = 2.0;
  dist_fact[2] = 3.0;
  dist_fact[3] = 4.0;
  dist_fact[4] = 5.0;
  dist_fact[5] = 1.1;
  dist_fact[6] = 2.1;
  dist_fact[7] = 3.1;

  {
    struct ex_set_specs set_specs;

    set_specs.sets_ids            = ids;
    set_specs.num_entries_per_set = num_nodes_per_set;
    set_specs.num_dist_per_set    = num_df_per_set;
    set_specs.sets_entry_index    = node_ind;
    set_specs.sets_dist_index     = df_ind;
    set_specs.sets_entry_list     = node_list;
    set_specs.sets_extra_list     = NULL;
    set_specs.sets_dist_fact      = dist_fact;
    error                         = ex_put_concat_sets(exoid, EX_NODE_SET, &set_specs);
  }

  printf("after ex_put_concat_node_sets, error = %d\n", error);

  error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
  printf("after ex_put_prop, error = %d\n", error);

  prop_array[0] = 1000;
  prop_array[1] = 2000;

  error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
  printf("after ex_put_prop_array, error = %d\n", error);

  ids[0] = 30;
  ids[1] = 31;
  ids[2] = 32;
  ids[3] = 33;
  ids[4] = 34;
  ids[5] = 35;

  /* side set #1  - quad */
  node_list[0] = 8;
  node_list[1] = 5;
  node_list[2] = 6;
  node_list[3] = 7;

  /* side set #2  - quad/hex, spanning 2 element types  */
  node_list[4] = 2;
  node_list[5] = 3;
  node_list[6] = 7;
  node_list[7] = 8;

  /* side set #3  - hex */
  node_list[8]  = 9;
  node_list[9]  = 12;
  node_list[10] = 11;
  node_list[11] = 10;

  node_list[12] = 11;
  node_list[13] = 12;
  node_list[14] = 16;
  node_list[15] = 15;

  node_list[16] = 16;
  node_list[17] = 15;
  node_list[18] = 11;
  node_list[19] = 12;

  node_list[20] = 10;
  node_list[21] = 11;
  node_list[22] = 15;
  node_list[23] = 14;

  node_list[24] = 13;
  node_list[25] = 16;
  node_list[26] = 12;
  node_list[27] = 9;

  node_list[28] = 14;
  node_list[29] = 13;
  node_list[30] = 9;
  node_list[31] = 10;

  node_list[32] = 16;
  node_list[33] = 13;
  node_list[34] = 14;
  node_list[35] = 15;

  /* side set #4  - tetras */
  node_list[36] = 17;
  node_list[37] = 18;
  node_list[38] = 20;

  node_list[39] = 18;
  node_list[40] = 19;
  node_list[41] = 20;

  node_list[42] = 20;
  node_list[43] = 19;
  node_list[44] = 17;

  node_list[45] = 19;
  node_list[46] = 18;
  node_list[47] = 17;

  /* side set #5  - circle and sphere */
  node_list[48] = 21;
  node_list[49] = 22;

  /* side set #6  - wedges */
  node_list[50] = 27;
  node_list[51] = 26;
  node_list[52] = 23;
  node_list[53] = 24;

  node_list[54] = 28;
  node_list[55] = 27;
  node_list[56] = 24;
  node_list[57] = 25;

  node_list[58] = 28;
  node_list[59] = 25;
  node_list[60] = 23;
  node_list[61] = 26;

  node_list[62] = 25;
  node_list[63] = 24;
  node_list[64] = 23;

  node_list[65] = 26;
  node_list[66] = 27;
  node_list[67] = 28;

  node_ind[0] = 0;
  node_ind[1] = 4;
  node_ind[2] = 8;
  node_ind[3] = 36;
  node_ind[4] = 47;
  node_ind[5] = 49;

  num_elem_per_set[0] = 2; /* two sides uses 2 elements */
  num_elem_per_set[1] = 2;
  num_elem_per_set[2] = 7;
  num_elem_per_set[3] = 4;
  num_elem_per_set[4] = 2;
  num_elem_per_set[5] = 5;
  /* num_elem_per_set[5] = 0; Uncomment to test NULL side sets */

  num_nodes_per_set[0] = 4;
  num_nodes_per_set[1] = 4;
  num_nodes_per_set[2] = 28;
  num_nodes_per_set[3] = 12;
  num_nodes_per_set[4] = 2;
  num_nodes_per_set[5] = 18;

  elem_ind[0] = 0;
  elem_ind[1] = 2;
  elem_ind[2] = 4;
  elem_ind[3] = 11;
  elem_ind[4] = 15;
  elem_ind[5] = 17;

  elem_list[0]  = 3;
  elem_list[1]  = 3; /* side set 1: Quad #2 */
  elem_list[2]  = 1;
  elem_list[3]  = 3; /* side set 2: Quad #1 & #2 */
  elem_list[4]  = 4;
  elem_list[5]  = 4; /* side set 3: Hex */
  elem_list[6]  = 4;
  elem_list[7]  = 4;
  elem_list[8]  = 4;
  elem_list[9]  = 4;
  elem_list[10] = 4;
  elem_list[11] = 5;
  elem_list[12] = 5; /* side set 4: Tetra */
  elem_list[13] = 5;
  elem_list[14] = 5;
  elem_list[15] = 6;
  elem_list[16] = 7; /* side set 5: Circle & Sphere */
  elem_list[17] = 8;
  elem_list[18] = 8; /* side set 6: Wedge  */
  elem_list[19] = 8;
  elem_list[20] = 8;
  elem_list[21] = 8;

  error = ex_cvt_nodes_to_sides(exoid, num_elem_per_set, num_nodes_per_set, elem_ind, node_ind,
                                elem_list, node_list, side_list);
  printf("after ex_cvt_nodes_to_sides, error = %d\n", error);

  num_df_per_set[0] = 4;
  num_df_per_set[1] = 4;
  num_df_per_set[2] = 0;
  num_df_per_set[3] = 0;
  num_df_per_set[4] = 0;
  num_df_per_set[5] = 0;

  df_ind[0] = 0;
  df_ind[1] = 4;

  /* side set #1 df */
  dist_fact[0] = 30.0;
  dist_fact[1] = 30.1;
  dist_fact[2] = 30.2;
  dist_fact[3] = 30.3;

  /* side set #2 df */
  dist_fact[4] = 31.0;
  dist_fact[5] = 31.1;
  dist_fact[6] = 31.2;
  dist_fact[7] = 31.3;

  {
    struct ex_set_specs set_specs;

    set_specs.sets_ids            = ids;
    set_specs.num_entries_per_set = num_elem_per_set;
    set_specs.num_dist_per_set    = num_df_per_set;
    set_specs.sets_entry_index    = elem_ind;
    set_specs.sets_dist_index     = df_ind;
    set_specs.sets_entry_list     = elem_list;
    set_specs.sets_extra_list     = side_list;
    set_specs.sets_dist_fact      = dist_fact;
    error                         = ex_put_concat_sets(exoid, EX_SIDE_SET, &set_specs);
  }
  printf("after ex_put_concat_side_sets, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
  printf("after ex_put_prop, error = %d\n", error);

  /* write QA records */

  num_qa_rec = 2;

  qa_record[0][0] = "TESTWT1";
  qa_record[0][1] = "testwt1";
  qa_record[0][2] = "03/16/94";
  qa_record[0][3] = "15:41:33";
  qa_record[1][0] = "FASTQ";
  qa_record[1][1] = "fastq";
  qa_record[1][2] = "07/07/93";
  qa_record[1][3] = "16:41:33";

  error = ex_put_qa(exoid, num_qa_rec, qa_record);
  printf("after ex_put_qa, error = %d\n", error);

  /* write information records */

  num_info = 3;

  info[0] = "This is the first information record.";
  info[1] = "This is the second information record.";
  info[2] = "This is the third information record.";

  error = ex_put_info(exoid, num_info, info);
  printf("after ex_put_info, error = %d\n", error);

  /* write results variables parameters and names */

  num_glo_vars = 1;

  var_names[0] = "glo vars";

  error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_name(exoid, EX_GLOBAL, 1, var_names[0]);
  printf("after ex_put_variable_name, error = %d\n", error);

  num_nod_vars = 2;

  var_names[0] = "nod_var0";
  var_names[1] = "nod_var1";

  error = ex_put_variable_param(exoid, EX_NODAL, num_nod_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_ele_vars = 3;

  var_names[0] = "ele_var0";
  var_names[1] = "ele_var1";
  var_names[2] = "ele_var2";

  error = ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  /* for each time step, write the analysis results;
   * the code below fills the arrays glob_var_vals,
   * nodal_var_vals, and elem_var_vals with values for debugging purposes;
   * obviously the analysis code will populate these arrays
   */

  whole_time_step = 1;
  num_time_steps  = 10;

  glob_var_vals  = (float *)calloc(num_glo_vars, CPU_word_size);
  nodal_var_vals = (float *)calloc(num_nodes, CPU_word_size);
  elem_var_vals  = (float *)calloc(4, CPU_word_size);

  for (i = 0; i < num_time_steps; i++) {
    time_value = (float)(i + 1) / 100.;

    /* write time value */

    error = ex_put_time(exoid, whole_time_step, &time_value);
    printf("after ex_put_time, error = %d\n", error);

    /* write global variables */

    for (j = 0; j < num_glo_vars; j++) {
      glob_var_vals[j] = (float)(j + 2) * time_value;
    }

    error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
    printf("after ex_put_glob_vars, error = %d\n", error);

    /* write nodal variables */

    for (k = 1; k <= num_nod_vars; k++) {
      for (j = 0; j < num_nodes; j++) {
        nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value);
      }

      error = ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals);
      printf("after ex_put_nodal_var, error = %d\n", error);
    }

    /* write element variables */

    for (k = 1; k <= num_ele_vars; k++) {
      for (j = 0; j < num_elem_blk; j++) {
        for (m = 0; m < num_elem_in_block[j]; m++) {
          elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value);
          /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
        }
        if (k == 1 && j == 2)
          continue; /* skip element block 3, variable 1 */
        else {
          error = ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j],
                             num_elem_in_block[j], elem_var_vals);
          printf("after ex_put_elem_var, error = %d\n", error);
        }
      }
    }

    whole_time_step++;

    /* update the data file; this should be done at the end of every time step
     * to ensure that no data is lost if the analysis dies
     */
    error = ex_update(exoid);
    printf("after ex_update, error = %d\n", error);
  }
  free(glob_var_vals);
  free(nodal_var_vals);
  free(elem_var_vals);

  /* close the EXODUS files
   */
  error = ex_close(exoid);
  printf("after ex_close, error = %d\n", error);
  return 0;
}
示例#7
0
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10], num_total_nodes_per_blk[10];
   int num_face_in_block[10], num_total_faces_per_blk[10];
   int num_face_in_sset[10], num_nodes_in_nset[10];
   int num_node_sets, num_side_sets, error;
   int i, j, k, m, *elem_map, *connect;
   int node_list[100],elem_list[100],side_list[100];
   int bids[10], ssids[10], nsids[10], nnpe[10];
   int  num_qa_rec, num_info;
   int num_glo_vars, num_nod_vars, num_ele_vars, num_sset_vars, num_nset_vars;
   int *truth_tab;
   int whole_time_step, num_time_steps;
   int CPU_word_size,IO_word_size;
   int prop_array[2];

   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
   float *sset_var_vals, *nset_var_vals;
   float time_value;
   float x[100], y[100], z[100];
   float dist_fact[100];
   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
   char *block_names[10], *nset_names[10], *sset_names[10];
   char *prop_names[2], *attrib_names[2];
   char *title = "This is a test";
   ex_opts (EX_VERBOSE | EX_ABORT );

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("test-nfaced.exo",       /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   /* ncopts = NC_VERBOSE; */

   /* initialize file with parameters */
   {
     ex_init_params par;
     
     num_dim = 3;
     num_nodes = 14;
     num_elem = 1;
     num_elem_blk = 1;
     num_node_sets = 0;

     strcpy( par.title, title );
     par.num_dim = num_dim;
     par.num_nodes = num_nodes;
     par.num_edge = 0;
     par.num_edge_blk = 0;
     par.num_face = 5;
     par.num_face_blk = 1;
     par.num_elem = num_elem;
     par.num_elem_blk = num_elem_blk;
     par.num_node_sets = num_node_sets;
     par.num_edge_sets = 0;
     par.num_face_sets = 0;
     par.num_side_sets = 0;
     par.num_elem_sets = 0;
     par.num_node_maps = 0;
     par.num_edge_maps = 0;
     par.num_face_maps = 0;
     par.num_elem_maps = 0;
     
     error = ex_put_init_ext (exoid, &par);
     
     printf ("after ex_put_init_ext, error = %d\n", error);
     
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }

/* write nodal coordinates values and names to database */
   x[ 0] =  0.00000e+00 ;    y[ 0] = 0.00000e+00 ;   z[ 0] =  0.00000e+00 ;
   x[ 1] =  2.00000e+00 ;    y[ 1] = 0.00000e+00 ;   z[ 1] =  0.00000e+00 ;
   x[ 2] =  0.00000e+00 ;    y[ 2] = 2.00000e+00 ;   z[ 2] =  0.00000e+00 ;
   x[ 3] =  2.00000e+00 ;    y[ 3] = 2.00000e+00 ;   z[ 3] =  0.00000e+00 ;
   x[ 4] =  0.00000e+00 ;    y[ 4] = 0.00000e+00 ;   z[ 4] =  2.00000e+00 ;
   x[ 5] =  2.00000e+00 ;    y[ 5] = 0.00000e+00 ;   z[ 5] =  2.00000e+00 ;
   x[ 6] =  0.00000e+00 ;    y[ 6] = 2.00000e+00 ;   z[ 6] =  2.00000e+00 ;
   x[ 7] =  2.00000e+00 ;    y[ 7] = 2.00000e+00 ;   z[ 7] =  2.00000e+00 ;
   x[ 8] =  0.00000e+00 ;    y[ 8] = 3.50000e+00 ;   z[ 8] =  1.00000e+00 ;
   x[ 9] =  2.00000e+00 ;    y[ 9] = 3.50000e+00 ;   z[ 9] =  1.00000e+00 ;
   x[10] =  0.00000e+00 ;    y[10] = 3.00000e+00 ;   z[10] =  1.50000e+00 ;
   x[11] =  2.00000e+00 ;    y[11] = 3.00000e+00 ;   z[11] =  1.50000e+00 ;
   x[12] =  0.00000e+00 ;    y[12] = 3.00000e+00 ;   z[12] =  0.50000e+00 ;
   x[13] =  2.00000e+00 ;    y[13] = 3.00000e+00 ;   z[13] =  0.50000e+00 ;

   error = ex_put_coord (exoid, x, y, z);
   printf ("after ex_put_coord, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   coord_names[0] = "x";
   coord_names[1] = "y";
   coord_names[2] = "z";

   error = ex_put_coord_names (exoid, coord_names);
   printf ("after ex_put_coord_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* Write the face block parameters */
   block_names[0] = "face_block_1";
   num_face_in_block[0] = 15;
   num_total_nodes_per_blk[0] = 54;
   bids[0] = 10;

   error = ex_put_block (exoid, EX_FACE_BLOCK, bids[0], "nsided",
			 num_face_in_block[0],
			 num_total_nodes_per_blk[0],
			 0, 0, 0);
   printf ("after ex_put_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   
    
   /* write face connectivity */

   connect = (int *) calloc(num_total_nodes_per_blk[0], sizeof(int));

   i = 0;
   j = 0;

   connect[i++] = 5;
   connect[i++] = 6;
   connect[i++] = 8; /* connectivity of face 1 of element 1 */


   connect[i++] = 2;
   connect[i++] = 1;
   connect[i++] = 4; /* face 2 of element 1 */


   connect[i++] = 6;
   connect[i++] = 2;
   connect[i++] = 4;
   connect[i++] = 8; /* face 3 of element 1 */


   connect[i++] = 8;
   connect[i++] = 4;
   connect[i++] = 1;
   connect[i++] = 5; /* face 4 of element 1 */

   connect[i++] = 1;
   connect[i++] = 2;
   connect[i++] = 6;
   connect[i++] = 5; /*  face 5 of element 1 */

   connect[i++] = 5;
   connect[i++] = 8;
   connect[i++] = 7; /* connectivity of face 1 of element 2 */

   connect[i++] = 1; connect[i++] = 2; connect[i++] = 3; connect[i++] = 4;
   nnpe[j++] = 4;

   connect[i++] = 5; connect[i++] = 3; connect[i++] = 4; connect[i++] = 6;
   nnpe[j++] = 4;

   connect[i++] = 5; connect[i++] = 1; connect[i++] = 2; connect[i++] = 6;
   nnpe[j++] = 4;

   connect[i++] = 6; connect[i++] = 2; connect[i++] = 4;
   nnpe[j++] = 3;

   connect[i++] = 5; connect[i++] = 3; connect[i++] = 1;
   nnpe[j++] = 3;

   assert(i == num_total_nodes_per_blk[0]);
   assert(j == num_face_in_block[0]);

   error = ex_put_conn (exoid, EX_FACE_BLOCK, bids[0], connect, NULL, NULL);
   printf ("after ex_put_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (connect);
   connect = NULL;

   error = ex_put_entity_count_per_polyhedra(exoid, EX_FACE_BLOCK, bids[0], nnpe);
   printf ("after ex_put_entity_count_per_polyhedra, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* write element block parameters */
   block_names[0] = "nfaced_1";

   num_elem_in_block[0] = 1;
   num_total_nodes_per_blk[0] = 6;   /* Do we need this; does it make sense... */
   num_total_faces_per_blk[0] = 5;

   bids[0] = 10;

   error = ex_put_block (exoid, EX_ELEM_BLOCK, bids[0], "nfaced",
			 num_elem_in_block[0],
			 0, 
			 0,
			 num_total_faces_per_blk[0],
			 0);
   printf ("after ex_put_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* Write face block names */
   error = ex_put_names(exoid, EX_FACE_BLOCK, block_names);
   printf ("after ex_put_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   /* Write element block names */
   error = ex_put_names(exoid, EX_ELEM_BLOCK, block_names);
   printf ("after ex_put_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   /* write element-face connectivity */
   connect = (int *) calloc(num_total_faces_per_blk[0], sizeof(int));

   i = 0;
   j = 0;
   connect[i++] = 1; connect[i++] = 2; connect[i++] = 3; connect[i++] = 4;
   connect[i++] = 5;
   nnpe[j++] = 5;  /* Number of faces per element */
   
   assert(i == num_total_faces_per_blk[0]);
   assert(j == num_elem_in_block[0]);

   error = ex_put_conn (exoid, EX_ELEM_BLOCK, bids[0], NULL, NULL, connect);
   printf ("after ex_put_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (connect);

   error = ex_put_entity_count_per_polyhedra(exoid, EX_ELEM_BLOCK, bids[0], nnpe);
   printf ("after ex_put_entity_count_per_polyhedra, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* write QA records; test empty and just blank-filled records */
   num_qa_rec = 2;


   qa_record[0][0] = "TESTWT-NFACED";
   qa_record[0][1] = "testwt-nfaced";
   qa_record[0][2] = "2010/02/15";
   qa_record[0][3] = "06:35:15";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   error = ex_put_qa (exoid, num_qa_rec, qa_record);
   printf ("after ex_put_qa, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* write information records; test empty and just blank-filled records */
   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   error = ex_put_info (exoid, num_info, info);
   printf ("after ex_put_info, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }



   /* write results variables parameters and names */
   num_glo_vars = 1;

   var_names[0] = "glo_vars";

   error = ex_put_var_param (exoid, "g", num_glo_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_var_names (exoid, "g", num_glo_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }



   num_nod_vars = 2;
   /*              12345678901234567890123456789012 */
   var_names[0] = "node_variable_a_very_long_name_0";
   var_names[1] = "n";

   error = ex_put_var_param (exoid, "n", num_nod_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_var_names (exoid, "n", num_nod_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   num_ele_vars = 3;

   var_names[0] = "ele_var0";
   var_names[1] = "ele_var1";
   var_names[2] = "ele_var2";

   error = ex_put_var_param (exoid, "e", num_ele_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_var_names (exoid, "e", num_ele_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* write element variable truth table */
   truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));

   k = 0;
   for (i=0; i<num_elem_blk; i++)
   {
      for (j=0; j<num_ele_vars; j++)
      {
         truth_tab[k++] = 1;
      }
   }

   error = ex_put_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab);
   printf ("after ex_put_elem_var_tab, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (truth_tab);


/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 * obviously the analysis code will populate these arrays
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
   elem_var_vals = (float *) calloc (8, CPU_word_size);
   
   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

     /* write time value */
     error = ex_put_time (exoid, whole_time_step, &time_value);
     printf ("after ex_put_time, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

     /* write global variables */
     for (j=0; j<num_glo_vars; j++)
     {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
                               glob_var_vals);
     printf ("after ex_put_glob_vars, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

     /* write nodal variables */
     for (k=1; k<=num_nod_vars; k++)
     {
       for (j=0; j<num_nodes; j++)
       {
         nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
       }

       error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes,
                                 nodal_var_vals);
       printf ("after ex_put_nodal_var, error = %d\n", error);
       if (error) {
         ex_close (exoid);
         exit(-1);
       }

     }

     /* write element variables */
     for (k=1; k<=num_ele_vars; k++)
     {
       for (j=0; j<num_elem_blk; j++)
       {
         for (m=0; m<num_elem_in_block[j]; m++)
         {
           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
                              ((float)(m+1)*time_value);
           /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
         }
         error = ex_put_elem_var (exoid, whole_time_step, k, bids[j],
                                  num_elem_in_block[j], elem_var_vals);
         printf ("after ex_put_elem_var, error = %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

     whole_time_step++;
     
     /* update the data file; this should be done at the end of every time step
      * to ensure that no data is lost if the analysis dies
      */
     error = ex_update (exoid);
     printf ("after ex_update, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
   free(glob_var_vals);
   free(nodal_var_vals);
   free(elem_var_vals);
   
   /* close the EXODUS files
    */
   error = ex_close (exoid);
   printf ("after ex_close, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   return 0;
}
示例#8
0
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_node_sets, num_side_sets, error;
   int i, j;
   int  num_qa_rec, num_info;
   int num_glo_vars;
   int whole_time_step, num_time_steps;
   int CPU_word_size,IO_word_size;

   float *glob_var_vals;
   float time_value;
   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];

   ex_opts (EX_VERBOSE | EX_ABORT );

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("test.exo",       /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   /* ncopts = NC_VERBOSE; */

/* initialize file with parameters */

   num_dim = 1;
   num_nodes = 0;
   num_elem = 0;
   num_elem_blk = 0;
   num_node_sets = 0;
   num_side_sets = 0;

   error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem,
                        num_elem_blk, num_node_sets, num_side_sets);

   printf ("after ex_put_init, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   coord_names[0] = "xcoor";

   error = ex_put_coord_names (exoid, coord_names);
   printf ("after ex_put_coord_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* write QA records; test empty and just blank-filled records */

   num_qa_rec = 2;


   qa_record[0][0] = "TESTWT";
   qa_record[0][1] = "testwt";
   qa_record[0][2] = "07/07/93";
   qa_record[0][3] = "15:41:33";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   error = ex_put_qa (exoid, num_qa_rec, qa_record);
   printf ("after ex_put_qa, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


/* write information records; test empty and just blank-filled records */

   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   error = ex_put_info (exoid, num_info, info);
   printf ("after ex_put_info, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }



/* write results variables parameters and names */

   num_glo_vars = 1;

   var_names[0] = "glo_vars";

   error = ex_put_var_param (exoid, "g", num_glo_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_var_names (exoid, "g", num_glo_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }



/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 * obviously the analysis code will populate these arrays
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);

   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

/* write time value */

     error = ex_put_time (exoid, whole_time_step, &time_value);
     printf ("after ex_put_time, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

/* write global variables */

     for (j=0; j<num_glo_vars; j++)
     {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
                               glob_var_vals);
     printf ("after ex_put_glob_vars, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

     whole_time_step++;

/* update the data file; this should be done at the end of every time step
 * to ensure that no data is lost if the analysis dies
 */
     error = ex_update (exoid);
     printf ("after ex_update, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
   free(glob_var_vals);


/* close the EXODUS files
 */
   error = ex_close (exoid);
   printf ("after ex_close, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   return 0;
}
int write_vis(std::string &nemI_out_file,
	      std::string &exoII_inp_file,
	      Machine_Description* machine,
	      Problem_Description* prob,
	      Mesh_Description<INT>* mesh,
	      LB_Description<INT>* lb)
{
  int    exid_vis, exid_inp;

  char  title[MAX_LINE_LENGTH+1];
  const char   *coord_names[] = {"X", "Y", "Z"};

  /*-----------------------------Execution Begins------------------------------*/

  /* Generate the file name for the visualization file */
  std::string vis_file_name = remove_extension(nemI_out_file);
  vis_file_name += "-vis.exoII";

  /* Generate the title for the file */
  strcpy(title, UTIL_NAME);
  strcat(title, " ");
  strcat(title, ELB_VERSION);
  strcat(title, " load balance visualization file");

  /*
   * If the vis technique is to be by element block then calculate the
   * number of element blocks.
   */
  int    vis_nelem_blks;
  if(prob->type == ELEMENTAL)
    vis_nelem_blks = machine->num_procs;
  else
    vis_nelem_blks = machine->num_procs + 1;

  /* Create the ExodusII file */
  std::cout << "Outputting load balance visualization file " << vis_file_name.c_str() << "\n";
  int cpu_ws = 0;
  int io_ws = 0;
  int mode = EX_CLOBBER;
  if (prob->int64db|prob->int64api) {
    mode |= EX_NETCDF4|EX_NOCLASSIC|prob->int64db|prob->int64api;
  }
  if((exid_vis=ex_create(vis_file_name.c_str(), mode, &cpu_ws, &io_ws)) < 0) {
    Gen_Error(0, "fatal: unable to create visualization output file");
    return 0;
  }
  ON_BLOCK_EXIT(ex_close, exid_vis);

  /*
   * Open the original input ExodusII file, read the values for the
   * element blocks and output them to the visualization file.
   */
  int icpu_ws=0;
  int iio_ws=0;
  float vers=0.0;
  mode = EX_READ | prob->int64api;
  if((exid_inp=ex_open(exoII_inp_file.c_str(), mode, &icpu_ws, &iio_ws, &vers)) < 0) {
    Gen_Error(0, "fatal: unable to open input ExodusII file");
    return 0;
  }
  ON_BLOCK_EXIT(ex_close, exid_inp);
  
  char **elem_type  = (char**)array_alloc(2, mesh->num_el_blks, MAX_STR_LENGTH+1,
					  sizeof(char));
  if(!elem_type) {
    Gen_Error(0, "fatal: insufficient memory");
    return 0;
  }
  ON_BLOCK_EXIT(free, elem_type);

  std::vector<INT> el_blk_ids(mesh->num_el_blks);
  std::vector<INT> el_cnt_blk(mesh->num_el_blks);
  std::vector<INT> node_pel_blk(mesh->num_el_blks);
  std::vector<INT> nattr_el_blk(mesh->num_el_blks);

  if(ex_get_elem_blk_ids(exid_inp, TOPTR(el_blk_ids)) < 0) {
    Gen_Error(0, "fatal: unable to get element block IDs");
    return 0;
  }

  int acc_vis = ELB_TRUE; // Output a different element block per processor
  if (prob->vis_out == 2)
    acc_vis = ELB_FALSE; // Output a nodal/element variable showing processor

  size_t nsize = 0;

  /*
   * Find out if the mesh consists of mixed elements. If not then
   * element blocks will be used to visualize the partitioning. Otherwise
   * nodal/element results will be used.
   */
  for(size_t ecnt=0; ecnt < mesh->num_el_blks; ecnt++) {
    if(ex_get_elem_block(exid_inp, el_blk_ids[ecnt], elem_type[ecnt],
			 &el_cnt_blk[ecnt], &node_pel_blk[ecnt],
			 &nattr_el_blk[ecnt]) < 0) {
      Gen_Error(0, "fatal: unable to get element block parameters");
      return 0;
    }

    nsize += el_cnt_blk[ecnt]*node_pel_blk[ecnt];

    if(strcmp(elem_type[0], elem_type[ecnt]) == 0) {
      if(node_pel_blk[0] != node_pel_blk[ecnt])
	acc_vis = ELB_FALSE;
    }
    else
      acc_vis = ELB_FALSE;
  }

  if(acc_vis == ELB_TRUE) {
    /* Output the initial information */
    if(ex_put_init(exid_vis, title, mesh->num_dims, mesh->num_nodes,
		   mesh->num_elems, vis_nelem_blks, 0, 0) < 0) {
      Gen_Error(0, "fatal: unable to output initial params to vis file");
      return 0;
    }
	
    /* Output the nodal coordinates */
    float *xptr = nullptr;
    float *yptr = nullptr;
    float *zptr = nullptr;
    switch(mesh->num_dims) {
    case 3:
      zptr = (mesh->coords) + 2*mesh->num_nodes;
      /* FALLTHRU */
    case 2:
      yptr = (mesh->coords) + mesh->num_nodes;
      /* FALLTHRU */
    case 1:
      xptr = mesh->coords;
    }
    if(ex_put_coord(exid_vis, xptr, yptr, zptr) < 0) {
      Gen_Error(0, "fatal: unable to output coords to vis file");
      return 0;
    }
	
    if(ex_put_coord_names(exid_vis, (char**)coord_names) < 0) {
      Gen_Error(0, "fatal: unable to output coordinate names");
      return 0;
    }

    std::vector<INT> elem_block(mesh->num_elems);
    std::vector<INT> elem_map(mesh->num_elems);
    std::vector<INT> tmp_connect(nsize);
    for(size_t ecnt=0; ecnt < mesh->num_elems; ecnt++) {
      elem_map[ecnt] = ecnt+1;
      if(prob->type == ELEMENTAL)
	elem_block[ecnt] = lb->vertex2proc[ecnt];
      else {
	int proc   = lb->vertex2proc[mesh->connect[ecnt][0]];
	int nnodes = get_elem_info(NNODES, mesh->elem_type[ecnt]);
	elem_block[ecnt] = proc;
	for(int ncnt=1; ncnt < nnodes; ncnt++) {
	  if(lb->vertex2proc[mesh->connect[ecnt][ncnt]] != proc) {
	    elem_block[ecnt] = machine->num_procs;
	    break;
	  }
	}
      }
    }

    int ccnt = 0;
    std::vector<INT> vis_el_blk_ptr(vis_nelem_blks+1);
    for(INT bcnt=0; bcnt < vis_nelem_blks; bcnt++) {
      vis_el_blk_ptr[bcnt] = ccnt;
      int pos = 0;
      int old_pos = 0;
      INT* el_ptr = TOPTR(elem_block);
      size_t ecnt   = mesh->num_elems;
      while(pos != -1) {
	pos = in_list(bcnt, ecnt, el_ptr);
	if(pos != -1) {
	  old_pos += pos + 1;
	  ecnt     = mesh->num_elems - old_pos;
	  el_ptr   = TOPTR(elem_block) + old_pos;
	  int nnodes = get_elem_info(NNODES, mesh->elem_type[old_pos-1]);
	  for(int ncnt=0; ncnt < nnodes; ncnt++)
	    tmp_connect[ccnt++] = mesh->connect[old_pos-1][ncnt] + 1;
	}
      }
    }
    vis_el_blk_ptr[vis_nelem_blks] = ccnt;
	
    /* Output the element map */
    if(ex_put_map(exid_vis, TOPTR(elem_map)) < 0) {
      Gen_Error(0, "fatal: unable to output element number map");
      return 0;
    }
	
    /* Output the visualization element blocks */
    for(int bcnt=0; bcnt < vis_nelem_blks; bcnt++) {
      /*
       * Note this assumes all the blocks contain the same type
       * element.
       */
      int ecnt = (vis_el_blk_ptr[bcnt+1]-vis_el_blk_ptr[bcnt])/node_pel_blk[0];
      if(ex_put_elem_block(exid_vis, bcnt+1, elem_type[0],
			   ecnt, node_pel_blk[0], 0) < 0) {
	Gen_Error(0, "fatal: unable to output element block params");
	return 0;
      }
	  
      /* Output the connectivity */
      if(ex_put_elem_conn(exid_vis, bcnt+1,
			  &tmp_connect[vis_el_blk_ptr[bcnt]]) < 0) {
	Gen_Error(0, "fatal: unable to output element connectivity");
	return 0;
      }
    }
  }

  else {	/* For nodal/element results visualization of the partioning. */
    // Copy the mesh portion to the vis file.
    ex_copy(exid_inp, exid_vis);

    /* Set up the file for nodal/element results */
    float time_val = 0.0;
    if(ex_put_time(exid_vis, 1, &time_val) < 0) {
      Gen_Error(0, "fatal: unable to output time to vis file");
      return 0;
    }

    const char  *var_names[] = {"proc"};
    if(prob->type == NODAL) {
      /* Allocate memory for the nodal values */
      std::vector<float> proc_vals(mesh->num_nodes);

      if(ex_put_variable_param(exid_vis, EX_NODAL, 1) < 0) {
	Gen_Error(0, "fatal: unable to output var params to vis file");
	return 0;
      }

      if(ex_put_variable_names(exid_vis, EX_NODAL, 1, (char**)var_names) < 0) {
	Gen_Error(0, "fatal: unable to output variable name");
	return 0;
      }

      /* Do some problem specific assignment */
      for(size_t ncnt=0; ncnt < mesh->num_nodes; ncnt++)
	proc_vals[ncnt] = lb->vertex2proc[ncnt];

      for(int pcnt=0; pcnt < machine->num_procs; pcnt++) {
	for(auto & elem : lb->bor_nodes[pcnt])
	  proc_vals[elem] = machine->num_procs + 1;
      }

      /* Output the nodal variables */
      if(ex_put_nodal_var(exid_vis, 1, 1, mesh->num_nodes, TOPTR(proc_vals)) < 0) {
	Gen_Error(0, "fatal: unable to output nodal variables");
	return 0;
      }
    }
    else if(prob->type == ELEMENTAL) {
      /* Allocate memory for the element values */
      std::vector<float> proc_vals(mesh->num_elems);

      if(ex_put_variable_param(exid_vis, EX_ELEM_BLOCK, 1) < 0) {
	Gen_Error(0, "fatal: unable to output var params to vis file");
	return 0;
      }

      if(ex_put_variable_names(exid_vis, EX_ELEM_BLOCK, 1, (char**)var_names) < 0) {
	Gen_Error(0, "fatal: unable to output variable name");
	return 0;
      }

      /* Do some problem specific assignment */
      for(int proc=0; proc < machine->num_procs; proc++) {
	for (size_t e = 0; e < lb->int_elems[proc].size(); e++) {
	  size_t ecnt = lb->int_elems[proc][e];
	  proc_vals[ecnt] = proc;
	}

	for (size_t e = 0; e < lb->bor_elems[proc].size(); e++) {
	  size_t ecnt = lb->bor_elems[proc][e];
	  proc_vals[ecnt] = proc;
	}
      }

      /* Output the element variables */
      size_t offset = 0;
      for (size_t i=0; i < mesh->num_el_blks; i++) {
	if(ex_put_var(exid_vis, 1, EX_ELEM_BLOCK, 1, el_blk_ids[i],
		      el_cnt_blk[i], &proc_vals[offset]) < 0) {
	  Gen_Error(0, "fatal: unable to output nodal variables");
	  return 0;
	}
	offset += el_cnt_blk[i];
      }
    }
  }
  return 1;
} /*---------------------------End write_vis()-------------------------------*/
示例#10
0
文件: testwt-zeron.c 项目: hpcdev/xdm
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10], num_nodes_per_elem[10];
   int num_node_sets, num_side_sets, error;
   int i, j, *elem_map;
   int ebids[10];
   int  num_qa_rec, num_info;
   int num_glo_vars;
   int whole_time_step, num_time_steps;
   int CPU_word_size,IO_word_size;

   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
   float time_value;
   float x[100], y[100], z[100];
   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];

   ex_opts (EX_VERBOSE | EX_ABORT );

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("test.exo",       /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   /* ncopts = NC_VERBOSE; */

/* initialize file with parameters */

   num_dim = 3;
   num_nodes = 0;
   num_elem = 0;
   num_elem_blk = 7;
   num_node_sets = 0;
   num_side_sets = 0;

   error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem,
                        num_elem_blk, num_node_sets, num_side_sets);

   printf ("after ex_put_init, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* write nodal varcoordinates values and names to database */

/* Quad #1 */
   x[0] = 0.0; y[0] = 0.0; z[0] = 0.0;
   x[1] = 1.0; y[1] = 0.0; z[1] = 0.0;
   x[2] = 1.0; y[2] = 1.0; z[2] = 0.0;
   x[3] = 0.0; y[3] = 1.0; z[3] = 0.0;

/* Quad #2 */
   x[4]  =  1.0; y[4]  =  0.0; z[4]  =  0.0;
   x[5]  =  2.0; y[5]  =  0.0; z[5]  =  0.0;
   x[6]  =  2.0; y[6]  =  1.0; z[6]  =  0.0;
   x[7]  =  1.0; y[7]  =  1.0; z[7]  =  0.0;

/* Hex #1 */
   x[8]  =  0.0; y[8]  =  0.0; z[8]  =  0.0;
   x[9]  = 10.0; y[9]  =  0.0; z[9]  =  0.0;
   x[10] = 10.0; y[10] =  0.0; z[10] =-10.0;
   x[11] =  1.0; y[11] =  0.0; z[11] =-10.0;
   x[12] =  1.0; y[12] = 10.0; z[12] =  0.0;
   x[13] = 10.0; y[13] = 10.0; z[13] =  0.0;
   x[14] = 10.0; y[14] = 10.0; z[14] =-10.0;
   x[15] =  1.0; y[15] = 10.0; z[15] =-10.0;

/* Tetra #1 */
   x[16] =  0.0; y[16] =  0.0; z[16] =  0.0;
   x[17] =  1.0; y[17] =  0.0; z[17] =  5.0;
   x[18] = 10.0; y[18] =  0.0; z[18] =  2.0;
   x[19] =  7.0; y[19] =  5.0; z[19] =  3.0;

/* Wedge #1 */
   x[20] =  3.0; y[20] =  0.0; z[20] =  6.0;
   x[21] =  6.0; y[21] =  0.0; z[21] =  0.0;
   x[22] =  0.0; y[22] =  0.0; z[22] =  0.0;
   x[23] =  3.0; y[23] =  2.0; z[23] =  6.0;
   x[24] =  6.0; y[24] =  2.0; z[24] =  2.0;
   x[25] =  0.0; y[25] =  2.0; z[25] =  0.0;

/* Tetra #2 */
   x[26] =  2.7; y[26] =  1.7; z[26] =  2.7;
   x[27] =  6.0; y[27] =  1.7; z[27] =  3.3;
   x[28] =  5.7; y[28] =  1.7; z[28] =  1.7;
   x[29] =  3.7; y[29] =  0.0; z[29] =  2.3;

/* 3d Tri */
   x[30] =  0.0; y[30] =  0.0; z[30] =  0.0;
   x[31] = 10.0; y[31] =  0.0; z[31] =  0.0;
   x[32] = 10.0; y[32] = 10.0; z[32] = 10.0;

   /*   error = ex_put_coord (exoid, x, y, z); */
   printf ("after ex_put_coord, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   coord_names[0] = "xcoor";
   coord_names[1] = "ycoor";
   coord_names[2] = "zcoor";

   error = ex_put_coord_names (exoid, coord_names);
   printf ("after ex_put_coord_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* write element order map */

   elem_map = (int *) calloc(num_elem, sizeof(int));

   for (i=1; i<=num_elem; i++)
   {
      elem_map[i-1] = i;
   }

   error = ex_put_map (exoid, elem_map);
   printf ("after ex_put_map, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (elem_map);


/* write element block parameters */

   num_elem_in_block[0] = 0;
   num_elem_in_block[1] = 0;
   num_elem_in_block[2] = 0;
   num_elem_in_block[3] = 0;
   num_elem_in_block[4] = 0;
   num_elem_in_block[5] = 0;
   num_elem_in_block[6] = 0;

   num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
   num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
   num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
   num_nodes_per_elem[3] = 4; /* elements in block #4 are 4-node tetras */
   num_nodes_per_elem[4] = 6; /* elements in block #5 are 6-node wedges */
   num_nodes_per_elem[5] = 8; /* elements in block #6 are 8-node tetras */
   num_nodes_per_elem[6] = 3; /* elements in block #7 are 3-node tris   */

   ebids[0] = 10;
   ebids[1] = 11;
   ebids[2] = 12;
   ebids[3] = 13;
   ebids[4] = 14;
   ebids[5] = 15;
   ebids[6] = 16;

   error = ex_put_elem_block (exoid, ebids[0], "quad", num_elem_in_block[0],
                              num_nodes_per_elem[0], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[1], "quad", num_elem_in_block[1],
                               num_nodes_per_elem[1], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[2], "hex", num_elem_in_block[2],
                               num_nodes_per_elem[2], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[3], "tetra", num_elem_in_block[3],
                               num_nodes_per_elem[3], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[4], "wedge", num_elem_in_block[4],
                               num_nodes_per_elem[4], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[5], "tetra", num_elem_in_block[5],
                               num_nodes_per_elem[5], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[6], "tri", num_elem_in_block[6],
                               num_nodes_per_elem[6], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* write QA records; test empty and just blank-filled records */

   num_qa_rec = 2;


   qa_record[0][0] = "TESTWT";
   qa_record[0][1] = "testwt";
   qa_record[0][2] = "07/07/93";
   qa_record[0][3] = "15:41:33";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   error = ex_put_qa (exoid, num_qa_rec, qa_record);
   printf ("after ex_put_qa, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


/* write information records; test empty and just blank-filled records */

   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   error = ex_put_info (exoid, num_info, info);
   printf ("after ex_put_info, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }



/* write results variables parameters and names */

   num_glo_vars = 1;

   var_names[0] = "glo_vars";

   error = ex_put_var_param (exoid, "g", num_glo_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_var_names (exoid, "g", num_glo_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }



/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 * obviously the analysis code will populate these arrays
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
   elem_var_vals = (float *) calloc (4, CPU_word_size);

   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

/* write time value */

     error = ex_put_time (exoid, whole_time_step, &time_value);
     printf ("after ex_put_time, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

/* write global variables */

     for (j=0; j<num_glo_vars; j++)
     {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
                               glob_var_vals);
     printf ("after ex_put_glob_vars, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

     whole_time_step++;

/* update the data file; this should be done at the end of every time step
 * to ensure that no data is lost if the analysis dies
 */
     error = ex_update (exoid);
     printf ("after ex_update, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
   free(glob_var_vals);
   free(nodal_var_vals);
   free(elem_var_vals);


/* close the EXODUS files
 */
   error = ex_close (exoid);
   printf ("after ex_close, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   return 0;
}
示例#11
0
int cCreateEdgeFace( int argc, char* argv[] )
{
  int exoid;
  int appWordSize = 8;
  int diskWordSize = 8;
  /*  int concatBlocks = ex_have_arg( argc, argv, "-pcab" ); */
  int concatSets   = ex_have_arg( argc, argv, "-pcset" );
  int concatResult = ex_have_arg( argc, argv, "-pvpax" );
  double t;

  ex_init_params modelParams = {
    "CreateEdgeFace Test", /* title */
    3,  /* num_dim */
    12, /* num_nodes */
    20, /* num_edge */
    1,  /* num_edge_blk */
    11, /* num_face */
    3,  /* num_face_blk */
    3,  /* num_elem */
    2,  /* num_elem_blk */
    1,  /* num_node_sets */
    1,  /* num_edge_sets */
    1,  /* num_face_sets */
    1,  /* num_side_sets */
    2,  /* num_elem_sets */
    1,  /* num_node_map */
    1,  /* num_edge_map */
    1,  /* num_face_map */
    1,  /* num_elem_map */
  };

  ex_block edgeBlocks[1];
  ex_block faceBlocks[3];
  ex_block elemBlocks[2];

  ex_var_params varParams;

  ex_opts (EX_VERBOSE | EX_ABORT );

  edgeBlocks[0].type = EX_EDGE_BLOCK;
  edgeBlocks[0].id = 100;
  edgeBlocks[0].num_entry = 20;
  edgeBlocks[0].num_nodes_per_entry = 2;
  edgeBlocks[0].num_attribute = 1;
  strcpy(edgeBlocks[0].topology, "EDGE2");
  
  faceBlocks[0].type = EX_FACE_BLOCK;
  faceBlocks[0].id = 500;
  faceBlocks[0].num_entry = 2;
  faceBlocks[0].num_nodes_per_entry = 4;
  faceBlocks[0].num_attribute = 1;
  strcpy(faceBlocks[0].topology, "QUAD4");
  
  faceBlocks[1].type = EX_FACE_BLOCK;
  faceBlocks[1].id = 600;
  faceBlocks[1].num_entry = 1;
  faceBlocks[1].num_nodes_per_entry = 4;
  faceBlocks[1].num_attribute = 1;
  strcpy(faceBlocks[1].topology, "QUAD4");
  
  faceBlocks[2].type = EX_FACE_BLOCK;
  faceBlocks[2].id = 700;
  faceBlocks[2].num_entry = 8;
  faceBlocks[2].num_nodes_per_entry = 4;
  faceBlocks[2].num_attribute = 1;
  strcpy(faceBlocks[2].topology, "QUAD4");
  
  elemBlocks[0].type = EX_ELEM_BLOCK;
  elemBlocks[0].id = 200;
  elemBlocks[0].num_entry = 2;
  elemBlocks[0].num_nodes_per_entry = 8;
  elemBlocks[0].num_edges_per_entry = 12;
  elemBlocks[0].num_faces_per_entry = 6;
  elemBlocks[0].num_attribute = 2;
  strcpy(elemBlocks[0].topology, "HEX8");
  
  elemBlocks[1].type = EX_ELEM_BLOCK;
  elemBlocks[1].id = 201;
  elemBlocks[1].num_entry = 1;
  elemBlocks[1].num_nodes_per_entry = 4;
  elemBlocks[1].num_edges_per_entry = 0;
  elemBlocks[1].num_faces_per_entry = 0;
  elemBlocks[1].num_attribute = 0;
  strcpy(elemBlocks[1].topology, "TET4");
  
  varParams.edge_var_tab  = (int*)malloc(2 * sizeof(int));
  varParams.face_var_tab  = (int*)malloc(3 * sizeof(int));
  varParams.elem_var_tab  = (int*)malloc(2 * sizeof(int));
  varParams.nset_var_tab  = (int*)0;
  varParams.eset_var_tab  = (int*)0;
  varParams.fset_var_tab  = (int*)malloc(1 * sizeof(int));
  varParams.sset_var_tab  = (int*)0;
  varParams.elset_var_tab = (int*)0;

  varParams.num_glob        = 2;
  varParams.num_node        = 1;
  varParams.num_edge        = 2;
  varParams.edge_var_tab[0] = 1;
  varParams.edge_var_tab[1] = 1;
  varParams.num_face        = 1;
  varParams.face_var_tab[0] = 1;
  varParams.face_var_tab[1] = 1;
  varParams.face_var_tab[2] = 1;
  varParams.num_elem        = 1;
  varParams.elem_var_tab[0] = 1;
  varParams.elem_var_tab[1] = 0;
  varParams.num_nset        = 0;
  varParams.num_eset        = 0;;
  varParams.num_fset        = 1;
  varParams.fset_var_tab[0] = 1;
  varParams.num_sset        = 0;
  varParams.num_elset       = 0;

  exoid = ex_create( EX_TEST_FILENAME, EX_CLOBBER, &appWordSize, &diskWordSize );
  if ( exoid <= 0 )
    {
      fprintf( stderr, "Unable to open \"%s\" for writing.\n", EX_TEST_FILENAME );
      return 1;
    }

  EXCHECK( ex_put_init_ext( exoid, &modelParams ),
	   "Unable to initialize database.\n" );

  {
    int blk;
    for ( blk = 0; blk < modelParams.num_edge_blk; ++blk ) {
      EXCHECK( ex_put_block_param( exoid, edgeBlocks[blk]), "Unable to write edge block" );
    }
    for ( blk = 0; blk < modelParams.num_face_blk; ++blk ) {
      EXCHECK( ex_put_block_param( exoid, faceBlocks[blk]), "Unable to write face block" );
    }
    for ( blk = 0; blk < modelParams.num_elem_blk; ++blk ) {
      EXCHECK( ex_put_block_param( exoid, elemBlocks[blk]), "Unable to write elem block" );
    }
  }

  EXCHECK( ex_put_coord( exoid, (void*)coordsX, (void*)coordsY, (void*)coordsZ ),
	   "Unable to write coordinates.\n" );

  EXCHECK( ex_put_coord_names( exoid, (char**)coordsNames ),
	   "Unable to write coordinate names.\n" );

  /*                  =============== Connectivity  ================== */
  /* *** NEW API *** */
  EXCHECK( ex_put_conn( exoid, EX_EDGE_BLOCK, edgeBlocks[0].id, ebconn1, 0, 0 ),
	   "Unable to write edge block connectivity.\n" );

  /* *** NEW API *** */
  EXCHECK( ex_put_conn( exoid, EX_FACE_BLOCK, faceBlocks[0].id, fbconn1, 0, 0 ),
	   "Unable to write face block 1 connectivity.\n" );
  EXCHECK( ex_put_conn( exoid, EX_FACE_BLOCK, faceBlocks[1].id, fbconn2, 0, 0 ),
	   "Unable to write face block 2 connectivity.\n" );
  EXCHECK( ex_put_conn( exoid, EX_FACE_BLOCK, faceBlocks[2].id, fbconn3, 0, 0 ),
	   "Unable to write face block 3 connectivity.\n" );

  /* *** NEW API *** */
  EXCHECK( ex_put_conn( exoid, EX_ELEM_BLOCK, elemBlocks[0].id, conn1, econn1, fconn1 ),
	   "Unable to write elem block 1 connectivity.\n" );

  /* *** NEW API *** */
  EXCHECK( ex_put_conn( exoid, EX_ELEM_BLOCK, elemBlocks[1].id, conn2, 0, 0 ),
	   "Unable to write elem block 2 connectivity.\n" );

  /* *** NEW API *** */
  EXCHECK( ex_put_names( exoid, EX_EDGE_BLOCK, (char**)edblk_names ), "Unable to write edge block names.\n" );
  EXCHECK( ex_put_names( exoid, EX_FACE_BLOCK, (char**)fablk_names ), "Unable to write face block names.\n" );
  EXCHECK( ex_put_names( exoid, EX_ELEM_BLOCK, (char**) eblk_names ), "Unable to write element block names.\n" );

  /*                  =============== Number Maps   ================== */
  /* *** NEW API *** */
  EXCHECK( ex_put_num_map( exoid, EX_NODE_MAP, 300, nmap1 ),  "Unable to write node map.\n" );
  EXCHECK( ex_put_num_map( exoid, EX_EDGE_MAP, 800, edmap1 ), "Unable to write edge map.\n" );
  EXCHECK( ex_put_num_map( exoid, EX_FACE_MAP, 900, famap1 ), "Unable to write face map.\n" );
  EXCHECK( ex_put_num_map( exoid, EX_ELEM_MAP, 400, emap1 ),  "Unable to write element map.\n" );

  /* *** NEW API *** */
  EXCHECK( ex_put_names( exoid, EX_NODE_MAP, (char**) nmap_names ), "Unable to write node map names.\n" );
  EXCHECK( ex_put_names( exoid, EX_EDGE_MAP, (char**)edmap_names ), "Unable to write edge map names.\n" );
  EXCHECK( ex_put_names( exoid, EX_FACE_MAP, (char**)famap_names ), "Unable to write face map names.\n" );
  EXCHECK( ex_put_names( exoid, EX_ELEM_MAP, (char**) emap_names ), "Unable to write element map names.\n" );

  /*                 =============== Attribute names ================ */
  /* *** NEW API *** */
  EXCHECK( ex_put_attr_names( exoid, EX_EDGE_BLOCK, edgeBlocks[0].id, (char**)edge_attr_names1 ),
	   "Unable to write edge block 1 attribute names.\n" );

  /* *** NEW API *** */
  EXCHECK( ex_put_attr_names( exoid, EX_FACE_BLOCK, faceBlocks[0].id, (char**)face_attr_names1 ),
	   "Unable to write face block 1 attribute names.\n" );
  EXCHECK( ex_put_attr_names( exoid, EX_FACE_BLOCK, faceBlocks[1].id, (char**)face_attr_names2 ),
	   "Unable to write face block 1 attribute names.\n" );
  EXCHECK( ex_put_attr_names( exoid, EX_FACE_BLOCK, faceBlocks[2].id, (char**)face_attr_names3 ),
	   "Unable to write face block 1 attribute names.\n" );

  /* *** NEW API *** */
  EXCHECK( ex_put_attr_names( exoid, EX_ELEM_BLOCK, elemBlocks[0].id, (char**)elem_attr_names1 ),
	   "Unable to write elem block 1 attribute names.\n" );

  /*                  =============== Attribute values =============== */
  /* *** NEW API *** */
  EXCHECK( ex_put_attr( exoid, EX_EDGE_BLOCK, edgeBlocks[0].id, edge_attr_values1 ),
	   "Unable to write edge block 1 attribute values.\n" );

  /* *** NEW API *** */
  EXCHECK( ex_put_attr( exoid, EX_FACE_BLOCK, faceBlocks[0].id, face_attr_values1 ),
	   "Unable to write face block 1 attribute values.\n" );
  EXCHECK( ex_put_attr( exoid, EX_FACE_BLOCK, faceBlocks[1].id, face_attr_values2 ),
	   "Unable to write face block 1 attribute values.\n" );
  EXCHECK( ex_put_attr( exoid, EX_FACE_BLOCK, faceBlocks[2].id, face_attr_values3 ),
	   "Unable to write face block 1 attribute values.\n" );

  /* *** NEW API *** */
  EXCHECK( ex_put_attr( exoid, EX_ELEM_BLOCK, elemBlocks[0].id, elem_attr_values1 ),
	   "Unable to write elem block 1 attribute values.\n" );

  /*                  =============== Set parameters ================= */
  /* *** NEW API *** */
  EXCHECK( ex_put_names( exoid, EX_NODE_SET,  (char**)nset_names ), "Unable to write node set names.\n" );
  EXCHECK( ex_put_names( exoid, EX_EDGE_SET,  (char**)eset_names ), "Unable to write edge set names.\n" );
  EXCHECK( ex_put_names( exoid, EX_FACE_SET,  (char**)fset_names ), "Unable to write face set names.\n" );
  EXCHECK( ex_put_names( exoid, EX_SIDE_SET,  (char**)sset_names ), "Unable to write side set names.\n" );
  EXCHECK( ex_put_names( exoid, EX_ELEM_SET, (char**)elset_names ), "Unable to write element set names.\n" );

  {
    ex_set allSets[1+1+1+1+2];

    ex_set *nodeSets = &allSets[0];
    ex_set *edgeSets = &allSets[1];
    ex_set *faceSets = &allSets[2];
    ex_set *sideSets = &allSets[3];
    ex_set *elemSets = &allSets[4];
    
    nodeSets[0].type = EX_NODE_SET;
    nodeSets[0].id  = 1000;
    nodeSets[0].num_entry = 3;
    nodeSets[0].num_distribution_factor = 0;
    nodeSets[0].entry_list = nset_nodes;
    nodeSets[0].extra_list = NULL;
    nodeSets[0].distribution_factor_list  = NULL;
    
    edgeSets[0].type = EX_EDGE_SET;
    edgeSets[0].id  = 1200;
    edgeSets[0].num_entry = 6;
    edgeSets[0].num_distribution_factor = 6;
    edgeSets[0].entry_list = eset_edges;
    edgeSets[0].extra_list = eset_orient;
    edgeSets[0].distribution_factor_list  = eset_df;
    
    faceSets[0].type = EX_FACE_SET;
    faceSets[0].id  = 1400;
    faceSets[0].num_entry = 2;
    faceSets[0].num_distribution_factor = 0;
    faceSets[0].entry_list = fset_faces;
    faceSets[0].extra_list = fset_orient;
    faceSets[0].distribution_factor_list  = NULL;
    
    sideSets[0].type = EX_SIDE_SET;
    sideSets[0].id  = 1400;
    sideSets[0].num_entry = 5;
    sideSets[0].num_distribution_factor = 0;
    sideSets[0].entry_list = sset_elems;
    sideSets[0].extra_list = sset_sides;
    sideSets[0].distribution_factor_list  = NULL;
    
    elemSets[0].type = EX_ELEM_SET;
    elemSets[0].id  = 1800;
    elemSets[0].num_entry = 1;
    elemSets[0].num_distribution_factor = 0;
    elemSets[0].entry_list = &elset_elems[0];
    elemSets[0].extra_list = NULL;
    elemSets[0].distribution_factor_list  = NULL;
    
    elemSets[1].type = EX_ELEM_SET;
    elemSets[1].id  = 1900;
    elemSets[1].num_entry = 1;
    elemSets[1].num_distribution_factor = 0;
    elemSets[1].entry_list = &elset_elems[1];
    elemSets[1].extra_list = NULL;
    elemSets[1].distribution_factor_list  = NULL;
    
    if ( concatSets ) {
      EXCHECK( ex_put_sets(exoid, 1+2+1+1+1, allSets), "Unable to output concatenated sets.\n" );
    } else {
      EXCHECK( ex_put_sets( exoid, 1, nodeSets), "Unable to write node sets.\n" );
      EXCHECK( ex_put_sets( exoid, 1, edgeSets), "Unable to write edge sets.\n" );
      EXCHECK( ex_put_sets( exoid, 1, faceSets), "Unable to write face sets.\n" );
      EXCHECK( ex_put_sets( exoid, 1, sideSets), "Unable to write side sets.\n" );
      EXCHECK( ex_put_sets( exoid, 2, elemSets), "Unable to write element sets.\n" );
    }
  }

  /*                  =============== Result variable params ========= */
  /* *** NEW API *** */
  if ( concatResult ) {
    EXCHECK( ex_put_all_var_param_ext( exoid, &varParams ),
	     "Unable to write result variable parameter information.\n" );
  } else {
    EXCHECK( ex_put_var_param( exoid, "G", 2 ),
	     "Unable to write global result variable parameters.\n" );
    EXCHECK( ex_put_var_param( exoid, "N", 1 ),
	     "Unable to write nodal result variable parameters.\n" );
    EXCHECK( ex_put_var_param( exoid, "E", 1 ),
	     "Unable to write element result variable parameters.\n" );
    EXCHECK( ex_put_var_param( exoid, "L", 2 ),
	     "Unable to write edge result variable parameters.\n" );
    EXCHECK( ex_put_var_param( exoid, "F", 1 ),
	     "Unable to write face result variable parameters.\n" );
    EXCHECK( ex_put_var_param( exoid, "A", 1 ),
	     "Unable to write faceset result variable parameters.\n" );
  }

  /*                  =============== Result variable names ========== */
  /* *** NEW API *** */
  EXCHECK( ex_put_var_name( exoid, "G", 1, "CALIBER" ), "Unable to write variable name.\n" );
  EXCHECK( ex_put_var_name( exoid, "g", 2, "GUNPOWDER" ), "Unable to write variable name.\n" );
  EXCHECK( ex_put_var_name( exoid, "N", 1, "RHO" ), "Unable to write variable name.\n" );
  EXCHECK( ex_put_var_name( exoid, "l", 1, "GAMMA1" ), "Unable to write variable name.\n" );
  EXCHECK( ex_put_var_name( exoid, "L", 2, "GAMMA2" ), "Unable to write variable name.\n" );
  EXCHECK( ex_put_var_name( exoid, "f", 1, "PHI" ), "Unable to write variable name.\n" );
  EXCHECK( ex_put_var_name( exoid, "E", 1, "EPSTRN" ), "Unable to write variable name.\n" );
  EXCHECK( ex_put_var_name( exoid, "A", 1, "PHI0" ), "Unable to write variable name.\n" );

  /*                  =============== Result variable values ========= */
  t = 1.;
  /* *** NEW API *** */
  EXCHECK( ex_put_time( exoid, 1, &t ), "Unable to write time value.\n" );
  EXCHECK( ex_put_var( exoid, 1, EX_GLOBAL, 1, 0/*N/A*/, 2,      vals_glo_var[0] ), "Unable to write global var 1.\n" );
  EXCHECK( ex_put_var( exoid, 1, EX_EDGE_BLOCK, 1, 100, 20, vals_edge_var1eb1[0] ), "Unable to write edge block 1 var 1.\n" );
  EXCHECK( ex_put_var( exoid, 1, EX_EDGE_BLOCK, 2, 100, 20, vals_edge_var2eb1[0] ), "Unable to write edge block 1 var 2.\n" );
  EXCHECK( ex_put_var( exoid, 1, EX_FACE_BLOCK, 1, 500,  2, vals_face_var1fb1[0] ), "Unable to write face block 1 var 1.\n" );
  EXCHECK( ex_put_var( exoid, 1, EX_FACE_BLOCK, 1, 700,  8, vals_face_var1fb3[0] ), "Unable to write face block 3 var 1.\n" );
  EXCHECK( ex_put_var( exoid, 1, EX_ELEM_BLOCK, 1, 200,  2, vals_elem_var1eb1[0] ), "Unable to write elem block 1 var 1.\n" );
  EXCHECK( ex_put_var( exoid, 1, EX_FACE_SET,  1, 1400,  2, vals_fset_var1fs1[0] ), "Unable to write face set 1 var 1.\n" );

  t = 2.;
  EXCHECK( ex_put_time( exoid, 2, &t ), "Unable to write time value.\n" );
  EXCHECK( ex_put_var( exoid, 2, EX_GLOBAL, 1, 0/*N/A*/, 2,      vals_glo_var[1] ), "Unable to write global var 1.\n" );
  EXCHECK( ex_put_var( exoid, 2, EX_EDGE_BLOCK, 1, 100, 20, vals_edge_var1eb1[1] ), "Unable to write edge block 1 var 1.\n" );
  EXCHECK( ex_put_var( exoid, 2, EX_EDGE_BLOCK, 2, 100, 20, vals_edge_var2eb1[1] ), "Unable to write edge block 1 var 2.\n" );
  EXCHECK( ex_put_var( exoid, 2, EX_FACE_BLOCK, 1, 500,  2, vals_face_var1fb1[1] ), "Unable to write face block 1 var 1.\n" );
  EXCHECK( ex_put_var( exoid, 2, EX_FACE_BLOCK, 1, 700,  8, vals_face_var1fb3[1] ), "Unable to write face block 3 var 1.\n" );
  EXCHECK( ex_put_var( exoid, 2, EX_ELEM_BLOCK, 1, 200,  2, vals_elem_var1eb1[1] ), "Unable to write elem block 1 var 1.\n" );
  EXCHECK( ex_put_var( exoid, 2, EX_FACE_SET,  1, 1400,  2, vals_fset_var1fs1[1] ), "Unable to write face set 1 var 1.\n" );

  EXCHECK( ex_put_nodal_var( exoid, 1, 1, 12, vals_nod_var[0] ), "Unable to write nodal var 1.\n" );
  EXCHECK( ex_put_nodal_var( exoid, 2, 1, 12, vals_nod_var[1] ), "Unable to write nodal var 1.\n" );

  EXCHECK( ex_close( exoid ),
	   "Unable to close database.\n" );

  return 0;
}
示例#12
0
int main (int argc, char *argv[]){

  char **str2,*line,*curr;
    
  const char* ext=".exo";

  int   
    i,j,k,n,n1,cpu_word_size,io_word_size,exo_file,
    num_axes,num_nodes,num_elements,num_blocks,
    num_side_sets,num_node_sets,num_time_steps,
    num_global_vars,
    num_nodal_vars,num_element_vars,*ids,*iscr,
    *nsssides,*nssdfac,*elem_list,*side_list,
    *nnsnodes,*nnsdfac,*node_list;

  double
    *scr,*x,*y,*z,
    *escr;

  char * blknames = NULL;
  int *num_elem_in_block = NULL;

  /* QA Info */
  printf("%s: %s, %s\n", qainfo[0], qainfo[2], qainfo[1]);

  /* usage message*/
  if(argc != 2){
    printf("%s matlab_file_name.\n",argv[0]);
    printf("   the matlab_file_name is required\n");
    printf("%d", argc);
    exit(1);
  }
  
  /*open input file*/
  mat_file = Mat_Open(argv[1], MAT_ACC_RDONLY);
  if (mat_file == NULL) {
    printf("Error opening matlab file %s\n", argv[1]);
    return(1);
  }

  /*open output file*/
  cpu_word_size=sizeof(double);
  io_word_size=sizeof(double);
  /* QA records */
  ext=".exo";
  line = (char *) calloc (2049,sizeof(char));
  strcpy(line,argv[1]);
  strtok(line,".");  
  strcat(line,ext);
  exo_file = ex_create(line,EX_CLOBBER,&cpu_word_size,&io_word_size);
  if (exo_file < 0){
    printf("error creating %s\n",line);
    exit(1);
  }

  /* print */
  fprintf(stderr,"translating %s to %s ... ",argv[1],line);
  
  /* read database parameters */
  matGetInt("naxes",  1, 1,&num_axes);
  matGetInt("nnodes", 1, 1,&num_nodes);
  matGetInt("nelems", 1, 1,&num_elements);
  matGetInt("nblks",  1, 1,&num_blocks);
  matGetInt("nnsets", 1, 1,&num_node_sets);
  matGetInt("nssets", 1, 1,&num_side_sets);
  matGetInt("nsteps", 1, 1,&num_time_steps);
  matGetInt("ngvars", 1, 1,&num_global_vars);
  matGetInt("nnvars", 1, 1,&num_nodal_vars);
  matGetInt("nevars", 1, 1,&num_element_vars);

  /*export parameters */
  ex_put_init(exo_file,line,
	      num_axes,num_nodes,num_elements,num_blocks,
	      num_node_sets,num_side_sets);
  free(line);
  
  if ( num_global_vars > 0 ){
    ex_put_variable_param(exo_file,EX_GLOBAL,num_global_vars);
  }
  
  if ( num_nodal_vars > 0 ){
    ex_put_variable_param(exo_file,EX_NODAL,num_nodal_vars);
  }
  
  if ( num_element_vars > 0 ){
    ex_put_variable_param(exo_file,EX_ELEM_BLOCK,num_element_vars);
  }

  /* nodal coordinates */
  x = (double *) calloc(num_nodes,sizeof(double));
  y = (double *) calloc(num_nodes,sizeof(double));
  if (num_axes == 3) 
    z = (double *) calloc(num_nodes,sizeof(double));
  else 
    z = NULL;
  matGetDbl("x0", num_nodes, 1, x);
  matGetDbl("y0", num_nodes, 1, y);
  if (num_axes == 3)
    matGetDbl("z0", num_nodes,1,z);
  ex_put_coord(exo_file,x,y,z);
  free(x);
  free(y);
  if (num_axes == 3){ 

    free(z);
  }
  

  /* side sets (section by dgriffi) */
  if(num_side_sets > 0){ 
     
    /* ssids */
    ids = (int *) calloc(num_side_sets,sizeof(int)); 
    matGetInt("ssids",num_side_sets, 1,ids);

    /* nsssides */
    nsssides = (int *) calloc(num_side_sets,sizeof(int));
    matGetInt("nsssides",num_side_sets,1,nsssides);

    /* nssdfac */
    nssdfac = (int *) calloc(num_side_sets,sizeof(int));
    matGetInt("nssdfac",num_side_sets,1,nssdfac);

    for(i=0;i<num_side_sets;i++){
      char name[32];
  
      ex_put_set_param(exo_file,EX_SIDE_SET,ids[i],nsssides[i],nssdfac[i]);
      elem_list = (int *) calloc(nsssides[i],sizeof(int));
      side_list = (int *) calloc(nsssides[i],sizeof(int));
      escr = (double *) calloc(nssdfac[i],sizeof(double));
           
      sprintf(name,"sselem%02d",i+1);
      matGetInt(name,nsssides[i],1,elem_list);

      sprintf(name,"ssside%02d",i+1);
      matGetInt(name,nsssides[i],1,side_list);
      ex_put_set(exo_file,EX_SIDE_SET,ids[i],elem_list,side_list);

      free(elem_list);
      free(side_list);
      sprintf(name,"ssfac%02d",i+1);
      matGetDbl(name,nssdfac[i],1,escr);
      ex_put_set_dist_fact(exo_file,EX_SIDE_SET,ids[i],escr);
      free(escr);      
    }
   
    free(nsssides);
    free(nssdfac);
    free(ids);
  }  

  /* node sets (section by dgriffi) */
  if(num_node_sets > 0){ 
     
    /* nsids */
    ids = (int *) calloc(num_node_sets,sizeof(int)); 
    matGetInt("nsids",num_node_sets, 1,ids);

    /* nnsnodes */
    nnsnodes = (int *) calloc(num_node_sets,sizeof(int));
    matGetInt("nnsnodes",num_node_sets,1,nnsnodes);

    /* nnsdfac */
    nnsdfac = (int *) calloc(num_node_sets,sizeof(int));
    matGetInt("nnsdfac",num_node_sets,1,nnsdfac);

    for(i=0;i<num_node_sets;i++){
      char name[32];

      ex_put_set_param(exo_file,EX_NODE_SET,ids[i],nnsnodes[i],nnsdfac[i]);
      node_list = (int *) calloc(nnsnodes[i],sizeof(int));
      escr = (double *) calloc(nnsdfac[i],sizeof(double));
           
      sprintf(name,"nsnod%02d",i+1);
      matGetInt(name,nnsnodes[i],1,node_list);
      ex_put_set(exo_file,EX_NODE_SET,ids[i],node_list,NULL);
      free(node_list);
      
      sprintf(name,"nsfac%02d",i+1);
      matGetDbl(name,nnsdfac[i],1,escr);
      ex_put_set_dist_fact(exo_file,EX_NODE_SET,ids[i],escr);
      free(escr);      
    }
   
    free(nnsdfac);
    free(nnsnodes);
    free(ids);
  }  


  /* element blocks */ 
  /* get elem block ids */
  ids = (int *) calloc(num_blocks,sizeof(int));
  matGetInt("blkids",num_blocks,1,ids);

  /* get elem block types */
  blknames = (char *) calloc(num_blocks*(MAX_STR_LENGTH+1),sizeof(char));
  matGetStr("blknames",blknames);
  num_elem_in_block = (int *) calloc(num_blocks,sizeof(int));
  curr = blknames;
  curr = strtok(curr,"\n");
  for(i=0;i<num_blocks;i++){
    char name[32];

    sprintf(name,"blk%02d",i+1);
    n1 = matArrNRow(name);
    n = matArrNCol(name);
    iscr = (int *) calloc(n*n1,sizeof(int));
    matGetInt(name,n1,n,iscr);
    num_elem_in_block[i]=n;
    ex_put_elem_block(exo_file,ids[i],curr,n,n1,0);
    ex_put_conn(exo_file,EX_ELEM_BLOCK,ids[i],iscr,NULL,NULL);
    free(iscr);
    curr = strtok(NULL, "\n");
  }
  free(blknames);

  /* time values */
  if (num_time_steps > 0 ) {
    scr = (double *) calloc(num_time_steps,sizeof(double));
    matGetDbl( "time", num_time_steps, 1,scr);
    for (i=0;i<num_time_steps;i++){
      ex_put_time(exo_file,i+1,&scr[i]);
    }
    free(scr); 
  }
  
  /* global variables */
  if (num_global_vars > 0 ){
    int max_name_length = ex_inquire_int(exo_file, EX_INQ_DB_MAX_USED_NAME_LENGTH);
    char *str = (char *) calloc(num_global_vars * (max_name_length+1), sizeof(char));
    matGetStr("gnames",str);
    str2 = (char **) calloc(num_global_vars,sizeof(char*));
    curr = strtok(str,"\n");
    for(i=0;i<num_global_vars;i++){
      str2[i]=curr;
      curr = strtok(NULL,"\n");
    }
    ex_put_variable_names(exo_file, EX_GLOBAL, num_global_vars, str2);
    free(str);
    free(str2);

    {
      double * global_var_vals;
      double * temp;
      global_var_vals = (double *) calloc(num_global_vars*num_time_steps,sizeof(double));
      temp            = (double *) calloc(num_time_steps,sizeof(double));
      for (j=0;j<num_global_vars;j++) {
	char name[32];
	sprintf(name,"gvar%02d",j+1);
	matGetDbl(name,num_time_steps,1,temp);
	for (i=0; i < num_time_steps; i++) {
	  global_var_vals[num_global_vars*i+j]=temp[i];
	}
      }
      for (i=0; i<num_time_steps; i++) {
	size_t offset = num_global_vars * i;
	ex_put_var(exo_file,i+1,EX_GLOBAL,1,0,num_global_vars,&global_var_vals[offset]);
      }
      free(temp);
      free(global_var_vals);
    }
  }

  
  /* nodal variables */ /* section by dtg */

  if (num_nodal_vars > 0){
    int max_name_length = ex_inquire_int(exo_file, EX_INQ_DB_MAX_USED_NAME_LENGTH);
    char *str = (char *) calloc(num_nodal_vars * (max_name_length+1), sizeof(char));
    matGetStr("nnames",str);
    str2 = (char **) calloc(num_nodal_vars,sizeof(char*));
    curr = strtok(str,"\n");
    for(i=0;i<num_nodal_vars;i++){
      str2[i]=curr;
      curr = strtok(NULL,"\n");
    }
    ex_put_variable_names(exo_file, EX_NODAL, num_nodal_vars, str2);	
    free(str);
    free(str2);
    {
      double * nodal_var_vals;
      for (i=0;i<num_nodal_vars;i++) {
	char name[32];
	nodal_var_vals = (double *) calloc(num_nodes*num_time_steps,sizeof(double));
	sprintf(name,"nvar%02d",i+1);
	matGetDbl(name,num_nodes,num_time_steps,nodal_var_vals);
	for (j=0;j<num_time_steps;j++) {
	  ex_put_var(exo_file,j+1,EX_NODAL,i+1,num_nodes,1,nodal_var_vals+num_nodes*j);
	}
	free(nodal_var_vals); 
      }
    }
  }

  /* elemental variables */ /* section by dtg */
  
  if (num_element_vars > 0){
    int max_name_length = ex_inquire_int(exo_file, EX_INQ_DB_MAX_USED_NAME_LENGTH);
    char *str = (char *) calloc(num_element_vars * (max_name_length+1), sizeof(char));
    matGetStr("enames",str);
    str2 = (char **) calloc(num_element_vars,sizeof(char*));
    curr = strtok(str,"\n");
    for(i=0;i<num_element_vars;i++){
      str2[i]=curr;
      curr = strtok(NULL,"\n");
    }
    ex_put_variable_names(exo_file, EX_ELEM_BLOCK, num_element_vars, str2);	
    free(str);
    free(str2);
    {
      double * element_var_vals;
      for (i=0;i<num_element_vars;i++) {
	char name[32];
	element_var_vals = (double *) calloc(num_elements*num_time_steps,sizeof(double));       
	sprintf(name,"evar%02d",i+1);
	matGetDbl(name,num_elements,num_time_steps,element_var_vals);
	n=0;       
	for (j=0;j<num_time_steps;j++) {
	  for (k=0;k<num_blocks;k++) {
	    ex_put_var(exo_file,j+1,EX_ELEM_BLOCK, i+1,ids[k],num_elem_in_block[k],element_var_vals+n);
	    n=n+num_elem_in_block[k];
	  }
	}
	free(element_var_vals);
      }
    }
  }
  free(ids); 

  /* node and element number maps */
  ids = (int *) calloc (num_nodes,sizeof(int));
  if ( !matGetInt("node_num_map",num_nodes,1,ids)){
    ex_put_node_num_map(exo_file,ids);
  }
  free(ids);

  ids = (int *) calloc (num_elements,sizeof(int));
  if ( !matGetInt("elem_num_map",num_elements,1,ids)){
    ex_put_elem_num_map(exo_file,ids);
  }
  free(ids);
  free(num_elem_in_block);
  
  /* close exo file */
  ex_close(exo_file);
  
  /* close mat file */
  Mat_Close(mat_file);

  /* */
  fprintf(stderr,"done.\n");

  /* exit status */
  add_to_log("mat2exo", 0);
  return(0);
}
示例#13
0
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10];
   int num_node_sets, num_side_sets, error;
   int i, j, k, m;
   int node_list[100];
   int ebids[10];
   int  num_qa_rec, num_info;
   int num_glo_vars, num_nod_vars, num_ele_vars;
   int whole_time_step, num_time_steps;
   int CPU_word_size,IO_word_size;
   int prop_array[2];

   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
   float time_value;
   float x[100], y[100], z[100];
   float dist_fact[100];
   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];

   ex_opts (EX_VERBOSE | EX_ABORT );

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("test.exo",       /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   /* ncopts = NC_VERBOSE; */

/* initialize file with parameters */

   num_dim = 3;
   num_nodes = 33;
   num_elem = 0;
   num_elem_blk = 0;
   num_node_sets = 2;
   num_side_sets = 0;

   error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem,
                        num_elem_blk, num_node_sets, num_side_sets);

   printf ("after ex_put_init, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* write nodal coordinates values and names to database */

/* Quad #1 */
   x[0] = 0.0; y[0] = 0.0; z[0] = 0.0;
   x[1] = 1.0; y[1] = 0.0; z[1] = 0.0;
   x[2] = 1.0; y[2] = 1.0; z[2] = 0.0;
   x[3] = 0.0; y[3] = 1.0; z[3] = 0.0;

/* Quad #2 */
   x[4]  =  1.0; y[4]  =  0.0; z[4]  =  0.0;
   x[5]  =  2.0; y[5]  =  0.0; z[5]  =  0.0;
   x[6]  =  2.0; y[6]  =  1.0; z[6]  =  0.0;
   x[7]  =  1.0; y[7]  =  1.0; z[7]  =  0.0;

/* Hex #1 */
   x[8]  =  0.0; y[8]  =  0.0; z[8]  =  0.0;
   x[9]  = 10.0; y[9]  =  0.0; z[9]  =  0.0;
   x[10] = 10.0; y[10] =  0.0; z[10] =-10.0;
   x[11] =  1.0; y[11] =  0.0; z[11] =-10.0;
   x[12] =  1.0; y[12] = 10.0; z[12] =  0.0;
   x[13] = 10.0; y[13] = 10.0; z[13] =  0.0;
   x[14] = 10.0; y[14] = 10.0; z[14] =-10.0;
   x[15] =  1.0; y[15] = 10.0; z[15] =-10.0;

/* Tetra #1 */
   x[16] =  0.0; y[16] =  0.0; z[16] =  0.0;
   x[17] =  1.0; y[17] =  0.0; z[17] =  5.0;
   x[18] = 10.0; y[18] =  0.0; z[18] =  2.0;
   x[19] =  7.0; y[19] =  5.0; z[19] =  3.0;

/* Wedge #1 */
   x[20] =  3.0; y[20] =  0.0; z[20] =  6.0;
   x[21] =  6.0; y[21] =  0.0; z[21] =  0.0;
   x[22] =  0.0; y[22] =  0.0; z[22] =  0.0;
   x[23] =  3.0; y[23] =  2.0; z[23] =  6.0;
   x[24] =  6.0; y[24] =  2.0; z[24] =  2.0;
   x[25] =  0.0; y[25] =  2.0; z[25] =  0.0;

/* Tetra #2 */
   x[26] =  2.7; y[26] =  1.7; z[26] =  2.7;
   x[27] =  6.0; y[27] =  1.7; z[27] =  3.3;
   x[28] =  5.7; y[28] =  1.7; z[28] =  1.7;
   x[29] =  3.7; y[29] =  0.0; z[29] =  2.3;

/* 3d Tri */
   x[30] =  0.0; y[30] =  0.0; z[30] =  0.0;
   x[31] = 10.0; y[31] =  0.0; z[31] =  0.0;
   x[32] = 10.0; y[32] = 10.0; z[32] = 10.0;

   error = ex_put_coord (exoid, x, y, z);
   printf ("after ex_put_coord, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   coord_names[0] = "xcoor";
   coord_names[1] = "ycoor";
   coord_names[2] = "zcoor";

   error = ex_put_coord_names (exoid, coord_names);
   printf ("after ex_put_coord_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* write individual node sets */


   error = ex_put_node_set_param (exoid, 20, 5, 5);
   printf ("after ex_put_node_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; 
   node_list[3] = 13; node_list[4] = 14; 

   dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0;
   dist_fact[3] = 4.0; dist_fact[4] = 5.0;

   error = ex_put_node_set (exoid, 20, node_list);
   printf ("after ex_put_node_set, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_node_set_dist_fact (exoid, 20, dist_fact);
   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   error = ex_put_node_set_param (exoid, 21, 3, 3);
   printf ("after ex_put_node_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   node_list[0] = 20; node_list[1] = 21; node_list[2] = 22; 

   dist_fact[0] = 1.1; dist_fact[1] = 2.1; dist_fact[2] = 3.1;

   error = ex_put_node_set (exoid, 21, node_list);
   printf ("after ex_put_node_set, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_node_set_dist_fact (exoid, 21, dist_fact);
   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
   printf ("after ex_put_prop, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   prop_array[0] = 1000;
   prop_array[1] = 2000;

   error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
   printf ("after ex_put_prop_array, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }



/* write QA records; test empty and just blank-filled records */

   num_qa_rec = 2;


   qa_record[0][0] = "TESTWT";
   qa_record[0][1] = "testwt";
   qa_record[0][2] = "07/07/93";
   qa_record[0][3] = "15:41:33";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   error = ex_put_qa (exoid, num_qa_rec, qa_record);
   printf ("after ex_put_qa, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


/* write information records; test empty and just blank-filled records */

   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   error = ex_put_info (exoid, num_info, info);
   printf ("after ex_put_info, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }



/* write results variables parameters and names */

   num_glo_vars = 1;

   var_names[0] = "glo_vars";

   error = ex_put_var_param (exoid, "g", num_glo_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_var_names (exoid, "g", num_glo_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }



   num_nod_vars = 2;
   /*              12345678901234567890123456789012 */
   var_names[0] = "node_variable_a_very_long_name_0";
   var_names[1] = "nod_var1";

   error = ex_put_var_param (exoid, "n", num_nod_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_var_names (exoid, "n", num_nod_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   num_ele_vars = 0;

/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 * obviously the analysis code will populate these arrays
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
   elem_var_vals = (float *) calloc (4, CPU_word_size);

   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

/* write time value */

     error = ex_put_time (exoid, whole_time_step, &time_value);
     printf ("after ex_put_time, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

/* write global variables */

     for (j=0; j<num_glo_vars; j++)
     {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
                               glob_var_vals);
     printf ("after ex_put_glob_vars, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

/* write nodal variables */

     for (k=1; k<=num_nod_vars; k++)
     {
       for (j=0; j<num_nodes; j++)
       {
         nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
       }

       error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes,
                                 nodal_var_vals);
       printf ("after ex_put_nodal_var, error = %d\n", error);
       if (error) {
         ex_close (exoid);
         exit(-1);
       }

     }

/* write element variables */

     for (k=1; k<=num_ele_vars; k++)
     {
       for (j=0; j<num_elem_blk; j++)
       {
         for (m=0; m<num_elem_in_block[j]; m++)
         {
           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
                              ((float)(m+1)*time_value);
           /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
         }
         error = ex_put_elem_var (exoid, whole_time_step, k, ebids[j],
                                  num_elem_in_block[j], elem_var_vals);
         printf ("after ex_put_elem_var, error = %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

     whole_time_step++;

/* update the data file; this should be done at the end of every time step
 * to ensure that no data is lost if the analysis dies
 */
     error = ex_update (exoid);
     printf ("after ex_update, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
   free(glob_var_vals);
   free(nodal_var_vals);
   free(elem_var_vals);


/* close the EXODUS files
 */
   error = ex_close (exoid);
   printf ("after ex_close, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   return 0;
}
示例#14
0
文件: Writer.cpp 项目: hpcdev/xdm
void ExodusWriter::writeItem( xdm::RefPtr< xdm::Item > item, const xdm::FileSystemPath& path ) {

  WritableExodusFile file( path );

  std::size_t timeStep = 0;

  ex_init_params meshParams;
  std::strcpy( meshParams.title, item->name().substr( 0, MAX_LINE_LENGTH + 1 ).c_str() );

  // First make up collections of pointers to everything that we know about. For now,
  // that is just Blocks.
  GatherExodusObjectsVisitor< EdgeBlock > edgeBlockGatherVisitor;
  GatherExodusObjectsVisitor< FaceBlock > faceBlockGatherVisitor;
  GatherExodusObjectsVisitor< ElementBlock > elementBlockGatherVisitor;
  item->traverse( edgeBlockGatherVisitor );
  item->traverse( faceBlockGatherVisitor );
  item->traverse( elementBlockGatherVisitor );
  meshParams.num_edge_blk = edgeBlockGatherVisitor.pointers().size();
  meshParams.num_face_blk = faceBlockGatherVisitor.pointers().size();
  meshParams.num_elem_blk = elementBlockGatherVisitor.pointers().size();

  if ( meshParams.num_edge_blk + meshParams.num_face_blk + meshParams.num_elem_blk < 1 ) {
    // There is nothing to write.
    return;
  }

  // There is only one Geometry (one unique set of nodes). To find it, we just need to find
  // the first one.
  xdmGrid::Geometry* geom;
  if ( meshParams.num_edge_blk > 0 ) {
    geom = dynamic_cast< Block* >( edgeBlockGatherVisitor.pointers().front() )->geometry().get();
  } else if ( meshParams.num_face_blk > 0 ) {
    geom = dynamic_cast< Block* >( faceBlockGatherVisitor.pointers().front() )->geometry().get();
  } else {
    geom = dynamic_cast< Block* >( elementBlockGatherVisitor.pointers().front() )->geometry().get();
  }
  meshParams.num_dim = geom->dimension();
  meshParams.num_nodes = geom->numberOfNodes();
  std::vector< void* > geomPtrs( 3, NULL );
  for ( std::size_t dim = 0; dim < meshParams.num_dim; ++dim ) {
    geomPtrs[ dim ] = geom->child( dim )->data()->array()->data();
  }
  EXODUS_CALL( ex_put_coord( file.id(), geomPtrs[0], geomPtrs[1], geomPtrs[2] ),
    "Unable to write coordinates." );
  std::vector< ExodusString > coordNames;
  coordNames.push_back( "X" );
  coordNames.push_back( "Y" );
  coordNames.push_back( "Z" );
  char* coordNamesCharArray[ 3 ];
  vectorToCharStarArray( coordNames, coordNamesCharArray );
  EXODUS_CALL( ex_put_coord_names( file.id(), coordNamesCharArray ),
    "Unable to write coordinate names." );

  // Count the entries in the blocks.
  meshParams.num_edge = edgeBlockGatherVisitor.totalNumberOfEntries();
  meshParams.num_face = faceBlockGatherVisitor.totalNumberOfEntries();
  meshParams.num_elem = elementBlockGatherVisitor.totalNumberOfEntries();

  // Not doing sets and maps at the moment...
  meshParams.num_node_sets = 0;
  meshParams.num_edge_sets = 0;
  meshParams.num_face_sets = 0;
  meshParams.num_side_sets = 0;
  meshParams.num_elem_sets = 0;
  meshParams.num_node_maps = 0;
  meshParams.num_edge_maps = 0;
  meshParams.num_face_maps = 0;
  meshParams.num_elem_maps = 0;

  EXODUS_CALL( ex_put_init_ext( file.id(), &meshParams ),
    "Unable to initialize database.\n" );

  // Write the time step info, if there is any.
  FindTimeVisitor timeVisit;
  item->traverse( timeVisit );
  if ( timeVisit.time() ) {
    double timeVal = timeVisit.time()->value();
    EXODUS_CALL( ex_put_time( file.id(), (int)( timeStep + 1 ), (void*)&timeVal ),
      "Unable to write time value." );
  }

  // Write the blocks.
  writeBlockData(
    file.id(),
    EX_EDGE_BLOCK,
    edgeBlockGatherVisitor.names(),
    edgeBlockGatherVisitor.pointers() );

  writeBlockData(
    file.id(),
    EX_FACE_BLOCK,
    faceBlockGatherVisitor.names(),
    faceBlockGatherVisitor.pointers() );

  writeBlockData(
    file.id(),
    EX_ELEM_BLOCK,
    elementBlockGatherVisitor.names(),
    elementBlockGatherVisitor.pointers() );

  // Write the variable data for this time step.
  for ( std::size_t blockIndex = 0; blockIndex < meshParams.num_edge_blk; ++blockIndex ) {
    edgeBlockGatherVisitor.pointers()[ blockIndex ]->writeTimeStep( file.id(), timeStep );
  }
  for ( std::size_t blockIndex = 0; blockIndex < meshParams.num_face_blk; ++blockIndex ) {
    faceBlockGatherVisitor.pointers()[ blockIndex ]->writeTimeStep( file.id(), timeStep );
  }
  for ( std::size_t blockIndex = 0; blockIndex < meshParams.num_elem_blk; ++blockIndex ) {
    elementBlockGatherVisitor.pointers()[ blockIndex ]->writeTimeStep( file.id(), timeStep );
  }

}
示例#15
0
int main(int argc, char **argv)
{
  int  exoid, num_dim, num_nodes, num_elem, num_elem_blk;
  int  exoidm[10], num_dim2, num_nodes2, num_elem2, num_elem_blk2;
  int  num_elem_in_block[10], num_node_sets, num_nodes_per_elem[10];
  int  num_elem_in_block2[10], num_node_sets2, num_nodes_per_elem2[10];
  int  num_side_sets, error;
  int  num_side_sets2, nexofiles = 5;
  int  i, j, k, m, n;
  int *elem_map, *connect, node_list[100], elem_list[100], side_list[100];
  int *elem_map2, *connect2, node_list2[100], elem_list2[100], side_list2[100];
  int  ebids[10], ids[10];
  int  ebids2[10], ids2[10];
  int  num_nodes_per_set[10], num_elem_per_set[10];
  int  num_nodes_per_set2[10], num_elem_per_set2[10];
  int  num_df_per_set[10], num_df_per_set2[10];
  int  df_ind[10], node_ind[10], elem_ind[10];
  int  df_ind2[10], node_ind2[10], elem_ind2[10];
  int  num_qa_rec, num_info;
  int  num_qa_rec2, num_info2;
  int  num_glo_vars, num_nod_vars, num_ele_vars;
  int  num_glo_vars2, num_nod_vars2, num_ele_vars2;
  int *truth_tab;
  int  whole_time_step, num_time_steps;
  int  CPU_word_size, IO_word_size;
  int  prop_array[2];

  float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
  float  time_value;
  float  time_value2;
  float  x[100], y[100], z[100];
  float  attrib[1], dist_fact[1008];
  float  attrib2[1], dist_fact2[100];
  char * coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
  char * coord_names2[3], *qa_record2[2][4], *info2[3], *var_names2[3];
  char   tmpstr[80];
  char * prop_names[2];
  char   exofname[256];

  ex_opts(EX_VERBOSE | EX_ABORT);

  /* Specify compute and i/o word size */

  CPU_word_size = 0; /* sizeof(float) */
  IO_word_size  = 4; /* (4 bytes) */

  /* create EXODUS II files */

  exoid = ex_create("test.exo",     /* filename path */
                    EX_CLOBBER,     /* create mode */
                    &CPU_word_size, /* CPU float word size in bytes */
                    &IO_word_size); /* I/O float word size in bytes */
  printf("after ex_create for test.exo, exoid = %d\n", exoid);
  printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);

  for (n = 0; n < nexofiles; n++) {
    sprintf(exofname, "test%d.exo", n);
    printf("test file name: %s\n", exofname);
    exoidm[n] = ex_create(exofname,       /* filename path */
                          EX_CLOBBER,     /* create mode */
                          &CPU_word_size, /* CPU float word size in bytes */
                          &IO_word_size); /* I/O float word size in bytes */
    printf("after ex_create for %s, exoid = %d\n", exofname, exoidm[n]);
  }

  /* initialize file with parameters */

  num_dim       = 3;
  num_nodes     = 26;
  num_elem      = 5;
  num_elem_blk  = 5;
  num_node_sets = 2;
  num_side_sets = 5;

  error = ex_put_init(exoid, "This is a test", num_dim, num_nodes, num_elem, num_elem_blk,
                      num_node_sets, num_side_sets);

  printf("after ex_put_init, error = %d\n", error);

  /* initialize file n with parameters */

  num_dim2       = 3;
  num_nodes2     = 26;
  num_elem2      = 5;
  num_elem_blk2  = 5;
  num_node_sets2 = 2;
  num_side_sets2 = 5;

  for (n = 0; n < nexofiles; n++) {
    sprintf(tmpstr, "This is test %d", n);

    error = ex_put_init(exoidm[n], tmpstr, num_dim2, num_nodes2, num_elem2, num_elem_blk2,
                        num_node_sets2, num_side_sets2);

    printf("after ex_put_init (%d), error = %d\n", n, error);
  }

  /* write nodal coordinates values and names to database */

  /* Quad #1 */
  x[0] = 0.0;
  y[0] = 0.0;
  z[0] = 0.0;
  x[1] = 1.0;
  y[1] = 0.0;
  z[1] = 0.0;
  x[2] = 1.0;
  y[2] = 1.0;
  z[2] = 0.0;
  x[3] = 0.0;
  y[3] = 1.0;
  z[3] = 0.0;

  /* Quad #2 */
  x[4] = 1.0;
  y[4] = 0.0;
  z[4] = 0.0;
  x[5] = 2.0;
  y[5] = 0.0;
  z[5] = 0.0;
  x[6] = 2.0;
  y[6] = 1.0;
  z[6] = 0.0;
  x[7] = 1.0;
  y[7] = 1.0;
  z[7] = 0.0;

  /* Hex #1 */
  x[8]  = 0.0;
  y[8]  = 0.0;
  z[8]  = 0.0;
  x[9]  = 10.0;
  y[9]  = 0.0;
  z[9]  = 0.0;
  x[10] = 10.0;
  y[10] = 0.0;
  z[10] = -10.0;
  x[11] = 1.0;
  y[11] = 0.0;
  z[11] = -10.0;
  x[12] = 1.0;
  y[12] = 10.0;
  z[12] = 0.0;
  x[13] = 10.0;
  y[13] = 10.0;
  z[13] = 0.0;
  x[14] = 10.0;
  y[14] = 10.0;
  z[14] = -10.0;
  x[15] = 1.0;
  y[15] = 10.0;
  z[15] = -10.0;

  /* Tetra #1 */
  x[16] = 0.0;
  y[16] = 0.0;
  z[16] = 0.0;
  x[17] = 1.0;
  y[17] = 0.0;
  z[17] = 5.0;
  x[18] = 10.0;
  y[18] = 0.0;
  z[18] = 2.0;
  x[19] = 7.0;
  y[19] = 5.0;
  z[19] = 3.0;

  /* Wedge #1 */
  x[20] = 3.0;
  y[20] = 0.0;
  z[20] = 6.0;
  x[21] = 6.0;
  y[21] = 0.0;
  z[21] = 0.0;
  x[22] = 0.0;
  y[22] = 0.0;
  z[22] = 0.0;
  x[23] = 3.0;
  y[23] = 2.0;
  z[23] = 6.0;
  x[24] = 6.0;
  y[24] = 2.0;
  z[24] = 2.0;
  x[25] = 0.0;
  y[25] = 2.0;
  z[25] = 0.0;

  error = ex_put_coord(exoid, x, y, z);
  printf("after ex_put_coord, error = %d\n", error);

  /* write nodal coordinates values and names to database */

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_coord(exoidm[n], x, y, z);
    printf("after ex_put_coord (%d), error = %d\n", n, error);
  }

  coord_names[0] = "xcoor";
  coord_names[1] = "ycoor";
  coord_names[2] = "zcoor";

  error = ex_put_coord_names(exoid, coord_names);
  printf("after ex_put_coord_names, error = %d\n", error);

  coord_names2[0] = "xcoor";
  coord_names2[1] = "ycoor";
  coord_names2[2] = "zcoor";

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_coord_names(exoidm[n], coord_names2);
    printf("after ex_put_coord_names (%d), error = %d\n", n, error);
  }

  /* write element order map */

  elem_map = (int *)calloc(num_elem, sizeof(int));

  for (i = 1; i <= num_elem; i++) {
    elem_map[i - 1] = i;
  }

  error = ex_put_map(exoid, elem_map);
  printf("after ex_put_map, error = %d\n", error);

  free(elem_map);

  elem_map2 = (int *)calloc(num_elem2, sizeof(int));

  for (i = 1; i <= num_elem2; i++) {
    elem_map2[i - 1] = i;
  }

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_map(exoidm[n], elem_map2);
    printf("after ex_put_map (%d), error = %d\n", n, error);
  }

  free(elem_map2);

  /* write element block parameters */

  num_elem_in_block[0] = 1;
  num_elem_in_block[1] = 1;
  num_elem_in_block[2] = 1;
  num_elem_in_block[3] = 1;
  num_elem_in_block[4] = 1;

  num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
  num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
  num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
  num_nodes_per_elem[3] = 4; /* elements in block #3 are 4-node tetras */
  num_nodes_per_elem[4] = 6; /* elements in block #3 are 6-node wedges */

  ebids[0] = 10;
  ebids[1] = 11;
  ebids[2] = 12;
  ebids[3] = 13;
  ebids[4] = 14;

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[0], "quad", num_elem_in_block[0],
                       num_nodes_per_elem[0], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[1], "quad", num_elem_in_block[1],
                       num_nodes_per_elem[1], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[2], "hex", num_elem_in_block[2],
                       num_nodes_per_elem[2], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[3], "tetra", num_elem_in_block[3],
                       num_nodes_per_elem[3], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[4], "wedge", num_elem_in_block[4],
                       num_nodes_per_elem[4], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  /* write element block properties */

  prop_names[0] = "MATL";
  prop_names[1] = "DENSITY";
  error         = ex_put_prop_names(exoid, EX_ELEM_BLOCK, 2, prop_names);
  printf("after ex_put_prop_names, error = %d\n", error);

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50);
  printf("after ex_put_prop, error = %d\n", error);

  /* files n */

  num_elem_in_block2[0] = 1;
  num_elem_in_block2[1] = 1;
  num_elem_in_block2[2] = 1;
  num_elem_in_block2[3] = 1;
  num_elem_in_block2[4] = 1;

  num_nodes_per_elem2[0] = 4; /* elements in block #1 are 4-node quads  */
  num_nodes_per_elem2[1] = 4; /* elements in block #2 are 4-node quads  */
  num_nodes_per_elem2[2] = 8; /* elements in block #3 are 8-node hexes  */
  num_nodes_per_elem2[3] = 4; /* elements in block #3 are 4-node tetras */
  num_nodes_per_elem2[4] = 6; /* elements in block #3 are 6-node wedges */

  ebids2[0] = 10;
  ebids2[1] = 11;
  ebids2[2] = 12;
  ebids2[3] = 13;
  ebids2[4] = 14;

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_block(exoidm[n], EX_ELEM_BLOCK, ebids2[0], "quad", num_elem_in_block2[0],
                         num_nodes_per_elem2[0], 0, 0, 1);
    printf("after ex_put_elem_block (%d), error = %d\n", n, error);

    error = ex_put_block(exoidm[n], EX_ELEM_BLOCK, ebids2[1], "quad", num_elem_in_block2[1],
                         num_nodes_per_elem2[1], 0, 0, 1);
    printf("after ex_put_elem_block (%d), error = %d\n", n, error);

    error = ex_put_block(exoidm[n], EX_ELEM_BLOCK, ebids2[2], "hex", num_elem_in_block2[2],
                         num_nodes_per_elem2[2], 0, 0, 1);
    printf("after ex_put_elem_block (%d), error = %d\n", n, error);

    error = ex_put_block(exoidm[n], EX_ELEM_BLOCK, ebids2[3], "tetra", num_elem_in_block2[3],
                         num_nodes_per_elem2[3], 0, 0, 1);
    printf("after ex_put_elem_block (%d), error = %d\n", n, error);

    error = ex_put_block(exoidm[n], EX_ELEM_BLOCK, ebids2[4], "wedge", num_elem_in_block2[4],
                         num_nodes_per_elem2[4], 0, 0, 1);
    printf("after ex_put_elem_block (%d), error = %d\n", n, error);

    /* write element block properties */

    prop_names[0] = "MATL";
    prop_names[1] = "DENSITY";
    error         = ex_put_prop_names(exoidm[n], EX_ELEM_BLOCK, 2, prop_names);
    printf("after ex_put_prop_names (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_ELEM_BLOCK, ebids2[0], "MATL", 100);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
    error = ex_put_prop(exoidm[n], EX_ELEM_BLOCK, ebids2[1], "MATL", 200);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
    error = ex_put_prop(exoidm[n], EX_ELEM_BLOCK, ebids2[2], "MATL", 300);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
    error = ex_put_prop(exoidm[n], EX_ELEM_BLOCK, ebids2[3], "MATL", 400);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
    error = ex_put_prop(exoidm[n], EX_ELEM_BLOCK, ebids2[4], "MATL", 500);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
  }

  /* write element connectivity */

  connect    = (int *)calloc(8, sizeof(int));
  connect[0] = 1;
  connect[1] = 2;
  connect[2] = 3;
  connect[3] = 4;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 5;
  connect[1] = 6;
  connect[2] = 7;
  connect[3] = 8;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[1], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 9;
  connect[1] = 10;
  connect[2] = 11;
  connect[3] = 12;
  connect[4] = 13;
  connect[5] = 14;
  connect[6] = 15;
  connect[7] = 16;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 17;
  connect[1] = 18;
  connect[2] = 19;
  connect[3] = 20;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[3], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 21;
  connect[1] = 22;
  connect[2] = 23;
  connect[3] = 24;
  connect[4] = 25;
  connect[5] = 26;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[4], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  free(connect);

  for (n = 0; n < nexofiles; n++) {
    connect2    = (int *)calloc(8, sizeof(int));
    connect2[0] = 1;
    connect2[1] = 2;
    connect2[2] = 3;
    connect2[3] = 4;

    error = ex_put_conn(exoidm[n], EX_ELEM_BLOCK, ebids[0], connect2, NULL, NULL);
    printf("after ex_put_elem_conn (%d), error = %d\n", n, error);

    connect2[0] = 5;
    connect2[1] = 6;
    connect2[2] = 7;
    connect2[3] = 8;

    error = ex_put_conn(exoidm[n], EX_ELEM_BLOCK, ebids[1], connect2, NULL, NULL);
    printf("after ex_put_elem_conn (%d), error = %d\n", n, error);

    connect2[0] = 9;
    connect2[1] = 10;
    connect2[2] = 11;
    connect2[3] = 12;
    connect2[4] = 13;
    connect2[5] = 14;
    connect2[6] = 15;
    connect2[7] = 16;

    error = ex_put_conn(exoidm[n], EX_ELEM_BLOCK, ebids2[2], connect2, NULL, NULL);
    printf("after ex_put_elem_conn (%d), error = %d\n", n, error);

    connect2[0] = 17;
    connect2[1] = 18;
    connect2[2] = 19;
    connect2[3] = 20;

    error = ex_put_conn(exoidm[n], EX_ELEM_BLOCK, ebids2[3], connect2, NULL, NULL);
    printf("after ex_put_elem_conn (%d), error = %d\n", n, error);

    connect2[0] = 21;
    connect2[1] = 22;
    connect2[2] = 23;
    connect2[3] = 24;
    connect2[4] = 25;
    connect2[5] = 26;

    error = ex_put_conn(exoidm[n], EX_ELEM_BLOCK, ebids2[4], connect2, NULL, NULL);
    printf("after ex_put_elem_conn (%d), error = %d\n", n, error);

    free(connect2);
  }

  /* write element block attributes */

  attrib[0] = 3.14159;
  error     = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[0], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  attrib[0] = 6.14159;
  error     = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[1], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[2], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[3], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[4], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  for (n = 0; n < nexofiles; n++) {
    attrib2[0] = 3.;
    error      = ex_put_attr(exoidm[n], EX_ELEM_BLOCK, ebids[0], attrib2);
    printf("after ex_put_elem_attr (%d), error = %d\n", n, error);

    attrib2[0] = 6.;
    error      = ex_put_attr(exoidm[n], EX_ELEM_BLOCK, ebids[1], attrib2);
    printf("after ex_put_elem_attr (%d), error = %d\n", n, error);

    error = ex_put_attr(exoidm[n], EX_ELEM_BLOCK, ebids[2], attrib2);
    printf("after ex_put_elem_attr (%d), error = %d\n", n, error);

    error = ex_put_attr(exoidm[n], EX_ELEM_BLOCK, ebids[3], attrib2);
    printf("after ex_put_elem_attr (%d), error = %d\n", n, error);

    error = ex_put_attr(exoidm[n], EX_ELEM_BLOCK, ebids[4], attrib2);
    printf("after ex_put_elem_attr (%d), error = %d\n", n, error);
  }

#ifdef EX_TEST_INDIV_NODESET
  /* write individual node sets */

  error = ex_put_set_param(exoid, EX_NODE_SET, 20, 5, 5);
  printf("after ex_put_node_set_param, error = %d\n", error);

  node_list[0] = 10;
  node_list[1] = 11;
  node_list[2] = 12;
  node_list[3] = 13;
  node_list[4] = 14;

  dist_fact[0] = 1.0;
  dist_fact[1] = 2.0;
  dist_fact[2] = 3.0;
  dist_fact[3] = 4.0;
  dist_fact[4] = 5.0;

  error = ex_put_set(exoid, EX_NODE_SET, 20, node_list, NULL);
  printf("after ex_put_node_set, error = %d\n", error);
  error = ex_put_set_dist_fact(exoid, EX_NODE_SET, 20, dist_fact);
  printf("after ex_put_node_set, error = %d\n", error);

  error = ex_put_set_param(exoid, EX_NODE_SET, 21, 3, 3);
  printf("after ex_put_node_set_param, error = %d\n", error);

  node_list[0] = 20;
  node_list[1] = 21;
  node_list[2] = 22;

  dist_fact[0] = 1.1;
  dist_fact[1] = 2.1;
  dist_fact[2] = 3.1;

  error = ex_put_set(exoid, EX_NODE_SET, 21, node_list, NULL);
  printf("after ex_put_node_set, error = %d\n", error);
  error = ex_put_set_dist_fact(exoid, EX_NODE_SET, 21, dist_fact);
  printf("after ex_put_node_set, error = %d\n", error);

  error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
  printf("after ex_put_prop, error = %d\n", error);

  prop_array[0] = 1000;
  prop_array[1] = 2000;

  error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
  printf("after ex_put_prop_array, error = %d\n", error);

  /* file 2 */
  for (n = 0; n < nexofiles; n++) {
    error = ex_put_set_param(exoidm[n], EX_NODE_SET, 20, 5, 5);
    printf("after ex_put_node_set_param (%d), error = %d\n", n, error);

    node_list2[0] = 10;
    node_list2[1] = 11;
    node_list2[2] = 12;
    node_list2[3] = 13;
    node_list2[4] = 14;

    dist_fact2[0] = 1.0;
    dist_fact2[1] = 2.0;
    dist_fact2[2] = 3.0;
    dist_fact2[3] = 4.0;
    dist_fact2[4] = 5.0;

    error = ex_put_set(exoidm[n], EX_NODE_SET, 20, node_list2, NULL);
    printf("after ex_put_node_set (%d), error = %d\n", n, error);
    error = ex_put_set_dist_fact(exoidm[n], EX_NODE_SET, 20, dist_fact2);
    printf("after ex_put_node_set (%d), error = %d\n", n, error);

    error = ex_put_set_param(exoidm[n], EX_NODE_SET, 21, 3, 3);
    printf("after ex_put_node_set_param (%d), error = %d\n", n, error);

    node_list2[0] = 20;
    node_list2[1] = 21;
    node_list2[2] = 22;

    dist_fact2[0] = 1.1;
    dist_fact2[1] = 2.1;
    dist_fact2[2] = 3.1;

    error = ex_put_set(exoidm[n], EX_NODE_SET, 21, node_list2, NULL);
    printf("after ex_put_node_set (%d), error = %d\n", n, error);
    error = ex_put_set_dist_fact(exoidm[n], EX_NODE_SET, 21, dist_fact2);
    printf("after ex_put_node_set (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_NODE_SET, 20, "FACE", 4);
    printf("after ex_put_prop (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_NODE_SET, 21, "FACE", 5);
    printf("after ex_put_prop (%d), error = %d\n", n, error);

    prop_array[0] = 1000;
    prop_array[1] = 2000;

    error = ex_put_prop_array(exoidm[n], EX_NODE_SET, "VELOCITY", prop_array);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
  }

#else /* EX_TEST_INDIV_NODESET */
  /* write concatenated node sets; this produces the same information as
   * the above code which writes individual node sets
   */

  ids[0] = 20;
  ids[1] = 21;

  num_nodes_per_set[0] = 5;
  num_nodes_per_set[1] = 3;

  node_ind[0] = 0;
  node_ind[1] = 5;

  node_list[0] = 10;
  node_list[1] = 11;
  node_list[2] = 12;
  node_list[3] = 13;
  node_list[4] = 14;
  node_list[5] = 20;
  node_list[6] = 21;
  node_list[7] = 22;

  num_df_per_set[0] = 5;
  num_df_per_set[1] = 3;

  df_ind[0] = 0;
  df_ind[1] = 5;

  dist_fact[0] = 1.0;
  dist_fact[1] = 2.0;
  dist_fact[2] = 3.0;
  dist_fact[3] = 4.0;
  dist_fact[4] = 5.0;
  dist_fact[5] = 1.1;
  dist_fact[6] = 2.1;
  dist_fact[7] = 3.1;

  error = ex_put_concat_node_sets(exoid, ids, num_nodes_per_set, node_ind, node_list, dist_fact);
  printf("after ex_put_concat_node_sets, error = %d\n", error);

  error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
  printf("after ex_put_prop, error = %d\n", error);

  prop_array[0] = 1000;
  prop_array[1] = 2000;

  error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
  printf("after ex_put_prop_array, error = %d\n", error);

  ids2[0] = 20;
  ids2[1] = 21;

  num_nodes_per_set2[0] = 5;
  num_nodes_per_set2[1] = 3;

  node_ind2[0] = 0;
  node_ind2[1] = 5;

  node_list2[0] = 10;
  node_list2[1] = 11;
  node_list2[2] = 12;
  node_list2[3] = 13;
  node_list2[4] = 14;
  node_list2[5] = 20;
  node_list2[6] = 21;
  node_list2[7] = 22;

  num_df_per_set2[0] = 5;
  num_df_per_set2[1] = 3;

  df_ind2[0] = 0;
  df_ind2[1] = 5;

  dist_fact2[0] = 1.0;
  dist_fact2[1] = 2.0;
  dist_fact2[2] = 3.0;
  dist_fact2[3] = 4.0;
  dist_fact2[4] = 5.0;
  dist_fact2[5] = 1.1;
  dist_fact2[6] = 2.1;
  dist_fact2[7] = 3.1;

  prop_array2[0] = 1000;
  prop_array2[1] = 2000;

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_concat_node_sets(exoidm[n], ids2, num_nodes_per_set2, num_df_per_set2, node_ind2,
                                    df_ind2, node_list2, dist_fact2);
    printf("after ex_put_concat_node_sets, error = %d\n", error);

    error = ex_put_prop(exoidm[n], EX_NODE_SET, 20, "FACE", 4);
    printf("after ex_put_prop, error = %d\n", error);
    error = ex_put_prop(exoidm[n], EX_NODE_SET, 21, "FACE", 5);
    printf("after ex_put_prop, error = %d\n", error);

    error = ex_put_prop_array(exoidm[n], EX_NODE_SET, "VELOCITY", prop_array2);
    printf("after ex_put_prop_array, error = %d\n", error);
  }

#endif /* EX_TEST_INDIV_NODESET */

#ifdef TEST_INDIV_SIDESET
  /* write individual side sets */

  /* side set #1  - quad */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 30, 2, 4);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 2;
  elem_list[1] = 2;

  side_list[0] = 4;
  side_list[1] = 2;

  dist_fact[0] = 30.0;
  dist_fact[1] = 30.1;
  dist_fact[2] = 30.2;
  dist_fact[3] = 30.3;

  error = ex_put_set(exoid, EX_SIDE_SET, 30, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  error = ex_put_set_dist_fact(exoid, EX_SIDE_SET, 30, dist_fact);
  printf("after ex_put_side_set_dist_fact, error = %d\n", error);

  /* side set #2  - quad  spanning elements */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 31, 2, 4);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 1;
  elem_list[1] = 2;

  side_list[0] = 2;
  side_list[1] = 3;

  dist_fact[0] = 31.0;
  dist_fact[1] = 31.1;
  dist_fact[2] = 31.2;
  dist_fact[3] = 31.3;

  error = ex_put_set(exoid, EX_SIDE_SET, 31, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  error = ex_put_set_dist_fact(exoid, EX_SIDE_SET, 31, dist_fact);
  printf("after ex_put_side_set_dist_fact, error = %d\n", error);

  /* side set #3  - hex */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 32, 7, 0);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 3;
  elem_list[1] = 3;
  elem_list[2] = 3;
  elem_list[3] = 3;
  elem_list[4] = 3;
  elem_list[5] = 3;
  elem_list[6] = 3;

  side_list[0] = 5;
  side_list[1] = 3;
  side_list[2] = 3;
  side_list[3] = 2;
  side_list[4] = 4;
  side_list[5] = 1;
  side_list[6] = 6;

  error = ex_put_set(exoid, EX_SIDE_SET, 32, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  /* side set #4  - tetras */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 33, 4, 0);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 4;
  elem_list[1] = 4;
  elem_list[2] = 4;
  elem_list[3] = 4;

  side_list[0] = 1;
  side_list[1] = 2;
  side_list[2] = 3;
  side_list[3] = 4;

  error = ex_put_set(exoid, EX_SIDE_SET, 33, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  /* side set #5  - wedges */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 34, 5, 0);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 5;
  elem_list[1] = 5;
  elem_list[2] = 5;
  elem_list[3] = 5;
  elem_list[4] = 5;

  side_list[0] = 1;
  side_list[1] = 2;
  side_list[2] = 3;
  side_list[3] = 4;
  side_list[4] = 5;

  error = ex_put_set(exoid, EX_SIDE_SET, 34, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
  printf("after ex_put_prop, error = %d\n", error);

  /* file 2 */

  for (n = 0; n < nexofiles; n++) {
    /* side set 1 */

    error = ex_put_set_param(exoidm[n], EX_SIDE_SET, 30, 2, 4);
    printf("after ex_put_side_set_param (%d), error = %d\n", n, error);

    elem_list2[0] = 2;
    elem_list2[1] = 2;

    side_list2[0] = 4;
    side_list2[1] = 2;

    dist_fact2[0] = 30.0;
    dist_fact2[1] = 30.1;
    dist_fact2[2] = 30.2;
    dist_fact2[3] = 30.3;

    error = ex_put_set(exoidm[n], EX_SIDE_SET, 30, elem_list2, side_list2);
    printf("after ex_put_side_set (%d), error = %d\n", n, error);

    error = ex_put_set_dist_fact(exoidm[n], EX_SIDE_SET, 30, dist_fact2);
    printf("after ex_put_side_set_dist_fact (%d), error = %d\n", n, error);

    /* side set 2 */

    error = ex_put_set_param(exoidm[n], EX_SIDE_SET, 31, 2, 4);
    printf("after ex_put_side_set_param (%d), error = %d\n", n, error);

    elem_list2[0] = 1;
    elem_list2[1] = 2;

    side_list2[0] = 2;
    side_list2[1] = 3;

    dist_fact2[0] = 31.0;
    dist_fact2[1] = 31.1;
    dist_fact2[2] = 31.2;
    dist_fact2[3] = 31.3;

    error = ex_put_set(exoidm[n], EX_SIDE_SET, 31, elem_list2, side_list2);
    printf("after ex_put_side_set (%d), error = %d\n", n, error);

    error = ex_put_set_dist_fact(exoidm[n], EX_SIDE_SET, 31, dist_fact2);
    printf("after ex_put_side_set_dist_fact (%d), error = %d\n", n, error);

    /* side set #3  - hex */

    error = ex_put_set_param(exoidm[n], EX_SIDE_SET, 32, 7, 0);
    printf("after ex_put_side_set_param (%d), error = %d\n", n, error);

    elem_list2[0] = 3;
    elem_list2[1] = 3;
    elem_list2[2] = 3;
    elem_list2[3] = 3;
    elem_list2[4] = 3;
    elem_list2[5] = 3;
    elem_list2[6] = 3;

    side_list2[0] = 5;
    side_list2[1] = 3;
    side_list2[2] = 3;
    side_list2[3] = 2;
    side_list2[4] = 4;
    side_list2[5] = 1;
    side_list2[6] = 6;

    error = ex_put_set(exoidm[n], EX_SIDE_SET, 32, elem_list2, side_list2);
    printf("after ex_put_side_set (%d), error = %d\n", n, error);

    /* side set #4  - tetras */

    error = ex_put_set_param(exoidm[n], EX_SIDE_SET, 33, 4, 0);
    printf("after ex_put_side_set_param (%d), error = %d\n", n, error);

    elem_list2[0] = 4;
    elem_list2[1] = 4;
    elem_list2[2] = 4;
    elem_list2[3] = 4;

    side_list2[0] = 1;
    side_list2[1] = 2;
    side_list2[2] = 3;
    side_list2[3] = 4;

    error = ex_put_set(exoidm[n], EX_SIDE_SET, 33, elem_list2, side_list2);
    printf("after ex_put_side_set (%d), error = %d\n", n, error);

    /* side set #5  - wedges */

    error = ex_put_set_param(exoidm[n], EX_SIDE_SET, 34, 5, 0);
    printf("after ex_put_side_set_param (%d), error = %d\n", n, error);

    elem_list2[0] = 5;
    elem_list2[1] = 5;
    elem_list2[2] = 5;
    elem_list2[3] = 5;
    elem_list2[4] = 5;

    side_list2[0] = 1;
    side_list2[1] = 2;
    side_list2[2] = 3;
    side_list2[3] = 4;
    side_list2[4] = 5;

    error = ex_put_set(exoidm[n], EX_SIDE_SET, 34, elem_list2, side_list2);
    printf("after ex_put_side_set (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_SIDE_SET, 30, "COLOR", 100);
    printf("after ex_put_prop (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_SIDE_SET, 31, "COLOR", 101);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
  }

#else /* TEST_INDIV_SIDESET */
  /* write concatenated side sets; this produces the same information as
   * the above code which writes individual side sets
   */

  ids[0] = 30;
  ids[1] = 31;
  ids[2] = 32;
  ids[3] = 33;
  ids[4] = 34;

  node_list[0] = 8;
  node_list[1] = 5;
  node_list[2] = 6;
  node_list[3] = 7;

  node_list[4] = 2;
  node_list[5] = 3;
  node_list[6] = 7;
  node_list[7] = 8;

  node_list[8]  = 9;
  node_list[9]  = 12;
  node_list[10] = 11;
  node_list[11] = 10;

  node_list[12] = 11;
  node_list[13] = 12;
  node_list[14] = 16;
  node_list[15] = 15;

  node_list[16] = 16;
  node_list[17] = 15;
  node_list[18] = 11;
  node_list[19] = 12;

  node_list[20] = 10;
  node_list[21] = 11;
  node_list[22] = 15;
  node_list[23] = 14;

  node_list[24] = 13;
  node_list[25] = 16;
  node_list[26] = 12;
  node_list[27] = 9;

  node_list[28] = 14;
  node_list[29] = 13;
  node_list[30] = 9;
  node_list[31] = 10;

  node_list[32] = 16;
  node_list[33] = 13;
  node_list[34] = 14;
  node_list[35] = 15;

  node_list[36] = 17;
  node_list[37] = 18;
  node_list[38] = 20;

  node_list[39] = 18;
  node_list[40] = 19;
  node_list[41] = 20;

  node_list[42] = 20;
  node_list[43] = 19;
  node_list[44] = 17;

  node_list[45] = 19;
  node_list[46] = 18;
  node_list[47] = 17;

  node_list[48] = 25;
  node_list[49] = 24;
  node_list[50] = 21;
  node_list[51] = 22;

  node_list[52] = 26;
  node_list[53] = 25;
  node_list[54] = 22;
  node_list[55] = 23;

  node_list[56] = 26;
  node_list[57] = 23;
  node_list[58] = 21;
  node_list[59] = 24;

  node_list[60] = 23;
  node_list[61] = 22;
  node_list[62] = 21;

  node_list[63] = 24;
  node_list[64] = 25;
  node_list[65] = 26;

  node_ind[0] = 0;
  node_ind[1] = 4;
  node_ind[2] = 8;
  node_ind[3] = 36;
  node_ind[4] = 47;

  num_elem_per_set[0] = 2;
  num_elem_per_set[1] = 2;
  num_elem_per_set[2] = 7;
  num_elem_per_set[3] = 4;
  num_elem_per_set[4] = 5;

  num_nodes_per_set[0] = 4;
  num_nodes_per_set[1] = 4;
  num_nodes_per_set[2] = 28;
  num_nodes_per_set[3] = 12;
  num_nodes_per_set[4] = 18;

  elem_ind[0] = 0;
  elem_ind[1] = 2;
  elem_ind[2] = 4;
  elem_ind[3] = 11;
  elem_ind[4] = 15;

  elem_list[0]  = 2;
  elem_list[1]  = 2;
  elem_list[2]  = 1;
  elem_list[3]  = 2;
  elem_list[4]  = 3;
  elem_list[5]  = 3;
  elem_list[6]  = 3;
  elem_list[7]  = 3;
  elem_list[8]  = 3;
  elem_list[9]  = 3;
  elem_list[10] = 3;
  elem_list[11] = 4;
  elem_list[12] = 4;
  elem_list[13] = 4;
  elem_list[14] = 4;
  elem_list[15] = 5;
  elem_list[16] = 5;
  elem_list[17] = 5;
  elem_list[18] = 5;
  elem_list[19] = 5;

  error = ex_cvt_nodes_to_sides(exoid, num_elem_per_set, num_nodes_per_set, elem_ind, node_ind,
                                elem_list, node_list, side_list);
  printf("after ex_cvt_nodes_to_sides, error = %d\n", error);

  num_df_per_set[0] = 4;
  num_df_per_set[1] = 4;
  num_df_per_set[2] = 0;
  num_df_per_set[3] = 0;
  num_df_per_set[4] = 0;

  df_ind[0] = 0;
  df_ind[1] = 4;

  dist_fact[0] = 30.0;
  dist_fact[1] = 30.1;
  dist_fact[2] = 30.2;
  dist_fact[3] = 30.3;

  dist_fact[4] = 31.0;
  dist_fact[5] = 31.1;
  dist_fact[6] = 31.2;
  dist_fact[7] = 31.3;

  {
    struct ex_set_specs set_specs;

    set_specs.sets_ids            = ids;
    set_specs.num_entries_per_set = num_elem_per_set;
    set_specs.num_dist_per_set    = num_df_per_set;
    set_specs.sets_entry_index    = elem_ind;
    set_specs.sets_dist_index     = df_ind;
    set_specs.sets_entry_list     = elem_list;
    set_specs.sets_extra_list     = side_list;
    set_specs.sets_dist_fact      = dist_fact;
    error                         = ex_put_concat_sets(exoid, EX_SIDE_SET, &set_specs);
  }

  printf("after ex_put_concat_side_sets, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
  printf("after ex_put_prop, error = %d\n", error);

  /* file 2 */

  ids2[0] = 30;
  ids2[1] = 31;
  ids2[2] = 32;
  ids2[3] = 33;
  ids2[4] = 34;

  node_list2[0] = 8;
  node_list2[1] = 5;
  node_list2[2] = 6;
  node_list2[3] = 7;

  node_list2[4] = 2;
  node_list2[5] = 3;
  node_list2[6] = 7;
  node_list2[7] = 8;

  node_list2[8]  = 9;
  node_list2[9]  = 12;
  node_list2[10] = 11;
  node_list2[11] = 10;

  node_list2[12] = 11;
  node_list2[13] = 12;
  node_list2[14] = 16;
  node_list2[15] = 15;

  node_list2[16] = 16;
  node_list2[17] = 15;
  node_list2[18] = 11;
  node_list2[19] = 12;

  node_list2[20] = 10;
  node_list2[21] = 11;
  node_list2[22] = 15;
  node_list2[23] = 14;

  node_list2[24] = 13;
  node_list2[25] = 16;
  node_list2[26] = 12;
  node_list2[27] = 9;

  node_list2[28] = 14;
  node_list2[29] = 13;
  node_list2[30] = 9;
  node_list2[31] = 10;

  node_list2[32] = 16;
  node_list2[33] = 13;
  node_list2[34] = 14;
  node_list2[35] = 15;

  node_list2[36] = 17;
  node_list2[37] = 18;
  node_list2[38] = 20;

  node_list2[39] = 18;
  node_list2[40] = 19;
  node_list2[41] = 20;

  node_list2[42] = 20;
  node_list2[43] = 19;
  node_list2[44] = 17;

  node_list2[45] = 19;
  node_list2[46] = 18;
  node_list2[47] = 17;

  node_list2[48] = 25;
  node_list2[49] = 24;
  node_list2[50] = 21;
  node_list2[51] = 22;

  node_list2[52] = 26;
  node_list2[53] = 25;
  node_list2[54] = 22;
  node_list2[55] = 23;

  node_list2[56] = 26;
  node_list2[57] = 23;
  node_list2[58] = 21;
  node_list2[59] = 24;

  node_list2[60] = 23;
  node_list2[61] = 22;
  node_list2[62] = 21;

  node_list2[63] = 24;
  node_list2[64] = 25;
  node_list2[65] = 26;

  node_ind2[0] = 0;
  node_ind2[1] = 4;
  node_ind2[2] = 8;
  node_ind2[3] = 36;
  node_ind2[4] = 47;

  num_elem_per_set2[0] = 2;
  num_elem_per_set2[1] = 2;
  num_elem_per_set2[2] = 7;
  num_elem_per_set2[3] = 4;
  num_elem_per_set2[4] = 5;

  num_nodes_per_set2[0] = 4;
  num_nodes_per_set2[1] = 4;
  num_nodes_per_set2[2] = 28;
  num_nodes_per_set2[3] = 12;
  num_nodes_per_set2[4] = 18;

  elem_ind2[0] = 0;
  elem_ind2[1] = 2;
  elem_ind2[2] = 4;
  elem_ind2[3] = 11;
  elem_ind2[4] = 15;

  elem_list2[0]  = 2;
  elem_list2[1]  = 2;
  elem_list2[2]  = 1;
  elem_list2[3]  = 2;
  elem_list2[4]  = 3;
  elem_list2[5]  = 3;
  elem_list2[6]  = 3;
  elem_list2[7]  = 3;
  elem_list2[8]  = 3;
  elem_list2[9]  = 3;
  elem_list2[10] = 3;
  elem_list2[11] = 4;
  elem_list2[12] = 4;
  elem_list2[13] = 4;
  elem_list2[14] = 4;
  elem_list2[15] = 5;
  elem_list2[16] = 5;
  elem_list2[17] = 5;
  elem_list2[18] = 5;
  elem_list2[19] = 5;

  num_df_per_set2[0] = 4;
  num_df_per_set2[1] = 4;
  num_df_per_set2[2] = 0;
  num_df_per_set2[3] = 0;
  num_df_per_set2[4] = 0;

  df_ind2[0] = 0;
  df_ind2[1] = 4;

  dist_fact2[0] = 30.0;
  dist_fact2[1] = 30.1;
  dist_fact2[2] = 30.2;
  dist_fact2[3] = 30.3;

  dist_fact2[4] = 31.0;
  dist_fact2[5] = 31.1;
  dist_fact2[6] = 31.2;
  dist_fact2[7] = 31.3;

  for (n = 0; n < nexofiles; n++) {
    error = ex_cvt_nodes_to_sides(exoidm[n], num_elem_per_set2, num_nodes_per_set2, elem_ind2,
                                  node_ind2, elem_list2, node_list2, side_list2);
    printf("after ex_cvt_nodes_to_sides (%d), error = %d\n", n, error);

    {
      struct ex_set_specs set_specs;

      set_specs.sets_ids            = ids2;
      set_specs.num_entries_per_set = num_elem_per_set2;
      set_specs.num_dist_per_set    = num_df_per_set2;
      set_specs.sets_entry_index    = elem_ind2;
      set_specs.sets_dist_index     = df_ind2;
      set_specs.sets_entry_list     = elem_list2;
      set_specs.sets_extra_list     = side_list2;
      set_specs.sets_dist_fact      = dist_fact2;
      error                         = ex_put_concat_sets(exoid, EX_SIDE_SET, &set_specs);
    }
    printf("after ex_put_concat_side_sets (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_SIDE_SET, 30, "COLOR", 100);
    printf("after ex_put_prop (%d), error = %d\n", n, error);

    error = ex_put_prop(exoidm[n], EX_SIDE_SET, 31, "COLOR", 101);
    printf("after ex_put_prop (%d), error = %d\n", n, error);
  }

/* END COMMENTED OUT SECTION */

#endif /* TEST_INDIV_SIDESET */

  /* write QA records */

  num_qa_rec = 2;

  qa_record[0][0] = "TESTWTM";
  qa_record[0][1] = "testwtm";
  qa_record[0][2] = "07/07/93";
  qa_record[0][3] = "15:41:33";
  qa_record[1][0] = "FASTQ";
  qa_record[1][1] = "fastq";
  qa_record[1][2] = "07/07/93";
  qa_record[1][3] = "16:41:33";

  error = ex_put_qa(exoid, num_qa_rec, qa_record);
  printf("after ex_put_qa, error = %d\n", error);

  num_qa_rec2 = 2;

  qa_record2[0][0] = "TESTWTM";
  qa_record2[0][1] = "testwtm";
  qa_record2[0][2] = "07/07/93";
  qa_record2[0][3] = "15:41:33";
  qa_record2[1][0] = "FASTQ";
  qa_record2[1][1] = "fastq";
  qa_record2[1][2] = "07/07/93";
  qa_record2[1][3] = "16:41:33";

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_qa(exoidm[n], num_qa_rec2, qa_record2);
    printf("after ex_put_qa (%d), error = %d\n", n, error);
  }

  /* write information records */

  num_info = 3;

  info[0] = "This is the first information record.";
  info[1] = "This is the second information record.";
  info[2] = "This is the third information record.";

  error = ex_put_info(exoid, num_info, info);
  printf("after ex_put_info, error = %d\n", error);

  num_info2 = 3;

  info2[0] = "This is the first information record.";
  info2[1] = "This is the second information record.";
  info2[2] = "This is the third information record.";

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_info(exoidm[n], num_info2, info2);
    printf("after ex_put_info (%d), error = %d\n", n, error);
  }

  /* write results variables parameters and names */

  num_glo_vars = 1;

  var_names[0] = "glo_vars";

  error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_glo_vars2 = 1;

  var_names2[0] = "glo_vars";

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_variable_param(exoidm[n], EX_GLOBAL, num_glo_vars2);
    printf("after ex_put_variable_param (%d), error = %d\n", n, error);
    error = ex_put_variable_names(exoidm[n], EX_GLOBAL, num_glo_vars2, var_names2);
    printf("after ex_put_variable_names (%d), error = %d\n", n, error);
  }

  num_nod_vars = 2;

  var_names[0] = "nod_var0";
  var_names[1] = "nod_var1";

  error = ex_put_variable_param(exoid, EX_NODAL, num_nod_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_nod_vars2 = 2;

  var_names2[0] = "nod_var0";
  var_names2[1] = "nod_var1";

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_variable_param(exoidm[n], EX_NODAL, num_nod_vars2);
    printf("after ex_put_variable_param (%d), error = %d\n", n, error);
    error = ex_put_variable_names(exoidm[n], EX_NODAL, num_nod_vars2, var_names2);
    printf("after ex_put_variable_names (%d), error = %d\n", n, error);
  }

  num_ele_vars = 3;

  var_names[0] = "ele_var0";
  var_names[1] = "ele_var1";
  var_names[2] = "ele_var2";

  error = ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_ele_vars2 = 3;

  var_names2[0] = "ele_var20";
  var_names2[1] = "ele_var21";
  var_names2[2] = "ele_var22";

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_variable_param(exoidm[n], EX_ELEM_BLOCK, num_ele_vars2);
    printf("after ex_put_variable_param (%d), error = %d\n", n, error);
    error = ex_put_variable_names(exoidm[n], EX_ELEM_BLOCK, num_ele_vars, var_names);
    printf("after ex_put_variable_names (%d), error = %d\n", n, error);
  }

  /* write element variable truth table */

  truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int));

  k = 0;
  for (i = 0; i < num_elem_blk; i++) {
    for (j = 0; j < num_ele_vars; j++) {
      truth_tab[k++] = 1;
    }
  }

  error = ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab);
  printf("after ex_put_elem_var_tab, error = %d\n", error);

  for (n = 0; n < nexofiles; n++) {
    error = ex_put_truth_table(exoidm[n], EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab);
    printf("after ex_put_elem_var_tab (%d), error = %d\n", n, error);
  }

  free(truth_tab);

  /* for each time step, write the analysis results;
   * the code below fills the arrays  glob_var_vals,
   * nodal_var_vals, and elem_var_vals with values for debugging purposes;
   * obviously the analysis code will populate these arrays
   */

  whole_time_step = 1;
  num_time_steps  = 10;

  glob_var_vals  = (float *)calloc(num_glo_vars, sizeof(float));
  nodal_var_vals = (float *)calloc(num_nodes, sizeof(float));
  elem_var_vals  = (float *)calloc(4, sizeof(float));

  for (i = 0; i < num_time_steps; i++) {
    time_value  = (float)(i + 1) / 100.;
    time_value2 = (float)(i + 1) / 100.;

    /* write time value */

    error = ex_put_time(exoid, whole_time_step, &time_value);
    printf("after ex_put_time, error = %d\n", error);

    for (n = 0; n < nexofiles; n++) {
      error = ex_put_time(exoidm[n], whole_time_step, &time_value2);
      printf("after ex_put_time (%d), error = %d\n", n, error);
    }

    /* write global variables */

    for (j = 0; j < num_glo_vars; j++) {
      glob_var_vals[j] = (float)(j + 2) * time_value;
    }

    error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
    printf("after ex_put_glob_vars, error = %d\n", error);

    for (n = 0; n < nexofiles; n++) {
      error = ex_put_var(exoidm[n], whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
      printf("after ex_put_glob_vars (%d), error = %d\n", n, error);
    }
    /* write nodal variables */

    for (k = 1; k <= num_nod_vars; k++) {
      for (j = 0; j < num_nodes; j++) {
        nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value);
      }

      error = ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals);
      printf("after ex_put_nodal_var, error = %d\n", error);

      for (n = 0; n < nexofiles; n++) {
        error = ex_put_var(exoidm[n], whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals);
        printf("after ex_put_nodal_var (%d), error = %d\n", n, error);
      }
    }

    /* write element variables */

    for (k = 1; k <= num_ele_vars; k++) {
      for (j = 0; j < num_elem_blk; j++) {
        for (m = 0; m < num_elem_in_block[j]; m++) {
          elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value);
          /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
        }
        error = ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j],
                           elem_var_vals);
        printf("after ex_put_elem_var, error = %d\n", error);

        for (n = 0; n < nexofiles; n++) {
          error = ex_put_var(exoidm[n], whole_time_step, EX_ELEM_BLOCK, k, ebids[j],
                             num_elem_in_block[j], elem_var_vals);
          printf("after ex_put_elem_var (%d), error = %d\n", n, error);
        }
      }
    }

    whole_time_step++;

    /* update the data file; this should be done at the end of every time step
     * to ensure that no data is lost if the analysis dies
     */
    error = ex_update(exoid);
    printf("after ex_update, error = %d\n", error);
    for (n = 0; n < nexofiles; n++) {
      error = ex_update(exoidm[n]);
      printf("after ex_update (%d), error = %d\n", n, error);
    }
  }
  free(glob_var_vals);
  free(nodal_var_vals);
  free(elem_var_vals);

  /* close the EXODUS files
   */
  error = ex_close(exoid);
  printf("after ex_close, error = %d\n", error);
  for (n = 0; n < nexofiles; n++) {
    error = ex_close(exoidm[n]);
    printf("after ex_close (%d), error = %d\n", n, error);
  }
  return 0;
}
示例#16
0
int main(int argc, char **argv)
{
  int  exoid, num_dim, num_nodes, num_elem, num_elem_blk;
  int  exoid2, num_dim2, num_nodes2, num_elem2, num_elem_blk2;
  int  num_elem_in_block[10], num_node_sets, num_nodes_per_elem[10];
  int  num_elem_in_block2[10], num_node_sets2, num_nodes_per_elem2[10];
  int  num_side_sets, error;
  int  num_side_sets2;
  int  i, j, k, m;
  int *elem_map, *connect, node_list[100], elem_list[100], side_list[100];
  int *elem_map2, *connect2, node_list2[100], elem_list2[100], side_list2[100];
  int  ebids[10];
  int  ebids2[10];
  int  num_qa_rec, num_info;
  int  num_qa_rec2, num_info2;
  int  num_glo_vars, num_nod_vars, num_ele_vars;
  int  num_glo_vars2, num_nod_vars2, num_ele_vars2;
  int *truth_tab;
  int  whole_time_step, num_time_steps;
  int  CPU_word_size, IO_word_size;
  int  prop_array[2];

  float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
  float  time_value;
  float  time_value2;
  float  x[100], y[100], z[100];
  float  attrib[1], dist_fact[100];
  float  attrib2[1], dist_fact2[100];
  char * coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
  char * coord_names2[3], *qa_record2[2][4], *info2[3], *var_names2[3];
  char * prop_names[2];

  ex_opts(EX_VERBOSE | EX_ABORT);

  /* Specify compute and i/o word size */

  CPU_word_size = 0; /* sizeof(float) */
  IO_word_size  = 4; /* (4 bytes) */

  /* create EXODUS II files (a "regular" and a "history") */

  exoid = ex_create("test.exo",     /* filename path */
                    EX_CLOBBER,     /* create mode */
                    &CPU_word_size, /* CPU float word size in bytes */
                    &IO_word_size); /* I/O float word size in bytes */
  printf("after ex_create for test.exo, exoid = %d\n", exoid);
  printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);

  exoid2 = ex_create("test2.exo",    /* filename path */
                     EX_CLOBBER,     /* create mode */
                     &CPU_word_size, /* CPU float word size in bytes */
                     &IO_word_size); /* I/O float word size in bytes */
  printf("after ex_create for test2.exo, exoid = %d\n", exoid2);

  /* initialize file with parameters */

  num_dim       = 3;
  num_nodes     = 26;
  num_elem      = 5;
  num_elem_blk  = 5;
  num_node_sets = 2;
  num_side_sets = 5;

  error = ex_put_init(exoid, "This is a test", num_dim, num_nodes, num_elem, num_elem_blk,
                      num_node_sets, num_side_sets);

  printf("after ex_put_init, error = %d\n", error);

  /* initialize file 2 with parameters */

  num_dim2       = 3;
  num_nodes2     = 26;
  num_elem2      = 5;
  num_elem_blk2  = 5;
  num_node_sets2 = 2;
  num_side_sets2 = 5;

  error = ex_put_init(exoid2, "This is test 2", num_dim2, num_nodes2, num_elem2, num_elem_blk2,
                      num_node_sets2, num_side_sets2);

  printf("after ex_put_init (2), error = %d\n", error);

  /* write nodal coordinates values and names to database */

  /* Quad #1 */
  x[0] = 0.0;
  y[0] = 0.0;
  z[0] = 0.0;
  x[1] = 1.0;
  y[1] = 0.0;
  z[1] = 0.0;
  x[2] = 1.0;
  y[2] = 1.0;
  z[2] = 0.0;
  x[3] = 0.0;
  y[3] = 1.0;
  z[3] = 0.0;

  /* Quad #2 */
  x[4] = 1.0;
  y[4] = 0.0;
  z[4] = 0.0;
  x[5] = 2.0;
  y[5] = 0.0;
  z[5] = 0.0;
  x[6] = 2.0;
  y[6] = 1.0;
  z[6] = 0.0;
  x[7] = 1.0;
  y[7] = 1.0;
  z[7] = 0.0;

  /* Hex #1 */
  x[8]  = 0.0;
  y[8]  = 0.0;
  z[8]  = 0.0;
  x[9]  = 10.0;
  y[9]  = 0.0;
  z[9]  = 0.0;
  x[10] = 10.0;
  y[10] = 0.0;
  z[10] = -10.0;
  x[11] = 1.0;
  y[11] = 0.0;
  z[11] = -10.0;
  x[12] = 1.0;
  y[12] = 10.0;
  z[12] = 0.0;
  x[13] = 10.0;
  y[13] = 10.0;
  z[13] = 0.0;
  x[14] = 10.0;
  y[14] = 10.0;
  z[14] = -10.0;
  x[15] = 1.0;
  y[15] = 10.0;
  z[15] = -10.0;

  /* Tetra #1 */
  x[16] = 0.0;
  y[16] = 0.0;
  z[16] = 0.0;
  x[17] = 1.0;
  y[17] = 0.0;
  z[17] = 5.0;
  x[18] = 10.0;
  y[18] = 0.0;
  z[18] = 2.0;
  x[19] = 7.0;
  y[19] = 5.0;
  z[19] = 3.0;

  /* Wedge #1 */
  x[20] = 3.0;
  y[20] = 0.0;
  z[20] = 6.0;
  x[21] = 6.0;
  y[21] = 0.0;
  z[21] = 0.0;
  x[22] = 0.0;
  y[22] = 0.0;
  z[22] = 0.0;
  x[23] = 3.0;
  y[23] = 2.0;
  z[23] = 6.0;
  x[24] = 6.0;
  y[24] = 2.0;
  z[24] = 2.0;
  x[25] = 0.0;
  y[25] = 2.0;
  z[25] = 0.0;

  error = ex_put_coord(exoid, x, y, z);
  printf("after ex_put_coord, error = %d\n", error);

  /* write nodal coordinates values and names to database 2 */

  error = ex_put_coord(exoid2, x, y, z);
  printf("after ex_put_coord (2), error = %d\n", error);

  coord_names[0] = "xcoor";
  coord_names[1] = "ycoor";
  coord_names[2] = "zcoor";

  error = ex_put_coord_names(exoid, coord_names);
  printf("after ex_put_coord_names, error = %d\n", error);

  coord_names2[0] = "xcoor";
  coord_names2[1] = "ycoor";
  coord_names2[2] = "zcoor";

  error = ex_put_coord_names(exoid2, coord_names2);
  printf("after ex_put_coord_names (2), error = %d\n", error);

  /* write element order map */

  elem_map = (int *)calloc(num_elem, sizeof(int));

  for (i = 1; i <= num_elem; i++) {
    elem_map[i - 1] = i;
  }

  error = ex_put_map(exoid, elem_map);
  printf("after ex_put_map, error = %d\n", error);

  free(elem_map);

  elem_map2 = (int *)calloc(num_elem2, sizeof(int));

  for (i = 1; i <= num_elem2; i++) {
    elem_map2[i - 1] = i;
  }

  error = ex_put_map(exoid2, elem_map2);
  printf("after ex_put_map (2), error = %d\n", error);

  free(elem_map2);

  /* write element block parameters */

  num_elem_in_block[0] = 1;
  num_elem_in_block[1] = 1;
  num_elem_in_block[2] = 1;
  num_elem_in_block[3] = 1;
  num_elem_in_block[4] = 1;

  num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
  num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
  num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
  num_nodes_per_elem[3] = 4; /* elements in block #3 are 4-node tetras */
  num_nodes_per_elem[4] = 6; /* elements in block #3 are 6-node wedges */

  ebids[0] = 10;
  ebids[1] = 11;
  ebids[2] = 12;
  ebids[3] = 13;
  ebids[4] = 14;

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[0], "quad", num_elem_in_block[0],
                       num_nodes_per_elem[0], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[1], "quad", num_elem_in_block[1],
                       num_nodes_per_elem[1], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[2], "hex", num_elem_in_block[2],
                       num_nodes_per_elem[2], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[3], "tetra", num_elem_in_block[3],
                       num_nodes_per_elem[3], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[4], "wedge", num_elem_in_block[4],
                       num_nodes_per_elem[4], 0, 0, 1);
  printf("after ex_put_elem_block, error = %d\n", error);

  /* write element block properties */

  prop_names[0] = "MATL";
  prop_names[1] = "DENSITY";
  error         = ex_put_prop_names(exoid, EX_ELEM_BLOCK, 2, prop_names);
  printf("after ex_put_prop_names, error = %d\n", error);

  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40);
  printf("after ex_put_prop, error = %d\n", error);
  error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50);
  printf("after ex_put_prop, error = %d\n", error);

  num_elem_in_block2[0] = 1;
  num_elem_in_block2[1] = 1;
  num_elem_in_block2[2] = 1;
  num_elem_in_block2[3] = 1;
  num_elem_in_block2[4] = 1;

  num_nodes_per_elem2[0] = 4; /* elements in block #1 are 4-node quads  */
  num_nodes_per_elem2[1] = 4; /* elements in block #2 are 4-node quads  */
  num_nodes_per_elem2[2] = 8; /* elements in block #3 are 8-node hexes  */
  num_nodes_per_elem2[3] = 4; /* elements in block #3 are 4-node tetras */
  num_nodes_per_elem2[4] = 6; /* elements in block #3 are 6-node wedges */

  ebids2[0] = 10;
  ebids2[1] = 11;
  ebids2[2] = 12;
  ebids2[3] = 13;
  ebids2[4] = 14;

  error = ex_put_block(exoid2, EX_ELEM_BLOCK, ebids2[0], "quad", num_elem_in_block2[0],
                       num_nodes_per_elem2[0], 0, 0, 1);
  printf("after ex_put_elem_block (2), error = %d\n", error);

  error = ex_put_block(exoid2, EX_ELEM_BLOCK, ebids2[1], "quad", num_elem_in_block2[1],
                       num_nodes_per_elem2[1], 0, 0, 1);
  printf("after ex_put_elem_blocki (2), error = %d\n", error);

  error = ex_put_block(exoid2, EX_ELEM_BLOCK, ebids2[2], "hex", num_elem_in_block2[2],
                       num_nodes_per_elem2[2], 0, 0, 1);
  printf("after ex_put_elem_blocki (2), error = %d\n", error);

  error = ex_put_block(exoid2, EX_ELEM_BLOCK, ebids2[3], "tetra", num_elem_in_block2[3],
                       num_nodes_per_elem2[3], 0, 0, 1);
  printf("after ex_put_elem_block (2), error = %d\n", error);

  error = ex_put_block(exoid2, EX_ELEM_BLOCK, ebids2[4], "wedge", num_elem_in_block2[4],
                       num_nodes_per_elem2[4], 0, 0, 1);
  printf("after ex_put_elem_block (2), error = %d\n", error);

  /* write element block properties for file 2 */

  prop_names[0] = "MATL";
  prop_names[1] = "DENSITY";
  error         = ex_put_prop_names(exoid2, EX_ELEM_BLOCK, 2, prop_names);
  printf("after ex_put_prop_names (2), error = %d\n", error);

  error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ebids[0], "MATL", 100);
  printf("after ex_put_prop (2), error = %d\n", error);
  error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ebids[1], "MATL", 200);
  printf("after ex_put_prop (2), error = %d\n", error);
  error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ebids[2], "MATL", 300);
  printf("after ex_put_prop (2), error = %d\n", error);
  error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ebids[3], "MATL", 400);
  printf("after ex_put_prop (2), error = %d\n", error);
  error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ebids[4], "MATL", 500);
  printf("after ex_put_prop (2), error = %d\n", error);

  /* write element connectivity */

  connect    = (int *)calloc(8, sizeof(int));
  connect[0] = 1;
  connect[1] = 2;
  connect[2] = 3;
  connect[3] = 4;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 5;
  connect[1] = 6;
  connect[2] = 7;
  connect[3] = 8;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[1], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 9;
  connect[1] = 10;
  connect[2] = 11;
  connect[3] = 12;
  connect[4] = 13;
  connect[5] = 14;
  connect[6] = 15;
  connect[7] = 16;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 17;
  connect[1] = 18;
  connect[2] = 19;
  connect[3] = 20;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[3], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  connect[0] = 21;
  connect[1] = 22;
  connect[2] = 23;
  connect[3] = 24;
  connect[4] = 25;
  connect[5] = 26;

  error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[4], connect, NULL, NULL);
  printf("after ex_put_elem_conn, error = %d\n", error);

  free(connect);

  connect2    = (int *)calloc(8, sizeof(int));
  connect2[0] = 1;
  connect2[1] = 2;
  connect2[2] = 3;
  connect2[3] = 4;

  error = ex_put_conn(exoid2, EX_ELEM_BLOCK, ebids2[0], connect2, NULL, NULL);
  printf("after ex_put_elem_conn (2), error = %d\n", error);

  connect2[0] = 5;
  connect2[1] = 6;
  connect2[2] = 7;
  connect2[3] = 8;

  error = ex_put_conn(exoid2, EX_ELEM_BLOCK, ebids2[1], connect2, NULL, NULL);
  printf("after ex_put_elem_conn (2), error = %d\n", error);

  connect2[0] = 9;
  connect2[1] = 10;
  connect2[2] = 11;
  connect2[3] = 12;
  connect2[4] = 13;
  connect2[5] = 14;
  connect2[6] = 15;
  connect2[7] = 16;

  error = ex_put_conn(exoid2, EX_ELEM_BLOCK, ebids2[2], connect2, NULL, NULL);
  printf("after ex_put_elem_conn (2), error = %d\n", error);

  connect2[0] = 17;
  connect2[1] = 18;
  connect2[2] = 19;
  connect2[3] = 20;

  error = ex_put_conn(exoid2, EX_ELEM_BLOCK, ebids2[3], connect2, NULL, NULL);
  printf("after ex_put_elem_conn (2), error = %d\n", error);

  connect2[0] = 21;
  connect2[1] = 22;
  connect2[2] = 23;
  connect2[3] = 24;
  connect2[4] = 25;
  connect2[5] = 26;

  error = ex_put_conn(exoid2, EX_ELEM_BLOCK, ebids2[4], connect2, NULL, NULL);
  printf("after ex_put_elem_conn (2), error = %d\n", error);

  free(connect2);

  /* write element block attributes */

  attrib[0] = 3.14159;
  error     = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[0], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  attrib[0] = 6.14159;
  error     = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[1], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[2], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[3], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[4], attrib);
  printf("after ex_put_elem_attr, error = %d\n", error);

  attrib2[0] = 3.;
  error      = ex_put_attr(exoid2, EX_ELEM_BLOCK, ebids2[0], attrib2);
  printf("after ex_put_elem_attr (2), error = %d\n", error);

  attrib2[0] = 6.;
  error      = ex_put_attr(exoid2, EX_ELEM_BLOCK, ebids2[1], attrib2);
  printf("after ex_put_elem_attr (2), error = %d\n", error);

  error = ex_put_attr(exoid2, EX_ELEM_BLOCK, ebids2[2], attrib2);
  printf("after ex_put_elem_attr (2), error = %d\n", error);

  error = ex_put_attr(exoid2, EX_ELEM_BLOCK, ebids2[3], attrib2);
  printf("after ex_put_elem_attr (2), error = %d\n", error);

  error = ex_put_attr(exoid2, EX_ELEM_BLOCK, ebids2[4], attrib2);
  printf("after ex_put_elem_attr (2), error = %d\n", error);

  /* write individual node sets */

  error = ex_put_set_param(exoid, EX_NODE_SET, 20, 5, 5);
  printf("after ex_put_node_set_param, error = %d\n", error);

  node_list[0] = 10;
  node_list[1] = 11;
  node_list[2] = 12;
  node_list[3] = 13;
  node_list[4] = 14;

  dist_fact[0] = 1.0;
  dist_fact[1] = 2.0;
  dist_fact[2] = 3.0;
  dist_fact[3] = 4.0;
  dist_fact[4] = 5.0;

  error = ex_put_set(exoid, EX_NODE_SET, 20, node_list, NULL);
  printf("after ex_put_node_set, error = %d\n", error);
  error = ex_put_set_dist_fact(exoid, EX_NODE_SET, 20, dist_fact);
  printf("after ex_put_node_set, error = %d\n", error);

  error = ex_put_set_param(exoid, EX_NODE_SET, 21, 3, 3);
  printf("after ex_put_node_set_param, error = %d\n", error);

  node_list[0] = 20;
  node_list[1] = 21;
  node_list[2] = 22;

  dist_fact[0] = 1.1;
  dist_fact[1] = 2.1;
  dist_fact[2] = 3.1;

  error = ex_put_set(exoid, EX_NODE_SET, 21, node_list, NULL);
  printf("after ex_put_node_set, error = %d\n", error);
  error = ex_put_set_dist_fact(exoid, EX_NODE_SET, 21, dist_fact);
  printf("after ex_put_node_set, error = %d\n", error);

  error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
  printf("after ex_put_prop, error = %d\n", error);

  prop_array[0] = 1000;
  prop_array[1] = 2000;

  error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
  printf("after ex_put_prop_array, error = %d\n", error);

  /* file 2 */
  error = ex_put_set_param(exoid2, EX_NODE_SET, 20, 5, 5);
  printf("after ex_put_node_set_param (2), error = %d\n", error);

  node_list2[0] = 10;
  node_list2[1] = 11;
  node_list2[2] = 12;
  node_list2[3] = 13;
  node_list2[4] = 14;

  dist_fact2[0] = 1.0;
  dist_fact2[1] = 2.0;
  dist_fact2[2] = 3.0;
  dist_fact2[3] = 4.0;
  dist_fact2[4] = 5.0;

  error = ex_put_set(exoid2, EX_NODE_SET, 20, node_list2, NULL);
  printf("after ex_put_node_set (2), error = %d\n", error);
  error = ex_put_set_dist_fact(exoid2, EX_NODE_SET, 20, dist_fact2);
  printf("after ex_put_node_set (2), error = %d\n", error);

  error = ex_put_set_param(exoid2, EX_NODE_SET, 21, 3, 3);
  printf("after ex_put_node_set_param (2), error = %d\n", error);

  node_list2[0] = 20;
  node_list2[1] = 21;
  node_list2[2] = 22;

  dist_fact2[0] = 1.1;
  dist_fact2[1] = 2.1;
  dist_fact2[2] = 3.1;

  error = ex_put_set(exoid2, EX_NODE_SET, 21, node_list2, NULL);
  printf("after ex_put_node_set (2), error = %d\n", error);
  error = ex_put_set_dist_fact(exoid2, EX_NODE_SET, 21, dist_fact2);
  printf("after ex_put_node_set (2), error = %d\n", error);

  error = ex_put_prop(exoid2, EX_NODE_SET, 20, "FACE", 4);
  printf("after ex_put_prop (2), error = %d\n", error);

  error = ex_put_prop(exoid2, EX_NODE_SET, 21, "FACE", 5);
  printf("after ex_put_prop (2), error = %d\n", error);

  prop_array[0] = 1000;
  prop_array[1] = 2000;

  error = ex_put_prop_array(exoid2, EX_NODE_SET, "VELOCITY", prop_array);
  printf("after ex_put_prop (2), error = %d\n", error);

  /* write individual side sets */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 30, 2, 4);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 2;
  elem_list[1] = 2;

  side_list[0] = 4;
  side_list[1] = 2;

  dist_fact[0] = 30.0;
  dist_fact[1] = 30.1;
  dist_fact[2] = 30.2;
  dist_fact[3] = 30.3;

  error = ex_put_set(exoid, EX_SIDE_SET, 30, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  error = ex_put_set_dist_fact(exoid, EX_SIDE_SET, 30, dist_fact);
  printf("after ex_put_side_set_dist_fact, error = %d\n", error);

  error = ex_put_set_param(exoid, EX_SIDE_SET, 31, 2, 4);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 1;
  elem_list[1] = 2;

  side_list[0] = 2;
  side_list[1] = 3;

  dist_fact[0] = 31.0;
  dist_fact[1] = 31.1;
  dist_fact[2] = 31.2;
  dist_fact[3] = 31.3;

  error = ex_put_set(exoid, EX_SIDE_SET, 31, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  error = ex_put_set_dist_fact(exoid, EX_SIDE_SET, 31, dist_fact);
  printf("after ex_put_side_set_dist_fact, error = %d\n", error);

  /* side set #3  - hex */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 32, 7, 0);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 3;
  elem_list[1] = 3;
  elem_list[2] = 3;
  elem_list[3] = 3;
  elem_list[4] = 3;
  elem_list[5] = 3;
  elem_list[6] = 3;

  side_list[0] = 5;
  side_list[1] = 3;
  side_list[2] = 3;
  side_list[3] = 2;
  side_list[4] = 4;
  side_list[5] = 1;
  side_list[6] = 6;

  error = ex_put_set(exoid, EX_SIDE_SET, 32, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  /* side set #4  - tetras */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 33, 4, 0);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 4;
  elem_list[1] = 4;
  elem_list[2] = 4;
  elem_list[3] = 4;

  side_list[0] = 1;
  side_list[1] = 2;
  side_list[2] = 3;
  side_list[3] = 4;

  error = ex_put_set(exoid, EX_SIDE_SET, 33, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  /* side set #5  - wedges */

  error = ex_put_set_param(exoid, EX_SIDE_SET, 34, 5, 0);
  printf("after ex_put_side_set_param, error = %d\n", error);

  elem_list[0] = 5;
  elem_list[1] = 5;
  elem_list[2] = 5;
  elem_list[3] = 5;
  elem_list[4] = 5;

  side_list[0] = 1;
  side_list[1] = 2;
  side_list[2] = 3;
  side_list[3] = 4;
  side_list[4] = 5;

  error = ex_put_set(exoid, EX_SIDE_SET, 34, elem_list, side_list);
  printf("after ex_put_side_set, error = %d\n", error);

  /* file 2 */
  error = ex_put_set_param(exoid2, EX_SIDE_SET, 30, 2, 4);
  printf("after ex_put_side_set_param (2), error = %d\n", error);

  elem_list2[0] = 2;
  elem_list2[1] = 2;

  side_list2[0] = 4;
  side_list2[1] = 2;

  dist_fact2[0] = 30.0;
  dist_fact2[1] = 30.1;
  dist_fact2[2] = 30.2;
  dist_fact2[3] = 30.3;

  error = ex_put_set(exoid2, EX_SIDE_SET, 30, elem_list2, side_list2);
  printf("after ex_put_side_set (2), error = %d\n", error);

  error = ex_put_set_dist_fact(exoid2, EX_SIDE_SET, 30, dist_fact2);
  printf("after ex_put_side_set_dist_fact (2), error = %d\n", error);

  error = ex_put_set_param(exoid2, EX_SIDE_SET, 31, 2, 4);
  printf("after ex_put_side_set_param (2), error = %d\n", error);

  elem_list2[0] = 1;
  elem_list2[1] = 2;

  side_list2[0] = 2;
  side_list2[1] = 3;

  dist_fact2[0] = 31.0;
  dist_fact2[1] = 31.1;
  dist_fact2[2] = 31.2;
  dist_fact2[3] = 31.3;

  error = ex_put_set(exoid2, EX_SIDE_SET, 31, elem_list2, side_list2);
  printf("after ex_put_side_set (2), error = %d\n", error);

  error = ex_put_set_dist_fact(exoid2, EX_SIDE_SET, 31, dist_fact2);
  printf("after ex_put_side_set_dist_fact (2), error = %d\n", error);

  /* side set #3  - hex */

  error = ex_put_set_param(exoid2, EX_SIDE_SET, 32, 7, 0);
  printf("after ex_put_side_set_param (2), error = %d\n", error);

  elem_list2[0] = 3;
  elem_list2[1] = 3;
  elem_list2[2] = 3;
  elem_list2[3] = 3;
  elem_list2[4] = 3;
  elem_list2[5] = 3;
  elem_list2[6] = 3;

  side_list2[0] = 5;
  side_list2[1] = 3;
  side_list2[2] = 3;
  side_list2[3] = 2;
  side_list2[4] = 4;
  side_list2[5] = 1;
  side_list2[6] = 6;

  error = ex_put_set(exoid2, EX_SIDE_SET, 32, elem_list2, side_list2);
  printf("after ex_put_side_set (2), error = %d\n", error);

  /* side set #4  - tetras */

  error = ex_put_set_param(exoid2, EX_SIDE_SET, 33, 4, 0);
  printf("after ex_put_side_set_param (2), error = %d\n", error);

  elem_list2[0] = 4;
  elem_list2[1] = 4;
  elem_list2[2] = 4;
  elem_list2[3] = 4;

  side_list2[0] = 1;
  side_list2[1] = 2;
  side_list2[2] = 3;
  side_list2[3] = 4;

  error = ex_put_set(exoid2, EX_SIDE_SET, 33, elem_list2, side_list2);
  printf("after ex_put_side_set (2), error = %d\n", error);

  /* side set #5  - wedges */

  error = ex_put_set_param(exoid2, EX_SIDE_SET, 34, 5, 0);
  printf("after ex_put_side_set_param (2), error = %d\n", error);

  elem_list2[0] = 5;
  elem_list2[1] = 5;
  elem_list2[2] = 5;
  elem_list2[3] = 5;
  elem_list2[4] = 5;

  side_list2[0] = 1;
  side_list2[1] = 2;
  side_list2[2] = 3;
  side_list2[3] = 4;
  side_list2[4] = 5;

  error = ex_put_set(exoid2, EX_SIDE_SET, 34, elem_list2, side_list2);
  printf("after ex_put_side_set (2), error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
  printf("after ex_put_prop, error = %d\n", error);

  error = ex_put_prop(exoid2, EX_SIDE_SET, 30, "COLOR", 100);
  printf("after ex_put_prop (2), error = %d\n", error);

  error = ex_put_prop(exoid2, EX_SIDE_SET, 31, "COLOR", 101);
  printf("after ex_put_prop (2), error = %d\n", error);

  /* write QA records */

  num_qa_rec = 2;

  qa_record[0][0] = "TESTWT2";
  qa_record[0][1] = "testwt2";
  qa_record[0][2] = "07/07/93";
  qa_record[0][3] = "15:41:33";
  qa_record[1][0] = "FASTQ";
  qa_record[1][1] = "fastq";
  qa_record[1][2] = "07/07/93";
  qa_record[1][3] = "16:41:33";

  error = ex_put_qa(exoid, num_qa_rec, qa_record);
  printf("after ex_put_qa, error = %d\n", error);

  num_qa_rec2 = 2;

  qa_record2[0][0] = "TESTWT2";
  qa_record2[0][1] = "testwt2";
  qa_record2[0][2] = "07/07/93";
  qa_record2[0][3] = "15:41:33";
  qa_record2[1][0] = "FASTQ";
  qa_record2[1][1] = "fastq";
  qa_record2[1][2] = "07/07/93";
  qa_record2[1][3] = "16:41:33";

  error = ex_put_qa(exoid2, num_qa_rec2, qa_record2);
  printf("after ex_put_qa (2), error = %d\n", error);

  /* write information records */

  num_info = 3;

  info[0] = "This is the first information record.";
  info[1] = "This is the second information record.";
  info[2] = "This is the third information record.";

  error = ex_put_info(exoid, num_info, info);
  printf("after ex_put_info, error = %d\n", error);

  num_info2 = 3;

  info2[0] = "This is the first information record.";
  info2[1] = "This is the second information record.";
  info2[2] = "This is the third information record.";

  error = ex_put_info(exoid2, num_info2, info2);
  printf("after ex_put_info (2), error = %d\n", error);

  /* write results variables parameters and names */

  num_glo_vars = 1;

  var_names[0] = "glo_vars";

  error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_glo_vars2 = 1;

  var_names2[0] = "glo_vars";

  error = ex_put_variable_param(exoid2, EX_GLOBAL, num_glo_vars2);
  printf("after ex_put_variable_param (2), error = %d\n", error);
  error = ex_put_variable_names(exoid2, EX_GLOBAL, num_glo_vars2, var_names2);
  printf("after ex_put_variable_names (2), error = %d\n", error);

  num_nod_vars = 2;

  var_names[0] = "nod_var0";
  var_names[1] = "nod_var1";

  error = ex_put_variable_param(exoid, EX_NODAL, num_nod_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_nod_vars2 = 2;

  var_names2[0] = "nod_var0";
  var_names2[1] = "nod_var1";

  error = ex_put_variable_param(exoid2, EX_NODAL, num_nod_vars2);
  printf("after ex_put_variable_param (2), error = %d\n", error);
  error = ex_put_variable_names(exoid2, EX_NODAL, num_nod_vars2, var_names2);
  printf("after ex_put_variable_names (2), error = %d\n", error);

  num_ele_vars = 3;

  var_names[0] = "ele_var0";
  var_names[1] = "ele_var1";
  var_names[2] = "ele_var2";

  error = ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars);
  printf("after ex_put_variable_param, error = %d\n", error);
  error = ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names);
  printf("after ex_put_variable_names, error = %d\n", error);

  num_ele_vars2 = 3;

  var_names2[0] = "ele_var20";
  var_names2[1] = "ele_var21";
  var_names2[2] = "ele_var22";

  error = ex_put_variable_param(exoid2, EX_ELEM_BLOCK, num_ele_vars2);
  printf("after ex_put_variable_param (2), error = %d\n", error);
  error = ex_put_variable_names(exoid2, EX_ELEM_BLOCK, num_ele_vars, var_names);
  printf("after ex_put_variable_names (2), error = %d\n", error);

  /* write element variable truth table */

  truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int));

  k = 0;
  for (i = 0; i < num_elem_blk; i++) {
    for (j = 0; j < num_ele_vars; j++) {
      truth_tab[k++] = 1;
    }
  }

  error = ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab);
  printf("after ex_put_elem_var_tab, error = %d\n", error);

  error = ex_put_truth_table(exoid2, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab);
  printf("after ex_put_elem_var_tab (2), error = %d\n", error);

  free(truth_tab);

  /* for each time step, write the analysis results;
   * the code below fills the arrays hist_var_vals, glob_var_vals,
   * nodal_var_vals, and elem_var_vals with values for debugging purposes;
   * obviously the analysis code will populate these arrays
   */

  whole_time_step = 1;
  num_time_steps  = 10;

  glob_var_vals  = (float *)calloc(num_glo_vars, sizeof(CPU_word_size));
  nodal_var_vals = (float *)calloc(num_nodes, sizeof(CPU_word_size));
  elem_var_vals  = (float *)calloc(4, sizeof(CPU_word_size));

  for (i = 0; i < num_time_steps; i++) {
    time_value  = (float)(i + 1) / 100.;
    time_value2 = (float)(i + 1) / 100.;

    /* write time value to regular file */

    error = ex_put_time(exoid, whole_time_step, &time_value);
    printf("after ex_put_time, error = %d\n", error);

    error = ex_put_time(exoid2, whole_time_step, &time_value2);
    printf("after ex_put_time (2), error = %d\n", error);

    /* write global variables */

    for (j = 0; j < num_glo_vars; j++) {
      glob_var_vals[j] = (float)(j + 2) * time_value;
    }

    error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
    printf("after ex_put_glob_vars, error = %d\n", error);

    error = ex_put_var(exoid2, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
    printf("after ex_put_glob_vars (2), error = %d\n", error);

    /* write nodal variables */

    for (k = 1; k <= num_nod_vars; k++) {
      for (j = 0; j < num_nodes; j++) {
        nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value);
      }

      error = ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals);
      printf("after ex_put_nodal_var, error = %d\n", error);

      error = ex_put_var(exoid2, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals);
      printf("after ex_put_nodal_var (2), error = %d\n", error);
    }

    /* write element variables */

    for (k = 1; k <= num_ele_vars; k++) {
      for (j = 0; j < num_elem_blk; j++) {
        for (m = 0; m < num_elem_in_block[j]; m++) {
          elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value);
          /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
        }
        error = ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j],
                           elem_var_vals);
        printf("after ex_put_elem_var, error = %d\n", error);

        error = ex_put_var(exoid2, whole_time_step, EX_ELEM_BLOCK, k, ebids[j],
                           num_elem_in_block[j], elem_var_vals);
        printf("after ex_put_elem_var (2), error = %d\n", error);
      }
    }

    whole_time_step++;

    /* update the data file; this should be done at the end of every time step
     * to ensure that no data is lost if the analysis dies
     */
    error = ex_update(exoid);
    printf("after ex_update, error = %d\n", error);
    error = ex_update(exoid2);
    printf("after ex_update (2), error = %d\n", error);
  }
  free(glob_var_vals);
  free(nodal_var_vals);
  free(elem_var_vals);

  /* close the EXODUS files
   */
  error = ex_close(exoid);
  printf("after ex_close, error = %d\n", error);
  error = ex_close(exoid2);
  printf("after ex_close (2), error = %d\n", error);
  return 0;
}
示例#17
0
文件: oned.c 项目: certik/exodus
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10], num_nodes_per_elem[10];
   int num_nodes_in_nset[10];
   int num_node_sets, num_side_sets;
   int i, j, k, m, *elem_map, *connect;
   int node_list[100];
   int ebids[10], nsids[10];
   int  num_qa_rec, num_info;
   int num_glo_vars, num_nod_vars, num_ele_vars, num_nset_vars;
   int *truth_tab;
   int whole_time_step, num_time_steps;
   int CPU_word_size,IO_word_size;
   int prop_array[2];

   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
   float *nset_var_vals;
   float time_value;
   float x[100];
   float attrib[10], dist_fact[100];
   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
   char *block_names[10], *nset_names[10];
   char *prop_names[2], *attrib_names[2];
   char *title = "This is a test";
   ex_opts (EX_VERBOSE | EX_ABORT );

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("oned.e",         /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for oned.e, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   EXCHECK(ex_set_max_name_length(exoid, 40));
   /* ncopts = NC_VERBOSE; */

/* initialize file with parameters */

   num_dim = 1;
   num_nodes = 10;
   num_elem = 10; /* 9 lines plus a point */
   num_elem_blk = 3;
   num_node_sets = 2;
   num_side_sets = 0;

   
   EXCHECK(ex_put_init (exoid, title, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets));

   for (i=0; i < num_nodes; i++) {
     x[i] = exp((float)i/10.0);
   }
   
   EXCHECK(ex_put_coord (exoid, x, NULL, NULL));
   
   coord_names[0] = "xcoor";
   EXCHECK(ex_put_coord_names (exoid, coord_names));
   
   /* Add nodal attributes */
   EXCHECK(ex_put_attr_param(exoid, EX_NODAL, 0, 1));
   
   EXCHECK(ex_put_one_attr(exoid, EX_NODAL, 0, 1, x));
   
   attrib_names[0] = "Node_attr_1";
   EXCHECK(ex_put_attr_names (exoid, EX_NODAL, 0, attrib_names));

   /* write element order map */
   elem_map = (int *) calloc(num_elem, sizeof(int));

   for (i=1; i<=num_elem; i++) {
     elem_map[i-1] = 10*i;
   }

   EXCHECK(ex_put_map (exoid, elem_map));
   free (elem_map);

   /* write element block parameters */
   block_names[0] = "left_side";
   block_names[1] = "right_side";
   block_names[2] = "center";

   num_elem_in_block[0] = 4;
   num_elem_in_block[1] = 5;
   num_elem_in_block[2] = 1;

   num_nodes_per_elem[0] = 2;
   num_nodes_per_elem[1] = 2;
   num_nodes_per_elem[2] = 1;

   ebids[0] = 10;
   ebids[1] = 20;
   ebids[2] = 30;

   EXCHECK(ex_put_elem_block (exoid, ebids[0], "line",  num_elem_in_block[0], num_nodes_per_elem[0], 1));
   EXCHECK(ex_put_elem_block (exoid, ebids[1], "line",  num_elem_in_block[1], num_nodes_per_elem[1], 1));
   EXCHECK(ex_put_elem_block (exoid, ebids[2], "point", num_elem_in_block[2], num_nodes_per_elem[2], 0));

   /* Write element block names */
   EXCHECK(ex_put_names(exoid, EX_ELEM_BLOCK, block_names));
   
   /* write element block properties */
   prop_names[0] = "DENSITY";
   EXCHECK(ex_put_prop_names(exoid,EX_ELEM_BLOCK,1,prop_names));
   EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], prop_names[0], 1.345));
   EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], prop_names[0], 10.995));
   EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], prop_names[0], 0.001));


   /* write element connectivity */
   connect = (int *) calloc(18, sizeof(int));
   for (i=0; i < num_elem*2; i+=2) {
     connect[i]   = i/2+1;
     connect[i+1] = i/2+2;
   }

   EXCHECK(ex_put_conn (exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL));
   EXCHECK(ex_put_conn (exoid, EX_ELEM_BLOCK, ebids[1], connect+8, NULL, NULL));

   /* Circle */
   connect[0] = 5;
   EXCHECK(ex_put_conn (exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL));

   /* write element block attributes */
   for (i=0; i < num_elem; i++) {
     attrib[i] = 3.14159 * i;
   }
   EXCHECK(ex_put_attr (exoid, EX_ELEM_BLOCK, ebids[0], attrib));
   EXCHECK(ex_put_attr (exoid, EX_ELEM_BLOCK, ebids[1], attrib+num_elem_in_block[0]));

   attrib_names[0] = "THICKNESS";
   EXCHECK(ex_put_attr_names (exoid, EX_ELEM_BLOCK, ebids[0], attrib_names));
   attrib_names[0] = "WIDTH";
   EXCHECK(ex_put_attr_names (exoid, EX_ELEM_BLOCK, ebids[1], attrib_names));

   /* write individual node sets */
   num_nodes_in_nset[0] = 5;
   num_nodes_in_nset[1] = 3;

   nsids[0] = 20;
   nsids[1] = 21;

   EXCHECK(ex_put_node_set_param (exoid, nsids[0], 5, 5));

   node_list[0] = 1;
   node_list[1] = 3;
   node_list[2] = 5;
   node_list[3] = 7;
   node_list[4] = 9;

   dist_fact[0] = 1.0;
   dist_fact[1] = 2.0;
   dist_fact[2] = 3.0;
   dist_fact[3] = 4.0;
   dist_fact[4] = 5.0;

   EXCHECK(ex_put_node_set (exoid, nsids[0], node_list));
   EXCHECK(ex_put_node_set_dist_fact (exoid, nsids[0], dist_fact));

   EXCHECK(ex_put_node_set_param (exoid, nsids[1], 3, 3));

   node_list[0] = 2;
   node_list[1] = 4;
   node_list[2] = 6;

   dist_fact[0] = 1.0;
   dist_fact[1] = 2.0;
   dist_fact[2] = 3.0;

   EXCHECK(ex_put_node_set (exoid, nsids[1], node_list));
   EXCHECK(ex_put_node_set_dist_fact (exoid, nsids[1], dist_fact));

   /* Write node set names */
   nset_names[0] = "all_odd_nodes";
   nset_names[1] = "some_even_nodes";

   EXCHECK(ex_put_names(exoid, EX_NODE_SET, nset_names));
   EXCHECK(ex_put_prop(exoid, EX_NODE_SET, nsids[0], "FACE", 4));

   EXCHECK(ex_put_prop(exoid, EX_NODE_SET, nsids[1], "FACE", 5));

   prop_array[0] = 1000;
   prop_array[1] = 2000;

   EXCHECK(ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array));
   /* Add nodeset attributes */
   EXCHECK(ex_put_attr_param(exoid, EX_NODE_SET, nsids[0], 1));
   
   EXCHECK(ex_put_attr(exoid, EX_NODE_SET, nsids[0], x));
   
   attrib_names[0] = "Nodeset_attribute";
   EXCHECK(ex_put_attr_names (exoid, EX_NODE_SET, nsids[0], attrib_names));

   /* write QA records; test empty and just blank-filled records */
   num_qa_rec = 2;

   qa_record[0][0] = "TESTWT";
   qa_record[0][1] = "testwt";
   qa_record[0][2] = "07/07/93";
   qa_record[0][3] = "15:41:33";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   EXCHECK(ex_put_qa (exoid, num_qa_rec, qa_record));

   /* write information records; test empty and just blank-filled records */
   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   EXCHECK(ex_put_info (exoid, num_info, info));


   /* write results variables parameters and names */
   num_glo_vars = 1;

   var_names[0] = "glo_vars";

   EXCHECK(ex_put_variable_param (exoid, EX_GLOBAL, num_glo_vars));
   EXCHECK(ex_put_variable_names (exoid, EX_GLOBAL, num_glo_vars, var_names));

   num_nod_vars = 2;
   /*              12345678901234567890123456789012 */
   var_names[0] = "node_variable_a_very_long_name_0";
   var_names[1] = "nod_var1";

   EXCHECK(ex_put_variable_param (exoid, EX_NODAL, num_nod_vars));
   EXCHECK(ex_put_variable_names (exoid, EX_NODAL, num_nod_vars, var_names));

   num_ele_vars = 3;
   /*              0        1         2         3   */
   /*              12345678901234567890123456789012 */
   var_names[0] = "this_variable_name_is_short";
   var_names[1] = "this_variable_name_is_just_right";
   var_names[2] = "this_variable_name_is_tooooo_long";

   EXCHECK(ex_put_variable_param (exoid, EX_ELEM_BLOCK, num_ele_vars));
   EXCHECK(ex_put_variable_names (exoid, EX_ELEM_BLOCK, num_ele_vars, var_names));

   num_nset_vars = 3;
     
   var_names[0] = "ns_var0";
   var_names[1] = "ns_var1";
   var_names[2] = "ns_var2";
     
   EXCHECK(ex_put_variable_param (exoid, EX_NODE_SET, num_nset_vars));
   EXCHECK(ex_put_variable_names (exoid, EX_NODE_SET, num_nset_vars, var_names));
   

   /* write element variable truth table */
   truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));

   k = 0;
   for (i=0; i<num_elem_blk; i++)
   {
      for (j=0; j<num_ele_vars; j++)
      {
         truth_tab[k++] = 1;
      }
   }

   EXCHECK(ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab));

   free (truth_tab);


/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
   elem_var_vals = (float *) calloc (num_elem, CPU_word_size);
   nset_var_vals = (float *) calloc (10, CPU_word_size);
   
   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

     /* write time value */
     EXCHECK(ex_put_time (exoid, whole_time_step, &time_value));

     /* write global variables */
     for (j=0; j<num_glo_vars; j++) {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     EXCHECK(ex_put_var (exoid, whole_time_step, EX_GLOBAL, 0, 0, num_glo_vars, glob_var_vals));

     /* write nodal variables */
     for (k=1; k<=num_nod_vars; k++) {
       for (j=0; j<num_nodes; j++) {
         nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
       }
       EXCHECK(ex_put_var (exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals));
     }

     /* write element variables */
     for (k=1; k<=num_ele_vars; k++) {
       for (j=0; j<num_elem_blk; j++) {
         for (m=0; m<num_elem_in_block[j]; m++) {
           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
                              ((float)(m+1)*time_value);
         }
         EXCHECK(ex_put_var (exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j], elem_var_vals));
       }
     }

     /* write nodeset variables */
     for (k=1; k<=num_nset_vars; k++) {
       for (j=0; j<num_node_sets; j++) {
         for (m=0; m<num_nodes_in_nset[j]; m++) {
           nset_var_vals[m] = (float)(k+3) + (float)(j+4) + 
                              ((float)(m+1)*time_value);
         }
         EXCHECK(ex_put_var (exoid, whole_time_step, EX_NODE_SET, k, nsids[j],  num_nodes_in_nset[j], nset_var_vals));
       }
     }

     whole_time_step++;

     /* update the data file; this should be done at the end of every time step
      * to ensure that no data is lost if the analysis dies
      */
     EXCHECK(ex_update (exoid));
   }

   free(glob_var_vals);
   free(nodal_var_vals);
   free(elem_var_vals);
   free(nset_var_vals);


/* close the EXODUS files */
   EXCHECK(ex_close (exoid));
   return 0;
}
void
PeridigmNS::InterfaceData::WriteExodusOutput(int timeStep, const float & timeValue, Teuchos::RCP<Epetra_Vector> x, Teuchos::RCP<Epetra_Vector> y){

  int error_int = 0;

  int CPU_word_size = 0;
  int IO_word_size = 0;
  float version = 0;
  std::string outputFileNameStr = filename.str();
  std::vector<char> writable(outputFileNameStr.size() + 1);
  std::copy(outputFileNameStr.begin(), outputFileNameStr.end(), writable.begin());

  exoid = ex_open(&writable[0], EX_WRITE, &CPU_word_size, &IO_word_size, &version);

  error_int = ex_put_time(exoid, timeStep, &timeValue);
  TEUCHOS_TEST_FOR_EXCEPTION(error_int,std::logic_error, "ex_put_time(): Failure");

  float * quadValues = new float[numQuads];
  float * triValues = new float[numTris];

  // populate the quad values
  int quadIndex = 0;
  int triIndex = 0;
  for(int i=0;i<numOwnedPoints;++i){
    if(interfaceNodesMap->ElementSize(i)==4){
      quadValues[quadIndex] = (*interfaceAperture)[i];
      quadIndex++;
    }
    else if(interfaceNodesMap->ElementSize(i)==3){
      triValues[triIndex] = (*interfaceAperture)[i];
      triIndex++;
    }
    else{
      TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,"size of this element is not recognized: " << interfaceNodesMap->ElementSize(i));
    }
  }

  int blockIndex = 0;
  const int varIndex = 1;
  blockIndex++;
  if(numQuads > 0){
    error_int = ex_put_elem_var(exoid, timeStep, varIndex, blockIndex, numQuads, &quadValues[0]);
    TEUCHOS_TEST_FOR_EXCEPTION(error_int,std::logic_error,"Failure ex_put_elem_var(): ");
  }
  blockIndex++;
  if(numTris > 0){
    error_int = ex_put_elem_var(exoid, timeStep, varIndex, blockIndex, numTris, &triValues[0]);
    TEUCHOS_TEST_FOR_EXCEPTION(error_int,std::logic_error,"Failure ex_put_elem_var(): ");
  }

  delete [] quadValues;
  delete [] triValues;

  // update the apertures...
  // import the mothership vectors x and y to the overlap epetra vectors
  Teuchos::RCP<const Epetra_Import> importer = Teuchos::rcp(new Epetra_Import(*elemOverlapMap, x->Map()));

  Teuchos::RCP<Epetra_Vector> xOverlap = Teuchos::rcp(new Epetra_Vector(*elemOverlapMap,true));
  xOverlap->Import(*x,*importer,Insert);
  Teuchos::RCP<Epetra_Vector> yOverlap = Teuchos::rcp(new Epetra_Vector(*elemOverlapMap,true));
  yOverlap->Import(*y,*importer,Insert);

  double *xValues;
  xOverlap->ExtractView( &xValues );
  double *yValues;
  yOverlap->ExtractView( &yValues );

  double xLeft=0,yLeft=0,zLeft=0,xRight=0,yRight=0,zRight=0;
  double XLeft=0,YLeft=0,ZLeft=0,XRight=0,YRight=0,ZRight=0;
  double X=0,Y=0;
  double dx=0,dy=0,dz=0,dX=0,dY=0,dZ=0;
  int elemIndexLeft=-1,elemIndexRight=-1,GIDLeft=-1,GIDRight=-1;

  for(int i=0;i<numOwnedPoints;++i){
    GIDLeft = elementLeft[i];
    GIDRight = elementRight[i];

    elemIndexLeft = xOverlap->Map().FirstPointInElement(elemOverlapMap->LID(GIDLeft));
    elemIndexRight = xOverlap->Map().FirstPointInElement(elemOverlapMap->LID(GIDRight));

    xLeft = xValues[elemIndexLeft+0];
    yLeft = xValues[elemIndexLeft+1];
    zLeft = xValues[elemIndexLeft+2];
    xRight = xValues[elemIndexRight+0];
    yRight = xValues[elemIndexRight+1];
    zRight = xValues[elemIndexRight+2];

    XLeft = yValues[elemIndexLeft+0];
    YLeft = yValues[elemIndexLeft+1];
    ZLeft = yValues[elemIndexLeft+2];
    XRight = yValues[elemIndexRight+0];
    YRight = yValues[elemIndexRight+1];
    ZRight = yValues[elemIndexRight+2];

    dx = xRight - xLeft;
    dy = yRight - yLeft;
    dz = zRight - zLeft;

    dX = XRight - XLeft;
    dY = YRight - YLeft;
    dZ = ZRight - ZLeft;

    X = std::sqrt(dx*dx + dy*dy + dz*dz);
    Y = std::sqrt(dX*dX + dY*dY + dZ*dZ);

    interfaceAperture->ReplaceMyValue(i,0,Y-X);
  }
  error_int = ex_update(exoid);
  TEUCHOS_TEST_FOR_EXCEPTION(error_int,std::logic_error,"Exodus file close failed.");
  error_int = ex_close(exoid);
  TEUCHOS_TEST_FOR_EXCEPTION(error_int,std::logic_error,"Exodus file close failed.");

}
示例#19
0
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10], num_nodes_per_elem[10];
   int num_face_in_sset[10], num_nodes_in_nset[10];
   int num_node_sets, num_side_sets, error;
   int i, j, k, m, *elem_map, *connect;
   int node_list[100],elem_list[100],side_list[100];
   int ebids[10], ssids[10], nsids[10];
   int  num_qa_rec, num_info;
   int num_glo_vars, num_nod_vars, num_ele_vars, num_sset_vars, num_nset_vars;
   int *truth_tab;
   int whole_time_step, num_time_steps;
   int CPU_word_size,IO_word_size;
   int prop_array[2];

   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
   float *sset_var_vals, *nset_var_vals;
   float time_value;
   float x[100], y[100], z[100];
   float attrib[1], dist_fact[100];
   char *coord_names[3], *qa_record[2][4], *info[3], *variable_names[3];
   char *block_names[10], *nset_names[10], *sset_names[10];
   char *prop_names[2], *attrib_names[2];
   char *title = "This is a test";
   ex_opts (EX_VERBOSE | EX_ABORT );

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   
   exoid = ex_create ("test.exo",       /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   ex_set_option(exoid, EX_OPT_MAX_NAME_LENGTH, 127); /* Using long names */

   /* initialize file with parameters */

   num_dim = 3;
   num_nodes = 33;
   num_elem = 7;
   num_elem_blk = 7;
   num_node_sets = 2;
   num_side_sets = 5;

   
   error = ex_put_init (exoid, title, num_dim, num_nodes, num_elem,
                        num_elem_blk, num_node_sets, num_side_sets);

   printf ("after ex_put_init, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

/* write nodal coordinates values and names to database */

/* Quad #1 */
   x[0] = 0.0; y[0] = 0.0; z[0] = 0.0;
   x[1] = 1.0; y[1] = 0.0; z[1] = 0.0;
   x[2] = 1.0; y[2] = 1.0; z[2] = 0.0;
   x[3] = 0.0; y[3] = 1.0; z[3] = 0.0;

/* Quad #2 */
   x[4]  =  1.0; y[4]  =  0.0; z[4]  =  0.0;
   x[5]  =  2.0; y[5]  =  0.0; z[5]  =  0.0;
   x[6]  =  2.0; y[6]  =  1.0; z[6]  =  0.0;
   x[7]  =  1.0; y[7]  =  1.0; z[7]  =  0.0;

/* Hex #1 */
   x[8]  =  0.0; y[8]  =  0.0; z[8]  =  0.0;
   x[9]  = 10.0; y[9]  =  0.0; z[9]  =  0.0;
   x[10] = 10.0; y[10] =  0.0; z[10] =-10.0;
   x[11] =  1.0; y[11] =  0.0; z[11] =-10.0;
   x[12] =  1.0; y[12] = 10.0; z[12] =  0.0;
   x[13] = 10.0; y[13] = 10.0; z[13] =  0.0;
   x[14] = 10.0; y[14] = 10.0; z[14] =-10.0;
   x[15] =  1.0; y[15] = 10.0; z[15] =-10.0;

/* Tetra #1 */
   x[16] =  0.0; y[16] =  0.0; z[16] =  0.0;
   x[17] =  1.0; y[17] =  0.0; z[17] =  5.0;
   x[18] = 10.0; y[18] =  0.0; z[18] =  2.0;
   x[19] =  7.0; y[19] =  5.0; z[19] =  3.0;

/* Wedge #1 */
   x[20] =  3.0; y[20] =  0.0; z[20] =  6.0;
   x[21] =  6.0; y[21] =  0.0; z[21] =  0.0;
   x[22] =  0.0; y[22] =  0.0; z[22] =  0.0;
   x[23] =  3.0; y[23] =  2.0; z[23] =  6.0;
   x[24] =  6.0; y[24] =  2.0; z[24] =  2.0;
   x[25] =  0.0; y[25] =  2.0; z[25] =  0.0;

/* Tetra #2 */
   x[26] =  2.7; y[26] =  1.7; z[26] =  2.7;
   x[27] =  6.0; y[27] =  1.7; z[27] =  3.3;
   x[28] =  5.7; y[28] =  1.7; z[28] =  1.7;
   x[29] =  3.7; y[29] =  0.0; z[29] =  2.3;

/* 3d Tri */
   x[30] =  0.0; y[30] =  0.0; z[30] =  0.0;
   x[31] = 10.0; y[31] =  0.0; z[31] =  0.0;
   x[32] = 10.0; y[32] = 10.0; z[32] = 10.0;

   error = ex_put_coord (exoid, x, y, z);
   printf ("after ex_put_coord, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   /*                0        1         2         3         4         5         6     */
   /*                1234567890123456789012345678901234567890123456789012345678901234 */
   coord_names[0] = "X coordinate name that is padded to be longer than 32 characters";
   coord_names[1] = "Y coordinate name that is padded to be longer than 32 characters";
   coord_names[2] = "Z coordinate name that is padded to be longer than 32 characters";

   error = ex_put_coord_names (exoid, coord_names);
   printf ("after ex_put_coord_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* Add nodal attributes */
   error = ex_put_attr_param(exoid, EX_NODAL, 0, 2);
   printf ("after ex_put_attr_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   error = ex_put_one_attr(exoid, EX_NODAL, 0, 1, x);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   error = ex_put_one_attr(exoid, EX_NODAL, 0, 2, y);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   {
     attrib_names[0] = "Node_attr_1";
     attrib_names[1] = "Node_attr_2";
     error = ex_put_attr_names (exoid, EX_NODAL, 0, attrib_names);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }

/* write element order map */

   elem_map = (int *) calloc(num_elem, sizeof(int));

   for (i=1; i<=num_elem; i++)
   {
      elem_map[i-1] = i;
   }

   error = ex_put_map (exoid, elem_map);
   printf ("after ex_put_map, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (elem_map);


/* write element block parameters */

   /*                0        1         2         3         4         5         6     */
   /*                1234567890123456789012345678901234567890123456789012345678901234 */
   block_names[0] = "Very long name for block_1 that exceeds 32 characters";
   block_names[1] = "Very long name for block_2 that exceeds 32 characters";
   block_names[2] = "Very long name for block_3 that exceeds 32 characters";
   block_names[3] = "Very long name for block_4 that exceeds 32 characters";
   block_names[4] = "Very long name for block_5 that exceeds 32 characters";
   block_names[5] = "Very long name for block_6 that exceeds 32 characters";
   block_names[6] = "Very long name for block_7 that exceeds 32 characters";
   num_elem_in_block[0] = 1;
   num_elem_in_block[1] = 1;
   num_elem_in_block[2] = 1;
   num_elem_in_block[3] = 1;
   num_elem_in_block[4] = 1;
   num_elem_in_block[5] = 1;
   num_elem_in_block[6] = 1;

   num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
   num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
   num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
   num_nodes_per_elem[3] = 4; /* elements in block #4 are 4-node tetras */
   num_nodes_per_elem[4] = 6; /* elements in block #5 are 6-node wedges */
   num_nodes_per_elem[5] = 8; /* elements in block #6 are 8-node tetras */
   num_nodes_per_elem[6] = 3; /* elements in block #7 are 3-node tris   */

   ebids[0] = 10;
   ebids[1] = 11;
   ebids[2] = 12;
   ebids[3] = 13;
   ebids[4] = 14;
   ebids[5] = 15;
   ebids[6] = 16;

   error = ex_put_elem_block (exoid, ebids[0], "quad", num_elem_in_block[0],
                              num_nodes_per_elem[0], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[1], "quad", num_elem_in_block[1],
                               num_nodes_per_elem[1], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[2], "hex", num_elem_in_block[2],
                               num_nodes_per_elem[2], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[3], "tetra", num_elem_in_block[3],
                               num_nodes_per_elem[3], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[4], "wedge", num_elem_in_block[4],
                               num_nodes_per_elem[4], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[5], "tetra", num_elem_in_block[5],
                               num_nodes_per_elem[5], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_block (exoid, ebids[6], "tri", num_elem_in_block[6],
                               num_nodes_per_elem[6], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* Write element block names */
   error = ex_put_names(exoid, EX_ELEM_BLOCK, block_names);
   printf ("after ex_put_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
/* write element block properties */

   /*               0        1         2         3         4         5         6     */
   /*               1234567890123456789012345678901234567890123456789012345678901234 */
   prop_names[0] = "MATERIAL_PROPERTY_LONG_NAME_32CH";
   prop_names[1] = "DENSITY";
   error = ex_put_prop_names(exoid,EX_ELEM_BLOCK,2,prop_names);
   printf ("after ex_put_prop_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], prop_names[0], 10);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], prop_names[0], 20);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], prop_names[0], 30);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], prop_names[0], 40);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], prop_names[0], 50);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], prop_names[0], 60);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], prop_names[0], 70);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


/* write element connectivity */

   connect = (int *) calloc(8, sizeof(int));
   connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;

   error = ex_put_elem_conn (exoid, ebids[0], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   connect[0] = 5; connect[1] = 6; connect[2] = 7; connect[3] = 8;

   error = ex_put_elem_conn (exoid, ebids[1], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12;
   connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16;

   error = ex_put_elem_conn (exoid, ebids[2], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;

   error = ex_put_elem_conn (exoid, ebids[3], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 21; connect[1] = 22; connect[2] = 23;
   connect[3] = 24; connect[4] = 25; connect[5] = 26;

   error = ex_put_elem_conn (exoid, ebids[4], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;
   connect[4] = 27; connect[5] = 28; connect[6] = 30; connect[7] = 29;

   error = ex_put_elem_conn (exoid, ebids[5], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   connect[0] = 31; connect[1] = 32; connect[2] = 33;

   error = ex_put_elem_conn (exoid, ebids[6], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (connect);


/* write element block attributes */

   attrib[0] = 3.14159;
   error = ex_put_elem_attr (exoid, ebids[0], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_attr (exoid, ebids[0], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   attrib[0] = 6.14159;
   error = ex_put_elem_attr (exoid, ebids[1], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_attr (exoid, ebids[2], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_attr (exoid, ebids[3], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_attr (exoid, ebids[4], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_attr (exoid, ebids[5], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_elem_attr (exoid, ebids[6], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /*                 0        1         2         3         4         5         6     */
   /*                 1234567890123456789012345678901234567890123456789012345678901234 */
   attrib_names[0] = "The name for the attribute representing the shell thickness";
   for (i=0; i < 7; i++) {
     error = ex_put_elem_attr_names (exoid, ebids[i], attrib_names);
     printf ("after ex_put_elem_attr_names, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }

/* write individual node sets */


   num_nodes_in_nset[0] = 5;
   num_nodes_in_nset[1] = 3;

   nsids[0] = 20;
   nsids[1] = 21;

   error = ex_put_node_set_param (exoid, nsids[0], 5, 5);
   printf ("after ex_put_node_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; 
   node_list[3] = 13; node_list[4] = 14; 

   dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0;
   dist_fact[3] = 4.0; dist_fact[4] = 5.0;

   error = ex_put_node_set (exoid, nsids[0], node_list);
   printf ("after ex_put_node_set, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_node_set_dist_fact (exoid, nsids[0], dist_fact);
   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   error = ex_put_node_set_param (exoid, nsids[1], 3, 3);
   printf ("after ex_put_node_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   node_list[0] = 20; node_list[1] = 21; node_list[2] = 22; 

   dist_fact[0] = 1.1; dist_fact[1] = 2.1; dist_fact[2] = 3.1;

   error = ex_put_node_set (exoid, nsids[1], node_list);
   printf ("after ex_put_node_set, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_node_set_dist_fact (exoid, nsids[1], dist_fact);
   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* Write node set names */
   nset_names[0] = "nset_1";
   nset_names[1] = "nset_2";

   error = ex_put_names(exoid, EX_NODE_SET, nset_names);
   printf ("after ex_put_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   error = ex_put_prop(exoid, EX_NODE_SET, nsids[0], "FACE", 4);
   printf ("after ex_put_prop, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_NODE_SET, nsids[1], "FACE", 5);
   printf ("after ex_put_prop, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   prop_array[0] = 1000;
   prop_array[1] = 2000;

   error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
   printf ("after ex_put_prop_array, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* Add nodeset attributes */
   error = ex_put_attr_param(exoid, EX_NODE_SET, nsids[0], 1);
   printf ("after ex_put_attr_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   error = ex_put_attr(exoid, EX_NODE_SET, nsids[0], x);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   {
     attrib_names[0] = "Nodeset_attribute";
     error = ex_put_attr_names (exoid, EX_NODE_SET, nsids[0], attrib_names);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }

/* write individual side sets */
   num_face_in_sset[0] =  2;
   num_face_in_sset[1] =  2;
   num_face_in_sset[2] =  7;
   num_face_in_sset[3] =  8;
   num_face_in_sset[4] = 10;
   
   ssids[0] = 30;
   ssids[1] = 31;
   ssids[2] = 32;
   ssids[3] = 33;
   ssids[4] = 34;

   /* side set #1  - quad */

   error = ex_put_side_set_param (exoid, ssids[0], 2, 4);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 2; elem_list[1] = 2;

   side_list[0] = 4; side_list[1] = 2;

   dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2;
   dist_fact[3] = 30.3;

   error = ex_put_side_set (exoid, 30, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_side_set_dist_fact (exoid, 30, dist_fact);
   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* side set #2  - quad, spanning 2 elements  */

   error = ex_put_side_set_param (exoid, 31, 2, 4);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 1; elem_list[1] = 2;

   side_list[0] = 2; side_list[1] = 3;

   dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2;
   dist_fact[3] = 31.3;

   error = ex_put_side_set (exoid, 31, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_side_set_dist_fact (exoid, 31, dist_fact);
   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* side set #3  - hex */

   error = ex_put_side_set_param (exoid, 32, 7, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 3; elem_list[1] = 3;
   elem_list[2] = 3; elem_list[3] = 3;
   elem_list[4] = 3; elem_list[5] = 3;
   elem_list[6] = 3;

   side_list[0] = 5; side_list[1] = 3;
   side_list[2] = 3; side_list[3] = 2;
   side_list[4] = 4; side_list[5] = 1;
   side_list[6] = 6;

   error = ex_put_side_set (exoid, 32, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* side set #4  - tetras */

   error = ex_put_side_set_param (exoid, 33, 8, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 4; elem_list[1] = 4;
   elem_list[2] = 4; elem_list[3] = 4;
   elem_list[4] = 6; elem_list[5] = 6;
   elem_list[6] = 6; elem_list[7] = 6;

   side_list[0] = 1; side_list[1] = 2;
   side_list[2] = 3; side_list[3] = 4;
   side_list[4] = 1; side_list[5] = 2;
   side_list[6] = 3; side_list[7] = 4;

   error = ex_put_side_set (exoid, 33, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   /* side set #5  - wedges and tris */

   error = ex_put_side_set_param (exoid, 34, 10, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   elem_list[0] = 5; elem_list[1] = 5;
   elem_list[2] = 5; elem_list[3] = 5;
   elem_list[4] = 5; elem_list[5] = 7;
   elem_list[6] = 7; elem_list[7] = 7;
   elem_list[8] = 7; elem_list[9] = 7;

   side_list[0] = 1; side_list[1] = 2;
   side_list[2] = 3; side_list[3] = 4;
   side_list[4] = 5; side_list[5] = 1;
   side_list[6] = 2; side_list[7] = 3;
   side_list[8] = 4; side_list[9] = 5;

   error = ex_put_side_set (exoid, 34, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   /* Write side set names */
   sset_names[0] = "sset_1";
   sset_names[1] = "sset_2";
   sset_names[2] = "sset_3";
   sset_names[3] = "sset_4";
   sset_names[4] = "sset_5";

   error = ex_put_names(exoid, EX_SIDE_SET, sset_names);
   printf ("after ex_put_names, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   
   error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
   printf ("after ex_put_prop, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
   printf ("after ex_put_prop, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


/* write QA records; test empty and just blank-filled records */

   num_qa_rec = 2;


   qa_record[0][0] = "TESTWT";
   qa_record[0][1] = "testwt";
   qa_record[0][2] = "07/07/93";
   qa_record[0][3] = "15:41:33";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   error = ex_put_qa (exoid, num_qa_rec, qa_record);
   printf ("after ex_put_qa, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }


/* write information records; test empty and just blank-filled records */

   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   error = ex_put_info (exoid, num_info, info);
   printf ("after ex_put_info, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }



/* write results variables parameters and names */

   num_glo_vars = 1;

   variable_names[0] = "glo_vars";

   error = ex_put_variable_param (exoid, EX_GLOBAL, num_glo_vars);
   printf ("after ex_put_variable_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_variable_names (exoid, EX_GLOBAL, num_glo_vars, variable_names);
   printf ("after ex_put_variable_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }



   num_nod_vars = 2;
   /*              0        1         2         3         4         5         6     */
   /*              1234567890123456789012345678901234567890123456789012345678901234 */
   variable_names[0] = "node_variable_a_somewhat_long_name_0";
   variable_names[1] = "node_variable_a_much_longer_name_that_is_not_too_long_name";

   error = ex_put_variable_param (exoid, EX_NODAL, num_nod_vars);
   printf ("after ex_put_variable_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_variable_names (exoid, EX_NODAL, num_nod_vars, variable_names);
   printf ("after ex_put_variable_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }


   num_ele_vars = 3;

   /*              0        1         2         3         4         5         6     */
   /*              1234567890123456789012345678901234567890123456789012345678901234 */
   variable_names[0] = "the_stress_on_the_elements_in_this_block_that_are_active_now";
   variable_names[1] = "ele_var1";
   variable_names[2] = "ele_var2";

   error = ex_put_variable_param (exoid, EX_ELEM_BLOCK, num_ele_vars);
   printf ("after ex_put_variable_param, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   error = ex_put_variable_names (exoid, EX_ELEM_BLOCK, num_ele_vars, variable_names);
   printf ("after ex_put_variable_names, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   {
     num_nset_vars = 3;
     
     variable_names[0] = "ns_var0";
     variable_names[1] = "ns_var1";
     variable_names[2] = "ns_var2";
     
     error = ex_put_variable_param (exoid, EX_NODE_SET, num_nset_vars);
     printf ("after ex_put_variable_param, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
     
     error = ex_put_variable_names (exoid, EX_NODE_SET, num_nset_vars, variable_names);
     printf ("after ex_put_variable_names, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
   
   {
     num_sset_vars = 3;

     variable_names[0] = "ss_var0";
     variable_names[1] = "ss_var1";
     variable_names[2] = "ss_var2";
     
     error = ex_put_variable_param (exoid, EX_SIDE_SET, num_sset_vars);
     printf ("after ex_put_variable_param, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
     
     error = ex_put_variable_names (exoid, EX_SIDE_SET, num_sset_vars, variable_names);
     printf ("after ex_put_variable_names, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }



/* write element variable truth table */

   truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));

   k = 0;
   for (i=0; i<num_elem_blk; i++)
   {
      for (j=0; j<num_ele_vars; j++)
      {
         truth_tab[k++] = 1;
      }
   }

   error = ex_put_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab);
   printf ("after ex_put_elem_var_tab, error = %d\n", error);

   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   free (truth_tab);


/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 * obviously the analysis code will populate these arrays
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
   elem_var_vals = (float *) calloc (4, CPU_word_size);
   sset_var_vals = (float *) calloc (10, CPU_word_size);
   nset_var_vals = (float *) calloc (10, CPU_word_size);
   
   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

/* write time value */

     error = ex_put_time (exoid, whole_time_step, &time_value);
     printf ("after ex_put_time, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

/* write global variables */

     for (j=0; j<num_glo_vars; j++)
     {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
                               glob_var_vals);
     printf ("after ex_put_glob_vars, error = %d\n", error);

     if (error) {
       ex_close (exoid);
       exit(-1);
     }

/* write nodal variables */

     for (k=1; k<=num_nod_vars; k++)
     {
       for (j=0; j<num_nodes; j++)
       {
         nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
       }

       error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes,
                                 nodal_var_vals);
       printf ("after ex_put_nodal_var, error = %d\n", error);
       if (error) {
         ex_close (exoid);
         exit(-1);
       }

     }

/* write element variables */

     for (k=1; k<=num_ele_vars; k++)
     {
       for (j=0; j<num_elem_blk; j++)
       {
         for (m=0; m<num_elem_in_block[j]; m++)
         {
           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
                              ((float)(m+1)*time_value);
           /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
         }
         error = ex_put_elem_var (exoid, whole_time_step, k, ebids[j],
                                  num_elem_in_block[j], elem_var_vals);
         printf ("after ex_put_elem_var, error = %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

/* write sideset variables */

     for (k=1; k<=num_sset_vars; k++)
     {
       for (j=0; j<num_side_sets; j++)
       {
         for (m=0; m<num_face_in_sset[j]; m++)
         {
           sset_var_vals[m] = (float)(k+2) + (float)(j+3) + 
                              ((float)(m+1)*time_value);
           /* printf("sset_var_vals[%d]: %f\n",m,sset_var_vals[m]); */
         }
         error = ex_put_sset_var (exoid, whole_time_step, k, ssids[j],
                                  num_face_in_sset[j], sset_var_vals);
         printf ("after ex_put_sset_var, error = %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

/* write nodeset variables */

     for (k=1; k<=num_nset_vars; k++)
     {
       for (j=0; j<num_node_sets; j++)
       {
         for (m=0; m<num_nodes_in_nset[j]; m++)
         {
           nset_var_vals[m] = (float)(k+3) + (float)(j+4) + 
                              ((float)(m+1)*time_value);
           /* printf("nset_var_vals[%d]: %f\n",m,nset_var_vals[m]); */
         }
         error = ex_put_nset_var (exoid, whole_time_step, k, nsids[j],
                                  num_nodes_in_nset[j], nset_var_vals);
         printf ("after ex_put_nset_var, error = %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

     whole_time_step++;

/* update the data file; this should be done at the end of every time step
 * to ensure that no data is lost if the analysis dies
 */
     error = ex_update (exoid);
     printf ("after ex_update, error = %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
   free(glob_var_vals);
   free(nodal_var_vals);
   free(elem_var_vals);
   free(sset_var_vals);
   free(nset_var_vals);


/* close the EXODUS files
 */
   error = ex_close (exoid);
   printf ("after ex_close, error = %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }
   return 0;
}
示例#20
0
文件: twod.c 项目: 00liujj/trilinos
int main (int argc, char **argv)
{
  int num_glo_vars = 10;
  int num_nod_vars = 2;
  int CPU_word_size = 8; 
  int IO_word_size = 8;
  const char* title = "This is a 2D mesh example with tri, quad, beam, truss, circle";
  int ebids[] = {100, 200, 300, 400, 500};
  int num_dim   =  2;
  int num_nodes = 13;
  int num_elem  = 20;
  int num_elem_blk = 5;
  int num_node_sets = 2;
  int num_side_sets = 2;

  /* create EXODUS II file */
  int exoid = ex_create ("twod.e",       /* filename path */
			 EX_CLOBBER,      /* create mode */
			 &CPU_word_size,  /* CPU float word size in bytes */
			 &IO_word_size);  /* I/O float word size in bytes */

   ex_opts(EX_VERBOSE);

   /* initialize file with parameters */
     ex_put_init (exoid, title, num_dim, num_nodes, num_elem,
			  num_elem_blk, num_node_sets, num_side_sets);

     /* write nodal coordinates values and names to database */
     {
       double x[13], y[13];
       x[0]  =  0.0; y[0]  =  0.0;
       x[1]  = -0.5; y[1]  = -0.5;
       x[2]  =  0.5; y[2]  = -0.5;
       x[3]  =  0.5; y[3]  =  0.5;
       x[4]  = -0.5; y[4]  =  0.5;
       x[5]  = -1.0; y[5]  = -1.0;
       x[6]  =  1.0; y[6]  = -1.0;
       x[7]  =  1.0; y[7]  =  1.0;
       x[8]  = -1.0; y[8]  =  1.0;
       x[9]  = -2.0; y[9]  =  0.0;
       x[10] =  0.0; y[10] = -2.0;
       x[11] =  2.0; y[11] =  0.0;
       x[12] =  0.0; y[12] =  2.0;

       ex_put_coord (exoid, x, y, 0);
     }

     {
       const char* coord_names[] = {"xcoor", "ycoor"};
       ex_put_coord_names (exoid, (char**)coord_names);
     }


     {
       int node_map[] = {10,20,30,40,50,60,70,80,90,100,110,120,130};
       ex_put_node_num_map(exoid, node_map);
     }

     /* write element order map */
     {
       int elem_map[] = {11,21,31,41, 52, 62, 72, 82, 93,103,113,123,133,143,153,163,  174,184,194,204};
       ex_put_elem_num_map (exoid, elem_map);
     }

     /* write element block parameters */
     {
       const char* block_names[] = {"Triangles", "Quadrilaterals", "", "Trusses", "Circles"};
       int num_elem_in_block[] = {4, 4, 4, 4, 4};
       int num_nodes_per_elem[] = {3, 4, 2, 2, 1};

       ex_put_elem_block (exoid, ebids[0], "triangle", num_elem_in_block[0], num_nodes_per_elem[0], 0);
       ex_put_elem_block (exoid, ebids[1], "quad",     num_elem_in_block[1], num_nodes_per_elem[1], 0);
       ex_put_elem_block (exoid, ebids[2], "beam",     num_elem_in_block[2], num_nodes_per_elem[2], 3);
       ex_put_elem_block (exoid, ebids[3], "truss",    num_elem_in_block[3], num_nodes_per_elem[3], 1);
       ex_put_elem_block (exoid, ebids[4], "circle",   num_elem_in_block[4], num_nodes_per_elem[4], 2);

       /* Write element block names */
       ex_put_names(exoid, EX_ELEM_BLOCK, (char**)block_names);
     }

     /* write element connectivity */
     {
       int conn_t[] = {2,3,1,  3,4,1,  4,5,1,  5,2,1};
       int conn_q[] = {6,7,3,2,  7,8,4,3,  8,9,5,4,  9,6,2,5};
       int conn_B[] = {11,7,  8,13,  13,9,  6,11};
       int conn_T[] = {10,6,  9,10,  7,12,  12,8};
       int conn_c[] = {6,7,8,9};
       
       ex_put_elem_conn (exoid, ebids[0], conn_t);
       ex_put_elem_conn (exoid, ebids[1], conn_q);
       ex_put_elem_conn (exoid, ebids[2], conn_B);
       ex_put_elem_conn (exoid, ebids[3], conn_T);
       ex_put_elem_conn (exoid, ebids[4], conn_c);
     }

     /* write element block attributes */
     {
       const char* attn_T[] = {"Area"};
       double attr_T[] = {1.0, 1.1, 1.2, 1.3};

       const char* attn_B[] = {"A", "I", "J"};
       double attr_B[] = {1.0, 100.0, 200.0,   1.1, 100.1, 200.1,  1.2, 100.2, 200.2,  1.3, 100.3, 200.3};

       const char* attn_c[] = {"Radius", "A"};
       double attr_c[] = {1.0, 3.14, 1.1, 4.14, 1.2, 5.14, 1.3, 6.14};
     
       ex_put_elem_attr (exoid, ebids[2], attr_B);
       ex_put_elem_attr (exoid, ebids[3], attr_T);
       ex_put_elem_attr (exoid, ebids[4], attr_c);

       ex_put_elem_attr_names (exoid, ebids[2], (char**)attn_B);
       ex_put_elem_attr_names (exoid, ebids[3], (char**)attn_T);
       ex_put_elem_attr_names (exoid, ebids[4], (char**)attn_c);
     }

     /* write individual node sets */
     {
       int num_nodes_in_nset[] = {5, 8};
       int nsids[] = {20, 22};
       int nod1[] = {5,4,3,2,1};
       int nod2[] = {6,7,8,9,2,3,4,5};
       const char* nset_names[] = {"Triangle_Nodes", "Quadrilateral_Nodes"};

       ex_put_set_param (exoid, EX_NODE_SET, nsids[0], num_nodes_in_nset[0], 0);
       ex_put_set_param (exoid, EX_NODE_SET, nsids[1], num_nodes_in_nset[1], 0);

       ex_put_set (exoid, EX_NODE_SET, nsids[0], nod1, 0);
       ex_put_set (exoid, EX_NODE_SET, nsids[1], nod2, 0);
       ex_put_names(exoid, EX_NODE_SET, (char**)nset_names);
     }

     {
       /* write individual side sets */
       int num_face_in_sset[] =  {4,4};
       int ssids[] = {100,200};
       int ss1el[] = {1,2,3,4};
       int ss1si[] = {1,1,1,1};
       
       int ss2el[] = {5,7,6,8};
       int ss2si[] = {1,1,1,1};
       const char* sset_names[] = {"A", "B"};
       
       ex_put_set_param (exoid, EX_SIDE_SET, ssids[0], num_face_in_sset[0], 0);
       ex_put_set_param (exoid, EX_SIDE_SET, ssids[1], num_face_in_sset[1], 0);
       
       ex_put_set (exoid, EX_SIDE_SET, ssids[0], ss1el, ss1si);
       ex_put_set (exoid, EX_SIDE_SET, ssids[1], ss2el, ss2si);
       ex_put_names(exoid, EX_SIDE_SET, (char**)sset_names);
     }


     /* write results variables parameters and names */
     {
       const char* gvarn[] = {"g_01", "g_02", "g_03", "g_04", "g_05", "g_06", "g_07", "g_08", "g_09", "g_10"};
       ex_put_variable_param (exoid, EX_GLOBAL, num_glo_vars);
       ex_put_variable_names (exoid, EX_GLOBAL, num_glo_vars, (char**)gvarn);
     }

     {
       const char* nvarn[] = {"disp_x", "disp_y"};
       ex_put_variable_param (exoid, EX_NODAL, num_nod_vars);
       ex_put_variable_names (exoid, EX_NODAL, num_nod_vars, (char**)nvarn);
     }

     
#if 0
   num_ele_vars = 3;
   /*              0        1         2         3   */
   /*              12345678901234567890123456789012 */
   var_names[0] = "this_variable_name_is_short";
   var_names[1] = "this_variable_name_is_just_right";
   var_names[2] = "this_variable_name_is_tooooo_long";

   ex_put_var_param (exoid, "e", num_ele_vars);
   printf ("after ex_put_var_param, %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   ex_put_var_names (exoid, "e", num_ele_vars, var_names);
   printf ("after ex_put_var_names, %d\n", error);
   if (error) {
     ex_close (exoid);
     exit(-1);
   }

   {
     num_nset_vars = 3;
     
     var_names[0] = "ns_var0";
     var_names[1] = "ns_var1";
     var_names[2] = "ns_var2";
     
     ex_put_var_param (exoid, "m", num_nset_vars);
     printf ("after ex_put_var_param, %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
     
     ex_put_var_names (exoid, "m", num_nset_vars, var_names);
     printf ("after ex_put_var_names, %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
   
   {
     num_sset_vars = 3;

     var_names[0] = "ss_var0";
     var_names[1] = "ss_var1";
     var_names[2] = "ss_var2";
     
     ex_put_var_param (exoid, "s", num_sset_vars);
     printf ("after ex_put_var_param, %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
     
     ex_put_var_names (exoid, "s", num_sset_vars, var_names);
     printf ("after ex_put_var_names, %d\n", error);
     if (error) {
       ex_close (exoid);
       exit(-1);
     }
   }
#endif
   
   /* for each time step, write the analysis results;
    * the code below fills the arrays glob_var_vals, 
    * nodal_var_vals, and elem_var_vals with values for debugging purposes;
    * obviously the analysis code will populate these arrays
    */

   {
     int i, j, k;
     int whole_time_step = 1;
     int num_time_steps = 10;

     double gvar[10];
     double nvar[20];
   
     for (i=0; i<num_time_steps; i++) {
       double time_value = (double)(i)/100.;

       ex_put_time (exoid, whole_time_step, &time_value);

       for (j=0; j<num_glo_vars; j++) {
	 gvar[j] = (double)(j+2) * time_value;
       }
       ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, gvar);

       /* write nodal variables */
       for (k=0; k < num_nod_vars; k++) {
	 for (j=0; j<num_nodes; j++) {
	   nvar[j] = (double)k + ((double)(j+1) * time_value);
	 }
	 
	 ex_put_nodal_var (exoid, whole_time_step, k+1, num_nodes, nvar);
       }
       
#if 0
/* write element variables */

     for (k=1; k<=num_ele_vars; k++)
     {
       for (j=0; j<num_elem_blk; j++)
       {
         for (m=0; m<num_elem_in_block[j]; m++)
         {
           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
                              ((float)(m+1)*time_value);
           /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
         }
         ex_put_elem_var (exoid, whole_time_step, k, ebids[j],
                                  num_elem_in_block[j], elem_var_vals);
         printf ("after ex_put_elem_var, %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

/* write sideset variables */

     for (k=1; k<=num_sset_vars; k++)
     {
       for (j=0; j<num_side_sets; j++)
       {
         for (m=0; m<num_face_in_sset[j]; m++)
         {
           sset_var_vals[m] = (float)(k+2) + (float)(j+3) + 
                              ((float)(m+1)*time_value);
           /* printf("sset_var_vals[%d]: %f\n",m,sset_var_vals[m]); */
         }
         ex_put_sset_var (exoid, whole_time_step, k, ssids[j],
                                  num_face_in_sset[j], sset_var_vals);
         printf ("after ex_put_sset_var, %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }

/* write nodeset variables */

     for (k=1; k<=num_nset_vars; k++)
     {
       for (j=0; j<num_node_sets; j++)
       {
         for (m=0; m<num_nodes_in_nset[j]; m++)
         {
           nset_var_vals[m] = (float)(k+3) + (float)(j+4) + 
                              ((float)(m+1)*time_value);
           /* printf("nset_var_vals[%d]: %f\n",m,nset_var_vals[m]); */
         }
         ex_put_nset_var (exoid, whole_time_step, k, nsids[j],
                                  num_nodes_in_nset[j], nset_var_vals);
         printf ("after ex_put_nset_var, %d\n", error);
         if (error) {
           ex_close (exoid);
           exit(-1);
         }
       }
     }
#endif

     whole_time_step++;
   }
   }
   ex_close (exoid);
   return 0;
}
示例#21
0
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10], num_nodes_per_elem[10];
   int num_node_sets, num_sides, num_side_sets, error;
   int i, j, k, m, *elem_map, *connect;
   int node_list[100],elem_list[100],side_list[100];
   int ebids[10], ids[10];
   int num_sides_per_set[10], num_nodes_per_set[10], num_elem_per_set[10];
   int num_df_per_set[10];
   int df_ind[10], node_ind[10], elem_ind[10], side_ind[10];
   int  num_qa_rec, num_info;
   int num_glo_vars, num_nod_vars, num_ele_vars;
   int *truth_tab;
   int whole_time_step, num_time_steps;
   int ndims, nvars, ngatts, recdim;
   int CPU_word_size,IO_word_size;
   int prop_array[2];

   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
   float time_value;
   float *x, *y, *z, *dummy;
   float attrib[1], dist_fact[100];
   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
   char tmpstr[80];
   char *prop_names[2];

   ex_opts (EX_VERBOSE | EX_ABORT);

   dummy = 0; /* assign this so the Cray compiler doesn't complain */

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("test.exo",       /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

/* initialize file with parameters */

   num_dim = 3;
   num_nodes = BIG;
   num_elem = BIG;
   num_elem_blk = 5;
   num_node_sets = 2;
   num_side_sets = 5;

   error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem,
                        num_elem_blk, num_node_sets, num_side_sets);

   printf ("after ex_put_init, error = %d\n", error);

/* write nodal coordinates values and names to database */

   if (!(x = (float *) calloc(BIG, sizeof(float))))
   {
     printf ("couldn't allocate memory for x node array%d\n");
     exit(1);
   }

   if (!(y = (float *) calloc(BIG, sizeof(float))))
   {
     printf ("couldn't allocate memory for y node array%d\n");
     exit(1);
   }

   if (!(z = (float *) calloc(BIG, sizeof(float))))
   {
     printf ("couldn't allocate memory for z node array%d\n");
     exit(1);
   }

   for (i=0; i<num_nodes; i++)
   {
     /* dummy up the coordinate space */
     x[i]=i;
     y[i]=i+.1;
     z[i]=i+.2;
   }

   error = ex_put_coord (exoid, x, y, z);
   printf ("after ex_put_coord, error = %d\n", error);


   coord_names[0] = "xcoor";
   coord_names[1] = "ycoor";
   coord_names[2] = "zcoor";

   error = ex_put_coord_names (exoid, coord_names);
   printf ("after ex_put_coord_names, error = %d\n", error);


/* write element order map */

   elem_map = (int *) calloc(num_elem, sizeof(int));

   for (i=1; i<=num_elem; i++)
   {
      elem_map[i-1] = i;
   }

   error = ex_put_map (exoid, elem_map);
   printf ("after ex_put_map, error = %d\n", error);

   free (elem_map);


/* write element block parameters */

   num_elem_in_block[0] = 1;
   num_elem_in_block[1] = 1;
   num_elem_in_block[2] = 1;
   num_elem_in_block[3] = 1;
   num_elem_in_block[4] = 1;

   num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
   num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
   num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
   num_nodes_per_elem[3] = 4; /* elements in block #3 are 4-node tetras */
   num_nodes_per_elem[4] = 6; /* elements in block #3 are 6-node wedges */

   ebids[0] = 10;
   ebids[1] = 11;
   ebids[2] = 12;
   ebids[3] = 13;
   ebids[4] = 14;

   error = ex_put_elem_block (exoid, ebids[0], "quad", num_elem_in_block[0],
                              num_nodes_per_elem[0], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   error = ex_put_elem_block (exoid, ebids[1], "quad", num_elem_in_block[1],
                               num_nodes_per_elem[1], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   error = ex_put_elem_block (exoid, ebids[2], "hex", num_elem_in_block[2],
                               num_nodes_per_elem[2], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   error = ex_put_elem_block (exoid, ebids[3], "tetra", num_elem_in_block[3],
                               num_nodes_per_elem[3], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

   error = ex_put_elem_block (exoid, ebids[4], "wedge", num_elem_in_block[4],
                               num_nodes_per_elem[4], 1);
   printf ("after ex_put_elem_block, error = %d\n", error);

/* write element block properties */

   prop_names[0] = "MATL";
   prop_names[1] = "DENSITY";
   error = ex_put_prop_names(exoid,EX_ELEM_BLOCK,2,prop_names);
   printf ("after ex_put_prop_names, error = %d\n", error);

   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10);
   printf ("after ex_put_prop, error = %d\n", error);
   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20);
   printf ("after ex_put_prop, error = %d\n", error);
   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30);
   printf ("after ex_put_prop, error = %d\n", error);
   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40);
   printf ("after ex_put_prop, error = %d\n", error);
   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50);
   printf ("after ex_put_prop, error = %d\n", error);

/* write element connectivity */

   connect = (int *) calloc(8, sizeof(int));
   connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;

   error = ex_put_elem_conn (exoid, ebids[0], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   connect[0] = 5; connect[1] = 6; connect[2] = 7; connect[3] = 8;

   error = ex_put_elem_conn (exoid, ebids[1], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12;
   connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16;

   error = ex_put_elem_conn (exoid, ebids[2], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;

   error = ex_put_elem_conn (exoid, ebids[3], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   connect[0] = 21; connect[1] = 22; connect[2] = 23;
   connect[3] = 24; connect[4] = 25; connect[5] = 26;

   error = ex_put_elem_conn (exoid, ebids[4], connect);
   printf ("after ex_put_elem_conn, error = %d\n", error);

   free (connect);


/* write element block attributes */

   attrib[0] = 3.14159;
   error = ex_put_elem_attr (exoid, ebids[0], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   attrib[0] = 6.14159;
   error = ex_put_elem_attr (exoid, ebids[1], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   error = ex_put_elem_attr (exoid, ebids[2], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   error = ex_put_elem_attr (exoid, ebids[3], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

   error = ex_put_elem_attr (exoid, ebids[4], attrib);
   printf ("after ex_put_elem_attr, error = %d\n", error);

/* write individual node sets */


   error = ex_put_node_set_param (exoid, 20, 5, 5);
   printf ("after ex_put_node_set_param, error = %d\n", error);

   node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; 
   node_list[3] = 13; node_list[4] = 14; 

   dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0;
   dist_fact[3] = 4.0; dist_fact[4] = 5.0;

   error = ex_put_node_set (exoid, 20, node_list);
   printf ("after ex_put_node_set, error = %d\n", error);
   error = ex_put_node_set_dist_fact (exoid, 20, dist_fact);
   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);

   error = ex_put_node_set_param (exoid, 21, 3, 3);
   printf ("after ex_put_node_set_param, error = %d\n", error);

   node_list[0] = 20; node_list[1] = 21; node_list[2] = 22; 

   dist_fact[0] = 1.1; dist_fact[1] = 2.1; dist_fact[2] = 3.1;

   error = ex_put_node_set (exoid, 21, node_list);
   printf ("after ex_put_node_set, error = %d\n", error);
   error = ex_put_node_set_dist_fact (exoid, 21, dist_fact);
   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);

   error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
   printf ("after ex_put_prop, error = %d\n", error);
   error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
   printf ("after ex_put_prop, error = %d\n", error);

   prop_array[0] = 1000;
   prop_array[1] = 2000;

   error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
   printf ("after ex_put_prop_array, error = %d\n", error);


/* write concatenated node sets; this produces the same information as
 * the above code which writes individual node sets
 */

/* THIS SECTION IS COMMENTED OUT

   ids[0] = 20; ids[1] = 21;

   num_nodes_per_set[0] = 5; num_nodes_per_set[1] = 3;

   node_ind[0] = 0; node_ind[1] = 5;

   node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; 
   node_list[3] = 13; node_list[4] = 14; 
   node_list[5] = 20; node_list[6] = 21; node_list[7] = 22;

   num_df_per_set[0] = 5; num_df_per_set[1] = 3;

   df_ind[0] = 0; df_ind[1] = 5;

   dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0; 
   dist_fact[3] = 4.0; dist_fact[4] = 5.0; 
   dist_fact[5] = 1.1; dist_fact[6] = 2.1; dist_fact[7] = 3.1;

   error = ex_put_concat_node_sets (exoid, ids, num_nodes_per_set,
                                    num_df_per_set, node_ind,
                                    df_ind, node_list, dist_fact);
   printf ("after ex_put_concat_node_sets, error = %d\n", error);

   error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
   printf ("after ex_put_prop, error = %d\n", error);
   error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
   printf ("after ex_put_prop, error = %d\n", error);

   prop_array[0] = 1000;
   prop_array[1] = 2000;

   error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
   printf ("after ex_put_prop_array, error = %d\n", error);

   END COMMENTED OUT SECTION */


/* write individual side sets */

   /* side set #1  - quad */

   error = ex_put_side_set_param (exoid, 30, 2, 4);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   elem_list[0] = 2; elem_list[1] = 2;

   side_list[0] = 4; side_list[1] = 2;

   dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2;
   dist_fact[3] = 30.3;

   error = ex_put_side_set (exoid, 30, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   error = ex_put_side_set_dist_fact (exoid, 30, dist_fact);
   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);


   /* side set #2  - quad, spanning 2 elements  */

   error = ex_put_side_set_param (exoid, 31, 2, 4);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   elem_list[0] = 1; elem_list[1] = 2;

   side_list[0] = 2; side_list[1] = 3;

   dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2;
   dist_fact[3] = 31.3;

   error = ex_put_side_set (exoid, 31, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   error = ex_put_side_set_dist_fact (exoid, 31, dist_fact);
   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);


   /* side set #3  - hex */

   error = ex_put_side_set_param (exoid, 32, 7, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   elem_list[0] = 3; elem_list[1] = 3;
   elem_list[2] = 3; elem_list[3] = 3;
   elem_list[4] = 3; elem_list[5] = 3;
   elem_list[6] = 3;

   side_list[0] = 5; side_list[1] = 3;
   side_list[2] = 3; side_list[3] = 2;
   side_list[4] = 4; side_list[5] = 1;
   side_list[6] = 6;

   error = ex_put_side_set (exoid, 32, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);


   /* side set #4  - tetras */

   error = ex_put_side_set_param (exoid, 33, 4, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   elem_list[0] = 4; elem_list[1] = 4;
   elem_list[2] = 4; elem_list[3] = 4;

   side_list[0] = 1; side_list[1] = 2;
   side_list[2] = 3; side_list[3] = 4;

   error = ex_put_side_set (exoid, 33, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);


   /* side set #5  - wedges */

   error = ex_put_side_set_param (exoid, 34, 5, 0);
   printf ("after ex_put_side_set_param, error = %d\n", error);

   elem_list[0] = 5; elem_list[1] = 5;
   elem_list[2] = 5; elem_list[3] = 5;
   elem_list[4] = 5;

   side_list[0] = 1; side_list[1] = 2;
   side_list[2] = 3; side_list[3] = 4;
   side_list[4] = 5;

   error = ex_put_side_set (exoid, 34, elem_list, side_list);
   printf ("after ex_put_side_set, error = %d\n", error);

   /* END COMMENTED OUT SECTION */

/* write concatenated side sets; this produces the same information as
 * the above code which writes individual side sets
 */

/* THIS SECTION IS COMMENTED OUT

   ids[0] = 30;
   ids[1] = 31;
   ids[2] = 32;
   ids[3] = 33;
   ids[4] = 34;

   node_list[0] = 8; node_list[1] = 5;
   node_list[2] = 6; node_list[3] = 7;

   node_list[4] = 2; node_list[5] = 3;
   node_list[6] = 7; node_list[7] = 8;

   node_list[8] = 9; node_list[9] = 12;
   node_list[10] = 11; node_list[11] = 10;

   node_list[12] = 11; node_list[13] = 12;
   node_list[14] = 16; node_list[15] = 15;
 
   node_list[16] = 16; node_list[17] = 15;
   node_list[18] = 11; node_list[19] = 12;

   node_list[20] = 10; node_list[21] = 11;
   node_list[22] = 15; node_list[23] = 14;

   node_list[24] = 13; node_list[25] = 16;
   node_list[26] = 12; node_list[27] =  9;

   node_list[28] = 14; node_list[29] = 13;
   node_list[30] =  9; node_list[31] = 10;

   node_list[32] = 16; node_list[33] = 13;
   node_list[34] = 14; node_list[35] = 15;

   node_list[36] = 17; node_list[37] = 18;
   node_list[38] = 20;

   node_list[39] = 18; node_list[40] = 19;
   node_list[41] = 20;

   node_list[42] = 20; node_list[43] = 19;
   node_list[44] = 17;

   node_list[45] = 19; node_list[46] = 18;
   node_list[47] = 17;

   node_list[48] = 25; node_list[49] = 24;
   node_list[50] = 21; node_list[51] = 22;

   node_list[52] = 26; node_list[53] = 25;
   node_list[54] = 22; node_list[55] = 23;

   node_list[56] = 26; node_list[57] = 23;
   node_list[58] = 21; node_list[59] = 24;

   node_list[60] = 23; node_list[61] = 22;
   node_list[62] = 21;

   node_list[63] = 24; node_list[64] = 25;
   node_list[65] = 26;

   node_ind[0] = 0;
   node_ind[1] = 4;
   node_ind[2] = 8;
   node_ind[3] = 36;
   node_ind[4] = 47;

   num_elem_per_set[0] = 2;
   num_elem_per_set[1] = 2;
   num_elem_per_set[2] = 7;
   num_elem_per_set[3] = 4;
   num_elem_per_set[4] = 5;

   num_nodes_per_set[0] = 4;
   num_nodes_per_set[1] = 4;
   num_nodes_per_set[2] = 28;
   num_nodes_per_set[3] = 12;
   num_nodes_per_set[4] = 18;

   elem_ind[0] = 0;
   elem_ind[1] = 2;
   elem_ind[2] = 4;
   elem_ind[3] = 11;
   elem_ind[4] = 15;

   elem_list[0] = 2; elem_list[1] = 2;
   elem_list[2] = 1; elem_list[3] = 2;
   elem_list[4] = 3; elem_list[5] = 3;
   elem_list[6] = 3; elem_list[7] = 3;
   elem_list[8] = 3; elem_list[9] = 3;
   elem_list[10] = 3; elem_list[11] = 4;
   elem_list[12] = 4; elem_list[13] = 4;
   elem_list[14] = 4; elem_list[15] = 5;
   elem_list[16] = 5; elem_list[17] = 5;
   elem_list[18] = 5; elem_list[19] = 5;

   error = ex_cvt_nodes_to_sides(exoid,
                         num_elem_per_set,
                         num_nodes_per_set,
                         elem_ind,
                         node_ind,
                         elem_list,
                         node_list,
                         side_list);
   printf ("after ex_cvt_nodes_to_sides, error = %d\n", error);

   num_df_per_set[0] = 4;
   num_df_per_set[1] = 4;
   num_df_per_set[2] = 0;
   num_df_per_set[3] = 0;
   num_df_per_set[4] = 0;

   df_ind[0] = 0;
   df_ind[1] = 4;

   dist_fact[0] = 30.0; dist_fact[1] = 30.1;
   dist_fact[2] = 30.2; dist_fact[3] = 30.3;

   dist_fact[4] = 31.0; dist_fact[5] = 31.1;
   dist_fact[6] = 31.2; dist_fact[7] = 31.3;

   error = ex_put_concat_side_sets (exoid, ids, num_elem_per_set,
                                    num_df_per_set, elem_ind, df_ind,
                                    elem_list, side_list, dist_fact);
   printf ("after ex_put_concat_side_sets, error = %d\n", error);

   /* END COMMENTED OUT SECTION */

   error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
   printf ("after ex_put_prop, error = %d\n", error);

   error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
   printf ("after ex_put_prop, error = %d\n", error);


/* write QA records */

   num_qa_rec = 2;


   qa_record[0][0] = "TESTWT";
   qa_record[0][1] = "testwt";
   qa_record[0][2] = "07/07/93";
   qa_record[0][3] = "15:41:33";
   qa_record[1][0] = "FASTQ";
   qa_record[1][1] = "fastq";
   qa_record[1][2] = "07/07/93";
   qa_record[1][3] = "16:41:33";

   error = ex_put_qa (exoid, num_qa_rec, qa_record);
   printf ("after ex_put_qa, error = %d\n", error);


/* write information records */

   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "This is the second information record.";
   info[2] = "This is the third information record.";

   error = ex_put_info (exoid, num_info, info);
   printf ("after ex_put_info, error = %d\n", error);



/* write results variables parameters and names */

   num_glo_vars = 1;

   var_names[0] = "glo_vars";

   error = ex_put_var_param (exoid, "g", num_glo_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   error = ex_put_var_names (exoid, "g", num_glo_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);


   num_nod_vars = 2;

   var_names[0] = "nod_var0";
   var_names[1] = "nod_var1";

   error = ex_put_var_param (exoid, "n", num_nod_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   error = ex_put_var_names (exoid, "n", num_nod_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);

   num_ele_vars = 3;

   var_names[0] = "ele_var0";
   var_names[1] = "ele_var1";
   var_names[2] = "ele_var2";

   error = ex_put_var_param (exoid, "e", num_ele_vars);
   printf ("after ex_put_var_param, error = %d\n", error);
   error = ex_put_var_names (exoid, "e", num_ele_vars, var_names);
   printf ("after ex_put_var_names, error = %d\n", error);


/* write element variable truth table */

   truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));

   k = 0;
   for (i=0; i<num_elem_blk; i++)
   {
      for (j=0; j<num_ele_vars; j++)
      {
         truth_tab[k++] = 1;
      }
   }

   error = ex_put_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab);
   printf ("after ex_put_elem_var_tab, error = %d\n", error);

   free (truth_tab);


/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 * obviously the analysis code will populate these arrays
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
   elem_var_vals = (float *) calloc (4, CPU_word_size);

   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

/* write time value */

     error = ex_put_time (exoid, whole_time_step, &time_value);
     printf ("after ex_put_time, error = %d\n", error);

/* write global variables */

     for (j=0; j<num_glo_vars; j++)
     {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
                               glob_var_vals);
     printf ("after ex_put_glob_vars, error = %d\n", error);

/* write nodal variables */

     for (k=1; k<=num_nod_vars; k++)
     {
       for (j=0; j<num_nodes; j++)
       {
         nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
       }

       error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes,
                                 nodal_var_vals);
       printf ("after ex_put_nodal_var, error = %d\n", error);
     }

/* write element variables */

     for (k=1; k<=num_ele_vars; k++)
     {
       for (j=0; j<num_elem_blk; j++)
       {
         for (m=0; m<num_elem_in_block[j]; m++)
         {
           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
                              ((float)(m+1)*time_value);
           /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
         }
         error = ex_put_elem_var (exoid, whole_time_step, k, ebids[j],
                                  num_elem_in_block[j], elem_var_vals);
         printf ("after ex_put_elem_var, error = %d\n", error);
       }
     }

     whole_time_step++;

/* update the data file; this should be done at the end of every time step
 * to ensure that no data is lost if the analysis dies
 */
     error = ex_update (exoid);
     printf ("after ex_update, error = %d\n", error);
   }
   free(glob_var_vals);
   free(nodal_var_vals);
   free(elem_var_vals);


/* close the EXODUS files
 */
   error = ex_close (exoid);
   printf ("after ex_close, error = %d\n", error);
   return 0;
}
示例#22
0
文件: wr_exo.c 项目: goma/goma
void 
wr_resetup_exo(Exo_DB *exo,
	       char *filename,
	       int verbosity)
{
  int error;
  int i;
  int status;

  /*
   * This file must already exist.
   */

  exo->cmode = EX_WRITE;

#ifdef DEBUG
  fprintf(stderr, "%s: begins\n", yo);
#endif

  exo->io_wordsize   = 0;	/* i.e., query */
  exo->comp_wordsize = sizeof(dbl);
  exo->exoid         = ex_open(filename, exo->cmode, &exo->comp_wordsize, 
			       &exo->io_wordsize, &exo->version);

#ifdef DEBUG
  fprintf(stderr, "\t\tfilename    = \"%s\"\n", filename);
  fprintf(stderr, "\t\tcomp_ws     = %d\n", exo->comp_wordsize);
  fprintf(stderr, "\t\tio_wordsize = %d\n", exo->io_wordsize);
#endif

  /*
   * Results setup...
   */

  if ( exo->num_glob_vars > 0 )
    {
      status = ex_put_variable_param(exo->exoid, EX_GLOBAL, exo->num_glob_vars);
      EH(status, "ex_put_variable_param global");
      status = ex_put_variable_names(exo->exoid, EX_GLOBAL, exo->num_glob_vars,
				exo->glob_var_names);
      EH(status, "ex_put_variable_names global");
    }

  if ( exo->num_elem_vars > 0 )
    {
      status = ex_put_variable_param(exo->exoid, EX_ELEM_BLOCK, exo->num_elem_vars);
      EH(status, "ex_put_variable_param elem block");
      status = ex_put_variable_names(exo->exoid, EX_ELEM_BLOCK,
				     exo->num_elem_vars,
				     exo->elem_var_names);
      EH(status, "ex_put_variable_names elem block");
      status = ex_put_truth_table(exo->exoid, EX_ELEM_BLOCK,
				   exo->num_elem_blocks,
				   exo->num_elem_vars, 
				   exo->elem_var_tab);
      EH(status, "ex_put_truth_table elem block");
    }

  if ( exo->num_node_vars > 0 )
    {
      status = ex_put_variable_param(exo->exoid, EX_NODAL, exo->num_node_vars);
      EH(status, "ex_put_variable_param nodal");
      status = ex_put_variable_names(exo->exoid, EX_NODAL,
				exo->num_node_vars,
				exo->node_var_names);
      EH(status, "ex_put_variable_names nodal");
    }

  if ( exo->num_times > 0 )
    {
      for ( i=0; i<exo->num_times; i++)
	{
	  status = ex_put_time(exo->exoid, i+1, &(exo->time_vals[i]));
	  EH(status, "ex_put_times");
	}
    }

  error      = ex_close(exo->exoid);
  if ( error != 0 ) exit(2);
  return;
}