pyvista / tetgen

A Python interface to the C++ TetGen library to generate tetrahedral meshes of any 3D polyhedral domains
http://tetgen.pyvista.org
Other
219 stars 32 forks source link

Inconsistent default options for tetrahedralize? #24

Open sampotter opened 3 years ago

sampotter commented 3 years ago

Doing a very basic test with tetgen, getting some funky behavior.

I have the following command-line invocation of tetgen: tetgen -q -k -C -B -N -E -F -a0.01 L.off.

Trying to straightforwardly translate this a call to tetrahedralize, I get:

import pyvista as pv

from tetgen import TetGen

grid = pv.read('box.off')
points = grid.points
faces = grid.cells_dict[5]

tet = TetGen(points, faces)
tet.tetrahedralize(docheck=True, nobound=True, maxvolume=0.01)

Passing the -q flag by setting quality=True appears to be redundant, and the -N, -E, and -F flags don't have equivalents for this wrapper library (makes sense). Likewise, -k flag doesn't make much sense. So far so good.

Now, the problem is that if I vary maxvolume, nothing happens:

In [32]: tet.tetrahedralize(docheck=True, nobound=True, maxvolume=0.01); tet.grid
(... many lines of output omitted...)
Out[32]:
UnstructuredGrid (0x11bfa77c0)
  N Cells:  18
  N Points: 53
  X Bounds: 0.000e+00, 2.000e+00
  Y Bounds: 0.000e+00, 2.000e+00
  Z Bounds: 0.000e+00, 1.000e+00
  N Arrays: 0

In [33]: tet.tetrahedralize(docheck=True, nobound=True, maxvolume=0.001); tet.grid
(... many lines of output omitted...)
Out[33]:
UnstructuredGrid (0x11bfa5ad0)
  N Cells:  18
  N Points: 53
  X Bounds: 0.000e+00, 2.000e+00
  Y Bounds: 0.000e+00, 2.000e+00
  Z Bounds: 0.000e+00, 1.000e+00
  N Arrays: 0

In [34]: tet.tetrahedralize(docheck=True, nobound=True, maxvolume=0.0001); tet.grid
(... many lines of output omitted...)
Out[34]:
UnstructuredGrid (0x11bfab8a0)
  N Cells:  18
  N Points: 53
  X Bounds: 0.000e+00, 2.000e+00
  Y Bounds: 0.000e+00, 2.000e+00
  Z Bounds: 0.000e+00, 1.000e+00
  N Arrays: 0

I'll attach the original OFF file, but this is definitely the wrong behavior. There should be many more tetrahedra as I decrease maxvolume. The mesh is just a simple L-shaped room = ([0, 2] x [0, 2] x [0, 1]) \ ([1, 2] x [1, 2] x [0, 1]) (IIRC... maybe slightly different dimensions, but this is the gist.)

L.off.zip

MichaelHillier commented 3 years ago

I had the same experience as you. In the end I had to go through a trial and error process varying the flags/variables to the tetrahedralize command.

A working example of varying the maxvolume I have is:

nodes, tetras = tgen.tetrahedralize(minratio=1.414, mindihedral=16, fixedvolume=1, maxvolume=maxvol, regionattrib=1, nobisect=False, steinerleft=-1, order=1, metric=1, meditview=1, nonodewritten=0, verbose=2)

There are a lot of issues with the flags: some are redundant and some don't work at all. Hope this helps.

sampotter commented 3 years ago

Do you have the same problem if you use tetgen from the command line? For now, I'm avoiding this wrapper library and just using the command-line interface to tetgen, since it seems to, you know... work...

I would really like to be able to use this wrapper to eliminate a few shell scripts from my usual workflow, but can't do this right now since this wrapper doesn't seem very reliable (or developed for actively, for that matter). I also don't have time to take this project on myself at the moment.

Bummer. :-(

MichaelHillier commented 3 years ago

Tetgen from the command line does not have the same problem. It's really robust code. I kept hammering away at finding work arounds within the wrapper library to get it to work to streamline my workflow. Having to run separate programs to get my end result was cumbersome. I have something working for my current needs but the process was frustrating. If I had the time to make the necessary updates to the wrapper I would, but don't have the time.

Nobregaigor commented 1 year ago

I am also experiencing similar issues. Is there any update on this topic?