pyvista / tetgen

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

Ansys CDB output #48

Closed Telos4 closed 1 year ago

Telos4 commented 1 year ago

The documentation of the write() method claims that meshes can be output in Ansys .cdb format:

write(filename, binary=False) method of tetgen.pytetgen.TetGen instance
    Writes an unstructured grid to disk.

    Parameters
    ----------
    filename : str
        Filename of grid to be written.  The file extension will
        select the type of writer to use.

        - ``".vtk"`` will use the vtk legacy writer
        - ``".vtu"`` will select the VTK XML writer
        - ``".cdb"`` will write an ANSYS APDL archive file

    binary : bool, optional
        Writes as a binary file by default.  Set to False to write
        ASCII.  Ignored when output is a cdb.

    Examples
    --------
    >>> tgen.write('grid.vtk', binary=True)

    Notes
    -----
    Binary files write much faster than ASCII, but binary files
    written on one system may not be readable on other systems.
    Binary can be used only with the legacy writer.

However, I think this is not actually possible with the most recent version of tetgen==0.6.2 and pyvista==0.38.3. Am I missing something?

Here's a short demo:

tet = tetgen.TetGen(pv.Sphere())
tet.tetrahedralize(order=1, mindihedral=20, minratio=1.5)
tet.write('sphere.cdb')

This gives the error:

ValueError: Invalid file extension for this data type. Must be one of: dict_keys(['.vtu', '.vtk'])

I suggest the documentation should be fixed or (preferably) the .cdb output should be implemented in pyvista.

banesullivan commented 1 year ago

cc @akaszynski?

akaszynski commented 1 year ago

Sorry @Telos4 for the delay.

I need to fix the docs here, because it should read that you can output the result to pyansys/pymapdl-reader in the Archive class in save_as_archive.

Leaving this open as an issue until the docs are resolved.