libMesh::TetGenWrapper Class Reference

#include <mesh_tetgen_wrapper.h>

Public Member Functions

 TetGenWrapper ()
 
 ~TetGenWrapper ()
 
void set_switches (const std::string &s)
 
void run_tetgen ()
 
int get_numberoftetrahedra ()
 
int get_numberoftrifaces ()
 
void set_numberofpoints (int i)
 
int get_numberofpoints ()
 
void set_numberoffacets (int i)
 
void set_numberofholes (int i)
 
void set_numberofregions (int i)
 
void allocate_pointlist (int numofpoints)
 
void allocate_facetlist (int numoffacets, int numofholes)
 
void allocate_regionlist (int numofregions)
 
void set_node (unsigned i, REAL x, REAL y, REAL z)
 
void get_output_node (unsigned i, REAL &x, REAL &y, REAL &z)
 
int get_element_node (unsigned i, unsigned j)
 
int get_triface_node (unsigned i, unsigned j)
 
REAL get_element_attribute (unsigned i)
 
void set_hole (unsigned i, REAL x, REAL y, REAL z)
 
void set_facet_numberofpolygons (unsigned i, int num)
 
void set_facet_numberofholes (unsigned i, int num)
 
void allocate_facet_polygonlist (unsigned i, int numofpolygons)
 
void set_polygon_numberofvertices (unsigned i, unsigned j, int num)
 
void allocate_polygon_vertexlist (unsigned i, unsigned j, int numofvertices)
 
void set_vertex (unsigned i, unsigned j, unsigned k, int nodeindex)
 
void set_region (unsigned i, REAL x, REAL y, REAL z, REAL attribute, REAL vol_constraint)
 

Public Attributes

tetgenio tetgen_data
 
std::unique_ptr< tetgenio > tetgen_output
 
tetgenmesh tetgen_mesh
 
tetgenbehavior tetgen_be
 

Detailed Description

The TetGenWrapper provides an interface for basic access to TetGen data structures and methods.

Author
Steffen Petersen
Date
2004
Author
John W. Peterson
Date
2011

Definition at line 45 of file mesh_tetgen_wrapper.h.

Constructor & Destructor Documentation

◆ TetGenWrapper()

libMesh::TetGenWrapper::TetGenWrapper ( )

Constructor.

Definition at line 31 of file mesh_tetgen_wrapper.C.

References tetgen_data.

31  :
32  tetgen_output(new tetgenio)
33 {
34  this->tetgen_data.mesh_dim = 3;
35  this->tetgen_data.numberofpointattributes = 0;
36  this->tetgen_data.firstnumber = 0;
37 }
std::unique_ptr< tetgenio > tetgen_output

◆ ~TetGenWrapper()

libMesh::TetGenWrapper::~TetGenWrapper ( )

Destructor. Empty.

Definition at line 41 of file mesh_tetgen_wrapper.C.

42 {
43 }

Member Function Documentation

◆ allocate_facet_polygonlist()

void libMesh::TetGenWrapper::allocate_facet_polygonlist ( unsigned  i,
int  numofpolygons 
)

Allocates memory, sets number of polygons for facet i in the TetGen input.

Definition at line 276 of file mesh_tetgen_wrapper.C.

References set_facet_numberofholes(), set_facet_numberofpolygons(), and tetgen_data.

Referenced by libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole().

277 {
278  this->set_facet_numberofpolygons(i, numofpolygons);
279  this->set_facet_numberofholes(i, 0);
280 
281  // Don't try to create an array of size zero, this isn't portable
282  if (numofpolygons > 0)
283  {
284  // Is there previously-allocated memory here?
285  if (this->tetgen_data.facetlist[i].polygonlist != nullptr)
286  libmesh_error_msg("Cannot allocate on top of previously allocated memory!");
287 
288  // We allocate memory here, the tetgenio destructor cleans it up.
289  this->tetgen_data.facetlist[i].polygonlist = new tetgenio::polygon[numofpolygons];
290 
291  for (int j=0; j<this->tetgen_data.facetlist[i].numberofpolygons; j++)
292  this->tetgen_data.init(&(this->tetgen_data.facetlist[i].polygonlist[j]));
293  }
294 }
void set_facet_numberofpolygons(unsigned i, int num)
void set_facet_numberofholes(unsigned i, int num)

◆ allocate_facetlist()

void libMesh::TetGenWrapper::allocate_facetlist ( int  numoffacets,
int  numofholes 
)

