+++ title="GMSH" linktitle="GMSH" summary="" type="book" icon="" icon_pack="" date = 2018-09-09T00:00:00
draft = false # Is this a draft? true/false toc = true # Show table of contents? true/false
math = true weight = 1 diagram = false #markup = "mmark"
edit_page = {repo_url = "https://github.com/Bertbk/gmsh", repo_branch = "master", submodule_dir="tutorial/gmsh/"}
[git] icon = "github" repo = "https://github.com/Bertbk/course_gmsh" submodule_dir = "tutorial/gmsh/"
+++
GMSH is an open-source software for 2D/3D mesh and data visualization, developped in Belgium by (mainly) C. Geuzaine and J-F. Remacle.
{{% callout warning %}}
Linux user: please do not install GMSH via package manager (apt-get
, ...): version is outdated.
{{% /callout %}}
Source code are available on Onelab's Gitlab and GMSH can be compiled by hand.
The easiest way to install GMSH is to simply download the binary files for Linux/Windows/Mac, either Stable or Latest automatic Gmsh snapshot (recommended (by me)). The binary file gmsh
is located in bin/gmsh
in the compressed downloaded file. You can launch it directly
cd folder/of/gmsh/bin
./gmsh
Apart from (maybe) the color theme, a new window should have been launched and looks like this
{{< figure src="img/gmsh_splash.png" title="GMSH splash screen. GMSH's version is displayed at the bottom of the window (here 4.5.0)" numbered="true" >}}
{{% callout warning %}}
Never copy a binary file in usr/bin
. This folder is reserved to your package manager.
{{% /callout %}}
For Linux (and Mac) users, it might be convenient to be able to launch GMSH in a terminal and from whichever folder. To do that, simply add to the $PATH
environment variable, the path to gmsh
's folder. This can be automated by adding a line in $HOME/.bash_profile
(or $HOME/.profile
or ...)
export PATH=$PATH:/path/to/gmsh
You must rerun your shell to get the changes applied (or usr source
command).
A question that quickly arises is:
Where and how do I store every binary and lib files without making my computer a full mess?
Good question.
There are multiple answers and here you'll find one which you may like (or not). I like to have a $HOME/install
folder (local to my account, thus) which mimic the /usr/
folder, i.e. containing bin
, lib
, share
and include
folders:
$HOME/install
└── bin/ # binary files
└── gmsh #some binaries (gmsh, ...)
└── lib/ # library files
└── gmsh.py
└── libgmsh.so
└── share/ # dynamic libraries
└── include/ # header files
I then set the $PATH
environment variable to
export PATH=$PATH:$HOME/install/bin
Every time I add a new file to $HOME/install/bin
it becomes accessible, without having to change the environment variable.
{{% callout note %}} Actually I have three main folders
$HOME/src
: Source codes$HOME/build
: Where the source codes are compiled$HOME/install
: Installed software that I either compiled or downloaded
This way, source code, build process and installed file are well separated. {{% /callout %}}
{{% callout note %}} Part of the tutorial is written in GMSH's language but using the API instead is direct and highly recommended. {{% /callout %}}
GMSH provides a powerful API compatible with Python, Julia or C++
. The GMSH SDK1 is available online and easy to install.
For example on Unix system and for Python, a way to install it locally (without being root) and by hand ("à la hussarde") is to add this in this in the header of your Python file
import sys
sys.path.insert(0, "/path/to/sdk/lib")
import gmsh
A better method is to use the $PYTHONPATH
environment variable and set it to the SDK's folder. Following the previous paragraph, create a folder install
at your $HOME
folder and copy the content of lib
folder of the SDK's zip file inside $HOME/install/lib
. You would then have this stucture
$HOME/install
└── lib/ # library files
└── gmsh.py
└── libgmsh.so
You have now to add to Python the path:
export PYTHONPATH=$HOME/install/lib
A relaunch of the terminal might be necessary to take these changes into account. In your Python code, you juste have to import gmsh
without any other condition
import gmsh
{{% callout warning %}}
The binary file bin/gmsh
contained in the SDK's zip file might not work as a standalone binary file. Please download and use the binary provided by GMSH's website for that use.
{{% /callout %}}
Footnotes
-
Software Development Toolkit ↩