pybind11 binding for FunctionSpace


97
views
1
7 weeks ago by
Dear community,

I'm running FEniCS 2018.1.0 (stable) with Python 3.6.5 on Arch Linux and have problems using compile_cpp_code() with FunctionSpace. I've had success using for instance GenericMatrix. Is there something I'm missing or is there something wrong with FEniCS? Here's an MWE::
from dolfin import *

code="""

#include <pybind11/pybind11.h>
#include <dolfin/function/FunctionSpace.h>

void func(const dolfin::FunctionSpace& V){}
PYBIND11_MODULE(SIGNATURE, m)
{
  m.def("func", &func);
}

"""

compiled = compile_cpp_code(code) 

mesh = UnitSquareMesh(8,8)
V = FunctionSpace(mesh, 'CG', 1)
compiled.func(V)
​


Output:

Traceback (most recent call last):
  File "mwe_FunctionSpace.py", line 20, in <module>
    compiled.func(V)
TypeError: func(): incompatible function arguments. The following argument types are supported:
    1. (arg0: dolfin.cpp.function.FunctionSpace) -> None

Invoked with: FunctionSpace(Mesh(VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2), 0), FiniteElement('Lagrange', triangle, 1))
​


Kind regards
Community: FEniCS Project

1 Answer


5
7 weeks ago by
There is a difference between a Python FunctionSpace, and the one expected by c++. In this case, you can use V.cpp_object() - I think.

Not quite right, I think, since the member function V.cpp_object() doesn't exist, but you indeed put me on the right track. What worked was this:

compiled.func(V._cpp_object)

Thank you.

written 7 weeks ago by Sigvald Marholm  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »