Poster of Linux kernelThe best gift for a Linux geek
ExodusII_IO

ExodusII_IO

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

ExodusII_IO -  

SYNOPSIS


#include <exodusII_io.h>

Inherits MeshInput< MeshBase >, and MeshOutput< MeshBase >.  

Public Member Functions


ExodusII_IO (MeshBase &mesh)

virtual ~ExodusII_IO ()

virtual void read (const std::string &name)

virtual void write (const std::string &fname)

void verbose (bool set_verbosity)

void copy_nodal_solution (System &es, std::string nodal_var_name, unsigned int timestep=1)

void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)

void write_timestep (const std::string &fname, const EquationSystems &es, const int timestep, const double time)

virtual void write_equation_systems (const std::string &, const EquationSystems &)
 

Protected Member Functions


MeshBase & mesh ()

void skip_comment_lines (std::istream &in, const char comment_start)

const MeshBase & mesh () const
 

Private Attributes


ExodusII_IO_Helper exio_helper

int _timestep

bool _verbose
 

Detailed Description

The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs. By default, LibMesh expects ExodusII files to have a '.exd' or '.e' file extension.

Author:

Benjamin Kirk, John Peterson, 2004.

Definition at line 48 of file exodusII_io.h.  

Constructor & Destructor Documentation

 

ExodusII_IO::ExodusII_IO (MeshBase &mesh)Constructor. Takes a writeable reference to a mesh object. This is the constructor required to read a mesh.

Definition at line 41 of file exodusII_io.C.

                                        :
  MeshInput<MeshBase> (mesh),
  MeshOutput<MeshBase> (mesh),
  _timestep(1),
  _verbose (false)
{
}
 

ExodusII_IO::~ExodusII_IO () [virtual]Destructor.

Definition at line 51 of file exodusII_io.C.

References ExodusII_IO_Helper::close(), exio_helper, and libMesh::processor_id().

{
#ifndef LIBMESH_HAVE_EXODUS_API

  std::cerr <<  'ERROR, ExodusII API is not defined.
            << std::endl;
  libmesh_error();
    
#else
  
  if(libMesh::processor_id() == 0)
    exio_helper.close();
  
#endif
}
 

Member Function Documentation

 

void ExodusII_IO::copy_nodal_solution (System &es, std::stringnodal_var_name, unsigned inttimestep = 1)If we read in a nodal solution while reading in a mesh, we can attempt to copy that nodal solution into an EquationSystems object.

Definition at line 238 of file exodusII_io.C.

{

  std::cerr <<  'ERROR, ExodusII API is not defined.
            << std::endl;
  libmesh_error();
}
 

const MeshBase & MeshOutput< MeshBase >::mesh () const [protected, inherited]Returns the object as a read-only reference.

Referenced by PostscriptIO::write(), FroIO::write(), MEDITIO::write_ascii(), EnsightIO::write_geometry_ascii(), EnsightIO::write_scalar_ascii(), GnuPlotIO::write_solution(), DivaIO::write_stream(), and EnsightIO::write_vector_ascii().  

MeshBase & MeshInput< MeshBase >::mesh () [protected, inherited]Returns the object as a writeable reference.

Referenced by GMVIO::_read_materials(), GMVIO::_read_nodes(), GMVIO::_read_one_cell(), GMVIO::add_cell_centered_data(), GMVIO::copy_nodal_solution(), UNVIO::element_in(), TetGenIO::element_in(), UNVIO::element_out(), UNVIO::node_in(), TetGenIO::node_in(), UNVIO::node_out(), XdrIO::read(), VTKIO::read(), GMVIO::read(), read(), LegacyXdrIO::read_ascii(), LegacyXdrIO::read_binary(), UCDIO::read_implementation(), LegacyXdrIO::read_mesh(), GmshIO::read_mesh(), XdrIO::read_serialized_bcs(), XdrIO::read_serialized_connectivity(), XdrIO::read_serialized_nodes(), OFFIO::read_stream(), MatlabIO::read_stream(), VTKIO::solution_to_vtk(), XdrIO::write(), VTKIO::write(), TetGenIO::write(), GMVIO::write_ascii_new_impl(), GMVIO::write_ascii_old_impl(), GMVIO::write_binary(), GMVIO::write_discontinuous_gmv(), UNVIO::write_implementation(), UCDIO::write_implementation(), LegacyXdrIO::write_mesh(), GmshIO::write_mesh(), GmshIO::write_post(), XdrIO::write_serialized_bcs(), XdrIO::write_serialized_connectivity(), XdrIO::write_serialized_nodes(), and LegacyXdrIO::write_soln().  

