Passing Element Vectors for C++ to Python

Hello everyone!

We are trying to pass individual element vectors from our C++ extension MyCollect to Python. The C++ extension code is in the attachments.
In Minimum.py a small test case is given.

From py:print() we can see that the output values are being overwritten during the iteration over all elements, although the element vectors should be written for every element individually. Also the values that MyCollect returns are nonsense.

Does anyone know what’s going wrong or how to fix these problems?

Thanks and best regards.
Nils

https://ngsolve.org/media/kunena/attachments/1180/Minimum.py
https://ngsolve.org/media/kunena/attachments/1180/myCollecting.hpp
https://ngsolve.org/media/kunena/attachments/1180/myCollecting.cpp
https://ngsolve.org/media/kunena/attachments/1180/ngsextension.cpp

Attachment: Minimum.py

Attachment: myCollecting.hpp

Attachment: myCollecting.cpp

Attachment: ngsextension.cpp

Hi Nils,

you allocate your element vectors at LocalHeap. This memory is gone after your IterateElements kernel function, and your FlatVector pointers point to garbage.

Use a vector of Vector entries, which take care of dynamic memory allocation.

Joachim

Attachment: myCollecting.cpp