Prescribing spatially varying cell sizes

I don’t know of a way to prescribe cell size as a function, but you can refine cells in subdomains, as illustrated in here

or also deform a given mesh according to a function, to focus refinement in a given location:

from dolfin import *

mesh = UnitSquareMesh(10,10)
V = VectorFunctionSpace(mesh,"Lagrange",1)
x = SpatialCoordinate(mesh)
meshDisp = Constant(0.1)*as_vector((sin(2.0*pi*x[0])*sin(pi*x[1]),
                                    sin(2.0*pi*x[1])*sin(pi*x[0])))
ALE.move(mesh,project(meshDisp,V))

from matplotlib import pyplot as plt
plot(mesh)
plt.show()
2 Likes