Test code:
from dolfin import *
import cppimport
compiled_cpp_module = cppimport.imp('delta_interpolation')
mesh = UnitCubeMesh(21, 21, 21)
V = VectorFunctionSpace(mesh, 'CG', 2)
dof_component_map = {}
compiled_cpp_module.extract_dof_component_map_1(dof_component_map, V)
cpp file:
void extract_dof_component_map_1(std::unordered_map<std::size_t,
std::size_t>& dof_component_map,
const FunctionSpace& V)
{
std::cout << "hi";
}
PYBIND11_MODULE(delta_interpolation, m)
{
py::bind_map<std::unordered_map<std::size_t, std::size_t>>(m, "unordered_mapping");
m.def("extract_dof_component_map_1", (void (*)(std::unordered_map<std::size_t,
std::size_t>& , const FunctionSpace&))
&extract_dof_component_map_1);
m.def("extract_dof_component_map_1", [](py::dict d, py::object U){
auto _d = d.cast<std::unordered_map<std::size_t, std::size_t>&>();
auto _U = U.attr("_cpp_object").cast<const FunctionSpace&>();
extract_dof_component_map_1(_d, _U);
});
}
Error:
Line: compiled_cpp_module.extract_dof_component_map_1(dof_component_map, V)
RuntimeError: Uable to cast Python instance to C++ type (complie in debug mode for details)
It should return a “Hi” when running the program. I don’t know the reason that causes the runtime error. When looking at the debug mode, it either didn’t show anything.
I apprieciate any help.