---
title: "TetGenTetrahedralize"
language: "en"
type: "Symbol"
summary: "TetGenTetrahedralize[expr, settings] tetrahedralizes a TetGen expression using settings and returns the result in a new TetGen expression."
keywords: 
- Tetrahedralization
- mesh
- mesh generation
- surface mesh
- volume mesh
- boundary mesh
- refinement
- mesh refinement
- 3D mesh
- tetrahedra
- grid
- convex hull
- delaunay
- delaunay mesh
canonical_url: "https://reference.wolfram.com/language/TetGenLink/ref/TetGenTetrahedralize.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "TetGenLink"
    link: "https://reference.wolfram.com/language/TetGenLink/guide/TetGenLink.en.md"
related_tutorials: 
  - 
    title: "Introduction in TetGenLink User Guide"
    link: "https://reference.wolfram.com/language/TetGenLink/tutorial/Introduction.en.md"
  - 
    title: "TetGenLink User Guide"
    link: "https://reference.wolfram.com/language/TetGenLink/tutorial/Overview.en.md"
---
## TetGenLink\`

# TetGenTetrahedralize

TetGenTetrahedralize[expr, settings] tetrahedralizes a TetGen expression using settings and returns the result in a new TetGen expression.

## Details and Options

* To use ``TetGenTetrahedralize``, you first need to load it using ``Needs["TetGenLink`"]``.

* The settings given to ``TetGenTetrahedralize`` are a string of different commands:

|      |                                                                                     |
| ---- | ----------------------------------------------------------------------------------- |
| "p"  | tetrahedralize a piecewise linear complex (PLC)                                     |
| "q"  | quality mesh generation; a minimum radius-edge ratio may be specified (default 2.0) |
| "a"  | apply a maximum tetrahedron volume constraint                                       |
| "A"  | assign attributes to identify tetrahedra in certain regions                         |
| "r"  | reconstruct/refine a previously generated mesh                                      |
| "Y"  | suppress splitting of boundary facets/segments                                      |
| "YY" | suppress splitting of exterior and interior boundary facets/segments                |
| "i"  | insert a list of additional points into mesh                                        |
| "M"  | do not merge coplanar facets                                                        |
| "T"  | set a tolerance for coplanar test (default $10^-8$)       |
| "d"  | detect intersections of PLC facets                                                  |
| "o2" | generate second-order subparametric elements                                        |
| "C"  | check the consistency of the final mesh                                             |
| "Q"  | quiet: no terminal output except error                                              |

* An empty string ``" "`` given to ``TetGenTetrahedralize`` creates a Delaunay tetrahedralization.

* ``TetGenTetrahedralize`` has the following options:

