Dear all, I'm used to using gmsh through the python API, on Ubuntu 18.04. With the version 4.4 of gmsh , I am faced with an unwanted behaviour when I try to import both gmsh and matplotlib into the same script.
Firstly, if matplotlib is imported before gmsh , a Segmentation fault error occurs. Steps to reproduce this : * Create a new virtual environment : * Activate this environment : * Install wheels : pip3 install wheels * Install gmsh python API using the gmsh -sdk package on pypi.org : pip3 install gmsh -sdk * Install the matplotlib package : pip3 install matplotlib * Add the line "import matplotlib" before "import gmsh " in the demo script t1.py * Run this demo script in the virtual environment : python3 t1.py This results in : Segmentation fault (core dumped) If matplotlib is not imported or is imported after gmsh this segmentation fault doesn't occur. In addition, if include-system-site-packages is set to true in the configuration file of the virtual environment (pyvenv.cfg) another problem appears. I need this setting because I would like to use the FEniCS finite element code and it cannot be installed inside a virtual environment. Even if matplotlib is imported after gmsh , the resulting mesh file is unreadable because the decimal separator is a comma. Has anyone faced a similar issue ? Best regards, Baptiste Durand --- Baptiste Durand Doctorant – Laboratoire Navier baptiste.dur...@enpc.fr – 01 64 15 37 21 ( 06 58 88 05 41 ) – linkedin.com/in/baptistedurand
# This file reimplements gmsh/tutorial/t1.geo in Python. # For all the elementary explanations about the general philosphy of entities in # Gmsh, see the comments in the .geo file. Comments here focus on the specifics # of the Python API. # The API is entirely defined in the gmsh module # import matplotlib.pyplot as plt # ! ERROR : Segmentation fault. import gmsh # import matplotlib.pyplot as plt # Before using any functions in the Python API, Gmsh must be initialized. gmsh.initialize() # By default Gmsh will not print out any messages: in order to output messages # on the terminal, just set the standard Gmsh option "General.Terminal" (same # format and meaning as in .geo files): gmsh.option.setNumber("General.Terminal", 1) # Next we add a new model named "t1" (if gmsh.model.add() is not called a new # unnamed model will be created on the fly, if necessary): gmsh.model.add("t1") # The Python API provides direct access to the internal CAD kernels. The # built-in CAD kernel was used in t1.geo: the corresponding API functions have # the "gmsh.model.geo" prefix. To create geometrical points with the built-in # CAD kernel, one thus uses gmsh.model.geo.addPoint(): # # - the first 3 arguments are the point coordinates (x, y, z) # # - the next (optional) argument is the target mesh size close to the point # # - the last (optional) argument is the point tag lc = 1e-2 gmsh.model.geo.addPoint(0, 0, 0, lc, 1) gmsh.model.geo.addPoint(.1, 0, 0, lc, 2) gmsh.model.geo.addPoint(.1, .3, 0, lc, 3) gmsh.model.geo.addPoint(0, .3, 0, lc, 4) # The API to create lines with the built-in kernel follows the same # conventions: the first 2 arguments are point tags, the last (optional one) # is the line tag. gmsh.model.geo.addLine(1, 2, 1) gmsh.model.geo.addLine(3, 2, 2) gmsh.model.geo.addLine(3, 4, 3) gmsh.model.geo.addLine(4, 1, 4) # The philosophy to construct curve loops and surfaces is similar: the first # argument is now a vector of integers. gmsh.model.geo.addCurveLoop([4, 1, -2, 3], 1) gmsh.model.geo.addPlaneSurface([1], 1) # Physical groups are defined by providing the dimension of the group (0 for # physical points, 1 for physical curves, 2 for physical surfaces and 3 for # phsyical volumes) followed by a vector of entity tags. The last (optional) # argument is the tag of the new group to create. gmsh.model.addPhysicalGroup(0, [1, 2], 1) gmsh.model.addPhysicalGroup(1, [1, 2], 2) gmsh.model.addPhysicalGroup(2, [1], 6) # Physical names are also defined by providing the dimension and tag of the # entity. gmsh.model.setPhysicalName(2, 6, "My surface") # Before it can be meshed, the internal CAD representation must be synchronized # with the Gmsh model, which will create the relevant Gmsh data structures. This # is achieved by the gmsh.model.geo.synchronize() API call for the built-in CAD # kernel. Synchronizations can be called at any time, but they involve a non # trivial amount of processing; so while you could synchronize the internal CAD # data after every CAD command, it is usually better to minimize the number of # synchronization points. gmsh.model.geo.synchronize() # We can then generate a 2D mesh... gmsh.model.mesh.generate(2) # ... and save it to disk gmsh.write("t1_msh2.msh") gmsh.option.setNumber("Mesh.MshFileVersion",4.1) gmsh.write("t1_msh4.msh") # Remember that by default, if physical groups are defined, Gmsh will export in # the output mesh file only those elements that belong to at least one physical # group. To force Gmsh to save all elements, you can use # # gmsh.option.setNumber("Mesh.SaveAll", 1) # This should be called at the end: gmsh.finalize()
_______________________________________________ gmsh mailing list gmsh@onelab.info http://onelab.info/mailman/listinfo/gmsh