This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Different mesh cell sizes at different subdomains

+1 vote

Hey,

In this simple example, I have a rectangular domain with inside a circular subdomain. When solving Poisson's equation inside my domain, I'm particularly interested in the solution in the circular subdomain, while the rest of my domain is of less interest. So I want different mesh cell sizes; a dense mesh inside the circle, a coarser mesh outside. The very simple code to plot the equal-meshed domain looks like:

domain=Rectangle(-10,-10,10,10)
domain.set_subdomain(1,Circle(0,0,4))
mesh=Mesh(domain,20)
plot(mesh,interactive=True)

So you can adjust the whole mesh spacing with the second argument of Mesh(domain,20). How to refine the mesh inside the circular subdomain, without changing the outer mesh?

Thanks for any help,

Adriaan

asked Apr 10, 2014 by Adriaan FEniCS Novice (660 points)

1 Answer

+2 votes
 
Best answer

You could continue with something like

cc = CellFunction("bool", mesh, False)
circle = AutoSubDomain(lambda x: sqrt(x[0]*x[0]+x[1]*x[1]) < 4+1e-8)
circle.mark(cc, True)
mesh = refine(mesh, cc)
answered Apr 10, 2014 by mikael-mortensen FEniCS Expert (29,340 points)
selected Apr 10, 2014 by Adriaan

This works fine, thanks!
Is it also possible to manually adjust the mesh sizes? When you create a circular mesh like

CircleMesh(Point(0.0),4,3.0)

the mesh spacing is regulated by the third parameter (3.0 here). Is it also possible to do something like this for the mesh refinement in the circular subdomain?

...