hi, I am trying to use adapt(space) in dolfin-version 2019.1 it gives me an error, however, the same command works fine in dolfin-version 2016 . The erorr msg is:
ph = adapt(meshFunctionToAdapt,ph)
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
Invoked with: <dolfin.cpp.mesh.MeshFunctionSizet object at 0x7f94c0e99650>, Coefficient(FunctionSpace(Mesh(VectorElement(FiniteElement(‘Lagrange’, triangle, 1), dim=2), 0), FiniteElement(‘Lagrange’, triangle, 1)), 32)
is there any workaround for this problem? Thanks for help.
Hi,
this is due to missing pybind11 interface for adapt
(see discussion Adapt a function on a refined mesh)
Here is a fix that can be used for MeshFunctions, Forms, DirichletBC and FunctionSpace
cpp_code = """
#include<pybind11/pybind11.h>
#include<dolfin/adaptivity/adapt.h>
#include<dolfin/mesh/Mesh.h>
#include<dolfin/mesh/MeshFunction.h>
#include<dolfin/fem/DirichletBC.h>
#include<dolfin/function/FunctionSpace.h>
#include<dolfin/fem/Form.h>
namespace py = pybind11;
PYBIND11_MODULE(SIGNATURE, m) {
m.def("adapt", (std::shared_ptr<dolfin::MeshFunction<std::size_t>> (*)(const dolfin::MeshFunction<std::size_t>&,
std::shared_ptr<const dolfin::Mesh>)) &dolfin::adapt,
py::arg("mesh_function"), py::arg("adapted_mesh"));
m.def("adapt", (std::shared_ptr<dolfin::DirichletBC> (*)(const dolfin::DirichletBC&,
std::shared_ptr<const dolfin::Mesh>, const dolfin::FunctionSpace&)) &dolfin::adapt,
py::arg("bc"), py::arg("adapted_mesh"), py::arg("S"));
m.def("adapt", (std::shared_ptr<dolfin::FunctionSpace> (*)(const dolfin::FunctionSpace&,
std::shared_ptr<const dolfin::Mesh>)) &dolfin::adapt,
py::arg("space"), py::arg("adapted_mesh"));
m.def("adapt", (std::shared_ptr<dolfin::Form> (*)(const dolfin::Form&,
std::shared_ptr<const dolfin::Mesh>, bool)) &dolfin::adapt,
py::arg("form"), py::arg("adapted_mesh"), py::arg("adapt_coefficients")=true);
}
"""
adapt = compile_cpp_code(cpp_code).adapt