"TetrahedronRefinement" 	[`None`](https://reference.wolfram.com/language/ref/None.en.md)	function to refine a tetrahedron

---

## Examples (3)

### Basic Examples (1)

First, load the package:

```wl
In[1]:= Needs["TetGenLink`"]
```

This creates an instance of a TetGen expression:

```wl
In[2]:= inst = TetGenCreate[]

Out[2]= TetGenExpression[1]
```

This sets up points and facets to use:

```wl
In[3]:=
pts = {{0., 0., 0.}, {2., 0., 0.}, {2., 0., 2.}, {0., 0., 2.}, {0., 12., 0.}, {2., 12., 0.}, {2., 12., 2.}, {0., 12., 2.}};
facets = {{{1, 2, 3, 4}}, {{5, 6, 7, 8}}, {{1, 5, 6, 2}}, {{2, 6, 7, 3}}, {{3, 7, 8, 4}}, {{4, 8, 5, 1}}};
```

This sets the points and facets in the TetGen instance:

```wl
In[4]:=
TetGenSetPoints[inst, pts];
TetGenSetFacets[inst, facets];
```

This carries out the tetrahedralization, returning a new TetGen instance:

```wl
In[5]:= inst1 = TetGenTetrahedralize[ inst, "pq1.414a0.1"]

Out[5]= TetGenExpression[2]
```

This extracts the points and faces from the tetrahedralization:

```wl
In[6]:=
elemPts = TetGenGetPoints[inst1];
elemFaces = TetGenGetFaces[inst1];
```

This plots the faces:

```wl
In[7]:= Graphics3D[GraphicsComplex[elemPts, Polygon[elemFaces]]]

Out[7]= [image]
```

Set the "r" string in place of "p" to refine an existing TetGen instance:

```wl
In[8]:= inst2 = TetGenTetrahedralize[ inst1, "rq1.414a0.01"]

Out[8]= TetGenExpression[3]
```

This extracts the points and faces from the tetrahedralization:

```wl
In[9]:=
elemPts = TetGenGetPoints[inst2];
elemFaces = TetGenGetFaces[inst2];
```

This plots the faces:

```wl
In[10]:= Graphics3D[GraphicsComplex[elemPts, Polygon[elemFaces]]]

Out[10]= [image]
```

### Options (1)

#### "TetrahedronRefinement" (1)

First, load the package:

```wl
In[1]:= Needs["TetGenLink`"]
```

This creates an instance of a TetGen expression:

```wl
In[2]:= inst = TetGenCreate[]

Out[2]= TetGenExpression[1]
```

This sets up points and facets to use:

```wl
In[3]:=
pts = {{0., 0., 0.}, {2., 0., 0.}, {2., 0., 2.}, {0., 0., 2.}, {0., 12., 0.}, {2., 12., 0.}, {2., 12., 2.}, {0., 12., 2.}};
facets = {{{1, 2, 3, 4}}, {{5, 6, 7, 8}}, {{1, 5, 6, 2}}, {{2, 6, 7, 3}}, {{3, 7, 8, 4}}, {{4, 8, 5, 1}}};
```

This sets the points and facets in the TetGen instance:

```wl
In[4]:=
TetGenSetPoints[inst, pts];
TetGenSetFacets[inst, facets];
```

This carries out the tetrahedralization, returning a new TetGen instance:

```wl
In[5]:= inst1 = TetGenTetrahedralize[ inst, "pq1.414"]

Out[5]= TetGenExpression[2]
```

This extracts the points and faces from the tetrahedralization:

```wl
In[6]:=
elemPts = TetGenGetPoints[inst1];
elemFaces = TetGenGetFaces[inst1];
```

This plots the faces:

```wl
In[7]:= Graphics3D[GraphicsComplex[elemPts, Polygon[elemFaces]]]

Out[7]= [image]
```

This sets up a compiled function that returns ``True`` if a tetrahedron should be refined and ``False`` otherwise:

```wl
In[8]:=
cf = Compile[{{coordinates, _Real, 2}, {volume, _Real, 0}}, 
	If[volume > 0.1, True, False]
	];
```

This carries out the tetrahedralization with the refinement function, returning a new TetGen instance:

```wl
In[9]:= inst2 = TetGenTetrahedralize[inst, "pq1.414", "TetrahedronRefinement" -> cf]

Out[9]= TetGenExpression[3]
```

In this case the "p" string is used as the refinement operates on the initial TetGen instance.

This extracts the points and faces from the tetrahedralization:

```wl
In[10]:=
elemPts = TetGenGetPoints[inst2];
elemFaces = TetGenGetFaces[inst2];
```

This plots the faces:

```wl
In[11]:= Graphics3D[GraphicsComplex[elemPts, Polygon[elemFaces]]]

Out[11]= [image]
```

Refine the already tetrahedralized TetGen instance:

```wl
In[12]:= inst2 = TetGenTetrahedralize[inst1, "rq1.414", "TetrahedronRefinement" -> cf]

Out[12]= TetGenExpression[4]
```

In this case the "r" string is used as the refinement operates on an already tetrahedralized TetGen instance.

This extracts the points and faces from the tetrahedralization:

```wl
In[13]:=
elemPts = TetGenGetPoints[inst2];
elemFaces = TetGenGetFaces[inst2];
```

This plots the faces:

```wl
In[14]:= Graphics3D[GraphicsComplex[elemPts, Polygon[elemFaces]]]

Out[14]= [image]
```

### Possible Issues (1)

Refinement of an already tetrahedralized TetGen instance needs to be done with the "r" string.

First, load the package:

```wl
In[1]:= Needs["TetGenLink`"]
```

Set up and tetrahedralize an initial TetGen instance:

```wl
In[2]:=
coordinates = {{0., 0., 0.}, {2., 0., 0.}, {2., 0., 2.}, {0., 0., 2.}, {0., 12., 0.}, {2., 12., 0.}, {2., 12., 2.}, {0., 12., 2.}};
facets = {{{1, 2, 3, 4}}, {{5, 6, 7, 8}}, {{1, 5, 6, 2}}, {{2, 6, 7, 3}}, {{3, 7, 8, 4}}, {{4, 8, 5, 1}}};

In[3]:=
geometry = TetGenCreate[];
TetGenSetPoints[geometry, coordinates];
TetGenSetFacets[geometry, facets];
discretization = TetGenTetrahedralize[geometry, "pq"];
```

Inspect the number of tetrahedra in the tetrahedralized instance:

```wl
In[4]:= TetGenGetElements[discretization]//Length

Out[4]= 12
```

Tetrahedralization of an already tetrahedralized TetGen instance as a piecewise linear complex (PLC) does not work. No new elements are generated:

```wl
In[5]:=
refinement = TetGenTetrahedralize[discretization, "pqa.01"];
TetGenGetElements[refinement]//Length

Out[5]= 0
```

Refinement of an already tetrahedralized TetGen instance needs to be done with the "r" string:

```wl
In[6]:=
discretization = TetGenTetrahedralize[geometry, "pq"];
refinement = TetGenTetrahedralize[discretization, "rqa.01"];

In[7]:= TetGenGetElements[refinement]//Length

Out[7]= 9414
```

## Tech Notes

* [Introduction in *TetGenLink* User Guide](https://reference.wolfram.com/language/TetGenLink/tutorial/Introduction.en.md)
* [*TetGenLink* User Guide](https://reference.wolfram.com/language/TetGenLink/tutorial/Overview.en.md)

## Related Guides

* [TetGenLink](https://reference.wolfram.com/language/TetGenLink/guide/TetGenLink.en.md)