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

where is python version of compute_vertex_values?

0 votes

I looked at the source code and I do not find a definition for

values = f.compute_vertex_values() 

that returns a numpy array. But the function seems to work. I am asking because I'd like to implement something similar from c++ to python.

asked Feb 19, 2014 by chaffra FEniCS User (1,830 points)

1 Answer

+2 votes

The python version of f.compute_vertex_values can be found in the installed site-packages/dolfin/cpp/function.py module that is automatically generated by swig. The python version simply wraps the C++ function and the implementation can be found in the source file dolfin/function/Function.cpp.

answered Feb 19, 2014 by mikael-mortensen FEniCS Expert (29,340 points)

Yes the problem is that I do not see the function in c++ that takes no argument and return the array of vertex values. I'd like to know how this is done.

There is no such function in c++. Have a look also at dolfin/swig/function/post.i for how the no argument version is created.

But it look like the section %extend dolfin::GenericFunction in that file is commented out. Does swig ignore the /* ....*/? That's what was puzzling me...

Sorry, I did not see that it was commented out. I think this function is wrapped using a typemap that automatically converts a std::vector input argument (a non-const) to a numpy array return type. You can look in swig/typemaps/std_vector.i and see if that makes sense.

Well I looked at that file and I don't really see how that's possible since all the c++ compute_vertex_values return void. Unless someone can direct me to the exact code that does that trick I am confused here.

Does this have to do with ARGOUT_TYPEMAP_STD_VECTOR_OF_PRIMITIVES?

I'm no swig expert, but I think so, yes. dolfin's C++ functions that take a std::vector as argument are type mapped to return a numpy array. This is considered a more pythonic way of operating functions.

...