Skip to content

Commit

Permalink
upgrade to tetgen1.6 (#31)
Browse files Browse the repository at this point in the history
* upgrade to tetgen1.6

* fix readme and examples

* fix example
  • Loading branch information
akaszynski authored Sep 20, 2021
1 parent 334aa9b commit 79d0ff3
Show file tree
Hide file tree
Showing 10 changed files with 12,593 additions and 8,217 deletions.
11 changes: 5 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ tetgen
.. image:: https://img.shields.io/pypi/v/tetgen.svg?logo=python&logoColor=white
:target: https://pypi.org/project/tetgen/

This Python module is an interface to Hang Si's
This Python library is an interface to Hang Si's
`TetGen <https://github.com/ufz/tetgen>`__ C++ software.
This module combines speed of C++ with the portability and ease of installation
of Python along with integration to `PyVista <https://docs.pyvista.org>`_ for
3D visualization and analysis.
See the `TetGen <https://github.com/ufz/tetgen>`__ GitHub page for more details
on the original creator.

This python module uses the C++ source from TetGen (version 1.5.1,
released on August 18, 2018) hosted at `ufz/TetGen <https://github.com/ufz/tetgen>`__.
This Python library uses the C++ source from TetGen (version 1.6.0,
released on August 31, 2020) hosted at `libigl/tetgen <https://github.com/libigl/tetgen>`__.

Brief description from
`Weierstrass Institute Software <http://wias-berlin.de/software/index.jsp?id=TetGen&lang=1>`__:
Expand Down Expand Up @@ -96,14 +96,13 @@ the mesh quality.
.. image:: https://github.com/pyvista/tetgen/raw/master/doc/images/sphere_subgrid.png

Here is the cell quality as computed according to the scaled jacobian. This example uses the ansys.mapdl.reader library to compute the quality.
Here is the cell quality as computed according to the minimum scaled jacobian.

.. code::
Compute cell quality
>>> from ansys.mapdl.reader import quality
>>> cell_qual = quality(subgrid)
>>> cell_qual = subgrid.compute_cell_quality()['CellQuality']
Plot quality
Expand Down
12 changes: 6 additions & 6 deletions examples/cow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
cow_mesh = examples.download_cow().triangulate()

cpos = [(13., 7.6, -13.85),
(0.44, -0.4, -0.37),
(-0.28, 0.9, 0.3)]
(0.44, -0.4, -0.37),
(-0.28, 0.9, 0.3)]

cpos=[(15.87144235049248, 4.879216382405231, -12.14248864876951),
(1.1623113035352375, -0.7609060338348953, 0.3192320579894903),
(-0.19477922834083672, 0.9593375398915212, 0.20428542963665386)]
cpos = [(15.87144235049248, 4.879216382405231, -12.14248864876951),
(1.1623113035352375, -0.7609060338348953, 0.3192320579894903),
(-0.19477922834083672, 0.9593375398915212, 0.20428542963665386)]

cow_mesh.plot(cpos=cpos)

Expand Down Expand Up @@ -60,7 +60,7 @@
xb = np.array(cow_grid.bounds[0:2])
step = xb.ptp() / nframe
for val in np.arange(xb[0]+step, xb[1]+step, step):
mask = np.argwhere(cow_grid.cell_centers().points[:,0] < val)
mask = np.argwhere(cow_grid.cell_centers().points[:, 0] < val)
half_cow = cow_grid.extract_cells(mask)
plotter.add_mesh(half_cow, color='w', show_edges=True, name='building')
plotter.update()
Expand Down
16 changes: 7 additions & 9 deletions examples/sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,10 @@
plotter.show()

###############################################################################
# Using ``ansys-mapdl-reader``
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Use pyansys's `legacy reader <https://github.com/pyansys/reader>`_
# library to compute cell quality. This is the minimum scaled
# Use pyvista to compute cell quality. This is the minimum scaled
# jacobian of each cell.

from ansys.mapdl.reader import quality
cell_qual = quality(subgrid)
cell_qual = subgrid.compute_cell_quality()['CellQuality']
print(f'Mean cell quality: {cell_qual.mean():.3}')

# plot quality
Expand Down Expand Up @@ -77,20 +72,23 @@
clustered.cluster(n_surf)
uniform_surf = clustered.create_mesh()

# generate interior mesh
# generate interior mesh and plot the surface of it
tet = tetgen.TetGen(uniform_surf)
tet.tetrahedralize(order=1, mindihedral=20, minratio=1.5)
uniform_grid = tet.grid
uniform_grid.plot(show_edges=True)

###############################################################################
# Plot the cross section of the tetrahedralization

cell_center = uniform_grid.cell_centers().points

# extract cells below the 0 xy plane
mask = cell_center[:, 2] < 0
cell_ind = mask.nonzero()[0]
subgrid = uniform_grid.extract_cells(cell_ind)

cell_qual = quality(subgrid)
cell_qual = subgrid.compute_cell_quality()['CellQuality']
print(f'Mean cell quality: {cell_qual.mean():.3}')

# plot quality
Expand Down
20 changes: 13 additions & 7 deletions examples/super_toroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@
Super Toroid
~~~~~~~~~~~~
Tetrahedralize a super toroid surface
Tetrahedralize a super toroid surface.
"""
# sphinx_gallery_thumbnail_number = 2
import pyvista as pv
import tetgen
import numpy as np


###############################################################################
toroid = pv.ParametricSuperToroid()
# Create and tetrahedralize a super torid.
#
# We merge the points here to make sure that the surface is manifold.

toroid = pv.ParametricSuperToroid(u_res=50, v_res=50, w_res=50).clean(tolerance=1E-9)
tet = tetgen.TetGen(toroid)
tet.tetrahedralize(order=1, mindihedral=20, minratio=1.5)
grid = tet.grid
grid.plot()


###############################################################################
# Plot the tesselated mesh.

# get cell centroids
cells = grid.cells.reshape(-1, 5)[:, 1:]
Expand All @@ -37,10 +44,9 @@
plotter.show()

###############################################################################
# Cell quality using pyansys
from ansys.mapdl.reader import quality
cell_qual = quality(subgrid)
# Show the cell quality

# plot quality
subgrid.plot(scalars=cell_qual, stitle='quality', cmap='bwr', clim=[0,1],
cell_qual = subgrid.compute_cell_quality()['CellQuality']
subgrid.plot(scalars=cell_qual, scalar_bar_args={'title': 'Cell Quality'},
cmap='bwr', clim=[0, 1],
flip_scalars=True, show_edges=True)
1 change: 0 additions & 1 deletion requirements_docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ sphinx_gallery
sphinx-notfound-page>=0.3.0
sphinx-copybutton
pymeshfix
ansys-mapdl-reader
pyacvd
Loading

0 comments on commit 79d0ff3

Please sign in to comment.