Example #1
0
int main (int argc, char **argv)
{
   int exoid, exoid1, error, idum;
   int CPU_word_size,IO_word_size;

   float version;

   char *cdum = 0;

   ex_opts(EX_VERBOSE | EX_ABORT);

/* open EXODUS II files */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 0;                    /* use size in file */

   exoid = ex_open ("test.exo",         /* filename path */
                     EX_READ,           /* access mode = READ */
                     &CPU_word_size,    /* CPU word size */
                     &IO_word_size,     /* IO word size */
                     &version);         /* ExodusII library version */

   printf ("\nafter ex_open\n");
   if (exoid < 0) exit(1);

   printf ("test.exo is an EXODUSII file; version %4.2f\n",
            version);
   printf ("         CPU word size %1d\n",CPU_word_size);
   printf ("         I/O word size %1d\n",IO_word_size);
   ex_inquire(exoid,EX_INQ_API_VERS, &idum, &version, cdum);
   printf ("EXODUSII API; version %4.2f\n", version);

   CPU_word_size = 8;                   /* this really shouldn't matter for
                                           the copy but tests the conversion
                                           routines */
   IO_word_size = 4;

   exoid1 = ex_create ("testcp.exo",    /* filename */
                        EX_CLOBBER|EX_NORMAL_MODEL,     /* OK to overwrite, normal */
                        &CPU_word_size, /* CPU float word size in bytes */
                        &IO_word_size); /* I/O float word size in bytes */

   printf ("\nafter ex_create, exoid = %3d\n",exoid1);
   if (exoid1 < 0) exit(1);

   printf ("         CPU word size %1d\n",CPU_word_size);
   printf ("         I/O word size %1d\n",IO_word_size);

   /* ncopts = NC_VERBOSE; */

   error = ex_copy (exoid, exoid1);
   printf ("\nafter ex_copy, error = %3d\n", error);

   error = ex_close (exoid);
   printf ("\nafter ex_close, error = %3d\n", error);

   error = ex_close (exoid1);
   printf ("\nafter ex_close, error = %3d\n", error);
   return 0;
}
Example #2
0
File: wr_exo.c Project: 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;
}
Excn::ExodusFile::ExodusFile(int processor)
  : myProcessor_(processor)
{
  SMART_ASSERT(processor < processorCount_)(processor)(processorCount_);
  SMART_ASSERT(fileids_.size() == (size_t)processorCount_);
  if (!keepOpen_ && processor != 0) {
    float version = 0.0;
    int cpu_word_size = cpuWordSize_;
    int io_word_size_var  = ioWordSize_;
    int mode = EX_READ;
    mode |= mode64bit_;
    
    fileids_[processor] = ex_open(filenames_[processor].c_str(),
				  mode, &cpu_word_size,
				  &io_word_size_var, &version);
    if (fileids_[processor] < 0) {
      std::cerr << "Cannot open file '" << filenames_[processor]
	   << "' - exiting" << std::endl;
      exit(1);
    }
    ex_set_max_name_length(fileids_[processor], maximumNameLength_);
    
    SMART_ASSERT(io_word_size_var  == ioWordSize_);
    SMART_ASSERT(cpu_word_size == cpuWordSize_);
  }
}
Example #4
0
int main(int argc, char *argv[])
{
  int exoid;
  char *filename;
  int cpu_word_size = 8;
  int io_word_size  = 0;
  float version = 0.0;
  
  banner();

  if (argc != 3) {
    fprintf(stderr, "ERROR: Usage is exotec2 exo_in tec_out\n\n");
    exit(1);
  }
  
  /* Open the files... */
  filename = argv[1];
  exoid = ex_open(filename, EX_READ, &cpu_word_size, &io_word_size, &version);
  
  if (exoid < 0) {
    fprintf(stderr, "Cannot open file '%s' - exiting.\n", filename);
    exit(1);
  }

  /* Write the tec file... */
  filename = argv[2];

  tec(exoid, filename);

  ex_close(exoid);

  add_to_log(argv[0], 0.0);
}
Example #5
0
/* Open ExodusII File for reading */
int c_read_ex_open(const char *path, int mode, int *comp_ws, int *io_ws, float *version)
{
  int exoid=0;
#ifdef HAVE_LIBEXOIIV2C
   exoid = ex_open(path, EX_READ, comp_ws, io_ws, version);
#else
   FLExit("Fluidity was not configured with exodusII, reconfigure with '--with-exodusii'!");
#endif
   return (exoid);
}
int open_exodus_file(char *filename)
{
  int   cpu = sizeof(double);
  int   io  = 0;
  int   exo;
  float version; 

 exo=ex_open(filename,EX_READ,&cpu,&io,&version);
 if (exo < 0) {
   yyerror("Error opening exodusII file.");
 } else {
  symrec *ptr;
  ptr = putsym("ex_version", VAR, 0);
  ptr->value.var = version;
 }
 return exo;
}
Example #7
0
PetscErrorCode MyPetscReadExodusII(MPI_Comm comm,const char filename[],DM dmBody,DM dmFS)
{
  ALE::Obj<PETSC_MESH_TYPE>               meshBody,meshFS;
  typedef ALE::Mesh<PetscInt,PetscScalar> FlexMesh;
  //typedef std::set<FlexMesh::point_type>  PointSet;
  //ALE::Obj<FlexMesh>  boundarymesh;
  PetscMPIInt         rank;
  int                 CPU_word_size = 0;
  int                 IO_word_size  = 0;
  PetscBool           interpolate   = PETSC_FALSE;
  int               **connect = PETSC_NULL;
  int                 exoid;
  char                title[MAX_LINE_LENGTH+1];
  float               version;
  int                 num_dim,num_nodes = 0,num_elem = 0;
  int                 num_eb = 0,num_ns = 0,num_ss = 0;
  PetscErrorCode      ierr;
  //const char          known_elements[] = "tri,tri3,triangle,triangle3,quad,quad4,tet,tet4,tetra,tetra4,hex,hex8";
  float              *x = PETSC_NULL,*y = PETSC_NULL,*z = PETSC_NULL;
  PetscBool           debug = PETSC_FALSE;

  PetscFunctionBegin;
  ierr = PetscOptionsGetBool(PETSC_NULL,"-interpolate",&interpolate,PETSC_NULL);CHKERRQ(ierr);

  /*
    Get the sieve meshes from the dms
  */
  ierr = DMMeshGetMesh(dmBody,meshBody);CHKERRQ(ierr);
  ierr = DMMeshGetMesh(dmFS,meshFS);CHKERRQ(ierr);
  rank = meshBody->commRank();

  /*
    Open EXODUS II file and read basic informations on rank 0,
    then broadcast to all nodes
  */
  if (rank == 0) {
    exoid = ex_open(filename,EX_READ,&CPU_word_size,&IO_word_size,&version);CHKERRQ(!exoid);
    ierr = ex_get_init(exoid,title,&num_dim,&num_nodes,&num_elem,&num_eb,&num_ns,&num_ss);CHKERRQ(ierr);
    if (num_eb == 0) {
      SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Exodus file does not contain any element block\n");
    }
    ierr = PetscMalloc3(num_nodes,float,&x,num_nodes,float,&y,num_nodes,float,&z);CHKERRQ(ierr);
    ierr = ex_get_coord(exoid,x,y,z);CHKERRQ(ierr);
  }
Example #8
0
template <typename INT> std::string ExoII_Read<INT>::Open_File(const char *fname)
{
  SMART_ASSERT(Check_State());

  if (Open())
    return "ERROR: File already open!";

  if (fname && std::strlen(fname) > 0)
    file_name = fname;
  else if (file_name == "")
    return "ERROR: No file name to open!";

  int   ws = 0, comp_ws = 8;
  float dum  = 0.0;
  int   mode = EX_READ;
  if (sizeof(INT) == 8) {
    mode |= EX_ALL_INT64_API;
  }
  int err = ex_open(file_name.c_str(), mode, &comp_ws, &ws, &dum);
  if (err < 0) {
    std::ostringstream oss;
    oss << "ERROR: Couldn't open file \"" << file_name << "\".";

    // ExodusII library could not open file.  See if a file (exodusII
    // or not) exists with the specified name.
    FILE *fid = fopen(file_name.c_str(), "r");
    if (fid != nullptr) {
      oss << " File exists, but is not an exodusII file.";
      fclose(fid);
    }
    else {
      oss << " File does not exist.";
    }
    return oss.str();
  }

  file_id      = err;
  io_word_size = ws;

  Get_Init_Data();

  return "";
}
Example #9
0
File: wr_exo.c Project: goma/goma
void
wr_global_result_exo( Exo_DB *exo, 
		      const char *filename, 
		      const int time_step, 
		      const int ngv, 
		      double u[] )
{
     /*****************************************************************
      * write_global_result_exo() 
      *     -- open/write/close EXODUS II db for all global values
      *
      * The output EXODUS II database contains the original model
      * information with some minor QA and info additions, with new 
      * global data written.
      * 
      ******************************************************************/
  int error;


  /* 
   * This capability is deactivated for parallel processing.
   * brkfix doesn't support global variables, when this
   * changes this restriction should be removed. TAB 3/2002 */

  if( u == NULL ) return ; /* Do nothing if this is NULL */

  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) {
    EH(-1,"wr_nodal_result_exo: could not open the output file");
  }

  error = ex_put_var( exo->exoid, time_step, EX_GLOBAL, 1, 0, ngv, u );

  EH(error, "ex_put_var glob_vars");

  error = ex_close( exo->exoid);


  return;
}
Example #10
0
void ExodusModel::getInitialization() {

    int io_ws = 0;
    int comp_ws = 8;
    try {
        mExodusId = ex_open(mExodusFileName.c_str(), EX_READ, &comp_ws, &io_ws, &mExodusVersion);
        if (mExodusId < 0) { throw std::runtime_error("Error opening exodus model file."); }

        exodusError(ex_get_init(
                            mExodusId, mExodusTitle, &mNumberDimension, &mNumberVertices, &mNumberElements,
                            &mNumberElementBlocks, &mNumberNodeSets, &mNumberSideSets),
                    "ex_get_init");

    } catch (std::exception &e) {
        utilities::print_from_root_mpi(e.what());
        MPI_Abort(PETSC_COMM_WORLD, -1);
    }

}
Example #11
0
int main()
{
  float version = 0.0;

  ex_opts(EX_VERBOSE | EX_ABORT);
  int CPU_word_size = 0; /* sizeof(float) */
  int IO_word_size  = 4; /* (4 bytes) */

  /* ======================================== */
  /* Create an empty exodus file             */
  /* ====================================== */
  int exoid = ex_create("test.exo", EX_CLOBBER, &CPU_word_size, &IO_word_size);
  ex_close(exoid);

  /* ======================================== */
  /* Now try to open and read the empty file */
  /* ====================================== */

  exoid = ex_open("test.exo",     /* filename path */
                  EX_READ,        /* access mode = READ */
                  &CPU_word_size, /* CPU word size */
                  &IO_word_size,  /* IO word size */
                  &version);      /* ExodusII library version */

  printf("test.exo exoid = %d\n", exoid);

  {
    char title[MAX_LINE_LENGTH + 1];
    int  num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets;
    int  error = ex_get_init(exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk,
                            &num_node_sets, &num_side_sets);
    printf("after ex_get_init, error = %3d\n", error);
    if (error)
      exit(-1);
    else
      exit(0);
  }
}
Example #12
0
Excn::ExodusFile::ExodusFile(size_t which)
  : myLocation_(which)
{
  SMART_ASSERT(which < filenames_.size())(which)(filenames_.size());
  SMART_ASSERT(fileids_.size() == filenames_.size());
  if (!keepOpen_ && which != 0) {
    float version = 0.0;
    int cpu_word_size = cpuWordSize_;
    int io_wrd_size  = ioWordSize_;
    fileids_[which] = ex_open(filenames_[which].c_str(),
				  EX_READ|exodusMode_, &cpu_word_size,
				  &io_wrd_size, &version);
    if (fileids_[which] < 0) {
      std::cerr << "Cannot open file '" << filenames_[which]
	   << "' - exiting" << std::endl;
      exit(1);
    }
    ex_set_max_name_length(fileids_[which], maximumNameLength_);

    SMART_ASSERT(io_wrd_size  == ioWordSize_);
    SMART_ASSERT(cpu_word_size == cpuWordSize_);
  }
}
Example #13
0
/*@C
  DMPlexCreateExodus - Create a DMPlex mesh from an ExodusII file.

  Collective on comm

  Input Parameters:
+ comm  - The MPI communicator
. filename - The name of the ExodusII file
- interpolate - Create faces and edges in the mesh

  Output Parameter:
. dm  - The DM object representing the mesh

  Level: beginner

.keywords: mesh,ExodusII
.seealso: DMPLEX, DMCreate(), DMPlexCreateExodus()
@*/
PetscErrorCode DMPlexCreateExodusFromFile(MPI_Comm comm, const char filename[], PetscBool interpolate, DM *dm)
{
  PetscMPIInt    rank;
  PetscErrorCode ierr;
#if defined(PETSC_HAVE_EXODUSII)
  int   CPU_word_size = 0, IO_word_size = 0, exoid = -1;
  float version;
#endif

  PetscFunctionBegin;
  PetscValidCharPointer(filename, 2);
  ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr);
#if defined(PETSC_HAVE_EXODUSII)
  if (!rank) {
    exoid = ex_open(filename, EX_READ, &CPU_word_size, &IO_word_size, &version);
    if (exoid <= 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_LIB, "ex_open(\"%s\",...) did not return a valid file ID", filename);
  }
  ierr = DMPlexCreateExodus(comm, exoid, interpolate, dm);CHKERRQ(ierr);
  if (!rank) {ierr = ex_close(exoid);CHKERRQ(ierr);}
#else
  SETERRQ(comm, PETSC_ERR_SUP, "This method requires ExodusII support. Reconfigure using --download-exodusii");
#endif
  PetscFunctionReturn(0);
}
Example #14
0
File: wr_exo.c Project: 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;
}
Example #15
0
/**
 * XdmfExodusConverter is a command line utility for converting
 * between Xdmf and Exodus files. If given an Xdmf file, the tool
 * converts the file to Exodus and if given a path to an Exodus file,
 * the tool converts the file to Xdmf.
 *
 * Usage:
 *     XdmfExodusConverter <path-of-file-to-convert> 
 *                         (Optional: <path-to-output-file>)
 *
 */
int main(int argc, char* argv[])
{

  std::string inputFileName = "";
  std::string outputFileName = "";

  processCommandLine(inputFileName,
                     outputFileName,
                     argc,
                     argv);

  FILE * refFile = fopen(inputFileName.c_str(), "r");
  if (refFile) {
    // Success
    fclose(refFile);
  }
  else {
    std::cout << "Cannot open file: " << argv[1] << std::endl;
    return 1;
  }

  std::string meshName;
  if(outputFileName.compare("") == 0) {
    meshName = inputFileName;
  }
  else {
    meshName = outputFileName;
  }

  if(meshName.find_last_of("/\\") != std::string::npos) {
    meshName = meshName.substr(meshName.find_last_of("/\\") + 1,
                               meshName.length());
  }

  if (meshName.rfind(".") != std::string::npos) {
    meshName = meshName.substr(0, meshName.rfind("."));
  }

  int CPU_word_size = sizeof(double);
  int IO_word_size = 0; // Get from file
  float version;
  const int exodusHandle = 
    ex_open(argv[1], EX_READ, &CPU_word_size, &IO_word_size, &version);
  if(exodusHandle < 0) {
    // Xdmf to Exodus
    shared_ptr<XdmfReader> reader = XdmfReader::New();
    shared_ptr<XdmfDomain> domain = 
      shared_dynamic_cast<XdmfDomain>(reader->read(inputFileName));
    std::stringstream exodusFileName;
    exodusFileName << meshName << ".exo";
    shared_ptr<XdmfExodusWriter> writer = XdmfExodusWriter::New();
    if(domain->getNumberUnstructuredGrids() == 1) {
      const shared_ptr<XdmfUnstructuredGrid> grid = 
        domain->getUnstructuredGrid(0);
      writer->write(exodusFileName.str(),
                    grid);
      std::cout << "Wrote: " << exodusFileName.str() << std::endl;
    }
    else if(domain->getNumberGridCollections() == 1) {
      const shared_ptr<XdmfGridCollection> grid = 
        domain->getGridCollection(0);
      writer->write(exodusFileName.str(),
                    grid);
      std::cout << "Wrote: " << exodusFileName.str() << std::endl;
    }
    else {
      XdmfError::message(XdmfError::FATAL,
                         "Cannot find grid in Xdmf file to convert to "
                         "exodus.");
    }
  }
  else {
    // Exodus to Xdmf
    std::stringstream heavyFileName;
    heavyFileName << meshName << ".h5";
    shared_ptr<XdmfHDF5Writer> heavyDataWriter =
      XdmfHDF5Writer::New(heavyFileName.str());
    heavyDataWriter->setReleaseData(true);
    shared_ptr<XdmfExodusReader> exodusReader = XdmfExodusReader::New();
    shared_ptr<XdmfUnstructuredGrid> readGrid = 
      exodusReader->read(inputFileName,
                         heavyDataWriter);
    shared_ptr<XdmfDomain> newDomain = XdmfDomain::New();
    newDomain->insert(readGrid);
    std::stringstream xmlFileName;
    xmlFileName << meshName << ".xmf";
    shared_ptr<XdmfWriter> writer = XdmfWriter::New(xmlFileName.str(),
                                                    heavyDataWriter);
    newDomain->accept(writer);
    std::cout << "Wrote: " << xmlFileName.str() << std::endl;
  }

}
Example #16
0
void NemSpread<T,INT>::load_lb_info(void)