void ExodusII_IO::read (const std::string &name) [virtual]This method implements reading a mesh from a specified file. Open the file named name and read the mesh in Sandia National Lab's ExodusII format. This is the method to use for reading in meshes generated by cubit. Works in 2D for TRIs, TRI6s, QUAD s, and QUAD9s. Works in 3D for TET4s, TET10s, HEX8s, and HEX27s.

Implements MeshInput< MeshBase >.

Definition at line 82 of file exodusII_io.C.

References MeshBase::add_elem(), MeshBase::add_point(), ExodusII_IO_Helper::ElementMaps::assign_conversion(), MeshBase::boundary_info, Elem::build(), MeshBase::clear(), MeshBase::elem(), exio_helper, ExodusII_IO_Helper::get_block_id(), ExodusII_IO_Helper::get_connect(), ExodusII_IO_Helper::get_elem_list(), ExodusII_IO_Helper::get_elem_type(), ExodusII_IO_Helper::get_id_list(), ExodusII_IO_Helper::get_node_list(), ExodusII_IO_Helper::get_nodeset_id(), ExodusII_IO_Helper::get_num_elem(), ExodusII_IO_Helper::get_num_elem_blk(), ExodusII_IO_Helper::get_num_elem_this_blk(), ExodusII_IO_Helper::get_num_node_sets(), ExodusII_IO_Helper::get_num_nodes(), ExodusII_IO_Helper::get_num_nodes_per_elem(), ExodusII_IO_Helper::get_num_side_sets(), ExodusII_IO_Helper::get_num_sides_per_set(), ExodusII_IO_Helper::get_side_list(), ExodusII_IO_Helper::Conversion::get_side_map(), ExodusII_IO_Helper::get_x(), ExodusII_IO_Helper::get_y(), ExodusII_IO_Helper::get_z(), DofObject::id(), MeshInput< MeshBase >::mesh(), MeshBase::mesh_dimension(), MeshBase::n_elem(), MeshBase::n_nodes(), MeshBase::node_ptr(), ExodusII_IO_Helper::open(), ExodusII_IO_Helper::print_header(), ExodusII_IO_Helper::read_block_info(), ExodusII_IO_Helper::read_elem_in_block(), ExodusII_IO_Helper::read_header(), ExodusII_IO_Helper::read_nodes(), ExodusII_IO_Helper::read_nodeset(), ExodusII_IO_Helper::read_nodeset_info(), ExodusII_IO_Helper::read_sideset(), ExodusII_IO_Helper::read_sideset_info(), MeshBase::reserve_elem(), MeshBase::reserve_nodes(), Elem::set_node(), Elem::subdomain_id(), Elem::type(), and verbose().

Referenced by UnstructuredMesh::read(), and Nemesis_IO::read().

