$extrastylesheet
libMesh::TetGenIO Class Reference

#include <tetgen_io.h>

Inheritance diagram for libMesh::TetGenIO:

List of all members.

Public Member Functions

 TetGenIO (MeshBase &mesh, MeshData *mesh_data=NULL)
 TetGenIO (const MeshBase &mesh, MeshData *mesh_data=NULL)
virtual void read (const std::string &)
virtual void write (const std::string &)
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=NULL)
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
unsigned int & ascii_precision ()

Public Attributes

std::vector< std::vector< Real > > node_attributes
std::vector< std::vector< Real > > element_attributes

Protected Member Functions

MeshBasemesh ()
void set_n_partitions (unsigned int n_parts)
void skip_comment_lines (std::istream &in, const char comment_start)
const MeshBasemesh () const

Protected Attributes

std::vector< bool > elems_of_dimension
const bool _is_parallel_format

Private Member Functions

void read_nodes_and_elem (std::istream &node_stream, std::istream &ele_stream)
void node_in (std::istream &node_stream)
void element_in (std::istream &ele_stream)

Private Attributes

std::map< dof_id_type,
dof_id_type
_assign_nodes
dof_id_type _num_nodes
dof_id_type _num_elements
MeshData_mesh_data

Detailed Description

This class implements reading and writing meshes in the TetGen format. Format description: cf. TetGen home page.

Author:
Benjamin S. Kirk, 2004

Definition at line 50 of file tetgen_io.h.


Constructor & Destructor Documentation

libMesh::TetGenIO::TetGenIO ( MeshBase mesh,
MeshData mesh_data = NULL 
) [inline, explicit]

Constructor. Takes a writeable reference to a mesh object. This is the constructor required to read a mesh.

Definition at line 156 of file tetgen_io.h.

                                                       :
  MeshInput<MeshBase> (mesh),
  MeshOutput<MeshBase>(mesh),
  _mesh_data(mesh_data)
{
}
libMesh::TetGenIO::TetGenIO ( const MeshBase mesh,
MeshData mesh_data = NULL 
) [inline, explicit]

Constructor. Takes a read-only reference to a mesh object. This is the constructor required to write a mesh.

Definition at line 166 of file tetgen_io.h.

                                                             :
  MeshOutput<MeshBase>(mesh),
  _mesh_data(mesh_data)
{
}

Member Function Documentation

unsigned int& libMesh::MeshOutput< MeshBase >::ascii_precision ( ) [inherited]

Return/set the precision to use when writing ASCII files.

By default we use numeric_limits<Real>::digits10 + 2, which should be enough to write out to ASCII and get the exact same Real back when reading in.

Referenced by libMesh::TecplotIO::write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), and libMesh::GMVIO::write_ascii_old_impl().

void libMesh::TetGenIO::element_in ( std::istream &  ele_stream) [private]

Method reads elements and stores them in vector<Elem*> elements in the same order as they come in. Within TetGenMeshInterface, element labels are ignored, but MeshData takes care of such things (if active).

Definition at line 181 of file tetgen_io.C.

References _assign_nodes, _mesh_data, _num_elements, libMesh::MeshData::add_foreign_elem_id(), element_attributes, libMesh::libmesh_assert(), libMesh::MeshInput< MeshBase >::mesh(), and n_nodes.

Referenced by read_nodes_and_elem().

