# SOS : Combine two 2D quad element meshes using mshr

**URL:** https://fenicsproject.discourse.group/t/sos-combine-two-2d-quad-element-meshes-using-mshr/6330
**Category:** mesh
**Created:** [August 3, 2021, 1:40am UTC](https://fenicsproject.discourse.group/t/sos-combine-two-2d-quad-element-meshes-using-mshr/6330 "2021-08-03T01:40:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ferdi\_ferdi](https://avatars.discourse-cdn.com/v4/letter/f/8c91f0/32.png) [@Ferdi\_ferdi](https://fenicsproject.discourse.group/u/Ferdi_ferdi)
#### Post date: [August 3, 2021, 1:40am UTC](https://fenicsproject.discourse.group/t/sos-combine-two-2d-quad-element-meshes-using-mshr/6330/1 "2021-08-03T01:40:08Z")

</div>

Hello everyone, I would like to make a 2D quadrangular mesh on a heterogeneous structure (defined by two rectangular domains). Here is the syntax that does not work :

```auto
from fenics import *
import dolfin
from mshr import *
################### 
P1 = Point(0,0)
P2 = Point(1,1-0.003)
P3 = Point(0,1-0.003)
P4 = Point(1,1)
nx1 = 50
ny1 = 50
nx2 = 100
ny2 = 100
############
mesh1 = RectangleMesh.create([P1,P2],[nx2,ny2],CellType.Type.quadrilateral)
###########
mesh2 = RectangleMesh.create([P3,P4],[nx1,ny1],CellType.Type.quadrilateral)
domain_mesh = mesh1 + mesh2
mesh = generate_mesh(domain_mesh)
info(mesh)
import matplotlib.pyplot as plt
dolfin.plot(mesh, "2D mesh","Subdomains")
plt.show()

```

Error lessage :

> Blockquote  
> Traceback (most recent call last):  
> File “maillage\_Banouho.py”, line 21, in   
> domain = mesh1 - mesh2  
> TypeError: unsupported operand type(s) for +: ‘dolfin.cpp.mesh.Mesh’ and ‘dolfin.cpp.mesh.Mesh’

> Blockquote

Could someone help me to solve this problem. Thanks in advance

---

<div class="post-metadata">

### Author: ![Kei\_Yamamoto](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/kei_yamamoto/32/2904_2.png) [@Kei\_Yamamoto](https://fenicsproject.discourse.group/u/Kei_Yamamoto)
#### Post date: [August 3, 2021, 8:52am UTC](https://fenicsproject.discourse.group/t/sos-combine-two-2d-quad-element-meshes-using-mshr/6330/2 "2021-08-03T08:52:48Z")

</div>

As `mshr` is not maintained anymore, I would suggest using other external programs to create mesh, for example `gmsh`.

Then, it would be much easier for you to create other geometries in the future as well as getting an answer if you have problem creating a mesh.

---

<div class="post-metadata">

### Author: ![Banouho](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/banouho/32/4291_2.png) [@Banouho](https://fenicsproject.discourse.group/u/Banouho)
#### Post date: [August 3, 2021, 2:48pm UTC](https://fenicsproject.discourse.group/t/sos-combine-two-2d-quad-element-meshes-using-mshr/6330/3 "2021-08-03T14:48:32Z")

</div>

Hello Kei\_Yamamoto,  
I have the same problem with the mshr, I used the gmsh program to make the mesh but I have a problem with converting the .msh file to xml with dolfin-convert. Could you help me to solve this problem?

---

<div class="post-metadata">

### Author: ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)
#### Post date: [August 3, 2021, 2:50pm UTC](https://fenicsproject.discourse.group/t/sos-combine-two-2d-quad-element-meshes-using-mshr/6330/4 "2021-08-03T14:50:27Z")

</div>

The `xml` format of dolfin is also long deprecated. [meshio](https://github.com/nschloe/meshio) should convert a gmsh mesh to XDMF for use with dolfin without issue. See also this [enormous discussion](https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412).
