# How to extract and use physical labels from GMSH surfaces on FEniCS (2D mesh)

**URL:** <https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269>\
**Category:** mesh\
**Created:** [January 22, 2020, 1:01pm UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269 "2020-01-22T13:01:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![AMM](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AMM](https://fenicsproject.discourse.group/u/AMM)\
**Post date:** [January 22, 2020, 1:01pm UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/1 "2020-01-22T13:01:53Z")

</div>

Hi,

I would like to know how to extract physical surface label for a 2D mesh define on Gmsh.  
For example, a square domain composed of 4 sub domains (with physical tag 1,2,3 and 4) : I would like to be able to integrate on each of these subdomain (dx(1), dx(2), dx(3) and dx(4)).

I naively tried (without success) to initialize my subdomain as I will do with the borders and the measure ds

```
mesh = Mesh()

with XDMFFile("/home/amoreno3/meshTESTplusieursDomaine.xdmf") as infile:
    infile.read(mesh)
File("Dolfin_circle_mesh.pvd").write(mesh)
mvc = MeshValueCollection("size_t", mesh, 1)

with XDMFFile("/home/amoreno3/mfTESTplusieursDomaine.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
File("Dolfin_circle_facets.pvd").write(mf)

domains = MeshFunction("size_t", mesh, mesh.topology().dim())
dx = Measure("dx")(subdomain_data=domains)
dx1 = Measure("dx", domain=mesh, subdomain_data=mvc, subdomain_id=1)
dx2 = Measure("dx", domain=mesh, subdomain_data=mvc, subdomain_id=2)
dx3 = Measure("dx", domain=mesh, subdomain_data=mvc, subdomain_id=3)
dx4 = Measure("dx", domain=mesh, subdomain_data=mvc, subdomain_id=4)

```

Thank you

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [January 22, 2020, 2:07pm UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/2 "2020-01-22T14:07:23Z")

</div>

Dear @AMM,

the subdomain data should be the mesh function `mf` and not the mesh value collection `mvc`.

Could you please supply the output of

```auto
print(assemble(Constant(1)*dx)))
print(assemble(Constant(1)*dx1)))
print(assemble(Constant(1)*dx2)))
print(assemble(Constant(1)*dx3)))
print(assemble(Constant(1)*dx4)))

```

Additionally, you could the following instead of creating new measures for each data:

```auto
dx = Measure("dx",subdomain_data=mf)
print(assemble(Constant(1)*dx))
print(assemble(Constant(1)*dx(1)))
print(assemble(Constant(1)*dx(2)))
print(assemble(Constant(1)*dx(3)))
print(assemble(Constant(1)*dx(4)))

```

---

<div class="post-metadata">

**Author:** ![AMM](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AMM](https://fenicsproject.discourse.group/u/AMM)\
**Post date:** [January 23, 2020, 2:33pm UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/3 "2020-01-23T14:33:30Z")

</div>

Hi Dokken,

Thank you for your answer.  
I tried what you asked me to do but the two things don’t work.  
For the first print, it tells me

```auto
> UFLException: This integral is missing an integration domain.

```

For the second print, using an integral (for example dx(4)) of the form assemble(Constant(1)\*dx(4, domain=mesh, subdomain\_data=mf)) to avoid the above error message, I get 0.0 as result.

One could think of error on the definition of my geometry on gmsh but I checked and it does not seem that it is the case. (the geo file is pretty simple as you can see below)

```auto
// Gmsh project created on Wed Jan 22 11:30:14 2020
SetFactory("OpenCASCADE");
//+
Point(1) = {0, 0, 0, 1.0};
//+
Point(2) = {1, 0, 0, 1.0};
Point(3) = {1, 1, 0, 1.0};
Point(4) = {0, 1, 0, 1.0};
//+
Point(5) = {0.5, 1, 0, 1.0};
//+
Point(6) = {0, 0.5, 0, 1.0};
//+
Point(7) = {1, 0.5, 0, 1.0};
//+
Point(8) = {0.5, -0, 0, 1.0};

//+
Point(9) = {0.5, 0.5, 0, 1.0};
//+

//+
Line(1) = {4, 6};
//+
Line(2) = {6, 1};
//+
Line(3) = {1, 8};
//+
Line(4) = {8, 2};
//+
Line(5) = {2, 7};
//+
Line(6) = {7, 3};
//+
Line(7) = {3, 5};
//+
Line(8) = {5, 4};
//+
Line(9) = {5, 9};
//+
Line(10) = {9, 6};
//+
Line(11) = {9, 8};
//+
Line(12) = {9, 7};
//+
Curve Loop(1) = {10, 2, 3, -11};
//+
Plane Surface(1) = {1};
//+
Curve Loop(2) = {12, -5, -4, -11};
//+
Plane Surface(2) = {2};
//+
Curve Loop(3) = {7, 9, 12, 6};
//+
Plane Surface(3) = {3};
//+
Curve Loop(4) = {8, 1, -10, -9};
//+
Plane Surface(4) = {4};
//+
Physical Curve("inlet", 10000) = {2, 1};
//+
Physical Curve("outlet", 10001) = {6, 5};
//+
Physical Curve("wall", 10002) = {7, 8, 3, 4};
//+
Physical Surface("surface1", 1) = {1};
//+
Physical Surface("surface2", 2) = {2};
//+
Physical Surface("surface3", 3) = {4};
//+
Physical Surface("surface4", 4) = {3};

```

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [January 23, 2020, 2:53pm UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/4 "2020-01-23T14:53:36Z")

</div>

> [@AMM](#):
>
> // Gmsh project created on Wed Jan 22 11:30:14 2020 SetFactory(“OpenCASCADE”); //+ Point(1) = {0, 0, 0, 1.0}; //+ Point(2) = {1, 0, 0, 1.0}; Point(3) = {1, 1, 0, 1.0}; Point(4) = {0, 1, 0, 1.0}; //+ Point(5) = {0.5, 1, 0, 1.0}; //+ Point(6) = {0, 0.5, 0, 1.0}; //+ Point(7) = {1, 0.5, 0,

If you change `dx` to `dx(domain=mesh)` the first problem is solved.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [January 23, 2020, 2:58pm UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/5 "2020-01-23T14:58:20Z")

</div>

@AMM  
Secondly, writing your mesh to xdmf as described in the next snippets works for me:

```auto
import meshio
msh = meshio.read("amm.msh")

meshio.write("mesh.xdmf", meshio.Mesh(points=msh.points, cells={"triangle": msh.cells["triangle"]}))
meshio.write("mf.xdmf", meshio.Mesh(points=msh.points, cells={"triangle": msh.cells["triangle"]},
                                    cell_data={"triangle": {"name_to_read": msh.cell_data["triangle"]["gmsh:physical"]}}))

from dolfin import *
mesh = Mesh()
with XDMFFile("mesh.xdmf") as infile:
    infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 2)
with XDMFFile("mf.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)

domains = MeshFunction("size_t", mesh, mesh.topology().dim())
dx = Measure("dx",domain=mesh, subdomain_data=mf)
print(assemble(Constant(1)*dx))
print(assemble(Constant(1)*dx(1)))
print(assemble(Constant(1)*dx(2)))
print(assemble(Constant(1)*dx(3)))
print(assemble(Constant(1)*dx(4)))

```

as it gives the output:

```auto
1.0
0.25
0.25
0.25
0.25

```

---

<div class="post-metadata">

**Author:** ![AMM](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AMM](https://fenicsproject.discourse.group/u/AMM)\
**Post date:** [January 23, 2020, 4:15pm UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/6 "2020-01-23T16:15:31Z")

</div>

Ok, I just saw the problem : I write “line” instead of “triangle” for **mf** in the bash script that help me to create the xdmf file (and to prune them with meshio). it works well now.

By the way, running other code with this rectification (line to triangle for writing mf.xdmf) give me an error on the Dirichlet Boundary condition :  
\*\*\* Error: Unable to create Dirichlet boundary condition.  
\*\*\* Reason: User MeshFunction is not a facet MeshFunction (dimension is wrong).  
\*\*\* Where: This error was encountered inside DirichletBC.cpp.

The code previously worked with “line” for mf.xdmf.

Can you explain to me why?  
Do I have to write two **mf** files like **mf1** (which gives the physical labels of surfaces with “triangle”) and **mf2** (which gives the physical labels of borders with “line”)

Thank you in advance for your answer

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [January 23, 2020, 4:22pm UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/7 "2020-01-23T16:22:10Z")

</div>

You can write both the facet data and cell data to one xdmf file by doing the same thing for lines as for triangle. However, you Need to read it into a separate meshvaluecollection and meshfunction, Which takes in dimension 1 instead of 2.

---

<div class="post-metadata">

**Author:** ![AMM](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AMM](https://fenicsproject.discourse.group/u/AMM)\
**Post date:** [January 24, 2020, 8:38am UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/8 "2020-01-24T08:38:17Z")

</div>

Thank you very much. That’s now working well.

Maybe I can ask you one last question here (tell me if i should open another thread) : do you know how to define a discontinuous coefficient k on the whole domain (ie k = k\_i\chi\_i where \chi\_i is the characteristic function of a subdomain and k\_i are constant).

I would like something like for the 4 subdomains :

```
k_values = [1.5, 50, 2, 3] 
help = np.asarray(subdomains.array(), dtype=np.int32)
k.vector()[:] = np.choose(help, k_values)

```

But with that, I need to rename all my physical surface from gmsh. Do you have an idea on how to proceed?

Thank you for your help

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [January 24, 2020, 9:23am UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/9 "2020-01-24T09:23:46Z")

</div>

You can do something like:

```auto
V = FunctionSpace(mesh, "DG", 0)
f = Function(V)
f.vector()[:] = 1.5*(1==subdomains.array()) + 50*(2==subdomains.array()) + ...

```

---

<div class="post-metadata">

**Author:** ![AMM](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AMM](https://fenicsproject.discourse.group/u/AMM)\
**Post date:** [January 24, 2020, 9:48am UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/10 "2020-01-24T09:48:12Z")

</div>

Dokken,

I really appreciate your help and advice.

Thank you very much and have a good day.

---

<div class="post-metadata">

**Author:** ![AMM](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AMM](https://fenicsproject.discourse.group/u/AMM)\
**Post date:** [January 29, 2020, 12:58pm UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/11 "2020-01-29T12:58:00Z")

</div>

Hi,

I’m sorry to bother you again with this question but it I cannot make it work again.

What did you take for “subdomain” in your lines of code below?

```auto
V = FunctionSpace(mesh, "DG", 0)
f = Function(V)
f.vector()[:] = 1.5*(1==subdomains.array()) + 50*(2==subdomains.array()) + ...

```

When I choose “subdomain = MeshFunction(“size\_t”, mesh, mesh.topology().dim())”, it doesn’t work.

The thing is that I don’t know how and where my physical tag (for surfaces from gmsh) are stored.

Thank you in advance for your answer

AMM

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [January 29, 2020, 1:19pm UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/12 "2020-01-29T13:19:25Z")

</div>

Hi,  
You need to load your data as described in the post above.

```auto
mvc = MeshValueCollection("size_t", mesh, 2)
with XDMFFile("mf.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)

```

So `subdomains` would be equal to `mf`

---

<div class="post-metadata">

**Author:** ![AMM](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AMM](https://fenicsproject.discourse.group/u/AMM)\
**Post date:** [January 29, 2020, 1:48pm UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/13 "2020-01-29T13:48:05Z")

</div>

Thank you very much (I wrote your mf file under two different files “mf” and “cf” and I tested only mf…)  
That’s working.

Sorry for this trivial question.

---

<div class="post-metadata">

**Author:** ![meteoguc](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/meteoguc/32/3416_2.png) [@meteoguc](https://fenicsproject.discourse.group/u/meteoguc)\
**Post date:** [July 22, 2022, 7:40am UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/14 "2022-07-22T07:40:39Z")

</div>

I think this does not work anymore?

I am trying to repeat this example but stuck with this part of the code. I will write down what I have done so far.

Write xdmf file for surfaces and boundaries with the most recent working script that I can find:

```auto
import meshio
import numpy as np
msh = meshio.read("mesh.msh")

line_cells = []
for cell in msh.cells:
    if cell.type == "triangle":
        triangle_cells = cell.data
    elif cell.type == "line":
        if len(line_cells) == 0:
            line_cells = cell.data
        else:
            line_cells = np.vstack([line_cells, cell.data])

line_data = []
for key in msh.cell_data_dict["gmsh:physical"].keys():
    if key == "line":
        if len(line_data) == 0:
            line_data = msh.cell_data_dict["gmsh:physical"][key]
        else:
            line_data = np.vstack([line_data, msh.cell_data_dict["gmsh:physical"][key]])
    elif key == "triangle":
        triangle_data = msh.cell_data_dict["gmsh:physical"][key]

triangle_mesh = meshio.Mesh(points=msh.points[:,:2], cells={"triangle": triangle_cells})
line_mesh =meshio.Mesh(points=msh.points,
                           cells=[("line", line_cells)],
                           cell_data={"name_to_read":[line_data]})
meshio.write("mesh.xdmf", triangle_mesh)

meshio.xdmf.write("mf.xdmf", line_mesh)

```

This creates mesh.h5, mesh.xdmf and mf.xdmf files. Now tried to define mf and mvc and calculate the integrals:

```auto
from dolfin import * 
mesh = Mesh()
with XDMFFile("mesh.xdmf") as infile:
    infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 2) 
with XDMFFile("mf.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)

```

But this gives an error:  
\*\*\* DOLFIN encountered an error. If you are not able to resolve this issue  
\*\*\* using the information listed below, you can ask for help at

* * *

\*\*\* [fenics-support@googlegroups.com](mailto:fenics-support@googlegroups.com)

* * *

\*\*\* Remember to include the error message listed below and, if possible,  
\*\*\* include a _minimal_ running example to reproduce the error.

* * *

\*\*\* -------------------------------------------------------------------------  
\*\*\* Error: Unable to find entity in map.  
\*\*\* Reason: Error reading MeshValueCollection.  
\*\*\* Where: This error was encountered inside HDF5File.cpp.  
\*\*\* Process: 0

* * *

\*\*\* DOLFIN version: 2019.1.0

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [July 22, 2022, 8:01am UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/15 "2022-07-22T08:01:27Z")

</div>

See the links in: [Marking the boundaries of a 2D mesh for a mixed function-space problem - #4 by dokken](https://fenicsproject.discourse.group/t/marking-the-boundaries-of-a-2d-mesh-for-a-mixed-function-space-problem/8799/4)

---

<div class="post-metadata">

**Author:** ![meteoguc](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/meteoguc/32/3416_2.png) [@meteoguc](https://fenicsproject.discourse.group/u/meteoguc)\
**Post date:** [July 22, 2022, 8:16am UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/16 "2022-07-22T08:16:29Z")

</div>

Actually that is also me 🙂 But this time I am trying to define multiple Physical Surfaces inside the domain as in this problem. Physical Lines do not cause a problem but dividing the domain and marking different regions is a problem.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [July 22, 2022, 8:21am UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/17 "2022-07-22T08:21:22Z")

</div>

My point is that:

1. You are using an old and very complicated way of converting meshes (that is known to be error prone).
2. The links in the previous posts shows you how to tag both surfaces and volumes.
3. Without a reproducible example, there is not much we can do to help you

---

<div class="post-metadata">

**Author:** ![meteoguc](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/meteoguc/32/3416_2.png) [@meteoguc](https://fenicsproject.discourse.group/u/meteoguc)\
**Post date:** [July 22, 2022, 9:04am UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/18 "2022-07-22T09:04:35Z")

</div>

I will be using FEniCSx someday for sure. Unfortunately I have to stick with Docker Toolbox and some older scripts for at least a couple of months.

Here is the .geo for a rectangle divided to two in gmsh and exported as Version 4 ASCI II:

```auto
Point(1) = {0, 0, 0, 0.1};
Point(2) = {1, 0, 0, 0.1};
Point(3) = {2, 0, 0, 0.1};
Point(4) = {2, 2, 0, 0.1};
Point(5) = {1, 2, 0, 0.1};
Point(6) = {0, 2, 0, 0.1};
//+
Line(7) = {1, 2};
Line(8) = {2, 5};
Line(9) = {5, 6};
Line(10) = {6, 1};
Line(11) = {2, 3};
Line(12) = {3, 4};
Line(13) = {4, 5};
//+
Curve Loop(14) = {7, 8, 9, 10};
Plane Surface(15) = {14};
Curve Loop(16) = {8, -13, -12, -11};
Plane Surface(17) = {16};
//+
Physical Surface(111) = {15};
Physical Surface(222) = {17};

```

The code above I used in this and the other topic this time gives:  
AttributeError: ‘list’ object has no attribute ‘shape’

Method 1: I have achieved a good accuracy for my problem with mshr but it is of no use to me since I need to create my mesh in gmsh and mark my boundaries and areas:  
(and I know this is an ancient method now)

```auto
from mshr import *
from fenics import *
import numpy as np

# This method is actually fine but I couldn't implement it to gmsh;
# I tried to find a way to implement this to gmsh but so far I couldn't...

domain_rectangle = Rectangle(Point(0, 0), Point(2, 2))
domain_L = Rectangle(Point(0, 0), Point(1, 2))

domain_setter = domain_rectangle

domain_rectangle.set_subdomain(1, domain_setter)
domain_rectangle.set_subdomain(2, domain_L)

mesh = generate_mesh(domain_rectangle, 10)

mf = MeshFunction('size_t',mesh,mesh.topology().dim(), mesh.domains())
dx_sub = Measure('dx', domain=mesh, subdomain_data=mf)

# Check if the area is marked correctly
File("Marked_Area.pvd").write(mf)

# Check if the area is calculated correctly
Method_1_A = assemble(1*dx_sub(1))
Method_1_S = assemble(1*dx_sub(2))
print("Total Area = ", Method_1_A)
print("Subdomain Area = ", Method_1_S)

```

Method 2: If I create mesh with a single Physical Surface and use AutoSubdomain as I show below:

```auto
region_L = AutoSubDomain(lambda x: x[0] <= 1)
region_L.mark(mf_1, 1)

```

my integration gives unmeaningful results.

So the Method 1 is so far my best solution. But it is of no use to me.

I would really appreciate if you showed me a very simple example for this because what I am trying to achieve is to mark my boundaries and subdomains before I get my mesh from gmsh so that I can integrate for different areas within my 2D domain. Also, I actually thought this was one of the most recent methods 🥲

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [July 22, 2022, 9:27am UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/19 "2022-07-22T09:27:37Z")

</div>

> [@meteoguc](#):
>
> I will be using FEniCSx someday for sure. Unfortunately I have to stick with Docker Toolbox and some older scripts for at least a couple of months.

Consider [Mesh generation and conversion with GMSH and PYGMSH | Jørgen S. Dokken](http://jsdokken.com/src/pygmsh_tutorial.html#second)

---

<div class="post-metadata">

**Author:** ![meteoguc](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/meteoguc/32/3416_2.png) [@meteoguc](https://fenicsproject.discourse.group/u/meteoguc)\
**Post date:** [July 22, 2022, 9:54am UTC](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269/20 "2022-07-22T09:54:02Z")

</div>

Thank you! I will try my best.

[Next page](https://fenicsproject.discourse.group/t/how-to-extract-and-use-physical-labels-from-gmsh-surfaces-on-fenics-2d-mesh/2269.md?page=2)