{
  // This is a serial-only process for now;
  // the Mesh should be read on processor 0 and
  // broadcast later
//  libmesh_assert(libMesh::processor_id() == 0);

#ifndef LIBMESH_HAVE_EXODUS_API

  std::cerr <<  'ERROR, ExodusII API is not defined.
            << 'Input file ' << fname << ' cannot be read'
            << std::endl;
  libmesh_error();
    
#else
  
  // Get a reference to the mesh we are reading
  MeshBase& mesh = MeshInput<MeshBase>::mesh();
  
  // Clear any existing mesh data
  mesh.clear();
  
  if (mesh.mesh_dimension() == 1) // No support for 1D ExodusII meshes
    libmesh_not_implemented();
  
#ifdef DEBUG
  this->verbose(true);
#endif

  
  ExodusII_IO_Helper::ElementMaps em;     // Instantiate the ElementMaps interface
    
  exio_helper.open(fname.c_str());       // Open the exodus file, if possible
  exio_helper.read_header();             // Get header information from exodus file
  exio_helper.print_header();            // Print header information

  //assertion fails due to inconsistent mesh dimension
//  libmesh_assert(static_cast<unsigned int>(exio_helper.get_num_dim()) == mesh.mesh_dimension()); // Be sure number of dimensions
                                                                                // is equal to the number of 
                                                                                // dimensions in the mesh supplied.
  
  exio_helper.read_nodes();                        // Read nodes from the exodus file
  mesh.reserve_nodes(exio_helper.get_num_nodes()); // Reserve space for the nodes.
  
  // Loop over the nodes, create Nodes with local processor_id 0.
  for (int i=0; i<exio_helper.get_num_nodes(); i++)
    mesh.add_point (Point(exio_helper.get_x(i),
                          exio_helper.get_y(i),
                          exio_helper.get_z(i)), i);
  
  libmesh_assert (static_cast<unsigned int>(exio_helper.get_num_nodes()) == mesh.n_nodes());

  exio_helper.read_block_info();                 // Get information about all the blocks
  mesh.reserve_elem(exio_helper.get_num_elem()); // Reserve space for the elements
   

  // Read in the element connectivity for each block.
  int nelem_last_block = 0;

  std::map<int, unsigned int> exodus_id_to_mesh_id;

  // Loop over all the blocks
  for (int i=0; i<exio_helper.get_num_elem_blk(); i++)
    {
      // Read the information for block i
      exio_helper.read_elem_in_block (i);
      int subdomain_id = exio_helper.get_block_id(i);

      // Set any relevant node/edge maps for this element
      const std::string type_str (exio_helper.get_elem_type());
      const ExodusII_IO_Helper::Conversion conv = em.assign_conversion(type_str); 
      //if (_verbose)
      //std::cout << 'Reading a block of ' << type_str << ' elements.' << std::endl;
      
      // Loop over all the faces in this block
      int jmax = nelem_last_block+exio_helper.get_num_elem_this_blk();
      for (int j=nelem_last_block; j<jmax; j++)
        {
          Elem* elem = Elem::build (conv.get_canonical_type()).release();
          libmesh_assert (elem);
          elem->subdomain_id() = static_cast<subdomain_id_type>(subdomain_id) ;
          //elem->set_id(j);// Don't try to second guess the Element ID setting scheme!
          elem = mesh.add_elem (elem); // Catch the Elem pointer that the Mesh throws back

          exodus_id_to_mesh_id[j+1] = elem->id();
            
          // Set all the nodes for this element
          for (int k=0; k<exio_helper.get_num_nodes_per_elem(); k++)
            {
              int gi = (j-nelem_last_block)*exio_helper.get_num_nodes_per_elem() + conv.get_node_map(k); // global index 
              int node_number   = exio_helper.get_connect(gi);             // Global node number (1-based)
              elem->set_node(k) = mesh.node_ptr((node_number-1)); // Set node number
                                                                  // Subtract 1 since
                                                                  // exodus is internally 1-based
            }
        }
      
      // running sum of # of elements per block,
      // (should equal total number of elements in the end)
      nelem_last_block += exio_helper.get_num_elem_this_blk();
    }
  libmesh_assert (static_cast<unsigned int>(nelem_last_block) == mesh.n_elem());

  // Read in sideset information -- this is useful for applying boundary conditions
  {
    exio_helper.read_sideset_info(); // Get basic information about ALL sidesets
    int offset=0;
    for (int i=0; i<exio_helper.get_num_side_sets(); i++)
      {
        offset += (i > 0 ? exio_helper.get_num_sides_per_set(i-1) : 0); // Compute new offset
        exio_helper.read_sideset (i, offset);
      }
    
    const std::vector<int>& elem_list = exio_helper.get_elem_list();
    const std::vector<int>& side_list = exio_helper.get_side_list();
    const std::vector<int>& id_list   = exio_helper.get_id_list();

    for (unsigned int e=0; e<elem_list.size(); e++)
      {
        // Set any relevant node/edge maps for this element

        Elem * elem = mesh.elem(exodus_id_to_mesh_id[elem_list[e]]);
        
        const ExodusII_IO_Helper::Conversion conv =
          em.assign_conversion(elem->type());
        
        mesh.boundary_info->add_side (exodus_id_to_mesh_id[elem_list[e]],
                                      conv.get_side_map(side_list[e]-1),
                                      id_list[e]);
      }
  }

  // Read nodeset info
  {
    exio_helper.read_nodeset_info();

    for (int nodeset=0; nodeset<exio_helper.get_num_node_sets(); nodeset++)
      {
        int nodeset_id = exio_helper.get_nodeset_id(nodeset);
        
        exio_helper.read_nodeset(nodeset);

        const std::vector<int>& node_list = exio_helper.get_node_list();

        for(unsigned int node=0; node<node_list.size(); node++)
          mesh.boundary_info->add_node(node_list[node], nodeset_id);
      }
  }
      
#endif
}
 

void MeshInput< MeshBase >::skip_comment_lines (std::istream &in, const charcomment_start) [protected, inherited]Reads input from in, skipping all the lines that start with the character comment_start.

Referenced by TetGenIO::read(), and UCDIO::read_implementation().  

void ExodusII_IO::verbose (boolset_verbosity)Set the flag indicationg if we should be verbose.

Definition at line 69 of file exodusII_io.C.

References _verbose, exio_helper, and ExodusII_IO_Helper::verbose().

Referenced by read().

