Thursday, August 30, 2012

Gmsh tasting


Gmsh is a mesh generator, but it permits to create geometry too. However there are some limitations for that. For example, you cannot create shapes that intersect each other. This feature rises from the way that Gmsh uses to define geometry. The process of geometry creation is sequential. At first you should define points, then lines, and so on. The full list of entities, that you should determine to create 3D model is here:
  1. points
  2. lines
  3. line loops
  4. surfaces
  5. surface loops
  6. volumes
Therefore to define intersecting shapes you should calculate points of intersecting surfaces, define lines, etc. So the process is difficult. That's why for complex models you need to use any third-party CAD software. For example,
To bind the model from these packages with Gmsh, you need to export geometry in one of OpenCascade formats (BRep, STEP or IGES, but note that IGES format is not recommended), or any other compatible to Gmsh format (STL, etc). Then you can load such model into Gmsh just typing in command line

$ gmsh model.brep

Note, that in some cases you'll need to turn off two options to see the model. They are "Remove small edges" and "Remove small faces" on Options -> Geometry -> General of GUI


Or write in geometry file (model.geo):

Merge "model.brep";
Geometry.OCCFixSmallEdges=0; // Remove small edges from GUI
Geometry.OCCFixSmallFaces=0; // Remove small faces from GUI
Mesh.CharacteristicLengthFactor = 0.5; // any actions with model

In this case Gmsh is launched:

$ gmsh model.geo

There is one additional feature: to load OpenCascade models, Gmsh should be built with OCCT support. And a little hint: if any of presented packages doesn't export a model in OCCT format, you can save it in some CAD format and then use CAD Exchanger for converting.

7 comments:

  1. Hi Mikhail,
    Thanks for the useful post.
    Do you have any comments or feedback regarding the CAD programs you've listed? Based on your experience, how compatible are they with Gmsh?

    ReplyDelete
  2. Hi Omid,
    Thanks for the question.
    Though my experience of using some of those programs is not very long, I'll try to answer on your questions.
    Being built with OCCT support Gmsh can read BRep (native OCCT format) and STEP files. I can say that for those relatively complex models that I used, Gmsh worked perfectly well. So the question of compatibility between programs listed above and Gmsh is the question of ability of these programs exporting models in BRep format. If the program is constructed on OCC library like Salome or FreeCAD - you can be sure that your models can be exported in any of OCCT formats and then used in Gmsh. I don't know anything and have never used other programs from the list, but even if they aren't based on OCCT, you can use CAD Exchanger to convert their native format into BRep (or STEP). I'm not sure about saving all mesh features in this case (for example, material IDs, or physical domains) though.
    My feedback regarding OCCT, Salome and FreeCAD... I can say nothing but they are great. OCC is a huge library. Salome seems to me to be even bigger than OCC. It has meshing and post-processing abilities besides its main target - to be an interface for OCCT. Though reading FreeCAD forum I realized, that Salome not fully depends on OCC and has its own algorithms for geometry definition. So maybe you even don't need to use Gmsh at all - Salome also can build simplicial grids, and have stronger CAD capabilities. FreeCAD is also based on OCCT, but it's much smaller than Salome, and that can be advantage. Salome is not completely supported on Windows (though it can be used there), FreeCAD is supported.

    ReplyDelete
  3. Thank you Mikhail for your detailed response.
    I intend to use a CAD program for Linux since I don't really use Windows. I've used the trial version of BricsCAD. I really liked it, in particular, since its shortcuts and philosophy were very similar to AutoCAD. However, its main issue currently is that it doesn't support any of the BRep, STEP or IGES file types. According to their support team, though, this will be addressed in their new version that they're currently working on.

    I have also been able to successfully import iges files exported from Rhino.

    I also attempted at using OpenCascade but wasn't able to build the code from source. I will give the other programs a try.

    By the way, what do you exactly mean by OCCT?

    ReplyDelete
  4. Thanks for sharing your experience.
    By the way, Gmsh's FAQ says about IGES files the following:

    "IGES files do not contain the topology of the model, and tolerance problems can thus appear when the OpenCASCADE importer cannot identify two (close) curves as actually being identical." (more information here)

    So, be careful using IGES files.

    What about OCCT: OCCT stands for OpenCasCade Technology. Actually we should use this term when we talk about the library. This is a quotation from OpenCascade history:

    "In 2004 Open CASCADE software was renamed to Open CASCADE Technology to clearly distinguish the name of the OPEN CASCADE company from the software platform it develops."

    But usually no one cares about that distinguishing and uses OpenCascade term thinknig about the software. I also use both abbreviations OCCT and OCC, and don't differentiate them :-)

    ReplyDelete
  5. Thanks Mikhail for the clarification. I'm doing some experimentation with some of the above CAD programs and Gmsh. I'll keep you posted about my findings.

    ReplyDelete
  6. Hi Mikhail,
    I experimented with some of the CAD programs available for Linux. I liked FreeCAD for its simple ease of use, the possibility to open dxf files and exporting to BRep or iges formats, which I need for Gmsh. However, the drawing mechanisms in FreeCAD differ from typical CAD programs, which makes drawing something from scratch a bit limiting. Almost the same holds for Salome.

    I've also played around a bit with DraftSight (http://www.3ds.com/products/draftsight/free-cad-software/) and I liked it a lot. I don't fully understand their license -- it appears that they're only free for personal use. Anyhow, their interface resembles more closely the conventional CAD software (AutoCAD, Rhino, etc.). I found the graphical interface a bit slow and choppy. Moreover, there is no direct export to brep, etc.. So essentially you would have to export from Draftsight into dxf and use FreeCAD.

    ReplyDelete
    Replies
    1. Thanks a lot for the information, it's very useful!

      Delete