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

Using Adapt on a MeshFunction (looking for a working example)

+1 vote

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
*** -------------------------------------------------------------------------
asked Mar 9, 2015 by leibs FEniCS Novice (360 points)

1 Answer

+1 vote
 
Best answer

This is a known bug related to the choice of mesh refinement algorithm. Add the following lines in the beginning, then it works:

from dolfin import *
parameters["refinement_algorithm"] = "plaza_with_parent_facets"
answered Mar 9, 2015 by Gregor Mitscha-Baude FEniCS User (2,280 points)
selected Mar 9, 2015 by leibs
...