← Back to team overview

dolfin team mailing list archive

Re: TriTetMesh 0.1

 

On Friday 14 March 2008 01:37:37 Bartosz Sawicki wrote:
> > On Thursday 13 March 2008 21:26:38 Anders Logg wrote:
> >> On Thu, Feb 28, 2008 at 03:08:25PM +0100, Johan Hake wrote:
> >>> Dear all!
> >>>
> >>> I hearby present version 0.1 of TriTetMesh. It is a c++/python wrapper
> >>> of the high quality mesh generators: Tetgen and Triangle.
> >>>
> >>> The output format is dolfin mesh, and dolfin meshfunctions for markers.
> >>> It is also possible to output the native Tetgen and Triangle formats.
> >>>
> >>> For now the code resides in a tarball:
> >>>
> >>> <http://folk.uio.no/hake/tritetmesh/tritetmesh.tar.gz>
> >>>
> >>> I have not checked if it builds on mac, but it should build on
> >>> Linux/Ubuntu. You will then need swig, python, python-dev,
> >>> python-numpy, python-numpy-dev and scons. (I think this is all...)
> >>>
> >>> The documentation is sparse but have a look at the provided demos. It
> >>> can be usefull to look at the docstrings for the python functions too.
> >>> As TriTetMesh is a more or less complete wrapper of Triangle and Tetgen
> >>> it is instructive to have a look at their webpages for clues.
> >>>
> >>> Tetgen <http://tetgen.berlios.de>
> >>> Triangle <http://www.cs.cmu.edu/~quake/triangle.html>
> >>>
> >>> Please have a try!
> >>>
> >>> Send me an email if you encounter problems. Such discussions should
> >>> probably stay of this list ;)
> >>>
> >>> Cheers
> >>>
> >>> Johan
> >>
> >> Looks very nice!
> >>
> >> I've also looked a bit a Netgen as an alternative to Tetgen and it
> >> seems to have a simple interface that might be simpler to wrap than
> >> Tetgen. Netgen can also save directly to DOLFIN XML (patch from
> >> Kent-Andre that is in Netgen CVS).
> >
> > I have had a brief look at. It looks like it is much more complex than
> > tetgen and triangle. Triangle is two files, and tetgen three and the
> > interface is well documented.
> >
> > Netgen is at least... well, many files. I think it will take some digging
> > to get hte hang of the programing interface to the library.
> >
> > As I understand it, netgen can only save dolfin mesh, not MeshFunction
> > with markers, right?
>
> Netgen is much more advanced mesh generator, so it is not suprising that
>   the code is more complicated. I've use Netgen, Triangle and Tetgen for
> years, and my experience showed that Netgen is the leader.
>
> Triangle and Tetgen are also powerful, but their main advantage is
> simple API. You can easily embed it in other applications. Just like it
> is in TriTetMesh.
>
> I'm sure that Netgen is supporting subdomains markers. Even if current
> export into DOLFIN XML this informations is lost, this can be improved.
>
> >> Netgen uses input files like these:
> >>
> >> # a cube
> >> solid cube = plane (0, 0, 0; 0, 0, -1)
> >>          and plane (0, 0, 0; 0, -1, 0)
> >>          and plane (0, 0, 0; -1, 0, 0)
> >>          and plane (1, 1, 1; 0, 0, 1)
> >>          and plane (1, 1, 1; 0, 1, 0)
> >>          and plane (1, 1, 1; 1, 0, 0);
> >>
> >> # two shperes
> >> solid sph1 = sphere (0.5, 0.5, 0.5; 0.58);
> >> solid sph2 = sphere (0.5, 0.5, 0.5; 0.75);
> >>
> >> # cut cube with inner and outer sphere
> >> solid main = cube and sph2 and not sph1;
> >>
> >> This would be *very* easy to wrap in DOLFIN so one could do things
> >> like
> >>
> >>   s1 = Sphere(...)
> >>   s2 = Sphere(...)
> >>   c  = Cube(...)
> >>
> >>   mesh = Mesh(c + s2 - s1)
> >
> > It looks very nice. It could be cool to get it integrated in to a python
> > environment. But it wont be done over night...
> >
> >> Perhaps this could be done also with Tetgen/Triangle?
> >
> > Not straight of. Tetgen uses what they call piecwise linear complexes
> > (PLC), to define some surface geometry. A PLC can be any polygon in a
> > plane, so this rules out a strict circular geometry. But it quite easy to
> > defin circular geometries that is defined by these PLCs in python.
> >
> > The Eularian operations, i.e., union, intersection and complement need
> > it's own geometrical logic, which is not supported in tetgen or triangle.
> > One could hypotesize that this could be added as a layer on top of
> > triangle or tetgen.
>
> There are two main methods to describe geometry of the model - boundary
> representation (BR) and constructive solid geometry (CSG).
>
> The first use definition of boundary - described by some analitical
> functions (planes, splines, nurbs) or using set of triangles
> (3d)/edges(2d) (PLC, STL).
> http://en.wikipedia.org/wiki/Boundary_representation
>
> The second method is called Constructive Solid Geometry. Where
> primitives such as cubes, spheres are logically combined into more
> complicated objects.
> http://en.wikipedia.org/wiki/Constructive_solid_geometry
>
> The CSG is very useful for prototyping. You can quickly build geometry,
> smoothly control mesh quality, and solve some PDE.
> However, in real problems, more often BR are used. The CAD software
> generates STL files, which are just a set of triangles on boudary. If
> you use 3D scanners they also produce BR.
>
> Netgen can use both of this methods, CSG and BR. Tetgen/Triangle works
> only with BR. Thats the big difference.

Thanks for the nice overview!

> In my opinion Netgen would be the best canditate for mesh generator for
> Fenics, but ... it has poor API :(. Netgen was design as a GUI
> application and the most of its features needs to be clicked.

I see that one large part of Netgen is gui related, but what I and probably 
Anders had in mind was not to wrap this part, but rather the interface to the 
CSG file parser, and potentially also to the BR parser. You could then 
hopefully just skip the gui related commands.

Instead of writing a file with e.g. the CSG specifications you have a script 
where you define the different geometries like Anders did in his example, and 
then call an appropriate generate function.

The most straight forward way to do this would probably be to write a thin 
python application that defines some sort of interface to netgen, a la what 
Anders wrote above, and then let e.g. his call to 

Mesh(c + s2 - s1)

write the information to a .csg file, piping this to netgen and we have a 
mesh. That depends on Netgen having a commandline interface. Is this the 
case?

I could have done this with both tetgen and triangle too, but I used it as an 
excercise to learn more of wrapping a c/c++ library and to get more into 
swig :)


Johan


Follow ups

References