I'm trying to understand how to use the adapt
function to refine a MeshFunction
. I've tried to hunt down a fully working example without much luck. Below is the simplest near-working example I could come up with to illustrate my lack of understanding.
Goal: given a MeshFunction
on the facets (ie. mesh.topology().dim()-1
) that marks a boundary, I would like to "interpolate" the function to an adapted mesh and preserve the marked boundary facets.
from dolfin import *
# Build a simple mesh
mesh = RectangleMesh(0,0,1,1,8,8)
# subdomain class for south boundary
class South(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and near(x[1],0.0)
# Mark the south boundary facets with 1 and the rest with 0
south = South()
mesh_func = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
south.mark(mesh_func, 1)
# Adapt the mesh based on a single cell marker
markers = MeshFunction("bool", mesh, mesh.topology().dim(), False)
markers.array()[21] = True
mesh_a = adapt(mesh, markers)
# Attempt to adapt the facet function
mesh_func_a = adapt(mesh_func, mesh_a)
An error is thrown on the last line when adapt
is called on the MeshFunction
:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** fenics@fenicsproject.org
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to adapt mesh function.
*** Reason: Unable to extract information about parent mesh entities.
*** Where: This error was encountered inside adapt.cpp.
*** Process: unknown
***
*** DOLFIN version: 1.5.0
*** Git changeset: f467b66dcfd821ec20e9f9070c7cef5a991dbc42
*** -------------------------------------------------------------------------