Adapt a function on a refined mesh

I have a mesh, and I refine it using the adapt function

mesh1 = adapt(mesh,markedCells)

In Fenics 2017.2, I was able to adapt a function from the original mesh onto the adapted one using the adapt function

u1 = adapt(u,mesh1)

Nevertheless, I am not able to do it in Fenics 2019.1. I get the following error:

TypeError: adapt(): incompatible function arguments. The following argument types are supported:
    1. (arg0: dolfin.cpp.mesh.Mesh) -> dolfin.cpp.mesh.Mesh
    2. (arg0: dolfin.cpp.mesh.MeshFunctionSizet, arg1: dolfin.cpp.mesh.Mesh) -> dolfin.cpp.mesh.MeshFunctionSizet

Is there this functionality on Fenics 2019.1?

Thank you in advance!

A function with the signature that you’re looking for is still in

But, looking at

it doesn’t seem to have made it into the Python interface after the switch to pybind11. You can implement a quick workaround as follows:

from dolfin import *

cpp_code = """
#include <pybind11/pybind11.h>
#include <dolfin/adaptivity/adapt.h>
#include <dolfin/function/Function.h>
#include <dolfin/mesh/Mesh.h>
namespace py = pybind11;
m.def("adapt", [](const dolfin::Function &function,
		  std::shared_ptr<const dolfin::Mesh> adapted_mesh,
                  bool interpolate){
	         return dolfin::adapt(function, adapted_mesh, interpolate);});
m = compile_cpp_code(cpp_code)
def adaptFunction(f,mesh,interp=True):
    return m.adapt(f.cpp_object(),mesh,interp)

# Test:
mesh = UnitSquareMesh(2,2)
V = FunctionSpace(mesh,"CG",1)
f = interpolate(Expression("x[0]",degree=1),V)

rmesh = refine(mesh)
rf = adaptFunction(f,rmesh)

# Plot:
from matplotlib import pyplot as plt

Thank you!

I would like to add that rf is of a pybind_11 type. If, for some reason, you need a pure python type, you can use the assign function as


where python_rf is a function of a function space.

Thank you again!