# [Gmsh] Problem with physical groups to label surface in GMSH

Christophe Geuzaine cgeuzaine at uliege.be
Mon Jun 22 18:13:39 CEST 2020

```
> On 21 Jun 2020, at 06:24, Quang Ha <haqthinh at gmail.com> wrote:
>
> Hi all,
>
> I'm having some troubles setting the ID for the physical group of the boundary and then extract them later in Python. Here's my main.geo file:
>
> // Gmsh project created on Sat Jun 20 11:28:19 2020
> Mesh.Algorithm = 6;
> Mesh.CharacteristicLengthMin = 0.4;
> Mesh.CharacteristicLengthMax = 0.4;
>
> //+
> Box(1) = {-2, -2, -2, 4, 4, 4};
> // Surface for Box
> box_bnd[] = Boundary{Volume{1};};
> Physical Surface("boundary", 1) = box_bnd[];
> //+
> Sphere(3) = {0, 0, 0, 1.0, -Pi/2, Pi/2, 2*Pi};
> sphere_bnd[] = Boundary{Volume{3};};
> Physical Surface("boundary", 1) += sphere_bnd[];
> // Cut
> BooleanDifference(5) = {Volume{1}; Delete;}{Volume{3}; Delete;};
> Physical Volume("internal", 2) = {5};
>
> Having run this inside Gmsh and generate main.msh, I try to explore this mesh inside Python and extract out the coordinates on the boundary for checking.

The boolean operation with OpenCASCADE will change the surfaces, so your Physical Surface definition becomes invalid (and should be done afterwards).

Improving the surface tag persistence is on our TODO list, but OpenCASCADE does not make this easy (or more probably we don't use OpenCASCADE intelligently enough ;-).

Christophe

> Here is my extract.py:
>
> import matplotlib.pyplot as plt
> import gmsh
>
> # Mesh characteristic length
> char_length = 0.4
> # Some reference dimension
> max_coord, min_coord = -2.0, 2.0
> a = 1.0
> # Tolerance allowed in the mesh point
> tol = 1e-12
>
> gmsh.initialize()
> gmsh.option.setNumber("General.Terminal", 1)
> gmsh.open("main.msh".format(char_length))
>
> # all mesh node coordinates
> nodeTags, nodeCoords, _ = gmsh.model.mesh.getNodes()
>
> # just the boundary coordinates
> bTags, bCoords, = gmsh.model.mesh.getNodesForPhysicalGroup(3, 1)
>
> gmsh.finalize()
>
> which seems to give me empty arrays of bTags and bCoords, i.e.:
>
> In [7]: run extract.py
> Warning : Gmsh has aleady been initialized
> Info    : 33 entities
> Info    : 1260 nodes
> Info    : 6524 elements
> Info    : Done reading 'main.msh'
> /usr/local/lib/python3.7/site-packages/numpy/ctypeslib.py:523: RuntimeWarning: A builtin ctypes object gave a PEP3118 format string that does not match its itemsize, so a best-guess will be made of the data type. Newer versions of python may behave correctly.
>   return array(obj, copy=False)
>
> In [8]: bTags
> Out[8]: array([], dtype=uint64)
>
> In [9]: bCoords
> Out[9]: array([], dtype=float64)
>
> Any suggestions on where I have made a mistake?
>
> Thanks,
> Quang
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh

—
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science
http://www.montefiore.ulg.ac.be/~geuzaine

```