Allocates memory, sets number of facets, holes in the TetGen input.

Definition at line 207 of file mesh_tetgen_wrapper.C.

References set_numberoffacets(), set_numberofholes(), and tetgen_data.

Referenced by libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole().

208 {
209  // These are both stored as ints in TetGen
210  this->set_numberoffacets(numoffacets);
211  this->set_numberofholes(numofholes);
212 
213  // Don't try to allocate an array of size zero, this is not portable...
214  if (this->tetgen_data.numberoffacets > 0)
215  {
216  // Is there previously-allocated memory here?
217  if (this->tetgen_data.facetlist != nullptr)
218  libmesh_error_msg("Cannot allocate on top of previously allocated memory!");
219 
220  // We allocate memory here, the tetgenio destructor cleans it up.
221  this->tetgen_data.facetlist = new tetgenio::facet[this->tetgen_data.numberoffacets];
222 
223  for (int i=0; i<numoffacets; i++)
224  this->tetgen_data.init(&(this->tetgen_data.facetlist[i]));
225  }
226 
227 
228  // Don't try to allocate an array of size zero, this is not portable...
229  if (this->tetgen_data.numberofholes > 0)
230  {
231  // Is there previously-allocated memory here?
232  if (this->tetgen_data.holelist != nullptr)
233  libmesh_error_msg("Cannot allocate on top of previously allocated memory!");
234 
235  this->tetgen_data.holelist = new REAL[this->tetgen_data.numberofholes * 3];
236  }
237 }

◆ allocate_pointlist()

void libMesh::TetGenWrapper::allocate_pointlist ( int  numofpoints)

Allocates memory, sets number of nodes in the TetGen input.

Definition at line 135 of file mesh_tetgen_wrapper.C.

References set_numberofpoints(), and tetgen_data.

Referenced by libMesh::TetGenMeshInterface::fill_pointlist().

136 {
137  // This is stored as an int in tetgen, so we store it that way as well.
138  this->set_numberofpoints(numofpoints);
139 
140  // Don't try to allocate an array of size zero, this is not portable...
141  if (this->tetgen_data.numberofpoints > 0)
142  {
143  // Is there previously-allocated memory here?
144  if (this->tetgen_data.pointlist != nullptr)
145  libmesh_error_msg("Cannot allocate on top of previously allocated memory!");
146 
147  // We allocate memory here, the tetgenio destructor will delete it.
148  this->tetgen_data.pointlist = new REAL[this->tetgen_data.numberofpoints * 3];
149  }
150 }

◆ allocate_polygon_vertexlist()

void libMesh::TetGenWrapper::allocate_polygon_vertexlist ( unsigned  i,
unsigned  j,
int  numofvertices 
)

Allocates memory, sets number of vertices for polygon j, facet i in the TetGen input.

Definition at line 306 of file mesh_tetgen_wrapper.C.

References set_polygon_numberofvertices(), and tetgen_data.

Referenced by libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole().

307 {
308  this->set_polygon_numberofvertices(i, j, numofvertices);
309 
310  // Don't try to create an array of size zero, this isn't portable
311  if (numofvertices > 0)
312  {
313  // Is there previously-allocated memory here?
314  if (this->tetgen_data.facetlist[i].polygonlist[j].vertexlist != nullptr)
315  libmesh_error_msg("Cannot allocate on top of previously allocated memory!");
316 
317  // We allocate memory here, the tetgenio destructor cleans it up.
318  this->tetgen_data.facetlist[i].polygonlist[j].vertexlist = new int[numofvertices];
319  }
320 }
void set_polygon_numberofvertices(unsigned i, unsigned j, int num)

◆ allocate_regionlist()

void libMesh::TetGenWrapper::allocate_regionlist ( int  numofregions)

Allocates memory, sets number of regions in the TetGen input.

Definition at line 241 of file mesh_tetgen_wrapper.C.

References set_numberofregions(), and tetgen_data.

242 {
243  this->set_numberofregions(numofregions);
244 
245  // Don't try to allocate an array of size zero, this is not portable...
246  if (this->tetgen_data.numberofregions > 0)
247  {
248  // Is there previously-allocated memory here?
249  if (this->tetgen_data.regionlist != nullptr)
250  libmesh_error_msg("Cannot allocate on top of previously allocated memory!");
251 
252  // We allocate memory here, the tetgenio destructor cleans it up.
253  this->tetgen_data.regionlist = new REAL[this->tetgen_data.numberofregions * 5];
254  }
255 }

