#include <tetgen_io.h>
Inherits MeshInput< MeshBase >, and MeshOutput< MeshBase >.
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 &)
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_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)
std::map< unsigned int, unsigned int > _assign_nodes
unsigned int _num_nodes
unsigned int _num_elements
MeshData * _mesh_data
This class implements reading and writing meshes in the TetGen format. Format description: cf. TetGen home page.
Author:
Definition at line 48 of file tetgen_io.h.
Definition at line 140 of file tetgen_io.h.
:
MeshInput<MeshBase> (mesh),
MeshOutput<MeshBase>(mesh),
_mesh_data(mesh_data)
{
}
Definition at line 150 of file tetgen_io.h.
:
MeshOutput<MeshBase>(mesh),
_mesh_data(mesh_data)
{
}
Definition at line 175 of file tetgen_io.C.
References _assign_nodes, _mesh_data, _num_elements, MeshData::add_foreign_elem_id(), MeshInput< MeshBase >::mesh(), and MeshTools::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;
Real dummy=0.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};
for (unsigned int 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
{
std::cerr << 'Elements with ' << n_nodes
<< ' nodes are not supported in the LibMesh tetgen module;
libmesh_error();
}
elem->set_id(i);
mesh.add_elem (elem);
libmesh_assert (elem != NULL);
libmesh_assert (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 (unsigned int j=0; j<n_nodes; j++)
{
unsigned long int 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 attributes from the stream.
for (unsigned int j=0; j<nAttri; j++)
ele_stream >> dummy;
}
}
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().
Referenced by GMVIO::_read_materials(), GMVIO::_read_nodes(), GMVIO::_read_one_cell(), GMVIO::add_cell_centered_data(), GMVIO::copy_nodal_solution(), UNVIO::element_in(), element_in(), UNVIO::element_out(), UNVIO::node_in(), node_in(), UNVIO::node_out(), XdrIO::read(), VTKIO::read(), GMVIO::read(), ExodusII_IO::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(), 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().
Definition at line 119 of file tetgen_io.C.
References _assign_nodes, _mesh_data, _num_nodes, MeshData::add_foreign_node_id(), and MeshInput< MeshBase >::mesh().
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;
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
// For the number of attributes read all into dummy.
for (unsigned int j=0; j<nAttributes; j++)
node_stream >> dummy;
// Read boundary marker if BoundaryMarker=1.
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);
}
}
Implements MeshInput< MeshBase >.
Definition at line 33 of file tetgen_io.C.
References Quality::name(), libMesh::processor_id(), read_nodes_and_elem(), and MeshInput< MeshBase >::skip_comment_lines().
Referenced by UnstructuredMesh::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);
std::string name_node, name_ele, dummy;
// tetgen only works in 3D
libmesh_assert (MeshInput<MeshBase>::mesh().mesh_dimension() == 3);
// 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;
int position = dummy.rfind('.node');
name_ele = dummy.replace(position, 5, '.ele');
}
else if (name.rfind('.ele') < name.size())
{
name_ele = name;
dummy = name;
int position = dummy.rfind('.ele');
name_node = dummy.replace(position, 4, '.node');
}
else
{
std::cerr << 'ERROR: Unrecognized file name: '
<< name << std::endl;
libmesh_error();
}
// 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() )
{
std::cerr << 'ERROR: One or both Input file(s) not good.' << std::endl
<< 'Error checking files '
<< name_node << ' and '
<< name_ele << std::endl;
libmesh_error();
}
std::cout<< '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);
std::cout<< 'read in nodes and elements ' <<std::endl;
}
Definition at line 96 of file tetgen_io.C.
References _assign_nodes, _mesh_data, _num_elements, _num_nodes, 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();
}
Referenced by read(), and UCDIO::read_implementation().
Implements MeshOutput< MeshBase >.
Definition at line 252 of file tetgen_io.C.
References MeshBase::active_elements_begin(), MeshBase::active_elements_end(), MeshInput< MeshBase >::mesh(), MeshBase::n_elem(), MeshBase::n_nodes(), and MeshBase::point().
Referenced by UnstructuredMesh::write().
{
// libmesh_assert three dimensions (should be extended later)
libmesh_assert (MeshOutput<MeshBase>::mesh().mesh_dimension() == 3);
if (!(fname.rfind('.poly') < fname.size()))
{
std::cerr << 'ERROR: Unrecognized file name: '
<< fname << std::endl;
libmesh_error();
}
// Open the output file stream
std::ofstream out (fname.c_str());
// Make sure it opened correctly
if (!out.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 << '# poly file output generated by libmesh
<< mesh.n_nodes() << ' 3 0 0;
// write the nodes:
for (unsigned int v=0; v<mesh.n_nodes(); v++)
out << v << ' '
<< mesh.point(v)(0) << ' '
<< mesh.point(v)(1) << ' '
<< mesh.point(v)(2) << ';
}
{
// write the connectivity:
out << '# Facets:
<< mesh.n_elem() << ' 0;
// 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 << '1 ' // no. of facet polygons
// << (*it)->n_nodes() << ' '
<< (*it)->node(0) << ' '
<< (*it)->node(1) << ' '
<< (*it)->node(2) << ';
}
// end of the file
out << '0; // no holes output!
out << 'n# end of file;
}
Reimplemented in ExodusII_IO, GmshIO, GMVIO, GnuPlotIO, MEDITIO, and TecplotIO.
Definition at line 91 of file mesh_output.h.
{ libmesh_error(); }
Definition at line 116 of file tetgen_io.h.
Referenced by element_in(), node_in(), and read_nodes_and_elem().
Definition at line 132 of file tetgen_io.h.
Referenced by element_in(), node_in(), and read_nodes_and_elem().
Definition at line 126 of file tetgen_io.h.
Referenced by element_in(), and read_nodes_and_elem().
Definition at line 121 of file tetgen_io.h.
Referenced by node_in(), and read_nodes_and_elem().
Generated automatically by Doxygen for libMesh from the source code.