Prescribing spatially varying cell sizes

Hi!

I am setting up my mesh by

domain = mshr.Polygon(points)
mesh = mshr.generate_mesh(domain, N)

However, I need a very high resolution in some specific part of my domain, while other parts can be resolved coarsely. Therefore, I would like to prescribe the cell size as a function of the coordinates, for instance.

Is this possible?

1 Like

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

Hi kamensky,

thank you for your answer. Refine is roughly dividing the cell size by two, I guess? So I would need to apply the refine method iteratively with a varying mesh function…

Yeah, I’ve done that before when I needed significant refinement in a specific region. It’s a bit tedious, but, for simple geometries, still may be easier than using a “real” mesh generator (e.g., Gmsh).

Ok, I’ll try this. Thanks again!