{
  // Check input buffer
  libmesh_assert (ele_stream.good());

  // Get a reference to the mesh
  MeshBase& mesh = MeshInput<MeshBase>::mesh();

  // Read the elements from the ele_stream (*.ele file).
  unsigned int element_lab=0, n_nodes=0, nAttri=0;

  ele_stream >> _num_elements // Read the number of tetrahedrons from the stream.
             >> n_nodes       // Read the number of nodes per tetrahedron from the stream (defaults to 4).
             >> nAttri;       // Read the number of attributes from stream.

  // Vector that assigns element nodes to their correct position.
  // TetGen is normaly 0-based
  // (right now this is strictly not necessary since it is the identity map,
  //  but in the future TetGen could change their numbering scheme.)
  static const unsigned int assign_elm_nodes[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

  // If present, make room for element attributes to be stored.
  this->element_attributes.resize(nAttri);
  for (unsigned i=0; i<nAttri; ++i)
    this->element_attributes[i].resize(_num_elements);

  for (dof_id_type i=0; i<_num_elements; i++)
    {
      libmesh_assert (ele_stream.good());

      // TetGen only supports Tet4 and Tet10 elements.
      Elem* elem;

      if (n_nodes==4)
        elem = new Tet4;

      else if (n_nodes==10)
        elem = new Tet10;

      else
        libmesh_error_msg("Elements with " << n_nodes << " nodes are not supported in the LibMesh tetgen module.");

      elem->set_id(i);

      mesh.add_elem (elem);

      libmesh_assert(elem);
      libmesh_assert_equal_to (elem->n_nodes(), n_nodes);

      // Read the element label
      ele_stream >> element_lab;

      // Add the element to the mesh &
      // tell the MeshData object the foreign element id
      if (this->_mesh_data != NULL)
        this->_mesh_data->add_foreign_elem_id (elem, element_lab);

      // Read node labels
      for (dof_id_type j=0; j<n_nodes; j++)
        {
          dof_id_type node_label;
          ele_stream >> node_label;

          // Assign node to element
          elem->set_node(assign_elm_nodes[j]) =
            mesh.node_ptr(_assign_nodes[node_label]);
        }

      // Read and store attributes from the stream.
      for (unsigned int j=0; j<nAttri; j++)
        ele_stream >> this->element_attributes[j][i];
    }
}
MeshBase & libMesh::MeshInput< MeshBase >::mesh ( ) [protected, inherited]

Returns the object as a writeable reference.

Referenced by libMesh::GMVIO::_read_materials(), libMesh::GMVIO::_read_nodes(), libMesh::GMVIO::_read_one_cell(), libMesh::AbaqusIO::assign_boundary_node_ids(), libMesh::AbaqusIO::assign_sideset_ids(), libMesh::AbaqusIO::assign_subdomain_ids(), libMesh::VTKIO::cells_to_vtk(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_nodal_solution(), libMesh::GMVIO::copy_nodal_solution(), element_in(), libMesh::UNVIO::elements_in(), libMesh::UNVIO::elements_out(), libMesh::UNVIO::groups_in(), node_in(), libMesh::UNVIO::nodes_in(), libMesh::UNVIO::nodes_out(), libMesh::VTKIO::nodes_to_vtk(), libMesh::AbaqusIO::read(), libMesh::NameBasedIO::read(), read(), libMesh::Nemesis_IO::read(), libMesh::ExodusII_IO::read(), libMesh::GMVIO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::VTKIO::read(), libMesh::LegacyXdrIO::read_ascii(), libMesh::CheckpointIO::read_bcs(), libMesh::CheckpointIO::read_connectivity(), libMesh::AbaqusIO::read_elements(), libMesh::UCDIO::read_implementation(), libMesh::UNVIO::read_implementation(), libMesh::GmshIO::read_mesh(), libMesh::LegacyXdrIO::read_mesh(), libMesh::AbaqusIO::read_nodes(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::XdrIO::read_serialized_bcs(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::OFFIO::read_stream(), libMesh::MatlabIO::read_stream(), libMesh::CheckpointIO::read_subdomain_names(), libMesh::NameBasedIO::write(), write(), libMesh::Nemesis_IO::write(), libMesh::ExodusII_IO::write(), libMesh::CheckpointIO::write(), libMesh::XdrIO::write(), libMesh::GMVIO::write_ascii_new_impl(), libMesh::GMVIO::write_ascii_old_impl(), libMesh::CheckpointIO::write_bcs(), libMesh::GMVIO::write_binary(), libMesh::CheckpointIO::write_connectivity(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::UCDIO::write_implementation(), libMesh::GmshIO::write_mesh(), libMesh::LegacyXdrIO::write_mesh(), libMesh::UCDIO::write_nodal_data(), libMesh::VTKIO::write_nodal_data(), libMesh::Nemesis_IO::write_nodal_data(), libMesh::NameBasedIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_common(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::CheckpointIO::write_nodes(), libMesh::CheckpointIO::write_nodesets(), libMesh::XdrIO::write_parallel(), libMesh::GmshIO::write_post(), libMesh::XdrIO::write_serialized_bcs(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::LegacyXdrIO::write_soln(), and libMesh::CheckpointIO::write_subdomain_names().

void libMesh::TetGenIO::node_in ( std::istream &  node_stream) [private]

Method reads nodes from node_stream and stores them in vector<Node*> nodes in the order they come in. The original node labels are being stored in the map _assign_nodes in order to assign the elements to the right nodes later. In addition, provided it is active, the MeshData gets to know the node id from the file, too.

Definition at line 118 of file tetgen_io.C.

References _assign_nodes, _mesh_data, _num_nodes, libMesh::MeshData::add_foreign_node_id(), libMesh::libmesh_assert(), libMesh::MeshInput< MeshBase >::mesh(), node_attributes, and libMesh::Real.

Referenced by read_nodes_and_elem().

{
  // Check input buffer
  libmesh_assert (node_stream.good());

  // Get a reference to the mesh
  MeshBase& mesh = MeshInput<MeshBase>::mesh();

  unsigned int dimension=0, nAttributes=0, BoundaryMarkers=0;

  node_stream >> _num_nodes       // Read the number of nodes from the stream
              >> dimension        // Read the dimension from the stream
              >> nAttributes      // Read the number of attributes from stream
              >> BoundaryMarkers; // Read if or not boundary markers are included in *.node (0 or 1)

  // Read the nodal coordinates from the node_stream (*.node file).
  unsigned int node_lab=0;
  Point xyz;
  Real dummy;

  // If present, make room for node attributes to be stored.
  this->node_attributes.resize(nAttributes);
  for (unsigned i=0; i<nAttributes; ++i)
    this->node_attributes[i].resize(_num_nodes);


  for (unsigned int i=0; i<_num_nodes; i++)
    {
      // Check input buffer
      libmesh_assert (node_stream.good());

      node_stream >> node_lab  // node number
                  >> xyz(0)    // x-coordinate value
                  >> xyz(1)    // y-coordinate value
                  >> xyz(2);   // z-coordinate value

      // Read and store attributes from the stream.
      for (unsigned int j=0; j<nAttributes; j++)
        node_stream >> node_attributes[j][i];

      // Read (and discard) boundary marker if BoundaryMarker=1.
      // TODO: should we store this somehow?
      if (BoundaryMarkers == 1)
        node_stream >> dummy;

      // Store the new position of the node under its label.
      //_assign_nodes.insert (std::make_pair(node_lab,i));
      _assign_nodes[node_lab] = i;

      // do this irrespective whether MeshData exists
      Node* newnode = mesh.add_point(xyz, i);

      // Add node to the nodes vector &
      // tell the MeshData object the foreign node id.
      if (this->_mesh_data != NULL)
        this->_mesh_data->add_foreign_node_id (newnode, node_lab);
    }
}
void libMesh::TetGenIO::read ( const std::string &  name) [virtual]

This method implements reading a mesh from a specified file in TetGen format.

Implements libMesh::MeshInput< MeshBase >.

Definition at line 34 of file tetgen_io.C.

References libMesh::MeshInput< MeshBase >::mesh(), libMesh::Quality::name(), libMesh::out, libMesh::processor_id(), read_nodes_and_elem(), libMesh::MeshBase::set_mesh_dimension(), and libMesh::MeshInput< MeshBase >::skip_comment_lines().

Referenced by libMesh::NameBasedIO::read(), and libMesh::UnstructuredMesh::read().

{
  // This is a serial-only process for now;
  // the Mesh should be read on processor 0 and
  // broadcast later
  libmesh_assert_equal_to (MeshOutput<MeshBase>::mesh().processor_id(), 0);

  std::string name_node, name_ele, dummy;

  // tetgen only works in 3D
  MeshInput<MeshBase>::mesh().set_mesh_dimension(3);

#if LIBMESH_DIM < 3
  libmesh_error_msg("Cannot open dimension 3 mesh file when configured without 3D support.");
#endif

  // Check name for *.node or *.ele extension.
  // Set std::istream for node_stream and ele_stream.
  //
  if (name.rfind(".node") < name.size())
    {
      name_node            = name;
      dummy                = name;
      std::size_t position = dummy.rfind(".node");
      name_ele             = dummy.replace(position, 5, ".ele");
    }
  else if (name.rfind(".ele") < name.size())
    {
      name_ele = name;
      dummy    = name;
      std::size_t position = dummy.rfind(".ele");
      name_node    = dummy.replace(position, 4, ".node");
    }
  else
    libmesh_error_msg("ERROR: Unrecognized file name: " << name);



  // Set the streams from which to read in
  std::ifstream node_stream (name_node.c_str());
  std::ifstream ele_stream  (name_ele.c_str());

  if ( !node_stream.good() || !ele_stream.good() )
    libmesh_error_msg("Error while opening either "     \
                      << name_node                      \
                      << " or "                         \
                      << name_ele);

  libMesh::out<< "TetGenIO found the tetgen files to read " <<std::endl;

  // Skip the comment lines at the beginning
  this->skip_comment_lines (node_stream, '#');
  this->skip_comment_lines (ele_stream, '#');

  // Read the nodes and elements from the streams
  this->read_nodes_and_elem (node_stream, ele_stream);
  libMesh::out<< "TetGenIO read in nodes and elements " <<std::endl;
}
void libMesh::TetGenIO::read_nodes_and_elem ( std::istream &  node_stream,
std::istream &  ele_stream 
) [private]

Reads a mesh (nodes & elements) from the file provided through node_stream and ele_stream.

Definition at line 95 of file tetgen_io.C.

References _assign_nodes, _mesh_data, _num_elements, _num_nodes, libMesh::MeshData::close_foreign_id_maps(), element_in(), and node_in().

Referenced by read().

{
  _num_nodes    = 0;
  _num_elements = 0;

  // Read all the datasets.
  this->node_in    (node_stream);
  this->element_in (ele_stream);

  // Tell the MeshData object that we are finished
  // reading data.
  if (this->_mesh_data != NULL)
    this->_mesh_data->close_foreign_id_maps ();

  // some more clean-up
  _assign_nodes.clear();
}
void libMesh::MeshInput< MeshBase >::set_n_partitions ( unsigned int  n_parts) [inline, protected, inherited]

Sets the number of partitions in the mesh. Typically this gets done by the partitioner, but some parallel file formats begin "pre-partitioned".

Definition at line 94 of file mesh_input.h.

References libMesh::MeshInput< MT >::mesh().

Referenced by libMesh::Nemesis_IO::read(), and libMesh::XdrIO::read().

{ this->mesh().set_n_partitions() = n_parts; }
void libMesh::MeshInput< MeshBase >::skip_comment_lines ( std::istream &  in,
const char  comment_start 
) [protected, inherited]

Reads input from in, skipping all the lines that start with the character comment_start.

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

void libMesh::TetGenIO::write ( const std::string &  fname) [virtual]

This method implements writing a mesh to a specified ".poly" file. ".poly" files defines so called Piecewise Linear Complex (PLC).

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 260 of file tetgen_io.C.

References libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), end, libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_nodes(), and libMesh::MeshBase::point().

Referenced by libMesh::NameBasedIO::write().

{
  // libmesh_assert three dimensions (should be extended later)
  libmesh_assert_equal_to (MeshOutput<MeshBase>::mesh().mesh_dimension(), 3);

  if (!(fname.rfind(".poly") < fname.size()))
    libmesh_error_msg("ERROR: Unrecognized file name: " << fname);

  // Open the output file stream
  std::ofstream out_stream (fname.c_str());

  // Make sure it opened correctly
  if (!out_stream.good())
    libmesh_file_error(fname.c_str());

  // Get a reference to the mesh
  const MeshBase& mesh = MeshOutput<MeshBase>::mesh();

  // Begin interfacing with the .poly file
  {
    // header:
    out_stream << "# poly file output generated by libmesh\n"
               << mesh.n_nodes() << " 3 0 0\n";

    // write the nodes:
    for (dof_id_type v=0; v<mesh.n_nodes(); v++)
      out_stream << v << " "
                 << mesh.point(v)(0) << " "
                 << mesh.point(v)(1) << " "
                 << mesh.point(v)(2) << "\n";
  }

  {
    // write the connectivity:
    out_stream << "# Facets:\n"
               << mesh.n_elem() << " 0\n";

    //     const_active_elem_iterator       it (mesh.elements_begin());
    //     const const_active_elem_iterator end(mesh.elements_end());

    MeshBase::const_element_iterator       it  = mesh.active_elements_begin();
    const MeshBase::const_element_iterator end = mesh.active_elements_end();

    for ( ; it != end; ++it)
      out_stream << "1\n3 " // no. of facet polygons
        //  << (*it)->n_nodes() << " "
                 << (*it)->node(0)   << " "
                 << (*it)->node(1)   << " "
                 << (*it)->node(2)   << "\n";
  }

  // end of the file
  out_stream << "0\n"; // no holes output!
  out_stream << "\n\n# end of file\n";
}
virtual void libMesh::MeshOutput< MeshBase >::write_equation_systems ( const std::string &  ,
const EquationSystems ,
const std::set< std::string > *  system_names = NULL 
) [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 libMesh::NameBasedIO.

Referenced by libMesh::Nemesis_IO::write_timestep(), and libMesh::ExodusII_IO::write_timestep().

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
) [inline, virtual, inherited]

This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided.

Reimplemented in libMesh::ExodusII_IO, libMesh::GMVIO, libMesh::NameBasedIO, libMesh::GmshIO, libMesh::Nemesis_IO, libMesh::VTKIO, libMesh::UCDIO, libMesh::MEDITIO, libMesh::GnuPlotIO, and libMesh::TecplotIO.

Definition at line 98 of file mesh_output.h.

  { libmesh_not_implemented(); }

Member Data Documentation

stores new positions of nodes. Used when reading.

Definition at line 132 of file tetgen_io.h.

Referenced by element_in(), node_in(), and read_nodes_and_elem().

const bool libMesh::MeshOutput< MeshBase >::_is_parallel_format [protected, inherited]

Flag specifying whether this format is parallel-capable. If this is false (default) I/O is only permitted when the mesh has been serialized.

Definition at line 126 of file mesh_output.h.

Referenced by libMesh::FroIO::write(), libMesh::DivaIO::write(), libMesh::PostscriptIO::write(), and libMesh::EnsightIO::write().

A pointer to the MeshData object you would like to use. with this TetGenIO object. Can be NULL.

Definition at line 148 of file tetgen_io.h.

Referenced by element_in(), node_in(), and read_nodes_and_elem().

total number of elements. Primarily used when reading.

Definition at line 142 of file tetgen_io.h.

Referenced by element_in(), and read_nodes_and_elem().

total number of nodes. Primarily used when reading.

Definition at line 137 of file tetgen_io.h.

Referenced by node_in(), and read_nodes_and_elem().

std::vector<std::vector<Real> > libMesh::TetGenIO::element_attributes

Data structure to hold element attributes read in from file. What you do with these is up to you!

Definition at line 91 of file tetgen_io.h.

Referenced by element_in().

std::vector<std::vector<Real> > libMesh::TetGenIO::node_attributes

Data structure to hold node attributes read in from file. What you do with these is up to you!

Definition at line 85 of file tetgen_io.h.

Referenced by node_in().


The documentation for this class was generated from the following files: