Hi all, I want to use adaptive refinement in a circle domain. As the boundary cells be refined I expect the new nodes to be added on the boundary but by using refine(mesh, cell_markers), they be added on the polygonal domain.
Is there a way to resolve this problem in refine?
Thank you in advance.
There is functionality to “snap” new nodes to a SubDomain
. It should be demonstrated by this demo
although the functionality is not properly accessible via Python in 2019.1. I fixed this in the development version (pull request 521), but you can also implement it yourself through the Python interface, by defining a function like
def py_snap_boundary(mesh, sub_domain):
boundary = BoundaryMesh(mesh,"exterior")
dim = mesh.geometry().dim()
x = boundary.coordinates()
for i in range(0,boundary.num_vertices()):
sub_domain.snap(x[i,:])
ALE.move(mesh,boundary)
Many thanks for your answer. I would be grateful if you could give a more explanation about considering sub_domain in py_snap_boundary(mesh, sub_domain).
In fact, I have already used refine(mesh, cell_markers), so I don’t know how I should consider sub_domain here.
Take a look at the demo I linked. To get the correct behavior in that demo, you would add the definition of py_snap_boundary
from my previous post and replace both instances of
mesh.snap_boundary(hole)
with
py_snap_boundary(mesh,hole)
I imagine it should be fine to just use a SubDomain
corresponding to the entire circular boundary for purposes of mesh snapping (i.e., to be used analogously to hole
from the demo). On parts of the boundary where the mesh was not refined, there just won’t be any new nodes to move, so the snapping won’t do anything.
Thank you very much, it worked well.