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.

Wednesday, August 15, 2012

Gmsh launching


I would like to say several words about Gmsh launching. If you want to start Gmsh without any input arguments, for example, by double-clicking on its icon (in systems with desktop environment), or typing only

$ path_to_gmsh_bin_directory/gmsh

in the command line (using Terminal in Unix-like systems, or, for example, Total Commander in Windows systems), in all these cases, you might face some problems. Being launched without input parameters, Gmsh creates a default file "untitled.geo", and uses it as an input argument. For Windows7 this file is created here

C:\Users\_UserName_\AppData\Local\Temp\

regardless the place where you launched Gmsh.
Now we simulate the situation when someone started Gmsh without arguments and made some actions using menu window. For example, we add 2 new points (Geometry->Elementary entities->Add->New->Point). When we'll close Gmsh, and launch it again (without input parameters), we'll see that all changes are saved in the default file (i.e. we'll see our 2 points). Now imagine that someone made actions, that led to Gmsh's crush. It's difficult to invent something of this kind right now, so we'll just write the following string to the default file.

Exit;

After that, we close Gmsh, and start it again in the same way as before. What will we see? Gmsh appears and closes immediately. I think the cause is clear - the Exit command forces Gmsh to shut down. This situation shows that if the default file contains something making Gmsh's crush, you, probably, will not know why this crush happens, because there is no error message from Gmsh or something else. The reason is just bad default file.
So the remedy is obvious:
I. To find the default geometry file (look for "untitled.geo") and
1. delete it;
2. change it to cancel all actions that lead to such bad result.
II. To start Gmsh with new geometry file as an argument

gmsh newfile.geo

The second solution will not return the geometry you previously created, but Gmsh will start anyway.

If you launch Gmsh without input parameters under Unix-like system, the behaviour stays the same. But in this case the default file "untitled.geo" is created in the directory where you start Gmsh. So to find this file is a little bit easier.

Be careful launching Gmsh without arguments!