{
  _verbose = set_verbosity;

#ifdef LIBMESH_HAVE_EXODUS_API
  // Set the verbose flag in the helper object
  // as well.
  exio_helper.verbose(_verbose);
#endif
}
 

void ExodusII_IO::write (const std::string &fname) [virtual]This method implements writing a mesh to a specified file.

Implements MeshOutput< MeshBase >.

Definition at line 365 of file exodusII_io.C.

Referenced by UnstructuredMesh::write().

{
  std::cerr <<  'ERROR, ExodusII API is not defined.
            << std::endl;
  libmesh_error();
}
 

virtual void MeshOutput< MeshBase >::write_equation_systems (const std::string &, const EquationSystems &) [virtual, inherited]This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.

Reimplemented in VTKIO.  

void ExodusII_IO::write_nodal_data (const std::string &fname, const std::vector< Number > &soln, const std::vector< std::string > &names) [virtual]Write out a nodal solution.

Reimplemented from MeshOutput< MeshBase >.

Definition at line 279 of file exodusII_io.C.

{

  std::cerr <<  'ERROR, ExodusII API is not defined.
            << std::endl;
  libmesh_error();
}
 

void ExodusII_IO::write_timestep (const std::string &fname, const EquationSystems &es, const inttimestep, const doubletime)Writes out the solution at a specific timestep.

Parameters:

timestep The timestep to write out, should be _1_ indexed.

Definition at line 334 of file exodusII_io.C.

{

  std::cerr <<  'ERROR, ExodusII API is not defined.
            << std::endl;
  libmesh_error();
}
 

Member Data Documentation

 

int ExodusII_IO::_timestep [private]

Definition at line 120 of file exodusII_io.h.  

bool ExodusII_IO::_verbose [private]should we be verbose?

Definition at line 125 of file exodusII_io.h.

Referenced by verbose().  

ExodusII_IO_Helper ExodusII_IO::exio_helper [private]Only attempt to instantiate an ExodusII helper class if the Exodus API is defined. This class will have no functionality when LIBMESH_HAVE_EXODUS_API is not defined.

Definition at line 114 of file exodusII_io.h.

Referenced by read(), verbose(), and ~ExodusII_IO().

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Member Functions
Protected Member Functions
Private Attributes
Detailed Description
Constructor & Destructor Documentation
ExodusII_IO::ExodusII_IO (MeshBase &mesh)Constructor. Takes a writeable reference to a mesh object. This is the constructor required to read a mesh.
ExodusII_IO::~ExodusII_IO () [virtual]Destructor.
Member Function Documentation
void ExodusII_IO::copy_nodal_solution (System &es, std::stringnodal_var_name, unsigned inttimestep = 1)If we read in a nodal solution while reading in a mesh, we can attempt to copy that nodal solution into an EquationSystems object.
const MeshBase & MeshOutput< MeshBase >::mesh () const [protected, inherited]Returns the object as a read-only reference.
MeshBase & MeshInput< MeshBase >::mesh () [protected, inherited]Returns the object as a writeable reference.
void ExodusII_IO::read (const std::string &name) [virtual]This method implements reading a mesh from a specified file. Open the file named name and read the mesh in Sandia National Lab's ExodusII format. This is the method to use for reading in meshes generated by cubit. Works in 2D for TRIs, TRI6s, QUAD s, and QUAD9s. Works in 3D for TET4s, TET10s, HEX8s, and HEX27s.
void MeshInput< MeshBase >::skip_comment_lines (std::istream &in, const charcomment_start) [protected, inherited]Reads input from in, skipping all the lines that start with the character comment_start.
void ExodusII_IO::verbose (boolset_verbosity)Set the flag indicationg if we should be verbose.
void ExodusII_IO::write (const std::string &fname) [virtual]This method implements writing a mesh to a specified file.
virtual void MeshOutput< MeshBase >::write_equation_systems (const std::string &, const EquationSystems &) [virtual, inherited]This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.
void ExodusII_IO::write_nodal_data (const std::string &fname, const std::vector< Number > &soln, const std::vector< std::string > &names) [virtual]Write out a nodal solution.
void ExodusII_IO::write_timestep (const std::string &fname, const EquationSystems &es, const inttimestep, const doubletime)Writes out the solution at a specific timestep.
Member Data Documentation
int ExodusII_IO::_timestep [private]
bool ExodusII_IO::_verbose [private]should we be verbose?
ExodusII_IO_Helper ExodusII_IO::exio_helper [private]Only attempt to instantiate an ExodusII helper class if the Exodus API is defined. This class will have no functionality when LIBMESH_HAVE_EXODUS_API is not defined.
Author

This document was created by man2html, using the manual pages.
Time: 21:45:45 GMT, April 16, 2011