◆ get_element_attribute()

REAL libMesh::TetGenWrapper::get_element_attribute ( unsigned  i)
Returns
The attribute of element i in the TetGen output.

Definition at line 127 of file mesh_tetgen_wrapper.C.

References tetgen_output.

128 {
129  libmesh_assert(tetgen_output->numberoftetrahedronattributes>0);
130  return tetgen_output->tetrahedronattributelist[tetgen_output->numberoftetrahedronattributes*i];
131 }
std::unique_ptr< tetgenio > tetgen_output

◆ get_element_node()

int libMesh::TetGenWrapper::get_element_node ( unsigned  i,
unsigned  j 
)
Returns
The index of jth node from element i in the TetGen output.

Definition at line 113 of file mesh_tetgen_wrapper.C.

References tetgen_output.

Referenced by libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole(), and libMesh::TetGenMeshInterface::triangulate_pointset().

114 {
115  return tetgen_output->tetrahedronlist[i*4+j];
116 }
std::unique_ptr< tetgenio > tetgen_output

◆ get_numberofpoints()

int libMesh::TetGenWrapper::get_numberofpoints ( )
Returns
Number of nodes in the TetGen output.

Definition at line 106 of file mesh_tetgen_wrapper.C.

References tetgen_output.

Referenced by libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole().

107 {
108  return tetgen_output->numberofpoints;
109 }
std::unique_ptr< tetgenio > tetgen_output

◆ get_numberoftetrahedra()

int libMesh::TetGenWrapper::get_numberoftetrahedra ( )
Returns
Number of tetrahedra in the TetGen output.

Definition at line 92 of file mesh_tetgen_wrapper.C.

References tetgen_output.

Referenced by libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole(), and libMesh::TetGenMeshInterface::triangulate_pointset().

93 {
94  return tetgen_output->numberoftetrahedra;
95 }
std::unique_ptr< tetgenio > tetgen_output

◆ get_numberoftrifaces()

int libMesh::TetGenWrapper::get_numberoftrifaces ( )
Returns
Number of triangle surface elements in the TetGen output.

Definition at line 99 of file mesh_tetgen_wrapper.C.

References tetgen_output.

Referenced by libMesh::TetGenMeshInterface::pointset_convexhull().

100 {
101  return tetgen_output->numberoftrifaces;
102 }
std::unique_ptr< tetgenio > tetgen_output

◆ get_output_node()

void libMesh::TetGenWrapper::get_output_node ( unsigned  i,
REAL x,
REAL y,
REAL z 
)
Returns
The coordinates of point i in the TetGen output.

Definition at line 75 of file mesh_tetgen_wrapper.C.

References tetgen_output.

Referenced by libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole().

76 {
77  // Bounds checking...
78  if (i >= static_cast<unsigned>(tetgen_output->numberofpoints))
79  libmesh_error_msg("Error, requested point " \
80  << i \
81  << ", but there are only " \
82  << tetgen_output->numberofpoints \
83  << " points available.");
84 
85  x = tetgen_output->pointlist[3*i];
86  y = tetgen_output->pointlist[3*i+1];
87  z = tetgen_output->pointlist[3*i+2];
88 }
std::unique_ptr< tetgenio > tetgen_output

◆ get_triface_node()

int libMesh::TetGenWrapper::get_triface_node ( unsigned  i,
unsigned  j 
)
Returns
The index of the jth node from surface triangle i in the TetGen output.

Definition at line 120 of file mesh_tetgen_wrapper.C.

References tetgen_output.

Referenced by libMesh::TetGenMeshInterface::pointset_convexhull().

121 {
122  return tetgen_output->trifacelist[i*3+j];
123 }
std::unique_ptr< tetgenio > tetgen_output

◆ run_tetgen()

void libMesh::TetGenWrapper::run_tetgen ( )

Starts the triangulation.

Definition at line 175 of file mesh_tetgen_wrapper.C.

References tetgen_be, tetgen_data, and tetgen_output.

Referenced by libMesh::TetGenMeshInterface::pointset_convexhull(), libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole(), and libMesh::TetGenMeshInterface::triangulate_pointset().

176 {
177  // Call tetrahedralize from the TetGen library.
178  tetrahedralize(&tetgen_be, &tetgen_data, tetgen_output.get());
179 }
std::unique_ptr< tetgenio > tetgen_output

