libMesh::TriangleWrapper Namespace Reference

Namespace that wraps the Triangle mesh generator's API. More...

Enumerations

enum  IO_Type { INPUT = 0, OUTPUT = 1, BOTH = 2 }
 

Functions

void init (triangulateio &t)
 
void destroy (triangulateio &t, IO_Type)
 
void copy_tri_to_mesh (const triangulateio &triangle_data_input, UnstructuredMesh &mesh_output, const ElemType type)
 

Detailed Description

Namespace that wraps the Triangle mesh generator's API.

A special namespace for wrapping the standard Triangle API, as well as some helper functions for initializing/destroying the structs triangle uses to communicate.

Author
John W. Peterson
Date
2011

Enumeration Type Documentation

◆ IO_Type

Function Documentation

◆ copy_tri_to_mesh()

void libMesh::TriangleWrapper::copy_tri_to_mesh ( const triangulateio &  triangle_data_input,
UnstructuredMesh mesh_output,
const ElemType  type 
)

Copies triangulation data computed by triangle from a triangulateio object to a LibMesh mesh. This routine is used internally by the MeshTools::Generation::build_delaunay_square(...) and MeshTools::Generation::build_delaunay_square_with_hole(...) routines.

Definition at line 103 of file mesh_triangle_wrapper.C.

References libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_point(), libMesh::MeshBase::clear(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::MeshBase::node_ptr(), libMesh::MeshBase::set_mesh_dimension(), libMesh::Elem::set_node(), libMesh::TRI3, and libMesh::TRI6.

Referenced by libMesh::TriangleInterface::triangulate().

106 {
107  // Transfer the information into the LibMesh mesh.
108  mesh_output.clear();
109 
110  // Make sure the new Mesh will be 2D
111  mesh_output.set_mesh_dimension(2);
112 
113  // Node information
114  for (int i=0, c=0; c<triangle_data_input.numberofpoints; i+=2, ++c)
115  {
116  // Specify ID when adding point, otherwise, if this is DistributedMesh,
117  // it might add points with a non-sequential numbering...
118  mesh_output.add_point( Point(triangle_data_input.pointlist[i],
119  triangle_data_input.pointlist[i+1]),
120  /*id=*/c);
121  }
122 
123  // Element information
124  for (int i=0; i<triangle_data_input.numberoftriangles; ++i)
125  {
126  switch (type)
127  {
128  case TRI3:
129  {
130  Elem * elem = mesh_output.add_elem (new Tri3);
131 
132  for (unsigned int n=0; n<3; ++n)
133  elem->set_node(n) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*3 + n]);
134 
135  break;
136  }
137 
138  case TRI6:
139  {
140  Elem * elem = mesh_output.add_elem (new Tri6);
141 
142  // Triangle number TRI6 nodes in a different way to libMesh
143  elem->set_node(0) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*6 + 0]);
144  elem->set_node(1) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*6 + 1]);
145  elem->set_node(2) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*6 + 2]);
146  elem->set_node(3) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*6 + 5]);
147  elem->set_node(4) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*6 + 3]);
148  elem->set_node(5) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*6 + 4]);
149 
150  break;
151  }
152 
153  default:
154  libmesh_error_msg("ERROR: Unrecognized triangular element type.");
155  }
156  }
157 
158  // Note: If the input mesh was a parallel one, calling
159  // prepare_for_use() now will re-parallelize it by a call to
160  // delete_remote_elements()... We do not actually want to
161  // reparallelize it here though: the triangulate() function may
162  // still do some Mesh smoothing. The main thing needed (for
163  // smoothing) is the neighbor information, so let's just find
164  // neighbors...
165  //mesh_output.prepare_for_use(/*skip_renumber =*/false);
166  mesh_output.find_neighbors();
167 }

◆ destroy()

void libMesh::TriangleWrapper::destroy ( triangulateio &  t,
IO_Type   
)

Frees any memory which has been dynamically allocated by Triangle.

Note
Triangle does not free any memory itself.
It is always safe to call free on a nullptr.
Triangle does shallow-copy (for example) the holelist pointer from the input to output struct without performing a deep copy of the holelist itself. Therefore, double-free will occur without additional care!

Referenced by libMesh::TriangleInterface::triangulate().

◆ init()