#include <ucd_io.h>
Inherits MeshInput< MeshBase >, and MeshOutput< MeshBase >.
UCDIO (MeshBase &)
UCDIO (const MeshBase &)
virtual void read (const std::string &)
virtual void write (const std::string &)
virtual void write_equation_systems (const std::string &, const EquationSystems &)
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
MeshBase & mesh ()
void skip_comment_lines (std::istream &in, const char comment_start)
const MeshBase & mesh () const
void read_implementation (std::istream &in_stream)
void write_implementation (std::ostream &out_stream)
This class implements reading & writing meshes in the AVS's UCD format.
Author:
Definition at line 43 of file ucd_io.h.
Definition at line 96 of file ucd_io.h.
:
MeshInput<MeshBase> (mesh),
MeshOutput<MeshBase>(mesh)
{
}
Definition at line 105 of file ucd_io.h.
:
MeshOutput<MeshBase> (mesh)
{
}
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(), ExodusII_IO::read(), LegacyXdrIO::read_ascii(), LegacyXdrIO::read_binary(), 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(), 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().
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().
Implements MeshInput< MeshBase >.
Definition at line 45 of file ucd_io.C.
References read_implementation().
Referenced by UnstructuredMesh::read().
{
if (file_name.rfind('.gz') < file_name.size())
{
#ifdef LIBMESH_HAVE_GZSTREAM
igzstream in_stream (file_name.c_str());
this->read_implementation (in_stream);
#else
std::cerr << 'ERROR: You must have the zlib.h header '
<< 'files and libraries to read and write '
<< 'compressed streams.'
<< std::endl;
libmesh_error();
#endif
return;
}
else
{
std::ifstream in_stream (file_name.c_str());
this->read_implementation (in_stream);
return;
}
}
Definition at line 107 of file ucd_io.C.
References MeshInput< MeshBase >::mesh(), Elem::n_nodes(), libMesh::processor_id(), DofObject::set_id(), Elem::set_node(), and MeshInput< MeshBase >::skip_comment_lines().
Referenced by 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);
// Check input buffer
libmesh_assert (in.good());
MeshBase& mesh = MeshInput<MeshBase>::mesh();
// UCD doesn't work in 1D
libmesh_assert (mesh.mesh_dimension() != 1);
this->skip_comment_lines (in, '#');
unsigned int nNodes=0, nElem=0, dummy=0;
in >> nNodes // Read the number of nodes from the stream
>> nElem // Read the number of elements from the stream
>> dummy
>> dummy
>> dummy;
// Read the nodal coordinates. Note that UCD format always
// stores (x,y,z), and in 2D z=0. We don't need to store this,
// however. So, we read in x,y,z for each node and make a point
// in the proper way based on what dimension we're in
{
Point xyz;
for (unsigned int i=0; i<nNodes; i++)
{
libmesh_assert (in.good());
in >> dummy // Point number
>> xyz(0) // x-coordinate value
>> xyz(1) // y-coordinate value
>> xyz(2); // z-coordinate value
// Build the node
mesh.add_point (xyz, i);
}
}
// Read the elements from the stream. Notice that the UCD node-numbering
// scheme is 1-based, and we just created a 0-based scheme above
// (which is of course what we want). So, when we read in the nodal
// connectivity for each element we need to take 1 off the value of
// each node so that we get the right thing.
{
unsigned int material_id=0, node=0;
std::string type;
for (unsigned int i=0; i<nElem; i++)
{
Elem* elem = NULL;
libmesh_assert (in.good());
in >> dummy // Cell number, means nothing to us
>> material_id // doesn't mean anything at present, might later
>> type; // string describing cell type:
// either tri, quad, tet, hex, or prism for the
// obvious cases
// Now read the connectivity.
if (type == 'quad')
elem = new Quad4;
else if (type == 'tri')
elem = new Tri3;
else if (type == 'hex')
elem = new Hex8;
else if (type == 'tet')
elem = new Tet4;
else if (type == 'prism')
elem = new Prism6;
else
libmesh_error();
for (unsigned int n=0; n<elem->n_nodes(); n++)
{
libmesh_assert (in.good());
in >> node; // read the current node
node -= 1; // UCD is 1-based, so subtract
libmesh_assert (node < mesh.n_nodes());
elem->set_node(n) =
mesh.node_ptr(node); // assign the node
}
// Add the element to the mesh
elem->set_id(i);
mesh.add_elem (elem);
}
}
}
Referenced by TetGenIO::read(), and read_implementation().
Implements MeshOutput< MeshBase >.
Definition at line 76 of file ucd_io.C.
References write_implementation().
Referenced by UnstructuredMesh::write().
{
if (file_name.rfind('.gz') < file_name.size())
{
#ifdef LIBMESH_HAVE_GZSTREAM
ogzstream out_stream (file_name.c_str());
this->write_implementation (out_stream);
#else
std::cerr << 'ERROR: You must have the zlib.h header '
<< 'files and libraries to read and write '
<< 'compressed streams.'
<< std::endl;
libmesh_error();
#endif
return;
}
else
{
std::ofstream out_stream (file_name.c_str());
this->write_implementation (out_stream);
return;
}
}
Definition at line 214 of file ucd_io.C.
References MeshInput< MeshBase >::mesh(), and libMeshEnums::UCD.
Referenced by write().
{
libmesh_assert (out.good());
const MeshBase& mesh = MeshOutput<MeshBase>::mesh();
// UCD doesn't work in 1D
libmesh_assert (mesh.mesh_dimension() != 1);
// Write header to stream
out << '# This file was generated by:
<< '#
<< '# $Id: ucd_io.C 3391 2009-05-26 03:50:35Z benkirk $
<< '#
<< '# For a description of the UCD format see the AVS Developer's guide.
<< '#;
// Write the mesh info
out << mesh.n_nodes() << ' '
<< mesh.n_elem() << ' '
<< ' 0 0 0;
// Write the coordinates
{
// const_node_iterator it (mesh.nodes_begin());
// const const_node_iterator end (mesh.nodes_end());
MeshBase::const_node_iterator it = mesh.nodes_begin();
const MeshBase::const_node_iterator end = mesh.nodes_end();
unsigned int n=1; // 1-based node number for UCD
for (; it != end; ++it)
{
libmesh_assert (out.good());
out << n++ << ' ';
(*it)->write_unformatted(out);
}
}
// Write the elements
{
std::string type[] =
{ 'edge', 'edge', 'edge',
'tri', 'tri',
'quad', 'quad', 'quad',
'tet', 'tet',
'hex', 'hex', 'hex',
'prism', 'prism', 'prism',
'pyramid' };
// const_elem_iterator it (mesh.elements_begin());
// const const_elem_iterator end (mesh.elements_end());
MeshBase::const_element_iterator it = mesh.elements_begin();
const MeshBase::const_element_iterator end = mesh.elements_end();
unsigned int e=1; // 1-based element number for UCD
for (; it != end; ++it)
{
libmesh_assert (out.good());
out << e++ << ' 0 ' << type[(*it)->type()] << ' ';
// (*it)->write_ucd_connectivity(out);
(*it)->write_connectivity(out, UCD);
}
}
}
Reimplemented in ExodusII_IO, GmshIO, GMVIO, GnuPlotIO, MEDITIO, and TecplotIO.
Definition at line 91 of file mesh_output.h.
{ libmesh_error(); }
Generated automatically by Doxygen for libMesh from the source code.