/*
 *       load_lb_info:
 *
 *            This function reads and distributes the load balance information.
 *    This information is defined as the following scalars, which are specific
 *    to each processor:
 *
 *        Num_Internal_Nodes
 *        Num_Border_Nodes
 *        Num_External_Nodes
 *        globals.Num_Internal_Elems
 *        globals.Num_Border_Elems
 *
 *    and the following vectors, also specific to each processor:
 *
 *        globals.GNodes [Num_Internal_Nodes+Num_Border_Nodes+Num_External_Nodes]
 *        globals.GElems [globals.Num_Internal_Elems+globals.Num_Border_Elems]
 *
 *    For the 1 processor case, this routine fills in appropriate values
 *    for these quantities.
 */
{

  int    lb_exoid=0;
  INT    cmap_max_size=0, *comm_vec;
  const char  *yo = "load_lb_info";
  char   Title[MAX_LINE_LENGTH+1];
  float  version;

  int    cpu_ws=0;

  /******************************** START EXECUTION ****************************/
  if(Debug_Flag)
    printf ("\nStart to read in and distribute the load balance info\n");

  /* Open the Load Balance exoII file for reading */

  printf ("EXODUS II load-balance file: %s\n", Exo_LB_File);
  cpu_ws = io_ws;
  int mode = EX_READ | int64api;
  int iio_ws = 0; // Don't interfere with exodus files; this is the nemesis file.
  if((lb_exoid = ex_open(Exo_LB_File, mode, &cpu_ws,
			 &iio_ws, &version)) == -1) {
    fprintf(stderr, "%sERROR: Couldn\'t open lb file, %s\n", yo,
	    Exo_LB_File);
    exit(1);
  }

  /* Read information about the processor configuration */
  read_proc_init(lb_exoid,Proc_Info, &Proc_Ids);

  /* Allocate space for the counts */
  globals.Num_Internal_Nodes = (INT *)array_alloc(__FILE__, __LINE__, 1,
						  7*Proc_Info[2], sizeof(INT));
  globals.Num_Border_Nodes   = globals.Num_Internal_Nodes +Proc_Info[2];
  globals.Num_External_Nodes = globals.Num_Border_Nodes   +Proc_Info[2];
  globals.Num_Internal_Elems = globals.Num_External_Nodes +Proc_Info[2];
  globals.Num_Border_Elems   = globals.Num_Internal_Elems +Proc_Info[2];
  globals.Num_N_Comm_Maps    = globals.Num_Border_Elems   +Proc_Info[2];
  globals.Num_E_Comm_Maps    = globals.Num_N_Comm_Maps    +Proc_Info[2];

  /* Allocate space for each processor entity */
  globals.GNodes   = (INT **)array_alloc(__FILE__, __LINE__, 1, 3*Proc_Info[2],
					 sizeof(INT *));
  globals.GElems   = globals.GNodes +Proc_Info[2];
  globals.Elem_Map = globals.GElems +Proc_Info[2];

  /* Allocate contiguous space for the pointer vectors on all processors */
  INT *Int_Space     = (INT *)array_alloc(__FILE__, __LINE__, 1,
                                     (7*Proc_Info[0] + 1), sizeof(INT));
  INT *Int_Node_Num  = Int_Space     + 1;
  INT *Bor_Node_Num  = Int_Node_Num  +Proc_Info[0];
  INT *Ext_Node_Num  = Bor_Node_Num  +Proc_Info[0];
  INT *Int_Elem_Num  = Ext_Node_Num  +Proc_Info[0];
  INT *Bor_Elem_Num  = Int_Elem_Num  +Proc_Info[0];
  INT *Node_Comm_Num = Bor_Elem_Num  +Proc_Info[0];
  INT *Elem_Comm_Num = Node_Comm_Num +Proc_Info[0];

  /* Read the initial information contained in the load balance file */
  read_lb_init(lb_exoid, Int_Space, Int_Node_Num,
               Bor_Node_Num, Ext_Node_Num, Int_Elem_Num,
               Bor_Elem_Num, Node_Comm_Num, Elem_Comm_Num,
               Title);

  /* Allocate memory for the communication map arrays */
  globals.N_Comm_Map = (NODE_COMM_MAP<INT>**)malloc(Proc_Info[2]*sizeof(NODE_COMM_MAP<INT> *));
  globals.E_Comm_Map = (ELEM_COMM_MAP<INT>**)malloc(Proc_Info[2]*sizeof(ELEM_COMM_MAP<INT> *));
  if(!globals.N_Comm_Map || !globals.E_Comm_Map) {
    fprintf(stderr, "ERROR: Insufficient memory!\n");
    exit(1);
  }

  for (int iproc=0; iproc <Proc_Info[2]; iproc++) {

    /*
     * Error check:
     *	Currently a maximum of one nodal communication map and one
     * elemental communication map is supported.
     */
    if(globals.Num_N_Comm_Maps[iproc] > 1 || globals.Num_E_Comm_Maps[iproc] > 1) {
      fprintf(stderr, "%s: ERROR. Only 1 nodal and elemental comm map "
              "is supported\n", yo);
      exit(1);
    }
    else {

      /* Always allocate at least one and initialize the counts to 0 */
      globals.N_Comm_Map[iproc] = (NODE_COMM_MAP<INT> *)malloc(PEX_MAX(1,
								  globals.Num_N_Comm_Maps[iproc]) *
							  sizeof(NODE_COMM_MAP<INT>));
      if(globals.N_Comm_Map[iproc] == NULL && globals.Num_N_Comm_Maps[iproc] > 0) {
        fprintf(stderr,
                "%s: ERROR. Insufficient memory for nodal comm. map!\n",
                yo);
        exit(1);
      }

      for(size_t ijump=0; ijump < PEX_MAX(1, globals.Num_N_Comm_Maps[iproc]); ijump++)
        ((globals.N_Comm_Map[iproc])+ijump)->node_cnt = 0;

      globals.E_Comm_Map[iproc] = (ELEM_COMM_MAP<INT> *)malloc(PEX_MAX(1,
								  globals.Num_E_Comm_Maps[iproc]) *
							  sizeof(ELEM_COMM_MAP<INT>));
      if(globals.E_Comm_Map[iproc] == NULL && globals.Num_E_Comm_Maps[iproc] > 0) {
        fprintf(stderr,
                "%s: ERROR. Insufficient memory for elemental comm. map!\n",
                yo);
        exit(1);
      }

      for(size_t ijump=0; ijump < PEX_MAX(1, globals.Num_E_Comm_Maps[iproc]); ijump++)
        ((globals.E_Comm_Map[iproc])+ijump)->elem_cnt = 0;

    }

  } /* End "for (int iproc=0; iproc <Proc_Info[2]; iproc++)" */

  /* Set up each processor for the communication map parameters */
  read_cmap_params(lb_exoid, Node_Comm_Num, Elem_Comm_Num,
                   globals.Num_N_Comm_Maps, globals.Num_E_Comm_Maps,
                   globals.E_Comm_Map, globals.N_Comm_Map, &cmap_max_size,
                   &comm_vec);

  /* Allocate enough space to read the LB_data for one processor */
  INT *Integer_Vector = (INT *)array_alloc(__FILE__, __LINE__, 1,
                                      Int_Space[0] + cmap_max_size,
                                      sizeof (INT));

  /*
   * loop through the processors, one at a time, to read
   * their load balance information
   *
   * NOTE: From here on there are no provisions for multiple nodal
   *       or elemental communication maps.
   */

  size_t ijump = 0; /* keep track of where in comm_vec we are */
  for (int iproc = 0; iproc <Proc_Info[0]; iproc++) {

    /* Get the node map for processor "iproc" */
    if(ex_get_processor_node_maps(lb_exoid, &Integer_Vector[0],
				  &Integer_Vector[Int_Node_Num[iproc]],
				  &Integer_Vector[Int_Node_Num[iproc]+
						  Bor_Node_Num[iproc]],
				  iproc) < 0) {
      fprintf(stderr, "%s: ERROR, failed to get node map for Proc %d!\n",
	      yo, iproc);
      exit(1);
    }

    size_t vec_indx = Int_Node_Num[iproc] + Bor_Node_Num[iproc] +
      Ext_Node_Num[iproc];

    /* Get the element map for processor number "iproc" */
    if(ex_get_processor_elem_maps(lb_exoid, &Integer_Vector[vec_indx],
				  &Integer_Vector[vec_indx+Int_Elem_Num[iproc]],
				  iproc) < 0) {
      fprintf(stderr, "%s: ERROR, failed to get element map for Proc %d!\n",
	      yo, iproc);
      exit(1);
    }

    if(Node_Comm_Num[iproc] > 0) {
      vec_indx += Int_Elem_Num[iproc] + Bor_Elem_Num[iproc];

      if(ex_get_node_cmap(lb_exoid, comm_vec[ijump],
			  &Integer_Vector[vec_indx],
			  &Integer_Vector[vec_indx+comm_vec[ijump+1]],
			  iproc) < 0) {
	/*
	 * If there are disconnected mesh pieces, then it is
	 * possible that there is no comminication between the
	 * pieces and there will be no communication maps.  Normally
	 * this is a problem, so output a warning, but don't abort.
	 */
	fprintf(stderr,
		"%s: WARNING. Failed to get nodal comm map for Proc %d!\n",
		yo, iproc);
      }
    }

    if(Elem_Comm_Num[iproc] > 0) {
      vec_indx += 2*comm_vec[ijump+1];

      if(ex_get_elem_cmap(lb_exoid, comm_vec[ijump+2],
                          &Integer_Vector[vec_indx],
                          &Integer_Vector[vec_indx+comm_vec[ijump+3]],
                          &Integer_Vector[vec_indx+2*comm_vec[ijump+3]],
                          iproc) < 0) {
	fprintf(stderr,
		"%s: ERROR. Failed to get elemental comm map for Proc %d!\n",
		yo, iproc);
	exit(1);
      }
    }

    /*
     * Communicate load balance information to the correct processor
     *   - if iproc = Proc_Ids[*] then process the data instead.
     */
    assert(Proc_Ids[iproc] == iproc);
    process_lb_data (Integer_Vector, iproc);

    /*
     * now move ijump to the next communications map
     * make sure to check if there are any for this processor
     */
    if (Node_Comm_Num[iproc] > 0) ijump += 2;
    if (Elem_Comm_Num[iproc] > 0) ijump += 2;

  }

  /* Close the load balance file - we are finished with it */
  if(ex_close (lb_exoid) == -1) {
    fprintf (stderr, "%sERROR: Error in closing load balance file\n", yo);
    exit(1);
  }

  /************************* Cleanup and Printout Phase ***********************/

  /* Free temporary memory */
  safe_free((void **) &Integer_Vector);

  if(num_qa_rec > 0) {
    for(int i = 0; i < length_qa; i++) safe_free((void **) &(qa_record_ptr[i]));
    safe_free((void **) &qa_record_ptr);
  }

  if(num_inf_rec > 0) {
    for(int i = 0; i < num_inf_rec; i++) safe_free((void **) &(inf_record_ptr[i]));
    safe_free((void **) &inf_record_ptr);
  }

  safe_free((void **) &Int_Space);

  safe_free((void **) &comm_vec);

  for (int iproc=0; iproc <Proc_Info[2]; iproc++) {
    if (globals.Num_Internal_Nodes[iproc] == 0 &&
	globals.Num_Border_Nodes[iproc] == 0 &&
	globals.Num_External_Nodes[iproc] == 0) {
      fprintf(stderr, "\n%s: WARNING, Processor %d has no nodes!\n",
	      yo, iproc);
      
    }
    if (globals.Num_Internal_Elems[iproc] == 0 &&
	globals.Num_Border_Elems[iproc] == 0) {
      fprintf(stderr, "\n%s: WARNING, Processor %d has no elements!\n",
	      yo, iproc);
    }
  }

  /*========================================================================*/

  if(Debug_Flag)
    printf ("\nFinished distributing load balance info\n");

  /* Output Detailed timing information for the progam */
  /*
   * Print out a Large table of Load Balance Information if the debug_flag
   * setting is large enough
   */

  if(Debug_Flag >= 7) {
    printf ("\n\n");
    print_line ("=", 79);
    for (int iproc=0; iproc <Proc_Info[2]; iproc++) {
      printf("\n\t***For Processor %d***\n", Proc_Ids[iproc]);
      printf("\tInternal nodes owned by the current processor\n\t");
      for(INT i = 0; i < globals.Num_Internal_Nodes[iproc]; i++)
        printf(" " ST_ZU "", (size_t)globals.GNodes[iproc][i]);

      printf("\n");

      printf("\tBorder nodes owned by the current processor\n\t");
      for(INT i = 0; i < globals.Num_Border_Nodes[iproc]; i++)
        printf(" " ST_ZU "", (size_t)globals.GNodes[iproc][i + globals.Num_Internal_Nodes[iproc]]);

      printf("\n");

      if(globals.Num_External_Nodes[iproc] > 0) {
        printf("\tExternal nodes needed by the current processor\n\t");
        for(INT i = 0; i < globals.Num_External_Nodes[iproc]; i++)
          printf(" " ST_ZU "", (size_t)globals.GNodes[iproc][i + globals.Num_Internal_Nodes[iproc] +
						       globals.Num_Border_Nodes[iproc]]);

        printf("\n");
      }

      printf("\tInternal elements owned by the current processor\n\t");
      for(INT i = 0; i < globals.Num_Internal_Elems[iproc]; i++)
        printf(" " ST_ZU "", (size_t)globals.GElems[iproc][i]);

      printf("\n");

      if(globals.Num_Border_Elems[iproc] > 0) {
        printf("\tBorder elements owned by the current processor\n\t");
        for(INT i=0; i < globals.Num_Border_Elems[iproc]; i++)
          printf(" " ST_ZU "", (size_t)globals.GElems[iproc][i+globals.Num_Internal_Elems[iproc]]);

        printf("\n");
      }

      if(globals.Num_N_Comm_Maps[iproc] > 0) {
        printf("\tNodal Comm Map for the current processor\n");
        printf("\t\tnode IDs:");
        for(size_t i=0; i < globals.N_Comm_Map[iproc]->node_cnt; i++)
          printf(" " ST_ZU "", (size_t)globals.N_Comm_Map[iproc]->node_ids[i]);
        printf("\n\t\tproc IDs:");
        for(size_t i=0; i < globals.N_Comm_Map[iproc]->node_cnt; i++)
          printf(" " ST_ZU "", (size_t)globals.N_Comm_Map[iproc]->proc_ids[i]);

        printf("\n");
      }

      if(globals.Num_E_Comm_Maps[iproc] > 0) {
        printf("\tElemental Comm Map for the current processor\n");
        printf("\t\telement IDs:");
        for(size_t i=0; i < globals.E_Comm_Map[iproc]->elem_cnt; i++)
          printf(" " ST_ZU "", (size_t)globals.E_Comm_Map[iproc]->elem_ids[i]);
        printf("\n\t\tside IDs:");
        for(size_t i=0; i < globals.E_Comm_Map[iproc]->elem_cnt; i++)
          printf(" " ST_ZU "", (size_t)globals.E_Comm_Map[iproc]->side_ids[i]);
        printf("\n\t\tproc IDs:");
        for(size_t i=0; i < globals.E_Comm_Map[iproc]->elem_cnt; i++)
          printf(" " ST_ZU "", (size_t)globals.E_Comm_Map[iproc]->proc_ids[i]);

        printf("\n");
      }
    }
    printf("\n");
    print_line ("=", 79);
  }

} /* END of routine load_lb_info () ******************************************/
Example #17
0
void NemSpread<T,INT>::read_restart_data ()

/* Function which reads the restart variable data from the EXODUS II
 * database which contains the results information. Then distribute
 * it to the processors, and write it to the parallel exodus files.
 *
 *----------------------------------------------------------------------------
 *
 * Functions called:
 *
 * read_vars -- function which reads the variable values from the restart
 *              file, and then distributes them to the processors
 *
 * write_var_timestep -- function which writes out the variables for a
 *                       to a parallel ExodusII file.
 *
 *----------------------------------------------------------------------------
 */

