SOS : Combine two 2D quad element meshes using mshr

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 :

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

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.

2 Likes

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?

The xml format of dolfin is also long deprecated. meshio should convert a gmsh mesh to XDMF for use with dolfin without issue. See also this enormous discussion.

1 Like