◆ set_facet_numberofholes()

void libMesh::TetGenWrapper::set_facet_numberofholes ( unsigned  i,
int  num 
)

Sets the number of holes for facet i in the TetGen input.

Definition at line 267 of file mesh_tetgen_wrapper.C.

References tetgen_data.

Referenced by allocate_facet_polygonlist().

268 {
269  // numberofholes is stored as an int in TetGen
270  this->tetgen_data.facetlist[i].numberofholes = num;
271 }

◆ set_facet_numberofpolygons()

void libMesh::TetGenWrapper::set_facet_numberofpolygons ( unsigned  i,
int  num 
)

Sets the number of polygons for facet i in the TetGen input.

Definition at line 259 of file mesh_tetgen_wrapper.C.

References tetgen_data.

Referenced by allocate_facet_polygonlist().

260 {
261  // numberofpolygons is stored as an int in TetGen
262  this->tetgen_data.facetlist[i].numberofpolygons = num;
263 }

◆ set_hole()

void libMesh::TetGenWrapper::set_hole ( unsigned  i,
REAL  x,
REAL  y,
REAL  z 
)

Sets coordinates of hole i in the TetGen input.

Definition at line 57 of file mesh_tetgen_wrapper.C.

References tetgen_data.

Referenced by libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole().

58 {
59  unsigned index = i*3;
60  tetgen_data.holelist[index++] = x;
61  tetgen_data.holelist[index++] = y;
62  tetgen_data.holelist[index++] = z;
63 }

◆ set_node()

void libMesh::TetGenWrapper::set_node ( unsigned  i,
REAL  x,
REAL  y,
REAL  z 
)

Sets coordinates of point i in the TetGen input.

Definition at line 47 of file mesh_tetgen_wrapper.C.

References tetgen_data.

Referenced by libMesh::TetGenMeshInterface::fill_pointlist().

48 {
49  unsigned index = i*3;
50  tetgen_data.pointlist[index++] = x;
51  tetgen_data.pointlist[index++] = y;
52  tetgen_data.pointlist[index++] = z;
53 }

◆ set_numberoffacets()

void libMesh::TetGenWrapper::set_numberoffacets ( int  i)

Sets the number of facets in the TetGen input.

Definition at line 183 of file mesh_tetgen_wrapper.C.

References tetgen_data.

Referenced by allocate_facetlist().

184 {
185  // This is stored as an int in TetGen
186  this->tetgen_data.numberoffacets = i;
187 }

◆ set_numberofholes()

void libMesh::TetGenWrapper::set_numberofholes ( int  i)

Sets the number of holes in the TetGen input.

Definition at line 191 of file mesh_tetgen_wrapper.C.

References tetgen_data.

Referenced by allocate_facetlist().

192 {
193  // This is stored as an int in TetGen
194  this->tetgen_data.numberofholes = i;
195 }

◆ set_numberofpoints()

void libMesh::TetGenWrapper::set_numberofpoints ( int  i)

Sets the number of nodes in the TetGen input.

Definition at line 67 of file mesh_tetgen_wrapper.C.

References tetgen_data.

Referenced by allocate_pointlist().

68 {
69  // This is an int in tetgen, so use an int here even though it should be unsigned
70  tetgen_data.numberofpoints = i;
71 }

◆ set_numberofregions()

void libMesh::TetGenWrapper::set_numberofregions ( int  i)

Sets the number of regions in the TetGen input.

Definition at line 199 of file mesh_tetgen_wrapper.C.

References tetgen_data.

Referenced by allocate_regionlist().

200 {
201  // This is stored as an int in TetGen
202  this->tetgen_data.numberofregions = i;
203 }

◆ set_polygon_numberofvertices()

void libMesh::TetGenWrapper::set_polygon_numberofvertices ( unsigned  i,
unsigned  j,
int  num 
)

Sets the number of vertices for polygon j, facet i in the TetGen input.

Definition at line 298 of file mesh_tetgen_wrapper.C.

References tetgen_data.

Referenced by allocate_polygon_vertexlist().

299 {
300  // numberofvertices is stored as an int in TetGen
301  this->tetgen_data.facetlist[i].polygonlist[j].numberofvertices = num;
302 }

◆ set_region()

void libMesh::TetGenWrapper::set_region ( unsigned  i,
REAL  x,
REAL  y,
REAL  z,
REAL  attribute,
REAL  vol_constraint 
)