{
    const char  *yo="read_restart_data";

    /* need to get the element block ids and counts */
    std::vector<INT> eb_ids_global(globals.Num_Elem_Blk);
    std::vector<INT> eb_cnts_global(globals.Num_Elem_Blk);
    std::vector<INT> ss_ids_global(globals.Num_Side_Set);
    std::vector<INT> ss_cnts_global(globals.Num_Side_Set);
    std::vector<INT> ns_ids_global(globals.Num_Node_Set);
    std::vector<INT> ns_cnts_global(globals.Num_Node_Set);

    INT ***eb_map_ptr = NULL, **eb_cnts_local = NULL;
    int    exoid=0, *par_exoid = NULL;

    float  vers;
    char   cTemp[512];

    /* computing precision should be the same as the database precision
     *
     * EXCEPTION: if the io_ws is smaller than the machine precision,
     * ie - database with io_ws == 4 on a Cray (sizeof(float) == 8),
     * then the cpu_ws must be the machine precision.
     */
    int cpu_ws;
    if (io_ws < (int)sizeof(float)) cpu_ws = sizeof(float);
    else                            cpu_ws = io_ws;

    /* Open the ExodusII file */
    {
        cpu_ws = io_ws;
        int mode = EX_READ | int64api;
        if ((exoid=ex_open(Exo_Res_File, mode, &cpu_ws, &io_ws, &vers)) < 0) {
            fprintf(stderr, "%s: Could not open file %s for restart info\n",
                    yo, Exo_Res_File);
            exit(1);
        }
    }

    /* allocate space for the global variables */
    Restart_Info.Glob_Vals.resize(Restart_Info.NVar_Glob);

    if (Restart_Info.NVar_Elem > 0 ) {

        /* allocate storage space */
        Restart_Info.Elem_Vals.resize(Proc_Info[2]);

        /* now allocate storage for the values */
        for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {
            size_t array_size = Restart_Info.NVar_Elem *
                                (globals.Num_Internal_Elems[iproc] + globals.Num_Border_Elems[iproc]);
            Restart_Info.Elem_Vals[iproc].resize(array_size);
        }

        /*
         * at this point, I need to broadcast the global element block ids
         * and counts to the processors. I know that this is redundant data
         * since they will all receive this information in read_mesh, but
         * the variables which contain that information are static in
         * el_exoII_io.c, and cannot be used here. So, take a second and
         * broadcast all of this out.
         *
         * I want to do this here so that it is done only once no matter
         * how many time steps are retrieved
         */

        /* Get the Element Block IDs from the input file */
        if (ex_get_ids (exoid, EX_ELEM_BLOCK, TOPTR(eb_ids_global)) < 0)
        {
            fprintf(stderr, "%s: unable to get element block IDs", yo);
            exit(1);
        }

        /* Get the count of elements in each element block */
        for (int cnt = 0; cnt < globals.Num_Elem_Blk; cnt++) {
            if (ex_get_block(exoid, EX_ELEM_BLOCK, eb_ids_global[cnt], cTemp,
                             &(eb_cnts_global[cnt]), NULL, NULL, NULL, NULL) < 0) {
                fprintf(stderr, "%s: unable to get element count for block id "ST_ZU"",
                        yo, (size_t)eb_ids_global[cnt]);
                exit(1);
            }
        }

        /*
         * in order to speed up finding matches in the global element
         * number map, set up an array of pointers to the start of
         * each element block's global element number map. That way
         * only entries for the current element block have to be searched
         */
        eb_map_ptr = (INT ***) array_alloc (__FILE__, __LINE__, 2,Proc_Info[2],
                                            globals.Num_Elem_Blk, sizeof(INT *));
        if (!eb_map_ptr) {
            fprintf(stderr, "[%s]: ERROR, insufficient memory!\n", yo);
            exit(1);
        }
        eb_cnts_local = (INT **) array_alloc (__FILE__, __LINE__, 2,Proc_Info[2],
                                              globals.Num_Elem_Blk, sizeof(INT));
        if (!eb_cnts_local) {
            fprintf(stderr, "[%s]: ERROR, insufficient memory!\n", yo);
            exit(1);
        }

        /*
         * for now, assume that element blocks have been
         * stored in the same order as the global blocks
         */
        for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {
            int    ifound = 0;
            size_t offset = 0;
            int    ilocal;
            for (int cnt = 0; cnt < globals.Num_Elem_Blk; cnt++) {
                for (ilocal = ifound; ilocal < globals.Proc_Num_Elem_Blk[iproc]; ilocal++) {
                    if (globals.Proc_Elem_Blk_Ids[iproc][ilocal] == eb_ids_global[cnt])
                        break;
                }

                if (ilocal < globals.Proc_Num_Elem_Blk[iproc]) {
                    eb_map_ptr[iproc][cnt] = &globals.GElems[iproc][offset];
                    eb_cnts_local[iproc][cnt] = globals.Proc_Num_Elem_In_Blk[iproc][ilocal];
                    offset += globals.Proc_Num_Elem_In_Blk[iproc][ilocal];
                    ifound = ilocal; /* don't search the same part of the list over */
                }
                else {
                    eb_map_ptr[iproc][cnt] = NULL;
                    eb_cnts_local[iproc][cnt] = 0;
                }
            }
        }

    } /* End: "if (Restart_Info.NVar_Elem > 0 )" */

    if (Restart_Info.NVar_Node > 0 ) {
        /* allocate storage space */
        Restart_Info.Node_Vals.resize(Proc_Info[2]);

        /* now allocate storage for the values */
        for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {
            size_t array_size = Restart_Info.NVar_Node * (globals.Num_Internal_Nodes[iproc] +
                                globals.Num_Border_Nodes[iproc] + globals.Num_External_Nodes[iproc]);
            Restart_Info.Node_Vals[iproc].resize(array_size);
        }
    }

    if (Restart_Info.NVar_Sset > 0 ) {

        /* allocate storage space */
        Restart_Info.Sset_Vals.resize(Proc_Info[2]);

        /* now allocate storage for the values */
        for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {
            size_t array_size = Restart_Info.NVar_Sset * globals.Proc_SS_Elem_List_Length[iproc];

            Restart_Info.Sset_Vals[iproc].resize(array_size);
        }

        /*
         * at this point, I need to broadcast the ids and counts to the
         * processors. I know that this is redundant data since they will
         * all receive this information in read_mesh, but the variables
         * which contain that information are static in el_exoII_io.c, and
         * cannot be used here. So, take a second and broadcast all of
         * this out.
         *
         * I want to do this here so that it is done only once no matter
         * how many time steps are retrieved
         */

        /* Get the Sideset IDs from the input file */
        if (ex_get_ids (exoid, EX_SIDE_SET, TOPTR(ss_ids_global)) < 0) {
            fprintf(stderr, "%s: unable to get sideset IDs", yo);
            exit(1);
        }

        /* Get the count of elements in each sideset */
        for (int cnt = 0; cnt < globals.Num_Side_Set; cnt++) {
            if (ex_get_set_param(exoid, EX_SIDE_SET,
                                 ss_ids_global[cnt],
                                 &(ss_cnts_global[cnt]), NULL) < 0) {
                fprintf(stderr, "%s: unable to get element count for sideset id "ST_ZU"",
                        yo, (size_t)ss_ids_global[cnt]);
                exit(1);
            }
        }
    } /* End: "if (Restart_Info.NVar_Sset > 0 )" */


    if (Restart_Info.NVar_Nset > 0 ) {

        /* allocate storage space */
        Restart_Info.Nset_Vals.resize(Proc_Info[2]);

        /* now allocate storage for the values */
        for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {
            size_t array_size = Restart_Info.NVar_Nset * globals.Proc_NS_List_Length[iproc];
            Restart_Info.Nset_Vals[iproc].resize(array_size);
        }

        /*
         * at this point, I need to broadcast the ids and counts to the
         * processors. I know that this is redundant data since they will
         * all receive this information in read_mesh, but the variables
         * which contain that information are static in el_exoII_io.c, and
         * cannot be used here. So, take a second and broadcast all of
         * this out.
         *
         * I want to do this here so that it is done only once no matter
         * how many time steps are retrieved
         */

        /* Get the Nodeset IDs from the input file */
        if (ex_get_ids (exoid, EX_NODE_SET, TOPTR(ns_ids_global)) < 0) {
            fprintf(stderr, "%s: unable to get nodeset IDs", yo);
            exit(1);
        }

        /* Get the count of elements in each nodeset */
        for (int cnt = 0; cnt < globals.Num_Node_Set; cnt++) {
            if (ex_get_set_param(exoid, EX_NODE_SET,
                                 ns_ids_global[cnt],
                                 &(ns_cnts_global[cnt]), NULL) < 0) {
                fprintf(stderr, "%s: unable to get element count for nodeset id "ST_ZU"",
                        yo, (size_t)ns_ids_global[cnt]);
                exit(1);
            }
        }
    } /* End: "if (Restart_Info.NVar_Nset > 0 )" */


    /*
     * NOTE: A possible place to speed this up would be to
     * get the global node and element lists here, and broadcast
     * them out only once.
     */

    par_exoid = (int*)malloc(Proc_Info[2] * sizeof(int));
    if(!par_exoid) {
        fprintf(stderr, "[%s]: ERROR, insufficient memory!\n",
                yo);
        exit(1);
    }

    /* See if any '/' in the name.  IF present, isolate the basename of the file */
    if (strrchr(PIO_Info.Scalar_LB_File_Name, '/') != NULL) {
        /* There is a path separator.  Get the portion after the
         * separator
         */
        strcpy(cTemp, strrchr(PIO_Info.Scalar_LB_File_Name, '/')+1);
    } else {
        /* No separator; this is already just the basename... */
        strcpy(cTemp, PIO_Info.Scalar_LB_File_Name);
    }

    if (strlen(PIO_Info.Exo_Extension) == 0)
        add_fname_ext(cTemp, ".par");
    else
        add_fname_ext(cTemp, PIO_Info.Exo_Extension);

    int open_file_count = get_free_descriptor_count();
    if (open_file_count >Proc_Info[5]) {
        printf("All output files opened simultaneously.\n");
        for (int iproc=Proc_Info[4]; iproc <Proc_Info[4]+Proc_Info[5]; iproc++) {

            gen_par_filename(cTemp, Par_Nem_File_Name, Proc_Ids[iproc],
                             Proc_Info[0]);

            /* Open the parallel Exodus II file for writing */
            cpu_ws = io_ws;
            int mode = EX_WRITE | int64api | int64db;
            if ((par_exoid[iproc]=ex_open(Par_Nem_File_Name, mode, &cpu_ws,
                                          &io_ws, &vers)) < 0) {
                fprintf(stderr,"[%d] %s Could not open parallel Exodus II file: %s\n",
                        iproc, yo, Par_Nem_File_Name);
                exit(1);
            }
        }
    } else {
        printf("All output files opened one-at-a-time.\n");
    }

    /* Now loop over the number of time steps */
    for (int time_idx = 0; time_idx < Restart_Info.Num_Times; time_idx++) {

        double start_t = second ();

        /* read and distribute the variables for this time step */
        if (read_vars(exoid, Restart_Info.Time_Idx[time_idx],
                      TOPTR(eb_ids_global), TOPTR(eb_cnts_global), eb_map_ptr,
                      eb_cnts_local,
                      TOPTR(ss_ids_global), TOPTR(ss_cnts_global),
                      TOPTR(ns_ids_global), TOPTR(ns_cnts_global)) < 0) {
            fprintf(stderr, "%s: Error occured while reading variables\n",
                    yo);
            exit(1);
        }
        double end_t   = second () - start_t;
        printf ("\tTime to read  vars for timestep %d: %f (sec.)\n", (time_idx+1), end_t);

        start_t = second ();
        for (int iproc=Proc_Info[4]; iproc <Proc_Info[4]+Proc_Info[5]; iproc++) {

            if (open_file_count <Proc_Info[5]) {
                gen_par_filename(cTemp, Par_Nem_File_Name, Proc_Ids[iproc],
                                 Proc_Info[0]);

                /* Open the parallel Exodus II file for writing */
                cpu_ws = io_ws;
                int mode = EX_WRITE | int64api | int64db;
                if ((par_exoid[iproc]=ex_open(Par_Nem_File_Name, mode, &cpu_ws,
                                              &io_ws, &vers)) < 0) {
                    fprintf(stderr,"[%d] %s Could not open parallel Exodus II file: %s\n",
                            iproc, yo, Par_Nem_File_Name);
                    exit(1);
                }
            }

            /*
             * Write out the variable data for the time steps in this
             * block to each parallel file.
             */
            write_var_timestep(par_exoid[iproc], iproc, (time_idx+1),
                               TOPTR(eb_ids_global), TOPTR(ss_ids_global), TOPTR(ns_ids_global));

            if (iproc%10 == 0 || iproc ==Proc_Info[2]-1)
                printf("%d", iproc);
            else
                printf(".");

            if (open_file_count <Proc_Info[5]) {
                if (ex_close(par_exoid[iproc]) == -1) {
                    fprintf(stderr, "[%d] %s Could not close the parallel Exodus II file.\n",
                            iproc, yo);
                    exit(1);
                }
            }
        } /* End "for (iproc=0; iproc <Proc_Info[2]; iproc++)" */

        end_t   = second () - start_t;
        printf ("\n\tTime to write vars for timestep %d: %f (sec.)\n", (time_idx+1), end_t);

    }
    if (Restart_Info.NVar_Elem > 0 ) {
        safe_free((void **) &eb_map_ptr);
        safe_free((void **) &eb_cnts_local);
    }

    /* Close the restart exodus II file */
    if (ex_close(exoid) == -1) {
        fprintf(stderr, "%sCould not close the restart Exodus II file\n",
                yo);
        exit(1);
    }

    if (open_file_count >Proc_Info[5]) {
        for (int iproc=Proc_Info[4]; iproc <Proc_Info[4]+Proc_Info[5]; iproc++) {
            /* Close the parallel exodus II file */
            if (ex_close(par_exoid[iproc]) == -1) {
                fprintf(stderr, "[%d] %s Could not close the parallel Exodus II file.\n",
                        iproc, yo);
                exit(1);
            }
        }
    }
    if (par_exoid != NULL) {
        free(par_exoid);
        par_exoid = NULL;
    }
}
Example #18
0
int main(int argc, char **argv)
{
  int  exoid, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets;
  int  num_side_sets, error;
  int  i, j, k, node_ctr;
  int *elem_map, *connect, *node_list, *node_ctr_list, *elem_list, *side_list;
  int *ids;
  int *num_nodes_per_set = NULL;
  int *num_elem_per_set  = NULL;
  int *num_df_per_set    = NULL;
  int *node_ind          = NULL;
  int *elem_ind          = NULL;
  int *df_ind            = NULL;
  int  num_qa_rec, num_info;
  int  num_glo_vars, num_nod_vars, num_ele_vars;
  int  num_nset_vars, num_sset_vars;
  int *truth_tab;
  int  num_time_steps;
  int *num_elem_in_block  = NULL;
  int *num_nodes_per_elem = NULL;
  int *num_attr           = NULL;
  int  num_nodes_in_set, num_elem_in_set;
  int  num_sides_in_set, num_df_in_set;
  int  list_len, elem_list_len, node_list_len, df_list_len;
  int  node_num, time_step, var_index, beg_time, end_time, elem_num;
  int  CPU_word_size, IO_word_size;
  int  num_props, prop_value, *prop_values;
  int  idum;

  float  time_value, *time_values, *var_values;
  float *x, *y, *z;
  float *attrib, *dist_fact;
  float  version, fdum;

  char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
  char *block_names[10], *nset_names[10], *sset_names[10];
  char *attrib_names[10];
  char  name[MAX_STR_LENGTH + 1];
  char  title[MAX_LINE_LENGTH + 1], elem_type[MAX_STR_LENGTH + 1];
  char  title_chk[MAX_LINE_LENGTH + 1];
  char *cdum = 0;
  char *prop_names[3];

  CPU_word_size = 0; /* sizeof(float) */
  IO_word_size  = 0; /* use what is stored in file */

  ex_opts(EX_VERBOSE | EX_ABORT);

  /* open EXODUS II files */
  exoid = ex_open("test.exo",     /* filename path */
                  EX_READ,        /* access mode = READ */
                  &CPU_word_size, /* CPU word size */
                  &IO_word_size,  /* IO word size */
                  &version);      /* ExodusII library version */

  printf("\nafter ex_open\n");
  if (exoid < 0)
    exit(1);

  printf("test.exo is an EXODUSII file; version %4.2f\n", version);
  /*   printf ("         CPU word size %1d\n",CPU_word_size);  */
  printf("         I/O word size %1d\n", IO_word_size);
  ex_inquire(exoid, EX_INQ_API_VERS, &idum, &version, cdum);
  printf("EXODUSII API; version %4.2f\n", version);

  ex_inquire(exoid, EX_INQ_LIB_VERS, &idum, &version, cdum);
  printf("EXODUSII Library API; version %4.2f (%d)\n", version, idum);

  /* read database parameters */

  error = ex_get_init(exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk, &num_node_sets,
                      &num_side_sets);

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

  printf("database parameters:\n");
  printf("title =  '%s'\n", title);
  printf("num_dim = %3d\n", num_dim);
  printf("num_nodes = %3d\n", num_nodes);
  printf("num_elem = %3d\n", num_elem);
  printf("num_elem_blk = %3d\n", num_elem_blk);
  printf("num_node_sets = %3d\n", num_node_sets);
  printf("num_side_sets = %3d\n", num_side_sets);

  /* Check that ex_inquire gives same title */
  error = ex_inquire(exoid, EX_INQ_TITLE, &idum, &fdum, title_chk);
  printf(" after ex_inquire, error = %d\n", error);
  if (strcmp(title, title_chk) != 0) {
    printf("error in ex_inquire for EX_INQ_TITLE\n");
  }

  /* read nodal coordinates values and names from database */

  x = (float *)calloc(num_nodes, sizeof(float));
  if (num_dim >= 2)
    y = (float *)calloc(num_nodes, sizeof(float));
  else
    y = 0;

  if (num_dim >= 3)
    z = (float *)calloc(num_nodes, sizeof(float));
  else
    z = 0;

  error = ex_get_coord(exoid, x, y, z);
  printf("\nafter ex_get_coord, error = %3d\n", error);

  printf("x coords = \n");
  for (i = 0; i < num_nodes; i++) {
    printf("%5.1f\n", x[i]);
  }

  if (num_dim >= 2) {
    printf("y coords = \n");
    for (i = 0; i < num_nodes; i++) {
      printf("%5.1f\n", y[i]);
    }
  }
  if (num_dim >= 3) {
    printf("z coords = \n");
    for (i = 0; i < num_nodes; i++) {
      printf("%5.1f\n", z[i]);
    }
  }

  /*
    error = ex_get_1_coord (exoid, 2, x, y, z);
    printf ("\nafter ex_get_1_coord, error = %3d\n", error);

    printf ("x coord of node 2 = \n");
    printf ("%f \n", x[0]);

    printf ("y coord of node 2 = \n");
    printf ("%f \n", y[0]);
  */
  free(x);
  if (num_dim >= 2)
    free(y);
  if (num_dim >= 3)
    free(z);

  for (i = 0; i < num_dim; i++) {
    coord_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
  }

  error = ex_get_coord_names(exoid, coord_names);
  printf("\nafter ex_get_coord_names, error = %3d\n", error);
  printf("x coord name = '%s'\n", coord_names[0]);
  if (num_dim > 1)
    printf("y coord name = '%s'\n", coord_names[1]);
  if (num_dim > 2)
    printf("z coord name = '%s'\n", coord_names[2]);

  for (i = 0; i < num_dim; i++)
    free(coord_names[i]);

  {
    int num_attrs = 0;
    error         = ex_get_attr_param(exoid, EX_NODAL, 0, &num_attrs);
    printf(" after ex_get_attr_param, error = %d\n", error);
    printf("num nodal attributes = %d\n", num_attrs);
    if (num_attrs > 0) {
      for (j = 0; j < num_attrs; j++) {
        attrib_names[j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
      }
      error = ex_get_attr_names(exoid, EX_NODAL, 0, attrib_names);
      printf(" after ex_get_attr_names, error = %d\n", error);

      if (error == 0) {
        attrib = (float *)calloc(num_nodes, sizeof(float));
        for (j = 0; j < num_attrs; j++) {
          printf("nodal attribute %d = '%s'\n", j, attrib_names[j]);
          error = ex_get_one_attr(exoid, EX_NODAL, 0, j + 1, attrib);
          printf(" after ex_get_one_attr, error = %d\n", error);
          for (i = 0; i < num_nodes; i++) {
            printf("%5.1f\n", attrib[i]);
          }
          free(attrib_names[j]);
        }
        free(attrib);
      }
    }
  }

  /* read element order map */

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

  error = ex_get_map(exoid, elem_map);
  printf("\nafter ex_get_map, error = %3d\n", error);

  for (i = 0; i < num_elem; i++) {
    printf("elem_map(%d) = %d \n", i, elem_map[i]);
  }

  free(elem_map);

  /* read element block parameters */

  if (num_elem_blk > 0) {
    ids                = (int *)calloc(num_elem_blk, sizeof(int));
    num_elem_in_block  = (int *)calloc(num_elem_blk, sizeof(int));
    num_nodes_per_elem = (int *)calloc(num_elem_blk, sizeof(int));
    num_attr           = (int *)calloc(num_elem_blk, sizeof(int));

    error = ex_get_elem_blk_ids(exoid, ids);
    printf("\nafter ex_get_elem_blk_ids, error = %3d\n", error);

    for (i = 0; i < num_elem_blk; i++) {
      block_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_names(exoid, EX_ELEM_BLOCK, block_names);
    printf("\nafter ex_get_names, error = %3d\n", error);

    for (i = 0; i < num_elem_blk; i++) {
      ex_get_name(exoid, EX_ELEM_BLOCK, ids[i], name);
      if (strcmp(name, block_names[i]) != 0) {
        printf("error in ex_get_name for block id %d\n", ids[i]);
      }
      error = ex_get_elem_block(exoid, ids[i], elem_type, &(num_elem_in_block[i]),
                                &(num_nodes_per_elem[i]), &(num_attr[i]));
      printf("\nafter ex_get_elem_block, error = %d\n", error);

      printf("element block id = %2d\n", ids[i]);
      printf("element type = '%s'\n", elem_type);
      printf("num_elem_in_block = %2d\n", num_elem_in_block[i]);
      printf("num_nodes_per_elem = %2d\n", num_nodes_per_elem[i]);
      printf("num_attr = %2d\n", num_attr[i]);
      printf("name = '%s'\n", block_names[i]);
      free(block_names[i]);
    }

    /* read element block properties */
    error = ex_inquire(exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum);
    printf("\nafter ex_inquire, error = %d\n", error);
    printf("\nThere are %2d properties for each element block\n", num_props);

    for (i = 0; i < num_props; i++) {
      prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_prop_names(exoid, EX_ELEM_BLOCK, prop_names);
    printf("after ex_get_prop_names, error = %d\n", error);

    for (i = 1; i < num_props; i++) /* Prop 1 is id; skip that here */
    {
      for (j = 0; j < num_elem_blk; j++) {
        error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i], &prop_value);
        if (error == 0)
          printf("element block %2d, property(%2d): '%s'= %5d\n", j + 1, i + 1, prop_names[i],
                 prop_value);
        else
          printf("after ex_get_prop, error = %d\n", error);
      }
    }

    for (i = 0; i < num_props; i++)
      free(prop_names[i]);
  }

  /* read element connectivity */

  for (i = 0; i < num_elem_blk; i++) {
    if (num_elem_in_block[i] > 0) {
      connect = (int *)calloc((num_nodes_per_elem[i] * num_elem_in_block[i]), sizeof(int));

      error = ex_get_elem_conn(exoid, ids[i], connect);
      printf("\nafter ex_get_elem_conn, error = %d\n", error);

      printf("connect array for elem block %2d\n", ids[i]);

      for (j = 0; j < num_nodes_per_elem[i]; j++) {
        printf("%3d\n", connect[j]);
      }
      /*
        error = ex_get_1_elem_conn (exoid, 1, ids[i], connect);
        printf ("\nafter ex_get_elem_conn, error = %d\n", error);

        printf ("node list for first element of element block %d \n ", ids[i]);
        for (j=0; j<num_nodes_per_elem[i]; j++)
        {
        printf ("%d \n", connect[j]);
        }
      */
      free(connect);
    }
  }

  /* read element block attributes */

  for (i = 0; i < num_elem_blk; i++) {
    if (num_elem_in_block[i] > 0) {
      for (j            = 0; j < num_attr[i]; j++)
        attrib_names[j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));

      attrib = (float *)calloc(num_attr[i] * num_elem_in_block[i], sizeof(float));
      error  = ex_get_elem_attr(exoid, ids[i], attrib);
      printf("\n after ex_get_elem_attr, error = %d\n", error);

      if (error == 0) {
        error = ex_get_elem_attr_names(exoid, ids[i], attrib_names);
        printf(" after ex_get_elem_attr_names, error = %d\n", error);

        if (error == 0) {
          printf("element block %d attribute '%s' = %6.4f\n", ids[i], attrib_names[0], *attrib);
        }
      }
      free(attrib);
      for (j = 0; j < num_attr[i]; j++)
        free(attrib_names[j]);
    }
  }

  if (num_elem_blk > 0) {
    free(ids);
    free(num_nodes_per_elem);
    free(num_attr);
  }

  /* read individual node sets */
  if (num_node_sets > 0) {
    ids = (int *)calloc(num_node_sets, sizeof(int));

    error = ex_get_node_set_ids(exoid, ids);
    printf("\nafter ex_get_node_set_ids, error = %3d\n", error);

    for (i = 0; i < num_node_sets; i++) {
      nset_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_names(exoid, EX_NODE_SET, nset_names);
    printf("\nafter ex_get_names, error = %3d\n", error);

    for (i = 0; i < num_node_sets; i++) {
      ex_get_name(exoid, EX_NODE_SET, ids[i], name);
      if (strcmp(name, nset_names[i]) != 0) {
        printf("error in ex_get_name for nodeset id %d\n", ids[i]);
      }

      error = ex_get_node_set_param(exoid, ids[i], &num_nodes_in_set, &num_df_in_set);
      printf("\nafter ex_get_node_set_param, error = %3d\n", error);

      printf("\nnode set %2d parameters: \n", ids[i]);
      printf("num_nodes = %2d\n", num_nodes_in_set);
      printf("name = '%s'\n", nset_names[i]);
      free(nset_names[i]);
      node_list = (int *)calloc(num_nodes_in_set, sizeof(int));
      dist_fact = (float *)calloc(num_nodes_in_set, sizeof(float));

      error = ex_get_node_set(exoid, ids[i], node_list);
      printf("\nafter ex_get_node_set, error = %3d\n", error);

      if (num_df_in_set > 0) {
        error = ex_get_node_set_dist_fact(exoid, ids[i], dist_fact);
        printf("\nafter ex_get_node_set_dist_fact, error = %3d\n", error);
      }

      printf("\nnode list for node set %2d\n", ids[i]);

      for (j = 0; j < num_nodes_in_set; j++) {
        printf("%3d\n", node_list[j]);
      }

      if (num_df_in_set > 0) {
        printf("dist factors for node set %2d\n", ids[i]);

        for (j = 0; j < num_df_in_set; j++) {
          printf("%5.2f\n", dist_fact[j]);
        }
      }
      else
        printf("no dist factors for node set %2d\n", ids[i]);

      free(node_list);
      free(dist_fact);

      {
        int num_attrs = 0;
        error         = ex_get_attr_param(exoid, EX_NODE_SET, ids[i], &num_attrs);
        printf(" after ex_get_attr_param, error = %d\n", error);
        printf("num nodeset attributes for nodeset %d = %d\n", ids[i], num_attrs);
        if (num_attrs > 0) {
          for (j = 0; j < num_attrs; j++) {
            attrib_names[j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
          }
          error = ex_get_attr_names(exoid, EX_NODE_SET, ids[i], attrib_names);
          printf(" after ex_get_attr_names, error = %d\n", error);

          if (error == 0) {
            attrib = (float *)calloc(num_nodes_in_set, sizeof(float));
            for (j = 0; j < num_attrs; j++) {
              printf("nodeset attribute %d = '%s'\n", j, attrib_names[j]);
              error = ex_get_one_attr(exoid, EX_NODE_SET, ids[i], j + 1, attrib);
              printf(" after ex_get_one_attr, error = %d\n", error);
              for (k = 0; k < num_nodes_in_set; k++) {
                printf("%5.1f\n", attrib[k]);
              }
              free(attrib_names[j]);
            }
            free(attrib);
          }
        }
      }
    }
    free(ids);

    /* read node set properties */
    error = ex_inquire(exoid, EX_INQ_NS_PROP, &num_props, &fdum, cdum);
    printf("\nafter ex_inquire, error = %d\n", error);
    printf("\nThere are %2d properties for each node set\n", num_props);

    for (i = 0; i < num_props; i++) {
      prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }
    prop_values = (int *)calloc(num_node_sets, sizeof(int));

    error = ex_get_prop_names(exoid, EX_NODE_SET, prop_names);
    printf("after ex_get_prop_names, error = %d\n", error);

    for (i = 0; i < num_props; i++) {
      error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i], prop_values);
      if (error == 0)
        for (j = 0; j < num_node_sets; j++)
          printf("node set %2d, property(%2d): '%s'= %5d\n", j + 1, i + 1, prop_names[i],
                 prop_values[j]);
      else
        printf("after ex_get_prop_array, error = %d\n", error);
    }
    for (i = 0; i < num_props; i++)
      free(prop_names[i]);
    free(prop_values);

    /* read concatenated node sets; this produces the same information as
     * the above code which reads individual node sets
     */

    error = ex_inquire(exoid, EX_INQ_NODE_SETS, &num_node_sets, &fdum, cdum);
    printf("\nafter ex_inquire, error = %3d\n", error);

    ids               = (int *)calloc(num_node_sets, sizeof(int));
    num_nodes_per_set = (int *)calloc(num_node_sets, sizeof(int));
    num_df_per_set    = (int *)calloc(num_node_sets, sizeof(int));
    node_ind          = (int *)calloc(num_node_sets, sizeof(int));
    df_ind            = (int *)calloc(num_node_sets, sizeof(int));

    error = ex_inquire(exoid, EX_INQ_NS_NODE_LEN, &list_len, &fdum, cdum);
    printf("\nafter ex_inquire: EX_INQ_NS_NODE_LEN = %d, error = %3d\n", list_len, error);
    node_list = (int *)calloc(list_len, sizeof(int));

    error = ex_inquire(exoid, EX_INQ_NS_DF_LEN, &list_len, &fdum, cdum);
    printf("\nafter ex_inquire: EX_INQ_NS_DF_LEN = %d, error = %3d\n", list_len, error);
    dist_fact = (float *)calloc(list_len, sizeof(float));

    error = ex_get_concat_node_sets(exoid, ids, num_nodes_per_set, num_df_per_set, node_ind, df_ind,
                                    node_list, dist_fact);
    printf("\nafter ex_get_concat_node_sets, error = %3d\n", error);

    printf("\nconcatenated node set info\n");

    printf("ids = \n");
    for (i = 0; i < num_node_sets; i++)
      printf("%3d\n", ids[i]);

    printf("num_nodes_per_set = \n");
    for (i = 0; i < num_node_sets; i++)
      printf("%3d\n", num_nodes_per_set[i]);

    printf("node_ind = \n");
    for (i = 0; i < num_node_sets; i++)
      printf("%3d\n", node_ind[i]);

    printf("node_list = \n");
    for (i = 0; i < list_len; i++)
      printf("%3d\n", node_list[i]);

    printf("dist_fact = \n");
    for (i = 0; i < list_len; i++)
      printf("%5.3f\n", dist_fact[i]);

    free(ids);
    free(df_ind);
    free(node_ind);
    free(num_df_per_set);
    free(node_list);
    free(dist_fact);
  }

  /* read individual side sets */

  if (num_side_sets > 0) {
    ids = (int *)calloc(num_side_sets, sizeof(int));

    error = ex_get_side_set_ids(exoid, ids);
    printf("\nafter ex_get_side_set_ids, error = %3d\n", error);

    for (i = 0; i < num_side_sets; i++) {
      sset_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_names(exoid, EX_SIDE_SET, sset_names);
    printf("\nafter ex_get_names, error = %3d\n", error);

    for (i = 0; i < num_side_sets; i++) {
      ex_get_name(exoid, EX_SIDE_SET, ids[i], name);
      if (strcmp(name, sset_names[i]) != 0) {
        printf("error in ex_get_name for sideset id %d\n", ids[i]);
      }

      error = ex_get_side_set_param(exoid, ids[i], &num_sides_in_set, &num_df_in_set);
      printf("\nafter ex_get_side_set_param, error = %3d\n", error);

      printf("side set %2d parameters:\n", ids[i]);
      printf("name = '%s'\n", sset_names[i]);
      printf("num_sides = %3d\n", num_sides_in_set);
      printf("num_dist_factors = %3d\n", num_df_in_set);
      free(sset_names[i]);

      /* Note: The # of elements is same as # of sides!  */
      num_elem_in_set = num_sides_in_set;
      elem_list       = (int *)calloc(num_elem_in_set, sizeof(int));
      side_list       = (int *)calloc(num_sides_in_set, sizeof(int));
      node_ctr_list   = (int *)calloc(num_elem_in_set, sizeof(int));
      node_list       = (int *)calloc(num_elem_in_set * 21, sizeof(int));
      dist_fact       = (float *)calloc(num_df_in_set, sizeof(float));

      error = ex_get_side_set(exoid, ids[i], elem_list, side_list);
      printf("\nafter ex_get_side_set, error = %3d\n", error);

      error = ex_get_side_set_node_list(exoid, ids[i], node_ctr_list, node_list);
      printf("\nafter ex_get_side_set_node_list, error = %3d\n", error);

      if (num_df_in_set > 0) {
        error = ex_get_side_set_dist_fact(exoid, ids[i], dist_fact);
        printf("\nafter ex_get_side_set_dist_fact, error = %3d\n", error);
      }

      printf("element list for side set %2d\n", ids[i]);
      for (j = 0; j < num_elem_in_set; j++) {
        printf("%3d\n", elem_list[j]);
      }

      printf("side list for side set %2d\n", ids[i]);
      for (j = 0; j < num_sides_in_set; j++) {
        printf("%3d\n", side_list[j]);
      }

      node_ctr = 0;
      printf("node list for side set %2d\n", ids[i]);
      for (k = 0; k < num_elem_in_set; k++) {
        for (j = 0; j < node_ctr_list[k]; j++) {
          printf("%3d\n", node_list[node_ctr + j]);
        }
        node_ctr += node_ctr_list[k];
      }

      if (num_df_in_set > 0) {
        printf("dist factors for side set %2d\n", ids[i]);

        for (j = 0; j < num_df_in_set; j++) {
          printf("%5.3f\n", dist_fact[j]);
        }
      }
      else
        printf("no dist factors for side set %2d\n", ids[i]);

      free(elem_list);
      free(side_list);
      free(node_ctr_list);
      free(node_list);
      free(dist_fact);
    }

    /* read side set properties */
    error = ex_inquire(exoid, EX_INQ_SS_PROP, &num_props, &fdum, cdum);
    printf("\nafter ex_inquire, error = %d\n", error);
    printf("\nThere are %2d properties for each side set\n", num_props);

    for (i = 0; i < num_props; i++) {
      prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_prop_names(exoid, EX_SIDE_SET, prop_names);
    printf("after ex_get_prop_names, error = %d\n", error);

    for (i = 0; i < num_props; i++) {
      for (j = 0; j < num_side_sets; j++) {
        error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i], &prop_value);
        if (error == 0)
          printf("side set %2d, property(%2d): '%s'= %5d\n", j + 1, i + 1, prop_names[i],
                 prop_value);
        else
          printf("after ex_get_prop, error = %d\n", error);
      }
    }
    for (i = 0; i < num_props; i++)
      free(prop_names[i]);
    free(ids);

    error = ex_inquire(exoid, EX_INQ_SIDE_SETS, &num_side_sets, &fdum, cdum);
    printf("\nafter ex_inquire: EX_INQ_SIDE_SETS = %d,  error = %d\n", num_side_sets, error);

    if (num_side_sets > 0) {
      error = ex_inquire(exoid, EX_INQ_SS_ELEM_LEN, &elem_list_len, &fdum, cdum);
      printf("\nafter ex_inquire: EX_INQ_SS_ELEM_LEN = %d,  error = %d\n", elem_list_len, error);

      error = ex_inquire(exoid, EX_INQ_SS_NODE_LEN, &node_list_len, &fdum, cdum);
      printf("\nafter ex_inquire: EX_INQ_SS_NODE_LEN = %d,  error = %d\n", node_list_len, error);

      error = ex_inquire(exoid, EX_INQ_SS_DF_LEN, &df_list_len, &fdum, cdum);
      printf("\nafter ex_inquire: EX_INQ_SS_DF_LEN = %d,  error = %d\n", df_list_len, error);
    }

    /* read concatenated side sets; this produces the same information as
     * the above code which reads individual side sets
     */

    /* concatenated side set read */

    if (num_side_sets > 0) {
      ids              = (int *)calloc(num_side_sets, sizeof(int));
      num_elem_per_set = (int *)calloc(num_side_sets, sizeof(int));
      num_df_per_set   = (int *)calloc(num_side_sets, sizeof(int));
      elem_ind         = (int *)calloc(num_side_sets, sizeof(int));
      df_ind           = (int *)calloc(num_side_sets, sizeof(int));
      elem_list        = (int *)calloc(elem_list_len, sizeof(int));
      side_list        = (int *)calloc(elem_list_len, sizeof(int));
      dist_fact        = (float *)calloc(df_list_len, sizeof(float));

      error = ex_get_concat_side_sets(exoid, ids, num_elem_per_set, num_df_per_set, elem_ind,
                                      df_ind, elem_list, side_list, dist_fact);
      printf("\nafter ex_get_concat_side_sets, error = %3d\n", error);

      printf("concatenated side set info\n");

      printf("ids = \n");
      for (i = 0; i < num_side_sets; i++)
        printf("%3d\n", ids[i]);

      printf("num_elem_per_set = \n");
      for (i = 0; i < num_side_sets; i++)
        printf("%3d\n", num_elem_per_set[i]);

      printf("num_dist_per_set = \n");
      for (i = 0; i < num_side_sets; i++)
        printf("%3d\n", num_df_per_set[i]);

      printf("elem_ind = \n");
      for (i = 0; i < num_side_sets; i++)
        printf("%3d\n", elem_ind[i]);

      printf("dist_ind = \n");
      for (i = 0; i < num_side_sets; i++)
        printf("%3d\n", df_ind[i]);

      printf("elem_list = \n");
      for (i = 0; i < elem_list_len; i++)
        printf("%3d\n", elem_list[i]);

      printf("side_list = \n");
      for (i = 0; i < elem_list_len; i++)
        printf("%3d\n", side_list[i]);

      printf("dist_fact = \n");
      for (i = 0; i < df_list_len; i++)
        printf("%5.3f\n", dist_fact[i]);

      free(ids);
      free(num_df_per_set);
      free(df_ind);
      free(elem_ind);
      free(elem_list);
      free(side_list);
      free(dist_fact);
    }
  }
  /* end of concatenated side set read */

  /* read QA records */

  ex_inquire(exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum);

  for (i = 0; i < num_qa_rec; i++) {
    for (j = 0; j < 4; j++) {
      qa_record[i][j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }
  }

  error = ex_get_qa(exoid, qa_record);
  printf("\nafter ex_get_qa, error = %3d\n", error);

  printf("QA records = \n");
  for (i = 0; i < num_qa_rec; i++) {
    for (j = 0; j < 4; j++) {
      printf(" '%s'\n", qa_record[i][j]);
      free(qa_record[i][j]);
    }
  }

  /* read information records */

  error = ex_inquire(exoid, EX_INQ_INFO, &num_info, &fdum, cdum);
  printf("\nafter ex_inquire, error = %3d\n", error);

  for (i = 0; i < num_info; i++) {
    info[i] = (char *)calloc((MAX_LINE_LENGTH + 1), sizeof(char));
  }

  error = ex_get_info(exoid, info);
  printf("\nafter ex_get_info, error = %3d\n", error);

  printf("info records = \n");
  for (i = 0; i < num_info; i++) {
    printf(" '%s'\n", info[i]);
    free(info[i]);
  }

  /* read global variables parameters and names */

  error = ex_get_var_param(exoid, "g", &num_glo_vars);
  printf("\nafter ex_get_var_param, error = %3d\n", error);

  for (i = 0; i < num_glo_vars; i++) {
    var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
  }

  error = ex_get_var_names(exoid, "g", num_glo_vars, var_names);
  printf("\nafter ex_get_var_names, error = %3d\n", error);

  printf("There are %2d global variables; their names are :\n", num_glo_vars);
  for (i = 0; i < num_glo_vars; i++) {
    printf(" '%s'\n", var_names[i]);
    free(var_names[i]);
  }

  /* read nodal variables parameters and names */
  num_nod_vars = 0;
  if (num_nodes > 0) {
    error = ex_get_var_param(exoid, "n", &num_nod_vars);
    printf("\nafter ex_get_var_param, error = %3d\n", error);

    for (i = 0; i < num_nod_vars; i++) {
      var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_var_names(exoid, "n", num_nod_vars, var_names);
    printf("\nafter ex_get_var_names, error = %3d\n", error);

    printf("There are %2d nodal variables; their names are :\n", num_nod_vars);
    for (i = 0; i < num_nod_vars; i++) {
      printf(" '%s'\n", var_names[i]);
      free(var_names[i]);
    }
  }

  /* read element variables parameters and names */

  num_ele_vars = 0;
  if (num_elem > 0) {
    error = ex_get_var_param(exoid, "e", &num_ele_vars);
    printf("\nafter ex_get_var_param, error = %3d\n", error);

    for (i = 0; i < num_ele_vars; i++) {
      var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

    error = ex_get_var_names(exoid, "e", num_ele_vars, var_names);
    printf("\nafter ex_get_var_names, error = %3d\n", error);

    printf("There are %2d element variables; their names are :\n", num_ele_vars);
    for (i = 0; i < num_ele_vars; i++) {
      printf(" '%s'\n", var_names[i]);
      free(var_names[i]);
    }

    /* read element variable truth table */

    if (num_ele_vars > 0) {
      truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int));

      error = ex_get_elem_var_tab(exoid, num_elem_blk, num_ele_vars, truth_tab);
      printf("\nafter ex_get_elem_var_tab, error = %3d\n", error);

      printf("This is the element variable truth table:\n");

      k = 0;
      for (i = 0; i < num_elem_blk * num_ele_vars; i++) {
        printf("%2d\n", truth_tab[k++]);
      }
      free(truth_tab);
    }
  }

  /* read nodeset variables parameters and names */

  num_nset_vars = 0;
  if (num_node_sets > 0) {
    error = ex_get_var_param(exoid, "m", &num_nset_vars);
    printf("\nafter ex_get_var_param, error = %3d\n", error);

    if (num_nset_vars > 0) {
      for (i = 0; i < num_nset_vars; i++) {
        var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
      }

      error = ex_get_var_names(exoid, "m", num_nset_vars, var_names);
      printf("\nafter ex_get_var_names, error = %3d\n", error);

      printf("There are %2d nodeset variables; their names are :\n", num_nset_vars);
      for (i = 0; i < num_nset_vars; i++) {
        printf(" '%s'\n", var_names[i]);
        free(var_names[i]);
      }

      /* read nodeset variable truth table */

      if (num_nset_vars > 0) {
        truth_tab = (int *)calloc((num_node_sets * num_nset_vars), sizeof(int));

        error = ex_get_nset_var_tab(exoid, num_node_sets, num_nset_vars, truth_tab);
        printf("\nafter ex_get_nset_var_tab, error = %3d\n", error);

        printf("This is the nodeset variable truth table:\n");

        k = 0;
        for (i = 0; i < num_node_sets * num_nset_vars; i++) {
          printf("%2d\n", truth_tab[k++]);
        }
        free(truth_tab);
      }
    }
  }

  /* read sideset variables parameters and names */

  num_sset_vars = 0;
  if (num_side_sets > 0) {
    error = ex_get_var_param(exoid, "s", &num_sset_vars);
    printf("\nafter ex_get_var_param, error = %3d\n", error);

    if (num_sset_vars > 0) {
      for (i = 0; i < num_sset_vars; i++) {
        var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
      }

      error = ex_get_var_names(exoid, "s", num_sset_vars, var_names);
      printf("\nafter ex_get_var_names, error = %3d\n", error);

      printf("There are %2d sideset variables; their names are :\n", num_sset_vars);
      for (i = 0; i < num_sset_vars; i++) {
        printf(" '%s'\n", var_names[i]);
        free(var_names[i]);
      }

      /* read sideset variable truth table */

      if (num_sset_vars > 0) {
        truth_tab = (int *)calloc((num_side_sets * num_sset_vars), sizeof(int));

        error = ex_get_sset_var_tab(exoid, num_side_sets, num_sset_vars, truth_tab);
        printf("\nafter ex_get_sset_var_tab, error = %3d\n", error);

        printf("This is the sideset variable truth table:\n");

        k = 0;
        for (i = 0; i < num_side_sets * num_sset_vars; i++) {
          printf("%2d\n", truth_tab[k++]);
        }
        free(truth_tab);
      }
    }
  }

  /* determine how many time steps are stored */

  error = ex_inquire(exoid, EX_INQ_TIME, &num_time_steps, &fdum, cdum);
  printf("\nafter ex_inquire, error = %3d\n", error);
  printf("There are %2d time steps in the database.\n", num_time_steps);

  /* read time value at one time step */

  time_step = 3;
  error     = ex_get_time(exoid, time_step, &time_value);
  printf("\nafter ex_get_time, error = %3d\n", error);

  printf("time value at time step %2d = %5.3f\n", time_step, time_value);

  /* read time values at all time steps */

  time_values = (float *)calloc(num_time_steps, sizeof(float));

  error = ex_get_all_times(exoid, time_values);
  printf("\nafter ex_get_all_times, error = %3d\n", error);

  printf("time values at all time steps are:\n");
  for (i = 0; i < num_time_steps; i++)
    printf("%5.3f\n", time_values[i]);

  free(time_values);

  /* read all global variables at one time step */

  var_values = (float *)calloc(num_glo_vars, sizeof(float));

  error = ex_get_glob_vars(exoid, time_step, num_glo_vars, var_values);
  printf("\nafter ex_get_glob_vars, error = %3d\n", error);

  printf("global variable values at time step %2d\n", time_step);
  for (i = 0; i < num_glo_vars; i++)
    printf("%5.3f\n", var_values[i]);

  free(var_values);

  /* read a single global variable through time */

  var_index = 1;
  beg_time  = 1;
  end_time  = -1;

  var_values = (float *)calloc(num_time_steps, sizeof(float));

  error = ex_get_glob_var_time(exoid, var_index, beg_time, end_time, var_values);
  printf("\nafter ex_get_glob_var_time, error = %3d\n", error);

  printf("global variable %2d values through time:\n", var_index);
  for (i = 0; i < num_time_steps; i++)
    printf("%5.3f\n", var_values[i]);

  free(var_values);

  /* read a nodal variable at one time step */

  if (num_nodes > 0) {
    var_values = (float *)calloc(num_nodes, sizeof(float));

    error = ex_get_nodal_var(exoid, time_step, var_index, num_nodes, var_values);
    printf("\nafter ex_get_nodal_var, error = %3d\n", error);

    printf("nodal variable %2d values at time step %2d\n", var_index, time_step);
    for (i = 0; i < num_nodes; i++)
      printf("%5.3f\n", var_values[i]);

    free(var_values);

    /* read a nodal variable through time */

    var_values = (float *)calloc(num_time_steps, sizeof(float));

    node_num = 1;
    error    = ex_get_nodal_var_time(exoid, var_index, node_num, beg_time, end_time, var_values);
    printf("\nafter ex_get_nodal_var_time, error = %3d\n", error);

    printf("nodal variable %2d values for node %2d through time:\n", var_index, node_num);
    for (i = 0; i < num_time_steps; i++)
      printf("%5.3f\n", var_values[i]);

    free(var_values);
  }
  /* read an element variable at one time step */

  if (num_elem_blk > 0) {
    ids = (int *)calloc(num_elem_blk, sizeof(int));

    error = ex_get_elem_blk_ids(exoid, ids);
    printf("\n after ex_get_elem_blk_ids, error = %3d\n", error);

    for (i = 0; i < num_elem_blk; i++) {
      if (num_elem_in_block[i] > 0) {
        var_values = (float *)calloc(num_elem_in_block[i], sizeof(float));

        error =
            ex_get_elem_var(exoid, time_step, var_index, ids[i], num_elem_in_block[i], var_values);
        printf("\nafter ex_get_elem_var, error = %3d\n", error);

        if (!error) {
          printf("element variable %2d values of element block %2d at time step %2d\n", var_index,
                 ids[i], time_step);
          for (j = 0; j < num_elem_in_block[i]; j++)
            printf("%5.3f\n", var_values[j]);
        }

        free(var_values);
      }
    }
    free(num_elem_in_block);
    free(ids);
  }
  /* read an element variable through time */

  if (num_ele_vars > 0) {
    var_values = (float *)calloc(num_time_steps, sizeof(float));

    var_index = 2;
    elem_num  = 2;
    error     = ex_get_elem_var_time(exoid, var_index, elem_num, beg_time, end_time, var_values);
    printf("\nafter ex_get_elem_var_time, error = %3d\n", error);

    printf("element variable %2d values for element %2d through time:\n", var_index, elem_num);
    for (i = 0; i < num_time_steps; i++)
      printf("%5.3f\n", var_values[i]);

    free(var_values);
  }

  /* read a sideset variable at one time step */

  if (num_sset_vars > 0) {
    ids = (int *)calloc(num_side_sets, sizeof(int));

    error = ex_get_side_set_ids(exoid, ids);
    printf("\n after ex_get_side_set_ids, error = %3d\n", error);

    for (i = 0; i < num_side_sets; i++) {
      var_values = (float *)calloc(num_elem_per_set[i], sizeof(float));

      error = ex_get_sset_var(exoid, time_step, var_index, ids[i], num_elem_per_set[i], var_values);
      printf("\nafter ex_get_sset_var, error = %3d\n", error);

      if (!error) {
        printf("sideset variable %2d values of sideset %2d at time step %2d\n", var_index, ids[i],
               time_step);
        for (j = 0; j < num_elem_per_set[i]; j++)
          printf("%5.3f\n", var_values[j]);
      }

      free(var_values);
    }
    free(num_elem_per_set);
    free(ids);
  }

  /* read a nodeset variable at one time step */

  if (num_nset_vars > 0) {
    ids = (int *)calloc(num_node_sets, sizeof(int));

    error = ex_get_node_set_ids(exoid, ids);
    printf("\n after ex_get_node_set_ids, error = %3d\n", error);

    for (i = 0; i < num_node_sets; i++) {
      var_values = (float *)calloc(num_nodes_per_set[i], sizeof(float));

      error =
          ex_get_nset_var(exoid, time_step, var_index, ids[i], num_nodes_per_set[i], var_values);
      printf("\nafter ex_get_nset_var, error = %3d\n", error);

      if (!error) {
        printf("nodeset variable %2d values of nodeset %2d at time step %2d\n", var_index, ids[i],
               time_step);
        for (j = 0; j < num_nodes_per_set[i]; j++)
          printf("%5.3f\n", var_values[j]);
      }

      free(var_values);
    }
    free(ids);
  }
  if (num_node_sets > 0)
    free(num_nodes_per_set);

  error = ex_close(exoid);
  printf("\nafter ex_close, error = %3d\n", error);
  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()-------------------------------*/
Example #20
0
int main(int argc, char *argv[])
{
  const char         *salsa_cmd_file;
  int c;

  double g_start_t = second();
  bool force_64_bit = false;
  int start_proc = 0;
  int num_proc = 0;
  int subcycles = 0;
  int cycle = -1;
  while ((c = getopt(argc, argv, "64Vhp:r:s:n:S:c:")) != -1) {
    switch (c) {
    case 'h':
      fprintf(stderr, " usage:\n");
      fprintf(stderr, "\tnem_spread  [-s <start_proc>] [-n <num_proc>] [-S <subcycles> -c <cycle>] [command_file]\n");
      fprintf(stderr, "\t\tDecompose for processors <start_proc> to <start_proc>+<num_proc>\n");
      fprintf(stderr, "\t\tDecompose for cycle <cycle> of <subcycle> groups\n");
      fprintf(stderr, "\tnem_spread  [-V] [-h] (show version or usage info)\n");
      fprintf(stderr, "\tnem_spread  [command file] [<-p Proc> <-r raid #>]\n");
      exit(1);
      break;
    case 'V':
      printf("%s version %s\n", UTIL_NAME, VER_STR);
      exit(0);
      break;
    case 'p': /* Which proc to use? Also for compatability */
      break;
    case 'r': /* raid number.  Seems to be unused; left around for compatability */
      break;
    case 's': /* Start with processor <x> */
      sscanf(optarg, "%d", &start_proc);
      break;
    case 'n': /* Number of processors to output files for */
      sscanf(optarg, "%d", &num_proc);
      break;
    case '6':
    case '4':
      force_64_bit = true; /* Force storing output mesh using 64bit integers */
      break;
    case 'S': /* Number of subcycles to use (see below) */
      sscanf(optarg, "%d", &subcycles);
      break;
    case 'c': /* Which cycle to spread (see below) */
      sscanf(optarg, "%d", &cycle);
      break;
    }
  }

  if (optind >= argc)
    salsa_cmd_file = "nem_spread.inp";
  else {
    salsa_cmd_file = argv[optind];
  }
    
  printf("%s version %s\n", UTIL_NAME, VER_STR);

  /* initialize some variables */
  ExoFile[0]                    = '\0';
  Exo_LB_File[0]                = '\0';
  Exo_Res_File[0]               = '\0';
  Debug_Flag                    = -1;

  Num_Nod_Var                   = -1;
  Num_Elem_Var                  = -1;
  Num_Glob_Var                  = -1;
  Num_Nset_Var                  = -1;
  Num_Sset_Var                  = -1;

  PIO_Info.Dsk_List_Cnt         = -1;
  PIO_Info.Num_Dsk_Ctrlrs       = -1;
  PIO_Info.PDsk_Add_Fact        = -1;
  PIO_Info.Zeros                = -1;
  PIO_Info.NoSubdirectory       =  0;
  PIO_Info.Par_Dsk_Root[0]      = '\0';
  PIO_Info.Par_Dsk_SubDirec[0]  = '\0';
  PIO_Info.Staged_Writes[0]     = '\0';

  // Read the ASCII input file and get the name of the mesh file
  // so we can determine the floating point and integer word sizes
  // needed to instantiate the templates...
  if (read_mesh_file_name(salsa_cmd_file) < 0) {
    static char yo[] = "nem_spread";
    fprintf(stderr,"%s ERROR: Could not read in the the I/O command file"
	    " \"%s\"!\n", yo, salsa_cmd_file);
    exit(1);
  }

  // Open the mesh file and determine word sizes...
  int io_ws = 0;
  int cpu_ws = sizeof(float);
  float version;
  
  int exoid = ex_open (ExoFile, EX_READ, &cpu_ws, &io_ws, &version);

  // See if any 64-bit integers stored on database...
  int int64api = 0;
  int int64db = ex_int64_status(exoid) & EX_ALL_INT64_DB;
  if (int64db != 0) {
    int64api = EX_ALL_INT64_API;
  }
  
  
  int status;
  if (io_ws == 4) {
    if (int64api) {
      NemSpread<float, int64_t> spreader;
      spreader.io_ws = io_ws;
      spreader.int64db = int64db;
      spreader.int64api = int64api;
      spreader.force64db = force_64_bit;
      spreader.Proc_Info[4] = start_proc;
      spreader.Proc_Info[5] = num_proc;
      status = nem_spread(spreader, salsa_cmd_file, subcycles, cycle);
    } else {
      NemSpread<float, int> spreader;
      spreader.io_ws = io_ws;
      spreader.int64db = int64db;
      spreader.int64api = int64api;
      spreader.force64db = force_64_bit;
      spreader.Proc_Info[4] = start_proc;
      spreader.Proc_Info[5] = num_proc;
      status = nem_spread(spreader, salsa_cmd_file, subcycles, cycle);
    }
  } else {
    if (int64api) {
      NemSpread<double, int64_t> spreader;
      spreader.io_ws = io_ws;
      spreader.int64db = int64db;
      spreader.int64api = int64api;
      spreader.force64db = force_64_bit;
      spreader.Proc_Info[4] = start_proc;
      spreader.Proc_Info[5] = num_proc;
      status = nem_spread(spreader, salsa_cmd_file, subcycles, cycle);
    } else {
      NemSpread<double, int> spreader;
      spreader.io_ws = io_ws;
      spreader.int64db = int64db;
      spreader.int64api = int64api;
      spreader.force64db = force_64_bit;
      spreader.Proc_Info[4] = start_proc;
      spreader.Proc_Info[5] = num_proc;
      status = nem_spread(spreader, salsa_cmd_file, subcycles, cycle);
    }
  }
  double g_end_t = second() - g_start_t;
  printf("The average run time was: %.2fs\n", g_end_t);

  ex_close(exoid);
  add_to_log(argv[0], g_end_t);
  return status;
}
Example #21
0
void NemSpread<T,INT>::read_restart_params()

/* Function which reads the restart variable parameters for the EXODUS II
 * database which contains the results information. Allocate necessary
 * memory on each processor.
 *
 *----------------------------------------------------------------------------
 *
 * Functions called:
 *
 * compare_mesh_param -- function which checks that parameters in
 *                       the restart EXODUS II file are the same as in
 *                       the mesh EXODUS II file
 * read_var_param -- function which reads the time indicies, number
 *                   of variables, and their names from the restart file
 *
 *----------------------------------------------------------------------------
 */

{
    const char  *yo="read_restart_params";

    int    exoid, cpu_ws=0;
    float  vers;
    int    max_name_length = 0;

    /* Open the ExodusII file */
    cpu_ws = io_ws;
    int mode = EX_READ | int64api;
    if ((exoid=ex_open(Exo_Res_File, mode, &cpu_ws, &io_ws, &vers)) < 0) {
        fprintf(stderr, "%s: Could not open file %s for restart info\n",
                yo, Exo_Res_File);
        exit(1);
    }

    max_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
    ex_set_max_name_length(exoid, max_name_length);

    /*
     * Just do a rudimentary check to figure out if the mesh parameters
     * in the results file are the same as the mesh parameters in the
     * mesh file.
     */
    if (strcmp(ExoFile, Exo_Res_File) != 0)
        if (!compare_mesh_param(exoid)) {
            fprintf(stderr, "%s: Mesh parameters in mesh and result files"
                    " differ\n", yo);
            exit(1);
        }

    /* get the time, and the variable names */
    if (read_var_param(exoid, max_name_length) < 0) {
        fprintf(stderr, "%s: Error occured while reading variable parameters\n",
                yo);
        exit(1);
    }

    /* Close the ExodusII file */
    ex_close(exoid);

    return;
}
Example #22
0
void
set_init_Element_Storage(ELEM_BLK_STRUCT *eb_ptr, int mn)

     /*****************************************************************
      *
      * set_init_Element_Storage()
      *
      *
      * like its predecessor init_element_storage, this function actually
      * places initial values for the draining and wetting curves for the
      * TANH_HYST function, according to the request in the material property
      * database cards for the current material
      *
      *****************************************************************/
{
  int ielem_type, ip_total, i, j, ifound, ip;
  double sat_switch = 0.0, pc_switch = 0.0, Draining_curve, *ev_tmp;
  int error, num_dim, num_nodes;
  int num_elem, num_elem_blk, num_node_sets, num_side_sets, time_step;
  float	version;		/* version number of EXODUS II */
  int	exoid;			/* ID of the open EXODUS II file */
  char	title[MAX_LINE_LENGTH];	/* title of the EXODUS II database */
  float	ret_float;		/* any returned float */
  char	ret_char[3];		/* any returned character */
  int	num_vars;		/* number of var_type variables */
  char	**var_names = NULL;     /* array containing num_vars variable names */
  char  appended_name[MAX_VAR_NAME_LNGTH];


  /*Quick return if model is not hysteretic in nature */
    
  if(mp_glob[mn]->SaturationModel == TANH_HYST)
    {
  
      ielem_type      = eb_ptr->Elem_Type;
      ip_total        = eb_ptr->IP_total;
      Draining_curve   = mp_glob[mn]->u_saturation[8];
      if (Guess_Flag ==4 || Guess_Flag == 5)
	{
	  EH(-1,"Not a smooth restart for hysteretic saturation function. If you really want to do this use read_exoII_file or call us");
	}

      if(Guess_Flag == 5 || Guess_Flag == 6)
	{
	  WH(-1,"Initializing Hysteretic Curve values at all Gauss points with read_exoII_file");
	  CPU_word_size = sizeof(double);
	  IO_word_size  = 0;    

	  exoid = ex_open(ExoAuxFile, EX_READ, &CPU_word_size, &IO_word_size , &version);
	  EH(exoid, "ex_open");

	  error = ex_get_init(exoid, title, &num_dim, &num_nodes, &num_elem,
			      &num_elem_blk, &num_node_sets, &num_side_sets);
	  EH(error, "ex_get_init for efv or init guess");

	  /*
	   * Obtain the number of time steps in the exodus file, time_step,
	   * We will read only from the last time step
	   */
	  error = ex_inquire(exoid, EX_INQ_TIME, &time_step, &ret_float, ret_char);
	  EH(error, "ex_inquire");

	  /* Based on problem type and available info in database, extract 
	   * appropriate fields
	   */

	  /*
	   * Get the number of nodal variables in the file, and allocate
	   * space for storage of their names.
	   */
	  error = ex_get_var_param(exoid, "e", &num_vars);
	  EH(error, "ex_get_var_param");
  
	  /* First extract all nodal variable names in exoII database */
	  if (num_vars > 0) {
	    var_names = alloc_VecFixedStrings(num_vars, (MAX_STR_LENGTH+1));
	    error = ex_get_var_names(exoid, "e", num_vars, var_names);
	    EH(error, "ex_get_var_names");
	    for (i = 0; i < num_vars; i++) strip(var_names[i]);
	  } else {
	    fprintf(stderr,
		    "Warning: no element variables for saturation stored in exoII input file.\n");
	  }


	  /*****THIS IS WHERE YOU LOAD THEM UP ******/

	  ev_tmp = (double *) smalloc(eb_ptr->Num_Elems_In_Block* sizeof(double));
	  ifound = 0;

	  for(ip = 0; ip < ip_total; ip++)
	    {
	      sprintf(appended_name,  "sat_curve_type%d", ip );
	      for(j=0; j < num_vars; j++)
		{
		  if(!strcasecmp(appended_name,var_names[j]))
		    {
		      /*Found variable so load it into element storage */
		      error  = ex_get_elem_var(exoid, time_step, j+1, 
					       eb_ptr->Elem_Blk_Id,
					       eb_ptr->Num_Elems_In_Block,
					       ev_tmp);
		      ifound = 1;
		    }
		}
	      if(ifound)
		{
		  for (i = 0; i < eb_ptr->Num_Elems_In_Block; i++) 
		    {
		      eb_ptr->ElemStorage[i].sat_curve_type[ip] = ev_tmp[i];
		    }
		}
	      else
		{
		  EH(-1,"Cannot find an element variable for sat. hysteresis");
		}

	      ifound = 0;

	      sprintf(appended_name,  "sat_switch%d", ip );
	      for(j=0; j < num_vars; j++)
		{
		  if(!strcasecmp(appended_name,var_names[j]))
		    {
		      /*Found variable so load it into element storage */
		      error  = ex_get_elem_var(exoid, time_step, j+1, 
					       eb_ptr->Elem_Blk_Id,
					       eb_ptr->Num_Elems_In_Block,
					       ev_tmp);
		      ifound = 1;
		    }
		}
	      if(ifound)
		{
		  for (i = 0; i < eb_ptr->Num_Elems_In_Block; i++) 
		    {
		      eb_ptr->ElemStorage[i].Sat_QP_tn[ip] = ev_tmp[i];
		    }
		}
	      else
		{
		  EH(-1,"Cannot find an element variable for sat. hysteresis");
		}

	      ifound = 0;
	      sprintf(appended_name,  "pc_switch%d", ip );
	      for(j=0; j < num_vars; j++)
		{
		  if(!strcasecmp(appended_name,var_names[j]))
		    {
		      /*Found variable so load it into element storage */
		      error  = ex_get_elem_var(exoid, time_step, j+1, 
					       eb_ptr->Elem_Blk_Id,
					       eb_ptr->Num_Elems_In_Block,
					       ev_tmp);
		      ifound = 1;
		    }
		}
	      if(ifound)
		{
		  for (i = 0; i < eb_ptr->Num_Elems_In_Block; i++) 
		    {
		      eb_ptr->ElemStorage[i].p_cap_QP[ip] = ev_tmp[i];
		    }
		}
	      else
		{
		  EH(-1,"Cannot find an element variable for sat. hysteresis");
		}

	    }
	  
	  error = ex_close(exoid);
	  safer_free((void **) &var_names);
	  free(ev_tmp);
	}
      else /*Initialize as dictated by input cards */
	{

	  if(Draining_curve == 1.0)
	    {
	      sat_switch = mp->u_saturation[0];
	      pc_switch = 1.e-12;
	    }
	  else if (Draining_curve == 0.0)
	    {
	      double sat_max = mp->u_saturation[0];
	      double sat_min = mp->u_saturation[4];
	      double alpha_w = mp->u_saturation[3];
	      double beta_w  = mp->u_saturation[2];

	      pc_switch = 1.e12*alpha_w;
	      sat_switch = sat_max - ( sat_max - sat_min)*0.5*(1.0+tanh( beta_w - alpha_w/pc_switch ) ) ;
	    }
	  else
	    {
	      EH(-1,"TANH_HYST must have 1.0 or 0.0 in  9th spot");
	    }

	  for (i = 0; i < eb_ptr->Num_Elems_In_Block; i++) 
	    {
	      for(ip = 0; ip < ip_total; ip++)
		{
		  eb_ptr->ElemStorage[i].p_cap_QP[ip] = pc_switch;
		  eb_ptr->ElemStorage[i].Sat_QP_tn[ip] = sat_switch;
		  eb_ptr->ElemStorage[i].sat_curve_type[ip] = Draining_curve;
		}
	    }
	}
    }

  if(elc_glob[mn]->thermal_expansion_model == SHRINKAGE)
    {
      ip_total        = eb_ptr->IP_total;
      if (Guess_Flag ==4 || Guess_Flag == 5)
	{
	  EH(-1,"Not a smooth restart for solidification shrinkage model.Use read_exoII_file or call us");
	}

      if(Guess_Flag == 5 || Guess_Flag == 6)
	{
	  EH(-1,"Initializing solidified shrinkage model from exoII file not available yet. Use zero");
	}
	
      // Load em up as all unsolidified

      for(ip = 0; ip < ip_total; ip++)
	{
	  for (i = 0; i < eb_ptr->Num_Elems_In_Block; i++) 
	    {
	      eb_ptr->ElemStorage[i].solidified[ip] = 0.0;
	    }
	}
    }
}
Example #23
0
int read_exoII_file(int Proc,
                    int Num_Proc,
                    PROB_INFO_PTR prob,
                    PARIO_INFO_PTR pio_info,
                    MESH_INFO_PTR mesh)
{
#ifndef ZOLTAN_NEMESIS
  Gen_Error(0, "Fatal:  Nemesis requested but not linked with driver.");
  return 0;

#else /* ZOLTAN_NEMESIS */
  /* Local declarations. */
  char  *yo = "read_exoII_mesh";
  char   par_nem_fname[FILENAME_MAX+1], title[MAX_LINE_LENGTH+1];
  char   cmesg[256];

  float  ver;

  int    i, pexoid, cpu_ws = 0, io_ws = 0;
  int   *nnodes = NULL, *etypes = NULL;
#ifdef DEBUG_EXO
  int    j, k, elem;
#endif
  FILE  *fdtmp;

/***************************** BEGIN EXECUTION ******************************/

  DEBUG_TRACE_START(Proc, yo);

  /* since this is a test driver, set error reporting in exodus */
  ex_opts(EX_VERBOSE | EX_DEBUG);

  /* generate the parallel filename for this processor */
  gen_par_filename(pio_info->pexo_fname, par_nem_fname, pio_info, Proc,
                   Num_Proc);

  /* 
   * check whether parallel file exists.  do the check with fopen 
   * as ex_open coredumps on the paragon when files do not exist.
   */

  if ((fdtmp = fopen(par_nem_fname, "r")) == NULL) {
    sprintf(cmesg,"fatal: parallel Exodus II file %s does not exist",
            par_nem_fname);
    Gen_Error(0, cmesg);
    return 0;
  }
  else
    fclose(fdtmp);

  /*
   * now open the existing parallel file using Exodus calls.
   */

  if ((pexoid = ex_open(par_nem_fname, EX_READ, &cpu_ws, &io_ws,
                        &ver)) < 0) {
    sprintf(cmesg,"fatal: could not open parallel Exodus II file %s",
            par_nem_fname);
    Gen_Error(0, cmesg);
    return 0;
  }

  /* and get initial information */
  if (ex_get_init(pexoid, title, &(mesh->num_dims),
                  &(mesh->num_nodes), &(mesh->num_elems),
                  &(mesh->num_el_blks), &(mesh->num_node_sets),
                  &(mesh->num_side_sets)) < 0) {
    Gen_Error(0, "fatal: Error returned from ex_get_init");
    return 0;
  }


  /* alocate some memory for the element blocks */
  mesh->data_type = MESH;
  mesh->vwgt_dim = 1;  /* One weight for now. */
  mesh->ewgt_dim = 1;  /* One weight for now. */
  mesh->eb_etypes = (int *) malloc (5 * mesh->num_el_blks * sizeof(int));
  if (!mesh->eb_etypes) {
    Gen_Error(0, "fatal: insufficient memory");
    return 0;
  }
  mesh->eb_ids = mesh->eb_etypes + mesh->num_el_blks;
  mesh->eb_cnts = mesh->eb_ids + mesh->num_el_blks;
  mesh->eb_nnodes = mesh->eb_cnts + mesh->num_el_blks;
  mesh->eb_nattrs = mesh->eb_nnodes + mesh->num_el_blks;

  mesh->eb_names = (char **) malloc (mesh->num_el_blks * sizeof(char *));
  if (!mesh->eb_names) {
    Gen_Error(0, "fatal: insufficient memory");
    return 0;
  }

  mesh->hindex = (int *) malloc(sizeof(int));
  mesh->hindex[0] = 0;

  if (ex_get_elem_blk_ids(pexoid, mesh->eb_ids) < 0) {
    Gen_Error(0, "fatal: Error returned from ex_get_elem_blk_ids");
    return 0;
  }

  /* allocate temporary storage for items needing global reduction.   */
  /* nemesis does not store most element block info about blocks for  */
  /* which the processor owns no elements.                            */
  /* we, however, use this information in migration, so we need to    */
  /* accumulate it for all element blocks.    kdd 2/2001              */

  if (mesh->num_el_blks > 0) {
    nnodes = (int *) malloc(2 * mesh->num_el_blks * sizeof(int));
    if (!nnodes) {
      Gen_Error(0, "fatal: insufficient memory");
      return 0;
    }
    etypes = nnodes + mesh->num_el_blks;
  }

  /* get the element block information */
  for (i = 0; i < mesh->num_el_blks; i++) {

    /* allocate space for name */
    mesh->eb_names[i] = (char *) malloc((MAX_STR_LENGTH+1) * sizeof(char));
    if (!mesh->eb_names[i]) {
      Gen_Error(0, "fatal: insufficient memory");
      return 0;
    }

    if (ex_get_elem_block(pexoid, mesh->eb_ids[i], mesh->eb_names[i],
                          &(mesh->eb_cnts[i]), &(nnodes[i]),
                          &(mesh->eb_nattrs[i])) < 0) {
      Gen_Error(0, "fatal: Error returned from ex_get_elem_block");
      return 0;
    }

    if (mesh->eb_cnts[i] > 0) {
      if ((etypes[i] =  (int) get_elem_type(mesh->eb_names[i],
                                            nnodes[i],
                                            mesh->num_dims)) == E_TYPE_ERROR) {
        Gen_Error(0, "fatal: could not get element type");
        return 0;
      }
    }
    else etypes[i] = (int) NULL_EL;
  }

  /* Perform reduction on necessary fields of element blocks.  kdd 2/2001 */
  MPI_Allreduce(nnodes, mesh->eb_nnodes, mesh->num_el_blks, MPI_INT, MPI_MAX, 
                MPI_COMM_WORLD);
  MPI_Allreduce(etypes, mesh->eb_etypes, mesh->num_el_blks, MPI_INT, MPI_MIN, 
                MPI_COMM_WORLD);
  for (i = 0; i < mesh->num_el_blks; i++) {
    strcpy(mesh->eb_names[i], get_elem_name(mesh->eb_etypes[i]));
  }
  free(nnodes);

  /*
   * allocate memory for the elements
   * allocate a little extra for element migration latter
   */
  mesh->elem_array_len = mesh->num_elems + 5;
  mesh->elements = (ELEM_INFO_PTR) malloc (mesh->elem_array_len 
                                         * sizeof(ELEM_INFO));
  if (!(mesh->elements)) {
    Gen_Error(0, "fatal: insufficient memory");
    return 0;
  }

  /*
   * intialize all of the element structs as unused by
   * setting the globalID to -1
   */
  for (i = 0; i < mesh->elem_array_len; i++) 
    initialize_element(&(mesh->elements[i]));

  /* read the information for the individual elements */
  if (!read_elem_info(pexoid, Proc, prob, mesh)) {
    Gen_Error(0, "fatal: Error returned from read_elem_info");
    return 0;
  }

  /* read the communication information */
  if (!read_comm_map_info(pexoid, Proc, prob, mesh)) {
    Gen_Error(0, "fatal: Error returned from read_comm_map_info");
    return 0;
  }

  /* Close the parallel file */
  if(ex_close (pexoid) < 0) {
    Gen_Error(0, "fatal: Error returned from ex_close");
    return 0;
  }

  /* print out the distributed mesh */
  if (Debug_Driver > 3)
    print_distributed_mesh(Proc, Num_Proc, mesh);

  DEBUG_TRACE_END(Proc, yo);
  return 1;

#endif /* ZOLTAN_NEMESIS */
}
Example #24
0
int main (int argc, char *argv[])
{

  char  
    *str,**str2,*(*qa_records)[4],*line, *oname, *dot, *filename;

  const char* ext=EXT;

  int   
    i,j,k,n,n1,n2,cpu_word_size,io_word_size,exo_file,err,
    num_axes,num_nodes,num_elements,num_blocks,
    num_side_sets,num_node_sets,num_time_steps,
    num_qa_lines,num_info_lines,num_global_vars,
    num_nodal_vars,num_element_vars,num_nodeset_vars, num_sideset_vars,
    *ids,*iscr,*num_elem_in_block,*junk,
    *elem_list,*side_list,
    *nsssides,*nssdfac,
    *nnsnodes,*nnsdfac,
    nstr2, has_ss_dfac;
    
  float
    exo_version;

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

  oname=0;

  /* process arguments */
  for (j=1; j< argc; j++){
    if ( strcmp(argv[j],"-t")==0){    /* write text file (*.m) */
      del_arg(&argc,argv,j);
      textfile=1;
      j--;
      continue;
    }
    if ( strcmp(argv[j],"-o")==0){    /* specify output file name */
      del_arg(&argc,argv,j);
      if ( argv[j] ){
         oname=(char*)calloc(strlen(argv[j])+10,sizeof(char));
	 strcpy(oname,argv[j]);
	 del_arg(&argc,argv,j);
	 printf("output file: %s\n",oname);
      }
      else {
         fprintf(stderr,"Invalid output file specification.\n");
	 return 2;
      }
      j--;

      continue;
    }
  }

   /* QA Info */
  printf("%s: %s, %s\n", qainfo[0], qainfo[2], qainfo[1]);
  
  /* usage message*/
  if(argc != 2){
    printf("%s [options] exodus_file_name.\n",argv[0]);
    printf("   the exodus_file_name is required (exodusII only).\n");
    printf("   Options:\n");
    printf("     -t write a text (.m) file rather than a binary .mat\n");
    printf("     -o output file name (rather than auto generate)\n");
    printf(" ** note **\n");
    printf("Binary files are written by default on all platforms with");
    printf(" available libraries.\n");
    exit(1);
  }

  /* open output file */
  if ( textfile )
    ext=".m";

  if ( !oname ){
      filename = (char*)malloc( strlen(argv[1])+10);
      strcpy(filename,argv[1]);
      dot=strrchr(filename,'.');
      if ( dot ) *dot=0;
      strcat(filename,ext);
  }
  else {
      filename=oname;
  }

  if ( textfile ){
    m_file = fopen(filename,"w");
    if (!m_file ){
      fprintf(stderr,"Unable to open %s\n",filename);
      exit(1);
    }
  }
  else {
    mat_file = Mat_CreateVer(filename, NULL, MAT_FT_MAT5);
    if (mat_file == NULL) {
      fprintf(stderr,"Unable to create matlab file %s\n",filename);
      exit(1);
    }
  }

  /* word sizes */
  cpu_word_size=sizeof(double);
  io_word_size=0;

  /* open exodus file */
  exo_file=ex_open(argv[1],EX_READ,&cpu_word_size,&io_word_size,&exo_version);
  if (exo_file < 0){
    printf("error opening %s\n",argv[1]);
    exit(1);
  }

  /* print */
  fprintf(stderr,"translating %s to %s ...\n",argv[1],filename);

  /* read database paramters */
  line=(char *) calloc ((MAX_LINE_LENGTH+1),sizeof(char));
  err = ex_get_init(exo_file,line,
	&num_axes,&num_nodes,&num_elements,&num_blocks,
        &num_node_sets,&num_side_sets);
  num_qa_lines   = ex_inquire_int(exo_file,EX_INQ_QA);
  num_info_lines = ex_inquire_int(exo_file,EX_INQ_INFO);
  num_time_steps = ex_inquire_int(exo_file,EX_INQ_TIME);
  err=ex_get_variable_param(exo_file,EX_GLOBAL,&num_global_vars);
  err=ex_get_variable_param(exo_file,EX_NODAL,&num_nodal_vars);
  err=ex_get_variable_param(exo_file,EX_ELEM_BLOCK,&num_element_vars);
  err=ex_get_variable_param(exo_file,EX_NODE_SET,&num_nodeset_vars);
  err=ex_get_variable_param(exo_file,EX_SIDE_SET,&num_sideset_vars);


  /* export paramters */
  PutInt("naxes",  1, 1,&num_axes);
  PutInt("nnodes", 1, 1,&num_nodes);
  PutInt("nelems", 1, 1,&num_elements);
  PutInt("nblks",  1, 1,&num_blocks);
  PutInt("nnsets", 1, 1,&num_node_sets);
  PutInt("nssets", 1, 1,&num_side_sets);
  PutInt("nsteps", 1, 1,&num_time_steps);
  PutInt("ngvars", 1, 1,&num_global_vars);
  PutInt("nnvars", 1, 1,&num_nodal_vars);
  PutInt("nevars", 1, 1,&num_element_vars);
  PutInt("nnsvars", 1, 1,&num_nodeset_vars);
  PutInt("nssvars", 1, 1,&num_sideset_vars);

  /* allocate -char- scratch space*/
  n =                              num_info_lines;
  n = (n > num_global_vars) ?  n : num_global_vars;
  n = (n > num_nodal_vars) ?   n : num_nodal_vars;
  n = (n > num_element_vars) ? n : num_element_vars;
  n = (n > num_blocks) ?       n : num_blocks;
  nstr2 = n;
  str2= (char **) calloc (n,sizeof(char *));
  for (i=0;i<nstr2;i++)
    str2[i]=(char *) calloc ((MAX_LINE_LENGTH+1),sizeof(char));
  str= (char *) calloc ((MAX_LINE_LENGTH+1)*n,sizeof(char));

  /* title */
  PutStr("Title",line);

#if 0
  /* QA records */
  if (num_qa_lines > 0 ){
    qa_records  =(char *(*)[4]) calloc (num_qa_lines*4,sizeof(char **));
    for (i=0;i<num_qa_lines;i++) 
      for (j=0;j<4;j++)
	qa_records[i][j]=(char *) calloc ((MAX_STR_LENGTH+1),sizeof(char));
    err=ex_get_qa(exo_file,qa_records);
    str[0]='\0';
    for (i=0;i<num_qa_lines;i++){
      for (j=0;j<4;j++)
	sprintf(str+strlen(str),"%s ",qa_records[i][j]);
      strcat(str,"\n");
    }
    for (i=0;i<num_qa_lines;i++){
        for (j=0;j<4;j++)
	  free(qa_records[i][j]);
    }
    free(qa_records);
  }

  /* information records */
  if (num_info_lines > 0 ){
    err = ex_get_info(exo_file,str2);
    str[0]='\0';
    for (i=0;i<num_info_lines;i++)
      sprintf(str+strlen(str),"%s\n",str2[i]);
    PutStr("info",str);
    str[0]='\0';
    for (i=0;i<num_info_lines;i++)
      if (strncmp(str2[i],"cavi",4)==0)
	sprintf(str+strlen(str),"%s\n",str2[i]);
    PutStr("cvxp",str);
  }
#endif
  /* 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;
  err = ex_get_coord(exo_file,x,y,z);
  PutDbl("x0", num_nodes, 1, x);
  PutDbl("y0", num_nodes, 1, y);
  free(x);
  free(y);
  if (num_axes == 3){ 
    PutDbl("z0",num_nodes,1, z);
    free(z);
  }
  
   /* side sets */
  if(num_side_sets > 0){
    ids=(int *) calloc(num_side_sets,sizeof(int));
    err = ex_get_ids(exo_file,EX_SIDE_SET,ids);
    PutInt( "ssids",num_side_sets, 1,ids);
    nsssides = (int *) calloc(num_side_sets,sizeof(int)); /*dgriffi */
    nssdfac  = (int *) calloc(num_side_sets,sizeof(int)); /*dgriffi */
    for (i=0;i<num_side_sets;i++){
      err = ex_get_set_param(exo_file,EX_SIDE_SET, ids[i],&n1,&n2);
      nsssides[i]=n1; /* dgriffi */
      nssdfac[i]=n2;  /* dgriffi */
      /*
       * the following provision is from Version 1.6 when there are no
       * distribution factors in exodus file
       */
      has_ss_dfac = (n2 != 0);
      if(n2==0 || n1==n2){
	
	printf(" WARNING: Exodus II file does not contain distribution factors.\n");
	
	/* n1=number of faces, n2=number of df */
	/* using distribution factors to determine number of nodes in the sideset
         causes a lot grief since some codes do not output distribution factors
         if they are all equal to 1. mkbhard: I am using the function call below
         to figure out the total number of nodes in this sideset. Some redundancy
         exists, but it works for now */

	junk = (int*) calloc(n1,sizeof(int)); 
	err = ex_get_side_set_node_count(exo_file,ids[i],junk);
	n2=0; /* n2 will be equal to the total number of nodes in the sideset */
	for (j=0;j<n1;j++) n2+=junk[j];
	free(junk);

      }
	
      iscr = (int *) calloc(n1+n2,sizeof(int));
      err = ex_get_side_set_node_list(exo_file,ids[i],iscr,iscr+n1);
      /* number-of-nodes-per-side list */
      sprintf(str,"ssnum%02d",i+1);
      PutInt(str,n1,1,iscr); 
      /* nodes list */
      sprintf(str,"ssnod%02d",i+1);
      PutInt(str,n2,1,iscr+n1);
      free(iscr);
      /* distribution-factors list */
      scr = (double *) calloc (n2,sizeof(double));
      if (has_ss_dfac) {
	ex_get_side_set_dist_fact(exo_file,ids[i],scr);
      } else {
	for (j=0; j<n2; j++) {
	  scr[j] = 1.0;
	}
      }
      sprintf(str,"ssfac%02d",i+1);
      PutDbl(str,n2,1,scr);
      free(scr);
      /* element and side list for side sets (dgriffi) */
      elem_list = (int *) calloc(n1, sizeof(int));
      side_list = (int *) calloc(n1, sizeof(int));
      err = ex_get_set(exo_file,EX_SIDE_SET,ids[i],elem_list,side_list);
      sprintf(str,"ssside%02d",i+1);
      PutInt(str,n1,1,side_list);
      sprintf(str,"sselem%02d",i+1);
      PutInt(str,n1,1,elem_list);
      free(elem_list);
      free(side_list);

    }
    /* Store # sides and # dis. factors per side set (dgriffi) */
    PutInt("nsssides",num_side_sets,1,nsssides);
    PutInt("nssdfac",num_side_sets,1,nssdfac);
    free(ids);
    free(nsssides);
    free(nssdfac);
  }

  /* node sets (section by dgriffi) */
  if(num_node_sets > 0){
    ids=(int *) calloc(num_node_sets,sizeof(int));
    err = ex_get_ids(exo_file,EX_NODE_SET, ids);
    PutInt( "nsids",num_node_sets, 1,ids);
    nnsnodes = (int *) calloc(num_node_sets,sizeof(int)); 
    nnsdfac  = (int *) calloc(num_node_sets,sizeof(int));
    for (i=0;i<num_node_sets;i++){
      err = ex_get_set_param(exo_file,EX_NODE_SET,ids[i],&n1,&n2);
      iscr = (int *) calloc(n1,sizeof(int));
      err = ex_get_node_set(exo_file,ids[i],iscr);
      /* nodes list */
      sprintf(str,"nsnod%02d",i+1);
      PutInt(str,n1,1,iscr);
      free(iscr);
      /* distribution-factors list */
      scr = (double *) calloc (n2,sizeof(double));
      ex_get_node_set_dist_fact(exo_file,ids[i],scr);  
      sprintf(str,"nsfac%02d",i+1);
      PutDbl(str,n2,1,scr);
      free(scr);

      nnsnodes[i]=n1;
      nnsdfac[i]=n2;

    }

      /* Store # nodes and # dis. factors per node set */
      PutInt("nnsnodes",num_node_sets,1,nnsnodes);
      PutInt("nnsdfac",num_node_sets,1,nnsdfac);
      free(ids);
   
    free(nnsdfac);
    free(nnsnodes);
    
  }

  /* element blocks */
  ids=(int *) calloc(num_blocks,sizeof(int));
  num_elem_in_block=(int *) calloc(num_blocks,sizeof(int));
  err = ex_get_ids(exo_file,EX_ELEM_BLOCK,ids);
  PutInt( "blkids",num_blocks, 1,ids);
  for (i=0;i<num_blocks;i++) {
    err = ex_get_elem_block(exo_file,ids[i],str2[i],&n,&n1,&n2);
    num_elem_in_block[i]=n;
    iscr = (int *) calloc(n*n1,sizeof(int));
    err = ex_get_conn(exo_file,EX_ELEM_BLOCK,ids[i],iscr, NULL, NULL);
    sprintf(str,"blk%02d",i+1);
    PutInt(str,n1,n,iscr);
    free(iscr);
  }
  str[0]='\0';
  for (i=0;i<num_blocks;i++)
    sprintf(str+strlen(str),"%s\n",str2[i]);
  PutStr("blknames",str);  

  /* time values */
  if (num_time_steps > 0 ) {
    scr = (double *) calloc (num_time_steps,sizeof(double));
    err= ex_get_all_times (exo_file,scr);
    PutDbl( "time", num_time_steps, 1,scr);
    free(scr); 
  }

  /* global variables */
  if (num_global_vars > 0 ) {
    err = ex_get_variable_names(exo_file,EX_GLOBAL,num_global_vars,str2);
    str[0]='\0';
    for (i=0;i<num_global_vars;i++)
      sprintf(str+strlen(str),"%s\n",str2[i]);
    PutStr("gnames",str);
    scr = (double *) calloc (num_time_steps,sizeof(double));
    for (i=0;i<num_global_vars;i++){
      sprintf(str,"gvar%02d",i+1);
      err=ex_get_glob_var_time(exo_file,i+1,1,num_time_steps,scr);
      PutDbl(str,num_time_steps,1,scr);
    }
    free(scr);
  }

  /* nodal variables */
  if (num_nodal_vars > 0 ) {
    err = ex_get_variable_names(exo_file,EX_NODAL,num_nodal_vars,str2);
    str[0]='\0';
    for (i=0;i<num_nodal_vars;i++)
      sprintf(str+strlen(str),"%s\n",str2[i]);
    PutStr("nnames",str);
    scr = (double *) calloc (num_nodes*num_time_steps,sizeof(double));
    for (i=0;i<num_nodal_vars;i++){
      sprintf(str,"nvar%02d",i+1);
      for (j=0;j<num_time_steps;j++)
	err=ex_get_nodal_var(exo_file,j+1,i+1,num_nodes,
                                  scr+num_nodes*j);
      PutDbl(str,num_nodes,num_time_steps,scr);
    }
    free(scr);
  }

  /* element variables */
  if (num_element_vars > 0 ) {
    err = ex_get_variable_names(exo_file,EX_ELEM_BLOCK,num_element_vars,str2);
    str[0]='\0';
    for (i=0;i<num_element_vars;i++)
      sprintf(str+strlen(str),"%s\n",str2[i]);
    PutStr("enames",str);
    /* truth table */
    iscr = (int *) calloc(num_element_vars*num_blocks, sizeof(int));
    ex_get_elem_var_tab(exo_file,num_blocks,num_element_vars,iscr);
    for (i=0;i<num_element_vars;i++){
      scr = (double *) calloc (num_elements*num_time_steps,sizeof(double));
      n=0;
      sprintf(str,"evar%02d",i+1);
      for (j=0;j<num_time_steps;j++){
	for (k=0;k<num_blocks;k++){ 
          if(iscr[num_element_vars*k+i]==1)
	      ex_get_elem_var(exo_file,j+1,i+1,ids[k],num_elem_in_block[k],scr+n);
	      n=n+num_elem_in_block[k];
	      
	}
      }
      PutDbl(str,num_elements,num_time_steps,scr);
      free(scr);
    }
    free(iscr);
  }
  free(num_elem_in_block);
  free(ids);
 
  /* node and element number maps */
  ex_opts(0);  /* turn off error reporting. It is not an error to have no map*/
  ids = (int *)malloc(num_nodes*sizeof(int));
  err = ex_get_node_num_map(exo_file,ids);
  if ( err==0 ){
    PutInt("node_num_map",num_nodes,1,ids);
  }
  free(ids);

  ids = (int *)malloc(num_elements*sizeof(int));
  err = ex_get_elem_num_map(exo_file,ids);
  if ( err==0 ){
    PutInt("elem_num_map",num_elements,1,ids);
  }
  free(ids);


  /* close exo file */
  ex_close(exo_file);
  
  /* close mat file */
  if ( textfile )
    fclose(m_file);
  else
    Mat_Close(mat_file);

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

  free(filename);
  free(line);
  
  free(str);
  for (i=0;i<nstr2;i++)
    free(str2[i]);
  free(str2);
  

  /* exit status */
  add_to_log("exo2mat", 0);
  return(0);
}
Example #25
0
int cReadEdgeFace(int argc, char *argv[])
{
  int            exoid;
  int            appWordSize  = 8;
  int            diskWordSize = 8;
  float          exoVersion;
  int            itmp[5];
  int *          ids;
  int            nids;
  int            obj;
  int            i, j;
  int            num_timesteps;
  int            ti;
  char **        obj_names;
  char **        var_names;
  int            have_var_names;
  int            num_vars;    /* number of variables per object */
  int            num_entries; /* number of values per variable per object */
  double *       entry_vals;  /* variable values for each entry of an object */
  ex_init_params modelParams;

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

  EXCHECK(ex_get_init_ext(exoid, &modelParams), "Unable to read database parameters.\n");

  fprintf(stdout, "Title: <%s>\n"
                  "Dimension: %" PRId64 "\n"
                  "Nodes: %" PRId64 "\n"
                  "Edges: %" PRId64 "\n"
                  "Faces: %" PRId64 "\n"
                  "Elements: %" PRId64 "\n"
                  "Edge Blocks: %" PRId64 "\n"
                  "Face Blocks: %" PRId64 "\n"
                  "Element Blocks: %" PRId64 "\n"
                  "Node Sets: %" PRId64 "\n"
                  "Edge Sets: %" PRId64 "\n"
                  "Face Sets: %" PRId64 "\n"
                  "Side Sets: %" PRId64 "\n"
                  "Element Sets: %" PRId64 "\n"
                  "Node Maps: %" PRId64 "\n"
                  "Edge Maps: %" PRId64 "\n"
                  "Face Maps: %" PRId64 "\n"
                  "Element Maps: %" PRId64 "\n",
          modelParams.title, modelParams.num_dim, modelParams.num_nodes, modelParams.num_edge,
          modelParams.num_face, modelParams.num_elem, modelParams.num_edge_blk,
          modelParams.num_face_blk, modelParams.num_elem_blk, modelParams.num_node_sets,
          modelParams.num_edge_sets, modelParams.num_face_sets, modelParams.num_side_sets,
          modelParams.num_elem_sets, modelParams.num_node_maps, modelParams.num_edge_maps,
          modelParams.num_face_maps, modelParams.num_elem_maps);

  num_timesteps = ex_inquire_int(exoid, EX_INQ_TIME);

  /* *** NEW API *** */
  for (i = 0; i < sizeof(obj_types) / sizeof(obj_types[0]); ++i) {
    int *truth_tab = 0;
    have_var_names = 0;

    EXCHECK(ex_inquire(exoid, obj_sizes[i], &nids, 0, 0),
            "Object ID list size could not be determined.\n");

    if (!nids) {
      fprintf(stdout, "=== %ss: none\n\n", obj_typenames[i]);
      continue;
    }
    else {
      fprintf(stdout, "=== %ss: %d\n", obj_typenames[i], nids);
    }

    ids       = (int *)malloc(nids * sizeof(int));
    obj_names = (char **)malloc(nids * sizeof(char *));
    for (obj         = 0; obj < nids; ++obj)
      obj_names[obj] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char));

    EXCHECK(ex_get_ids(exoid, obj_types[i], ids), "Could not read object ids.\n");
    EXCHECK(ex_get_names(exoid, obj_types[i], obj_names), "Could not read object ids.\n");

    if ((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) {
      int *tp;
      EXCHECK(ex_get_var_param(exoid, obj_typestr[i], &num_vars),
              "Could not read number of variables.\n");

      if (num_vars && num_timesteps > 0) {
        truth_tab = (int *)malloc(num_vars * nids * sizeof(int));
        EXCHECK(ex_get_var_tab(exoid, obj_typestr[i], nids, num_vars, truth_tab),
                "Could not read truth table.\n");
        tp = truth_tab;
        fprintf(stdout, "Truth:");
        for (obj = 0; obj < nids; ++obj) {
          for (j = 0; j < num_vars; ++j, ++tp) {
            fprintf(stdout, " %d", *tp);
          }
          fprintf(stdout, "\n      ");
        }
        fprintf(stdout, "\n");

        var_names = (char **)malloc(num_vars * sizeof(char *));
        for (j         = 0; j < num_vars; ++j)
          var_names[j] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char));

        EXCHECK(ex_get_var_names(exoid, obj_typestr[i], num_vars, var_names),
                "Could not read variable names.\n");
        have_var_names = 1;
      }
    }

    if (!have_var_names)
      var_names = 0;

    for (obj = 0; obj < nids; ++obj) {
      if (obj_names[obj])
        fprintf(stdout, "%s %3d (%s): ", obj_typenames[i], ids[obj], obj_names[obj]);
      else
        fprintf(stdout, "%s %3d: ", obj_typenames[i], ids[obj]);

      if (OBJECT_IS_BLOCK(i)) {
        int *nconn;
        int *econn;
        int *fconn;
        int  ele;
        int  ctr;
        int  num_attrs;
        if (obj_types[i] == EX_ELEM_BLOCK) {
          EXCHECK(ex_get_block(exoid, obj_types[i], ids[obj], 0, itmp, itmp + 1, itmp + 2, itmp + 3,
                               &num_attrs),
                  "Could not read block params.\n");
          fprintf(stdout,
                  "Entries: %3d Nodes/entry: %d Edges/entry: %d Faces/entry: %d Attributes: %d",
                  itmp[0], itmp[1], itmp[2], itmp[3], num_attrs);
        }
        else {
          EXCHECK(ex_get_block(exoid, obj_types[i], ids[obj], 0, itmp, itmp + 1, 0, 0, &num_attrs),
                  "Could not read block params.\n");
          fprintf(stdout, "Entries: %3d Nodes/entry: %d Attributes: %d", itmp[0], itmp[1],
                  num_attrs);
          itmp[2] = itmp[3] = 0;
        }
        fprintf(stdout, "\n   ");
        num_entries = itmp[0];
        nconn       = itmp[1] ? (int *)malloc(itmp[1] * num_entries * sizeof(int)) : 0;
        econn       = itmp[2] ? (int *)malloc(itmp[2] * num_entries * sizeof(int)) : 0;
        fconn       = itmp[3] ? (int *)malloc(itmp[3] * num_entries * sizeof(int)) : 0;
        EXCHECK(ex_get_conn(exoid, obj_types[i], ids[obj], nconn, econn, fconn),
                "Could not read connectivity.\n");
        for (ele = 0; ele < num_entries; ++ele) {
          for (ctr = 0; ctr < itmp[1]; ++ctr) {
            fprintf(stdout, " %2d", nconn[ele * itmp[1] + ctr]);
          }
          if (itmp[2]) {
            fprintf(stdout, "  ++");
            for (ctr = 0; ctr < itmp[2]; ++ctr) {
              fprintf(stdout, " %2d", econn[ele * itmp[2] + ctr]);
            }
          }
          if (itmp[3]) {
            fprintf(stdout, "  ++");
            for (ctr = 0; ctr < itmp[3]; ++ctr) {
              fprintf(stdout, " %2d", fconn[ele * itmp[3] + ctr]);
            }
          }
          fprintf(stdout, "\n   ");
        }
        free(nconn);
        free(econn);
        free(fconn);

        if (num_attrs) {
          char ** attr_names;
          double *attr;
          attr       = (double *)malloc(num_entries * num_attrs * sizeof(double));
          attr_names = (char **)malloc(num_attrs * sizeof(char *));
          for (j          = 0; j < num_attrs; ++j)
            attr_names[j] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char));

          EXCHECK(ex_get_attr_names(exoid, obj_types[i], ids[obj], attr_names),
                  "Could not read attributes names.\n");
          EXCHECK(ex_get_attr(exoid, obj_types[i], ids[obj], attr),
                  "Could not read attribute values.\n");

          fprintf(stdout, "\n      Attributes:\n      ID ");
          for (j = 0; j < num_attrs; ++j)
            fprintf(stdout, " %s", attr_names[j]);
          fprintf(stdout, "\n");
          for (j = 0; j < num_entries; ++j) {
            int k;
            fprintf(stdout, "      %2d ", j + 1);
            for (k = 0; k < num_attrs; ++k) {
              fprintf(stdout, " %4.1f", attr[j * num_attrs + k]);
            }
            fprintf(stdout, "\n");
          }

          for (j = 0; j < num_attrs; ++j)
            free(attr_names[j]);
          free(attr_names);
          free(attr);
        }
      }
      else if (OBJECT_IS_SET(i)) {
        int     num_df;
        int *   set_entry;
        int *   set_extra;
        double *set_df;
        EXCHECK(ex_get_set_param(exoid, obj_types[i], ids[obj], &num_entries, &num_df),
                "Could not read set parameters.\n");

        set_entry = (int *)malloc(num_entries * sizeof(int));
        set_extra = (obj_types[i] != EX_NODE_SET && obj_types[i] != EX_ELEM_SET)
                        ? (int *)malloc(num_entries * sizeof(int))
                        : 0;
        EXCHECK(ex_get_set(exoid, obj_types[i], ids[obj], set_entry, set_extra),
                "Could not read set.\n");
        fprintf(stdout, "Entries: %3d Distribution factors: %3d\n", num_entries, num_df);
        if (set_extra) {
          for (j = 0; j < num_entries; ++j)
            fprintf(stdout, "      %2d %2d\n", set_entry[j], set_extra[j]);
        }
        else {
          for (j = 0; j < num_entries; ++j)
            fprintf(stdout, "      %2d\n", set_entry[j]);
        }
        free(set_entry);
        free(set_extra);

        set_df = num_df ? (double *)malloc(num_df * sizeof(double)) : 0;
        if (set_df) {
          EXCHECK(ex_get_set_dist_fact(exoid, obj_types[i], ids[obj], set_df),
                  "Could not read set distribution factors.\n");
          fprintf(stdout, "\n    Distribution factors:\n");
          for (j = 0; j < num_df; ++j)
            fprintf(stdout, "      %4.1f\n", set_df[j]);
          free(set_df);
        }
      }
      else { /* object is map */
        int *map;
        switch (obj_types[i]) {
        case EX_NODE_MAP: num_entries = modelParams.num_nodes; break;
        case EX_EDGE_MAP: num_entries = modelParams.num_edge; break;
        case EX_FACE_MAP: num_entries = modelParams.num_face; break;
        case EX_ELEM_MAP: num_entries = modelParams.num_elem; break;
        default: num_entries          = 0;
        }
        if (num_entries) {
          fprintf(stdout, "Entries: %3d\n                :", num_entries);
          map = (int *)malloc(num_entries * sizeof(int));
          EXCHECK(ex_get_num_map(exoid, obj_types[i], ids[obj], map), "Could not read map.\n");
          for (j = 0; j < num_entries; ++j) {
            fprintf(stdout, " %d", map[j]);
          }
        }
        else {
          fprintf(stdout, "Entries: none");
        }
      }
      fprintf(stdout, "\n");

      /* Read results variables */
      if (((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) && num_vars && num_timesteps > 0) {
        /* Print out all the time values to exercise get_var */
        entry_vals = (double *)malloc(num_entries * sizeof(double));
        for (j = 0; j < num_vars; ++j) {
          int k;
          if (!truth_tab[num_vars * obj + j])
            continue;

          fprintf(stdout, "      Variable: %s", var_names[j]);
          for (ti = 1; ti <= num_timesteps; ++ti) {
            EXCHECK(ex_get_var(exoid, ti, obj_types[i], 1 + j, ids[obj], num_entries, entry_vals),
                    "Could not read variable values.\n");

            fprintf(stdout, "\n       @t%d ", ti);
            for (k = 0; k < num_entries; ++k) {
              fprintf(stdout, " %4.1f", entry_vals[k]);
            }
          }
          fprintf(stdout, "\n");
        }
        fprintf(stdout, "\n");
        free(entry_vals);
      }
    }

    if (((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) && num_vars && num_timesteps > 0) {
      /* Print out one element's time values to exercise get_var_time */
      entry_vals = (double *)malloc(num_timesteps * sizeof(double));
      EXCHECK(ex_inquire(exoid, obj_sizeinq[i], itmp, 0, 0), "Inquire failed.\n");
      itmp[1] = 11;
      while (itmp[1] > itmp[0])
        itmp[1] /= 2;
      for (j = 0; j < num_vars; ++j) {
        /* FIXME: This works for the dataset created by CreateEdgeFace, but not for any dataset in
         * general since
         * NULL truth table entries may mean the referenced elements don't have variable values.
         */
        EXCHECK(ex_get_var_time(exoid, obj_types[i], j + 1, itmp[1], 1, num_timesteps, entry_vals),
                "Could not read variable over time.\n");
        fprintf(stdout, "    Variable over time: %s  Entry: %3d ", var_names[j], itmp[1]);
        for (ti = 1; ti <= num_timesteps; ++ti)
          fprintf(stdout, " @t%d: %4.1f", ti, entry_vals[ti - 1]);
        fprintf(stdout, "\n");
      }
      free(entry_vals);
    }

    if (var_names) {
      for (j = 0; j < num_vars; ++j)
        free(var_names[j]);
      free(var_names);
    }
    free(truth_tab);
    free(ids);

    for (obj = 0; obj < nids; ++obj)
      free(obj_names[obj]);
    free(obj_names);

    fprintf(stdout, "\n");
  }

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

  return 0;
}
Example #26
0
int read_exo_weights(Problem_Description* prob, Weight_Description<INT>* weight)
{
  int    exoid, cpu_ws=0, io_ws=0;
  int    neblks;
  float  version, minval = 1.0f;
  char elem_type[MAX_STR_LENGTH+1];
  char ctemp[1024];
/*---------------------------Execution Begins--------------------------------*/

  /* Open the ExodusII file containing the weights */
  int mode = EX_READ | prob->int64api;
  if((exoid=ex_open(weight->exo_filename.c_str(), mode, &cpu_ws, &io_ws,
                    &version)) < 0)
  {
    sprintf(ctemp, "fatal: could not open ExodusII file %s",
            weight->exo_filename.c_str());
    Gen_Error(0, ctemp);
    return 0;
  }

  std::vector<float> values(weight->nvals);
  if(prob->type == NODAL)
  {
    size_t tmp_nodes = ex_inquire_int(exoid, EX_INQ_NODES);
    /* check to make sure the sizes agree */
    if ((size_t)weight->nvals != tmp_nodes) {
      Gen_Error(0, "fatal: different number of nodes in mesh and weight files");
      ex_close(exoid);
      return 0;
    }

    weight->ow.resize(weight->nvals);
    /* Read in the nodal values */
    if(ex_get_nodal_var(exoid, weight->exo_tindx, weight->exo_vindx,
                        weight->nvals, TOPTR(values)) < 0)
    {
      Gen_Error(0, "fatal: unable to read nodal values");
      ex_close(exoid);
      return 0;
    }
  }
  else
  {
    size_t tmp_elem = ex_inquire_int(exoid, EX_INQ_ELEM);
    /* check to make sure the sizes agree */
    if ((size_t)weight->nvals != tmp_elem) {
      Gen_Error(0, "fatal: different number of elems in mesh and weight files");
      ex_close(exoid);
      return 0;
    }

    /* Get the number of element blocks */
    neblks = ex_inquire_int(exoid, EX_INQ_ELEM_BLK);
    std::vector<INT> eblk_ids(neblks);
    std::vector<INT> eblk_ecnts(neblks);

    if(ex_get_ids(exoid, EX_ELEM_BLOCK, &eblk_ids[0]) < 0)
    {
      Gen_Error(0, "fatal: unable to get element block IDs");
      ex_close(exoid);
      return 0;
    }

    /* Get the count of elements in each element block */
    for(int cnt=0; cnt < neblks; cnt++) {
      INT dum1, dum2;
      if(ex_get_elem_block(exoid, eblk_ids[cnt], elem_type,
                           &(eblk_ecnts[cnt]), &dum1, &dum2) < 0)
      {
        Gen_Error(0, "fatal: unable to get element block");
        ex_close(exoid);
        return 0;
      }
    }

    /* Get the element variables */
    size_t offset = 0;
    for(int cnt=0; cnt < neblks; cnt++)
    {
      if(ex_get_elem_var(exoid, weight->exo_tindx, weight->exo_vindx,
                         eblk_ids[cnt], eblk_ecnts[cnt], &(values[offset])) < 0)
      {
        Gen_Error(0, "fatal: unable to get element variable");
        ex_close(exoid);
        return 0;
      }
      offset += eblk_ecnts[cnt];
    }
  }

  /* Close the ExodusII weighting file */
  if(ex_close(exoid) < 0)
  {
    sprintf(ctemp, "warning: failed to close ExodusII file %s",
            weight->exo_filename.c_str());
    Gen_Error(0, ctemp);
  }

  /* now I need to translate the values to positive integers */

  /* first find the minimum value */
  minval = *std::min_element(values.begin(), values.end());

  /* now translate the values to be greater than 1 and convert to ints */
  for (int cnt=0; cnt < weight->nvals; cnt++) {
    values[cnt] += 1.0 - minval;
    weight->vertices[cnt] = roundfloat(values[cnt]);
  }
  return 1;
} /*------------------------End read_exo_weights()----------------------*/
Example #27
0
int read_mesh(const std::string &exo_file,
              Problem_Description* problem,
              Mesh_Description<INT>* mesh,
              Weight_Description<INT>* weight
	      )
{
  float  version, *xptr, *yptr, *zptr;
  char   elem_type[MAX_STR_LENGTH+1];
  E_Type blk_elem_type;
  
  /*---------------------------Execution Begins--------------------------------*/

  /* Open the ExodusII file */
  int exoid, cpu_ws=0, io_ws=0;
  int mode = EX_READ | problem->int64api;
  if((exoid=ex_open(exo_file.c_str(), mode, &cpu_ws, &io_ws, &version)) < 0)
    {
      Gen_Error(0, "fatal: unable to open ExodusII mesh file");
      return 0;
    }

  /* Read the coordinates, if desired */
  xptr = yptr = zptr = NULL;
  if(problem->read_coords == ELB_TRUE)
    {
      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_get_coord(exoid, xptr, yptr, zptr) < 0)
	{
	  Gen_Error(0, "fatal: unable to read coordinate values for mesh");
	  return 0;
	}

    } /* End "if(problem->read_coords == ELB_TRUE)" */

  /* Read the element block IDs */
  std::vector<INT> el_blk_ids(mesh->num_el_blks);
  std::vector<INT> el_blk_cnts(mesh->num_el_blks);

  if(ex_get_elem_blk_ids(exoid, &el_blk_ids[0]) < 0)
    {
      Gen_Error(0, "fatal: unable to read element block IDs");
      return 0;
    }

  /* Read the element connectivity */
  size_t gelem_cnt=0;
  for(size_t cnt=0; cnt < mesh->num_el_blks; cnt++) {
    INT nodes_per_elem, num_attr;
    if(ex_get_elem_block(exoid, el_blk_ids[cnt], elem_type,
                         &(el_blk_cnts[cnt]), &nodes_per_elem,
                         &num_attr) < 0)
      {
	Gen_Error(0, "fatal: unable to read element block");
	return 0;
      }

    blk_elem_type = get_elem_type(elem_type, nodes_per_elem, mesh->num_dims);

    INT *blk_connect = (INT*)malloc(sizeof(INT)*el_blk_cnts[cnt]*nodes_per_elem);
    if(!blk_connect)
      {
	Gen_Error(0, "fatal: insufficient memory");
	return 0;
      }

    /* Get the connectivity for this element block */
    if(ex_get_elem_conn(exoid, el_blk_ids[cnt], blk_connect) < 0)
      {
	Gen_Error(0, "fatal: failed to get element connectivity");
	return 0;
      }

    /* find out if this element block is weighted */
    int wgt = -1;
    if (weight->type & EL_BLK)
      wgt = in_list(el_blk_ids[cnt], weight->elemblk);
    
    /* Fill the 2D global connectivity array */
    if (((problem->type == ELEMENTAL) && (weight->type & EL_BLK)) ||
        ((problem->type == NODAL) && (weight->type & EL_BLK))) {
      
      for(int64_t cnt2=0; cnt2 < el_blk_cnts[cnt]; cnt2++) {
	mesh->elem_type[gelem_cnt] = blk_elem_type;
      
	/* while going through the blocks, take care of the weighting */
	if ((problem->type == ELEMENTAL) && (weight->type & EL_BLK)) {
	  /* is this block weighted */
	  if (wgt >= 0) {
	    /* check if there is a read value */
	    if (weight->vertices[gelem_cnt] >= 1) {
	      /* and if it should be overwritten */
	      if (weight->ow_read)
		weight->vertices[gelem_cnt] = weight->elemblk_wgt[wgt];
	    }
	    else
	      weight->vertices[gelem_cnt] = weight->elemblk_wgt[wgt];
	  }
	  else {
	    /* now check if this weight has been initialized */
	    if (weight->vertices[gelem_cnt] < 1)
	      weight->vertices[gelem_cnt] = 1;
	  }
	}

	for(int64_t cnt3=0; cnt3 < nodes_per_elem; cnt3++) {
	  INT node = blk_connect[cnt3 + cnt2*nodes_per_elem] - 1;
	  assert(node >= 0);
	  mesh->connect[gelem_cnt][cnt3] = node;

	  /* deal with the weighting if necessary */
	  if ((problem->type == NODAL) && (weight->type & EL_BLK)) {
	    /* is this block weighted */
	    if (wgt >= 0) {
	      /* check if I read an exodus file */
	      if (weight->type & READ_EXO) {
		/* check if it can be overwritten */
		if (weight->ow_read) {
		  /* check if it has been overwritten already */
		  if (weight->ow[node]) {
		    weight->vertices[node] =
		      MAX(weight->vertices[node], weight->elemblk_wgt[wgt]);
		  }
		  else {
		    weight->vertices[node] = weight->elemblk_wgt[wgt];
		    weight->ow[node] = 1;   /* read value has been overwritten */
		  }
		}
	      }
	      else {
		weight->vertices[node] =
		  MAX(weight->vertices[node], weight->elemblk_wgt[wgt]);
	      }
	    }
	    else {
	      /* now check if this weight has been initialized */
	      if (weight->vertices[node] < 1)
		weight->vertices[node] = 1;
	    }
	  }
	}
	gelem_cnt++;
      }
    } else {
      // No weights...
      for (int64_t cnt2=0; cnt2 < el_blk_cnts[cnt]; cnt2++) {
	mesh->elem_type[gelem_cnt] = blk_elem_type;

	for (int64_t cnt3=0; cnt3 < nodes_per_elem; cnt3++) {
	  INT node = blk_connect[cnt2*nodes_per_elem + cnt3] - 1;
	  assert(node >= 0);
	  mesh->connect[gelem_cnt][cnt3] = node;
	}

	gelem_cnt++;
      }
    }
    /* Free up memory */
    free(blk_connect);

  } /* End "for(cnt=0; cnt < mesh->num_el_blks; cnt++)" */

  /* if there is a group designator, then parse it here */
  if (problem->groups != NULL) {
    if (!parse_groups(&el_blk_ids[0], &el_blk_cnts[0], mesh, problem)) {
      Gen_Error(0, "fatal: unable to parse group designator");
      ex_close(exoid);
      return 0;
    }
  }
  else problem->num_groups = 1; /* there is always one group */

  /* Close the ExodusII file */
  if(ex_close(exoid) < 0)
    Gen_Error(0, "warning: failed to close ExodusII mesh file");

  return 1;

} /*---------------------------End read_mesh()-------------------------------*/
Example #28
0
int read_mesh_params(const std::string &exo_file,
                     Problem_Description* problem,
                     Mesh_Description<INT>* mesh,
                     Sphere_Info* sphere
  )
{
  int    exoid, cpu_ws=0, io_ws=0;
  float  version;
  char   elem_type[MAX_STR_LENGTH+1];
/*---------------------------Execution Begins--------------------------------*/

  /* Open the ExodusII geometry file */
  int mode = EX_READ | problem->int64api;
  if((exoid=ex_open(exo_file.c_str(), mode, &cpu_ws, &io_ws, &version)) < 0)
  {
    Gen_Error(0, "fatal: unable to open ExodusII file for mesh params");
    return 0;
  }

  /* Get the init info */
  ex_init_params exo;
  if(ex_get_init_ext(exoid, &exo))
  {
    Gen_Error(0, "fatal: unable to get init info from ExodusII file");
    ex_close(exoid);
    return 0;
  }
  strcpy(mesh->title, exo.title);
  mesh->num_dims      = exo.num_dim;
  mesh->num_nodes     = exo.num_nodes;
  mesh->num_elems     = exo.num_elem;
  mesh->num_el_blks   = exo.num_elem_blk;
  mesh->num_node_sets = exo.num_node_sets;
  mesh->num_side_sets = exo.num_side_sets;

  /* Get the length of the concatenated node set node list */
  if(mesh->num_node_sets > 0)
  {
    mesh->ns_list_len = ex_inquire_int(exoid, EX_INQ_NS_NODE_LEN);
  }
  else
    mesh->ns_list_len = 0;

  /* Allocate and initialize memory for the sphere adjustment */
  sphere->adjust = (int*)malloc(sizeof(int)*3*(mesh->num_el_blks));
  if(!(sphere->adjust)) {
    Gen_Error(0, "fatal: insufficient memory");
    ex_close(exoid);
    return 0;
  }
  else {
    sphere->begin = sphere->adjust + mesh->num_el_blks;
    sphere->end   = sphere->begin  + mesh->num_el_blks;
    for(size_t cnt=0; cnt < mesh->num_el_blks; cnt++) {
      sphere->adjust[cnt] = 0;
      sphere->begin[cnt]  = 0;
      sphere->end[cnt]    = 0;
    }
  }

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

  /* Read the element block IDs */
  if(ex_get_elem_blk_ids(exoid, &el_blk_ids[0]) < 0) {
    Gen_Error(0, "fatal: unable to get element block IDs");
    ex_close(exoid);
    return 0;
  }

  /* Determine the maximum number of nodes per element */
  mesh->max_np_elem = 0;
  for(size_t cnt=0; cnt < mesh->num_el_blks; cnt++) {
    INT num_elems, idum;
    INT nodes_in_elem;
    
    if(ex_get_elem_block(exoid, el_blk_ids[cnt], elem_type,
                         &num_elems, &nodes_in_elem, &idum) < 0)
    {
      Gen_Error(0, "fatal: unable to get element block");
      ex_close(exoid);
      return 0;
    }

    if(cnt == 0)
      sphere->end[0] = num_elems;

    if(get_elem_type(elem_type, nodes_in_elem, mesh->num_dims) == SPHERE && problem->no_sph != 1) {
      sphere->num  += num_elems;
      sphere->adjust[cnt] = 0;
    }
    else
      sphere->adjust[cnt] = sphere->num;

    if(cnt != 0) {
      sphere->begin[cnt] = sphere->end[cnt-1];
      sphere->end[cnt]   = sphere->begin[cnt] + num_elems;
    }

    mesh->max_np_elem = MAX(mesh->max_np_elem, (size_t)nodes_in_elem);
  }

  /* Close the ExodusII file */
  if(ex_close(exoid) < 0)
    Gen_Error(1, "warning: unable to close ExodusII file");

  printf("ExodusII mesh information\n");
  if(strlen(mesh->title) > 0)
    printf("\ttitle: %s\n", mesh->title);
  printf("\tgeometry dimension: "ST_ZU"\n", mesh->num_dims);
  printf("\tnumber of nodes: "ST_ZU"\tnumber of elements: "ST_ZU"\n", mesh->num_nodes,
         mesh->num_elems);
  printf("\tnumber of element blocks: "ST_ZU"\n", mesh->num_el_blks);
  printf("\tnumber of node sets: "ST_ZU"\tnumber of side sets: "ST_ZU"\n",
         mesh->num_node_sets, mesh->num_side_sets);

  return 1;

} /*--------------------------End read_mesh_params()-------------------------*/
Example #29
0
int write_elem_vars(
  int Proc,
  MESH_INFO_PTR mesh,
  PARIO_INFO_PTR pio_info, 
  int num_exp, 
  ZOLTAN_ID_PTR exp_gids,
  int *exp_procs,
  int *exp_to_part
)
{
/* Routine to write processor assignments per element to the nemesis files. */
int iblk;
int i, j;
int tmp;
float ver;
int pexoid, cpu_ws = 0, io_ws = 0;
int max_cnt = 0;
float *vars;
char par_nem_fname[FILENAME_MAX+1];
char tmp_nem_fname[FILENAME_MAX+1];
int Num_Proc;
char cmesg[256];
char *str = "Proc";

  /* generate the parallel filename for this processor */
  MPI_Comm_size(MPI_COMM_WORLD, &Num_Proc);
  gen_par_filename(pio_info->pexo_fname, tmp_nem_fname, pio_info, Proc,
                   Num_Proc);
  /* 
   * Copy the parallel file to a new file (so we don't write results in the
   * cvs version).
   */
  sprintf(cmesg, "%s.blot", pio_info->pexo_fname);
  gen_par_filename(cmesg, par_nem_fname, pio_info, Proc,
                   Num_Proc);
  fcopy(tmp_nem_fname, par_nem_fname);

  if ((pexoid = ex_open(par_nem_fname, EX_WRITE, &cpu_ws, &io_ws,
                        &ver)) < 0) {
    sprintf(cmesg,"fatal: could not open parallel Exodus II file %s",
            par_nem_fname);
    Gen_Error(0, cmesg);
    return 0;
  }

  if (ex_put_var_names(pexoid, "e", 1, &str) < 0) {
    Gen_Error(0, "Error returned from ex_put_var_names.");
    return 0;
  }

  /* Get max number of elements in an element block; alloc vars array to size */
  for (iblk = 0; iblk < mesh->num_el_blks; iblk++)
    max_cnt = (mesh->eb_cnts[iblk] > max_cnt ? mesh->eb_cnts[iblk] : max_cnt);

  vars = (float *) malloc(max_cnt * sizeof(float));

  /* Must write data by element block; gather the data */
  for (iblk = 0; iblk < mesh->num_el_blks; iblk++) {
    for (j = 0, i = 0; i < mesh->num_elems; i++) {
      if (mesh->elements[i].elem_blk == iblk) {
        /* Element is in block; see whether it is to be exported. */
        if ((tmp=in_list(mesh->elements[i].globalID, num_exp, (int *) exp_gids)) != -1)
          vars[j++] = (Output.Plot_Partition ? (float) (exp_to_part[tmp]) 
                                       : (float) (exp_procs[tmp]));
        else
          vars[j++] = (Output.Plot_Partition ? mesh->elements[i].my_part 
                                       : (float) (Proc));
      }
    }
    if (ex_put_elem_var(pexoid, 1, 1, mesh->eb_ids[iblk], 
                        mesh->eb_cnts[iblk], vars) < 0) {
      Gen_Error(0, "fatal: Error returned from ex_put_elem_var");
      return 0;
    }
  }

  safe_free((void **)(void *) &vars);
  /* Close the parallel file */
  if(ex_close (pexoid) < 0) {
    Gen_Error(0, "fatal: Error returned from ex_close");
    return 0;
  }
  return 1;
}
Example #30
0
int main(int argc, char **argv)
{
  int  exoid, exoid2, num_dim, num_nodes, num_elem, num_elem_blk;
  int  num_elem_in_block, num_node_sets, num_nodes_per_elem, num_attr;
  int  num_side_sets, error;
  int  i, j;
  int *elem_map, *connect, *node_list, *node_ctr_list, *elem_list, *side_list;
  int *ids;
  int  num_nodes_in_set, num_elem_in_set;
  int  num_sides_in_set, num_df_in_set;
  int  num_qa_rec, num_info;
  int  CPU_word_size, IO_word_size;
  int  num_props, prop_value, *prop_values;

  float *x, *y, *z;
  float *dist_fact;
  float  version, fdum;
  float attrib[1];

  char *coord_names[3], *qa_record[2][4], *info[3];
  char  title[MAX_LINE_LENGTH + 1], elem_type[MAX_STR_LENGTH + 1];
  char *prop_names[3];
  char *cdum = 0;

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

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

  /* open EXODUS II file for reading */

  ex_opts(EX_VERBOSE | EX_ABORT);

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

  /* create EXODUS II file for writing */

  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);

  /* read initialization parameters */

  error = ex_get_init(exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk, &num_node_sets,
                      &num_side_sets);

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

  /* write initialization parameters */

  error = ex_put_init(exoid2, 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);

  /* read nodal coordinate values */

  x = (float *)calloc(num_nodes, sizeof(float));
  y = (float *)calloc(num_nodes, sizeof(float));
  if (num_dim >= 3)
    z = (float *)calloc(num_nodes, sizeof(float));
  else
    z = 0;

  error = ex_get_coord(exoid, x, y, z);
  printf("\nafter ex_get_coord, error = %3d\n", error);

  /* write nodal coordinate values */

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

  free(x);
  free(y);
  if (num_dim >= 3)
    free(z);

  /* read nodal coordinate names */

  for (i = 0; i < num_dim; i++) {
    coord_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
  }

  error = ex_get_coord_names(exoid, coord_names);
  printf("\nafter ex_get_coord_names, error = %3d\n", error);

  /* write nodal coordinate names */

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

  for (i = 0; i < num_dim; i++) {
    free(coord_names[i]);
  }

  /* read element order map */

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

  error = ex_get_map(exoid, elem_map);
  printf("\nafter ex_get_map, error = %3d\n", error);

  /* write element order map */

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

  free(elem_map);

  /* read and write element block parameters and element connectivity */

  ids   = (int *)calloc(num_elem_blk, sizeof(int));
  error = ex_get_elem_blk_ids(exoid, ids);
  printf("\nafter ex_get_elem_blk_ids, error = %3d\n", error);

  attrib[0] = 3.14159;
  for (i = 0; i < num_elem_blk; i++) {
    error = ex_get_elem_block(exoid, ids[i], elem_type, &num_elem_in_block, &num_nodes_per_elem,
                              &num_attr);
    printf("\nafter ex_get_elem_block, error = %d\n", error);

    error = ex_put_elem_block(exoid2, ids[i], elem_type, num_elem_in_block, num_nodes_per_elem,
                              num_attr);
    printf("after ex_put_elem_block, error = %d\n", error);

    connect = (int *)calloc((num_nodes_per_elem * num_elem_in_block), sizeof(int));

    error = ex_get_elem_conn(exoid, ids[i], connect);
    printf("\nafter ex_get_elem_conn, error = %d\n", error);

    error = ex_put_elem_conn(exoid2, ids[i], connect);
    printf("after ex_put_elem_conn, error = %d\n", error);

    /* write element block attributes */
    error = ex_put_attr(exoid2, EX_ELEM_BLOCK, ids[i], attrib);
    printf("after ex_put_elem_attr, error = %d\n", error);

    free(connect);
  }

  /* read and write element block properties */

  error = ex_inquire(exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum);
  printf("\nafter ex_inquire, error = %d\n", error);

  for (i = 0; i < num_props; i++) {
    prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
  }

  error = ex_get_prop_names(exoid, EX_ELEM_BLOCK, prop_names);
  printf("after ex_get_prop_names, error = %d\n", error);

  error = ex_put_prop_names(exoid2, EX_ELEM_BLOCK, num_props, prop_names);
  printf("after ex_put_prop_names, error = %d\n", error);

  for (i = 0; i < num_props; i++) {
    for (j = 0; j < num_elem_blk; j++) {
      error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i], &prop_value);
      printf("after ex_get_prop, error = %d\n", error);

      if (i > 0) { /* first property is the ID which is already stored */
        error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ids[j], prop_names[i], prop_value);
        printf("after ex_put_prop, error = %d\n", error);
      }
    }
  }

  for (i = 0; i < num_props; i++)
    free(prop_names[i]);

  free(ids);

  /* read and write individual node sets */

  ids = (int *)calloc(num_node_sets, sizeof(int));

  error = ex_get_node_set_ids(exoid, ids);
  printf("\nafter ex_get_node_set_ids, error = %3d\n", error);

  for (i = 0; i < num_node_sets; i++) {
    error = ex_get_node_set_param(exoid, ids[i], &num_nodes_in_set, &num_df_in_set);
    printf("\nafter ex_get_node_set_param, error = %3d\n", error);

    error = ex_put_node_set_param(exoid2, ids[i], num_nodes_in_set, num_df_in_set);
    printf("after ex_put_node_set_param, error = %d\n", error);

    node_list = (int *)calloc(num_nodes_in_set, sizeof(int));
    dist_fact = (float *)calloc(num_nodes_in_set, sizeof(float));

    error = ex_get_node_set(exoid, ids[i], node_list);
    printf("\nafter ex_get_node_set, error = %3d\n", error);

    error = ex_put_node_set(exoid2, ids[i], node_list);
    printf("after ex_put_node_set, error = %d\n", error);

    if (num_df_in_set > 0) {
      error = ex_get_node_set_dist_fact(exoid, ids[i], dist_fact);
      printf("\nafter ex_get_node_set_dist_fact, error = %3d\n", error);

      error = ex_put_node_set_dist_fact(exoid2, ids[i], dist_fact);
      printf("after ex_put_node_set, error = %d\n", error);
    }

    free(node_list);
    free(dist_fact);
  }
  free(ids);

  /* read node set properties */
  error = ex_inquire(exoid, EX_INQ_NS_PROP, &num_props, &fdum, cdum);
  printf("\nafter ex_inquire, error = %d\n", error);

  for (i = 0; i < num_props; i++) {
    prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
  }
  prop_values = (int *)calloc(num_node_sets, sizeof(int));

  error = ex_get_prop_names(exoid, EX_NODE_SET, prop_names);
  printf("after ex_get_prop_names, error = %d\n", error);

  error = ex_put_prop_names(exoid2, EX_NODE_SET, num_props, prop_names);
  printf("after ex_put_prop_names, error = %d\n", error);

  for (i = 0; i < num_props; i++) {
    error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i], prop_values);
    printf("after ex_get_prop_array, error = %d\n", error);

    error = ex_put_prop_array(exoid2, EX_NODE_SET, prop_names[i], prop_values);
    printf("after ex_put_prop_array, error = %d\n", error);
  }
  for (i = 0; i < num_props; i++)
    free(prop_names[i]);
  free(prop_values);

  /* read and write individual side sets */

  ids = (int *)calloc(num_side_sets, sizeof(int));

  error = ex_get_side_set_ids(exoid, ids);
  printf("\nafter ex_get_side_set_ids, error = %3d\n", error);

  for (i = 0; i < num_side_sets; i++) {
    error = ex_get_side_set_param(exoid, ids[i], &num_sides_in_set, &num_df_in_set);
    printf("\nafter ex_get_side_set_param, error = %3d\n", error);

    error = ex_put_side_set_param(exoid2, ids[i], num_sides_in_set, num_df_in_set);
    printf("after ex_put_side_set_param, error = %d\n", error);

    /* Note: The # of elements is same as # of sides!  */
    num_elem_in_set = num_sides_in_set;
    elem_list       = (int *)calloc(num_elem_in_set, sizeof(int));
    side_list       = (int *)calloc(num_sides_in_set, sizeof(int));
    node_ctr_list   = (int *)calloc(num_elem_in_set, sizeof(int));
    node_list       = (int *)calloc(num_elem_in_set * 21, sizeof(int));
    dist_fact       = (float *)calloc(num_df_in_set, sizeof(float));

    error = ex_get_side_set(exoid, ids[i], elem_list, side_list);
    printf("\nafter ex_get_side_set, error = %3d\n", error);

    error = ex_put_side_set(exoid2, ids[i], elem_list, side_list);
    printf("after ex_put_side_set, error = %d\n", error);

    error = ex_get_side_set_node_list(exoid, ids[i], node_ctr_list, node_list);
    printf("\nafter ex_get_side_set_node_list, error = %3d\n", error);

    if (num_df_in_set > 0) {
      error = ex_get_side_set_dist_fact(exoid, ids[i], dist_fact);
      printf("\nafter ex_get_side_set_dist_fact, error = %3d\n", error);

      error = ex_put_side_set_dist_fact(exoid2, ids[i], dist_fact);
      printf("after ex_put_side_set_dist_fact, error = %d\n", error);
    }

    free(elem_list);
    free(side_list);
    free(node_ctr_list);
    free(node_list);
    free(dist_fact);
  }

  /* read side set properties */
  error = ex_inquire(exoid, EX_INQ_SS_PROP, &num_props, &fdum, cdum);
  printf("\nafter ex_inquire, error = %d\n", error);

  for (i = 0; i < num_props; i++) {
    prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
  }

  error = ex_get_prop_names(exoid, EX_SIDE_SET, prop_names);
  printf("after ex_get_prop_names, error = %d\n", error);

  for (i = 0; i < num_props; i++) {
    for (j = 0; j < num_side_sets; j++) {
      error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i], &prop_value);
      printf("after ex_get_prop, error = %d\n", error);

      if (i > 0) { /* first property is ID so it is already stored */
        error = ex_put_prop(exoid2, EX_SIDE_SET, ids[j], prop_names[i], prop_value);
        printf("after ex_put_prop, error = %d\n", error);
      }
    }
  }
  for (i = 0; i < num_props; i++)
    free(prop_names[i]);
  free(ids);

  /* read and write QA records */

  ex_inquire(exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum);

  for (i = 0; i < num_qa_rec; i++) {
    for (j = 0; j < 4; j++) {
      qa_record[i][j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }
  }

  error = ex_get_qa(exoid, qa_record);
  printf("\nafter ex_get_qa, error = %3d\n", error);

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

  for (i = 0; i < num_qa_rec; i++) {
    for (j = 0; j < 4; j++) {
      free(qa_record[i][j]);
    }
  }
  /* read and write information records */

  error = ex_inquire(exoid, EX_INQ_INFO, &num_info, &fdum, cdum);
  printf("\nafter ex_inquire, error = %3d\n", error);

  for (i = 0; i < num_info; i++) {
    info[i] = (char *)calloc((MAX_LINE_LENGTH + 1), sizeof(char));
  }

  error = ex_get_info(exoid, info);
  printf("\nafter ex_get_info, error = %3d\n", error);

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

  for (i = 0; i < num_info; i++) {
    free(info[i]);
  }

  /* 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;
}