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 libmesh_error_msg_if(!node_stream.good() || !ele_stream.good(),
77 "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 libmesh_error_msg_if(region_attribute > 1,
207 "Invalid region_attribute " << region_attribute <<
" specified in .ele file.");
211 static const unsigned int assign_elm_nodes[] = {0, 1, 2, 3, 9, 7, 4, 5, 8, 6};
218 Elem * elem =
nullptr;
227 libmesh_error_msg(
"Elements with " <<
n_nodes <<
228 " nodes are not supported in the LibMesh tetgen module.");
231 libmesh_assert_equal_to (elem->n_nodes(),
n_nodes);
237 ele_stream >> element_lab;
243 ele_stream >> node_label;
246 elem->set_node(assign_elm_nodes[j],
251 if (region_attribute)
254 ele_stream >> region;
258 elem->subdomain_id() = cast_int<subdomain_id_type>(region);
273 libmesh_error_msg_if(!(fname.rfind(
".poly") < fname.size()),
274 "ERROR: Unrecognized file name: " << fname);
277 std::ofstream out_stream (fname.c_str());
280 if (!out_stream.good())
281 libmesh_file_error(fname.c_str());
289 out_stream <<
"# poly file output generated by libmesh\n" 294 out_stream << v <<
" " 302 out_stream <<
"# Facets:\n" 305 for (
const auto & elem :
mesh.active_element_ptr_range())
306 out_stream <<
"1\n3 " 308 << elem->node_id(0) <<
" " 309 << elem->node_id(1) <<
" " 310 << elem->node_id(2) <<
"\n";
315 out_stream <<
"\n\n# end of file\n";
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
dof_id_type _num_elements
total number of elements.
std::map< dof_id_type, dof_id_type > _assign_nodes
stores new positions of nodes.
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in TetGen format.
This is the base class from which all geometric element types are derived.
This class defines an abstract interface for Mesh output.
The libMesh namespace provides an interface to certain functionality in the library.
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.
This is the MeshBase class.
const dof_id_type n_nodes
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
dof_id_type _num_nodes
total number of nodes.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static std::unique_ptr< Elem > build_with_id(const ElemType type, dof_id_type id)
Calls the build() method above with a nullptr parent, and additionally sets the newly-created Elem's ...
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.
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
virtual void write(const std::string &) override
This method implements writing a mesh to a specified ".poly" file.
virtual const Point & point(const dof_id_type i) const =0
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...
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_elem() const =0
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.
A Point defines a location in LIBMESH_DIM dimensional Real space.
virtual dof_id_type n_nodes() const =0