Sets coordinates, attribute, and volume constraint for region i in the TetGen input.

Note
Coordinates and attributes will only be considered if the corresponding switches are enabled. See TetGen documentation for more details.

Definition at line 333 of file mesh_tetgen_wrapper.C.

References tetgen_data.

335 {
336  unsigned index = i*5;
337  tetgen_data.regionlist[index++] = x;
338  tetgen_data.regionlist[index++] = y;
339  tetgen_data.regionlist[index++] = z;
340  tetgen_data.regionlist[index++] = attribute;
341  tetgen_data.regionlist[index++] = vol_constraint;
342 }

◆ set_switches()

void libMesh::TetGenWrapper::set_switches ( const std::string &  s)

Method to set TetGen commandline switches -p Tetrahedralizes a piecewise linear complex (.poly or .smesh file). -q Quality mesh generation. A minimum radius-edge ratio may be specified (default 2.0). -a Applies a maximum tetrahedron volume constraint. -A Assigns attributes to identify tetrahedra in certain regions. -r Reconstructs and Refines a previously generated mesh. -Y Suppresses boundary facets/segments splitting. -i Inserts a list of additional points into mesh. -M Does not merge coplanar facets. -T Set a tolerance for coplanar test (default 1e-8). -d Detect intersections of PLC facets. -z Numbers all output items starting from zero. -o2 Generates second-order subparametric elements. -f Outputs faces (including non-boundary faces) to .face file. -e Outputs subsegments to .edge file. -n Outputs tetrahedra neighbors to .neigh file. -g Outputs mesh to .mesh file for viewing by Medit. -G Outputs mesh to .msh file for viewing by Gid. -O Outputs mesh to .off file for viewing by Geomview. -J No jettison of unused vertices from output .node file. -B Suppresses output of boundary information. -N Suppresses output of .node file. -E Suppresses output of .ele file. -F Suppresses output of .face file. -I Suppresses mesh iteration numbers. -C Checks the consistency of the final mesh. -Q Quiet: No terminal output except errors. -V Verbose: Detailed information, more terminal output. -v Prints the version information. -h Help: A brief instruction for using TetGen.

Definition at line 154 of file mesh_tetgen_wrapper.C.

References libMesh::out, and tetgen_be.

Referenced by libMesh::TetGenMeshInterface::pointset_convexhull(), libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole(), and libMesh::TetGenMeshInterface::triangulate_pointset().

155 {
156  // A temporary buffer for passing to the C API, it requires
157  // a char *, not a const char *...
158  char buffer[256];
159 
160  // Make sure char buffer has enough room
161  if (s.size() >= sizeof(buffer)-1)
162  libmesh_error_msg("Fixed size buffer of length " \
163  << sizeof(buffer) \
164  << " not large enough to hold TetGen switches.");
165 
166  // Copy the string, don't forget to terminate!
167  buffer[ s.copy( buffer , sizeof( buffer ) - 1 ) ] = '\0' ;
168 
169  if (!tetgen_be.parse_commandline(buffer))
170  libMesh::out << "TetGen replies: Wrong switches!" << std::endl;
171 }
OStreamProxy out(std::cout)

◆ set_vertex()

void libMesh::TetGenWrapper::set_vertex ( unsigned  i,
unsigned  j,
unsigned  k,
int  nodeindex 
)

Sets index of ith facet, jth polygon, kth vertex in the TetGen input.

Definition at line 325 of file mesh_tetgen_wrapper.C.

References tetgen_data.

Referenced by libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole().

326 {
327  // vertexlist entries are stored as ints in TetGen
328  this->tetgen_data.facetlist[i].polygonlist[j].vertexlist[k] = nodeindex;
329 }

Member Data Documentation

◆ tetgen_be

tetgenbehavior libMesh::TetGenWrapper::tetgen_be

TetGen control class (from the TetGen library).

Definition at line 240 of file mesh_tetgen_wrapper.h.

Referenced by run_tetgen(), and set_switches().

◆ tetgen_data

◆ tetgen_mesh

tetgenmesh libMesh::TetGenWrapper::tetgen_mesh

TetGen mesh structure (from the TetGen library).

Definition at line 235 of file mesh_tetgen_wrapper.h.

◆ tetgen_output

std::unique_ptr<tetgenio> libMesh::TetGenWrapper::tetgen_output

The documentation for this class was generated from the following files: