20#include "libmesh/tetgen_io.h"
22#include "libmesh/cell_tet4.h"
23#include "libmesh/cell_tet10.h"
24#include "libmesh/mesh_base.h"
25#include "libmesh/utility.h"
43 std::string name_node, name_ele, dummy;
49 libmesh_error_msg(
"Cannot open dimension 3 mesh file when configured without 3D support.");
59 std::size_t position = dummy.rfind(
".node");
60 name_ele = dummy.replace(position, 5,
".ele");
66 std::size_t position = dummy.rfind(
".ele");
67 name_node = dummy.replace(position, 4,
".node");
70 libmesh_error_msg(
"ERROR: Unrecognized file name: " << name);
75 std::ifstream node_stream (name_node.c_str());
76 std::ifstream ele_stream (name_ele.c_str());
78 libmesh_error_msg_if(!node_stream.good() || !ele_stream.good(),
79 "Error while opening either "
84 libMesh::out<<
"TetGenIO found the tetgen files to read " <<std::endl;
92 libMesh::out<<
"TetGenIO read in nodes and elements " <<std::endl;
98 std::istream & ele_stream)
123 unsigned int dimension=0, nAttributes=0, BoundaryMarkers=0;
131 unsigned int node_lab=0;
136 for (
unsigned i=0; i<nAttributes; ++i)
145 std::array<Real, 3> xyz;
147 node_stream >> node_lab
153 for (
unsigned int j=0; j<nAttributes; j++)
158 if (BoundaryMarkers == 1)
159 node_stream >> dummy;
169 libmesh_assert_equal_to(xyz[1], 0);
174 libmesh_assert_equal_to(xyz[2], 0);
195 unsigned int element_lab=0,
n_nodes=0, region_attribute=0;
208 libmesh_error_msg_if(region_attribute > 1,
209 "Invalid region_attribute " << region_attribute <<
" specified in .ele file.");
213 static const unsigned int assign_elm_nodes[] = {0, 1, 2, 3, 9, 7, 4, 5, 8, 6};
220 Elem * elem =
nullptr;
229 libmesh_error_msg(
"Elements with " <<
n_nodes <<
230 " nodes are not supported in the LibMesh tetgen module.");
239 ele_stream >> element_lab;
245 ele_stream >> node_label;
253 if (region_attribute)
256 ele_stream >> region;
260 elem->
subdomain_id() = restrict_int<subdomain_id_type>(region);
276 "ERROR: Unrecognized file name: " << fname);
279 std::ofstream out_stream (fname.c_str());
282 if (!out_stream.good())
283 libmesh_file_error(fname.c_str());
291 out_stream <<
"# poly file output generated by libmesh\n"
296 out_stream << v <<
" "
304 out_stream <<
"# Facets:\n"
307 for (
const auto & elem :
mesh.active_element_ptr_range())
308 out_stream <<
"1\n3 "
310 << elem->node_id(0) <<
" "
311 << elem->node_id(1) <<
" "
312 << elem->node_id(2) <<
"\n";
317 out_stream <<
"\n\n# end of file\n";
This is the base class from which all geometric element types are derived.
virtual Node *& set_node(const unsigned int i)
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 ...
virtual unsigned int n_nodes() const =0
subdomain_id_type subdomain_id() const
This is the MeshBase class.
virtual const Point & point(const dof_id_type i) const =0
virtual const Node * node_ptr(const dof_id_type i) const =0
virtual dof_id_type n_elem() const =0
virtual dof_id_type n_nodes() const =0
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.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
This class defines an abstract interface for Mesh output.
A Point defines a location in LIBMESH_DIM dimensional Real space.
dof_id_type _num_nodes
total number of nodes.
dof_id_type _num_elements
total number of elements.
std::vector< std::vector< Real > > node_attributes
Data structure to hold node attributes read in from file.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified ".poly" file.
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.
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...
std::map< dof_id_type, dof_id_type > _assign_nodes
stores new positions of nodes.
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.
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in TetGen format.
bool contains(std::string_view superstring, std::string_view substring)
Look for a substring within a string.
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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...
const dof_id_type n_nodes