Generate and read mesh files by using gmsh and given .geo files
Project description
The fc_oogmsh Python package make it possible to generate mesh files from .geo file by using gmsh which must be installed. It’s also possible with the ooGmsh class to read the mesh file and to store its contains in more user-friendly form. This package must be regarded as a very simple interface between gmsh files and Python. So you are free to create any objects you want from an ooGmsh object.
System |
Python |
|
---|---|---|
Ubuntu 18.04 |
2,7.15, 3.5.6, 3.6.6, 3.7.0 (python) |
from 3.0.0 to 4.0.1 |
Windows 10 |
2,7.15, 3.5.6, 3.6.6, 3.7.0 (python) |
from 3.0.0 to 4.0.1 |
MacOS High Sierra |
2.7.15, 3.5.4, 3.6.6, 3.7.0 (python) |
from 3.0.0 to 4.0.1 |
2.7.15, 3.7.0 (Miniconda) |
from 3.0.0 to 4.0.1 |
Documentation is available on fc-oogmsh dedicated web page.
Installation:
The fc_oogmsh Python package is available from the Python Package Index, so to install/upgrade simply type
pip install fc_oogmsh -U
Configuration:
One have to configure the package for using with gmsh. For the default configuration we run under Python:
import fc_oogmsh
fc_oogmsh.configure()
The function fc_oogmsh.configure() try to guess where is the gmsh binary. If this command failed or if we want to specify the gmsh binary location, one can use the gmsh option to specify the gmsh binary file with full path.
For example, under Linux:
import fc_oogmsh fc_oogmsh.configure(gmsh='/usr/local/GMSH/gmsh-3.0.4-Linux/bin/gmsh')
For example, under Windows:
import fc_oogmsh fc_oogmsh.configure(gmsh='C:\Users\toto\GMSH\gmsh-3.0.4-Windows/gmsh.exe')
For example, under MacOS:
import fc_oogmsh fc_oogmsh.configure(gmsh='/Users/toto/GMSH/3.0.4/Gmsh.app/Contents/MacOS/gmsh')
Now, it’s possible to run one of the demo functions
import fc_oogmsh
fc_oogmsh.demo02()
The output of the demo02() function under Linux is:
*********************** Running demo02 function *********************** *** Build mesh file [fc_oogmsh] Using input file: <...>/geodir/2d/condenser11.geo [fc_oogmsh] Overwritting mesh file <...>/.local/share/fc_oogmsh/meshes/condenser11-25.msh [fc_oogmsh] Running gmsh. Be patient... Use option verbose=3 to see gmsh output *** Read mesh file *** Print oGh -> ooGmsh object dim : 2 types : [1 2] orders : [1] nq : 3474 q : ndarray object[float64], size (3474, 2) toGlobal: ndarray object[int64], size (3474,) sElts : list of 2 elements *** Print oGh.sElts[0] -> Elt object d : 1, type : 1, order : 1 geo : line nme : 360 me : ndarray object[int64], size (2, 360) phys_lab: ndarray object[int64], size (360,) geo_lab : ndarray object[int64], size (360,) part_lab: list of 360 elements nb_parts: ndarray object[int64], size (360,) nTags : list of 0 elements
Examples usage:
We use the geometry file condenser11.geo given with the package to generate a 2D mesh file
meshfile=fc_oogmsh.buildmesh2d('condenser11',25,force=True)
The output of this command is:
[fc_oogmsh] Using input file: <...>/python/fc_oogmsh/geodir/2d/condenser11.geo [fc_oogmsh] Overwritting mesh file /home/toto/.local/share/fc_oogmsh/meshes/condenser11-25.msh [fc_oogmsh] Running gmsh. Be patient... Use option verbose=3 to see gmsh output
Thereafter one can read the mesh file by using the ooGmsh object constructor and print some informations
oGh=fc_oogmsh.ooGmsh(meshfile) print('*** Print oGh ->') print(oGh) print('*** Print oGh.sElts[0] ->') print(oGh.sElts[0])
The output of these commands are:
*** Print oGh -> ooGmsh object dim : 2 types : [1 2] orders : [1] nq : 3474 q : ndarray object[float64], size (3474, 2) toGlobal: ndarray object[int64], size (3474,) sElts : list of 2 elements *** Print oGh.sElts[0] -> Elt object d : 1, type : 1, order : 1 geo : line nme : 360 me : ndarray object[int64], size (2, 360) phys_lab: ndarray object[int64], size (360,) geo_lab : ndarray object[int64], size (360,) part_lab: list of 360 elements nb_parts: ndarray object[int64], size (360,) nTags : list of 0 elements
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.