Go to the documentation of this file.
   20 #include "libmesh/tetgen_io.h" 
   21 #include "libmesh/mesh_base.h" 
   22 #include "libmesh/cell_tet4.h" 
   23 #include "libmesh/cell_tet10.h" 
   41   std::string name_node, name_ele, dummy;
 
   47   libmesh_error_msg(
"Cannot open dimension 3 mesh file when configured without 3D support.");
 
   53   if (
name.rfind(
".node") < 
name.size())
 
   57       std::size_t position = dummy.rfind(
".node");
 
   58       name_ele             = dummy.replace(position, 5, 
".ele");
 
   60   else if (
name.rfind(
".ele") < 
name.size())
 
   64       std::size_t position = dummy.rfind(
".ele");
 
   65       name_node    = dummy.replace(position, 4, 
".node");
 
   68     libmesh_error_msg(
"ERROR: Unrecognized file name: " << 
name);
 
   73   std::ifstream node_stream (name_node.c_str());
 
   74   std::ifstream ele_stream  (name_ele.c_str());
 
   76   if (!node_stream.good() || !ele_stream.good())
 
   77     libmesh_error_msg(
"Error while opening either "     \
 
   82   libMesh::out<< 
"TetGenIO found the tetgen files to read " <<std::endl;
 
   90   libMesh::out<< 
"TetGenIO read in nodes and elements " <<std::endl;
 
   96                                     std::istream & ele_stream)
 
  121   unsigned int dimension=0, nAttributes=0, BoundaryMarkers=0;
 
  129   unsigned int node_lab=0;
 
  134   for (
unsigned i=0; i<nAttributes; ++i)
 
  143       std::array<Real, 3> xyz;
 
  145       node_stream >> node_lab  
 
  151       for (
unsigned int j=0; j<nAttributes; j++)
 
  156       if (BoundaryMarkers == 1)
 
  157         node_stream >> dummy;
 
  167       libmesh_assert_equal_to(xyz[1], 0);
 
  172       libmesh_assert_equal_to(xyz[2], 0);
 
  193   unsigned int element_lab=0, 
n_nodes=0, region_attribute=0;
 
  206   if (region_attribute > 1)
 
  207     libmesh_error_msg(
"Invalid region_attribute " << region_attribute << 
" specified in .ele file.");
 
  213   static const unsigned int assign_elm_nodes[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
 
  229         libmesh_error_msg(
"Elements with " << 
n_nodes << 
" nodes are not supported in the LibMesh tetgen module.");
 
  236       libmesh_assert_equal_to (elem->n_nodes(), 
n_nodes);
 
  242       ele_stream >> element_lab;
 
  248           ele_stream >> node_label;
 
  251           elem->set_node(assign_elm_nodes[j]) =
 
  256       if (region_attribute)
 
  259           ele_stream >> region;
 
  263           elem->subdomain_id() = cast_int<subdomain_id_type>(region);
 
  278   if (!(fname.rfind(
".poly") < fname.size()))
 
  279     libmesh_error_msg(
"ERROR: Unrecognized file name: " << fname);
 
  282   std::ofstream out_stream (fname.c_str());
 
  285   if (!out_stream.good())
 
  286     libmesh_file_error(fname.c_str());
 
  294     out_stream << 
"# poly file output generated by libmesh\n" 
  299       out_stream << v << 
" " 
  307     out_stream << 
"# Facets:\n" 
  311       out_stream << 
"1\n3 "  
  313                  << elem->node_id(0)   << 
" " 
  314                  << elem->node_id(1)   << 
" " 
  315                  << elem->node_id(2)   << 
"\n";
 
  320   out_stream << 
"\n\n# end of file\n";
 
  
virtual const Point & point(const dof_id_type i) const =0
 
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
 
virtual dof_id_type n_elem() const =0
 
The libMesh namespace provides an interface to certain functionality in the library.
 
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in TetGen format.
 
virtual void write(const std::string &) override
This method implements writing a mesh to a specified ".poly" file.
 
virtual const Node * node_ptr(const dof_id_type i) const =0
 
std::vector< std::vector< Real > > node_attributes
Data structure to hold node attributes read in from file.
 
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
 
This is the MeshBase class.
 
A Point defines a location in LIBMESH_DIM dimensional Real space.
 
std::map< dof_id_type, dof_id_type > _assign_nodes
stores new positions of nodes.
 
The Tet4 is an element in 3D composed of 4 nodes.
 
const dof_id_type n_nodes
 
void element_in(std::istream &ele_stream)
Method reads elements and stores them in vector<Elem *> elements in the same order as they come in.
 
virtual dof_id_type n_nodes() const =0
 
This class defines an abstract interface for Mesh output.
 
The Tet10 is an element in 3D composed of 10 nodes.
 
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
 
void node_in(std::istream &node_stream)
Method reads nodes from node_stream and stores them in vector<Node *> nodes in the order they come in...
 
This is the base class from which all geometric element types are derived.
 
dof_id_type _num_nodes
total number of nodes.
 
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
 
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
 
void read_nodes_and_elem(std::istream &node_stream, std::istream &ele_stream)
Reads a mesh (nodes & elements) from the file provided through node_stream and ele_stream.
 
dof_id_type _num_elements
total number of elements.
 
std::string name(const ElemQuality q)
This function returns a string containing some name for q.