Create a mesh from another one

Hi,

starting from a rectangular mesh

from dolfin import *
from mshr impot *
geom1 = Rectangle(Point(0., 0.), Point(100., 10.)
mesh1 = generate_mesh(geom1, 100)

i want to create a second mesh which takes only the central part of the first mesh with the exact same elements and nodes. I tried to define the new geometry as

geom2 = Rectangle(Point(25., 0), Point(75., 10.))
mesh2 = generate_mesh(geom2, 50)

as well as

 r1 = Rectangle(Point(0., 0), Point(25., 10.))
 r2 = Rectangle(Point(75., 0), Point(100., 10.))
 geom3 = geom1 - r1 - r2
 mesh3 = generate_mesh(geom3, 50)

but when generating the mesh 2 or 3 the elements are different in position and number.
Is possible to “cut” the central part of the mesh and use it to generate a second mesh?

Thanks in advance

Hi,

First I would recommend using the Dolfin function RectangleMesh here instead of mshr to get a more regular grid :

nx=100 # Number of elements along x
ny=10 # Number of elements along y
mesh1 = RectangleMesh(Point(0., 0.), Point(100., 10.), nx, ny)

You can then mark the elements of that mesh corresponding to the central part you want to extract :

class InnerRegion(SubDomain):
     def inside(self,x,on_boundary):
         return (25. <= x[0] ) and (x[0] <= 75.) 

marker = MeshFunction("size_t", mesh1, mesh1.topology().dim(), 0) # cells marker
inner_region = InnerRegion()
inner_region.mark(marker, 1) # marking inner region cells with 1

In the current version of dolfin you can use the SubMesh class to create a submesh composed of a subset of cells of your initial mesh :

submesh1 = SubMesh(mesh1, inner_region)

But note that SubMesh can only create submeshes composed of a subset of cells of the parent mesh (not facets, or any lower dimension entities), and as far as I know SubMesh doesn’t work in parallel.

In the context of the mixed-dimensional framework we are developing, there is also a new MeshView class that can be used to create such submeshes.

submesh2 = MeshView.create(marker, 1)

This feature works in parallel, and with lower dimension entities. It will soon be available in dolfin, but for now you can give it a try by using the dedicated branch cecile/mixed-dimensional, or the Docker container.

1 Like