libMesh::TriangleWrapper Namespace Reference

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

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


Enumeration Type Documentation

Enumerator:
INPUT 
OUTPUT 
BOTH 

Definition at line 53 of file mesh_triangle_wrapper.h.

00053                  {
00054       INPUT  = 0,
00055       OUTPUT = 1,
00056       BOTH   = 2};


Function Documentation

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

Copies triangulation data computed by triange 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 102 of file mesh_triangle_wrapper.C.

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

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

00105   {
00106     // Transfer the information into the LibMesh mesh.
00107     mesh_output.clear();
00108 
00109     // Make sure the new Mesh will be 2D
00110     mesh_output.set_mesh_dimension(2);
00111 
00112     // Node information
00113     for (int i=0, c=0; c<triangle_data_input.numberofpoints; i+=2, ++c)
00114       {
00115         // Specify ID when adding point, otherwise, if this is ParallelMesh,
00116         // it might add points with a non-sequential numbering...
00117         mesh_output.add_point( Point(triangle_data_input.pointlist[i],
00118                                      triangle_data_input.pointlist[i+1]),
00119                                /*id=*/c);
00120       }
00121 
00122     // Element information
00123     for (int i=0; i<triangle_data_input.numberoftriangles; ++i)
00124       {
00125         switch (type)
00126           {
00127           case TRI3:
00128             {
00129               Elem* elem = mesh_output.add_elem (new Tri3);
00130 
00131               for (unsigned int n=0; n<3; ++n)
00132                 elem->set_node(n) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*3 + n]);
00133 
00134               break;
00135             }
00136 
00137           case TRI6:
00138             {
00139               Elem* elem = mesh_output.add_elem (new Tri6);
00140 
00141               // Triangle number TRI6 nodes in a different way to libMesh
00142               elem->set_node(0) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*6 + 0]);
00143               elem->set_node(1) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*6 + 1]);
00144               elem->set_node(2) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*6 + 2]);
00145               elem->set_node(3) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*6 + 5]);
00146               elem->set_node(4) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*6 + 3]);
00147               elem->set_node(5) = mesh_output.node_ptr(triangle_data_input.trianglelist[i*6 + 4]);
00148 
00149               break;
00150             }
00151 
00152           default:
00153             {
00154               libMesh::err << "ERROR: Unrecognized triangular element type." << std::endl;
00155               libmesh_error();
00156             }
00157           }
00158       }
00159 
00160     // Note: If the input mesh was a parallel one, calling
00161     // prepare_for_use() now will re-parallelize it by a call to
00162     // delete_remote_elements()... We do not actually want to
00163     // reparallelize it here though: the triangulate() function may
00164     // still do some Mesh smoothing.  The main thing needed (for
00165     // smoothing) is the neighbor information, so let's just find
00166     // neighbors...
00167     //mesh_output.prepare_for_use(/*skip_renumber =*/false);
00168     mesh_output.find_neighbors();
00169   }

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

Frees any memory which has been dynamically allocated by Triangle. Note the following facts: 1) Triangle does not free any memory itself 2) It is always safe to call free on a NULL pointer.

However, 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().

void libMesh::TriangleWrapper::init ( triangulateio &  t  ) 

Initializes the fields of t to NULL/0 as necessary. This is helpful for preventing the access of uninitialized memory when working with C, which has no constructors or destructors.


Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:49 UTC

Hosted By:
SourceForge.net Logo