Is there a way to create different mesh density for several rectangular layers in 2D?

Hi everyone,
I’m trying to solve an elastic problem in 2D which contains a thin layer on a substrate. In 2D that translates to a rectangle for the substrate and a much thinner one for the layer. Because of that in a thin layer I need to have much higher vertical density of the mesh.

I tried to use mshr to create the two regions and join them, but it does not preserve the boundary and there is no refinement:

from dolfin import *
from mshr import *
domain =   Rectangle(Point(0., 0.), Point(5., 1.)) \
         + Rectangle(Point(0., 1.), Point(5., 1.05)) \
mesh2d = generate_mesh(domain, 45)
File("mesh2d.pvd") << mesh2d

Is there a way around this without using 3rd party tools such as gmsh?

You might be able to do something analogous to this 2D example, where an initially-uniform mesh is deformed using a piecewise function to compress part (in this case the left half) of it:

from dolfin import *

# Create initial mesh; generalizes to 3D in a clear way.
N = 16
mesh = UnitSquareMesh(N,N)

# A CG1 vector-valued function can be used as a displacement to deform
# a given mesh using ALE.move():
V = VectorFunctionSpace(mesh,"CG",1)
u = interpolate(Expression(("x[0]>0.5 ? -0.5*(x[0]-0.5) : 0","0"),
                           degree=1),V)
ALE.move(mesh,u)

# Plot results interactively:
from matplotlib import pyplot as plt
plot(mesh)
plt.show()
1 Like

Thanks a lot, it solves the problem :slight_smile:
So now I will have to work out the details to make it multilayer, and that will be it.